]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/CaloTrackCorrelations/macros/QA/DrawAnaCaloTrackQA.C
plot rapidity not eta of primary photon
[u/mrichter/AliRoot.git] / PWGGA / CaloTrackCorrelations / macros / QA / DrawAnaCaloTrackQA.C
1 ///////////////////////////////////////////
2 //
3 // Macro to plot few selected histograms
4 // to QA data productions at 0th order
5 // Analysis performed with the wagon
6 // AddTaskPi0IMGammaCorrQA.C
7 // It generates 5 eps plots, each containing 2 to 4 canvases
8 //
9 // To execute: root -q -b -l DrawAnaCaloTrackQA.C'("Pi0IM_GammaTrackCorr_EMCAL_default","AnalysisResults.root")'
10 // The input list name might change depending on the wagon / data type
11 // In case output file is too large, possiblity to dump the list content in a sepate file:  export = kTRUE
12 //
13 // Author: Gustavo.Conesa.Balbastre@cern.ch
14 //
15 //
16
17 // Some global variables
18 TList *list = 0;
19 TFile *file = 0;
20 TString histoTag = "";
21 Int_t color[]={kBlack,kRed,kOrange+1,kYellow+1,kGreen+2,kBlue,kCyan+1,kViolet,kMagenta+2,kGray};
22
23 //_______________________________________________________________________
24 void DrawAnaCaloTrackQA(TString listName = "Pi0IM_GammaTrackCorr_EMCAL_default",
25                         TString fileName = "AnalysisResultsQATrain.root",
26                         Bool_t export = kFALSE)
27 {
28
29   printf("Open <%s>; Get List : <%s>; Export list? <%d>\n",fileName.Data(),listName.Data(),export);
30   
31   histoTag = listName;
32   
33   //Access the file and list of histograms, global variables
34   GetFileAndList(fileName, listName, export);
35   
36   gStyle->SetOptTitle(1);
37   gStyle->SetOptStat(0);
38   gStyle->SetOptFit(000000);
39   gStyle->SetPadRightMargin(0.15);
40   //gStyle->SetPadTopMargin(0.02);
41   //gStyle->SetPadLeftMargin(0.15);
42   gStyle->SetTitleFontSize(0.06);
43
44   //Plot basic Calorimeter QA
45   CaloQA();
46
47   //Plot basic Track QA
48   TrackQA();
49
50   //Plot basic Pi0 QA
51   Pi0QA();
52
53   //Plot basic correlation QA
54   CorrelationQA();
55   
56   // MC basic QA plots, cluster origins (only if it run on MC)
57   MCQA();
58 }
59
60 //___________
61 void CaloQA()
62 {
63   // Basic calorimeter QA histograms
64   
65   TCanvas * ccalo = new TCanvas(Form("CaloHisto_%s",histoTag.Data()),"",1000,1000);
66   ccalo->Divide(2,2);
67   
68   ccalo->cd(1);
69   gPad->SetLogy();
70   
71   TH1F* hCellAmplitude = (TH1F*) GetHisto("QA_hAmplitude");
72   TH1F* hClusterEnergy = (TH1F*) GetHisto("QA_hE");
73   
74   hClusterEnergy->SetYTitle("entries");
75   hClusterEnergy->SetTitle("Cluster-cell energy spectra");
76   hClusterEnergy->Sumw2();
77   hClusterEnergy->SetMarkerColor(1);
78   hClusterEnergy->SetMarkerStyle(20);
79   hClusterEnergy->SetAxisRange(0.,50.,"X");
80   hClusterEnergy->Draw();
81   
82   hCellAmplitude->Sumw2();
83   hCellAmplitude->SetMarkerColor(4);
84   hCellAmplitude->SetMarkerStyle(25);
85   hCellAmplitude->Draw("same");
86   
87   TLegend l(0.25,0.7,0.83,0.85);
88   l.SetTextSize(0.04);
89   l.AddEntry(hClusterEnergy,"Cluster (no exotic+non lin.)","P");
90   l.AddEntry(hCellAmplitude,"Cell","P");
91   l.SetBorderSize(0);
92   l.SetFillColor(0);
93   l.Draw();
94   
95   
96   ccalo->cd(2);
97   //gPad->SetLogy();
98   
99   TH1F* hRaw  = (TH1F*) GetHisto("AnaPhoton_hCut_0_Open");
100   TH1F* hCorr = (TH1F*) GetHisto("AnaPhoton_hCut_4_NCells");
101   TH1F* hTM   = (TH1F*) GetHisto("AnaPhoton_hCut_7_Matching");
102   TH1F* hShSh = (TH1F*) GetHisto("AnaPhoton_hCut_9_PID");
103   
104   hRaw->Sumw2();
105   
106   hCorr->SetTitle("Ratio after cluster cuts application");
107   hCorr->SetYTitle("Selected clusters / Raw clusters");
108   hCorr->SetTitleOffset(1.5,"Y");
109   hCorr->Sumw2();
110   hCorr->SetMarkerColor(1);
111   hCorr->SetMarkerStyle(20);
112   hCorr->Divide(hRaw);
113   hCorr->SetAxisRange(0.,30.,"X");
114   hCorr->SetMaximum(1.1);
115   hCorr->SetMinimum(0);
116   hCorr->Draw();
117   
118   hTM  ->Sumw2();
119   hTM  ->SetMarkerColor(2);
120   hTM  ->SetMarkerStyle(21);
121   hTM  ->Divide(hRaw);
122   hTM  ->Draw("same");
123   
124   hShSh->Sumw2();
125   hShSh->SetMarkerColor(4);
126   hShSh->SetMarkerStyle(22);
127   hShSh->Divide(hRaw);
128   hShSh->Draw("same");
129   
130   TLegend l2(0.45,0.8,0.95,0.93);
131   l2.SetTextSize(0.04);
132   l2.AddEntry(hCorr,"No Exotics + non lin.","P");
133   l2.AddEntry(hTM,  "+ Track matching","P");
134   l2.AddEntry(hShSh,"+ #lambda^{2}_{0} < 0.4","P");
135   l2.SetBorderSize(0);
136   l2.SetFillColor(0);
137   l2.Draw();
138   
139   
140   // Plot track-matching residuals
141   // first test did not have this histogram, add protection
142   TH2F* hTrackMatchResEtaPhi = (TH2F*) GetHisto("QA_hTrackMatchedDEtaDPhi");
143   if(hTrackMatchResEtaPhi)
144   {
145     ccalo->cd(3);
146     gPad->SetLogz();
147     
148     hTrackMatchResEtaPhi->SetAxisRange(-0.025,0.025,"X");
149     hTrackMatchResEtaPhi->SetAxisRange(-0.025,0.025,"Y");
150     hTrackMatchResEtaPhi->SetTitleOffset(1.5,"Y");
151     hTrackMatchResEtaPhi->SetTitle("Track-cluster residual #Delta #phi vs #Delta #eta, E > 0.5 GeV");
152     hTrackMatchResEtaPhi->SetXTitle("#Delta #eta");
153     hTrackMatchResEtaPhi->SetYTitle("#Delta #phi");
154     hTrackMatchResEtaPhi->SetZTitle("entries");
155     hTrackMatchResEtaPhi->Draw("colz");
156     
157     ccalo->cd(4);
158     gPad->SetLogy();
159     
160     TH2F* h2TrackMatchResEtaNeg = (TH2F*) GetHisto("QA_hTrackMatchedDEta");
161     TH2F* h2TrackMatchResEtaPos = (TH2F*) GetHisto("QA_hTrackMatchedDEtaPos");
162     TH2F* h2TrackMatchResPhiNeg = (TH2F*) GetHisto("QA_hTrackMatchedDPhi");
163     TH2F* h2TrackMatchResPhiPos = (TH2F*) GetHisto("QA_hTrackMatchedDPhiPos");
164     
165     h2TrackMatchResEtaNeg->Add(h2TrackMatchResEtaPos,-1);
166     h2TrackMatchResPhiNeg->Add(h2TrackMatchResPhiPos,-1);
167     
168     Float_t binMin = hCorr->FindBin(0.5);
169     TH1F* hTrackMatchResEtaNeg = (TH1F*) h2TrackMatchResEtaNeg->ProjectionY("TMProjEtaNeg",binMin, 1000);
170     TH1F* hTrackMatchResEtaPos = (TH1F*) h2TrackMatchResEtaPos->ProjectionY("TMProjEtaPos",binMin, 1000);
171     TH1F* hTrackMatchResPhiNeg = (TH1F*) h2TrackMatchResPhiNeg->ProjectionY("TMProjPhiNeg",binMin, 1000);
172     TH1F* hTrackMatchResPhiPos = (TH1F*) h2TrackMatchResPhiPos->ProjectionY("TMProjPhiPos",binMin, 1000);
173     
174     hTrackMatchResEtaNeg->SetXTitle("#Delta #eta, #Delta #phi");
175     hTrackMatchResEtaNeg->SetYTitle("entries");
176     hTrackMatchResEtaNeg->SetTitle("Track-cluster residuals, E > 1 GeV");
177     hTrackMatchResEtaNeg->SetAxisRange(-0.05,0.05,"X");
178     hTrackMatchResEtaNeg->Sumw2();
179     hTrackMatchResEtaNeg->SetMarkerStyle(25);
180     hTrackMatchResEtaNeg->SetMarkerColor(2);
181     hTrackMatchResEtaNeg->Draw("");
182     
183     hTrackMatchResEtaPos->Sumw2();
184     hTrackMatchResEtaPos->SetMarkerStyle(25);
185     hTrackMatchResEtaPos->SetMarkerColor(4);
186     hTrackMatchResEtaPos->Draw("same");
187     
188     hTrackMatchResPhiNeg->Sumw2();
189     hTrackMatchResPhiNeg->SetMarkerStyle(24);
190     hTrackMatchResPhiNeg->SetMarkerColor(2);
191     hTrackMatchResPhiNeg->Draw("same");
192     
193     hTrackMatchResPhiPos->Sumw2();
194     hTrackMatchResPhiPos->SetMarkerStyle(24);
195     hTrackMatchResPhiPos->SetMarkerColor(4);
196     hTrackMatchResPhiPos->Draw("same");
197     
198     TLine l0(0,hTrackMatchResEtaNeg->GetMinimum(),0,hTrackMatchResEtaNeg->GetMaximum()*1.2);
199     l0.Draw("same");
200     
201     TLegend l3(0.55,0.7,0.83,0.85);
202     l3.SetTextSize(0.04);
203     l3.AddEntry(hTrackMatchResEtaNeg,"#Delta #eta, Negative","P");
204     l3.AddEntry(hTrackMatchResEtaPos,"#Delta #eta, Positive","P");
205     l3.AddEntry(hTrackMatchResPhiNeg,"#Delta #phi, Negative","P");
206     l3.AddEntry(hTrackMatchResPhiPos,"#Delta #phi, Positive","P");
207     l3.SetBorderSize(0);
208     l3.SetFillColor(0);
209     l3.Draw();
210   }
211   ccalo->Print(Form("%s_CaloHisto.eps",histoTag.Data()));
212   
213   
214   TCanvas * ccalo2 = new TCanvas(Form("CaloHisto2_%s",histoTag.Data()),"",500,500);
215   ccalo2->Divide(2,2);
216   
217   ccalo2->cd(3);
218 //  gPad->SetLogz();
219 //  TH2F* hCellAmpId   = (TH2F*) GetHisto("QA_hAmpId");
220 //  hCellAmpId->SetTitle("Cell Id vs energy");
221 //  hCellAmpId->SetYTitle("Cell Id");
222 //  //hCellAmpId->SetAxisRange(300.,900.,"Y");
223 //  hCellAmpId->SetAxisRange(0.,30.,"X");
224 //  hCellAmpId->SetTitleOffset(1.5,"Y");
225 //  hCellAmpId->Draw("colz");
226
227   gPad->SetLogz();
228   
229   TH2F* hClusterTime   = (TH2F*) GetHisto("QA_hClusterTimeEnergy");
230   hClusterTime->SetTitle("Cluster energy vs time");
231   hClusterTime->SetYTitle("time (ns)");
232   hClusterTime->SetAxisRange(300.,900.,"Y");
233   hClusterTime->SetAxisRange(0.,30.,"X");
234   hClusterTime->SetTitleOffset(1.5,"Y");
235   hClusterTime->Draw("colz");
236   
237   ccalo2->cd(1);
238   
239   TH2F* hCellActivity  = (TH2F*) GetHisto("QA_hGridCells");
240   hCellActivity->SetTitle("Hits per cell (E > 0.2 GeV)");
241   hCellActivity->SetTitleOffset(1.5,"Y");
242   hCellActivity->Draw("colz");
243   
244   ccalo2->cd(2);
245   
246   TH2F* hCellActivity  = (TH2F*) GetHisto("QA_hGridCells");
247   TH2F* hCellActivityE = (TH2F*) GetHisto("QA_hGridCellsE");
248   hCellActivityE->SetTitle("Mean energy per cell (E > 0.2 GeV)");
249   hCellActivityE->Divide(hCellActivity);
250   hCellActivityE->SetTitleOffset(1.5,"Y");
251   hCellActivityE->Draw("colz");
252   
253   ccalo2->cd(4);
254   //gPad->SetLogz();
255   TH2F* hClusterActivity  = (TH2F*) GetHisto("AnaPhoton_hEtaPhi");
256   hClusterActivity->SetTitle("Clusters activity (E > 0.5 GeV)");
257   hClusterActivity->SetTitleOffset(1.5,"Y");
258   hClusterActivity->Draw("colz");
259   
260   ccalo2->Print(Form("%s_CaloHisto2.eps",histoTag.Data()));
261   
262 }
263
264 //____________
265 void TrackQA()
266 {
267   // Basic hybrid tracks histograms
268   
269   TCanvas * ctrack = new TCanvas(Form("TrackHisto_%s",histoTag.Data()),"",1000,500);
270   ctrack->Divide(2,1);
271   
272   ctrack->cd(1);
273   //gPad->SetLogz();
274   TH2F * hTrackEtaPhi = (TH2F*) GetHisto("AnaHadrons_hEtaPhiNegative");
275   hTrackEtaPhi ->Add((TH2F*) GetHisto("AnaHadrons_hEtaPhiNegative"));
276   hTrackEtaPhi ->SetAxisRange(-0.9,0.9,"X");
277   hTrackEtaPhi ->SetTitle("Hybrid tracks #eta vs #phi (p_{T} > 0.2 GeV)");
278   hTrackEtaPhi ->Draw("colz");
279   
280   ctrack->cd(2);
281   //gPad->SetLogy();
282   TH2F * hTrackEtaPhiSPD   = (TH2F*) GetHisto("AnaHadrons_hEtaPhiSPDRefitPt02");
283   TH2F * hTrackEtaPhiNoSPD = (TH2F*) GetHisto("AnaHadrons_hEtaPhiNoSPDRefitPt02");
284   
285   TH1F* hPhiSPD   = (TH1F*)hTrackEtaPhiSPD  ->ProjectionY("hTrackPhiSPD"  ,0,1000);
286   TH1F* hPhiNoSPD = (TH1F*)hTrackEtaPhiNoSPD->ProjectionY("hTrackPhiNoSPD",0,1000);
287   //TH1F* hPhi      = (TH1F*)hTrackEtaPhi     ->ProjectionY("hTrackPhi"     ,0,1000);
288   TH1F* hPhi      = hPhiSPD->Clone("hTrackPhi");
289   hPhi->Add(hPhiNoSPD);
290   hPhi     ->SetTitle("Hybrid track in #phi, composition, p_{T} > 0.2 GeV");
291   hPhi     ->SetLineColor(1);
292   hPhiSPD  ->SetLineColor(2);
293   hPhiNoSPD->SetLineColor(4);
294   
295   hPhi     ->SetMinimum(1);
296   hPhi     ->SetMaximum(hPhi->GetMaximum()*1.2);
297   
298   hPhi     ->Draw("H");
299   hPhiSPD  ->Draw("Hsame");
300   hPhiNoSPD->Draw("Hsame");
301   
302   TLegend l(0.2,0.75,0.4,0.89);
303   l.SetTextSize(0.04);
304   l.AddEntry(hPhi,"Sum","L");
305   l.AddEntry(hPhiSPD  ,"SPD+Refit","L");
306   l.AddEntry(hPhiNoSPD,"No SPD+Refit","L");
307   l.SetBorderSize(0);
308   l.SetFillColor(0);
309   l.Draw();
310 //  ctrack->cd(3);
311 //  gPad->SetLogz();
312 //  
313 //  TH2F* hPtDCAxy = (TH2F*) GetHisto("AnaHadrons_hPtDCAxy");
314 //  hPtDCAxy->SetAxisRange(-1,1,"Y");
315 //  hPtDCAxy->SetAxisRange(0,30,"X");
316 //  hPtDCAxy->Draw("colz");
317 //  
318 //  ctrack->cd(4);
319 //  gPad->SetLogz();
320 //  
321 //  TH2F* hPtDCAz = (TH2F*) GetHisto("AnaHadrons_hPtDCAz");
322 //  hPtDCAz->SetAxisRange(-1,1,"Y");
323 //  hPtDCAz->SetAxisRange(0,30,"X");
324 //  hPtDCAz->Draw("colz");
325   
326   ctrack->Print(Form("%s_TrackHisto.eps",histoTag.Data()));
327   
328 }
329
330 //__________
331 void Pi0QA()
332 {
333   // Basic invariant mass QA
334   
335   TCanvas * cpi0 = new TCanvas(Form("Pi0Histo_%s",histoTag.Data()),"",500,500);
336   cpi0->Divide(2,2);
337   
338   TH2F* hMassE[10];
339   TH2F* hMixMassE[10];
340   for(Int_t icen = 0; icen < 10; icen++)
341   {
342     hMassE   [icen] = (TH2F*) GetHisto(Form("AnaPi0_hRe_cen%d_pidbit0_asy1_dist1",icen));
343     hMixMassE[icen] = (TH2F*) GetHisto(Form("AnaPi0_hMi_cen%d_pidbit0_asy1_dist1",icen));
344   }
345   
346   // 2D Invariant mass vs E, in PbPb from 60 to 100 %, all in pp
347   cpi0->cd(1);
348   gPad->SetLogz();
349   TH2F* h2DMass;
350   
351   if(hMassE[1]) // Plot centrality from 60 to 100%
352   {
353     h2DMass = (TH2F*) hMassE[6]->Clone("h2DMass");
354     for(Int_t icen = 7; icen < 10; icen++) h2DMass->Add(hMassE[icen]);
355     h2DMass->SetTitle("Invariant mass vs pair E, Cen: 60-100%");
356   }
357   else
358   {
359     h2DMass = (TH2F*) hMassE[0]->Clone("hMassProj");
360     h2DMass->SetTitle("Invariant mass vs cluster pair E");
361   }
362   
363   h2DMass->SetTitleOffset(1.6,"Y");
364   h2DMass->SetAxisRange(0.0,0.7,"Y");
365   h2DMass->SetAxisRange(0,30,"X");
366   h2DMass->Draw("colz");
367   
368   // Pi0 Invariant mass projection, in PbPb 6 centrality bins from 0 to 50%, all in pp
369   cpi0->cd(2);
370   TH1F* hMass   [10];
371   TH1F* hMix    [10];
372   TH1F* hMassEta[10];
373   TH1F* hMassPi0[10];
374   
375   //Init to 0
376   for(Int_t icen=0; icen<10; icen++ )
377   {
378     hMass   [icen] = 0;
379     hMix    [icen] = 0;
380     hMassEta[icen] = 0;
381     hMassPi0[icen] = 0;
382   }
383   
384   TH1F * hX = (TH1F*) hMassE[0]->ProjectionX("hEPairCen0",0,10000);
385   Int_t binmin = hX->FindBin(2);  // Project histo from 2 GeV pairs
386   Int_t binmax = hX->FindBin(10); // Project histo up to 10 GeV pairs
387   Float_t maxPi0 = 0;
388   Float_t maxEta = 0;
389   for(Int_t icen = 0; icen < 6; icen++)
390   {
391     if(!hMassE[icen]) continue;
392
393     hMass[icen] = (TH1F*) hMassE   [icen]->ProjectionY(Form("hMassCen%d",icen),binmin,binmax);
394     hMix [icen] = (TH1F*) hMixMassE[icen]->ProjectionY(Form("hMixCen%d" ,icen),binmin,binmax);
395     hMass[icen]->Sumw2();
396     hMix [icen]->Sumw2();
397     
398     hMassPi0[icen] = (TH1F*) hMass[icen]->Clone(Form("hMassPi0Cen%d",icen));
399     hMassEta[icen] = (TH1F*) hMass[icen]->Clone(Form("hMassEtaCen%d",icen));
400     
401     hMassPi0[icen]->Divide(hMix[icen]);
402     hMassPi0[icen]->Fit("pol0","Q","",0.25,0.35);
403     Float_t scale = 1;
404     if(hMassPi0[icen]->GetFunction("pol0")) scale = hMassPi0[icen]->GetFunction("pol0")->GetParameter(0);
405     //printf("Scale factor %f for cen %d\n",scale,icen);
406     hMassPi0[icen]->Scale(1./scale);
407     hMassPi0[icen]->SetMarkerStyle(24);
408     hMassPi0[icen]->SetMarkerColor(color[icen]);
409     hMassPi0[icen]->SetLineColor(color[icen]);
410     hMassPi0[icen]->SetAxisRange(0.04,0.24);
411     hMassPi0[icen]->SetMarkerSize(0.5);
412     
413     hMassEta[icen]->Rebin(4);
414     hMix    [icen]->Rebin(4);
415     hMassEta[icen]->Divide(hMix[icen]);
416     hMassEta[icen]->SetMarkerStyle(25);
417     hMassEta[icen]->SetMarkerColor(color[icen]);
418     hMassEta[icen]->SetLineColor(color[icen]);
419     hMassEta[icen]->SetAxisRange(0.4,0.9);
420     hMassEta[icen]->SetMarkerSize(0.5);
421     hMassEta[icen]->Scale(1./scale);
422     
423     if(maxEta < hMassEta[icen]->GetMaximum()) maxEta = hMassEta[icen]->GetMaximum();
424     if(maxPi0 < hMassPi0[icen]->GetMaximum()) maxPi0 = hMassPi0[icen]->GetMaximum();
425   }
426
427   //gPad->SetLogy();
428   //gPad->SetGridy();
429   hMassPi0[0]->SetMinimum(0.8);
430   hMassPi0[0]->SetTitleOffset(1.6,"Y");
431   hMassPi0[0]->SetYTitle("Real / Mixed");
432   hMassPi0[0]->SetTitle("#pi^{0} peak, 2 < E_{pair}< 10 GeV");
433   hMassPi0[0]->Draw();
434   
435   if(hMass[1]) // PbPb
436   {
437     hMassPi0[0]->SetMaximum(maxPi0*1.2);
438     hMassPi0[5]->Draw("Hsame");
439     hMassPi0[4]->Draw("Hsame");
440     hMassPi0[3]->Draw("Hsame");
441     hMassPi0[2]->Draw("Hsame");
442     hMassPi0[1]->Draw("Hsame");
443     hMassPi0[0]->Draw("Hsame");
444     //hMass[6]->Draw("Hsame");
445     //hMass[7]->Draw("same");
446     //hMass[8]->Draw("same");
447     //hMass[9]->Draw("same");
448     
449     TLegend l(0.12,0.6,0.4,0.85);
450     l.SetTextSize(0.04);
451     l.AddEntry(hMassPi0[0],"0-10%","P");
452     l.AddEntry(hMassPi0[1],"10-20%","P");
453     l.AddEntry(hMassPi0[2],"20-30%","P");
454     l.AddEntry(hMassPi0[3],"30-40%","P");
455     l.AddEntry(hMassPi0[4],"40-70%","P");
456     l.AddEntry(hMassPi0[5],"50-60%","P");
457     l.SetBorderSize(0);
458     l.SetFillColor(0);
459     l.Draw();
460   }
461
462   TLine l1(0.04,1,0.24,1);
463   l1.Draw("same");
464   
465   // Pi0 invariant mass per EMCal super module
466   cpi0->cd(3);
467   
468   TH1F* hSM   [10];
469   TH1F* hMixSM[10];
470   binmin = hX->FindBin(4);  // Project histo from 3 GeV pairs
471   binmax = hX->FindBin(20); // Project histo up to 20 GeV pairs
472   Float_t maxSM = 0;
473
474   for(Int_t ism = 0; ism < 10; ism++)
475   {
476     TH2F* hTmpSM = (TH2F*) GetHisto(Form("AnaPi0_hReMod_%d",ism));
477     if(!hTmpSM) hTmpSM = (TH2F*) GetHisto(Form("QA_hIM_Mod%d",ism));
478     
479     hSM[ism] = (TH1F*) hTmpSM->ProjectionY(Form("hMassSM%d",ism),binmin,binmax);
480     hSM[ism]->Sumw2();
481     hSM[ism]->SetMarkerStyle(26);
482     hSM[ism]->Rebin(2);
483     //hSM[ism]->Scale(1./hSM[ism]->Integral(0,10000));
484     hSM[ism]->SetMarkerColor(color[ism]);
485     hSM[ism]->SetLineColor(color[ism]);
486     hSM[ism]->SetMarkerSize(0.5);
487
488     TH2F* hTmpMixSM = (TH2F*) GetHisto(Form("AnaPi0_hMiMod_%d",ism));
489     if(hTmpMixSM)
490     {
491       hMixSM[ism] = (TH1F*) hTmpMixSM->ProjectionY(Form("hMassMixSM%d",ism),binmin,binmax);
492       hMixSM[ism]->Sumw2();
493       hMixSM[ism]->Rebin(2);
494       hSM[ism]->Divide(hMixSM[ism]);
495       hSM[ism]->Fit("pol0","Q","",0.25,0.35);
496       Float_t scale = 1;
497       if(hSM[ism]->GetFunction("pol0")) scale = hSM[ism]->GetFunction("pol0")->GetParameter(0);
498       //printf("Scale factor %f for cen %d\n",scale,icen);
499       hSM[ism]->Scale(1./scale);
500       hSM[ism]->SetYTitle("Real / Mixed");
501
502     }
503     
504     if(maxSM < hSM[ism]->GetMaximum()) maxSM = hSM[ism]->GetMaximum();
505
506   }
507   
508   hSM[0]->SetTitle("#pi^{0} peak in Modules, 4 < E_{pair}< 10 GeV");
509   hSM[0]->SetTitleOffset(1.6,"Y");
510   hSM[0]->SetAxisRange(0.04,0.24);
511   hSM[0]->SetMaximum(maxSM*1.2);
512   hSM[0]->SetMinimum(0.8);
513
514   hSM[0]->Draw("H");
515   TLegend lsm(0.12,0.5,0.35,0.85);
516   lsm.SetTextSize(0.04);
517   lsm.AddEntry(hSM[0],Form("Mod %d",0),"P");
518   
519   for(Int_t ism = 1; ism < 10; ism++)
520   {
521     hSM[ism]->Draw("Hsame");
522     lsm.AddEntry(hSM[ism],Form("Mod %d",ism),"P");
523   }
524   
525   lsm.SetBorderSize(0);
526   lsm.SetFillColor(0);
527   lsm.Draw();
528   
529   l1.Draw("same");
530   
531   // Pi0 Invariant mass projection, in PbPb 6 centrality bins from 0 to 50%, all in pp
532   cpi0->cd(4);
533   
534   //gPad->SetLogy();
535   //gPad->SetGridy();
536   hMassEta[0]->SetMinimum(0.8);
537   hMassEta[0]->SetTitleOffset(1.6,"Y");
538   hMassEta[0]->SetYTitle("Real / Mixed");
539   hMassEta[0]->SetTitle("#eta peak, 2 < E_{pair}< 10 GeV");
540   hMassEta[0]->Draw("H");
541   
542   if(hMass[1]) // PbPb
543   {
544     hMassEta[0]->SetMaximum(maxEta*1.2);
545     hMassEta[5]->Draw("Hsame");
546     hMassEta[4]->Draw("Hsame");
547     hMassEta[3]->Draw("Hsame");
548     hMassEta[2]->Draw("Hsame");
549     hMassEta[1]->Draw("Hsame");
550     hMassEta[0]->Draw("Hsame");
551     
552     
553     TLegend l2(0.12,0.6,0.4,0.85);
554     l2.SetTextSize(0.04);
555     l2.AddEntry(hMassEta[0],"0-10%","P");
556     l2.AddEntry(hMassEta[1],"10-20%","P");
557     l2.AddEntry(hMassEta[2],"20-30%","P");
558     l2.AddEntry(hMassEta[3],"30-40%","P");
559     l2.AddEntry(hMassEta[4],"40-70%","P");
560     l2.AddEntry(hMassEta[5],"50-60%","P");
561     l2.SetBorderSize(0);
562     l2.SetFillColor(0);
563     l2.Draw();
564   }
565
566   cpi0->Print(Form("%s_Pi0Histo.eps",histoTag.Data()));
567   
568 }
569
570 //__________________
571 void CorrelationQA()
572 {
573
574   TCanvas * cCorrelation = new TCanvas(Form("CorrelationHisto_%s",histoTag.Data()),"",1000,500);
575   cCorrelation->Divide(2,1);
576   
577   Float_t minClusterE = 8;
578   Float_t assocBins[] = {0.5,2.,5.,10.,20.};
579   Int_t nAssocBins = 4;
580   
581   TH1F * hLeading = (TH1F*) GetHisto("AnaPhotonHadronCorr_hPtLeading");
582   Int_t minClusterEBin = hLeading->FindBin(minClusterE);
583   Float_t nTrig = hLeading->Integral(minClusterE,100000);
584   
585   //Azimuthal correlation
586   cCorrelation->cd(1);
587   gPad->SetLogy();
588   TH1F* hDeltaPhi[4];
589   
590   TLegend l(0.35,0.6,0.83,0.85);
591   l.SetHeader(Form("p_{T,T} > %2.1f GeV/c",minClusterE));
592   l.SetTextSize(0.04);
593   l.SetBorderSize(0);
594   l.SetFillColor(0);
595
596   for(Int_t ibin = 0; ibin < nAssocBins; ibin++ )
597   {
598     TH2F* hDeltaPhiE = (TH2F*) GetHisto(Form("AnaPhotonHadronCorr_hDeltaPhiPtAssocPt%2.1f_%2.1f",assocBins[ibin],assocBins[ibin+1]));
599     hDeltaPhi[ibin]  = (TH1F*) hDeltaPhiE->ProjectionY(Form("DeltaPhi%2.1f",assocBins[ibin]),minClusterEBin,10000);
600     hDeltaPhi[ibin]->Sumw2();
601     hDeltaPhi[ibin]->Rebin(2);
602     hDeltaPhi[ibin]->Scale(1./nTrig);
603
604     hDeltaPhi[ibin]->Fit("pol0","Q","",1,2);
605     Float_t scale = 1;
606     if(hDeltaPhi[ibin]->GetFunction("pol0"))
607     {
608       scale = hDeltaPhi[ibin]->GetFunction("pol0")->GetParameter(0);
609       hDeltaPhi[ibin]->GetFunction("pol0")->SetRange(6,7); // move from plot
610     }
611     hDeltaPhi[ibin]->Scale(1./scale);
612     //printf("ibin %d, scale %f\n",ibin,scale);
613
614     hDeltaPhi[ibin]->SetAxisRange(-1.6,4.7);
615
616     hDeltaPhi[ibin]->SetMarkerStyle(24);
617     hDeltaPhi[ibin]->SetMarkerColor(color[ibin]);
618     hDeltaPhi[ibin]->SetLineColor(color[ibin]);
619     hDeltaPhi[ibin]->SetTitleOffset(1.5,"Y");
620     hDeltaPhi[ibin]->SetYTitle("N_{pairs} / N_{trig} / ZYAM");
621     hDeltaPhi[ibin]->SetTitle("#gamma (#lambda_{0}^{2} < 0.4, neutral cluster) trigger");
622     
623     l.AddEntry(hDeltaPhi[ibin],Form("%2.1f< p_{T,A}< %2.1f GeV/c",assocBins[ibin],assocBins[ibin+1]),"P");
624   }
625   
626   
627   hDeltaPhi[2]->SetMaximum(hDeltaPhi[2]->GetMaximum()*10);
628   hDeltaPhi[2]->SetMinimum(0.8);
629   
630    hDeltaPhi[2]->Draw("H");
631    hDeltaPhi[1]->Draw("Hsame");
632    hDeltaPhi[3]->Draw("Hsame");
633    hDeltaPhi[0]->Draw("Hsame");
634   
635   l.Draw("same");
636   
637   
638   // xE correlation
639   cCorrelation->cd(2);
640   gPad->SetLogy();
641   
642   TLegend l2(0.35,0.6,0.83,0.85);
643   l2.SetHeader(Form("p_{T,T} > %2.1f GeV/c",minClusterE));
644   l2.SetTextSize(0.04);
645   l2.SetBorderSize(0);
646   l2.SetFillColor(0);
647   
648   TH2F* hEXE   = (TH2F*) GetHisto("AnaPhotonHadronCorr_hXECharged");
649   TH2F* hEXEUE = (TH2F*) GetHisto("AnaPhotonHadronCorr_hXEUeCharged");
650   
651   TH1F* hXE  = (TH1F*) hEXE->ProjectionY(Form("XE%2.1fGeV",minClusterE),minClusterEBin,10000);
652   hXE->Sumw2();
653   hXE->Rebin(2);
654   hXE->Scale(1./nTrig);
655   hXE->SetAxisRange(0,1);
656   hXE->SetMarkerStyle(24);
657   hXE->SetMarkerColor(1);
658   hXE->SetLineColor(1);
659   hXE->SetTitleOffset(1.5,"Y");
660   hXE->SetYTitle("N_{pairs} / N_{trig}");
661   hXE->SetTitle("#gamma (#lambda_{0}^{2} < 0.4, neutral cluster) trigger");
662   l2.AddEntry(hXE,"raw x_{E}","P");
663   hXE->Draw();
664
665   TH1F* hXEUE  = (TH1F*) hEXEUE->ProjectionY(Form("XEUE%2.1fGeV",minClusterE),minClusterEBin,10000);
666   hXEUE->Sumw2();
667   hXEUE->Rebin(2);
668   hXEUE->Scale(1./nTrig);
669   hXEUE->SetAxisRange(0,1);
670   hXEUE->SetMarkerStyle(25);
671   hXEUE->SetMarkerColor(2);
672   hXEUE->SetLineColor(2);
673   l2.AddEntry(hXEUE,"raw Und. Event x_{E}","P");
674   hXEUE->Draw("same");
675
676   
677   l2.Draw("same");
678
679   
680   cCorrelation->Print(Form("%s_CorrelationHisto.eps",histoTag.Data()));
681
682 }
683
684 //___________
685 void MCQA()
686 {
687   // Basic calorimeter QA histograms
688   
689   TH2F* h2ClusterPho = (TH2F*) GetHisto("QA_hRecoMCE_Photon_Match0");    // not track-matched
690   TH2F* h2ClusterPi0 = (TH2F*) GetHisto("QA_hRecoMCE_Pi0_Match0");       // not track-matched
691   TH2F* h2ClusterEta = (TH2F*) GetHisto("QA_hRecoMCE_Eta_Match0");       // not track-matched
692   TH2F* h2ClusterEle = (TH2F*) GetHisto("QA_hRecoMCE_Electron_Match1");  // Track-matched
693   
694   if(!h2ClusterPho) return;
695   
696   
697   TH1F* hPrimPho = (TH1F*) GetHisto("QA_hGenMCAccE_Photon");
698   TH1F* hPrimPi0 = (TH1F*) GetHisto("QA_hGenMCAccE_Pi0");
699   TH1F* hPrimEta = (TH1F*) GetHisto("QA_hGenMCAccE_Eta");
700   
701   TCanvas * cmc = new TCanvas(Form("MCHisto_%s",histoTag.Data()),"",1000,1000);
702   cmc->Divide(2,2);
703   
704   cmc->cd(1);
705   gPad->SetLogy();
706   
707   TH1F* hClusterPho = (TH1F*) h2ClusterPho->ProjectionX("ClusterPho",0,1000);
708   TH1F* hClusterPi0 = (TH1F*) h2ClusterPi0->ProjectionX("ClusterPi0",0,1000);
709   TH1F* hClusterEta = (TH1F*) h2ClusterEta->ProjectionX("ClusterEta",0,1000);
710   
711   hClusterPho->SetTitle("Cluster origin spectra, primary spectra in Calo acceptance");
712   hClusterPho->Sumw2();
713   hClusterPho->SetMarkerColor(1);
714   hClusterPho->SetMarkerStyle(20);
715   hClusterPho->SetAxisRange(0.,50.,"X");
716   hClusterPho->SetXTitle("E_{rec,gen} (GeV)");
717   hClusterPho->Draw("");
718
719   hClusterPi0->Sumw2();
720   hClusterPi0->SetMarkerColor(4);
721   hClusterPi0->SetMarkerStyle(21);
722   hClusterPi0->Draw("same");
723
724   hClusterEta->Sumw2();
725   hClusterEta->SetMarkerColor(2);
726   hClusterEta->SetMarkerStyle(22);
727   hClusterEta->Draw("same");
728
729   hPrimPho->Sumw2();
730   hPrimPho->SetMarkerColor(1);
731   hPrimPho->SetMarkerStyle(24);
732   hPrimPho->Draw("same");
733   
734   hPrimPi0->Sumw2();
735   hPrimPi0->SetMarkerColor(4);
736   hPrimPi0->SetMarkerStyle(25);
737   hPrimPi0->Draw("same");
738   
739   hPrimEta->Sumw2();
740   hPrimEta->SetMarkerColor(2);
741   hPrimEta->SetMarkerStyle(26);
742   hPrimEta->Draw("same");
743   
744   TLegend l(0.45,0.6,0.83,0.89);
745   l.SetTextSize(0.04);
746   l.AddEntry(hClusterPho,"#gamma cluster","P");
747   l.AddEntry(hClusterPi0,"#pi^{0} (merged) cluster","P");
748   l.AddEntry(hClusterEta,"#eta (merged) cluster","P");
749   l.AddEntry(hPrimPho,"#gamma generated","P");
750   l.AddEntry(hPrimPi0,"#pi^{0} generated","P");
751   l.AddEntry(hPrimEta,"#eta generated","P");
752   l.SetBorderSize(0);
753   l.SetFillColor(0);
754   l.Draw();
755   
756   
757   cmc->cd(2);
758   gPad->SetLogy();
759   TH1F* hRatPho = (TH1F*) hClusterPho->Clone("hGenRecoPho");
760   TH1F* hRatPi0 = (TH1F*) hClusterPi0->Clone("hGenRecoPi0");
761   TH1F* hRatEta = (TH1F*) hClusterEta->Clone("hGenRecoEta");
762   
763   hRatPho->Divide(hPrimPho);
764   hRatPi0->Divide(hPrimPi0);
765   hRatEta->Divide(hPrimEta);
766   
767   hRatPho->SetTitle("Reconstructed cluster / Generated particle in Calo acc.");
768   hRatPho->SetYTitle("Ratio");
769   hRatPho->SetXTitle("E(GeV)");
770   hRatPho->SetMinimum(1e-3);
771   hRatPho->SetMaximum(10);
772   hRatPho->Draw("");
773   hRatPi0->Draw("same");
774   hRatEta->Draw("same");
775
776   TLegend l2(0.15,0.7,0.3,0.85);
777   l2.SetTextSize(0.04);
778   l2.AddEntry(hRatPho,"#gamma","P");
779   l2.AddEntry(hRatPi0,"#pi^{0}","P");
780   l2.AddEntry(hRatEta,"#eta","P");
781   l2.SetBorderSize(0);
782   l2.SetFillColor(0);
783   l2.Draw();
784
785   cmc->cd(3);
786   //gPad->SetLogy();
787
788   TH2F* h2PrimPhoPhi = (TH2F*) GetHisto("AnaPhoton_hPhiPrim_MCPhoton");
789   TH2F* h2PrimPi0Phi = (TH2F*) GetHisto("AnaPi0_hPrimPi0Phi");
790   TH2F* h2PrimEtaPhi = (TH2F*) GetHisto("AnaPi0_hPrimEtaPhi");
791   
792   Int_t binMin = hPrimPho->FindBin(3);
793   
794   TH1F* hPrimPhoPhi = (TH1F*) h2PrimPhoPhi->ProjectionY("PrimPhoPhi",binMin,1000);
795   TH1F* hPrimPi0Phi = (TH1F*) h2PrimPi0Phi->ProjectionY("PrimPi0Phi",binMin,1000);
796   TH1F* hPrimEtaPhi = (TH1F*) h2PrimEtaPhi->ProjectionY("PrimEtaPhi",binMin,1000);
797
798   hPrimPhoPhi->Scale(1./hPrimPhoPhi->Integral(0,1000));
799   hPrimPi0Phi->Scale(1./hPrimPi0Phi->Integral(0,1000));
800   hPrimEtaPhi->Scale(1./hPrimEtaPhi->Integral(0,1000));
801
802   Float_t maxPhi = hPrimPhoPhi->GetMaximum();
803   if(maxPhi < hPrimPi0Phi->GetMaximum()) maxPhi =  hPrimPi0Phi->GetMaximum();
804   if(maxPhi < hPrimEtaPhi->GetMaximum()) maxPhi =  hPrimEtaPhi->GetMaximum();
805
806   Float_t minPhi = hPrimPhoPhi->GetMinimum();
807   if(minPhi > hPrimPi0Phi->GetMinimum()) minPhi =  hPrimPi0Phi->GetMinimum();
808   if(minPhi > hPrimEtaPhi->GetMinimum()) minPhi =  hPrimEtaPhi->GetMinimum();
809
810   hPrimPi0Phi->SetMaximum(maxPhi*1.1);
811   hPrimPi0Phi->SetMinimum(minPhi);
812   TGaxis::SetMaxDigits(3);
813
814   hPrimPi0Phi->SetYTitle("1/total entries dN/d#phi");
815   hPrimPi0Phi->SetTitle("Generated particles #phi for E > 3 GeV");
816   hPrimPi0Phi->SetTitleOffset(1.6,"Y");
817   hPrimPi0Phi->Sumw2();
818   hPrimPi0Phi->SetMarkerColor(4);
819   hPrimPi0Phi->SetMarkerStyle(21);
820   hPrimPi0Phi->Draw("");
821   
822   hPrimPhoPhi->Sumw2();
823   hPrimPhoPhi->SetMarkerColor(1);
824   hPrimPhoPhi->SetMarkerStyle(20);
825   Float_t scale = TMath::RadToDeg();
826   ScaleXaxis(hPrimPhoPhi, TMath::RadToDeg());
827   hPrimPhoPhi->Draw("same");
828
829
830   hPrimEtaPhi->Sumw2();
831   hPrimEtaPhi->SetMarkerColor(2);
832   hPrimEtaPhi->SetMarkerStyle(22);
833   hPrimEtaPhi->Draw("same");
834
835   cmc->cd(4);
836   //gPad->SetLogy();
837   
838   TH2F* h2PrimPhoEta = (TH2F*) GetHisto("AnaPhoton_hYPrim_MCPhoton");
839   TH2F* h2PrimPi0Eta = (TH2F*) GetHisto("AnaPi0_hPrimPi0Rapidity");
840   TH2F* h2PrimEtaEta = (TH2F*) GetHisto("AnaPi0_hPrimEtaRapidity");
841   
842   Int_t binMin = hPrimPho->FindBin(3);
843   
844   TH1F* hPrimPhoEta = (TH1F*) h2PrimPhoEta->ProjectionY("PrimPhoEta",binMin,1000);
845   TH1F* hPrimPi0Eta = (TH1F*) h2PrimPi0Eta->ProjectionY("PrimPi0Eta",binMin,1000);
846   TH1F* hPrimEtaEta = (TH1F*) h2PrimEtaEta->ProjectionY("PrimEtaEta",binMin,1000);
847   
848   hPrimPhoEta->Scale(1./hPrimPhoEta->Integral(0,1000));
849   hPrimPi0Eta->Scale(1./hPrimPi0Eta->Integral(0,1000));
850   hPrimEtaEta->Scale(1./hPrimEtaEta->Integral(0,1000));
851   
852   Float_t maxEta = hPrimPhoEta->GetMaximum();
853   if(maxEta < hPrimPi0Eta->GetMaximum()) maxEta =  hPrimPi0Eta->GetMaximum();
854   if(maxEta < hPrimEtaEta->GetMaximum()) maxEta =  hPrimEtaEta->GetMaximum();
855   
856   Float_t minEta = hPrimPhoEta->GetMinimum();
857   if(minEta > hPrimPi0Eta->GetMinimum()) minEta =  hPrimPi0Eta->GetMinimum();
858   if(minEta > hPrimEtaEta->GetMinimum()) minEta =  hPrimEtaEta->GetMinimum();
859   
860   hPrimPi0Eta->SetMaximum(maxEta*1.1);
861   hPrimPi0Eta->SetMinimum(minEta);
862   TGaxis::SetMaxDigits(3);
863   
864   hPrimPi0Eta->SetYTitle("1/total entries dN/d#eta");
865   hPrimPi0Eta->SetTitle("Generated particles #eta for E > 3 GeV");
866   hPrimPi0Eta->SetTitleOffset(1.6,"Y");
867   hPrimPi0Eta->Sumw2();
868   hPrimPi0Eta->SetMarkerColor(4);
869   hPrimPi0Eta->SetMarkerStyle(21);
870   hPrimPi0Eta->Draw("");
871   
872   hPrimPhoEta->Sumw2();
873   hPrimPhoEta->SetMarkerColor(1);
874   hPrimPhoEta->SetMarkerStyle(20);
875   Float_t scale = TMath::RadToDeg();
876   hPrimPhoEta->Draw("same");
877   
878   hPrimEtaEta->Sumw2();
879   hPrimEtaEta->SetMarkerColor(2);
880   hPrimEtaEta->SetMarkerStyle(22);
881   hPrimEtaEta->Draw("same");
882   
883   cmc->Print(Form("%s_MCHisto.eps",histoTag.Data()));
884
885
886
887   
888  }
889
890
891 //____________________________________________________________________
892 void GetFileAndList(TString fileName, TString listName, Bool_t export)
893 {
894   file  = new TFile(fileName,"read");
895   
896   TDirectory * dir = (TDirectory*) file->Get(listName);
897   if(dir)
898   {
899     list = (TList*) dir->Get(listName);
900     if(export)
901     {
902       TFile * outputFile = new TFile("AnalysisResultsList.root","RECREATE");
903       list->Write();
904       outputFile->Close();
905     }
906   }
907 }
908
909 //___________________________________
910 TObject * GetHisto(TString histoName)
911 {
912   // Check if the list is available, if not get the histo directly from file
913   
914   if(list) return list->FindObject(histoName);
915   else     return file->Get       (histoName);
916 }
917
918 //___________________________________________________
919 void ScaleAxis(TAxis *a, Double_t scale)
920 {
921   if (!a) return; // just a precaution
922   if (a->GetXbins()->GetSize())
923   {
924     // an axis with variable bins
925     // note: bins must remain in increasing order, hence the "Scale"
926     // function must be strictly (monotonically) increasing
927     TArrayD X(*(a->GetXbins()));
928     for(Int_t i = 0; i < X.GetSize(); i++) X[i] = scale*X[i];
929     a->Set((X.GetSize() - 1), X.GetArray()); // new Xbins
930   }
931   else
932   {
933     // an axis with fix bins
934     // note: we modify Xmin and Xmax only, hence the "Scale" function
935     // must be linear (and Xmax must remain greater than Xmin)
936     a->Set(a->GetNbins(),
937            scale*a->GetXmin(), // new Xmin
938            scale*a->GetXmax()); // new Xmax
939   }
940   return;
941 }
942
943 //___________________________________________________
944 void ScaleXaxis(TH1 *h, Double_t scale)
945 {
946   if (!h) return; // just a precaution
947   ScaleAxis(h->GetXaxis(), scale);
948   return;
949 }
950
951