Removing dummy if
[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     if (!combinatoricsCorrection)
59       combinatoricsCorrection = (TH1*) gFile->Get("correctiondNdEta");
60     file->cd();
61   }
62   
63   // Note: the last parameter does not define which analysis is going to happen, the histograms will be overwritten when loading from the file
64   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaNSD", "dndetaNSD");
65   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
66   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kNSD, "ESD -> NSD", backgroundEvents, combinatoricsCorrection);
67   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
68   TFile* file2 = TFile::Open(dataOutput, "RECREATE");
69   fdNdEtaAnalysis->SaveHistograms();
70   
71   file->cd();
72   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
73   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
74   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kINEL, "ESD -> full inelastic", backgroundEvents, combinatoricsCorrection);
75   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
76   file2->cd();
77   fdNdEtaAnalysis->SaveHistograms();
78
79   file->cd();
80   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTr", "dndetaTr");
81   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
82   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kVertexReco, "ESD -> minimum bias", backgroundEvents, combinatoricsCorrection);
83   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
84   file2->cd();
85   fdNdEtaAnalysis->SaveHistograms();
86
87   file->cd();
88   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
89   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
90   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kTrack2Particle, "ESD -> MB with vertex", backgroundEvents, combinatoricsCorrection);
91   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
92   file2->cd();
93   fdNdEtaAnalysis->SaveHistograms();
94
95   file->cd();
96   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracks", "dndetaTracks");
97   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
98   fdNdEtaAnalysis->Finish(0, 0.151, AlidNdEtaCorrection::kNone, "ESD raw with pt cut", backgroundEvents, combinatoricsCorrection);
99   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
100   file2->cd();
101   fdNdEtaAnalysis->SaveHistograms();
102
103   file->cd();
104   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracksAll", "dndetaTracksAll");
105   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
106   fdNdEtaAnalysis->Finish(0, -1, AlidNdEtaCorrection::kNone, "ESD raw", backgroundEvents, combinatoricsCorrection);
107   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
108   file2->cd();
109   fdNdEtaAnalysis->SaveHistograms();
110
111   file->cd();
112   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaOnePart", "dndetaOnePart");
113   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
114   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kOnePart, "ESD -> OnePart", backgroundEvents, combinatoricsCorrection);
115   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
116   file2->cd();
117   fdNdEtaAnalysis->SaveHistograms();
118
119   file2->Write();
120   file2->Close();
121 }
122
123 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)
124 {
125   loadlibs();
126
127   TFile* file = TFile::Open(analysisFile);
128
129   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(analysisDir, analysisDir);
130   fdNdEtaAnalysis->LoadHistograms();
131
132   if (correctionMapFile)
133   {
134     AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
135     TFile::Open(correctionMapFile);
136     dNdEtaCorrection->LoadHistograms();
137
138     fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.151, AlidNdEtaCorrection::kINEL);
139     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kINEL);
140     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kTrack2Particle);
141   }
142   else
143     fdNdEtaAnalysis->Finish(0, 0.151, AlidNdEtaCorrection::kNone);
144
145   return fdNdEtaAnalysis;
146   
147   fdNdEtaAnalysis->DrawHistograms(simple);
148
149   TH1* hist = fdNdEtaAnalysis->GetdNdEtaHistogram(1);
150   Int_t binLeft = hist->GetXaxis()->FindBin(-0.5);
151   Int_t binRight = hist->GetXaxis()->FindBin(0.5);
152   Float_t value1 = hist->Integral(binLeft, binRight);
153
154   hist = fdNdEtaAnalysis->GetdNdEtaHistogram(2);
155   Float_t value2 = hist->Integral(binLeft, binRight);
156
157   if (value2 > 0)
158     printf("Ratio is %f, values are %f %f\n", value1 / value2, value1, value2);
159
160   return fdNdEtaAnalysis;
161 }
162
163 void FinishMC()
164 {
165   loadlibs();
166   
167   result1 = (dNdEtaAnalysis*) FinishAnalysis("analysis_mc.root", "dndeta", 0, 0, 1);
168   result2 = (dNdEtaAnalysis*) FinishAnalysis("analysis_mc.root", "dndetaNSD", 0, 0, 1);
169   
170   file = TFile::Open("out.root", "RECREATE");
171   result1->SaveHistograms();
172   result2->SaveHistograms();
173   file->Close();
174 }
175
176 void correct(Bool_t onlyESD = kFALSE, Bool_t mergedXSections = kTRUE)
177 {
178   gSystem->Unlink("analysis_esd.root");
179   if (mergedXSections)
180     FinishAnalysisAll("analysis_esd_raw.root", "analysis_esd.root", "correction_map2.root", "dndeta_correction_ua5");
181   else
182     FinishAnalysisAll("analysis_esd_raw.root", "analysis_esd.root", "correction_map.root", "dndeta_correction");
183   
184   gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/dNdEta/drawPlots.C");
185   dNdEta(onlyESD);
186 }
187
188