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