CbmRoot
CbmTrdUtils.cxx
Go to the documentation of this file.
1 
6 #include "CbmTrdUtils.h"
7 
8 #include "CbmTrdAddress.h" // for CbmTrdAddress
9 #include "CbmTrdParModDigi.h" // for CbmTrdParModDigi
10 #include "CbmTrdParSetDigi.h" // for CbmTrdParSetDigi
11 
12 #include <FairLogger.h> // for LOG, Logger
13 
14 #include <Rtypes.h> // for kWhite
15 #include <TAxis.h> // for TAxis
16 #include <TCanvas.h> // for TCanvas
17 #include <TColor.h> // for TColor
18 #include <TH1.h> // for TH1
19 #include <TH2.h> // for TH2I, TH2
20 #include <TH3.h> // for TH3
21 #include <TLegend.h> // for TLegend
22 #include <TMath.h> // for Log10, Power
23 #include <TPaveText.h> // for TPaveText
24 #include <TPolyLine.h> // for TPolyLine
25 #include <TProfile.h> // for TProfile
26 
27 #include <iostream> // for operator<<, cout, ostream, basic_ostream
28 #include <stdio.h> // for printf
29 #include <utility> // for pair
30 
31 using std::cout;
32 using std::endl;
33 using std::flush;
34 
35 CbmTrdUtils::CbmTrdUtils() : fColors(), fZLevel() {}
37 
38 void CbmTrdUtils::InitColorVector(Bool_t logScale, Double_t min, Double_t max) {
39  fColors.clear();
40  fZLevel.clear();
41  for (Int_t i = 0; i < TColor::GetNumberOfColors(); i++) {
42  fColors.push_back(TColor::GetColorPalette(i));
43  if (logScale)
44  fZLevel.push_back(
45  min
46  + TMath::Power(10,
47  TMath::Log10(max) / TColor::GetNumberOfColors()
48  * i)); // log scale
49  else
50  fZLevel.push_back(
51  min + (max / TColor::GetNumberOfColors() * i)); // lin scale
52  }
53 }
54 Int_t CbmTrdUtils::GetColorCode(Double_t value) {
55  Int_t j = 0;
56  while ((value > fZLevel[j]) && (j < (Int_t) fZLevel.size())) {
57  //printf (" %i<%i %i %E <= %E\n",j,(Int_t)fZLevel.size(),fColors[j], rate, fZLevel[j]);
58  j++;
59  }
60  if (j >= (Int_t) fZLevel.size())
61  return 2;
62  else
63  return fColors[j];
64 }
65 
66 TPolyLine* CbmTrdUtils::CreateTriangularPad(Int_t column,
67  Int_t row,
68  Double_t value,
69  Double_t min_range,
70  Double_t max_range,
71  Bool_t logScale) {
72  InitColorVector(logScale, min_range, max_range);
73  const Int_t nCoordinates = 4;
74  Double_t x[nCoordinates];
75  Double_t y[nCoordinates];
76  if (row % 2 != 0) {
77  x[0] = column - 0.5;
78  y[0] = row - 1.5;
79  x[1] = column + 0.5;
80  y[1] = row + 0.5;
81  x[2] = column - 0.5;
82  y[2] = row + 0.5;
83  x[3] = column - 0.5;
84  y[3] = row - 1.5;
85  } else {
86  x[0] = column - 0.5;
87  y[0] = row - 0.5;
88  x[1] = column + 0.5;
89  y[1] = row - 0.5;
90  x[2] = column + 0.5;
91  y[2] = row + 1.5;
92  x[3] = column - 0.5;
93  y[3] = row - 0.5;
94  }
95  TPolyLine* pad = new TPolyLine(nCoordinates, x, y);
96  pad->SetLineColor(1);
97  pad->SetFillColor(GetColorCode(value));
98 
99  return pad;
100 }
101 TPolyLine* CbmTrdUtils::CreateRectangularPad(Int_t column,
102  Int_t row,
103  Double_t value,
104  Double_t min_range,
105  Double_t max_range,
106  Bool_t logScale) {
107  InitColorVector(logScale, min_range, max_range);
108  const Int_t nCoordinates = 5;
109  Double_t x[nCoordinates];
110  Double_t y[nCoordinates];
111  x[0] = column - 0.5;
112  y[0] = row - 0.5;
113  x[1] = column - 0.5;
114  y[1] = row + 0.5;
115  x[2] = column + 0.5;
116  y[2] = row + 0.5;
117  x[3] = column + 0.5;
118  y[3] = row - 0.5;
119  x[4] = column - 0.5;
120  y[4] = row - 0.5;
121  TPolyLine* pad = new TPolyLine(nCoordinates, x, y);
122  pad->SetLineColor(1);
123  pad->SetFillColor(GetColorCode(value));
124 
125  return pad;
126 }
127 
128 
130  Int_t color,
131  Int_t mStyle,
132  Int_t mSize,
133  TString xTitle,
134  TString yTitle) {
135  h->SetStats(kFALSE);
136  h->SetMarkerStyle(mStyle);
137  h->SetMarkerSize(mSize);
138  h->SetMarkerColor(color);
139  h->SetLineColor(color);
140  h->GetXaxis()->SetLabelSize(0.03);
141  h->GetYaxis()->SetLabelSize(0.03);
142  //h->GetZaxis()->SetLabelSize(0.03);
143  h->GetXaxis()->SetTitleSize(0.035);
144  h->GetXaxis()->SetTitleOffset(1.25);
145  h->GetYaxis()->SetTitleSize(0.035);
146  h->GetYaxis()->SetTitleOffset(1.25);
147  //h->GetZaxis()->SetTitleSize(0.035);
148  //h->GetZaxis()->SetTitleOffset(-2);
149  h->SetXTitle(xTitle);
150  h->SetYTitle(yTitle);
151 }
152 
154  Int_t color,
155  Int_t mStyle,
156  Int_t mSize,
157  TString xTitle,
158  TString yTitle,
159  TString zTitle) {
160  h->SetStats(kFALSE);
161  h->SetMarkerStyle(mStyle);
162  h->SetMarkerSize(mSize);
163  h->SetMarkerColor(color);
164  h->SetLineColor(color);
165  h->GetXaxis()->SetLabelSize(0.03);
166  h->GetYaxis()->SetLabelSize(0.03);
167  h->GetZaxis()->SetLabelSize(0.03);
168  h->GetXaxis()->SetTitleSize(0.035);
169  h->GetXaxis()->SetTitleOffset(1.5);
170  h->GetYaxis()->SetTitleSize(0.035);
171  h->GetYaxis()->SetTitleOffset(1.5);
172  h->GetZaxis()->SetTitleSize(0.035);
173  h->GetZaxis()->SetTitleOffset(1.25);
174  h->SetXTitle(xTitle);
175  h->SetYTitle(yTitle);
176  h->SetZTitle(zTitle);
177 }
178 
180  Int_t color,
181  Int_t mStyle,
182  Int_t mSize,
183  TString xTitle,
184  TString yTitle,
185  TString zTitle) {
186  h->SetStats(kFALSE);
187  h->SetMarkerStyle(mStyle);
188  h->SetMarkerSize(mSize);
189  h->SetMarkerColor(color);
190  h->SetLineColor(color);
191  h->GetXaxis()->SetLabelSize(0.03);
192  h->GetYaxis()->SetLabelSize(0.03);
193  h->GetZaxis()->SetLabelSize(0.03);
194  h->GetXaxis()->SetTitleSize(0.035);
195  h->GetXaxis()->SetTitleOffset(1.25);
196  h->GetYaxis()->SetTitleSize(0.035);
197  h->GetYaxis()->SetTitleOffset(1.25);
198  h->GetZaxis()->SetTitleSize(0.035);
199  h->GetZaxis()->SetTitleOffset(1.25);
200  h->SetXTitle(xTitle);
201  h->SetYTitle(yTitle);
202  h->SetZTitle(zTitle);
203 }
204 
206  Int_t color,
207  Int_t mStyle,
208  Int_t mSize,
209  TString xTitle,
210  TString yTitle) {
211  h->SetStats(kFALSE);
212  h->SetMarkerStyle(mStyle);
213  h->SetMarkerSize(mSize);
214  h->SetMarkerColor(color);
215  h->SetLineColor(color);
216  h->GetXaxis()->SetLabelSize(0.03);
217  h->GetYaxis()->SetLabelSize(0.03);
218  //h->GetZaxis()->SetLabelSize(0.03);
219  h->GetXaxis()->SetTitleSize(0.035);
220  h->GetXaxis()->SetTitleOffset(1.25);
221  h->GetYaxis()->SetTitleSize(0.035);
222  h->GetYaxis()->SetTitleOffset(1.25);
223  //h->GetZaxis()->SetTitleSize(0.035);
224  //h->GetZaxis()->SetTitleOffset(-2);
225  h->SetXTitle(xTitle);
226  h->SetYTitle(yTitle);
227 }
228 
229 void CbmTrdUtils::NiceLegend(TLegend* l) {
230  l->SetLineColor(0);
231  l->SetLineStyle(0);
232  l->SetFillStyle(0);
233  l->SetTextSize(0.03);
234 }
235 
236 Int_t CbmTrdUtils::PdgToGeant(Int_t PdgCode) {
237  if (PdgCode == 22) return 1;
238  if (PdgCode == -11) return 2;
239  if (PdgCode == 11) return 3;
240  if (PdgCode == 12 || PdgCode == 14 || PdgCode == 16) return 4;
241  if (PdgCode == -13) return 5;
242  if (PdgCode == 13) return 6;
243  if (PdgCode == 111) return 7;
244  if (PdgCode == 211) return 8;
245  if (PdgCode == -211) return 9;
246  if (PdgCode == 130) return 10;
247  if (PdgCode == 321) return 11;
248  if (PdgCode == -321) return 12;
249  if (PdgCode == 2112) return 13;
250  if (PdgCode == 2212) return 14;
251  if (PdgCode == -2212) return 15;
252  if (PdgCode == 310) return 16;
253  if (PdgCode == 221) return 17;
254  if (PdgCode == 3122) return 18;
255  if (PdgCode == 3222) return 19;
256  if (PdgCode == 3212) return 20;
257  if (PdgCode == 3112) return 21;
258  if (PdgCode == 3322) return 22;
259  if (PdgCode == 3312) return 23;
260  if (PdgCode == 3332) return 24;
261  if (PdgCode == -2112) return 25;
262  if (PdgCode == -3122) return 26;
263  if (PdgCode == -3112) return 27;
264  if (PdgCode == -3212) return 28;
265  if (PdgCode == -3322) return 30;
266  if (PdgCode == -3312) return 31;
267  if (PdgCode == -3332) return 32;
268  if (PdgCode == -15) return 33;
269  if (PdgCode == 15) return 34;
270  if (PdgCode == 411) return 35;
271  if (PdgCode == -411) return 36;
272  if (PdgCode == 421) return 37;
273  if (PdgCode == -412) return 38;
274  if (PdgCode == 431) return 39;
275  if (PdgCode == -431) return 40;
276  if (PdgCode == 4122) return 41;
277  if (PdgCode == 24) return 42;
278  if (PdgCode == -24) return 43;
279  if (PdgCode == 23) return 44;
280  if (PdgCode == 50000050) return 45;
281  if (PdgCode == 1000010020) return 46;
282  if (PdgCode == 1000010030) return 47;
283  if (PdgCode == 1000020040) return 48;
284  //if (PdgCode == -1)
285  //return 49;
286  LOG(info) << PdgCode;
287  return 49;
288 }
289 
290 
291 void CbmTrdUtils::Statusbar(Int_t i, Int_t n) {
292  if (int(i * 100 / float(n)) - int((i - 1) * 100 / float(n)) >= 1) {
293  if (int(i * 100 / float(n)) == 1 || i == 1 || i == 0) cout << "[" << flush;
294  cout << "-" << flush;
295  if (int(i * 10 / float(n)) - int((i - 1) * 10 / float(n)) >= 1) cout << "|";
296  if (int(i * 100 / float(n)) >= 99) cout << "]" << endl;
297  }
298 }
299 
300 Int_t CbmTrdUtils::GetModuleType(Int_t moduleAddress,
301  CbmTrdParModDigi* fModuleInfo,
302  CbmTrdParSetDigi* fDigiPar) {
303  Int_t type = -1;
304  fModuleInfo = (CbmTrdParModDigi*) fDigiPar->GetModulePar(moduleAddress);
305  Int_t nRows = fModuleInfo->GetNofRows();
306  Int_t nCols = fModuleInfo->GetNofColumns();
307 
308  if (nCols == 80) {
309  if (nRows == 36)
310  type = 1; // v17a
311  else if (nRows == 24)
312  type = 2; // v17a
313  else if (nRows == 12)
314  type = 3; // v17a
315 
316  else if (nRows == 32)
317  type = 1; // v17n // v17c
318  else if (nRows == 16)
319  type = 2; // v17c
320  else if (nRows == 8)
321  type = 3; // v17n // v17c
322  else if (nRows == 4)
323  type = 4; // v17c - not used
324  } else if (nCols == 112) // FEB-7x1
325  {
326  if (nRows == 24)
327  type = 5; // v17c - not used
328  else if (nRows == 18)
329  type = 6; // v17c
330  else if (nRows == 12)
331  type = 7; // v17c
332  else if (nRows == 6)
333  type = 8; // v17c
334  } else if (nCols == 128) // FEB-8x1
335  {
336  if (nRows == 24)
337  type = 5; // v17a - not used
338  else if (nRows == 16)
339  type = 6; // v17a
340  else if (nRows == 12)
341  type = 6; // + v17o
342  else if (nRows == 8)
343  type = 7; // v17a
344  else if (nRows == 4)
345  type = 8; // v17a + v17o
346  } else if (nCols == 144) // FEB-9x1
347  {
348  if (nRows == 24)
349  type = 5; // v17n // v17l
350  else if (nRows == 16)
351  type = 6; // v17l
352  else if (nRows == 8)
353  type = 7; // v17n // v17l
354  else if (nRows == 4)
355  type = 8; // v17l
356  } else if (nCols == 160) // FEB-10x1
357  {
358  if (nRows == 48)
359  type = 5; // v17m
360  else if (nRows == 24)
361  type = 6; // v17m
362  else if (nRows == 12)
363  type = 7; // v17m
364  else if (nRows == 8)
365  type = 8; // v17m
366  }
367 
368  if (type == -1)
369  printf(
370  "ERROR::CbmTrdUtils:GetModuleType: nRows:%2i nCols:%3i\n", nRows, nCols);
371  return type;
372 }
373 
374 
375 void CbmTrdUtils::CreateLayerView(std::map<Int_t /*moduleAddress*/, TH1*>& Map,
376  CbmTrdParModDigi* fModuleInfo,
377  CbmTrdParSetDigi* fDigiPar,
378  const TString /*folder*/,
379  const TString pics,
380  const TString zAxisTitle,
381  const Double_t fmax,
382  const Double_t fmin,
383  const Bool_t logScale) {
384  TString title(""), name("");
385  //name.Form("_TH_%.2EGeV_",fTriggerThreshold);
386  TPaveText* text = nullptr;
387  std::map<Int_t, TH1*>::iterator MapIt;
388  InitColorVector(logScale, fmin, fmax);
389  TH2I* fLayerDummy = new TH2I("LayerDummy", "", 1, -600, 600, 1, -500, 500);
390  fLayerDummy->SetXTitle("x-coordinate [cm]");
391  fLayerDummy->SetYTitle("y-coordinate [cm]");
392  fLayerDummy->GetXaxis()->SetLabelSize(0.02);
393  fLayerDummy->GetYaxis()->SetLabelSize(0.02);
394  fLayerDummy->GetZaxis()->SetLabelSize(0.02);
395  fLayerDummy->GetXaxis()->SetTitleSize(0.02);
396  fLayerDummy->GetXaxis()->SetTitleOffset(1.5);
397  fLayerDummy->GetYaxis()->SetTitleSize(0.02);
398  fLayerDummy->GetYaxis()->SetTitleOffset(2);
399  fLayerDummy->GetZaxis()->SetTitleSize(0.02);
400  fLayerDummy->GetZaxis()->SetTitleOffset(-2);
401  fLayerDummy->SetStats(kFALSE);
402  fLayerDummy->SetContour(99);
403  fLayerDummy->Fill(0., 0., 0.);
404  std::map<Int_t, TCanvas*> fLayerMap;
405  std::map<Int_t, TCanvas*>::iterator fLayerMapIt;
406  /*
407  gDirectory->pwd();
408  if (!gDirectory->Cd(folder))
409  gDirectory->mkdir(folder);
410  gDirectory->Cd(folder);
411  */
412  for (MapIt = Map.begin(); MapIt != Map.end(); MapIt++) {
413  Double_t value = MapIt->second->GetMean(1);
414  Double_t valueE = MapIt->second->GetRMS(1);
415  fModuleInfo = (CbmTrdParModDigi*) fDigiPar->GetModulePar(MapIt->first);
416  Int_t Station = CbmTrdAddress::GetLayerId(MapIt->first) / 4
417  + 1; //fGeoHandler->GetStation(moduleId);
418  Int_t Layer = CbmTrdAddress::GetLayerId(MapIt->first) % 4
419  + 1; //fGeoHandler->GetLayer(moduleId);
420  Int_t combiId = 10 * Station + Layer;
421  if (fLayerMap.find(combiId) == fLayerMap.end()) {
422  title.Form("Station%i_Layer%i", Station, Layer);
423  fLayerMap[combiId] = new TCanvas(title, title, 1200, 1000);
424  fLayerDummy->SetZTitle(zAxisTitle);
425  fLayerDummy->GetZaxis()->SetRangeUser(fmin, fmax);
426  fLayerDummy->Draw("colz");
427  }
428  fLayerMap[combiId]->cd();
429 
430  // text = new TPaveText(fModuleInfo->GetX()-fModuleInfo->GetSizeX(),
431  // fModuleInfo->GetY()-fModuleInfo->GetSizeY(),
432  // fModuleInfo->GetX()+fModuleInfo->GetSizeX(),
433  // fModuleInfo->GetY()+fModuleInfo->GetSizeY());
434  // TODO should find a better way to get the position information for module
435  text =
436  new TPaveText(0, 0, fModuleInfo->GetSizeX(), fModuleInfo->GetSizeY());
437  text->SetFillStyle(1001);
438  text->SetLineColor(1);
439 
440  text->SetFillColor(GetColorCode(value));
441 
442  if (GetColorCode(value) < 65) text->SetTextColor(kWhite);
443  title.Form("%.1f#pm%.1f", value, valueE);
444  text->AddText(title);
445  text->Draw("same");
446  }
447  for (fLayerMapIt = fLayerMap.begin(); fLayerMapIt != fLayerMap.end();
448  fLayerMapIt++) {
449  //fLayerMapIt->second->Write("", TObject::kOverwrite);
450  title.Form("pics/TrdQa%s_S%i_L%i_%s.pdf",
451  pics.Data(),
452  fLayerMapIt->first / 10,
453  fLayerMapIt->first - (fLayerMapIt->first / 10) * 10,
454  name.Data());
455  fLayerMapIt->second->SaveAs(title);
456  title.ReplaceAll("pdf", "png");
457  fLayerMapIt->second->SaveAs(title);
458  }
459  for (MapIt = Map.begin(); MapIt != Map.end(); MapIt++) {
460  //MapIt->second->Write("", TObject::kOverwrite);
461  }
462  //gDirectory->Cd("..");
463 }
CbmTrdUtils::PdgToGeant
static Int_t PdgToGeant(Int_t PdgCode)
Definition: CbmTrdUtils.cxx:236
CbmTrdUtils::NiceTH2
void NiceTH2(TH2 *h, Int_t color, Int_t mStyle, Int_t mSize, TString xTitle, TString yTitle, TString zTitle)
Definition: CbmTrdUtils.cxx:153
CbmTrdUtils.h
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdParModDigi::GetNofRows
Int_t GetNofRows() const
Definition: CbmTrdParModDigi.cxx:340
CbmTrdUtils::NiceTH3
void NiceTH3(TH3 *h, Int_t color, Int_t mStyle, Int_t mSize, TString xTitle, TString yTitle, TString zTitle)
Definition: CbmTrdUtils.cxx:179
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdUtils::~CbmTrdUtils
virtual ~CbmTrdUtils()
Definition: CbmTrdUtils.cxx:36
CbmTrdUtils::fColors
std::vector< Int_t > fColors
Definition: CbmTrdUtils.h:182
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmTrdParModDigi::GetSizeX
Double_t GetSizeX() const
Definition: CbmTrdParModDigi.h:109
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:33
CbmTrdUtils::CreateRectangularPad
TPolyLine * CreateRectangularPad(Int_t column, Int_t row, Double_t value, Double_t min_range, Double_t max_range, Bool_t logScale)
Definition: CbmTrdUtils.cxx:101
h
Data class with information on a STS local track.
CbmTrdUtils::CbmTrdUtils
CbmTrdUtils()
Definition: CbmTrdUtils.cxx:35
CbmTrdParModDigi
Definition of chamber gain conversion for one TRD module.
Definition: CbmTrdParModDigi.h:14
CbmTrdUtils::InitColorVector
void InitColorVector(Bool_t logScale, Double_t min, Double_t max)
Definition: CbmTrdUtils.cxx:38
CbmTrdParModDigi.h
CbmTrdParSet::GetModulePar
virtual const CbmTrdParMod * GetModulePar(Int_t detId) const
Definition: CbmTrdParSet.cxx:45
CbmTrdUtils::NiceTH1
void NiceTH1(TH1 *h, Int_t color, Int_t mStyle, Int_t mSize, TString xTitle, TString yTitle)
Definition: CbmTrdUtils.cxx:129
CbmTrdParSetDigi.h
CbmTrdParModDigi::GetSizeY
Double_t GetSizeY() const
Definition: CbmTrdParModDigi.h:110
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdUtils::fZLevel
std::vector< Double_t > fZLevel
Definition: CbmTrdUtils.h:183
CbmTrdParSetDigi
Definition: CbmTrdParSetDigi.h:15
CbmTrdUtils::NiceLegend
void NiceLegend(TLegend *l)
Definition: CbmTrdUtils.cxx:229
CbmTrdUtils::NiceTProfile
void NiceTProfile(TProfile *h, Int_t color, Int_t mStyle, Int_t mSize, TString xTitle, TString yTitle)
Definition: CbmTrdUtils.cxx:205
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
CbmTrdUtils::Statusbar
void Statusbar(Int_t i, Int_t n)
Definition: CbmTrdUtils.cxx:291
CbmTrdUtils::CreateLayerView
void CreateLayerView(std::map< Int_t, TH1 * > &Map, CbmTrdParModDigi *fModuleInfo, CbmTrdParSetDigi *fDigiPar, const TString folder, const TString pics, const TString zAxisTitle, const Double_t fmax, const Double_t fmin, const Bool_t logScale)
Definition: CbmTrdUtils.cxx:375
CbmTrdUtils::GetColorCode
Int_t GetColorCode(Double_t value)
Definition: CbmTrdUtils.cxx:54
CbmTrdParModDigi::GetNofColumns
Int_t GetNofColumns() const
Definition: CbmTrdParModDigi.cxx:321
CbmTrdUtils::GetModuleType
Int_t GetModuleType(Int_t moduleAddress, CbmTrdParModDigi *fModuleInfo, CbmTrdParSetDigi *fDigiPar)
Definition: CbmTrdUtils.cxx:300
CbmTrdUtils::CreateTriangularPad
TPolyLine * CreateTriangularPad(Int_t column, Int_t row, Double_t value, Double_t min_range, Double_t max_range, Bool_t logScale)
Definition: CbmTrdUtils.cxx:66