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 // 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", nbin, binMin, binMax,isMC,1);
107 // AliAnalysisTaskPerformanceStrange ** task = AddTaskLambdaK0PbPb();
109 cout << nbin << endl;
110 // Init and run the analy
111 if (!mgr->InitAnalysis()) return;
115 if (runMode == kMyRunModeLocal ) {
116 // If running in local mode, create chain of ESD files
117 cout << "RUNNING LOCAL, CHAIN" << endl;
118 TChain * chain = GetAnalysisChain(data);
120 mgr->StartAnalysis("local",chain,nev);
121 } else if (runMode == kMyRunModeCAF) {
122 mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev);
123 } else if (runMode == kMyRunModeGRID) {
124 mgr->StartAnalysis("grid");
126 cout << "ERROR: unknown run mode" << endl;
129 pathsuffix += customSuffix;
131 if (doSave) MoveOutput(data, pathsuffix.Data());
136 void MoveOutput(const char * data, const char * suffix = ""){
138 // TString path("output10bins/");
139 TString path("output10binsNew/");
140 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
142 TString fileName = "lambdak0.root";
143 gSystem->mkdir(path, kTRUE);
144 gSystem->Rename(fileName, path + "/" + fileName);
145 for(Int_t ibin = 0; ibin < 20; ibin++){
146 TString fileBin = fileName;
147 fileBin.ReplaceAll(".root",Form("_%2.2d.root",ibin));
148 gSystem->Rename(fileBin, path + "/" + fileBin);
151 gSystem->Rename("event_stat.root", path + "/event_stat.root");
152 gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root");
153 Printf(">>>>> Moved files to %s", path.Data());
158 TChain * GetAnalysisChain(const char * incollection){
159 // Builds a chain of esd files
160 // incollection can be
161 // - a single root file
162 // - an xml collection of files on alien
163 // - a ASCII containing a list of local root files
165 TChain* analysisChain = 0;
167 analysisChain = new TChain("esdTree");
168 if (TString(incollection).Contains(".root")){
169 analysisChain->Add(incollection);
171 else if (TString(incollection).Contains("xml")){
172 TGrid::Connect("alien://");
173 TGridCollection * coll = TAlienCollection::Open (incollection);
175 analysisChain->Add(TString("alien://")+coll->GetLFN());
178 ifstream file_collect(incollection);
180 while (line.ReadLine(file_collect) ) {
181 analysisChain->Add(line.Data());
184 analysisChain->GetListOfFiles()->Print();
186 return analysisChain;
190 void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) {
191 // Loads libs and par files + custom task and classes (the order is important)
192 // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!?
193 listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx"));
194 listToLoad->Add(new TObjString("AliAnalysisTaskPerformanceStrange.cxx"));
196 if (runMode == kMyRunModeCAF)
198 cout << "Init in CAF mode" << endl;
200 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
201 Char_t* alienuser = gSystem->Getenv("alien_API_USER");
202 TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
203 // TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : "");
204 p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging
205 gProof->EnablePackage("VO_ALICE@AliRoot::v5-04-40-AN");
206 gProof->GetManager()->SetROOTVersion("VO_ALICE@ROOT::v5-34-05");
207 // gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN");
210 // Enable the needed package
211 // FIXME: what if I don't want to use par files?
212 gSystem->AddIncludePath("-I${ALICE_ROOT}/include/");
213 gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/");
214 // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase");
215 // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase");
216 // gProof->UploadPackage("$ALICE_ROOT/obj/ESD");
217 // gProof->EnablePackage("$ALICE_ROOT/obj/ESD");
218 // gProof->UploadPackage("$ALICE_ROOT/obj/AOD");
219 // gProof->EnablePackage("$ALICE_ROOT/obj/AOD");
220 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS");
221 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS");
222 // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice");
223 // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice");
224 // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW");
225 // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW");
226 // gProof->UploadPackage("~/Desktop/OADB");//FIXME
227 // gProof->EnablePackage("~/Desktop/OADB");//FIXME
232 cout << "Init in Local or Grid mode" << endl;
235 if ( gSystem->Load("libCore") < 0 ) return ret; ret--;
236 if ( gSystem->Load("libTree") < 0 ) return ret; ret--;
237 if ( gSystem->Load("libGeom") < 0 ) return ret; ret--;
238 if ( gSystem->Load("libVMC") < 0 ) return ret; ret--;
239 if ( gSystem->Load("libPhysics") < 0 ) return ret; ret--;
240 if ( gSystem->Load("libMinuit") < 0 ) return ret; ret--;
241 if ( gSystem->Load("libSTEERBase") < 0 ){ cout<<"libSTEERBase coul not be loaded!!!"<<endl; }//return ret; ret--;}
242 if ( gSystem->Load("libESD") < 0 ) return ret; ret--;
243 if ( gSystem->Load("libAOD") < 0 ) return ret; ret--;
244 if ( gSystem->Load("libANALYSIS") < 0 ) return ret; ret--;
245 if ( gSystem->Load("libANALYSISalice") < 0 ) return ret; ret--;
248 gROOT->ProcessLine(".include $ALICE_ROOT/include");
249 gROOT->ProcessLine(".include $ALICE_ROOT/STEER");
250 cout<<"/////////////////////////////////////"<<endl;
251 cout<<endl<<"libraries loaded !"<<endl;
252 cout<<"/////////////////////////////////////"<<endl;
254 // Load helper classes
255 TIterator * iter = listToLoad->MakeIterator();
256 TObjString * name = 0;
257 while ((name = (TObjString *)iter->Next())) {
258 gSystem->ExpandPathName(name->String());
259 cout << name->String().Data() << endl;
260 if (runMode == kMyRunModeCAF) {
261 gProof->Load(name->String()+(debug?"++g":"+"));
263 gROOT->LoadMacro(name->String()+(debug?"++g":"+"));