2 // #include "AliAnalysisManager.h"
3 // #include "AliESDInputHandler.h"
4 // #include "AliMCEventHandler.h"
5 // #include "AliAnalysisGrid.h"
6 // #include "AliCentralitySelectionTask.h"
7 // #include "AliAnalysisCentralitySelector.h"
8 // #include "AliAnalysisTaskPerformanceStrange.h"
9 // #include "TString.h"
10 // #include "TChain.h"
11 // #include "TAlienCollection.h"
13 // #include "TObjString.h"
14 // #include "TIterator.h"
18 // #include "CreateAlienHandler.C"
23 enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
25 TList * listToLoad = new TList(); // Additional classes to be loaded, see InitAndLoadLibs
27 TChain * GetAnalysisChain(const char * incollection);
28 void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) ;
30 void run(const char * data, const char * passOrPath, Long64_t nev = -1, Long64_t offset = 0, Bool_t debug = kFALSE, Int_t runMode = 0, Bool_t isMC = 0, Bool_t usePID = kTRUE, const char* option = "",TString customSuffix = "", Int_t workers = -1, const char * gridMode="full")
40 InitAndLoadLibs(runMode,workers,debug);
42 // Create the analysis manager
43 AliAnalysisManager * mgr = new AliAnalysisManager;
46 AliESDInputHandler* esdH = new AliESDInputHandler;
47 // Do I need any of this?
48 // esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
49 mgr->SetInputEventHandler(esdH);
52 AliMCEventHandler* handler = new AliMCEventHandler;
53 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
54 mgr->SetMCtruthEventHandler(handler);
58 // If we are running on grid, we need the alien handler
59 if (runMode == kMyRunModeGRID) {
60 // Create and configure the alien handler plugin
61 TGrid::Connect("alien://");// Why do I need this? Without a get a bus error...
62 // gROOT->LoadMacro("CreateAlienHandler.C");
63 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC);
65 cout << "Cannot create alien handler" << endl;
68 mgr->SetGridHandler(alienHandler);
73 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
74 AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC);
77 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
78 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
80 AliAnalysisCentralitySelector * centrSelector = new AliAnalysisCentralitySelector();
81 centrSelector->SetIsMC(isMC);
82 centrSelector->SetCentralityEstimator("V0M"); // Todo: add parameter to macro?
84 // Parse option strings
85 TString optionStr(option);
87 // remove SAVE option if set
88 Bool_t doSave = kFALSE;
90 if (optionStr.Contains("SAVE"))
92 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
95 TString pathsuffix = "";
96 // Not used, but may be useful
97 Bool_t useMCKinematics = isMC;
98 if (optionStr.Contains("NOMCKIN")) {
99 cout << ">>>> Ignoring MC kinematics" << endl;
100 useMCKinematics=kFALSE;
101 pathsuffix+="_NOMCKIN";
104 gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C");
105 Int_t nbin = 0; // will contain the number of centrality bins
106 AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", centrSelector, nbin); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...)
108 // else if (iAODanalysis) task->SetAnalysisType("AOD");
109 // FIXME: add options to macro
110 // FIXME: put physics selection inside the task
111 cout << nbin << endl;
113 for(Int_t ibin = 0; ibin < nbin; ibin++){
114 cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl;
116 task[ibin]->SetAnalysisType("ESD");
118 task[ibin]->SetAnalysisMC(isMC); // 0 or 1
120 task[ibin]->SetCollidingSystems(1); // 0 =pp, 1=AA
122 task[ibin]->SetAnalysisCut("no");
125 task[ibin]->SetUsePID("withPID"); // withPID or withoutPID
127 task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID
131 // Init and run the analy
132 if (!mgr->InitAnalysis()) return;
136 if (runMode == kMyRunModeLocal ) {
137 // If running in local mode, create chain of ESD files
138 cout << "RUNNING LOCAL, CHAIN" << endl;
139 TChain * chain = GetAnalysisChain(data);
141 mgr->StartAnalysis("local",chain,nev);
142 } else if (runMode == kMyRunModeCAF) {
143 mgr->StartAnalysis("proof",TString(passOrPath)+TString(data)+"#esdTree",nev);
144 } else if (runMode == kMyRunModeGRID) {
145 mgr->StartAnalysis("grid");
147 cout << "ERROR: unknown run mode" << endl;
150 pathsuffix += customSuffix;
152 if (doSave) MoveOutput(data, pathsuffix.Data());
157 void MoveOutput(const char * data, const char * suffix = ""){
159 TString path("output/");
160 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
162 TString fileName = "lambdak0.root";
163 gSystem->mkdir(path, kTRUE);
164 gSystem->Rename(fileName, path + "/" + fileName);
165 for(Int_t ibin = 0; ibin < 20; ibin++){
166 TString fileBin = fileName;
167 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
168 gSystem->Rename(fileBin, path + "/" + fileBin);
171 gSystem->Rename("event_stat.root", path + "/event_stat.root");
172 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
173 Printf(">>>>> Moved files to %s", path.Data());
178 TChain * GetAnalysisChain(const char * incollection){
179 // Builds a chain of esd files
180 // incollection can be
181 // - a single root file
182 // - an xml collection of files on alien
183 // - a ASCII containing a list of local root files
185 TChain* analysisChain = 0;
187 analysisChain = new TChain("esdTree");
188 if (TString(incollection).Contains(".root")){
189 analysisChain->Add(incollection);
191 else if (TString(incollection).Contains("xml")){
192 TGrid::Connect("alien://");
193 TGridCollection * coll = TAlienCollection::Open (incollection);
195 analysisChain->Add(TString("alien://")+coll->GetLFN());
198 ifstream file_collect(incollection);
200 while (line.ReadLine(file_collect) ) {
201 analysisChain->Add(line.Data());
204 analysisChain->GetListOfFiles()->Print();
206 return analysisChain;
210 void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
211 // Loads libs and par files + custom task and classes (the order is important)
212 listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!?
213 listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx"));
214 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx"));
216 if (runMode == kMyRunModeCAF)
218 cout << "Init in CAF mode" << endl;
220 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
221 TProof * p = TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
222 //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
223 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
224 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-13-AN");
227 // Enable the needed package
228 // FIXME: what if I don't want to use par files?
229 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
230 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
231 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
232 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
233 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
234 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
235 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
236 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
237 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
238 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
239 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
240 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
241 // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW");
242 // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW");
243 // gProof->UploadPackage("~/Desktop/OADB");//FIXME
244 // gProof->EnablePackage("~/Desktop/OADB");//FIXME
249 cout << "Init in Local or Grid mode" << endl;
250 gSystem->Load("libCore.so");
251 gSystem->Load("libTree.so");
252 gSystem->Load("libGeom.so");
253 gSystem->Load("libVMC.so");
254 gSystem->Load("libPhysics.so");
255 gSystem->Load("libSTEERBase");
256 gSystem->Load("libESD");
257 gSystem->Load("libAOD");
258 gSystem->Load("libANALYSIS");
259 gSystem->Load("libANALYSISalice");
261 // gSystem->Load("libVMC");
262 gROOT->ProcessLine(".include $ALICE_ROOT/include");
263 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
265 // Load helper classes
266 TIterator * iter = listToLoad->MakeIterator();
267 TObjString * name = 0;
268 while ((name = (TObjString *)iter->Next())) {
269 gSystem->ExpandPathName(name->String());
270 cout << name->String().Data() << endl;
271 if (runMode == kMyRunModeCAF) {
272 gProof->Load(name->String()+(debug?"++g":"+"));
274 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));