]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/multPbPb/run.C
Main Updates:
[u/mrichter/AliRoot.git] / PWG0 / multPbPb / run.C
1 // TODO:
2 // 1. Check cuts for 2010 (Jochen?)
3 // 2. Run with many centrality bins at once
4 #include <string.h>
5
6 enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
7
8 TList * listToLoad = new TList();
9
10 TChain * GetAnalysisChain(const char * incollection);
11
12 void run(Char_t* data, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 0, Bool_t isMC = 0, Int_t centrBin = 0, const char * centrEstimator = "VOM", const char* option = "",TString customSuffix = "", Int_t workers = -1)
13 {
14   // runMode:
15   //
16   // 0 local 
17   // 1 proof
18
19   if (nev < 0)
20     nev = 1234567890;
21
22   InitAndLoadLibs(runMode,workers,debug);
23
24   // Create the analysis manager
25   mgr = new AliAnalysisManager;
26
27   // Add ESD handler
28   AliESDInputHandler* esdH = new AliESDInputHandler;
29   // Do I need any of this? 
30   //  esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
31   mgr->SetInputEventHandler(esdH);
32
33   if(isMC) {
34     AliMCEventHandler* handler = new AliMCEventHandler;
35     handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
36     mgr->SetMCtruthEventHandler(handler);
37   }
38
39
40   // If we are running on grid, we need the alien handler
41   if (runMode == kMyRunModeGRID) {
42     // Create and configure the alien handler plugin
43     gROOT->LoadMacro("CreateAlienHandler.C");
44     AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, "test", isMC);  
45     if (!alienHandler) {
46       cout << "Cannot create alien handler" << endl;    
47       exit(1);
48     }
49     mgr->SetGridHandler(alienHandler);  
50   }
51
52
53
54   // physics selection
55   gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
56   physicsSelectionTask = AddTaskPhysicsSelection(isMC);
57
58   // Centrality
59   AliCentralitySelectionTask *taskCentr = new AliCentralitySelectionTask("CentralitySelection");
60   taskCentr->SetPercentileFile("$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityBy1D.root");
61   taskCentr->SetPercentileFile2("$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityByFunction.root");
62   mgr->AddTask(taskCentr);
63   mgr->ConnectInput (taskCentr,0, mgr->GetCommonInputContainer());
64
65
66   // Parse option strings
67   TString optionStr(option);
68   
69   // remove SAVE option if set
70   // 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
71   Bool_t doSave = kFALSE;
72   TString optionStr(option);
73   if (optionStr.Contains("SAVE"))
74   {
75     optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
76     doSave = kTRUE;
77   }
78
79   AliESDtrackCuts * cuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
80   TString pathsuffix = "";
81   // cuts->SetPtRange(0.15,0.2);// FIXME pt cut
82   // const char * pathsuffix = "_pt_015_020_nofakes";
83
84   if (optionStr.Contains("ITSsa")) {
85     delete cuts;
86     cuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2009();
87     cout << ">>>> USING ITS sa tracks" << endl;
88     pathsuffix="ITSsa";
89   }
90
91   if (optionStr.Contains("TPC")) {
92     delete cuts;
93     cuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
94     cout << ">>>> USING TPC only tracks" << endl;
95     pathsuffix="TPC";
96   }
97
98   Bool_t useMCKinematics = isMC;
99   if (optionStr.Contains("NOMCKIN")) {
100     cout << ">>>> Ignoring MC kinematics" << endl;
101     useMCKinematics=kFALSE;
102   }
103   
104   
105   // load my task
106   gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/multPbPb/AddTaskMultPbPbTracks.C");
107   AliAnalysisTaskMultPbTracks * task = AddTaskMultPbPbTracks("multPbPbtracks.root", cuts); // kTRUE enables DCA cut
108   task->SetIsMC(useMCKinematics);
109   if(useMCKinematics) task->GetHistoManager()->SetSuffix("MC");
110   if(customSuffix!=""){
111     cout << "Setting custom suffix: " << customSuffix << endl;    
112     task->GetHistoManager()->SetSuffix(customSuffix);
113   }
114   task->SetCentralityBin(centrBin);
115   task->SetCentralityEstimator(centrEstimator);
116   
117   if (!mgr->InitAnalysis()) return;
118         
119   mgr->PrintStatus();
120   
121   if (runMode == kMyRunModeLocal ) {
122     // If running in local mode, create chain of ESD files
123     cout << "RUNNING LOCAL, CHAIN" << endl;    
124     TChain * chain = GetAnalysisChain(data);
125     chain->Print();
126     mgr->StartAnalysis("local",chain,nev);
127   } else if (runMode == kMyRunModeCAF) {
128     mgr->StartAnalysis("proof",TString(data)+"#esdTree",nev);
129   } else if (runMode == kMyRunModeGRID) {
130     mgr->StartAnalysis("grid");
131   } else {
132     cout << "ERROR: unknown run mode" << endl;        
133   }
134
135   pathsuffix = pathsuffix + "_" + centrEstimator + "_bin_"+long(centrBin);
136   if (doSave) MoveOutput(data, pathsuffix.Data());
137
138   
139 }
140
141
142 void MoveOutput(const char * data, const char * suffix = ""){
143
144   TString path("output/");
145   path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
146   
147   TString fileName = "multPbPbtracks.root";
148   gSystem->mkdir(path, kTRUE);
149   gSystem->Rename(fileName, path + "/" + fileName);
150   gSystem->Rename("event_stat.root", path + "/event_stat.root");      
151   Printf(">>>>> Moved files to %s", path.Data());
152 }  
153
154
155
156 TChain * GetAnalysisChain(const char * incollection){
157   // Builds a chain of esd files
158   // incollection can be
159   // - a single root file
160   // - an xml collection of files on alien
161   // - a ASCII containing a list of local root files
162   TChain* analysisChain = 0;
163   // chain
164   analysisChain = new TChain("esdTree");
165   if (TString(incollection).Contains(".root")){
166     analysisChain->Add(incollection);
167   }
168   else if (TString(incollection).Contains("xml")){
169     TGrid::Connect("alien://");
170     TAlienCollection * coll = TAlienCollection::Open (incollection);
171     while(coll->Next()){
172       analysisChain->Add(TString("alien://")+coll->GetLFN());
173     }
174   } else {
175     ifstream file_collect(incollection);
176     TString line;
177     while (line.ReadLine(file_collect) ) {
178       analysisChain->Add(line.Data());
179     }
180   }
181   analysisChain->GetListOfFiles()->Print();
182
183   return analysisChain;
184 }
185
186
187 void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) {
188   // Loads libs and par files + custom task and classes
189
190   // Custom stuff to be loaded
191   listToLoad->Add(new TObjString("$ALICE_ROOT/ANALYSIS/AliCentralitySelectionTask.cxx+"));
192   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG1/background/AliHistoListWrapper.cxx+"));
193   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbTrackHistoManager.cxx+"));
194   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisTaskMultPbTracks.cxx+"));
195
196
197   if (runMode == kMyRunModeCAF)
198   {
199     cout << "Init in CAF mode" << endl;
200     
201     gEnv->SetValue("XSec.GSI.DelegProxy", "2");
202     TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
203     
204     // Enable the needed package
205     gProof->UploadPackage("$ALICE_ROOT/STEERBase");
206     gProof->EnablePackage("$ALICE_ROOT/STEERBase");
207     gProof->UploadPackage("$ALICE_ROOT/ESD");
208     gProof->EnablePackage("$ALICE_ROOT/ESD");
209     gProof->UploadPackage("$ALICE_ROOT/AOD");
210     gProof->EnablePackage("$ALICE_ROOT/AOD");
211     gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
212     gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
213     gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
214     gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
215     gProof->UploadPackage("$ALICE_ROOT/PWG0base");
216     gProof->EnablePackage("$ALICE_ROOT/PWG0base");
217     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
218     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
219   }
220   else
221   {
222     cout << "Init in Local or Grid mode" << endl;
223
224     gSystem->Load("libVMC");
225     gSystem->Load("libTree");
226     gSystem->Load("libSTEERBase");
227     gSystem->Load("libESD");
228     gSystem->Load("libAOD");
229     gSystem->Load("libANALYSIS");
230     gSystem->Load("libANALYSISalice");
231     gSystem->Load("libPWG0base");
232     
233     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
234     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
235     //    gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background/"));
236   }
237   // Load helper classes
238   TIterator * iter = listToLoad->MakeIterator();
239   TObjString * name = 0;
240   while (name = (TObjString *)iter->Next()) {
241     gSystem->ExpandPathName(name->String());
242     cout << name->String().Data();
243     if (runMode == kMyRunModeCAF) {
244       gProof->Load(name->String()+(debug?"+g":""));   
245     } else {
246       gROOT->LoadMacro(name->String()+(debug?"+g":""));   
247     }
248   }
249
250 }