]>
Commit | Line | Data |
---|---|---|
c36344c8 | 1 | // #include <iostream> |
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 "AliAnalysisTaskLK0Spectra.h" | |
9 | // #include "TString.h" | |
10 | // #include "TChain.h" | |
11 | // #include "TAlienCollection.h" | |
12 | // #include <fstream> | |
13 | // #include "TObjString.h" | |
14 | // #include "TIterator.h" | |
15 | // #include "TGrid.h" | |
16 | // #include "TROOT.h" | |
17 | ||
18 | // #include "CreateAlienHandler.C" | |
19 | // #include | |
20 | ||
21 | using namespace std; | |
22 | ||
23 | enum { kMyRunModeLocal = 0, kMyRunModeCAF, kMyRunModeGRID}; | |
24 | ||
25 | TList * listToLoad = new TList(); // Additional classes to be loaded, see InitAndLoadLibs | |
26 | ||
27 | TChain * GetAnalysisChain(const char * incollection); | |
28 | void InitAndLoadLibs(Int_t runMode=kMyRunModeLocal, Int_t workers=0,Bool_t debug=0) ; | |
29 | ||
30 | void runLK0Spectra(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) | |
31 | { | |
32 | // runMode: | |
33 | // | |
34 | // 0 local | |
35 | // 1 proof | |
36 | // 2 grid | |
37 | ||
38 | if (nev < 0) | |
39 | nev = 1234567890; | |
40 | InitAndLoadLibs(runMode,workers,debug); | |
41 | ||
42 | // Create the analysis manager | |
43 | AliAnalysisManager * mgr = new AliAnalysisManager; | |
44 | ||
45 | // Add ESD handler | |
46 | AliESDInputHandler* esdH = new AliESDInputHandler; | |
47 | // Do I need any of this? | |
48 | // esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks AliESDTZERO ALIESDACORDE MuonTracks TrdTracks"); | |
49 | mgr->SetInputEventHandler(esdH); | |
50 | ||
51 | if(isMC) { | |
52 | AliMCEventHandler* handler = new AliMCEventHandler; | |
53 | handler->SetPreReadMode(AliMCEventHandler::kLmPreRead); | |
54 | mgr->SetMCtruthEventHandler(handler); | |
55 | } | |
56 | ||
57 | ||
58 | // If we are running on grid, we need the alien handler | |
59 | if (runMode == kMyRunModeGRID) { | |
60 | // Create and configure the alien handler plugin | |
61 | TGrid::Connect("alien://");// Why do I need this? Without a get a bus error... | |
62 | gROOT->LoadMacro("CreateAlienHandler.C"); | |
63 | AliAnalysisGrid *alienHandler = CreateAlienHandler(data, listToLoad, gridMode, isMC); | |
64 | if (!alienHandler) { | |
65 | cout << "Cannot create alien handler" << endl; | |
66 | exit(1); | |
67 | } | |
68 | mgr->SetGridHandler(alienHandler); | |
69 | } | |
70 | ||
71 | // PID task | |
72 | gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C"); | |
73 | AddTaskPIDResponse(isMC,kTRUE); | |
74 | //AddTaskPIDResponse(); | |
75 | ||
76 | ||
77 | // Physics selection | |
78 | gROOT->ProcessLine(".L $ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); | |
79 | AliPhysicsSelectionTask * physicsSelectionTask = AddTaskPhysicsSelection(isMC,kTRUE,0); | |
80 | ||
81 | // Centrality | |
82 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C"); | |
83 | AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(); | |
84 | //taskCentrality->SetPass(2); | |
85 | if(isMC) taskCentrality->SetMCInput(); | |
86 | ||
87 | // Parse option strings | |
88 | TString optionStr(option); | |
89 | ||
90 | // remove SAVE option if set | |
91 | Bool_t doSave = kFALSE; | |
92 | ||
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 | TString pathsuffix = ""; | |
99 | // Not used, but may be useful | |
100 | Bool_t useMCKinematics = isMC; | |
101 | if (optionStr.Contains("NOMCKIN")) { | |
102 | cout << ">>>> Ignoring MC kinematics" << endl; | |
103 | useMCKinematics=kFALSE; | |
104 | pathsuffix+="_NOMCKIN"; | |
105 | } | |
106 | ||
107 | Int_t iCentralityBin = 0; | |
108 | gROOT->ProcessLine(".L AddTaskLK0Spectra.C"); | |
109 | iCentralityBin = 0; | |
2bfd3f82 | 110 | AddTaskLK0Spectra("lambdak0.root", iCentralityBin,isMC, usePID, kFALSE); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...) |
c36344c8 | 111 | iCentralityBin = 10; |
2bfd3f82 | 112 | AddTaskLK0Spectra("lambdak0.root", iCentralityBin,isMC, usePID, kFALSE); // FIXME also pass cuts, centrality bin type selection(5,10% percentiles, ranges...) |
c36344c8 | 113 | |
114 | ||
115 | ||
116 | // Init and run the analysis | |
117 | if (!mgr->InitAnalysis()) return; | |
118 | ||
119 | mgr->PrintStatus(); | |
120 | ||
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); | |
125 | // chain->Print(); | |
126 | mgr->StartAnalysis("local",chain,nev); | |
127 | } else if (runMode == kMyRunModeCAF) { | |
128 | mgr->StartAnalysis("proof",TString(passOrPath)+data+"#esdTree",nev); | |
129 | } else if (runMode == kMyRunModeGRID) { | |
130 | mgr->StartAnalysis("grid"); | |
131 | } else { | |
132 | cout << "ERROR: unknown run mode" << endl; | |
133 | } | |
134 | ||
135 | pathsuffix += customSuffix; | |
136 | ||
137 | //if (doSave) MoveOutput(data, pathsuffix.Data()); | |
138 | ||
139 | ||
140 | } | |
141 | ||
142 | void MoveOutput(const char * data, const char * suffix = ""){ | |
143 | ||
144 | // TString path("output10bins/"); | |
145 | TString path("output10binsNew/"); | |
146 | path = path + TString(data).Tokenize("/")->Last()->GetName() + suffix; | |
147 | ||
148 | TString fileName = "lambdak0.root"; | |
149 | gSystem->mkdir(path, kTRUE); | |
150 | gSystem->Rename(fileName, path + "/" + fileName); | |
151 | for(Int_t iCentralityBin = 0; iCentralityBin < 20; iCentralityBin++){ | |
152 | TString fileBin = fileName; | |
153 | fileBin.ReplaceAll(".root",Form("_%2.2d.root",iCentralityBin)); | |
154 | gSystem->Rename(fileBin, path + "/" + fileBin); | |
155 | } | |
156 | ||
157 | gSystem->Rename("event_stat.root", path + "/event_stat.root"); | |
158 | gSystem->Rename("EventStat_temp.root", path + "/EventStat_temp.root"); | |
159 | Printf(">>>>> Moved files to %s", path.Data()); | |
160 | } | |
161 | ||
162 | ||
163 | ||
164 | TChain * GetAnalysisChain(const char * incollection){ | |
165 | // Builds a chain of esd files | |
166 | // incollection can be | |
167 | // - a single root file | |
168 | // - an xml collection of files on alien | |
169 | // - a ASCII containing a list of local root files | |
170 | ||
171 | TChain* analysisChain = 0; | |
172 | // chain | |
173 | analysisChain = new TChain("esdTree"); | |
174 | if (TString(incollection).Contains(".root")){ | |
175 | analysisChain->Add(incollection); | |
176 | } | |
177 | else if (TString(incollection).Contains("xml")){ | |
178 | TGrid::Connect("alien://"); | |
179 | TGridCollection * coll = TAlienCollection::Open (incollection); | |
180 | while(coll->Next()){ | |
181 | analysisChain->Add(TString("alien://")+coll->GetLFN()); | |
182 | } | |
183 | } else { | |
184 | ifstream file_collect(incollection); | |
185 | TString line; | |
186 | while (line.ReadLine(file_collect) ) { | |
187 | analysisChain->Add(line.Data()); | |
188 | } | |
189 | } | |
190 | analysisChain->GetListOfFiles()->Print(); | |
191 | ||
192 | return analysisChain; | |
193 | } | |
194 | ||
195 | ||
196 | void InitAndLoadLibs(Int_t runMode, Int_t workers,Bool_t debug) { | |
197 | // Loads libs and par files + custom task and classes (the order is important) | |
198 | // listToLoad->Add(new TObjString("$ALICE_ROOT/STEER/AliCentrality.cxx")); // FIXME: why do I have to load it?!? | |
199 | listToLoad->Add(new TObjString("AliAnalysisCentralitySelector.cxx")); | |
200 | listToLoad->Add(new TObjString("AliAnalysisTaskLK0Spectra.cxx")); | |
201 | ||
202 | if (runMode == kMyRunModeCAF) | |
203 | { | |
204 | cout << "Init in CAF mode" << endl; | |
205 | ||
206 | gEnv->SetValue("XSec.GSI.DelegProxy", "2"); | |
207 | Char_t* alienuser = gSystem->Getenv("alien_API_USER"); | |
208 | TProof * p = TProof::Open(alienuser!=0 ? Form("%s@alice-caf.cern.ch",alienuser) : "alice-caf.cern.ch", workers>0 ? Form("workers=%d",workers) : ""); | |
209 | //TProof * p = TProof::Open("skaf.saske.sk", workers>0 ? Form("workers=%d",workers) : ""); | |
210 | p->Exec("TObject *o = gEnv->GetTable()->FindObject(\"Proof.UseMergers\"); gEnv->GetTable()->Remove(o);", kTRUE); // avoid submerging | |
211 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-18-AN"); | |
212 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-20-AN"); | |
213 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-21-AN"); | |
214 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-28-AN"); | |
215 | //gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-31-AN"); | |
216 | // gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-33-AN"); | |
217 | // gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-04-AN"); | |
218 | //gProof->EnablePackage("VO_ALICE@AliRoot::v5-02-08pA-AN"); | |
219 | gProof->EnablePackage("VO_ALICE@AliRoot::v5-03-01-AN"); | |
220 | ||
221 | // Enable the needed package | |
222 | // FIXME: what if I don't want to use par files? | |
223 | gSystem->AddIncludePath("-I${ALICE_ROOT}/include/"); | |
224 | gSystem->AddIncludePath("-I${ALICE_ROOT}/STEER/"); | |
225 | // gProof->UploadPackage("$ALICE_ROOT/obj/STEERBase"); | |
226 | // gProof->EnablePackage("$ALICE_ROOT/obj/STEERBase"); | |
227 | // gProof->UploadPackage("$ALICE_ROOT/obj/ESD"); | |
228 | // gProof->EnablePackage("$ALICE_ROOT/obj/ESD"); | |
229 | // gProof->UploadPackage("$ALICE_ROOT/obj/AOD"); | |
230 | // gProof->EnablePackage("$ALICE_ROOT/obj/AOD"); | |
231 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSIS"); | |
232 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSIS"); | |
233 | // gProof->UploadPackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
234 | // gProof->EnablePackage("$ALICE_ROOT/obj/ANALYSISalice"); | |
235 | // gProof->UploadPackage("$ALICE_ROOT/obj/CORRFW"); | |
236 | // gProof->EnablePackage("$ALICE_ROOT/obj/CORRFW"); | |
237 | // gProof->UploadPackage("~/Desktop/OADB");//FIXME | |
238 | // gProof->EnablePackage("~/Desktop/OADB");//FIXME | |
239 | ||
240 | } | |
241 | else | |
242 | { | |
243 | cout << "Init in Local or Grid mode" << endl; | |
4070f709 | 244 | gSystem->Load("libCore"); |
245 | gSystem->Load("libTree"); | |
246 | gSystem->Load("libGeom"); | |
247 | gSystem->Load("libVMC"); | |
248 | gSystem->Load("libPhysics"); | |
c36344c8 | 249 | gSystem->Load("libSTEERBase"); |
250 | gSystem->Load("libESD"); | |
251 | gSystem->Load("libAOD"); | |
252 | gSystem->Load("libANALYSIS"); | |
253 | gSystem->Load("libANALYSISalice"); | |
254 | ||
255 | // gSystem->Load("libVMC"); | |
256 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); | |
257 | gROOT->ProcessLine(".include $ALICE_ROOT/STEER"); | |
258 | } | |
259 | // Load helper classes | |
260 | TIterator * iter = listToLoad->MakeIterator(); | |
261 | TObjString * name = 0; | |
262 | while ((name = (TObjString *)iter->Next())) { | |
263 | gSystem->ExpandPathName(name->String()); | |
264 | cout << name->String().Data() << endl; | |
265 | if (runMode == kMyRunModeCAF) { | |
266 | gProof->Load(name->String()+(debug?"++g":"+")); | |
267 | } else { | |
268 | gROOT->LoadMacro(name->String()+(debug?"++g":"+")); | |
269 | } | |
270 | } | |
271 | ||
272 | } |