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