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