merging post-CVS changes into SVN:
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / drawSystematicsNew.C
1
2 Int_t markers[] = {20,21,22,23,28,29};
3 Int_t colors[]  = {1,2,3,4,6,8,102};
4
5 void loadlibs()
6 {
7   gSystem->Load("libTree");
8   gSystem->Load("libVMC");
9
10   gSystem->Load("libSTEERBase");
11   gSystem->Load("libANALYSIS");
12   gSystem->Load("libPWG0base");
13 }
14
15 void DrawpiKpAndCombinedZOnly(Float_t upperPtLimit=0.99)
16 {
17   //gROOT->ProcessLine(".L drawPlots.C");
18   gSystem->Load("libPWG0base");
19
20   const char* fileNames[] = { "systematics.root", "systematics.root", "systematics.root", "correction_map.root" };
21   const char* folderNames[] = { "correction_0", "correction_1", "correction_2", "dndeta_correction" };
22   const char* legendNames[] = { "#pi", "K", "p", "standard" };
23   Int_t folderCount = 3;
24
25
26
27   TH2F* h2DCorrections[4];
28   TH1F* h1DCorrections[4];
29   for (Int_t i=0; i<4; i++) {
30     TFile::Open(fileNames[i]);
31     AlidNdEtaCorrection* correctionTmp = new AlidNdEtaCorrection(folderNames[i],folderNames[i]);
32     correctionTmp->LoadHistograms();
33     
34     //    h2DCorrections[i] = correctionTmp->GetTrack2ParticleCorrection()->GetTrackCorrection()->Get2DCorrectionHistogram("yz",-1,1);
35
36     h1DCorrections[i] = correctionTmp->GetTrack2ParticleCorrection()->GetTrackCorrection()->Get1DCorrectionHistogram("z",-10,10,0.8,0.8);
37   }
38
39   TH2F* null = new TH2F("","",100,0.1,10,100,0.5,9.99);
40   null->SetXTitle("p_{T} (GeV/c)");
41   null->SetXTitle("Correction");
42
43   null->Draw();
44
45   //h1DCorrections[0]->SetMaximum(5);
46   //h1DCorrections[0]->Draw();
47   //  h2DCorrections[0]->Draw("colz");
48   for (Int_t i=1; i<4; i++) {
49     h1DCorrections[i]->Draw("same");
50   }
51   
52 }
53
54
55 void DrawEffectOfChangeInCrossSection(const char* fileName) {
56   
57   //get the data
58   TFile* fin = TFile::Open(fileName);
59
60   const Char_t* changes[]  = {"pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless", "sdmoreddless", "sdlessddmore" };
61   //const Char_t* changes[]  = {"pythia","ddmore25","ddless25","sdmore25","sdless25", "dmore25", "dless25", "sdmoreddless25", "sdlessddmore25" };
62   Int_t colors[] = {1,1,kRed,kBlue,kGreen,kPink,1,kRed,kBlue};
63
64   TH1F* hRatios[9];
65   for(Int_t i=0; i<9; i++) {
66     hRatios[i] = (TH1F*)fin->Get(Form("ratio_vertexReco_triggerBias_%s",changes[i]));
67     hRatios[i]->SetLineWidth(2);
68     hRatios[i]->SetLineColor(colors[i]);
69     hRatios[i]->SetMarkerStyle(22);
70     hRatios[i]->SetMarkerSize(0.8);
71
72     Float_t average = hRatios[i]->Integral(hRatios[i]->FindBin(-1), hRatios[i]->FindBin(1)) / (hRatios[i]->FindBin(1) - hRatios[i]->FindBin(-1) + 1);
73     Printf("%s: %.2f %%" , hRatios[i]->GetTitle(), (average - 1) * 100);
74   }
75
76   TPad* p = DrawCanvasAndPad("syst_changeInXsection",700,400);
77   p->SetRightMargin(0.2);
78   p->SetLeftMargin(0.13);
79
80   TH2F* null = new TH2F("","",100,-1.05,1.05,100,0.9,1.1);
81   null->GetXaxis()->SetTitle("#eta");
82   null->GetYaxis()->SetTitle("Ratio pythia/modified cross-sections");
83   null->Draw();
84
85   TLatex* text[9];
86
87   for(Int_t i=1; i<9; i++) {
88     hRatios[i]->Draw("same");
89     
90     TString str(hRatios[i]->GetTitle());
91     str.Remove(0,str.First("DD"));
92     str.Remove(str.First(")"),1);
93     text[i] = new TLatex(1.08,hRatios[i]->GetBinContent(hRatios[i]->FindBin(0.))-0.002,str.Data());
94     text[i]->SetTextColor(colors[i]);
95     text[i]->Draw();
96   }
97 }
98
99
100 void DrawEffectOfChangeInComposition() {
101   
102   //get the data
103   TFile* fin = TFile::Open("systematics_composition.root");
104
105   Int_t colors[] = {1,2,103,102,4,6,1};
106
107   TH1F* hRatios[6];
108
109   Float_t etaRange = 0.899;
110
111   for (Int_t i=0; i<6; i++) {
112     hRatios[i] = (TH1F*)fin->Get(Form("ratio_%d",i));
113
114     hRatios[i]->SetLineWidth(2);
115     hRatios[i]->SetLineColor(colors[i]);
116     hRatios[i]->SetMarkerStyle(22);
117     hRatios[i]->SetMarkerSize(0.8);
118
119     hRatios[i]->GetXaxis()->SetRangeUser(-etaRange, etaRange);
120   }
121
122   TPad* p = DrawCanvasAndPad("syst_changeOfComposition",700,400);
123   p->SetRightMargin(0.2);
124   p->SetLeftMargin(0.13);
125
126   TH2F* null = new TH2F("","",100,-1.05,1.05,100,0.97,1.03);
127   null->GetXaxis()->SetTitle("#eta");
128   null->GetYaxis()->SetTitle("Ratio pythia/modified composition");
129   null->Draw();
130
131   TLatex* text[6];
132
133   for(Int_t i=0; i<6; i++) {
134     hRatios[i]->Draw("same");
135     
136     TString str(hRatios[i]->GetTitle());
137     str.Remove(0,16);
138     text[i] = new TLatex(1.08,hRatios[i]->GetBinContent(hRatios[i]->FindBin(0))-0.002,str.Data());
139     text[i]->SetTextColor(colors[i]);
140     text[i]->SetTextSize(0.053);
141     
142     text[i]->Draw();
143   }
144
145
146 }
147
148 TPad* DrawCanvasAndPad(const Char_t* name, Int_t sizeX=600, Int_t sizeY=500) {
149
150   gStyle->SetOptStat(0);
151   gStyle->SetOptTitle(0);
152   gStyle->SetOptFit(0);
153
154   gStyle->SetTextSize(0.04);
155   gStyle->SetTitleSize(0.05,"xyz");
156   //gStyle->SetTitleFont(133, "xyz");
157   //gStyle->SetLabelFont(133, "xyz");
158   //gStyle->SetLabelSize(17, "xyz");
159   gStyle->SetLabelOffset(0.01, "xyz");
160
161   gStyle->SetTitleOffset(1.1, "y");
162   gStyle->SetTitleOffset(1.1, "x");
163   gStyle->SetEndErrorSize(0.0);
164
165   //##############################################
166
167   //making canvas and pads
168   TCanvas *c = new TCanvas(name,name,sizeX,sizeY);
169
170   TPad* p1 = new TPad("pad1","", 0, 0.0, 1.0, 1.0, 0, 0, 0);
171
172   p1->SetBottomMargin(0.15);
173   p1->SetTopMargin(0.03);
174   p1->SetLeftMargin(0.15);
175   p1->SetRightMargin(0.03);
176   
177   p1->SetGridx();
178   p1->SetGridy();
179
180   p1->Draw();
181   p1->cd();
182
183   return p1;
184 }
185
186 void MisalignmentShowRawTrackPlots(const char* dirName = "fdNdEtaAnalysisESD")
187 {
188   loadlibs();
189
190   TFile* file = TFile::Open("fullA-simrec/MB2/analysis_esd_raw.root");
191   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(dirName, dirName);
192   fdNdEtaAnalysis->LoadHistograms();
193
194   TFile* file2 = TFile::Open("fullA-sim/analysis_esd_raw.root");
195   dNdEtaAnalysis* fdNdEtaAnalysis2 = new dNdEtaAnalysis(dirName, dirName);
196   fdNdEtaAnalysis2->LoadHistograms();
197
198   TH3* track1 = fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("track1");
199   TH3* track2 = fdNdEtaAnalysis2->GetData()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("track2");
200
201   // normalize to number of events;
202   TH2* event1 = fdNdEtaAnalysis->GetData()->GetEventCorrection()->GetMeasuredHistogram();
203   TH2* event2 = fdNdEtaAnalysis2->GetData()->GetEventCorrection()->GetMeasuredHistogram();
204   Int_t event1Count = event1->Integral();
205   Int_t event2Count = event2->Integral();
206   track1->Scale(1.0 / event1Count);
207   track2->Scale(1.0 / event2Count);
208
209   const Float_t innerLimit = 0.49;
210   const Float_t outerLimit = 0.99;
211
212   track1->GetYaxis()->SetRangeUser(-outerLimit, outerLimit);
213   track2->GetYaxis()->SetRangeUser(-outerLimit, outerLimit);
214   AliPWG0Helper::CreateDividedProjections(track1, track2, "ze1");
215   TH1* fullRange = gROOT->FindObject("track1_ze1_div_track2_ze1");
216
217   track1->GetYaxis()->SetRangeUser(-innerLimit, innerLimit);
218   track2->GetYaxis()->SetRangeUser(-innerLimit, innerLimit);
219   AliPWG0Helper::CreateDividedProjections(track1, track2, "ze2");
220   TH1* central = gROOT->FindObject("track1_ze2_div_track2_ze2");
221   central->SetLineColor(1);
222   central->SetMarkerStyle(21);
223
224   for (Int_t x=1; x<track1->GetXaxis()->GetNbins(); ++x)
225     for (Int_t y=track1->GetYaxis()->FindBin(-innerLimit); y<track1->GetYaxis()->FindBin(innerLimit); ++y)
226       for (Int_t z=1; z<track1->GetZaxis()->GetNbins(); ++z)
227       {
228         track1->SetBinContent(x, y, z, 0);
229         track1->SetBinError(x, y, z, 0);
230         track2->SetBinContent(x, y, z, 0);
231         track2->SetBinError(x, y, z, 0);
232       }
233
234   track1->GetYaxis()->SetRangeUser(-outerLimit, outerLimit);
235   track2->GetYaxis()->SetRangeUser(-outerLimit, outerLimit);
236   AliPWG0Helper::CreateDividedProjections(track1, track2, "ze3");
237   TH1* peripheral = gROOT->FindObject("track1_ze3_div_track2_ze3");
238   peripheral->SetLineColor(2);
239   peripheral->SetMarkerStyle(22);
240   peripheral->SetMarkerColor(2);
241
242   TH2* tmp = new TH2F("tmp", ";p_{T} [GeV/c]      ;#frac{tracks full misalignment during rec.}{tracks ideal misalignment during rec.}", 1, 0.1, 10, 1, 0.9, 1.3);
243
244   tmp->SetStats(kFALSE);
245   //tmp->GetXaxis()->SetNoExponent();
246
247   Float_t ptStart = 0.1;
248
249   fullRange->GetXaxis()->SetRangeUser(ptStart, 9.9);
250   central->GetXaxis()->SetRangeUser(ptStart, 9.9);
251   peripheral->GetXaxis()->SetRangeUser(ptStart, 9.9);
252
253   TCanvas* canvas = new TCanvas("MisalignmentShowRawTrackPlots", "MisalignmentShowRawTrackPlots", 700, 400);
254   gPad->SetLogx();
255   gPad->SetGridx();
256   gPad->SetGridy();
257
258   TLegend* legend = new TLegend(0.2, 0.7, 0.4, 0.8);
259
260   legend->AddEntry(central, "|#eta| < 0.5");
261   legend->AddEntry(peripheral, "0.5 < |#eta| < 1.0");
262
263   legend->SetFillColor(0);
264
265   tmp->Draw();
266   //fullRange->Draw("SAME");
267   central->Draw("SAME");
268   peripheral->Draw("SAME");
269
270   legend->Draw();
271
272   canvas->SaveAs("syst_mis_ntracks.eps");
273 }
274
275
276 void drawdNdEtaRatios(const char* canvasName, Int_t n, const char** files, const char** dirs, const char** names, Int_t* histID)
277 {
278   gSystem->Load("libPWG0base");
279
280   TCanvas* canvas = new TCanvas(canvasName, canvasName, 1000, 500);
281   canvas->Divide(2, 1);
282
283   TLegend* legend = new TLegend(0.63, 0.73, 0.98, 0.98);
284   legend->SetFillColor(0);
285
286   TH1* base = 0;
287
288   for (Int_t i = 0; i < n; ++i)
289   {
290     TFile::Open(files[i]);
291
292     dNdEtaAnalysis* tmp = new dNdEtaAnalysis(dirs[i], dirs[i]);
293     tmp->LoadHistograms();
294
295     TH1* hist = tmp->GetdNdEtaPtCutOffCorrectedHistogram(histID[i]);
296
297     if (i == 0)
298       base = hist;
299
300     legend->AddEntry(hist, names[i]);
301
302     hist->SetMarkerColor(colors[i]);
303     hist->SetMarkerStyle(markers[i]);
304
305     canvas->cd(1);
306     hist->DrawCopy((i == 0) ? "" : "SAME");
307
308     if (i != 0)
309     {
310       canvas->cd(2);
311       hist->Divide(hist, base, 1, 1, "B");
312       hist->GetYaxis()->SetRangeUser(0.98, 1.02);
313       hist->DrawCopy((i == 1) ? "" : "SAME");
314     }
315   }
316
317   legend->Draw();
318
319   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
320 }
321
322 void drawdNdEtaRatios(const char* canvasName, Int_t n, const char** files1, const char** files2, const char** dirs1, const char** dirs2, const char** names, Int_t* histID)
323 {
324   gSystem->Load("libPWG0base");
325
326   TCanvas* canvas = new TCanvas(canvasName, canvasName, 700, 400);
327   canvas->SetLeftMargin(0.12);
328
329   TLegend* legend = new TLegend(0.35, 0.7, 0.65, 0.85);
330   legend->SetFillColor(0);
331
332   for (Int_t i = 0; i < n; ++i)
333   {
334     TFile::Open(files1[i]);
335
336     dNdEtaAnalysis* tmp1 = new dNdEtaAnalysis(dirs1[i], dirs1[i]);
337     tmp1->LoadHistograms();
338
339     TFile::Open(files2[i]);
340
341     dNdEtaAnalysis* tmp2 = new dNdEtaAnalysis(dirs2[i], dirs2[i]);
342     tmp2->LoadHistograms();
343
344     TH1* hist1 = tmp1->GetdNdEtaPtCutOffCorrectedHistogram(histID[i]);
345     TH1* hist2 = tmp2->GetdNdEtaPtCutOffCorrectedHistogram(histID[i]);
346
347     TH1* division = hist1->Clone();
348
349     division->Divide(hist1, hist2, 1, 1, "B");
350
351     division->SetMarkerColor(colors[i]);
352     division->SetMarkerStyle(markers[i]);
353
354     legend->AddEntry(division, names[i]);
355
356     division->SetTitle("");
357     division->GetYaxis()->SetTitle("#frac{dN_{ch}/d#eta using MC vtx}{dN_{ch}/d#eta using ESD vtx}");
358     division->SetStats(kFALSE);
359     division->GetYaxis()->SetTitleOffset(1.3);
360     division->GetXaxis()->SetRangeUser(-0.99, 0.99);
361     division->GetYaxis()->SetRangeUser(0.981, 1.02);
362     division->DrawCopy((i == 0) ? "" : "SAME");
363   }
364
365   gPad->SetGridx();
366   gPad->SetGridy();
367
368   legend->Draw();
369
370   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
371 }
372
373 void vertexShiftStudy(Int_t histID)
374 {
375   const char* files[] = { "maps/idealA/mc-vertex/analysis_esd.root", "results/idealC-idealA/analysis_esd.root", "maps/idealA/mc-vertex-shift-0.05/analysis_esd.root", "maps/idealA/mc-vertex-shift-0.1/analysis_esd.root", "maps/idealA/mc-vertex-shift-dep/analysis_esd.root" };
376   const char* dirs[] = { "dndeta", "dndeta", "dndeta", "dndeta", "dndeta" };
377   const char* names[] = { "mc vtx", "esd vtx", "+ 0.05 cm", "+ 0.1 cm", "old vtx shift" };
378   Int_t hist[] = { histID, histID, histID, histID, histID };
379
380   drawdNdEtaRatios("syst_vertex_shift1", 5, files, dirs, names, hist);
381
382   const char* files1[] = { "maps/idealA/mc-vertex/analysis_esd.root", "maps/idealA/mc-vertex/analysis_esd.root", "maps/idealA/mc-vertex/analysis_esd.root" };
383   const char* files2[] = { "results/idealC-idealA/analysis_esd.root", "results/idealC-idealA/analysis_esd.root", "results/idealC-idealA/analysis_esd.root" };
384   const char* dirs1[] = { "dndeta", "dndeta", "dndeta"};
385   const char* names[] = { "|vtx-z| < 10 cm", "-10 cm < vtx-z < 0 cm", "0 cm < vtx-z < 10 cm" };
386   Int_t hist[] = { 0, 1, 2 };
387
388   drawdNdEtaRatios("syst_vertex_shift2", 3, files1, files2, dirs, dirs, names, hist);
389 }
390
391 void vertexShift()
392 {
393   TFile::Open("vertex.root");
394
395   TH2* hist = gFile->Get("fVertexCorr");
396   TProfile* prof = hist->ProfileX();
397
398   prof->SetStats(kFALSE);
399   prof->SetTitle(";MC vtx-z [cm];mean (ESD vtx-z - MC vtx-z) [cm]");
400   prof->GetYaxis()->SetTitleOffset(1.2);
401
402   prof->SetLineWidth(2);
403
404   TCanvas* canvas = new TCanvas("syst_vertex_shift", "syst_vertex_shift", 700, 400);
405
406   gPad->SetGridx();
407   gPad->SetGridy();
408
409   prof->Draw();
410
411   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
412 }
413
414 void CompareRawTrackPlots(Float_t ptCut = 0.0)
415 {
416   loadlibs();
417
418   const char* dirName = "fdNdEtaAnalysisESD";
419
420   TFile* file = TFile::Open("fullA-simrec/MB2/analysis_esd_raw.root");
421   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(dirName, dirName);
422   fdNdEtaAnalysis->LoadHistograms();
423
424   //TFile* file2 = TFile::Open("fullA-sim/analysis_esd_raw.root");
425   TFile* file2 = TFile::Open("fullA-simrecexcepttpc/analysis_esd_raw.root");
426   dNdEtaAnalysis* fdNdEtaAnalysis2 = new dNdEtaAnalysis(dirName, dirName);
427   fdNdEtaAnalysis2->LoadHistograms();
428
429   TH3* track1 = fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("track1");
430   TH3* track2 = fdNdEtaAnalysis2->GetData()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("track2");
431
432   // normalize to number of events;
433   TH2* event1 = fdNdEtaAnalysis->GetData()->GetEventCorrection()->GetMeasuredHistogram();
434   TH2* event2 = fdNdEtaAnalysis2->GetData()->GetEventCorrection()->GetMeasuredHistogram();
435   Int_t event1Count = event1->Integral();
436   Int_t event2Count = event2->Integral();
437   track1->Scale(1.0 / event1Count);
438   track2->Scale(1.0 / event2Count);
439
440   Float_t nTrack1 = track1->Integral(-1, -1, -1, -1, track1->GetZaxis()->FindBin(ptCut), track1->GetZaxis()->GetNbins());
441   Float_t nTrack2 = track2->Integral(-1, -1, -1, -1, track2->GetZaxis()->FindBin(ptCut), track2->GetZaxis()->GetNbins());
442
443   Printf("There are %.2f tracks/event in the first sample and %.2f tracks/event in the second sample. %.2f %% difference (with pt cut at %.2f GeV/c)", nTrack1, nTrack2, 100.0 * (nTrack1 - nTrack2) / nTrack1, ptCut);
444
445   gROOT->cd();
446
447   AliPWG0Helper::CreateDividedProjections(track1, track2);
448
449   new TCanvas; gROOT->FindObject("track1_yx_div_track2_yx")->Draw("COLZ");
450   new TCanvas; gROOT->FindObject("track1_zx_div_track2_zx")->Draw("COLZ");
451   new TCanvas; gROOT->FindObject("track1_zy_div_track2_zy")->Draw("COLZ");
452
453   new TCanvas;
454   proj1 = track1->Project3D("ze2");
455   proj2 = track2->Project3D("ze2");
456   AliPWG0Helper::NormalizeToBinWidth(proj1);
457   AliPWG0Helper::NormalizeToBinWidth(proj2);
458
459   proj1->DrawCopy();
460   proj2->SetLineColor(2);
461   proj2->SetMarkerColor(2);
462   proj2->DrawCopy("SAME");
463
464   AliPWG0Helper::CreateDividedProjections(track1, track2, "ze2");
465   TH1* pt = gROOT->FindObject("track1_ze2_div_track2_ze2");
466   new TCanvas; pt->Draw();
467 }
468
469 void MagnitudeOfCorrection(const char* fileName, const char* dirName = "dndeta", Float_t ptCut = 0.3)
470 {
471   loadlibs();
472
473   TFile* file = TFile::Open(fileName);
474   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(dirName, dirName);
475   fdNdEtaAnalysis->LoadHistograms();
476   fdNdEtaAnalysis->GetData()->PrintInfo(ptCut);
477 }
478