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 = 2, Bool_t isMC = 0, Bool_t usePID = kTRUE, const char* option = "",TString customSuffix = "", Int_t workers = -1, const char * gridMode="full", Int_t binMin=0, Int_t binMax = 10)
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);
72 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
74 //AddTaskPIDResponse();
76 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
77 AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC);
80 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
81 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
82 //taskCentrality->SetPass(2);
83 if(isMC) taskCentrality->SetMCInput();
85 AliAnalysisCentralitySelector * centrSelector = new AliAnalysisCentralitySelector();
86 centrSelector->SetIsMC(isMC);
87 centrSelector->SetCentralityEstimator("V0M"); // Todo: add parameter to macro?
89 // Parse option strings
90 TString optionStr(option);
92 // remove SAVE option if set
93 Bool_t doSave = kFALSE;
95 if (optionStr.Contains("SAVE"))
97 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
100 TString pathsuffix = "";
101 // Not used, but may be useful
102 Bool_t useMCKinematics = isMC;
103 if (optionStr.Contains("NOMCKIN")) {
104 cout << ">>>> Ignoring MC kinematics" << endl;
105 useMCKinematics=kFALSE;
106 pathsuffix+="_NOMCKIN";
109 gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C");
110 Int_t nbin = 0; // will contain the number of centrality bins
111 AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", centrSelector, nbin, binMin, binMax,isMC); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...)
113 // else if (iAODanalysis) task->SetAnalysisType("AOD");
114 // FIXME: add options to macro
115 // FIXME: put physics selection inside the task
116 cout << nbin << endl;
118 for(Int_t ibin = 0; ibin < nbin; ibin++){
119 cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl;
121 task[ibin]->SetAnalysisType("ESD");
123 task[ibin]->SetAnalysisMC(isMC); // 0 or 1
125 task[ibin]->SetCollidingSystems(1); // 0 =pp, 1=AA
127 task[ibin]->SetAnalysisCut("no");
130 task[ibin]->SetUsePID("withPID"); // withPID or withoutPID
132 task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID
136 // Init and run the analy
137 if (!mgr->InitAnalysis()) return;
141 if (runMode == kMyRunModeLocal ) {
142 // If running in local mode, create chain of ESD files
143 cout << "RUNNING LOCAL, CHAIN" << endl;
144 TChain * chain = GetAnalysisChain(data);
146 mgr->StartAnalysis("local",chain,nev);
147 } else if (runMode == kMyRunModeCAF) {
148 mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev);
149 } else if (runMode == kMyRunModeGRID) {
150 mgr->StartAnalysis("grid");
152 cout << "ERROR: unknown run mode" << endl;
155 pathsuffix += customSuffix;
157 if (doSave) MoveOutput(data, pathsuffix.Data());
162 void MoveOutput(const char * data, const char * suffix = ""){
164 // TString path("output10bins/");
165 TString path("output10binsNew/");
166 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
168 TString fileName = "lambdak0.root";
169 gSystem->mkdir(path, kTRUE);
170 gSystem->Rename(fileName, path + "/" + fileName);
171 for(Int_t ibin = 0; ibin < 20; ibin++){
172 TString fileBin = fileName;
173 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
174 gSystem->Rename(fileBin, path + "/" + fileBin);
177 gSystem->Rename("event_stat.root", path + "/event_stat.root");
178 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
179 Printf(">>>>> Moved files to %s", path.Data());
184 TChain * GetAnalysisChain(const char * incollection){
185 // Builds a chain of esd files
186 // incollection can be
187 // - a single root file
188 // - an xml collection of files on alien
189 // - a ASCII containing a list of local root files
191 TChain* analysisChain = 0;
193 analysisChain = new TChain("esdTree");
194 if (TString(incollection).Contains(".root")){
195 analysisChain->Add(incollection);
197 else if (TString(incollection).Contains("xml")){
198 TGrid::Connect("alien://");
199 TGridCollection * coll = TAlienCollection::Open (incollection);
201 analysisChain->Add(TString("alien://")+coll->GetLFN());
204 ifstream file_collect(incollection);
206 while (line.ReadLine(file_collect) ) {
207 analysisChain->Add(line.Data());
210 analysisChain->GetListOfFiles()->Print();
212 return analysisChain;
216 void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
217 // Loads libs and par files + custom task and classes (the order is important)
218 // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!?
219 listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx"));
220 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx"));
222 if (runMode == kMyRunModeCAF)
224 cout << "Init in CAF mode" << endl;
226 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
227 Char_t* alienuser = gSystem->Getenv("alien_API_USER");
228 TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
229 //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
230 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
231 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-18-AN");
232 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-20-AN");
233 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-21-AN");
234 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-28-AN");
235 //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-31-AN");
236 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-33-AN");
238 // Enable the needed package
239 // FIXME: what if I don't want to use par files?
240 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
241 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
242 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
243 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
244 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
245 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
246 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
247 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
248 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
249 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
250 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
251 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
252 // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW");
253 // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW");
254 // gProof->UploadPackage("~/Desktop/OADB");//FIXME
255 // gProof->EnablePackage("~/Desktop/OADB");//FIXME
260 cout << "Init in Local or Grid mode" << endl;
261 gSystem->Load("libCore.so");
262 gSystem->Load("libTree.so");
263 gSystem->Load("libGeom.so");
264 gSystem->Load("libVMC.so");
265 gSystem->Load("libPhysics.so");
266 gSystem->Load("libSTEERBase");
267 gSystem->Load("libESD");
268 gSystem->Load("libAOD");
269 gSystem->Load("libANALYSIS");
270 gSystem->Load("libANALYSISalice");
272 // gSystem->Load("libVMC");
273 gROOT->ProcessLine(".include $ALICE_ROOT/include");
274 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
276 // Load helper classes
277 TIterator * iter = listToLoad->MakeIterator();
278 TObjString * name = 0;
279 while ((name = (TObjString *)iter->Next())) {
280 gSystem->ExpandPathName(name->String());
281 cout << name->String().Data() << endl;
282 if (runMode == kMyRunModeCAF) {
283 gProof->Load(name->String()+(debug?"++g":"+"));
285 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));