Working on the electron cut
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / ChargedHadrons / multPbPb / run.C
CommitLineData
a23f7c97 1// TODO:
2// 1. Check cuts for 2010 (Jochen?)
54b31d6a 3// 2. Run with many centrality bins at once
e0376287 4#include <string.h>
a23f7c97 5
5ad99723 6enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID, kMyRunModeProofLite};
e0376287 7
8TList * listToLoad = new TList();
a23f7c97 9
10TChain * GetAnalysisChain(const char * incollection);
11
eef42d18 12void run(Char_t* data, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 0, Bool_t isMC = 0,
3b8cbf2d 13 Int_t centrBin = 0, const char * centrEstimator = "VOM", Int_t useOtherCentralityCut = 0, Int_t trackMin=0, Int_t trackMax=10000,
5ad99723 14 const char* option = "",TString customSuffix = "", Int_t workers = -1, Bool_t useSingleBin=kTRUE, const char * runList = 0)
a23f7c97 15{
16 // runMode:
17 //
18 // 0 local
19 // 1 proof
20
21 if (nev < 0)
22 nev = 1234567890;
23
24 InitAndLoadLibs(runMode,workers,debug);
25
26 // Create the analysis manager
27 mgr = new AliAnalysisManager;
28
29 // Add ESD handler
30 AliESDInputHandler* esdH = new AliESDInputHandler;
31 // Do I need any of this?
eef42d18 32 esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
a23f7c97 33 mgr->SetInputEventHandler(esdH);
34
35 if(isMC) {
36 AliMCEventHandler* handler = new AliMCEventHandler;
b00e8ba9 37 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
a23f7c97 38 mgr->SetMCtruthEventHandler(handler);
39 }
40
e0376287 41
5ad99723 42
43 // Parse option strings
44 TString optionStr(option);
45
46 // remove SAVE option if set
47 // This is copied from a macro by Jan. The reason I kept it is that I may want to pass textual options to the new task at some point
48 Bool_t doSave = kFALSE;
49 TString optionStr(option);
50 if (optionStr.Contains("SAVE"))
51 {
52 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
53 doSave = kTRUE;
54 }
55
56 AliESDtrackCuts * cuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kFALSE);
57 TString pathsuffix = "";
58
59 if(!useSingleBin) pathsuffix += "_AllCentr";
60
61 if (optionStr.Contains("DCA")) {
62 delete cuts;
63 // cuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2009();
64 cout << ">>>> USING DCA cut" << endl;
65 cuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
66 cuts->SetMaxChi2TPCConstrainedGlobal(); // remove golden cut
67 pathsuffix+="_DCAcut";
68 }
69
70 if (optionStr.Contains("ITSsa")) {
71 delete cuts;
72 cuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2009();
73 cout << ">>>> USING ITS sa tracks" << endl;
74 pathsuffix+="_ITSsa";
75 }
76
77 if (optionStr.Contains("TPC")) {
78 delete cuts;
79 cuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
80 cout << ">>>> USING TPC only tracks" << endl;
81 pathsuffix+="_TPC";
82 }
83
84 if(optionStr.Contains("NoElectrons")) pathsuffix +="_NoElectrons";
85
86
87
88 Bool_t useMCKinematics = isMC;
89 if (optionStr.Contains("NOMCKIN")) {
90 cout << ">>>> Ignoring MC kinematics" << endl;
91 useMCKinematics=kFALSE;
92 pathsuffix+="_NOMCKIN";
93 }
94
e0376287 95 // If we are running on grid, we need the alien handler
96 if (runMode == kMyRunModeGRID) {
97 // Create and configure the alien handler plugin
98 gROOT->LoadMacro("CreateAlienHandler.C");
5ad99723 99 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, runList, pathsuffix.Data(), listToLoad, "full", isMC); // full
e0376287 100 if (!alienHandler) {
101 cout << "Cannot create alien handler" << endl;
102 exit(1);
103 }
104 mgr->SetGridHandler(alienHandler);
105 }
106
107
108
5ad99723 109 // Add tasks
a23f7c97 110 // physics selection
111 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
e9c445f5 112 physicsSelectionTask = AddTaskPhysicsSelection(isMC);
8b628a20 113
2b42cee2 114 //PID
115 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
116 AddTaskPIDResponse(isMC);
117
5ad99723 118 // // PID QA:
119 // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
120 // AddTaskPIDqa();
121
2b42cee2 122
54b31d6a 123 // Centrality
5ad99723 124 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
125 AliCentralitySelectionTask *taskCentr = AddTaskCentrality();
126 // OBSOLETE
3b8cbf2d 127 const char * file1 = "$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityBy1D.root";
128 const char * file2 = "$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityByFunction.root";
5ad99723 129 // END of OBSOLETE
2b42cee2 130 if(isMC) taskCentr-> SetMCInput();
131 taskCentr->SetPass(2);
132
2bbfd8c6 133 // Create my own centrality selector
134 AliAnalysisMultPbCentralitySelector * centrSelector = new AliAnalysisMultPbCentralitySelector();
bfae2924 135 centrSelector->SetIsMC(isMC);
8b628a20 136 centrSelector->SetCentrTaskFiles(file1,file2); // for bookkeping only
2bbfd8c6 137 centrSelector->SetCentralityBin(centrBin);
bcf2601a 138 if (!useSingleBin) centrSelector->SetCentralityBin(0); // FIXME: ok?
2bbfd8c6 139 centrSelector->SetCentralityEstimator(centrEstimator);
eef42d18 140
3b8cbf2d 141 if(useOtherCentralityCut == 1){
9441cdaa 142 cout << "Setting centrality by MULT" << endl;
eef42d18 143 centrSelector->SetUseMultRange();
144 centrSelector->SetMultRange(trackMin,trackMax);
145 }
3b8cbf2d 146 if(useOtherCentralityCut == 2){
9441cdaa 147 cout << "Setting centrality by V0" << endl;
3b8cbf2d 148
149 centrSelector->SetUseV0Range();
150 centrSelector->SetMultRange(trackMin,trackMax);
151 }
72491d7c 152 if(useOtherCentralityCut == 3){
9441cdaa 153 cout << "Setting centrality by SPD outer" << endl;
72491d7c 154 centrSelector->SetUseSPDOuterRange();
155 centrSelector->SetMultRange(trackMin,trackMax);
156 }
a23f7c97 157
a23f7c97 158 // load my task
bcf2601a 159 if (useSingleBin) {
160 gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/multPbPb/AddTaskMultPbPbTracks.C");
161 AliAnalysisTaskMultPbTracks * task = AddTaskMultPbPbTracks("multPbPbtracks.root", cuts, centrSelector);
162 task->SetIsMC(useMCKinematics);
163 task->SetOfflineTrigger(AliVEvent::kMB);
164 if(optionStr.Contains("TPC")) task->SetTPCOnly();
5ad99723 165 if(optionStr.Contains("NoElectrons")) task->RejectElectrons(kTRUE);
bcf2601a 166 if(useMCKinematics) task->GetHistoManager()->SetSuffix("MC");
167 if(customSuffix!=""){
168 cout << "Setting custom suffix: " << customSuffix << endl;
169 task->GetHistoManager()->SetSuffix(customSuffix);
170 }
171 } else {
172 gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/multPbPb/AddTaskMultPbPbTracksAllCentrality.C");
173 centrSelector->SetUseV0Range(kTRUE);
174 Int_t ncentr = 11;
abd808b9 175
176 const Float_t minCentr[] = {0 ,79 ,239,559 ,1165,2135,3555,5525,8213 ,12191,15079};
177 const Float_t maxCentr[] = {79,239,559,1165,2135,3555,5525,8213,12191,15079,21000};
bcf2601a 178 AliAnalysisTaskMultPbTracks ** tasks = AddTaskMultPbPbTracksAllCentrality("multPbPbtracks.root", cuts, centrSelector, ncentr,minCentr,maxCentr);
179 for(Int_t icentr = 0; icentr < ncentr; icentr++){
bcf2601a 180 tasks[icentr]->Print();
e9c445f5 181 cout << "MC KINEMATICS:" << useMCKinematics << endl;
182
bcf2601a 183 tasks[icentr]->SetIsMC(useMCKinematics);
bcf2601a 184 tasks[icentr]->SetOfflineTrigger(AliVEvent::kMB);
bcf2601a 185 if(optionStr.Contains("TPC")) tasks[icentr]->SetTPCOnly();
5ad99723 186 if(optionStr.Contains("NoElectrons")) task[icentr]->RejectElectrons(kTRUE);
bcf2601a 187 if(useMCKinematics) tasks[icentr]->GetHistoManager()->SetSuffix("MC");
bcf2601a 188 if(customSuffix!=""){
e9c445f5 189 cout << "Setting custom suffix: " << customSuffix+long(icentr) << endl;
bcf2601a 190 tasks[icentr]->GetHistoManager()->SetSuffix(customSuffix+long(icentr));
bcf2601a 191 }
192 }
e0376287 193 }
bcf2601a 194 // Init and run the analy
a23f7c97 195 if (!mgr->InitAnalysis()) return;
bcf2601a 196
a23f7c97 197 mgr->PrintStatus();
198
199 if (runMode == kMyRunModeLocal ) {
200 // If running in local mode, create chain of ESD files
54b31d6a 201 cout << "RUNNING LOCAL, CHAIN" << endl;
a23f7c97 202 TChain * chain = GetAnalysisChain(data);
5ad99723 203 chain->Print();
a23f7c97 204 mgr->StartAnalysis("local",chain,nev);
5ad99723 205 } else if (runMode == kMyRunModeProofLite) {
206 TChain * chain = GetAnalysisChain(data);
207 mgr->StartAnalysis("proof",chain,nev);
208 }
209 else if (runMode == kMyRunModeCAF) {
a23f7c97 210 mgr->StartAnalysis("proof",TString(data)+"#esdTree",nev);
e0376287 211 } else if (runMode == kMyRunModeGRID) {
212 mgr->StartAnalysis("grid");
a23f7c97 213 } else {
214 cout << "ERROR: unknown run mode" << endl;
215 }
216
3b8cbf2d 217 if (!useOtherCentralityCut) {
eef42d18 218 pathsuffix = pathsuffix + "_" + centrEstimator + "_bin_"+long(centrBin);
3b8cbf2d 219 } else if(useOtherCentralityCut==1){
eef42d18 220 pathsuffix = pathsuffix + "_TrackRange_" + long(trackMin) + "_" + long(trackMax);
3b8cbf2d 221 } else if(useOtherCentralityCut==2){
222 pathsuffix = pathsuffix + "_V0Range_" + long(trackMin) + "_" + long(trackMax);
72491d7c 223 } else if(useOtherCentralityCut==3){
224 pathsuffix = pathsuffix + "_SPDOutRange_" + long(trackMin) + "_" + long(trackMax);
eef42d18 225 }
7f5f2e0c 226 pathsuffix += customSuffix;
227
a23f7c97 228 if (doSave) MoveOutput(data, pathsuffix.Data());
229
2b42cee2 230
231
a23f7c97 232
233}
234
235
236void MoveOutput(const char * data, const char * suffix = ""){
237
238 TString path("output/");
239 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
240
241 TString fileName = "multPbPbtracks.root";
242 gSystem->mkdir(path, kTRUE);
243 gSystem->Rename(fileName, path + "/" + fileName);
bcf2601a 244 for(Int_t ibin = 0; ibin < 20; ibin++){
245 TString fileBin = fileName;
246 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
247 gSystem->Rename(fileBin, path + "/" + fileBin);
248 }
249
a23f7c97 250 gSystem->Rename("event_stat.root", path + "/event_stat.root");
251 Printf(">>>>> Moved files to %s", path.Data());
252}
253
254
255
256TChain * GetAnalysisChain(const char * incollection){
257 // Builds a chain of esd files
258 // incollection can be
259 // - a single root file
260 // - an xml collection of files on alien
261 // - a ASCII containing a list of local root files
262 TChain* analysisChain = 0;
263 // chain
264 analysisChain = new TChain("esdTree");
265 if (TString(incollection).Contains(".root")){
266 analysisChain->Add(incollection);
267 }
268 else if (TString(incollection).Contains("xml")){
269 TGrid::Connect("alien://");
270 TAlienCollection * coll = TAlienCollection::Open (incollection);
271 while(coll->Next()){
272 analysisChain->Add(TString("alien://")+coll->GetLFN());
273 }
274 } else {
275 ifstream file_collect(incollection);
276 TString line;
277 while (line.ReadLine(file_collect) ) {
278 analysisChain->Add(line.Data());
279 }
280 }
281 analysisChain->GetListOfFiles()->Print();
282
283 return analysisChain;
284}
285
286
287void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) {
e0376287 288 // Loads libs and par files + custom task and classes
289
290 // Custom stuff to be loaded
5ad99723 291 // listToLoad->Add(new TObjString("$ALICE_ROOT/ANALYSIS/AliCentralitySelectionTask.cxx+"));
292 listToLoad->Add(new TObjString("/Users/mfloris/Work/AliSoft/AliRoot-trunk/PWGPP/background/AliHistoListWrapper.cxx+")); // FIXME
293 listToLoad->Add(new TObjString("AliAnalysisMultPbTrackHistoManager.cxx+"));
294 listToLoad->Add(new TObjString("AliAnalysisMultPbCentralitySelector.cxx+"));
295 listToLoad->Add(new TObjString("AliAnalysisTaskMultPbTracks.cxx+"));
296 // listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbTrackHistoManager.cxx+"));
297 // listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbCentralitySelector.cxx+"));
298 // listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisTaskMultPbTracks.cxx+"));
e0376287 299
a23f7c97 300
301 if (runMode == kMyRunModeCAF)
bcf2601a 302 {
303 cout << "Init in CAF mode" << endl;
a23f7c97 304
2b42cee2 305 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
5ad99723 306 // TProof::Mgr("alice-caf.cern.ch")->SetROOTVersion("VO_ALICE@ROOT::v5-30-03-1");
307 TProof::Mgr("alice-caf.cern.ch")->SetROOTVersion("current");
84bad6b8 308 TProof * p = TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "1x");
f07573a6 309 // TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
bcf2601a 310 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE);
311
5ad99723 312 // TProof::Mgr("alice-caf.cern.ch")->SetROOTVersion("VO_ALICE@ROOT::v5-28-00f");
313 gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-12-AN");
2b42cee2 314 gSystem->Load("libCore.so");
315 gSystem->Load("libTree.so");
316 gSystem->Load("libGeom.so");
317 gSystem->Load("libVMC.so");
318 gSystem->Load("libPhysics.so");
5ad99723 319 gSystem->Load("libMinuit");
2b42cee2 320 gSystem->Load("libSTEERBase");
321 gSystem->Load("libESD");
322 gSystem->Load("libAOD");
323 gSystem->Load("libANALYSIS");
324 gSystem->Load("libOADB");
325 gSystem->Load("libANALYSISalice");
9ef42f6c 326
bcf2601a 327 // Enable the needed package
2b42cee2 328 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
329 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
330 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
331 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
332 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
333 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
334 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
335 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
336 // gProof->UploadPackage("$ALICE_ROOT/obj/OADB");
337 // gProof->EnablePackage("$ALICE_ROOT/obj/OADB");
338 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
339 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
340 // gProof->UploadPackage("$ALICE_ROOT/obj/PWG0base");
341 // gProof->EnablePackage("$ALICE_ROOT/obj/PWG0base");
5ad99723 342 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/include"));
343 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
344 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
345 }
346 else if (runMode == kMyRunModeProofLite)
347 {
348 cout << "Init in CAF mode" << endl;
349
350 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
351 TProof * p = TProof::Open("");
352 // TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
353 // p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE);
354
355 // TProof::Mgr("alice-caf.cern.ch")->SetROOTVersion("VO_ALICE@ROOT::v5-28-00f");
356 // TProof::Mgr("alice-caf.cern.ch")->SetROOTVersion("5.28/00f");
357 gProof->UploadPackage("$ALICE_ROOT/ANALYSIS/macros/AliRootProofLite.par");
358 gProof->EnablePackage("AliRootProofLite");
359
bcf2601a 360 }
a23f7c97 361 else
bcf2601a 362 {
363 cout << "Init in Local or Grid mode" << endl;
364 gSystem->Load("libCore.so");
365 gSystem->Load("libTree.so");
366 gSystem->Load("libGeom.so");
367 gSystem->Load("libVMC.so");
368 gSystem->Load("libPhysics.so");
5ad99723 369 gSystem->Load("libMinuit");
bcf2601a 370 gSystem->Load("libSTEERBase");
371 gSystem->Load("libESD");
372 gSystem->Load("libAOD");
373 gSystem->Load("libANALYSIS");
9ef42f6c 374 gSystem->Load("libOADB");
bcf2601a 375 gSystem->Load("libANALYSISalice");
376 // Use AliRoot includes to compile our task
377 gROOT->ProcessLine(".include $ALICE_ROOT/include");
378
379 // gSystem->Load("libVMC");
380 // gSystem->Load("libTree");
381 // gSystem->Load("libSTEERBase");
382 // gSystem->Load("libESD");
383 // gSystem->Load("libAOD");
384 // gSystem->Load("libANALYSIS");
385 // gSystem->Load("libANALYSISalice");
386 // gSystem->Load("libPWG0base");
a23f7c97 387
bcf2601a 388 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
2bfe5463 389 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWGPP/background"));
390 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWGPP/background/"));
bcf2601a 391 }
a23f7c97 392 // Load helper classes
e0376287 393 TIterator * iter = listToLoad->MakeIterator();
394 TObjString * name = 0;
395 while (name = (TObjString *)iter->Next()) {
396 gSystem->ExpandPathName(name->String());
397 cout << name->String().Data();
5ad99723 398 if (runMode == kMyRunModeCAF || runMode == kMyRunModeProofLite) {
e0376287 399 gProof->Load(name->String()+(debug?"+g":""));
400 } else {
401 gROOT->LoadMacro(name->String()+(debug?"+g":""));
402 }
a23f7c97 403 }
404
a23f7c97 405}