added correction for events with vertex but 0 tracks
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / run.C
CommitLineData
0f67a57c 1void run(Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool_t aDebug = kFALSE, Bool_t aProof = kFALSE, Bool_t mc = kTRUE, const char* option = "")
2{
3 if (aProof)
4 {
5 TProof::Open("lxb6046");
6
7 // Enable the needed package
8 gProof->UploadPackage("STEERBase");
9 gProof->EnablePackage("STEERBase");
10 gProof->UploadPackage("ESD");
11 gProof->EnablePackage("ESD");
144ff489 12 gProof->UploadPackage("AOD");
13 gProof->EnablePackage("AOD");
0f67a57c 14 gProof->UploadPackage("ANALYSIS");
15 gProof->EnablePackage("ANALYSIS");
16 gProof->UploadPackage("PWG0base");
17 gProof->EnablePackage("PWG0base");
18 }
19 else
20 {
21 gSystem->Load("libVMC");
22 gSystem->Load("libTree");
23 gSystem->Load("libSTEERBase");
24 gSystem->Load("libESD");
25 gSystem->Load("libANALYSIS");
26 gSystem->Load("libPWG0base");
27 }
28
29 // Create chain of input files
30 gROOT->LoadMacro("../CreateESDChain.C");
31 chain = CreateESDChain(data, nRuns, offset);
32
33 // Create the analysis manager
34 mgr = new AliAnalysisManager;
35
0f67a57c 36 TString taskName("AlidNdEtaTask.cxx+");
37 if (aDebug)
38 taskName += "+g";
39
40 // Create, add task
41 if (aProof) {
42 gProof->Load(taskName);
43 } else
44 gROOT->Macro(taskName);
45
46 task = new AlidNdEtaTask(option);
770a1f1d 47
48 AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kTPC;
49 task->SetAnalysisMode(analysisMode);
50
51 if (analysisMode != AliPWG0Helper::kSPD)
52 {
53 // selection of esd tracks
54 gROOT->ProcessLine(".L ../CreateStandardCuts.C");
55 AliESDtrackCuts* esdTrackCuts = CreateTrackCuts(analysisMode);
56 if (!esdTrackCuts)
57 {
58 printf("ERROR: esdTrackCuts could not be created\n");
59 return;
60 }
61
62 task->SetTrackCuts(esdTrackCuts);
63 }
0f67a57c 64
65 if (mc)
66 task->SetReadMC();
67
68 mgr->AddTask(task);
69
70 if (mc) {
71 // Enable MC event handler
72 AliMCEventHandler* handler = new AliMCEventHandler;
73 handler->SetReadTR(kFALSE);
74 mgr->SetMCtruthEventHandler(handler);
75 }
76
77 // Add ESD handler
78 AliESDInputHandler* esdH = new AliESDInputHandler;
79 mgr->SetInputEventHandler(esdH);
80
81 // Attach input
82 cInput = mgr->CreateContainer("cInput", TChain::Class(), AliAnalysisManager::kInputContainer);
83 mgr->ConnectInput(task, 0, cInput);
84
85 // Attach output
86 cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer);
87 mgr->ConnectOutput(task, 0, cOutput);
88
89 // Enable debug printouts
90 if (aDebug)
91 mgr->SetDebugLevel(2);
92
93 // Run analysis
94 mgr->InitAnalysis();
95 mgr->PrintStatus();
96
97 mgr->StartAnalysis((aProof) ? "proof" : "local", chain);
98}
dd367a14 99
100void loadlibs()
101{
102 gSystem->Load("libTree");
103 gSystem->Load("libVMC");
104
105 gSystem->Load("libSTEERBase");
106 gSystem->Load("libANALYSIS");
107 gSystem->Load("libPWG0base");
108}
109
110void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const char* dataOutput = "analysis_esd.root", const char* correctionMapFile = "correction_map.root", const char* correctionMapFolder = "dndeta_correction")
111{
112 loadlibs();
113
114 AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
115 TFile::Open(correctionMapFile);
116 dNdEtaCorrection->LoadHistograms();
117
118 TFile* file = TFile::Open(dataInput);
119
120 if (!file)
121 {
122 cout << "Error. File not found" << endl;
123 return;
124 }
125
126 dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
127 fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
3dfa46a4 128 fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL, 1);
770a1f1d 129 //fdNdEtaAnalysis->DrawHistograms(kTRUE);
dd367a14 130 TFile* file2 = TFile::Open(dataOutput, "RECREATE");
131 fdNdEtaAnalysis->SaveHistograms();
132
133 file->cd();
134 fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTr", "dndetaTr");
135 fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
3dfa46a4 136 fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kVertexReco, 1);
770a1f1d 137 //fdNdEtaAnalysis->DrawHistograms(kTRUE);
dd367a14 138 file2->cd();
139 fdNdEtaAnalysis->SaveHistograms();
140
141 file->cd();
142 fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
143 fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
3dfa46a4 144 fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kTrack2Particle, 1);
770a1f1d 145 //fdNdEtaAnalysis->DrawHistograms(kTRUE);
dd367a14 146 file2->cd();
147 fdNdEtaAnalysis->SaveHistograms();
148
149 file->cd();
150 fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracks", "dndetaTracks");
151 fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
3dfa46a4 152 fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone, 1);
770a1f1d 153 //fdNdEtaAnalysis->DrawHistograms(kTRUE);
dd367a14 154 file2->cd();
155 fdNdEtaAnalysis->SaveHistograms();
9c4cc5e7 156
157 file2->Write();
158 file2->Close();
dd367a14 159}
160
161void* 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)
162{
163 loadlibs();
164
165 TFile* file = TFile::Open(analysisFile);
166
167 dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(analysisDir, analysisDir);
168 fdNdEtaAnalysis->LoadHistograms();
169
170 if (correctionMapFile)
171 {
172 AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
173 TFile::Open(correctionMapFile);
174 dNdEtaCorrection->LoadHistograms();
175
176 fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL);
177 //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kINEL);
178 //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kTrack2Particle);
179 }
180 else
3dfa46a4 181 fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone);
dd367a14 182
183 fdNdEtaAnalysis->DrawHistograms(simple);
184
185 TH1* hist = fdNdEtaAnalysis->GetdNdEtaHistogram(1);
186 Int_t binLeft = hist->GetXaxis()->FindBin(-0.5);
187 Int_t binRight = hist->GetXaxis()->FindBin(0.5);
188 Float_t value1 = hist->Integral(binLeft, binRight);
189
190 hist = fdNdEtaAnalysis->GetdNdEtaHistogram(2);
191 Float_t value2 = hist->Integral(binLeft, binRight);
192
193 if (value2 > 0)
194 printf("Ratio is %f, values are %f %f\n", value1 / value2, value1, value2);
195
196 return fdNdEtaAnalysis;
197}