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)
41 InitAndLoadLibs(runMode,workers,debug);
43 // Create the analysis manager
44 AliAnalysisManager * mgr = new AliAnalysisManager;
47 AliESDInputHandler* esdH = new AliESDInputHandler;
48 mgr->SetInputEventHandler(esdH);
51 AliMCEventHandler* handler = new AliMCEventHandler;
52 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
53 mgr->SetMCtruthEventHandler(handler);
57 // If we are running on grid, we need the alien handler
58 if (runMode == kMyRunModeGRID) {
59 // Create and configure the alien handler plugin
60 TGrid::Connect("alien://");// Why do I need this? Without a get a bus error...
61 gROOT->LoadMacro("CreateAlienHandler.C");
62 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC);
64 cout << "Cannot create alien handler" << endl;
67 mgr->SetGridHandler(alienHandler);
71 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
72 AddTaskPIDResponse(isMC,kTRUE);
73 //AddTaskPIDResponse();
75 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
76 AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0);
79 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
80 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
81 //taskCentrality->SetPass(2);
82 if(isMC) taskCentrality->SetMCInput();
84 AliAnalysisCentralitySelector * centrSelector = new AliAnalysisCentralitySelector();
85 centrSelector->SetIsMC(isMC);
86 centrSelector->SetCentralityEstimator("V0M"); // Todo: add parameter to macro?
88 // Parse option strings
89 TString optionStr(option);
91 // remove SAVE option if set
92 Bool_t doSave = kFALSE;
94 if (optionStr.Contains("SAVE"))
96 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
99 TString pathsuffix = "";
100 // Not used, but may be useful
101 Bool_t useMCKinematics = isMC;
102 if (optionStr.Contains("NOMCKIN")) {
103 cout << ">>>> Ignoring MC kinematics" << endl;
104 useMCKinematics=kFALSE;
105 pathsuffix+="_NOMCKIN";
108 gROOT->ProcessLine(".L AddTaskLambdaK0PbPb.C");
109 Int_t nbin = 0; // will contain the number of centrality bins
110 AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb("lambdak0.root", centrSelector, nbin, binMin, binMax,isMC);
112 // else if (iAODanalysis) task->SetAnalysisType("AOD");
113 // FIXME: add options to macro
114 // FIXME: put physics selection inside the task
115 cout << nbin << endl;
117 for(Int_t ibin = 0; ibin < nbin; ibin++){
118 cout << "ibin " << ibin << " "<< endl;//task[ibin] << endl;
120 task[ibin]->SetAnalysisType("ESD");
122 task[ibin]->SetAnalysisMC(isMC); // 0 or 1
124 task[ibin]->SetCollidingSystems(2); // 0 =pp, 1=AA 2=pA
126 task[ibin]->SetAnalysisCut("no");
128 task[ibin]->SetQASelector(kFALSE); // Todo -> put trees for QA
131 task[ibin]->SetUsePID("withPID"); // withPID or withoutPID
133 task[ibin]->SetUsePID("withoutPID"); // withPID or withoutPID
137 // Init and run the analy
138 if (!mgr->InitAnalysis()) return;
142 if (runMode == kMyRunModeLocal ) {
143 // If running in local mode, create chain of ESD files
144 cout << "RUNNING LOCAL, CHAIN" << endl;
145 TChain * chain = GetAnalysisChain(data);
147 mgr->StartAnalysis("local",chain,nev);
148 } else if (runMode == kMyRunModeCAF) {
149 mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev);
150 } else if (runMode == kMyRunModeGRID) {
151 mgr->StartAnalysis("grid");
153 cout << "ERROR: unknown run mode" << endl;
156 pathsuffix += customSuffix;
158 if (doSave) MoveOutput(data, pathsuffix.Data());
163 void MoveOutput(const char * data, const char * suffix = ""){
165 // TString path("output10bins/");
166 TString path("output10binsNew/");
167 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
169 TString fileName = "lambdak0.root";
170 gSystem->mkdir(path, kTRUE);
171 gSystem->Rename(fileName, path + "/" + fileName);
172 for(Int_t ibin = 0; ibin < 20; ibin++){
173 TString fileBin = fileName;
174 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
175 gSystem->Rename(fileBin, path + "/" + fileBin);
178 gSystem->Rename("event_stat.root", path + "/event_stat.root");
179 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
180 Printf(">>>>> Moved files to %s", path.Data());
185 TChain * GetAnalysisChain(const char * incollection){
186 // Builds a chain of esd files
187 // incollection can be
188 // - a single root file
189 // - an xml collection of files on alien
190 // - a ASCII containing a list of local root files
192 TChain* analysisChain = 0;
194 analysisChain = new TChain("esdTree");
195 if (TString(incollection).Contains(".root")){
196 analysisChain->Add(incollection);
198 else if (TString(incollection).Contains("xml")){
199 TGrid::Connect("alien://");
200 TGridCollection * coll = TAlienCollection::Open (incollection);
202 analysisChain->Add(TString("alien://")+coll->GetLFN());
205 ifstream file_collect(incollection);
207 while (line.ReadLine(file_collect) ) {
208 analysisChain->Add(line.Data());
211 analysisChain->GetListOfFiles()->Print();
213 return analysisChain;
217 void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
218 // Loads libs and par files + custom task and classes (the order is important)
219 // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!?
220 listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx"));
221 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx"));
223 if (runMode == kMyRunModeCAF)
225 cout << "Init in CAF mode" << endl;
227 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
228 Char_t* alienuser = gSystem->Getenv("alien_API_USER");
229 TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
230 //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
231 //p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
232 gProof->EnablePackage("VO_ALICE@AliRoot::v5-04-11-AN");
233 gProof->GetManager()->SetROOTVersion("VO_ALICE@ROOT::v5-34-02");
234 // gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN");
237 // Enable the needed package
238 // FIXME: what if I don't want to use par files?
239 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
240 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
241 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
242 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
243 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
244 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
245 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
246 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
247 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
248 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
249 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
250 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
251 // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW");
252 // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW");
253 // gProof->UploadPackage("~/Desktop/OADB");//FIXME
254 // gProof->EnablePackage("~/Desktop/OADB");//FIXME
259 cout << "Init in Local or Grid mode" << endl;
262 if ( gSystem->Load("libCore") < 0 ) return ret; ret--;
263 if ( gSystem->Load("libTree") < 0 ) return ret; ret--;
264 if ( gSystem->Load("libGeom") < 0 ) return ret; ret--;
265 if ( gSystem->Load("libVMC") < 0 ) return ret; ret--;
266 if ( gSystem->Load("libPhysics") < 0 ) return ret; ret--;
267 if ( gSystem->Load("libMinuit") < 0 ) return ret; ret--;
268 if ( gSystem->Load("libSTEERBase") < 0 ){ cout<<"libSTEERBase coul not be loaded!!!"<<endl; }//return ret; ret--;}
269 if ( gSystem->Load("libESD") < 0 ) return ret; ret--;
270 if ( gSystem->Load("libAOD") < 0 ) return ret; ret--;
271 if ( gSystem->Load("libANALYSIS") < 0 ) return ret; ret--;
272 if ( gSystem->Load("libANALYSISalice") < 0 ) return ret; ret--;
275 gROOT->ProcessLine(".include $ALICE_ROOT/include");
276 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
277 cout<<"/////////////////////////////////////"<<endl;
278 cout<<endl<<"libraries loaded !"<<endl;
279 cout<<"/////////////////////////////////////"<<endl;
281 // Load helper classes
282 TIterator * iter = listToLoad->MakeIterator();
283 TObjString * name = 0;
284 while ((name = (TObjString *)iter->Next())) {
285 gSystem->ExpandPathName(name->String());
286 cout << name->String().Data() << endl;
287 if (runMode == kMyRunModeCAF) {
288 gProof->Load(name->String()+(debug?"++g":"+"));
290 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));