2 //--------------------------------------------------
3 // Example macro to check QA outputs from the histograms itself
6 //The input file needs:
7 // 1. the root output from AliAnaCalorimeterQA (or QA train) run by run ie runnumber.root
8 // placed in the directory period/pass/
9 // 2. the run list (runlist.txt) of these run output placed in the directory period/pass/ runlist mean : index runnumber//
11 // 2 trigger options " MB" : CaloQA_default output from train
12 // " EMC" : CaloQA_EMC7
14 // Configured by options of EMCAL checker with:
15 // a. cell multiplicity
16 // b. cluster multiplicity/event
17 // c. Cells per Cluster
18 // d. mean cluster energy
20 // more checker valuse could be added based on request (more canvas)
23 // Modified M. Germain
30 #include <Riostream.h>
32 #include <TGraphErrors.h>
34 #include <TFileMerger.h>
35 #include <TMultiGraph.h>
40 #include <TGridCollection.h>
42 #include <TGridResult.h>
43 #include <TClonesArray.h>
44 #include <TObjString.h>
50 #include <sstream> // Required for stringstreams
54 void trendingCluster(TString fCalorimeter = "EMCAL", TString period = "LHC11h", TString pass = "pass1_HLT", const Int_t n = 10, TString fTrigger = "MB"){
59 if (fTrigger=="EMC") file = "/scratch/alicehp2/germain/QA/"+period+"/"+ pass + "/runlist.txt" ;
60 else file = "/scratch/alicehp2/germain/QA/"+period+"/"+ pass + "/runlistMB.txt" ;
63 pFile = fopen(file.Data(), "r"); //open the text file where include the run list and correct run index
66 cout << " fcalo: " << fCalorimeter << "; period: " << period << "; pass: " << pass << " trigger "<<fTrigger<< endl;
67 char outfilename [100] ;
80 ncols = fscanf(pFile,"%d %d ",&p,&q);
89 const Int_t nRun = nlines ;
92 Double_t nEvent[nRun] ;
93 // Double_t TimeMean[nRun] ;
94 // Double_t TimeRMS[nRun] ;
95 Double_t CellMean[nRun] ;
96 Double_t CellRMS[nRun] ;
97 Double_t ClusterMean[nRun] ;
98 Double_t ClusterRMS[nRun] ;
99 Double_t EtotalMean[nRun] ;//total energy deposited per event
100 Double_t EtotalRMS[nRun] ;
102 Double_t CellPerClusterMean[nRun] ;
103 Double_t CellPerClusterRMS[nRun] ;
104 Double_t ECell1Mean[nRun] ;//total energy deposited per event without 1 cell clusters
105 Double_t ECell1RMS[nRun] ;
108 TDirectoryFile * dir;
116 TH3D * fhNCellsPerCluster ;
121 TH2F * NCellsPerCluster[n];
124 TGraphErrors * AverNcellsSM[n];
125 TGraphErrors * AverNclustersSM[n];
126 TGraphErrors * AverNcellsPerClusterSM[n];
127 TGraphErrors * AverESM[n];
128 TGraphErrors * AverTimeSM[n];
129 TGraphErrors * AverMggSM[n];
130 TGraphErrors * AverEcell1SM[n];
132 Double_t CellMeanSM[n][nRun] ;
133 Double_t CellRMSSM[n][nRun] ;
134 Double_t ClusterMeanSM[n][nRun] ;
135 Double_t ClusterRMSSM[n][nRun] ;
136 Double_t EtotalMeanSM[n][nRun] ;//total energy deposited per event
137 Double_t EtotalRMSSM[n][nRun] ;
138 Double_t CellPerClusterMeanSM[n][nRun] ;
139 Double_t CellPerClusterRMSSM[n][nRun] ;
140 Double_t ECell1MeanSM[n][nRun] ;//total energy deposited per event without 1 cell clusters
141 Double_t ECell1RMSSM[n][nRun] ;
144 TString namefile = "/scratch/alicehp2/germain/QA/"+period+"/"+pass+"/"+ fCalorimeter + period + pass + fTrigger+"data.txt";
146 fstream QAData(namefile, ios::out); //write the QA check values at the end
148 cout << " namefile " << namefile << endl;
149 cout << " nRun " << nRun << " index(nRun) " << index[nRun-1] << endl;
151 for(Int_t i = 0 ; i < nRun ; i++){
155 TString name = "/scratch/alicehp2/germain/QA/"+period +"/"+ pass + "/";
159 f = TFile::Open(name.Data(),"read") ;
162 // cout << " i = " << i << " file opend Output" << RunId[i]<< endl;
164 if(fTrigger=="EMC"){ dir = (TDirectoryFile *)f->Get("CaloQA_EMC7");
165 outputList = (TList*)dir->Get("CaloQA_EMC7");
168 dir = (TDirectoryFile *)f->Get("CaloQA_default");
169 outputList = (TList*)dir->Get("CaloQA_default");
172 //define the averages for checking Histograms
175 fhNEvents =(TH1F *)outputList->FindObject("hNEvents");
176 nEvent[i]=fhNEvents->GetEntries();
177 cout << " Run " << RunId[i]<< " nevent " << nEvent[i]<< endl;
178 if( nEvent[i] == 0) continue ;
179 if( nEvent[i] < 2) continue ;
180 fhE = (TH1F *)outputList->FindObject(fCalorimeter+"_hE");
182 Double_t energy = 0. ;
184 for(Int_t ibin = fhE->FindBin(0.3) ; ibin <fhE->FindBin(50.) ; ibin++){ //Starting from 0.3eV
185 energy+=fhE->GetBinCenter(ibin)*fhE->GetBinContent(ibin);
187 EtotalMean[i]=energy/fhE->Integral(fhE->FindBin(0.3), fhE->FindBin(50.)) ;
188 EtotalRMS[i]=fhE->GetMeanError();
192 //for single module check
193 for(Int_t ism = 0 ; ism < n ; ism++){
194 TString nameNCell = Form("%s_hNCells_Mod%d",fCalorimeter.Data(),ism);
196 TString nameNCluster = Form("%s_hNClusters_Mod%d",fCalorimeter.Data(),ism);
197 TString nameNCellPerCluster = Form("%s_hNCellsPerCluster_Mod%d",fCalorimeter.Data(),ism);
198 TString nameE = Form("%s_hE_Mod%d",fCalorimeter.Data(),ism);
200 NCells[ism] = (TH1F*)outputList->FindObject(nameNCell.Data());
201 NClusters[ism] = (TH1F*)outputList->FindObject(nameNCluster.Data());
202 NCellsPerCluster[ism] = (TH2F*)outputList->FindObject(nameNCellPerCluster.Data());
203 E[ism] = (TH1F*)outputList->FindObject(nameE.Data());
204 CellMeanSM[ism][i]=NCells[ism]->GetMean();
205 CellRMSSM[ism][i]=NCells[ism]->GetMeanError();
206 ClusterMeanSM[ism][i]=NClusters[ism]->GetMean();
207 ClusterRMSSM[ism][i]=NClusters[ism]->GetMeanError();
208 CellPerClusterMeanSM[ism][i]=NCellsPerCluster[ism]->GetMean(2);
209 CellPerClusterRMSSM[ism][i]=NCellsPerCluster[ism]->GetMeanError(2);
210 // cout<<"SM = "<<ism<<" Mean : = "<<CellPerClusterMeanSM[ism][i]<<endl ;
211 ECell1MeanSM[ism][i] =NCellsPerCluster[ism]->ProjectionX("",2,300,"")->Integral(5,100)/(nEvent[i]);
212 ECell1RMSSM[ism][i] =NCellsPerCluster[ism]->ProjectionX("",2,300,"")->GetMeanError();
213 Double_t energySM = 0. ;
214 for(Int_t ibin = E[ism]->FindBin(0.3) ; ibin <E[ism]->FindBin(50.) ; ibin++){ //starting from 0.3GeV
215 energySM+=E[ism]->GetBinCenter(ibin)*(E[ism]->GetBinContent(ibin));
217 EtotalMeanSM[ism][i]=energySM/(E[ism]->Integral(E[ism]->FindBin(0.3),E[ism]->FindBin(50.)));
219 EtotalRMSSM[ism][i]=E[ism]->GetMeanError();
222 fhNCells = (TH1F*)NCells[ism]->Clone("NCells");
223 fhNClusters = (TH1F*)NClusters[ism]->Clone("NClusters");
226 fhNCells->Add(NCells[ism],1);
227 fhNClusters->Add(NClusters[ism],1);
230 ClusterMean[i]=fhNClusters->GetMean();
231 ClusterRMS[i]=fhNClusters->GetMeanError();
232 CellMean[i]=fhNCells->GetMean();
233 CellRMS[i]=fhNCells->GetMeanError();
234 outputList->Clear() ;
241 //if you want to write all the QA check values at the end, otherwise just comment out below
242 // becareful with different detectors as the check output are different since different modules/SM for different detetcor
244 QAData <<i+1<<" "<< RunId[i] <<" "<< nEvent[i]
245 // <<" "<< RunId[i]<<" "<<CellMean[i]
246 // <<" "<< CellMeanSM[0][i] <<" "<< CellMeanSM[1][i]
247 // <<" "<<CellMeanSM[2][i]
248 // <<" "<< RunId[i] <<" "<<ClusterMean[i]
249 // <<" "<< ClusterMeanSM[0][i]<<" "<< ClusterMeanSM[1][i]
250 // <<" "<< ClusterMeanSM[2][i]
251 // <<" "<< RunId[i]<<" "<< CellPerClusterMean[i]
252 // <<" "<< CellPerClusterMeanSM[0][i]<<" "<< CellPerClusterMeanSM[1][i]
253 // <<" "<< CellPerClusterMeanSM[2][i]
254 // <<" "<< RunId[i]<<" "<< EtotalMean[i]
255 // <<" "<< EtotalMeanSM[0][i] <<" "<< EtotalMeanSM[1][i]
256 // <<" "<< EtotalMeanSM[2][i]
260 } // end loop on nrun
265 TString base = "/scratch/alicehp2/germain/QA/";
272 TString ClusterAverages ; ClusterAverages = base + "ClusterAverages.gif";
273 TString Entries ; Entries = base + "Nentries.gif";
274 TString ClusterAveragesEnergy ; ClusterAveragesEnergy = base + "ClusterAveragesEnergy.gif";
275 TString ClusterAveragesEntries ; ClusterAveragesEntries = base + "ClusterAveragesEntries.gif";
276 TString ClusterAveragesCells ; ClusterAveragesCells = base + "ClusterAveragescells.gif";
279 cout << "c11 nEvents" << endl;
280 //just for the canvas defination
282 cout << " index(0)" << index[nRun-1] << " index(20) " << index[20] <<endl;
283 TH1F * dummy = new TH1F("dummy", "dummy", nRun, 0., nRun+0.5);
284 // TH1F * dummy = new TH1F("dummy", "dummy", index[nRun-1], 0., index[nRun-1]+0.5);
285 dummy->SetTitle("") ;
286 dummy->SetStats(kFALSE) ;
287 dummy->SetAxisRange(0., nRun, "X") ;
289 for(Int_t i = 0 ; i < nRun ; i++){
292 cout <<" run "<< RunId[i] << " label " <<label << endl;
294 dummy->GetXaxis()->SetBinLabel(i+1,label.Data());
295 dummy->GetXaxis()->LabelsOption("v");
300 //number of events passes physics selection for each run
301 TCanvas * c11 = new TCanvas("nEvents", "nEvents", 1000, 500);
302 c11->SetFillColor(0);
303 c11->SetBorderSize(0);
304 c11->SetFrameBorderMode(0);
305 gStyle->SetOptStat(0);
308 // dummy->GetXaxis()->SetTitle("RUN");
309 dummy->GetXaxis()->SetTitleOffset(0.05);
310 dummy->GetYaxis()->SetTitle("N_{events}");
311 dummy->SetMinimum(1.) ; //should addjust based on the statistics
312 dummy->SetMaximum(1.e6) ; //should addjust based on the statistics
314 TGraph * nEvents = new TGraph(nRun, x, nEvent);
315 nEvents->SetMarkerStyle(20);
316 nEvents->SetMarkerColor(1);
317 nEvents->SetLineColor(2);
318 nEvents->Draw("same PL") ;
322 if (fTrigger=="MB")sprintf(outfilename,"nEventMB.gif");
323 if (fTrigger=="EMC")sprintf(outfilename,"nEventEMC.gif");
326 c11->SaveAs(Entries);
329 cout << "c1 Aver NCell" << endl;
331 TCanvas * c1 = new TCanvas("AverNCell", "AverNCell", 600, 600);
334 c1->SetBorderSize(0);
335 c1->SetFrameBorderMode(0);
336 gStyle->SetOptStat(0);
337 TH1F * h1 = (TH1F*)dummy->Clone("");
338 h1->GetXaxis()->SetTitle("RUN Index");
339 h1->GetYaxis()->SetTitle("<N_{cells}>");
341 h1->SetMaximum(10.) ;
342 if(fCalorimeter=="EMCAL") h1->SetMaximum(5.) ;
345 TGraphErrors * AverNcells = new TGraphErrors(nRun, x, CellMean, xe, CellRMS);
347 AverNcells->SetMarkerColor(1);
348 AverNcells->SetMarkerStyle(20);
349 AverNcells->Draw("same P") ;
350 for(Int_t ism = 0 ; ism < n ; ism++){
351 AverNcellsSM[ism] = new TGraphErrors(nRun, x, CellMeanSM[ism], xe, CellRMSSM[ism]);
352 AverNcellsSM[ism]->SetMarkerColor(ism+2);
353 AverNcellsSM[ism]->SetMarkerStyle(21+ism);
354 AverNcellsSM[ism]->Draw("same P");
359 TLegend * l1 = new TLegend(0.4, 0.6, 0.75, 0.85);
361 l1->SetBorderSize(0);
362 l1->SetTextSize(0.02);
363 l1->AddEntry(AverNcells, "<# of cells>", "") ;
364 l1->AddEntry(AverNcells, Form("det = %s",fCalorimeter.Data()), "") ;
365 l1->AddEntry(AverNcells,"average", "p");
366 for(Int_t ism = 0 ; ism < n ; ism++){
367 TString projname = Form("SM_ %d",ism);
368 l1->AddEntry(AverNcellsSM[ism],projname.Data(), "p");
374 TCanvas * c200 = new TCanvas("ClusterAverages", "ClusterAverages", 1000, 500);
375 c200->SetFillColor(0);
376 c200->SetBorderSize(0);
377 c200->SetFrameBorderMode(0);
380 gPad->SetLeftMargin(0.08);
381 gPad->SetRightMargin(0.02);
384 TH1F * h2 = (TH1F*)dummy->Clone("");
386 h2->GetYaxis()->SetTitle("<N_{clusters}>/event");
388 if (fTrigger=="EMC") h2->SetMaximum(70) ;
389 else h2->SetMaximum(50) ;
390 h2->SetMinimum(10) ; // for Pb Pb
393 TGraphErrors * AverNclusters = new TGraphErrors(nRun, x, ClusterMean, xe, ClusterRMS);
394 AverNclusters->SetMarkerStyle(20);
395 AverNclusters->SetMarkerColor(1);
396 AverNclusters->Draw("same P") ;
398 for(Int_t ism = 0 ; ism < n ; ism++){
399 AverNclustersSM[ism] = new TGraphErrors(nRun, x, ClusterMeanSM[ism], xe, ClusterRMSSM[ism]);
400 AverNclustersSM[ism]->SetMarkerColor(ism+2);
401 AverNclustersSM[ism]->SetMarkerStyle(21+ism);
403 AverNclustersSM[ism]->Draw("same P");
407 TLegend * l200 = new TLegend(0.4, 0.6, 0.75, 0.85);
408 l200->SetFillColor(0);
409 l200->SetBorderSize(0);
410 l200->SetTextSize(0.02);
411 l200->AddEntry(AverNclusters, "<# of clusters>", "") ;
412 l200->AddEntry(AverNclusters, Form("det = %s",fCalorimeter.Data()), "") ;
413 l200->AddEntry(AverNclusters,"average", "p");
415 for(Int_t ism = 0 ; ism < n ; ism++){
416 TString projname = Form("SM_ %d",ism);
417 l200->AddEntry(AverNclustersSM[ism],projname.Data(), "p");
422 c200->SaveAs(ClusterAveragesEntries);
424 TCanvas * c201 = new TCanvas("ClusterAveragesEnergy", "ClusterAveragesEnergy", 1000, 500);
425 c201->SetFillColor(0);
426 c201->SetBorderSize(0);
427 c201->SetFrameBorderMode(0);
431 gPad->SetLeftMargin(0.08);
432 gPad->SetRightMargin(0.02);
436 TH1F * h3 = (TH1F*)dummy->Clone("");
438 h3->GetYaxis()->SetTitle("<E> (GeV)");
439 h3->SetMinimum(0.2) ;
443 TGraphErrors * AverE = new TGraphErrors(nRun, x, EtotalMean, xe, EtotalRMS);
444 AverE->SetMarkerStyle(20);
445 AverE->SetMarkerColor(1);
446 AverE->Draw("same P");
448 for(Int_t ism = 0 ; ism < n ; ism++){
449 AverESM[ism] = new TGraphErrors(nRun, x, EtotalMeanSM[ism], xe, EtotalRMSSM[ism]);
450 AverESM[ism]->SetMarkerColor(ism+2);
451 AverESM[ism]->SetMarkerStyle(21+ism);
452 AverESM[ism]->Draw("same P");
456 TLegend * l3 = new TLegend(0.4, 0.6, 0.75, 0.85);
458 l3->SetBorderSize(0);
459 l3->SetTextSize(0.02);
460 l3->AddEntry(AverE, "<E>", "") ;
461 l3->AddEntry(AverE, Form("det = %s",fCalorimeter.Data()), "") ;
462 l3->AddEntry(AverE,"average", "p");
464 for(Int_t ism = 0 ; ism < n ; ism++){
465 TString projname = Form("SM_ %d",ism);
466 l3->AddEntry(AverESM[ism],projname.Data(), "p");
471 c201->SaveAs(ClusterAveragesEnergy);
474 TCanvas * c202 = new TCanvas("ClusterAveragesCells", "ClusterAveragesCells", 1000, 500);
475 c202->SetFillColor(0);
476 c202->SetBorderSize(0);
477 c202->SetFrameBorderMode(0);
480 gPad->SetLeftMargin(0.08);
481 gPad->SetRightMargin(0.02);
486 TH1F * h4 = (TH1F*)dummy->Clone("");
488 h4->GetYaxis()->SetTitle("<N_{CellsPerCluster}>");
489 h4->SetMinimum(1.5) ;
490 h4->SetMaximum(5.5) ;
494 TGraphErrors * AverCellPerCluster = new TGraphErrors(nRun, x, CellPerClusterMean, xe, CellPerClusterRMS);
495 AverCellPerCluster->SetMarkerStyle(20);
496 AverCellPerCluster->SetMarkerColor(1);
498 for(Int_t ism = 0 ; ism < n ; ism++){
499 AverNcellsPerClusterSM[ism] = new TGraphErrors(nRun, x, CellPerClusterMeanSM[ism], xe, CellPerClusterRMSSM[ism]);
500 AverNcellsPerClusterSM[ism]->SetMarkerColor(ism+2);
501 AverNcellsPerClusterSM[ism]->SetMarkerStyle(21+ism);
502 AverNcellsPerClusterSM[ism]->Draw("same P");
506 TLegend * l4 = new TLegend(0.4, 0.6, 0.75, 0.85);
508 l4->SetBorderSize(0);
509 l4->SetTextSize(0.02);
510 l4->AddEntry(AverCellPerCluster, "<# of cells per cluster>", "") ;
511 l4->AddEntry(AverCellPerCluster, Form("det = %s",fCalorimeter.Data()), "") ;
512 l4->AddEntry(AverCellPerCluster,"average", "p");
514 for(Int_t ism = 0 ; ism < n ; ism++){
515 TString projname = Form("SM_ %d",ism);
516 l4->AddEntry(AverNcellsPerClusterSM[ism],projname.Data(), "p");
521 c202->SaveAs(ClusterAveragesCells);