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