ce581c5a1e9b4a8e80d97b63a3df6c843e0ea287
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / run.C
1 void 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");
12     gProof->UploadPackage("AOD");
13     gProof->EnablePackage("AOD");
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
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);
47
48   AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD;
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   }
64
65   if (mc)
66     task->SetReadMC();
67
68   //task->SetUseMCVertex();
69   //task->SetUseMCKine();
70
71   mgr->AddTask(task);
72
73   if (mc) {
74     // Enable MC event handler
75     AliMCEventHandler* handler = new AliMCEventHandler;
76     handler->SetReadTR(kFALSE);
77     mgr->SetMCtruthEventHandler(handler);
78   }
79
80   // Add ESD handler
81   AliESDInputHandler* esdH = new AliESDInputHandler;
82   mgr->SetInputEventHandler(esdH);
83
84   // Attach input
85   cInput  = mgr->CreateContainer("cInput", TChain::Class(), AliAnalysisManager::kInputContainer);
86   mgr->ConnectInput(task, 0, cInput);
87
88   // Attach output
89   cOutput = mgr->CreateContainer("cOutput", TList::Class(), AliAnalysisManager::kOutputContainer);
90   mgr->ConnectOutput(task, 0, cOutput);
91
92   // Enable debug printouts
93   if (aDebug)
94     mgr->SetDebugLevel(2);
95
96   // Run analysis
97   mgr->InitAnalysis();
98   mgr->PrintStatus();
99
100   mgr->StartAnalysis((aProof) ? "proof" : "local", chain);
101 }
102
103 void loadlibs()
104 {
105   gSystem->Load("libTree");
106   gSystem->Load("libVMC");
107
108   gSystem->Load("libSTEERBase");
109   gSystem->Load("libANALYSIS");
110   gSystem->Load("libPWG0base");
111 }
112
113 void 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")
114 {
115   loadlibs();
116
117   AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
118   TFile::Open(correctionMapFile);
119   dNdEtaCorrection->LoadHistograms();
120
121   TFile* file = TFile::Open(dataInput);
122
123   if (!file)
124   {
125     cout << "Error. File not found" << endl;
126     return;
127   }
128
129   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
130   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
131   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL, 1);
132   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
133   TFile* file2 = TFile::Open(dataOutput, "RECREATE");
134   fdNdEtaAnalysis->SaveHistograms();
135
136   file->cd();
137   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTr", "dndetaTr");
138   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
139   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kVertexReco, 1);
140   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
141   file2->cd();
142   fdNdEtaAnalysis->SaveHistograms();
143
144   file->cd();
145   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
146   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
147   fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kTrack2Particle, 1);
148   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
149   file2->cd();
150   fdNdEtaAnalysis->SaveHistograms();
151
152   file->cd();
153   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracks", "dndetaTracks");
154   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
155   fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone, 1);
156   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
157   file2->cd();
158   fdNdEtaAnalysis->SaveHistograms();
159
160   file2->Write();
161   file2->Close();
162 }
163
164 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)
165 {
166   loadlibs();
167
168   TFile* file = TFile::Open(analysisFile);
169
170   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(analysisDir, analysisDir);
171   fdNdEtaAnalysis->LoadHistograms();
172
173   if (correctionMapFile)
174   {
175     AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
176     TFile::Open(correctionMapFile);
177     dNdEtaCorrection->LoadHistograms();
178
179     fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL);
180     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kINEL);
181     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kTrack2Particle);
182   }
183   else
184     fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone);
185
186   fdNdEtaAnalysis->DrawHistograms(simple);
187
188   TH1* hist = fdNdEtaAnalysis->GetdNdEtaHistogram(1);
189   Int_t binLeft = hist->GetXaxis()->FindBin(-0.5);
190   Int_t binRight = hist->GetXaxis()->FindBin(0.5);
191   Float_t value1 = hist->Integral(binLeft, binRight);
192
193   hist = fdNdEtaAnalysis->GetdNdEtaHistogram(2);
194   Float_t value2 = hist->Integral(binLeft, binRight);
195
196   if (value2 > 0)
197     printf("Ratio is %f, values are %f %f\n", value1 / value2, value1, value2);
198
199   return fdNdEtaAnalysis;
200 }