2 // 1. Check cuts for 2010 (Jochen?)
3 // 2. Run with many centrality bins at once
6 enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
8 TList * listToLoad = new TList();
10 TChain * GetAnalysisChain(const char * incollection);
12 void run(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 centrBin = 0, const char * centrEstimator = "VOM", const char* option = "",TString customSuffix = "", Int_t workers = -1)
22 InitAndLoadLibs(runMode,workers,debug);
24 // Create the analysis manager
25 mgr = new AliAnalysisManager;
28 AliESDInputHandler* esdH = new AliESDInputHandler;
29 // Do I need any of this?
30 // esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks");
31 mgr->SetInputEventHandler(esdH);
34 AliMCEventHandler* handler = new AliMCEventHandler;
35 handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
36 mgr->SetMCtruthEventHandler(handler);
40 // If we are running on grid, we need the alien handler
41 if (runMode == kMyRunModeGRID) {
42 // Create and configure the alien handler plugin
43 gROOT->LoadMacro("CreateAlienHandler.C");
44 AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, "test", isMC);
46 cout << "Cannot create alien handler" << endl;
49 mgr->SetGridHandler(alienHandler);
55 gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
56 physicsSelectionTask = AddTaskPhysicsSelection(isMC);
59 AliCentralitySelectionTask *taskCentr = new AliCentralitySelectionTask("CentralitySelection");
60 taskCentr->SetPercentileFile("$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityBy1D.root");
61 taskCentr->SetPercentileFile2("$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityByFunction.root");
62 mgr->AddTask(taskCentr);
63 mgr->ConnectInput (taskCentr,0, mgr->GetCommonInputContainer());
66 // Parse option strings
67 TString optionStr(option);
69 // remove SAVE option if set
70 // 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
71 Bool_t doSave = kFALSE;
72 TString optionStr(option);
73 if (optionStr.Contains("SAVE"))
75 optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
79 AliESDtrackCuts * cuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
80 TString pathsuffix = "";
81 // cuts->SetPtRange(0.15,0.2);// FIXME pt cut
82 // const char * pathsuffix = "_pt_015_020_nofakes";
84 if (optionStr.Contains("ITSsa")) {
86 cuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2009();
87 cout << ">>>> USING ITS sa tracks" << endl;
91 if (optionStr.Contains("TPC")) {
93 cuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
94 cout << ">>>> USING TPC only tracks" << endl;
98 Bool_t useMCKinematics = isMC;
99 if (optionStr.Contains("NOMCKIN")) {
100 cout << ">>>> Ignoring MC kinematics" << endl;
101 useMCKinematics=kFALSE;
106 gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/multPbPb/AddTaskMultPbPbTracks.C");
107 AliAnalysisTaskMultPbTracks * task = AddTaskMultPbPbTracks("multPbPbtracks.root", cuts); // kTRUE enables DCA cut
108 task->SetIsMC(useMCKinematics);
109 if(useMCKinematics) task->GetHistoManager()->SetSuffix("MC");
110 if(customSuffix!=""){
111 cout << "Setting custom suffix: " << customSuffix << endl;
112 task->GetHistoManager()->SetSuffix(customSuffix);
114 task->SetCentralityBin(centrBin);
115 task->SetCentralityEstimator(centrEstimator);
117 if (!mgr->InitAnalysis()) return;
121 if (runMode == kMyRunModeLocal ) {
122 // If running in local mode, create chain of ESD files
123 cout << "RUNNING LOCAL, CHAIN" << endl;
124 TChain * chain = GetAnalysisChain(data);
126 mgr->StartAnalysis("local",chain,nev);
127 } else if (runMode == kMyRunModeCAF) {
128 mgr->StartAnalysis("proof",TString(data)+"#esdTree",nev);
129 } else if (runMode == kMyRunModeGRID) {
130 mgr->StartAnalysis("grid");
132 cout << "ERROR: unknown run mode" << endl;
135 pathsuffix = pathsuffix + "_" + centrEstimator + "_bin_"+long(centrBin);
136 if (doSave) MoveOutput(data, pathsuffix.Data());
142 void MoveOutput(const char * data, const char * suffix = ""){
144 TString path("output/");
145 path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
147 TString fileName = "multPbPbtracks.root";
148 gSystem->mkdir(path, kTRUE);
149 gSystem->Rename(fileName, path + "/" + fileName);
150 gSystem->Rename("event_stat.root", path + "/event_stat.root");
151 Printf(">>>>> Moved files to %s", path.Data());
156 TChain * GetAnalysisChain(const char * incollection){
157 // Builds a chain of esd files
158 // incollection can be
159 // - a single root file
160 // - an xml collection of files on alien
161 // - a ASCII containing a list of local root files
162 TChain* analysisChain = 0;
164 analysisChain = new TChain("esdTree");
165 if (TString(incollection).Contains(".root")){
166 analysisChain->Add(incollection);
168 else if (TString(incollection).Contains("xml")){
169 TGrid::Connect("alien://");
170 TAlienCollection * coll = TAlienCollection::Open (incollection);
172 analysisChain->Add(TString("alien://")+coll->GetLFN());
175 ifstream file_collect(incollection);
177 while (line.ReadLine(file_collect) ) {
178 analysisChain->Add(line.Data());
181 analysisChain->GetListOfFiles()->Print();
183 return analysisChain;
187 void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) {
188 // Loads libs and par files + custom task and classes
190 // Custom stuff to be loaded
191 listToLoad->Add(new TObjString("$ALICE_ROOT/ANALYSIS/AliCentralitySelectionTask.cxx+"));
192 listToLoad->Add(new TObjString("$ALICE_ROOT/PWG1/background/AliHistoListWrapper.cxx+"));
193 listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbTrackHistoManager.cxx+"));
194 listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisTaskMultPbTracks.cxx+"));
197 if (runMode == kMyRunModeCAF)
199 cout << "Init in CAF mode" << endl;
201 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
202 TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
204 // Enable the needed package
205 gProof->UploadPackage("$ALICE_ROOT/STEERBase");
206 gProof->EnablePackage("$ALICE_ROOT/STEERBase");
207 gProof->UploadPackage("$ALICE_ROOT/ESD");
208 gProof->EnablePackage("$ALICE_ROOT/ESD");
209 gProof->UploadPackage("$ALICE_ROOT/AOD");
210 gProof->EnablePackage("$ALICE_ROOT/AOD");
211 gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
212 gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
213 gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
214 gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
215 gProof->UploadPackage("$ALICE_ROOT/PWG0base");
216 gProof->EnablePackage("$ALICE_ROOT/PWG0base");
217 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
218 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
222 cout << "Init in Local or Grid mode" << endl;
224 gSystem->Load("libVMC");
225 gSystem->Load("libTree");
226 gSystem->Load("libSTEERBase");
227 gSystem->Load("libESD");
228 gSystem->Load("libAOD");
229 gSystem->Load("libANALYSIS");
230 gSystem->Load("libANALYSISalice");
231 gSystem->Load("libPWG0base");
233 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
234 gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
235 // gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background/"));
237 // Load helper classes
238 TIterator * iter = listToLoad->MakeIterator();
239 TObjString * name = 0;
240 while (name = (TObjString *)iter->Next()) {
241 gSystem->ExpandPathName(name->String());
242 cout << name->String().Data();
243 if (runMode == kMyRunModeCAF) {
244 gProof->Load(name->String()+(debug?"+g":""));
246 gROOT->LoadMacro(name->String()+(debug?"+g":""));