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