updated dndeta analysis
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / correct.C
1 void loadlibs()
2 {
3   gSystem->Load("libTree");
4   gSystem->Load("libVMC");
5
6   gSystem->Load("libSTEERBase");
7   gSystem->Load("libANALYSIS");
8   gSystem->Load("libPWG0base");
9 }
10
11 void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const char* dataOutput = "analysis_esd.root", const char* correctionMapFile = "correction_map2.root", const char* correctionMapFolder = "dndeta_correction_ua5")
12 {
13   loadlibs();
14
15   AlidNdEtaCorrection* dNdEtaCorrection = 0;
16   
17   if (correctionMapFile)
18   {
19     dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
20     if (!TFile::Open(correctionMapFile))
21       return;
22     dNdEtaCorrection->LoadHistograms();
23   }
24   
25   TFile* file = TFile::Open(dataInput);
26
27   if (!file)
28   {
29     cout << "Error. File not found" << endl;
30     return;
31   }
32   
33   Int_t backgroundEvents = 0;
34   
35   //backgroundEvents = 1162+434; // Michele for MB1, run 104892, 15.02.10
36   //backgroundEvents = 842;    // JF estimate for V0 systematic case 1
37   backgroundEvents = 6;          // Michele for V0AND, run 104892, 15.02.10
38   
39   //backgroundEvents = 1758+434; // MB1, run 104867-92
40   
41   //backgroundEvents = 4398+961;   // Michele for MB1, run 104824-52, 16.02.10
42   //backgroundEvents = 19;         // Michele for V0AND, run 104824-52, 16.02.10
43   
44   //backgroundEvents = -1;    // use 0 bin from MC! for 2.36 TeV
45   //backgroundEvents = 900; // my estimate for 2.36 TeV
46   
47   //backgroundEvents = 918;   // V0OR for run 114786 w/o bunch intensities w/o proper 0 checking!
48   //backgroundEvents = 723; // V0OR for run 114798 w/o bunch intensities w/o proper 0 checking!
49   
50   Printf("Subtracting %d background events!!!", backgroundEvents);
51   gSystem->Sleep(1000);
52   
53   TH1* combinatoricsCorrection = 0;
54   if (1)
55   {
56     TFile::Open("corrComb.root");
57     combinatoricsCorrection = (TH1*) gFile->Get("ratioofratios");
58     file->cd();
59   }
60   
61   // Note: the last parameter does not define which analysis is going to happen, the histograms will be overwritten when loading from the file
62   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaNSD", "dndetaNSD");
63   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
64   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kNSD, "ESD -> NSD", backgroundEvents, combinatoricsCorrection);
65   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
66   TFile* file2 = TFile::Open(dataOutput, "RECREATE");
67   fdNdEtaAnalysis->SaveHistograms();
68   
69   file->cd();
70   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
71   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
72   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kINEL, "ESD -> full inelastic", backgroundEvents, combinatoricsCorrection);
73   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
74   file2->cd();
75   fdNdEtaAnalysis->SaveHistograms();
76
77   file->cd();
78   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTr", "dndetaTr");
79   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
80   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kVertexReco, "ESD -> minimum bias", backgroundEvents, combinatoricsCorrection);
81   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
82   file2->cd();
83   fdNdEtaAnalysis->SaveHistograms();
84
85   file->cd();
86   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
87   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
88   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kTrack2Particle, "ESD -> MB with vertex", backgroundEvents, combinatoricsCorrection);
89   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
90   file2->cd();
91   fdNdEtaAnalysis->SaveHistograms();
92
93   file->cd();
94   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracks", "dndetaTracks");
95   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
96   fdNdEtaAnalysis->Finish(0, 0.151, AlidNdEtaCorrection::kNone, "ESD raw with pt cut", backgroundEvents, combinatoricsCorrection);
97   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
98   file2->cd();
99   fdNdEtaAnalysis->SaveHistograms();
100
101   file->cd();
102   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracksAll", "dndetaTracksAll");
103   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
104   fdNdEtaAnalysis->Finish(0, -1, AlidNdEtaCorrection::kNone, "ESD raw", backgroundEvents, combinatoricsCorrection);
105   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
106   file2->cd();
107   fdNdEtaAnalysis->SaveHistograms();
108
109   file->cd();
110   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaOnePart", "dndetaOnePart");
111   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
112   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kOnePart, "ESD -> OnePart", backgroundEvents, combinatoricsCorrection);
113   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
114   file2->cd();
115   fdNdEtaAnalysis->SaveHistograms();
116
117   file2->Write();
118   file2->Close();
119 }
120
121 void* FinishAnalysis(const char* analysisFile = "analysis_esd_raw.root", const char* analysisDir = "fdNdEtaAnalysisESD", const char* correctionMapFile = "correction_map.root", const char* correctionMapFolder = "dndeta_correction", Bool_t useUncorrected = kFALSE, Bool_t simple = kFALSE)
122 {
123   loadlibs();
124
125   TFile* file = TFile::Open(analysisFile);
126
127   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(analysisDir, analysisDir);
128   fdNdEtaAnalysis->LoadHistograms();
129
130   if (correctionMapFile)
131   {
132     AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
133     TFile::Open(correctionMapFile);
134     dNdEtaCorrection->LoadHistograms();
135
136     fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kINEL);
137     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kINEL);
138     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kTrack2Particle);
139   }
140   else
141     fdNdEtaAnalysis->Finish(0, 0.151, AlidNdEtaCorrection::kNone);
142
143   return fdNdEtaAnalysis;
144   
145   fdNdEtaAnalysis->DrawHistograms(simple);
146
147   TH1* hist = fdNdEtaAnalysis->GetdNdEtaHistogram(1);
148   Int_t binLeft = hist->GetXaxis()->FindBin(-0.5);
149   Int_t binRight = hist->GetXaxis()->FindBin(0.5);
150   Float_t value1 = hist->Integral(binLeft, binRight);
151
152   hist = fdNdEtaAnalysis->GetdNdEtaHistogram(2);
153   Float_t value2 = hist->Integral(binLeft, binRight);
154
155   if (value2 > 0)
156     printf("Ratio is %f, values are %f %f\n", value1 / value2, value1, value2);
157
158   return fdNdEtaAnalysis;
159 }
160
161 void FinishMC()
162 {
163   loadlibs();
164   
165   result1 = (dNdEtaAnalysis*) FinishAnalysis("analysis_mc.root", "dndeta", 0, 0, 1);
166   result2 = (dNdEtaAnalysis*) FinishAnalysis("analysis_mc.root", "dndetaNSD", 0, 0, 1);
167   
168   file = TFile::Open("out.root", "RECREATE");
169   result1->SaveHistograms();
170   result2->SaveHistograms();
171   file->Close();
172 }
173
174 void correct(Bool_t onlyESD = kFALSE, Bool_t mergedXSections = kTRUE)
175 {
176   gSystem->Unlink("analysis_esd.root");
177   if (mergedXSections)
178     FinishAnalysisAll("analysis_esd_raw.root", "analysis_esd.root", "correction_map2.root", "dndeta_correction_ua5");
179   else
180     FinishAnalysisAll("analysis_esd_raw.root", "analysis_esd.root", "correction_map.root", "dndeta_correction");
181   
182   gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/dNdEta/drawPlots.C");
183   dNdEta(onlyESD);
184 }
185
186