]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/multPbPb/run.C
Glauber files for real data (Alberica)
[u/mrichter/AliRoot.git] / PWG0 / multPbPb / run.C
1 // TODO:
2 // 1. Check cuts for 2010 (Jochen?)
3 // 2. Run with many centrality bins at once
4 #include <string.h>
5
6 enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID};
7
8 TList * listToLoad = new TList();
9
10 TChain * GetAnalysisChain(const char * incollection);
11
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)
13 {
14   // runMode:
15   //
16   // 0 local 
17   // 1 proof
18
19   if (nev < 0)
20     nev = 1234567890;
21
22   InitAndLoadLibs(runMode,workers,debug);
23
24   // Create the analysis manager
25   mgr = new AliAnalysisManager;
26
27   // Add ESD handler
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);
32
33   if(isMC) {
34     AliMCEventHandler* handler = new AliMCEventHandler;
35     handler->SetPreReadMode(AliMCEventHandler::kLmPreRead);
36     mgr->SetMCtruthEventHandler(handler);
37   }
38
39
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, "full", isMC);  
45     if (!alienHandler) {
46       cout << "Cannot create alien handler" << endl;    
47       exit(1);
48     }
49     mgr->SetGridHandler(alienHandler);  
50   }
51
52
53
54   // physics selection
55   gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
56   physicsSelectionTask = AddTaskPhysicsSelection(isMC,1);
57   // FIXME!!
58   if(!isMC) {
59     AliPhysicsSelection * physSel = physicsSelectionTask->GetPhysicsSelection();
60     //    physSel->AddCollisionTriggerClass("+CTRUE-B-NOPF-ALL");
61     physSel->AddCollisionTriggerClass("+C0SM1-B-NOPF-ALL");
62     physSel->AddBGTriggerClass       ("+C0SM1-A-NOPF-ALL");
63     physSel->AddBGTriggerClass       ("+C0SM1-C-NOPF-ALL");
64     physSel->AddBGTriggerClass       ("+C0SM1-E-NOPF-ALL");
65   }
66
67   // Centrality
68   AliCentralitySelectionTask *taskCentr = new AliCentralitySelectionTask("CentralitySelection");
69   // const char * file1 = "$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityBy1D.root";
70   // const char * file2 = "$ALICE_ROOT/ANALYSIS/macros/test_AliCentralityByFunction.root";
71   const char * file1 = "$ALICE_ROOT/ANALYSIS/macros/AliCentralityBy1D_LHC10g2a_100.root";
72   const char * file2 = "$ALICE_ROOT/ANALYSIS/macros/AliCentralityByFunction_LHC10g2a_100.root";
73   taskCentr->SetPercentileFile (file1);
74   taskCentr->SetPercentileFile2(file2);
75   mgr->AddTask(taskCentr);
76   mgr->ConnectInput (taskCentr,0, mgr->GetCommonInputContainer());
77
78   // Create my own centrality selector
79   AliAnalysisMultPbCentralitySelector * centrSelector = new AliAnalysisMultPbCentralitySelector();
80   centrSelector->SetCentrTaskFiles(file1,file2); // for bookkeping only
81   centrSelector->SetCentralityBin(centrBin);
82   centrSelector->SetCentralityEstimator(centrEstimator);
83   // FIXME!!!
84   // centrSelector->SetUseMultRange();
85   centrSelector->SetIsMC(isMC,1500,2300);
86   //  centrSelector->SetMultRange(10,20);
87
88   // Parse option strings
89   TString optionStr(option);
90   
91   // remove SAVE option if set
92   // 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
93   Bool_t doSave = kFALSE;
94   TString optionStr(option);
95   if (optionStr.Contains("SAVE"))
96   {
97     optionStr = optionStr(0,optionStr.Index("SAVE")) + optionStr(optionStr.Index("SAVE")+4, optionStr.Length());
98     doSave = kTRUE;
99   }
100
101   AliESDtrackCuts * cuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kTRUE);
102   TString pathsuffix = "";
103   // cuts->SetPtRange(0.15,0.2);// FIXME pt cut
104   // const char * pathsuffix = "_pt_015_020_nofakes";
105
106   if (optionStr.Contains("ITSsa")) {
107     delete cuts;
108     cuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2009();
109     cout << ">>>> USING ITS sa tracks" << endl;
110     pathsuffix="ITSsa";
111   }
112
113   if (optionStr.Contains("TPC")) {
114     delete cuts;
115     cuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
116     cout << ">>>> USING TPC only tracks" << endl;
117     pathsuffix="TPC";
118   }
119
120   Bool_t useMCKinematics = isMC;
121   if (optionStr.Contains("NOMCKIN")) {
122     cout << ">>>> Ignoring MC kinematics" << endl;
123     useMCKinematics=kFALSE;
124   }
125   
126   
127   // load my task
128   gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/multPbPb/AddTaskMultPbPbTracks.C");
129   AliAnalysisTaskMultPbTracks * task = AddTaskMultPbPbTracks("multPbPbtracks.root", cuts, centrSelector); // kTRUE enables DCA cut
130   task->SetIsMC(useMCKinematics);
131   if (isMC) {
132     task->SetOfflineTrigger(AliVEvent::kMB);
133   } else {
134     task->SetOfflineTrigger(AliVEvent::kUserDefined);
135   }
136   if(useMCKinematics) task->GetHistoManager()->SetSuffix("MC");
137   if(customSuffix!=""){
138     cout << "Setting custom suffix: " << customSuffix << endl;    
139     task->GetHistoManager()->SetSuffix(customSuffix);
140   }
141   //  task->SelectCollisionCandidates(AliVEvent::kUserDefined);
142   if (!mgr->InitAnalysis()) return;
143   
144   mgr->PrintStatus();
145   
146   if (runMode == kMyRunModeLocal ) {
147     // If running in local mode, create chain of ESD files
148     cout << "RUNNING LOCAL, CHAIN" << endl;    
149     TChain * chain = GetAnalysisChain(data);
150     //    chain->Print();
151     mgr->StartAnalysis("local",chain,nev);
152   } else if (runMode == kMyRunModeCAF) {
153     mgr->StartAnalysis("proof",TString(data)+"#esdTree",nev);
154   } else if (runMode == kMyRunModeGRID) {
155     mgr->StartAnalysis("grid");
156   } else {
157     cout << "ERROR: unknown run mode" << endl;        
158   }
159
160   pathsuffix = pathsuffix + "_" + centrEstimator + "_bin_"+long(centrBin);
161   pathsuffix += customSuffix;
162
163   if (doSave) MoveOutput(data, pathsuffix.Data());
164
165   
166 }
167
168
169 void MoveOutput(const char * data, const char * suffix = ""){
170
171   TString path("output/");
172   path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix;
173   
174   TString fileName = "multPbPbtracks.root";
175   gSystem->mkdir(path, kTRUE);
176   gSystem->Rename(fileName, path + "/" + fileName);
177   gSystem->Rename("event_stat.root", path + "/event_stat.root");      
178   Printf(">>>>> Moved files to %s", path.Data());
179 }  
180
181
182
183 TChain * GetAnalysisChain(const char * incollection){
184   // Builds a chain of esd files
185   // incollection can be
186   // - a single root file
187   // - an xml collection of files on alien
188   // - a ASCII containing a list of local root files
189   TChain* analysisChain = 0;
190   // chain
191   analysisChain = new TChain("esdTree");
192   if (TString(incollection).Contains(".root")){
193     analysisChain->Add(incollection);
194   }
195   else if (TString(incollection).Contains("xml")){
196     TGrid::Connect("alien://");
197     TAlienCollection * coll = TAlienCollection::Open (incollection);
198     while(coll->Next()){
199       analysisChain->Add(TString("alien://")+coll->GetLFN());
200     }
201   } else {
202     ifstream file_collect(incollection);
203     TString line;
204     while (line.ReadLine(file_collect) ) {
205       analysisChain->Add(line.Data());
206     }
207   }
208   analysisChain->GetListOfFiles()->Print();
209
210   return analysisChain;
211 }
212
213
214 void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) {
215   // Loads libs and par files + custom task and classes
216
217   // Custom stuff to be loaded
218   listToLoad->Add(new TObjString("$ALICE_ROOT/ANALYSIS/AliCentralitySelectionTask.cxx+"));
219   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG1/background/AliHistoListWrapper.cxx+"));
220   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbTrackHistoManager.cxx+"));
221   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisMultPbCentralitySelector.cxx+"));
222   listToLoad->Add(new TObjString("$ALICE_ROOT/PWG0/multPbPb/AliAnalysisTaskMultPbTracks.cxx+"));
223
224
225   if (runMode == kMyRunModeCAF)
226   {
227     cout << "Init in CAF mode" << endl;
228     
229     gEnv->SetValue("XSec.GSI.DelegProxy", "2");
230     TProof::Open("alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : "");
231     
232     // Enable the needed package
233     gProof->UploadPackage("$ALICE_ROOT/STEERBase");
234     gProof->EnablePackage("$ALICE_ROOT/STEERBase");
235     gProof->UploadPackage("$ALICE_ROOT/ESD");
236     gProof->EnablePackage("$ALICE_ROOT/ESD");
237     gProof->UploadPackage("$ALICE_ROOT/AOD");
238     gProof->EnablePackage("$ALICE_ROOT/AOD");
239     gProof->UploadPackage("$ALICE_ROOT/ANALYSIS");
240     gProof->EnablePackage("$ALICE_ROOT/ANALYSIS");
241     gProof->UploadPackage("$ALICE_ROOT/ANALYSISalice");
242     gProof->EnablePackage("$ALICE_ROOT/ANALYSISalice");
243     gProof->UploadPackage("$ALICE_ROOT/PWG0base");
244     gProof->EnablePackage("$ALICE_ROOT/PWG0base");
245     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
246     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
247   }
248   else
249   {
250     cout << "Init in Local or Grid mode" << endl;
251     gSystem->Load("libCore.so");  
252     gSystem->Load("libTree.so");
253     gSystem->Load("libGeom.so");
254     gSystem->Load("libVMC.so");
255     gSystem->Load("libPhysics.so");
256     gSystem->Load("libSTEERBase");
257     gSystem->Load("libESD");
258     gSystem->Load("libAOD");
259     gSystem->Load("libANALYSIS");
260     gSystem->Load("libANALYSISalice");   
261   // Use AliRoot includes to compile our task
262     gROOT->ProcessLine(".include $ALICE_ROOT/include");
263
264     // gSystem->Load("libVMC");
265     // gSystem->Load("libTree");
266     // gSystem->Load("libSTEERBase");
267     // gSystem->Load("libESD");
268     // gSystem->Load("libAOD");
269     // gSystem->Load("libANALYSIS");
270     // gSystem->Load("libANALYSISalice");
271     // gSystem->Load("libPWG0base");
272     
273     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG0/multPb"));
274     gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background"));
275     //    gROOT->ProcessLine(gSystem->ExpandPathName(".include $ALICE_ROOT/PWG1/background/"));
276   }
277   // Load helper classes
278   TIterator * iter = listToLoad->MakeIterator();
279   TObjString * name = 0;
280   while (name = (TObjString *)iter->Next()) {
281     gSystem->ExpandPathName(name->String());
282     cout << name->String().Data();
283     if (runMode == kMyRunModeCAF) {
284       gProof->Load(name->String()+(debug?"+g":""));   
285     } else {
286       gROOT->LoadMacro(name->String()+(debug?"+g":""));   
287     }
288   }
289
290 }