Moving PbPb multiplicity in the new directory structure
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / ChargedHadrons / multPbPb / runTriggerStudy.C
CommitLineData
eef42d18 1enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
84bad6b8 2//#define TENDER
9d173aad 3TChain * GetAnalysisChain(const char * incollection);
4
eef42d18 5void runTriggerStudy(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 ntrackletsKine = 100, Bool_t rejectBGV0Trigger = kFALSE, const char* option = "", Int_t workers = -1)
9d173aad 6{
7 // runMode:
8 //
9 // 0 local
10 // 1 proof
84bad6b8 11#ifdef TENDER
12 TGrid::Connect("alien://");
13#endif
9d173aad 14 if (nev < 0)
15 nev = 1234567890;
9d173aad 16 InitAndLoadLibs(runMode,workers,debug);
17
18 // Create the analysis manager
19 mgr = new AliAnalysisManager;
20
21 // Add ESD handler
22 AliESDInputHandler* esdH = new AliESDInputHandler;
23 // Do I need any of this?
24 // esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
25 mgr->SetInputEventHandler(esdH);
26
27 if(isMC) {
28 AliMCEventHandler* handler = new AliMCEventHandler;
29 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
30 mgr->SetMCtruthEventHandler(handler);
31 }
32
eef42d18 33 // If we are running on grid, we need the alien handler
34 if (runMode == kMyRunModeGRID) {
35 // Create and configure the alien handler plugin
36 gROOT->LoadMacro("CreateAlienHandlerTrigger.C");
37 AliAnalysisGrid *alienHandler = CreateAlienHandlerTrigger(data,"pass1",isMC);
38 if (!alienHandler) {
39 cout << "Cannot create alien handler" << endl;
40 exit(1);
41 }
42 mgr->SetGridHandler(alienHandler);
43 }
9d173aad 44
84bad6b8 45 // Add tender
46#ifdef TENDER
47 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/TenderSupplies/AddTaskTender.C");
48 AliAnalysisTask* tender=0x0;
49 if(!isMC)
50 {
51 tender = AddTaskTender(kTRUE);
52 // tender->SetDebugLevel(10);
53 }
54 else
55 {
56 tender = AddTaskTender(kFALSE);
57 // tender->SetDebugLevel(10);
58 }
59#endif
60
bcc49144 61 // Add physics selection
62 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
84bad6b8 63 physicsSelectionTask = AddTaskPhysicsSelection(isMC,1,!isMC);//FIXME
abd808b9 64 physicsSelectionTask->GetPhysicsSelection()->SetSkipZDCTime(1);// Skip ZDC - applyied later
bcc49144 65
66
67
9d173aad 68 // Parse option strings
69 TString optionStr(option);
70
71 // remove SAVE option if set
72 // 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
73 Bool_t doSave = kFALSE;
74 TString optionStr(option);
75 if (optionStr.Contains("SAVE"))
76 {
77 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
78 doSave = kTRUE;
79 }
80
81
82
83 // load my task
84 AliAnalysisTaskTriggerStudy *task = new AliAnalysisTaskTriggerStudy("TaskOfflineTrigger");
85 mgr->AddTask(task);
86 // Set I/O
87 AliAnalysisDataContainer *cinput0 = mgr->GetCommonInputContainer();
88 AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("cTrigStudy",
89 AliHistoListWrapper::Class(),
90 AliAnalysisManager::kOutputContainer,
91 "Trig_Temp.root");
92 mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
93 mgr->ConnectOutput(task,1,coutput1);
94
95
96
97 task->SetIsMC(isMC);
eef42d18 98 task->SetNTrackletsCutKine(ntrackletsKine);
99 task->SetRejectBGWithV0(rejectBGV0Trigger);
100
9d173aad 101 if (!mgr->InitAnalysis()) return;
102
103 mgr->PrintStatus();
104
105 if (runMode == kMyRunModeLocal ) {
106 // If running in local mode, create chain of ESD files
107 cout << "RUNNING LOCAL, CHAIN" << endl;
108 TChain * chain = GetAnalysisChain(data);
109 // chain->Print();
110 mgr->StartAnalysis("local",chain,nev);
111 } else if (runMode == kMyRunModeCAF) {
112 mgr->StartAnalysis("proof",TString(data)+"#esdTree",nev);
eef42d18 113 } else if (runMode == kMyRunModeGRID) {
114 mgr->StartAnalysis("grid");
115 }else {
9d173aad 116 cout << "ERROR: unknown run mode" << endl;
117 }
118
eef42d18 119 if (doSave) MoveOutput(data, Form("_TrkCut_%d_V0BGCUT_%d",ntrackletsKine,rejectBGV0Trigger));
9d173aad 120
121
122}
123
124
125void MoveOutput(const char * data, const char * suffix = ""){
126
127 TString path("outTrigger/");
128 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
129
130 TString fileName = "trigger_study.root";
131 gSystem->mkdir(path, kTRUE);
132 gSystem->Rename(fileName, path + "/" + fileName);
84bad6b8 133 gSystem->Rename("event_stat.root", path + "/" + "event_stat.root");
9d173aad 134 Printf(">>>>> Moved files to %s", path.Data());
135}
136
137
138
139TChain * GetAnalysisChain(const char * incollection){
140 // Builds a chain of esd files
141 // incollection can be
142 // - a single root file
143 // - an xml collection of files on alien
144 // - a ASCII containing a list of local root files
145 TChain* analysisChain = 0;
146 // chain
147 analysisChain = new TChain("esdTree");
148 if (TString(incollection).Contains(".root")){
149 analysisChain->Add(incollection);
150 }
151 else if (TString(incollection).Contains("xml")){
152 TGrid::Connect("alien://");
153 TAlienCollection * coll = TAlienCollection::Open (incollection);
154 while(coll->Next()){
155 analysisChain->Add(TString("alien://")+coll->GetLFN());
156 }
157 } else {
158 ifstream file_collect(incollection);
159 TString line;
160 while (line.ReadLine(file_collect) ) {
161 analysisChain->Add(line.Data());
162 }
163 }
164 analysisChain->GetListOfFiles()->Print();
165
166 return analysisChain;
167}
168
169
170void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) {
171
172 if (runMode == kMyRunModeCAF)
173 {
174 cout << "Init in CAF mode" << endl;
175
176 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
84bad6b8 177 // cout << workers>0 ? Form("workers=%d",workers) : "workers=1x" << endl;
178 // exit(1);
179 TProof * p = TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "workers=1x");
bfae2924 180 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE);
181 //TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
9d173aad 182
84bad6b8 183 // Enable the needed package (par fileS)
184 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
185 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
186 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
187 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
188 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
189 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
190 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
191 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
192 // gProof->UploadPackage("$ALICE_ROOT/obj/OADB");
193 // gProof->EnablePackage("$ALICE_ROOT/obj/OADB");
194 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
195 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
196 // gProof->UploadPackage("$ALICE_ROOT/PWG0base");
197 // gProof->EnablePackage("$ALICE_ROOT/PWG0base");
9d173aad 198 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
2bfe5463 199 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWGPP/background"));
84bad6b8 200 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/include "));
201 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/TOF "));
202
203 // Use a precompiled tag
204 TString alirootMode=""; // STEERBase,ESD,AOD,ANALYSIS,ANALYSISalice (default aliroot mode)
205 //alirootMode="ALIROOT"; // $ALICE_ROOT/macros/loadlibs.C
206 // alirootMode="REC"; // $ALICE_ROOT/macros/loadlibsrec.C
207 // alirootMode="SIM"; // $ALICE_ROOT/macros/loadlibssim.C
208 // alirootMode="TRAIN"; // $ALICE_ROOT/macros/loadlibstrain.C (not working yet)
209 // alirootMode="CUSTOM"; // nothing is loaded, but aliroot variables are set (not working yet)
210
211 TString extraLibs;
212 extraLibs= ""; // not needed in default aliroot mode
213 extraLibs+="CDB:RAWDatabase:STEER:TENDER:TRDbase:STAT:TRDrec:VZERObase:VZEROsim:VZEROrec:RAWDatarec:TPCbase:TPCrec:TPCcalib:TENDERSupplies:RAWDatabase:RAWDatarec:RAWDatasim:TOFbase:TOFrec";
214 TList *list = new TList();
215 // sets $ALIROOT_MODE on each worker to let proof to know to run in special mode
216 list->Add(new TNamed("ALIROOT_MODE", alirootMode.Data()));
217 // sets $ALIROOT_EXTRA_LIBS on each worker to let proof to know to load extra libs
218 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", extraLibs.Data()));
219#ifdef TENDER
220 list->Add(new TNamed("ALIROOT_ENABLE_ALIEN", "1"));
221#endif
222 // connect to proof
223 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-22-AN", list);
224 // gProof->Exec("TGrid::Connect(\"alien://\");");
9d173aad 225 }
226 else
227 {
eef42d18 228 cout << "Init in Local or Grid mode" << endl;
9d173aad 229
f07573a6 230 gSystem->Load("libCore");
231 gSystem->Load("libGeom");
232 gSystem->Load("libPhysics");
9d173aad 233 gSystem->Load("libVMC");
234 gSystem->Load("libTree");
f07573a6 235 gSystem->Load("libProof");
236 gSystem->Load("libTree");
9d173aad 237 gSystem->Load("libSTEERBase");
238 gSystem->Load("libESD");
239 gSystem->Load("libAOD");
240 gSystem->Load("libANALYSIS");
84bad6b8 241 gSystem->Load("libOADB");
9d173aad 242 gSystem->Load("libANALYSISalice");
243 gSystem->Load("libPWG0base");
244
245 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
2bfe5463 246 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWGPP/background"));
247 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWGPP/background/"));
9d173aad 248 }
249 // Load helper classes
250 // TODO: replace this by a list of TOBJStrings
251 TString taskName("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisTaskTriggerStudy.cxx+");
2bfe5463 252 TString listName("$ALICE_ROOT/PWGPP/background/AliHistoListWrapper.cxx+");
9d173aad 253
254 gSystem->ExpandPathName(taskName);
255 gSystem->ExpandPathName(listName);
256
257
258
259 // Create, add task
260 if (runMode == kMyRunModeCAF) {
261 gProof->Load(listName+(debug?"+g":""));
262 gProof->Load(taskName+(debug?"+g":""));
263 } else {
264 gROOT->LoadMacro(listName+(debug?"+g":""));
265 gROOT->LoadMacro(taskName+(debug?"+g":""));
266 }
267
268
269}