2 author: Ionut-Cristian Arsene
3 email: i.c.arsene@cern.ch
5 Macro to plot trends from an input root file containing a tree.
7 DrawTrendingTRDQA("trendingFile.root")
9 How to add a new trending plot:
10 1. If a new trending variables needs to be added, its name must be added
11 in the gTrendNames array and also a corresponding entry in the Trends enumeration.
12 The name must match the name of its corresponding branch in the trending tree.
13 If no new trending variable is added, proceed to step 2
14 2. Define the needed histogram in DefineHistograms()
15 2.1 If just a plot of the trending variable as a function of run number is needed, then
16 a) define the histogram,
17 b) set the uniqueID for the TH1D (with the corresponding Trends index needed to be filled)
18 c) set the uniqueID for the y axis which will represent the variable used as error bar (optional)
19 d) add it to the output list
20 The histogram will then be filled and drawn automatically.
21 2.2 If the plot is more complicated then defined at 2.1 (e.g. use quantities derived from the existing trends,
22 correlations between various trends, etc.):
23 a) define the histogram
24 b) add it to the output list
25 c) fill the histogram in the FillHistograms() function in the section for exceptions.
26 d) drawing will be done automatically
30 // Trending variable indices
32 kTPCTRDmatchEffPosAll=0, kTPCTRDmatchEffPosAllErr,
33 kTPCTRDmatchEffNegAll, kTPCTRDmatchEffNegAllErr,
34 kTRDTOFmatchEffPosAll, kTRDTOFmatchEffPosAllErr,
35 kTRDTOFmatchEffNegAll, kTRDTOFmatchEffNegAllErr,
36 kAvTRDtrkltsPerTrackAll, kAvTRDtrkltsPerTrackAllErr,
37 kAvNclsPerTrackAll, kAvNclsPerTrackAllErr,
38 kPHplateauHeight, kPHplateauHeightErr,
39 kPHplateauSlope, kPHplateauSlopeErr,
40 kQtotLandauMPV1GeVAll, kQtotLandauWidth1GeVAll,
41 kPHplateauHeightAbsolute, kPHplateauHeightErrAbsolute,
42 kPHplateauSlopeAbsolute, kPHplateauSlopeErrAbsolute,
43 kQtotLandauMPV1GeVAllAbsolute, kQtotLandauWidth1GeVAllAbsolute,
44 kTRDcheckDET_NTracksEvent, kTRDcheckDET_NTracksEventRMS,
45 kTRDcheckDET_NTracksSector,
46 kTRDcheckDET_NClustersTrack, kTRDcheckDET_NClustersTrackRMS,
47 kTRDcheckDET_NClustersTracklet, kTRDcheckDET_NClustersTrackletRMS,
48 kTRDcheckDET_NTrackletsTrack, kTRDcheckDET_NTrackletsTrackRMS,
49 kTRDcheckDET_ChargeCluster, kTRDcheckDET_ChargeClusterRMS,
50 kTRDcheckDET_ChargeTracklet, kTRDcheckDET_ChargeTrackletRMS,
51 kTRDcheckDET_PHplateau, kTRDcheckDET_PHslope, kTRDcheckDET_PHamplificationPeak,
53 kMeanGainFactor, kRmsGainFactor,
55 kMeanVdrift, kRmsVdrift,
56 kBeamIntensityA, kBeamIntensityC,
61 // Trending variable names
62 // These names must match the names of the branches in the trending tree
63 // since branches are detected automatically based on the strings in this array
64 TString gTrendNames[kNtrends] = {
65 "TPCTRDmatchEffPosAll", "TPCTRDmatchEffPosAllErr",
66 "TPCTRDmatchEffNegAll", "TPCTRDmatchEffNegAllErr",
67 "TRDTOFmatchEffPosAll", "TRDTOFmatchEffPosAllErr",
68 "TRDTOFmatchEffNegAll", "TRDTOFmatchEffNegAllErr",
69 "AvTRDtrkltsPerTrackAll", "AvTRDtrkltsPerTrackAllErr",
70 "AvNclsPerTrackAll", "AvNclsPerTrackAllErr",
71 "PHplateauHeight", "PHplateauHeightErr",
72 "PHplateauSlope", "PHplateauSlopeErr",
73 "QtotLandauMPV1GeVAll", "QtotLandauWidth1GeVAll",
74 "PHplateauHeightAbsolute", "PHplateauHeightErrAbsolute",
75 "PHplateauSlopeAbsolute", "PHplateauSlopeErrAbsolute",
76 "QtotLandauMPV1GeVAllAbsolute", "QtotLandauWidth1GeVAllAbsolute",
77 "TRDcheckDET_NTracksEvent", "TRDcheckDET_NTracksEventRMS",
78 "TRDcheckDET_NTracksSector",
79 "TRDcheckDET_NClustersTrack", "TRDcheckDET_NClustersTrackRMS",
80 "TRDcheckDET_NClustersTracklet", "TRDcheckDET_NClustersTrackletRMS",
81 "TRDcheckDET_NTrackletsTrack", "TRDcheckDET_NTrackletsTrackRMS",
82 "TRDcheckDET_ChargeCluster", "TRDcheckDET_ChargeClusterRMS",
83 "TRDcheckDET_ChargeTracklet", "TRDcheckDET_ChargeTrackletRMS",
84 "TRDcheckDET_PHplateau", "TRDcheckDET_PHslope", "TRDcheckDET_PHamplificationPeak",
86 "meanGainFactor", "rmsGainFactor",
88 "meanVdrift", "rmsVdrift",
89 "beamIntensityA", "beamIntensityC"
94 void DefineHistograms(TList* outList, Int_t nRuns);
95 void FillHistograms(Int_t irun, TList* hList, Double_t* values, Bool_t* branchFound);
96 void DrawAllHistograms(TList* hList);
97 void SetDrawStyle(TObject* obj, TString drawOption="E1",
98 Int_t markerStyle=24, Int_t markerColor=4, Double_t markerSize=2.0,
99 Int_t lineStyle=1, Int_t lineColor=4, Double_t lineWidth=2.0);
101 //________________________________________________________________________
102 void DrawTrendingTRDQA(TString trendingFilename="trending.root") {
104 // Draw the TRD QA trending
106 TFile* trendingFile = TFile::Open(trendingFilename.Data(), "READ");
107 TTree* tree = (TTree*)trendingFile->Get("trending");
109 cout << "E-DrawTrendingTRDQA.C: Cannot get the trending tree!" << endl;
114 tree->SetBranchAddress("run",&run);
116 // Array which will hold the information from the tree
117 // Note that its size is kNtrends+1. The extra element is reserved for the run number and
118 // is always located at the back of the array (element at index kNtrends)
119 Double_t trends[kNtrends+1]={0.0};
121 // Detect branches in the tree and assign an address
122 Bool_t branchFound[kNtrends]; for(Int_t i=0;i<kNtrends;++i) branchFound[i]=kFALSE;
123 for(Int_t i=0;i<kNtrends;++i) {
124 TBranch* branch = tree->FindBranch(gTrendNames[i].Data());
125 if(!branch) continue;
126 branch->SetAddress(&trends[i]);
127 branchFound[i]=kTRUE;
130 // Define histograms and add them to a list
131 Int_t nRuns = tree->GetEntries();
133 histList.SetOwner(kTRUE);
134 DefineHistograms(&histList, nRuns);
136 // loop over all entries in the tree (one entry per run)
137 for(Int_t i=0; i<nRuns; ++i) {
139 trends[kNtrends] = run;
140 FillHistograms(i, &histList, trends, branchFound);
141 } // end loop over runs
143 // Draw trending histograms
144 // Here the canvases with one drawn histogram each are saved as PNG files.
145 // The names of the PNG files use the name of the histogram
146 DrawAllHistograms(&histList);
148 // save histograms into a root file
149 TFile* save=new TFile("PeriodTRDQAtrends.hist.root", "RECREATE");
155 //________________________________________________________________________
156 void DrawAllHistograms(TList* l) {
158 // Draw all histograms in the list
162 for(Int_t i=0; i<l->GetEntries(); ++i) {
164 c=new TCanvas(Form("canvas_%s",o->GetName()), Form("%s", o->GetName()), 800.,600.);
165 c->SetLeftMargin(0.15); c->SetBottomMargin(0.15); c->SetTopMargin(0.08); c->SetRightMargin(0.03);
166 ((TH1*)o)->SetStats(kFALSE);
169 if(TString(o->GetName()).Contains("BeamIntensity")) c->SetLogy();
172 c->Print(Form("%s.png", TString(o->GetName()).Remove(0,1).Data()));
178 //________________________________________________________________________
179 void FillHistograms(Int_t irun, TList* l, Double_t* v, Bool_t* branchFound) {
181 // Fill all histograms in the list
184 for(Int_t i=0; i<l->GetEntries(); ++i) {
186 if(TString(o->IsA()->GetName()).Contains("TH1D")) {
188 h1->GetXaxis()->SetBinLabel(irun+1, Form("%.0f", v[kNtrends]));
190 // Deal with the exceptions (no assigned space in the Trends enum)
191 if(TString(h1->GetName()).Contains("hTPCTRDmatchChargeAsymm")) {
192 if(branchFound[kTPCTRDmatchEffPosAll] && branchFound[kTPCTRDmatchEffNegAll]) {
193 Double_t p=v[kTPCTRDmatchEffPosAll], m=v[kTPCTRDmatchEffNegAll],
194 dp=v[kTPCTRDmatchEffPosAllErr], dm=v[kTPCTRDmatchEffNegAllErr];
195 if(TMath::Abs(p+m)>1.0e-6) {
196 h1->SetBinContent(irun+1, 100.0*2.0*(p-m)/(p+m));
197 h1->SetBinError(irun+1, 100.0*4.0*TMath::Sqrt(m*m*dp*dp+p*p*dm*dm)/(p+m)/(p+m));
202 if(TString(h1->GetName()).Contains("hTRDTOFmatchChargeAsymm")) {
203 if(branchFound[kTRDTOFmatchEffPosAll] && branchFound[kTRDTOFmatchEffNegAll]) {
204 Double_t p=v[kTRDTOFmatchEffPosAll], m=v[kTRDTOFmatchEffNegAll],
205 dp=v[kTRDTOFmatchEffPosAllErr], dm=v[kTRDTOFmatchEffNegAllErr];
206 if(TMath::Abs(p+m)>1.0e-6) {
207 h1->SetBinContent(irun+1, 100.0*2.0*(p-m)/(p+m));
208 h1->SetBinError(irun+1, 100.0*4.0*TMath::Sqrt(m*m*dp*dp+p*p*dm*dm)/(p+m)/(p+m));
214 // Fill the rest of the histograms
215 Int_t var = h1->GetUniqueID()-1;
216 Int_t errY = h1->GetYaxis()->GetUniqueID()-1;
217 if(var>=0 && branchFound[var])
218 h1->SetBinContent(irun+1, v[var]);
219 if(errY>=0 && branchFound[errY]) h1->SetBinError(irun+1, v[errY]);
222 } // end loop over histograms
226 //________________________________________________________________________
227 void DefineHistograms(TList* outList, Int_t nRuns) {
229 // Define trending histograms
231 TH1D* hTPCTRDmatchPos=new TH1D("hTPCTRDmatchPos","TPC-TRD matching efficiency at pt=1GeV/c, positive tracks;run;matching efficiency",
233 hTPCTRDmatchPos->SetUniqueID(kTPCTRDmatchEffPosAll+1); hTPCTRDmatchPos->GetYaxis()->SetUniqueID(kTPCTRDmatchEffPosAllErr+1);
234 SetDrawStyle(hTPCTRDmatchPos); outList->Add(hTPCTRDmatchPos);
236 TH1D* hTPCTRDmatchNeg=new TH1D("hTPCTRDmatchNeg","TPC-TRD matching efficiency at pt=1GeV/c, negative tracks;run;matching efficiency",
238 hTPCTRDmatchNeg->SetUniqueID(kTPCTRDmatchEffNegAll+1); hTPCTRDmatchNeg->GetYaxis()->SetUniqueID(kTPCTRDmatchEffNegAllErr+1);
239 SetDrawStyle(hTPCTRDmatchNeg); outList->Add(hTPCTRDmatchNeg);
241 TH1D* hTPCTRDmatchChargeAsymm=new TH1D("hTPCTRDmatchChargeAsymm","TPC-TRD matching efficiency at pt=1GeV/c, charge asymmetry;run;percents",
243 SetDrawStyle(hTPCTRDmatchChargeAsymm); outList->Add(hTPCTRDmatchChargeAsymm);
245 TH1D* hTRDTOFmatchPos=new TH1D("hTRDTOFmatchPos","TRD-TOF matching efficiency at pt=1GeV/c, positive tracks;run;matching efficiency",
247 hTRDTOFmatchPos->SetUniqueID(kTRDTOFmatchEffPosAll+1); hTRDTOFmatchPos->GetYaxis()->SetUniqueID(kTRDTOFmatchEffPosAllErr+1);
248 SetDrawStyle(hTRDTOFmatchPos); outList->Add(hTRDTOFmatchPos);
250 TH1D* hTRDTOFmatchNeg=new TH1D("hTRDTOFmatchNeg","TRD-TOF matching efficiency at pt=1GeV/c, negative tracks;run;matching efficiency",
252 hTRDTOFmatchNeg->SetUniqueID(kTRDTOFmatchEffNegAll+1); hTRDTOFmatchNeg->GetYaxis()->SetUniqueID(kTRDTOFmatchEffNegAllErr+1);
253 SetDrawStyle(hTRDTOFmatchNeg); outList->Add(hTRDTOFmatchNeg);
255 TH1D* hTRDTOFmatchChargeAsymm=new TH1D("hTRDTOFmatchChargeAsymm","TRD-TOF matching efficiency at pt=1GeV/c, charge asymmetry;run;percents",
257 SetDrawStyle(hTRDTOFmatchChargeAsymm); outList->Add(hTRDTOFmatchChargeAsymm);
259 TH1D* hTrkltsPerTrack=new TH1D("hTrkltsPerTrack","Average no. tracklets per TRD track at pt=1GeV/c;run;#tracklets",
261 hTrkltsPerTrack->SetUniqueID(kAvTRDtrkltsPerTrackAll+1); hTrkltsPerTrack->GetYaxis()->SetUniqueID(kAvTRDtrkltsPerTrackAllErr+1);
262 SetDrawStyle(hTrkltsPerTrack); outList->Add(hTrkltsPerTrack);
264 TH1D* hClsPerTrack=new TH1D("hClsPerTrack","Average no. clusters per TRD track at pt=1GeV/c;run;#tracklets",
266 SetDrawStyle(hClsPerTrack); outList->Add(hClsPerTrack);
267 hClsPerTrack->SetUniqueID(kAvNclsPerTrackAll+1); hClsPerTrack->GetYaxis()->SetUniqueID(kAvNclsPerTrackAllErr+1);
269 TH1D* hPHplateauHeight=new TH1D("hPHplateauHeight","PH plateau height from slices;run;PH",
271 hPHplateauHeight->SetUniqueID(kPHplateauHeightAbsolute+1); hPHplateauHeight->GetYaxis()->SetUniqueID(kPHplateauHeightErrAbsolute+1);
272 SetDrawStyle(hPHplateauHeight); outList->Add(hPHplateauHeight);
274 TH1D* hPHplateauSlope=new TH1D("hPHplateauSlope","PH plateau slope from slices;run;slope",
276 hPHplateauSlope->SetUniqueID(kPHplateauSlopeAbsolute+1); hPHplateauSlope->GetYaxis()->SetUniqueID(kPHplateauSlopeErrAbsolute+1);
277 SetDrawStyle(hPHplateauSlope); outList->Add(hPHplateauSlope);
279 TH1D* hQtotLandauMPV=new TH1D("hQtotLandauMPV","Landau MPV for the tracklet charge distribution (Q_{tot}) ;run;Q_{tot}",
281 hQtotLandauMPV->SetUniqueID(kQtotLandauMPV1GeVAllAbsolute+1);
282 SetDrawStyle(hQtotLandauMPV); outList->Add(hQtotLandauMPV);
284 TH1D* hQtotLandauWidth=new TH1D("hQtotLandauWidth","Landau width for the tracklet charge distribution (Q_{tot});run;Q_{tot}",
286 hQtotLandauWidth->SetUniqueID(kQtotLandauWidth1GeVAllAbsolute+1);
287 SetDrawStyle(hQtotLandauWidth); outList->Add(hQtotLandauWidth);
289 TH1D* hNTracksPerEvent_DET=new TH1D("hNTracksPerEvent_DET", "Number of TRD tracks per event, (TRDcheckDET);run;#tracks",
291 hNTracksPerEvent_DET->SetUniqueID(kTRDcheckDET_NTracksEvent+1); hNTracksPerEvent_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_NTracksEventRMS+1);
292 SetDrawStyle(hNTracksPerEvent_DET); outList->Add(hNTracksPerEvent_DET);
294 TH1D* hNTracksPerSector_DET=new TH1D("hNTracksPerSector_DET", "Number of TRD tracks per sector (TRDcheckDET);run;#tracks",
296 hNTracksPerSector_DET->SetUniqueID(kTRDcheckDET_NTracksSector+1);
297 SetDrawStyle(hNTracksPerSector_DET); outList->Add(hNTracksPerSector_DET);
299 TH1D* hNClustersPerTrack_DET=new TH1D("hNClustersPerTrack_DET", "Number of clusters per track (TRDcheckDET);run;#clusters",
301 hNClustersPerTrack_DET->SetUniqueID(kTRDcheckDET_NClustersTrack+1); hNClustersPerTrack_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_NClustersTrackRMS+1);
302 SetDrawStyle(hNClustersPerTrack_DET); outList->Add(hNClustersPerTrack_DET);
304 TH1D* hNClustersPerTracklet_DET=new TH1D("hNClustersPerTracklet_DET", "Number of clusters per tracklet (TRDcheckDET);run;#clusters",
306 hNClustersPerTracklet_DET->SetUniqueID(kTRDcheckDET_NClustersTracklet+1); hNClustersPerTracklet_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_NClustersTrackletRMS+1);
307 SetDrawStyle(hNClustersPerTracklet_DET); outList->Add(hNClustersPerTracklet_DET);
309 TH1D* hNTrackletsPerTrack_DET=new TH1D("hNTrackletsPerTrack_DET", "Number of tracklets per track (TRDcheckDET);run;#tracklets",
311 hNTrackletsPerTrack_DET->SetUniqueID(kTRDcheckDET_NTrackletsTrack+1); hNTrackletsPerTrack_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_NTrackletsTrackRMS+1);
312 SetDrawStyle(hNTrackletsPerTrack_DET); outList->Add(hNTrackletsPerTrack_DET);
314 TH1D* hClusterCharge_DET=new TH1D("hClusterCharge_DET", "Cluster charge (TRDcheckDET);run;#charge",
316 hClusterCharge_DET->SetUniqueID(kTRDcheckDET_ChargeCluster+1); hClusterCharge_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_ChargeClusterRMS+1);
317 SetDrawStyle(hClusterCharge_DET); outList->Add(hClusterCharge_DET);
319 TH1D* hTrackletCharge_DET=new TH1D("hTrackletCharge_DET", "Tracklet charge (TRDcheckDET);run;#charge",
321 hTrackletCharge_DET->SetUniqueID(kTRDcheckDET_ChargeTracklet+1); hTrackletCharge_DET->GetYaxis()->SetUniqueID(kTRDcheckDET_ChargeTrackletRMS+1);
322 SetDrawStyle(hTrackletCharge_DET); outList->Add(hTrackletCharge_DET);
324 TH1D* hPHplateau_DET=new TH1D("hPHplateau_DET", "PH plateau (TRDcheckDET);run;#charge",
326 hPHplateau_DET->SetUniqueID(kTRDcheckDET_PHplateau+1);
327 SetDrawStyle(hPHplateau_DET); outList->Add(hPHplateau_DET);
329 TH1D* hPHslope_DET=new TH1D("hPHslope_DET", "PH slope (TRDcheckDET);run;#charge/timebin",
331 hPHslope_DET->SetUniqueID(kTRDcheckDET_PHslope+1);
332 SetDrawStyle(hPHslope_DET); outList->Add(hPHslope_DET);
334 TH1D* hPHamplifPeak_DET=new TH1D("hPHamplifPeak_DET", "PH amplification peak position (TRDcheckDET);run;#timebin",
336 hPHamplifPeak_DET->SetUniqueID(kTRDcheckDET_PHamplificationPeak+1);
337 SetDrawStyle(hPHamplifPeak_DET); outList->Add(hPHamplifPeak_DET);
339 TH1D* hMeanExB=new TH1D("hMeanExB", "Mean ExB over all chambers from OCDB;run;ExB correction",
341 hMeanExB->SetUniqueID(kMeanExB+1); hMeanExB->GetYaxis()->SetUniqueID(kRmsExB+1);
342 SetDrawStyle(hMeanExB); outList->Add(hMeanExB);
344 TH1D* hMeanGainFactor=new TH1D("hMeanGainFactor", "Mean gain factor over all chambers from OCDB;run;gain factor",
346 hMeanGainFactor->SetUniqueID(kMeanGainFactor+1); hMeanGainFactor->GetYaxis()->SetUniqueID(kRmsGainFactor+1);
347 SetDrawStyle(hMeanGainFactor); outList->Add(hMeanGainFactor);
349 TH1D* hMeanT0=new TH1D("hMeanT0", "Mean T0 over all chambers from OCDB;run;T0",
351 hMeanT0->SetUniqueID(kMeanT0+1); hMeanT0->GetYaxis()->SetUniqueID(kRmsT0+1);
352 SetDrawStyle(hMeanT0); outList->Add(hMeanT0);
354 TH1D* hMeanVdrift=new TH1D("hMeanVdrift", "Mean drift velocity over all chambers from OCDB;run;drift velocity",
356 hMeanVdrift->SetUniqueID(kMeanVdrift+1); hMeanVdrift->GetYaxis()->SetUniqueID(kRmsVdrift+1);
357 SetDrawStyle(hMeanVdrift); outList->Add(hMeanVdrift);
359 TH1D* hBeamIntensityA=new TH1D("hBeamIntensityA", "Beam A intensity from OCDB;run;beam intensity",
361 hBeamIntensityA->SetUniqueID(kBeamIntensityA+1);
362 SetDrawStyle(hBeamIntensityA); outList->Add(hBeamIntensityA);
364 TH1D* hBeamIntensityC=new TH1D("hBeamIntensityC", "Beam C intensity from OCDB;run;beam intensity",
366 hBeamIntensityC->SetUniqueID(kBeamIntensityC+1);
367 SetDrawStyle(hBeamIntensityC); outList->Add(hBeamIntensityC);
371 //________________________________________________________________________
372 void SetDrawStyle(TObject* obj,
373 TString drawOption /*="E1"*/,
374 Int_t markerStyle /*=24*/, Int_t markerColor /*=4*/, Double_t markerSize /*=2.0*/,
375 Int_t lineStyle /*=1*/, Int_t lineColor /*=4*/, Double_t lineWidth /*=2.0*/) {
379 if(TString(obj->IsA()->GetName()).Contains("TH1D")) {
381 o->SetDrawOption(drawOption.Data());
382 o->SetMarkerStyle(markerStyle);
383 o->SetMarkerColor(markerColor);
384 o->SetMarkerSize(markerSize);
385 o->SetLineStyle(lineStyle);
386 o->SetLineColor(lineColor);
387 o->SetLineWidth(lineWidth);
388 o->GetXaxis()->SetTitleOffset(1.6);
389 o->GetYaxis()->SetNdivisions(507);
390 o->GetXaxis()->SetLabelFont(42);
391 o->GetXaxis()->SetTitleFont(42);
392 o->GetYaxis()->SetLabelFont(42);
393 o->GetYaxis()->SetTitleFont(42);