]>
Commit | Line | Data |
---|---|---|
97a28f97 | 1 | #if !defined(__CINT__) || defined(__MAKECINT__) |
2 | #include <TSystem.h> | |
3 | #include <TStyle.h> | |
4 | #include <TROOT.h> | |
5 | #include <Riostream.h> | |
6 | #include <TFile.h> | |
7 | #include <TH1F.h> | |
8 | #include <TCanvas.h> | |
9 | #include <TGraphErrors.h> | |
10 | #include <TLegend.h> | |
11 | #include <TTree.h> | |
12 | #include <TTreeFormula.h> | |
13 | #include <TEventList.h> | |
14 | #include <TObjString.h> | |
15 | #include <TList.h> | |
16 | #include <TCut.h> | |
17 | #include <TError.h> | |
18 | #include <TDatime.h> | |
19 | #include <TPRegexp.h> | |
20 | #include <TInterpreter.h> | |
21 | #include <TGaxis.h> | |
22 | #endif | |
23 | ||
24 | // This macro produces periodLevelQA for EMCAL from a trending tree | |
25 | // Authors: A. Mas, M. Germain & A.Shabetai SUBATECH | |
26 | // re-factored for automatic QA processing and trending A. A.SHABETAI | |
27 | ||
28 | int PlotEMCALQATrendingTree(TTree* tree, const char* trig,TFile* fout,Bool_t SavePlots,TString expr); | |
29 | TH1F* ZoomFromTree(TH1F* h, TTree* atree, Int_t n, const char* aVar, UShort_t aScaleFactor=1); | |
30 | Double_t GetTreeMinimum(TTree* aTree, Int_t n, const char* columname); | |
31 | Double_t GetTreeMaximum(TTree* aTree, Int_t n, const char* columname); | |
32 | ||
33 | TString QAPATH; | |
34 | TString QAPATHF= "./"; | |
35 | ||
36 | //-------------------------------------------------------------------------------------------------------------------- | |
37 | int NextInt(int newMax=0) | |
38 | { | |
39 | ||
40 | static int N=0; | |
41 | static int nMax=1; | |
42 | ||
43 | if(newMax) {nMax = newMax; N=0; return 0;} | |
44 | if (N == nMax) N=0; | |
45 | N = N +1; | |
46 | return N; | |
47 | ||
48 | } | |
49 | ||
50 | //-------------------------------------------------------------------------------------------------------------------- | |
51 | int PlotEMCALQATrendingTree(const char* filename="trending.root",Bool_t SavePlots=0, TString expr ="", TString fTrigger="") | |
52 | { | |
53 | ||
54 | QAPATH = TString(gSystem->Getenv("QAPATH")); | |
55 | if(QAPATH.IsNull()) QAPATH = QAPATHF; | |
56 | ||
57 | Int_t ret=0; | |
58 | TFile* f = TFile::Open(filename); | |
59 | if(!f) { return -1;} | |
60 | TTree* tree = (TTree*)f->Get("trending"); | |
61 | if (! tree) {Error("PlotEMCALQATrendingTree","No Tree found!"); return -1;} | |
62 | TFile* fout = new TFile(Form("%s/trendingPlots.root",QAPATH.Data()),"RECREATE"); | |
63 | ||
64 | TList* TriggersList = new TList(); | |
65 | if (fTrigger=="") | |
66 | { | |
67 | tree->Draw("fTrigger","","goff"); | |
68 | const char* obj; | |
69 | for(Int_t i = 0 ; i < tree->GetSelectedRows() ; i++){ | |
70 | tree->GetEntry(i); | |
71 | obj = tree->GetVar1()->PrintValue(0); | |
72 | if(! TriggersList->FindObject(obj)) {TriggersList->Add(new TObjString(obj));} | |
73 | } | |
74 | } | |
75 | else | |
76 | { | |
77 | if(!fTrigger.Contains("QA")) {fTrigger = "CaloQA_" + fTrigger;} | |
78 | TriggersList->Add(new TObjString(fTrigger.Data())); | |
79 | } | |
80 | TIter next(TriggersList); | |
81 | TObject* obj1; | |
82 | while ((obj1 = next())) | |
83 | { | |
84 | ret = PlotEMCALQATrendingTree(tree,obj1->GetName(),fout,SavePlots,expr); | |
85 | } | |
86 | ||
87 | f->Close(); | |
88 | return ret; | |
89 | ||
90 | } | |
91 | ||
92 | //-------------------------------------------------------------------------------------------------------------------- | |
93 | int PlotEMCALQATrendingTree(TTree* tree, const char* Trig, TFile* fout, Bool_t SavePlots,TString Expr) | |
94 | { | |
95 | ||
96 | TCut trig = Form("fTrigger==\"%s\"",Trig); | |
97 | TCut NotZero = TCut("Nevent>0."); | |
98 | TCut select = trig; | |
99 | ||
100 | if (Expr.Contains(".C")) | |
101 | { | |
102 | Info("PlotEMCALQATrendingTree",Form("Additional selections from %s: ", Expr.Data())); | |
103 | gInterpreter->ExecuteMacro(Expr.Data()); | |
104 | select = trig + expr; | |
105 | } | |
106 | ||
107 | if (! tree) {Error("PlotEMCALQATrendingTree","No Tree found!"); return -1;} | |
108 | select.Print(); | |
109 | int CurN=0; | |
110 | TString* fCalorimeter; | |
111 | TString* period; | |
112 | TString* pass; | |
113 | TString* fTrigger; | |
114 | TString* system; | |
115 | TDatime* dtime; | |
116 | ||
117 | tree->SetBranchAddress("fDate",&dtime); | |
118 | tree->SetBranchAddress("nSM",&CurN); | |
119 | tree->SetBranchAddress("fCalorimeter",&fCalorimeter); | |
120 | tree->SetBranchAddress("system",&system); | |
121 | tree->SetBranchAddress("period",&period); | |
122 | tree->SetBranchAddress("pass",&pass); | |
123 | tree->SetBranchAddress("fTrigger",&fTrigger); | |
124 | ||
125 | ||
126 | tree->SetEventList(0); | |
127 | tree->Draw(">>elist",select); | |
128 | tree->Draw(">>listNotZero",select+NotZero); | |
129 | TEventList* listNotZero = (TEventList*)gDirectory->Get("listNotZero"); | |
130 | TEventList* elist = (TEventList*)gDirectory->Get("elist"); | |
131 | tree->SetEventList(elist); | |
132 | if(! elist->GetN()) { Error("PlotEMCALQATrendingTree","The current selection doess not match any entry!"); return -2; } | |
133 | CurN = tree->GetMinimum("nSM"); | |
134 | const Int_t n = CurN; | |
135 | tree->GetEntry(elist->GetEntry(0)); | |
136 | ||
137 | TGraphErrors* AverNclustersSM[n]; | |
138 | TGraphErrors* AverNcellsPerClusterSM[n]; | |
139 | TGraphErrors* AverESM[n]; | |
140 | TGraphErrors* AverMeanSM[n]; | |
141 | TGraphErrors* AverWidthSM[n]; | |
142 | TGraphErrors* AverNpi0SM[n]; | |
143 | ||
144 | // --------------------------------- plots ------------------------------ | |
145 | ||
146 | TString base = QAPATH + period->Data() + "_" + pass->Data() + "_"; | |
147 | TPRegexp r("_\\w+"); | |
148 | ||
149 | TString ClusterAverages ; ClusterAverages = base + "ClAvNew" + (*fTrigger)(r) + ".png"; | |
150 | TString Entries; Entries = base + "Nentries" + (*fTrigger)(r) + ".png"; | |
151 | TString ClusterAveragesEnergy; ClusterAveragesEnergy = base + "ClAvEne" + (*fTrigger)(r) + ".png"; | |
152 | TString ClusterAveragesEnergy2; ClusterAveragesEnergy2 = base + "ClAvEne" + (*fTrigger)(r) + ".pdf"; | |
153 | TString ClusterAveragesEntries; ClusterAveragesEntries = base + "ClAvEnt" + (*fTrigger)(r) + ".png"; | |
154 | TString ClusterAveragesEntries2; ClusterAveragesEntries2 = base + "ClAvEnt" + (*fTrigger)(r) + ".pdf"; | |
155 | TString ClusterAveragesCells; ClusterAveragesCells = base + "ClAvCells" + (*fTrigger)(r) + ".png"; | |
156 | TString ClusterAveragesCells2; ClusterAveragesCells2 = base + "ClAvCells" + (*fTrigger)(r) + ".pdf"; | |
157 | TString Pi0Entries; Pi0Entries = base + "Pi0Entries" + (*fTrigger)(r) + ".png"; | |
158 | TString Pi0Entries2; Pi0Entries2 = base + "Pi0Entries" + (*fTrigger)(r) + ".pdf"; | |
159 | TString Pi0Mass; Pi0Mass = base + "Pi0Mass" + (*fTrigger)(r) + ".png"; | |
160 | TString Pi0Mass2; Pi0Mass2 = base + "Pi0Mass" + (*fTrigger)(r) + ".pdf"; | |
161 | TString Pi0Width; Pi0Width = base + "Pi0Width" + (*fTrigger)(r) + ".png"; | |
162 | TString Pi0Width2; Pi0Width2 = base + "Pi0Width" + (*fTrigger)(r) + ".pdf"; | |
163 | ||
164 | ||
165 | int nEmptyRuns = tree->Draw("run","Nevent==0","goff"); | |
166 | if (nEmptyRuns && (nEmptyRuns != -1)) { | |
167 | Info("PlotEMCALQATrendingTree",Form("The following %i runs are empty for trigger %s:",nEmptyRuns,Trig)); | |
168 | for(Int_t i = 0 ; i < nEmptyRuns ; i++){ | |
169 | cout<<tree->GetV1()[i]<<endl; | |
170 | } | |
171 | } | |
172 | ||
173 | int nRun = tree->Draw("run","","goff"); | |
174 | NextInt(nRun); | |
175 | TH1F* h1 = new TH1F("h1", "dummy", nRun, 0., nRun+0.5); | |
176 | TGaxis::SetMaxDigits(3); | |
177 | h1->SetTitle("") ; | |
178 | h1->SetStats(kFALSE) ; | |
179 | h1->SetAxisRange(0, nRun, "X") ; | |
180 | h1->GetXaxis()->SetTitle("RUN Index"); | |
181 | h1->GetXaxis()->SetTitleOffset(1.86); | |
182 | h1->GetXaxis()->SetTitleSize(0.03); | |
183 | ||
184 | for(Int_t i = 0 ; i < nRun ; i++){ | |
185 | TString label = " "; | |
186 | label+=tree->GetV1()[i]; | |
187 | h1->GetXaxis()->SetBinLabel(i+1,label.Data()); | |
188 | h1->GetXaxis()->LabelsOption("v"); | |
189 | } | |
190 | ||
191 | //number of events | |
192 | TCanvas* c1 = new TCanvas("Nevents","Nb of events", 1000, 500); | |
193 | c1->SetFillColor(0); | |
194 | c1->SetBorderSize(0); | |
195 | c1->SetFrameBorderMode(0); | |
196 | gStyle->SetOptStat(0); | |
197 | gPad->SetLeftMargin(0.08); | |
198 | gPad->SetRightMargin(0.02); | |
199 | c1->SetGrid(); | |
200 | tree->Draw("NextInt():Nevent","","goff"); | |
201 | h1->GetYaxis()->SetTitle("N_{events}"); | |
202 | ZoomFromTree(h1,tree,n,"Nevent",2); | |
203 | if (h1->GetMinimum() > 0.) {c1->SetLogy();} | |
204 | h1->Draw(); | |
205 | ||
206 | TGraph* Nevents = new TGraph(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2()); | |
207 | Nevents->SetMarkerStyle(20); | |
208 | Nevents->SetMarkerColor(1); | |
209 | Nevents->SetLineColor(2); | |
210 | Nevents->Draw("same lp") ; | |
211 | ||
212 | c1->Update(); | |
213 | if(SavePlots) c1->SaveAs(Entries); | |
214 | ||
215 | TCanvas* c2 = new TCanvas("ClusterAveragesEvents", "Mean Nb of Cluster per Event", 1000, 500); | |
216 | c2->SetFillColor(0); | |
217 | c2->SetBorderSize(0); | |
218 | c2->SetFrameBorderMode(0); | |
219 | c2->SetGrid(); | |
220 | ||
221 | gPad->SetLeftMargin(0.08); | |
222 | gPad->SetRightMargin(0.02); | |
223 | gPad->SetGrid(); | |
224 | ||
225 | TH1F* h2 = (TH1F*)h1->Clone(""); | |
226 | h2->GetYaxis()->SetTitle("<N_{clusters}>/event"); | |
227 | ZoomFromTree(h2,tree,n,"ClusterMeanSM"); | |
228 | h2->GetXaxis()->SetTitle("RUN Index"); | |
229 | h2->GetXaxis()->SetTitleOffset(1.86); | |
230 | h2->GetXaxis()->SetTitleSize(0.03); | |
231 | h2->Draw(); | |
232 | ||
233 | tree->Draw("NextInt():ClusterMean:xe:ClusterRMS","","goff"); | |
234 | TGraphErrors * AverNclusters = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(), tree->GetV4()); | |
235 | AverNclusters->SetMarkerStyle(20); | |
236 | AverNclusters->SetMarkerColor(1); | |
237 | AverNclusters->Draw("same P") ; | |
238 | ||
239 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
240 | tree->Draw(Form("NextInt():ClusterMeanSM[%i]:xe:ClusterRMSSM[%i]",ism,ism),"","goff"); | |
241 | AverNclustersSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
242 | if (ism !=8)AverNclustersSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNclustersSM[ism]->SetMarkerColor(7); | |
243 | AverNclustersSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
244 | ||
245 | AverNclustersSM[ism]->Draw("same P"); | |
246 | } | |
247 | ||
248 | TLegend* l2 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
249 | l2->SetNColumns((n+1)/2.); | |
250 | l2->SetFillColor(0); | |
251 | l2->SetBorderSize(0); | |
252 | l2->SetTextSize(0.04); | |
253 | l2->SetHeader(Form("<# of clusters> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
254 | l2->AddEntry(AverNclusters,"average", "p"); | |
255 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
256 | TString projname = Form("SM %d",ism); | |
257 | l2->AddEntry(AverNclustersSM[ism],projname.Data(), "p"); | |
258 | } | |
259 | l2->Draw("same"); | |
260 | c2->Update(); | |
261 | if(SavePlots) c2->SaveAs(ClusterAveragesEntries); | |
262 | if(SavePlots==2) c2->SaveAs(ClusterAveragesEntries2); | |
263 | ||
264 | TCanvas* c3 = new TCanvas("ClusterAveragesEnergy", "Mean Cluster Energy", 1000, 500); | |
265 | c3->SetFillColor(0); | |
266 | c3->SetBorderSize(0); | |
267 | c3->SetFrameBorderMode(0); | |
268 | c3->SetGrid(); | |
269 | ||
270 | gPad->SetLeftMargin(0.08); | |
271 | gPad->SetRightMargin(0.02); | |
272 | gPad->SetGrid(); | |
273 | ||
274 | TH1F* h3 = (TH1F*)h1->Clone(""); | |
275 | h3->GetYaxis()->SetTitle("<E> (GeV)"); | |
276 | ZoomFromTree(h3,tree,n,"EtotalMeanSM"); | |
277 | h3->GetXaxis()->SetTitle("RUN Index"); | |
278 | h3->GetXaxis()->SetTitleOffset(1.86); | |
279 | h3->GetXaxis()->SetTitleSize(0.03); | |
280 | h3->Draw(); | |
281 | ||
282 | tree->Draw("NextInt():EtotalMean:xe:EtotalRMS","","goff"); | |
283 | TGraphErrors * AverE = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
284 | AverE->SetMarkerStyle(20); | |
285 | AverE->SetMarkerColor(1); | |
286 | AverE->Draw("same P"); | |
287 | ||
288 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
289 | ||
290 | tree->Draw(Form("NextInt():EtotalMeanSM[%i]:xe:EtotalRMSSM[%i]",ism,ism),"","goff"); | |
291 | AverESM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
292 | if (ism !=8)AverESM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverESM[ism]->SetMarkerColor(7); | |
293 | AverESM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
294 | AverESM[ism]->Draw("same P"); | |
295 | ||
296 | } | |
297 | ||
298 | TLegend* l3 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
299 | l3->SetNColumns((n+1)/2.); | |
300 | l3->SetFillColor(0); | |
301 | l3->SetBorderSize(0); | |
302 | l3->SetTextSize(0.04); | |
303 | l3->SetHeader(Form("<E> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
304 | l3->AddEntry(AverE,"average", "p"); | |
305 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
306 | TString projname = Form("SM %d",ism); | |
307 | l3->AddEntry(AverESM[ism],projname.Data(), "p"); | |
308 | } | |
309 | l3->Draw("same"); | |
310 | ||
311 | if(SavePlots) c3->SaveAs(ClusterAveragesEnergy); | |
312 | if(SavePlots==2) c3->SaveAs(ClusterAveragesEnergy2); | |
313 | ||
314 | TCanvas* c4 = new TCanvas("ClusterAveragesCells", "Mean Nb of Cells per Cluster", 1000, 500); | |
315 | c4->SetFillColor(0); | |
316 | c4->SetBorderSize(0); | |
317 | c4->SetFrameBorderMode(0); | |
318 | c4->SetGrid(); | |
319 | ||
320 | gPad->SetLeftMargin(0.08); | |
321 | gPad->SetRightMargin(0.02); | |
322 | gPad->SetGrid(); | |
323 | ||
324 | TH1F* h4 = (TH1F*)h1->Clone(""); | |
325 | h4->GetYaxis()->SetTitle("<N_{CellsPerCluster}>"); | |
326 | ZoomFromTree(h4,tree,n,"CellPerClusterMeanSM"); | |
327 | h4->GetXaxis()->SetTitle("RUN Index"); | |
328 | h4->GetXaxis()->SetTitleOffset(1.86); | |
329 | h4->GetXaxis()->SetTitleSize(0.03); | |
330 | h4->Draw(); | |
331 | ||
332 | // | |
333 | tree->Draw("NextInt():CellPerClusterMean:xe:CellPerClusterRMS","","goff"); | |
334 | TGraphErrors * AverCellPerCluster = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
335 | AverCellPerCluster->SetMarkerStyle(20); | |
336 | AverCellPerCluster->SetMarkerColor(1); | |
337 | ||
338 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
339 | tree->Draw(Form("NextInt():CellPerClusterMeanSM[%i]:xe:CellPerClusterRMSSM[%i]",ism,ism),"","goff"); | |
340 | AverNcellsPerClusterSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
341 | if (ism !=8)AverNcellsPerClusterSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNcellsPerClusterSM[ism]->SetMarkerColor(7); | |
342 | AverNcellsPerClusterSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
343 | AverNcellsPerClusterSM[ism]->Draw("same P"); | |
344 | ||
345 | } | |
346 | ||
347 | TLegend* l4 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
348 | l4->SetNColumns((n+1)/2.); | |
349 | l4->SetFillColor(0); | |
350 | l4->SetBorderSize(0); | |
351 | l4->SetTextSize(0.04); | |
352 | l4->SetHeader(Form("<# of cells per cluster> in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
353 | l4->AddEntry(AverCellPerCluster,"average", "p"); | |
354 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
355 | TString projname = Form("SM %d",ism); | |
356 | l4->AddEntry(AverNcellsPerClusterSM[ism],projname.Data(), "p"); | |
357 | } | |
358 | l4->Draw("same"); | |
359 | ||
360 | if(SavePlots) c4->SaveAs(ClusterAveragesCells); | |
361 | ||
362 | TCanvas* c5 = new TCanvas("Pi0Position", "Mean Pi0 Mass", 1000, 500); | |
363 | c5->SetFillColor(0); | |
364 | c5->SetBorderSize(0); | |
365 | c5->SetFrameBorderMode(0); | |
366 | c5->SetGrid(); | |
367 | ||
368 | gStyle->SetOptStat(0); | |
369 | ||
370 | gPad->SetLeftMargin(0.08); | |
371 | gPad->SetRightMargin(0.02); | |
372 | gPad->SetGrid(); | |
373 | ||
374 | TH1F * h5 = (TH1F*)h1->Clone(""); | |
375 | ZoomFromTree(h5,tree,n,"MeanPosSM"); | |
376 | h5->GetXaxis()->SetTitle("RUN Index"); | |
377 | h5->GetXaxis()->SetTitleOffset(1.86); | |
378 | h5->GetXaxis()->SetTitleSize(0.03); | |
379 | h5->GetYaxis()->SetTitle("Mean_{#pi^{0}}"); | |
380 | ||
381 | h5->Draw(); | |
382 | ||
383 | tree->Draw("NextInt():MeanPos:xe:MeanPosErr","","goff"); | |
384 | TGraphErrors * AverMean = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
385 | AverMean->SetMarkerStyle(20); | |
386 | AverMean->SetMarkerColor(1); | |
387 | AverMean->Draw("same P"); | |
388 | ||
389 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
390 | ||
391 | tree->Draw(Form("NextInt():MeanPosSM[%i]:xe:MeanPosErrSM[%i]",ism,ism),"","goff"); | |
392 | AverMeanSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
393 | if (ism !=8)AverMeanSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverMeanSM[ism]->SetMarkerColor(7); | |
394 | AverMeanSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
395 | AverMeanSM[ism]->Draw("same P"); | |
396 | } | |
397 | ||
398 | ||
399 | TLegend* l5 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
400 | l5->SetNColumns((n+1)/2.); | |
401 | l5->SetFillColor(0); | |
402 | l5->SetBorderSize(0); | |
403 | l5->SetTextSize(0.04); | |
404 | l5->SetHeader(Form("<M_{#pi^{0}}> (MeV) in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
405 | l5->AddEntry(AverMean,"average", "p"); | |
406 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
407 | TString projname = Form("SM %d",ism); | |
408 | l5->AddEntry(AverMeanSM[ism],projname.Data(), "p"); | |
409 | } | |
410 | l5->Draw("same"); | |
411 | ||
412 | c5->Update(); | |
413 | if(SavePlots) c5->SaveAs(Pi0Mass); | |
414 | ||
415 | ||
416 | TCanvas* c6 = new TCanvas("Pi0Width", "Mean Pi0 Width", 1000, 500); | |
417 | c6->SetFillColor(0); | |
418 | c6->SetBorderSize(0); | |
419 | c6->SetFrameBorderMode(0); | |
420 | c6->SetGrid(); | |
421 | ||
422 | gPad->SetLeftMargin(0.08); | |
423 | gPad->SetRightMargin(0.02); | |
424 | gPad->SetGrid(); | |
425 | ||
426 | TH1F* h6 = (TH1F*)h1->Clone(""); | |
427 | ZoomFromTree(h6,tree,n,"WidthSM"); | |
428 | h6->GetXaxis()->SetTitle("RUN Index"); | |
429 | h6->GetXaxis()->SetTitleOffset(1.86); | |
430 | h6->GetXaxis()->SetTitleSize(0.03); | |
431 | h6->GetYaxis()->SetTitle("#sigma_{#pi^{0}}"); | |
432 | h6->Draw(); | |
433 | ||
434 | tree->Draw("NextInt():Width:xe:WidthErr","","goff"); | |
435 | TGraphErrors * AverWidth = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
436 | AverWidth->SetMarkerStyle(20); | |
437 | AverWidth->SetMarkerColor(1); | |
438 | AverWidth->Draw("same P"); | |
439 | ||
440 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
441 | tree->Draw(Form("NextInt():WidthSM[%i]:xe:WidthErrSM[%i]",ism,ism),"","goff"); | |
442 | AverWidthSM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
443 | if (ism !=8)AverWidthSM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverWidthSM[ism]->SetMarkerColor(7); | |
444 | AverWidthSM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
445 | AverWidthSM[ism]->Draw("same P"); | |
446 | } | |
447 | ||
448 | ||
449 | TLegend* l6 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
450 | l6->SetNColumns((n+1)/2.); | |
451 | l6->SetFillColor(0); | |
452 | l6->SetBorderSize(0); | |
453 | l6->SetTextSize(0.04); | |
454 | l6->SetHeader(Form("#sigma_{#pi^{0}} in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
455 | l6->AddEntry(AverWidth,"total", "p"); | |
456 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
457 | TString projname = Form("SM %d",ism); | |
458 | l6->AddEntry(AverWidthSM[ism],projname.Data(), "p"); | |
459 | } | |
460 | l6->Draw("same"); | |
461 | c6->Update(); | |
462 | if(SavePlots) c6->SaveAs(Pi0Width); | |
463 | ||
464 | TCanvas* c7 = new TCanvas("Npi0", "Mean Nb of Pi0", 1000, 500); | |
465 | c7->SetFillColor(0); | |
466 | c7->SetBorderSize(0); | |
467 | c7->SetFrameBorderMode(0); | |
468 | c7->SetGrid(); | |
469 | ||
470 | gPad->SetLeftMargin(0.08); | |
471 | gPad->SetRightMargin(0.02); | |
472 | gPad->SetGrid(); | |
473 | ||
474 | TH1F* h7 = (TH1F*)h1->Clone(""); | |
475 | ZoomFromTree(h7,tree,n,"Npi0SM"); | |
476 | if (h7->GetMinimum() > 0.) {c7->SetLogy();} | |
477 | h7->GetXaxis()->SetTitle("RUN Index"); | |
478 | h7->GetXaxis()->SetTitleOffset(1.86); | |
479 | h7->GetXaxis()->SetTitleSize(0.03); | |
480 | h7->GetYaxis()->SetTitle("<N_{#pi^{0}}>/event"); | |
481 | h7->Draw(); | |
482 | ||
483 | tree->Draw("NextInt():Npi0:xe:Npi0Err","","goff"); | |
484 | if (tree->GetMinimum("Npi0") > 1) c4->SetLogy(); | |
485 | TGraphErrors * AverNpi0 = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
486 | AverNpi0->SetMarkerStyle(20); | |
487 | AverNpi0->SetMarkerColor(1); | |
488 | AverNpi0->Draw("same P"); | |
489 | ||
490 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
491 | tree->Draw(Form("NextInt():Npi0SM[%i]:xe:Npi0ErrSM[%i]",ism,ism),"","goff"); | |
492 | AverNpi0SM[ism] = new TGraphErrors(tree->GetSelectedRows(), tree->GetV1(), tree->GetV2(),tree->GetV3(),tree->GetV4()); | |
493 | if (ism !=8)AverNpi0SM[ism]->SetMarkerColor(ism<10?ism+2:ism+1);else AverNpi0SM[ism]->SetMarkerColor(7); | |
494 | AverNpi0SM[ism]->SetMarkerStyle(21+(ism<10 ? ism: ism-10)); | |
495 | AverNpi0SM[ism]->Draw("same P"); | |
496 | } | |
497 | ||
498 | TLegend* l7 = new TLegend(0.123, 0.744, 0.933, 0.894); | |
499 | l7->SetNColumns((n+1)/2.); | |
500 | l7->SetFillColor(0); | |
501 | l7->SetBorderSize(0); | |
502 | l7->SetTextSize(0.04); | |
503 | l7->SetHeader(Form("<N_{#pi^{0}}>/event in %s (period %s trigger %s)",fCalorimeter->Data(),period->Data(),((*fTrigger)(r)).Data())); | |
504 | l7->AddEntry(AverNpi0,"total", "p"); | |
505 | for(Int_t ism = 0 ; ism < n ; ism++){ | |
506 | TString projname = Form("SM %d",ism); | |
507 | l7->AddEntry(AverNpi0SM[ism],projname.Data(), "p"); | |
508 | } | |
509 | l7->Draw("same"); | |
510 | c7->Update(); | |
511 | if(SavePlots) c7->SaveAs(Pi0Entries); | |
512 | if(SavePlots==2) c7->SaveAs(Pi0Entries2); | |
513 | ||
514 | fout->mkdir(Form("%s/%s/%s/%s",period->Data(),pass->Data(),"TrendingQA",fTrigger->Data())); | |
515 | fout->cd(); | |
516 | fout->Cd(Form("%s/%s/%s/%s",period->Data(),pass->Data(),"TrendingQA",fTrigger->Data())); | |
517 | ||
518 | gROOT->GetListOfCanvases()->Write(); | |
519 | gROOT->GetListOfCanvases()->Delete(); | |
520 | ||
521 | if((!Expr.IsNull()) && (!Expr.EndsWith(".root"))) elist->Write(); | |
522 | if(listNotZero) {listNotZero->Reset();} | |
523 | if(elist) {elist->Reset();} | |
524 | delete h1; | |
525 | ||
526 | return 0; | |
527 | ||
528 | } | |
529 | ||
530 | //--------------------------------------------------------------------------------------------- | |
531 | TH1F* ZoomFromTree(TH1F* h, TTree* atree, Int_t n, const char* aVar, UShort_t aScaleFactor) | |
532 | { | |
533 | ||
534 | atree->SetEventList(0); | |
535 | TEventList *listNotZero = (TEventList*)gDirectory->Get("listNotZero"); | |
536 | atree->SetEventList(listNotZero); | |
537 | ||
538 | double treeMin = GetTreeMinimum(atree,n,aVar); | |
539 | double treeMax = GetTreeMaximum(atree,n,aVar); | |
540 | double offset = 30*((treeMax - treeMin)/(100.*aScaleFactor)); | |
541 | ||
542 | if(treeMin != -treeMax){ | |
543 | h->SetMinimum(TMath::Max(0.,treeMin-offset)); | |
544 | h->SetMaximum(treeMax+2*offset); | |
545 | } | |
546 | ||
547 | atree->SetEventList(0); | |
548 | TEventList *elist = (TEventList*)gDirectory->Get("elist"); | |
549 | atree->SetEventList(elist); | |
550 | ||
551 | return h; | |
552 | ||
553 | } | |
554 | ||
555 | //-------------------------------------------------------------------------------------------- | |
556 | Double_t GetTreeMinimum(TTree* aTree,Int_t n, const char* columname) | |
557 | { | |
558 | ||
559 | TLeaf* leaf = aTree->GetLeaf(columname); | |
560 | if (!leaf) { | |
561 | return 0; | |
562 | } | |
563 | TBranch* branch = leaf->GetBranch(); | |
564 | Double_t cmin = 3.40282e+38; | |
565 | for (Long64_t i = 0; i < aTree->GetEntries(); ++i) { | |
566 | Long64_t entryNumber = aTree->GetEntryNumber(i); | |
567 | if (entryNumber < 0) break; | |
568 | branch->GetEntry(entryNumber); | |
569 | for (Int_t j = 0;j < TMath::Min(leaf->GetLen(),n); ++j) { | |
570 | Double_t val = leaf->GetValue(j); | |
571 | if (val < cmin) { | |
572 | cmin = val; | |
573 | } | |
574 | } | |
575 | } | |
576 | ||
577 | return cmin; | |
578 | ||
579 | } | |
580 | ||
581 | //______________________________________________________________________________ | |
582 | Double_t GetTreeMaximum(TTree* aTree,Int_t n,const char* columname) | |
583 | { | |
584 | ||
585 | TLeaf* leaf = aTree->GetLeaf(columname); | |
586 | if (!leaf) { | |
587 | return 0; | |
588 | } | |
589 | TBranch* branch = leaf->GetBranch(); | |
590 | Double_t cmax = - 3.40282e+38; | |
591 | for (Long64_t i = 0; i < aTree->GetEntries(); ++i) { | |
592 | Long64_t entryNumber = aTree->GetEntryNumber(i); | |
593 | if (entryNumber < 0) break; | |
594 | branch->GetEntry(entryNumber); | |
595 | for (Int_t j = 0; j < TMath::Min(leaf->GetLen(),n); ++j) { | |
596 | Double_t val = leaf->GetValue(j); | |
597 | if (val > cmax) { | |
598 | cmax = val; | |
599 | } | |
600 | } | |
601 | } | |
602 | ||
603 | return cmax; | |
604 | ||
605 | } | |
606 |