]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/macros/QA/trendingCluster.C
Updated stat unc on the Raa (Zaida)
[u/mrichter/AliRoot.git] / PWG4 / macros / QA / trendingCluster.C
1 /* $Id:  $ */
2 //--------------------------------------------------
3 // Example macro to check QA outputs from the histograms itself
4 // Executed with Root 
5
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//
10 // Trigger
11 // 2 trigger options " MB"  : CaloQA_default output from train
12 //                   " EMC" : CaloQA_EMC7
13
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 
19
20 // more checker valuse could be added based on request (more canvas)
21 //
22 // Author: Yaxian Mao
23 // Modified M. Germain
24 //
25
26 #include <TFile.h>
27 #include <TH1F.h>
28 #include <TH2F.h>
29 #include <TH3D.h>
30 #include <Riostream.h>
31 #include <TCanvas.h>
32 #include <TGraphErrors.h>
33 #include <TGrid.h>
34 #include <TFileMerger.h>
35 #include <TMultiGraph.h>
36 #include <TROOT.h>
37 #include <TString.h>
38 #include <TStyle.h>
39 #include <TLegend.h>
40 #include <TGridCollection.h>
41 #include <TROOT.h>
42 #include <TGridResult.h>
43 #include <TClonesArray.h>
44 #include <TObjString.h>
45 #include <stdio.h>
46
47 #include <string> 
48 #include <fstream>
49 #include <iostream>
50 #include <sstream>  // Required for stringstreams
51
52 using namespace std;
53
54 void  trendingCluster(TString fCalorimeter = "EMCAL", TString period = "LHC11h", TString pass = "pass1_HLT", const Int_t n = 10, TString fTrigger = "MB"){
55   
56   FILE * pFile;
57   
58   TString file = "";
59   if (fTrigger=="EMC") file = "/scratch/alicehp2/germain/QA/"+period+"/"+ pass + "/runlist.txt" ;
60   else                 file = "/scratch/alicehp2/germain/QA/"+period+"/"+ pass + "/runlistMB.txt" ;
61   
62   //cout<<file<<endl;
63   pFile = fopen(file.Data(), "r"); //open the text file where include the run list and correct run index
64   
65   cout<<file<<endl;
66   cout << " fcalo: " << fCalorimeter << "; period: " << period << "; pass: " << pass << "  trigger "<<fTrigger<<  endl; 
67   char outfilename [100]     ;
68   
69   Int_t index[500];
70   Int_t p;
71   Int_t q;
72   Int_t ncols;
73   Int_t nlines = 0 ;
74   Int_t RunId[500] ;
75   Double_t x[500] ;
76   Double_t xrun[500] ;
77   //TString label; 
78   
79   while (1){
80     ncols = fscanf(pFile,"%d  %d ",&p,&q);
81     if (ncols< 0) break;
82     x[nlines]=p;
83     index[nlines]=p;
84     RunId[nlines]=q;
85     xrun[nlines]=1.*q;
86     nlines++;
87   }
88   fclose(pFile);
89   const Int_t nRun = nlines ;
90   
91   Double_t xe[nRun] ;
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] ;
101   
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] ;
106   
107   TFile * f ;
108   TDirectoryFile * dir;
109   TList * outputList;
110   
111   TH1F * fhNEvents;
112   TH1F * fhE;
113   TH1F * fhNClusters;
114   TH1F * fhNCells;
115   TH2F * fhIM ;
116   TH3D * fhNCellsPerCluster ;
117   TH2F * fhTimeAmp ;
118   
119   TH1F * NCells[n];
120   TH1F * NClusters[n];
121   TH2F * NCellsPerCluster[n];
122   TH1F * E[n];
123   
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];
131   
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] ;
142   
143   
144   TString namefile = "/scratch/alicehp2/germain/QA/"+period+"/"+pass+"/"+ fCalorimeter + period + pass + fTrigger+"data.txt";
145   
146   fstream QAData(namefile, ios::out); //write the QA check values at the end
147   
148   cout << " namefile " << namefile << endl;
149   cout << " nRun " << nRun <<  " index(nRun) " << index[nRun-1]  << endl;
150   
151   for(Int_t i = 0 ; i < nRun ; i++){
152     
153     xe[i] = 0.5 ; 
154     
155     TString name = "/scratch/alicehp2/germain/QA/"+period +"/"+ pass + "/";
156     
157     name += RunId[i] ;
158     name += ".root";
159     f = TFile::Open(name.Data(),"read") ;
160     if (!f) continue; 
161     
162     //  cout << " i = " << i << " file opend Output" <<  RunId[i]<< endl;
163     
164     if(fTrigger=="EMC"){        dir = (TDirectoryFile *)f->Get("CaloQA_EMC7");
165       outputList = (TList*)dir->Get("CaloQA_EMC7");
166     }
167     else{
168       dir = (TDirectoryFile *)f->Get("CaloQA_default");
169       outputList = (TList*)dir->Get("CaloQA_default");
170     }
171     
172     //define the averages for checking Histograms
173     //
174     
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");
181     
182     Double_t energy = 0. ;
183     
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);
186     }
187     EtotalMean[i]=energy/fhE->Integral(fhE->FindBin(0.3), fhE->FindBin(50.)) ;
188     EtotalRMS[i]=fhE->GetMeanError();
189     
190     
191     
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);
195       
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);
199       
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));
216       }
217       EtotalMeanSM[ism][i]=energySM/(E[ism]->Integral(E[ism]->FindBin(0.3),E[ism]->FindBin(50.)));
218       
219       EtotalRMSSM[ism][i]=E[ism]->GetMeanError();
220       
221       if(ism==0) {
222         fhNCells = (TH1F*)NCells[ism]->Clone("NCells");
223         fhNClusters = (TH1F*)NClusters[ism]->Clone("NClusters");  
224       }
225       else {
226         fhNCells->Add(NCells[ism],1);
227         fhNClusters->Add(NClusters[ism],1);
228       }
229     } //per SM loop
230     ClusterMean[i]=fhNClusters->GetMean();
231     ClusterRMS[i]=fhNClusters->GetMeanError();  
232     CellMean[i]=fhNCells->GetMean();
233     CellRMS[i]=fhNCells->GetMeanError();  
234     outputList->Clear() ; 
235     dir->Close();
236     f->Close();
237     f=NULL;
238     dir=NULL;
239     outputList=NULL;
240     
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
243     
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] 
257     
258     <<"\n" ; 
259     
260   } // end loop on nrun
261   
262   
263   QAData.close();
264   
265   TString base = "/scratch/alicehp2/germain/QA/";
266   base += period ;
267   base += "/";
268   base += pass ;
269   base += "/";
270   
271   base += fTrigger;
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";
277   
278   
279   cout << "c11 nEvents" << endl;
280   //just for the canvas defination
281   
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") ; 
288   
289   for(Int_t i = 0 ; i < nRun ; i++){
290     TString label = " ";
291     label+=RunId[i];
292     cout <<" run "<< RunId[i] << " label " <<label << endl;
293     
294     dummy->GetXaxis()->SetBinLabel(i+1,label.Data());
295     dummy->GetXaxis()->LabelsOption("v");
296   }
297   
298   
299   
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);  
306   c11->SetLogy();
307   c11->SetGrid();
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 
313   dummy->Draw();
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") ;
319   c11->Update();
320   
321   
322   if (fTrigger=="MB")sprintf(outfilename,"nEventMB.gif");
323   if (fTrigger=="EMC")sprintf(outfilename,"nEventEMC.gif");
324   
325   
326   c11->SaveAs(Entries);
327   
328   
329   cout << "c1 Aver NCell" << endl;
330   
331   TCanvas  * c1 = new TCanvas("AverNCell", "AverNCell", 600, 600);
332   // c1->SetLogy();
333   c1->SetFillColor(0);
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}>");  
340   h1->SetMinimum(0.) ; 
341   h1->SetMaximum(10.) ; 
342   if(fCalorimeter=="EMCAL") h1->SetMaximum(5.) ;
343   h1->Draw();
344   
345   TGraphErrors * AverNcells = new TGraphErrors(nRun, x, CellMean, xe, CellRMS);
346   
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");
355   }
356   
357   
358   
359   TLegend  * l1 = new TLegend(0.4, 0.6, 0.75, 0.85);
360   l1->SetFillColor(0);
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");
369   }
370   l1->Draw("same");
371   c1->Update();
372   
373   
374   TCanvas  * c200 = new TCanvas("ClusterAverages", "ClusterAverages", 1000, 500);
375   c200->SetFillColor(0);
376   c200->SetBorderSize(0);
377   c200->SetFrameBorderMode(0); 
378   c200->SetGrid();
379   
380   gPad->SetLeftMargin(0.08);
381   gPad->SetRightMargin(0.02);
382   gPad->SetGrid();
383   
384   TH1F * h2 = (TH1F*)dummy->Clone("");
385   
386   h2->GetYaxis()->SetTitle("<N_{clusters}>/event");  
387   
388   if (fTrigger=="EMC") h2->SetMaximum(70) ;
389   else                 h2->SetMaximum(50) ;
390   h2->SetMinimum(10) ; // for Pb Pb
391   h2->Draw();
392   
393   TGraphErrors * AverNclusters = new TGraphErrors(nRun, x, ClusterMean, xe, ClusterRMS);
394   AverNclusters->SetMarkerStyle(20);
395   AverNclusters->SetMarkerColor(1);
396   AverNclusters->Draw("same P") ;  
397   
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);
402     
403     AverNclustersSM[ism]->Draw("same P");  
404   }
405   
406   
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");
414   
415   for(Int_t ism = 0 ; ism < n ; ism++){
416     TString projname = Form("SM_ %d",ism);
417     l200->AddEntry(AverNclustersSM[ism],projname.Data(), "p");
418   }
419   
420   l200->Draw("same");
421   c200->Update();
422   c200->SaveAs(ClusterAveragesEntries);
423   
424   TCanvas  * c201 = new TCanvas("ClusterAveragesEnergy", "ClusterAveragesEnergy", 1000, 500);
425   c201->SetFillColor(0);
426   c201->SetBorderSize(0);
427   c201->SetFrameBorderMode(0); 
428   c201->SetGrid();
429   
430   
431   gPad->SetLeftMargin(0.08);
432   gPad->SetRightMargin(0.02);
433   gPad->SetGrid();
434   
435   
436   TH1F * h3 = (TH1F*)dummy->Clone("");
437   
438   h3->GetYaxis()->SetTitle("<E> (GeV)");  
439   h3->SetMinimum(0.2) ; 
440   h3->SetMaximum(1.) ; 
441   h3->Draw();
442   
443   TGraphErrors * AverE = new TGraphErrors(nRun, x, EtotalMean, xe, EtotalRMS);
444   AverE->SetMarkerStyle(20);
445   AverE->SetMarkerColor(1);
446   AverE->Draw("same P");
447   
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");
453     
454   }
455   
456   TLegend  * l3 = new TLegend(0.4, 0.6, 0.75, 0.85);
457   l3->SetFillColor(0);
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");
463   
464   for(Int_t ism = 0 ; ism < n ; ism++){
465     TString projname = Form("SM_ %d",ism);
466     l3->AddEntry(AverESM[ism],projname.Data(), "p");
467   }
468   
469   l3->Draw("same");
470   
471   c201->SaveAs(ClusterAveragesEnergy);
472   
473   
474   TCanvas  * c202 = new TCanvas("ClusterAveragesCells", "ClusterAveragesCells", 1000, 500);
475   c202->SetFillColor(0);
476   c202->SetBorderSize(0);
477   c202->SetFrameBorderMode(0); 
478   c202->SetGrid();
479   
480   gPad->SetLeftMargin(0.08);
481   gPad->SetRightMargin(0.02); 
482   
483   gPad->SetGrid();
484   
485   
486   TH1F * h4 = (TH1F*)dummy->Clone("");
487   
488   h4->GetYaxis()->SetTitle("<N_{CellsPerCluster}>");  
489   h4->SetMinimum(1.5) ; 
490   h4->SetMaximum(5.5) ; 
491   h4->Draw();
492   
493   
494   TGraphErrors * AverCellPerCluster = new TGraphErrors(nRun, x, CellPerClusterMean, xe, CellPerClusterRMS);
495   AverCellPerCluster->SetMarkerStyle(20);
496   AverCellPerCluster->SetMarkerColor(1);
497   
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");
503     
504   }
505   
506   TLegend  * l4 = new TLegend(0.4, 0.6, 0.75, 0.85);
507   l4->SetFillColor(0);
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");
513   
514   for(Int_t ism = 0 ; ism < n ; ism++){
515     TString projname = Form("SM_ %d",ism);
516     l4->AddEntry(AverNcellsPerClusterSM[ism],projname.Data(), "p");
517   }
518   
519   l4->Draw("same");
520   
521   c202->SaveAs(ClusterAveragesCells);
522   
523 }