]>
Commit | Line | Data |
---|---|---|
af2b48fb | 1 | class AliAnalysisGrid; |
2 | const char *dataset = ""; | |
3 | TString anaLibs = ""; | |
4 | Int_t iESDfilter = 1; | |
5 | Int_t iAODTagCreation = 1; | |
6 | Int_t iAODAddMCBranch = 1; | |
7 | ||
8 | void AnalysisTrainFromESDToAOD(const char *analysisMode = "GRID", Bool_t usePLUGIN = kFALSE, Int_t nev=12345678) | |
9 | ||
10 | //======================================================================== | |
11 | // The macro produces a standard AOD starting from ESD files. | |
12 | // (Simplified version of ANALYSIS/macros/AnalysisTrainNew.C) | |
13 | // | |
14 | // Two wagons are attached to the train: | |
15 | // AddTaskESDFilter.C and AddTaskTagCreation.C | |
16 | // | |
17 | // If the iESDfilter flag is activated, in AddTaskESDFilter.C | |
18 | // two tasks are executed : | |
19 | // 1- with the first one (AliAnalysisTaskESDfilter), | |
20 | // all the branches of the AOD are filled apart from the muons | |
21 | // 2- with the second task (AliAnalysisTaskESDMuonFilter) | |
22 | // muons tracks are added to the tracks branch | |
23 | // | |
24 | // In AddTaskESDFilter.C there is the possibility to apply cuts | |
25 | // on the tracks and muon tracks in order to reject them before | |
26 | // filling the AOD. | |
27 | // | |
28 | // - if the flag iAODAddMCBranch is activated the MC branch | |
29 | // (containing Kinematics info) is added to the AOD | |
30 | ||
31 | // - if the iAODTagCreation flag is activated, in AddTaskTagCreation.C the | |
32 | // AliAnalysisTaskTagCreator task is executed in order to create aod tags. | |
33 | // | |
34 | // | |
35 | // Options tested: (case sensitive) | |
36 | // GRID (with/without AliEn plugin) | |
37 | // LOCAL (you have to specify in TChain *CreateChain(...) | |
38 | // the directory where your data are) | |
39 | //======================================================================== | |
40 | ||
41 | { | |
42 | // Global configuration flags | |
43 | //===================================================================== | |
44 | Bool_t debug = kTRUE; | |
45 | Bool_t readTR = kFALSE; | |
46 | Bool_t useKFILTER = kFALSE; // add MC Branch | |
47 | if(iAODAddMCBranch) useKFILTER=kTRUE; | |
48 | if(strcmp(analysisMode,"LOCAL")==0) usePLUGIN = kFALSE; | |
49 | ||
50 | // Load common libraries (STEERBase, ESD, AOD, ANALYSIS. ANALYSISalice) | |
51 | //===================================================================== | |
52 | LoadCommonLibraries(analysisMode); | |
53 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); | |
54 | ||
55 | // Load analysis specific libraries | |
56 | //===================================================================== | |
57 | if (iESDfilter) { | |
58 | if(!strcmp(analysisMode, "LOCAL")){ | |
40a0a69c | 59 | gSystem->Load("libPWGHFbase.so"); |
60 | gSystem->Load("libPWGmuon.so"); | |
af2b48fb | 61 | } |
62 | else if(!strcmp(analysisMode, "GRID"))LoadAnalysisLibraries(analysisMode); | |
63 | } | |
64 | ||
65 | // If Plugin is used, load macro with JDL parameters | |
66 | //===================================================================== | |
67 | if(usePLUGIN){ | |
68 | gROOT->LoadMacro("CreateAlienHandler_FromESDToAOD.C"); | |
69 | AliAnalysisGrid *alienHandler = CreateAlienHandler_FromESDToAOD(); | |
70 | if (!alienHandler) return; | |
71 | } | |
72 | ||
73 | // Create the chain. This is dependent on the analysis mode. | |
74 | //===================================================================== | |
75 | if(!usePLUGIN){ | |
76 | if (!strcmp(analysisMode, "GRID")) TGrid::Connect("alien://"); | |
77 | TChain* chain = CreateChain(analysisMode,""); | |
78 | } | |
79 | ||
80 | // Create the train and set-up the handlers | |
81 | //===================================================================== | |
82 | AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "Analysis Train for standard AOD production"); | |
83 | ||
84 | // GRID handler | |
85 | if(usePLUGIN) mgr->SetGridHandler(alienHandler); | |
86 | ||
87 | // ESD input handler | |
88 | AliESDInputHandler *esdHandler = new AliESDInputHandler(); | |
89 | mgr->SetInputEventHandler(esdHandler); | |
90 | ||
91 | // Monte Carlo handler | |
92 | if (iAODAddMCBranch) { | |
93 | AliMCEventHandler* mcHandler = new AliMCEventHandler(); | |
94 | mgr->SetMCtruthEventHandler(mcHandler); | |
95 | mcHandler->SetReadTR(readTR); | |
96 | } | |
97 | ||
98 | // AOD output handler | |
99 | AliAODHandler* aodHandler = new AliAODHandler(); | |
100 | mgr->SetOutputEventHandler(aodHandler); | |
101 | aodHandler->SetOutputFileName("AliAODs.root"); | |
102 | ||
103 | // Debugging if requested | |
104 | if (debug) mgr->SetDebugLevel(3); | |
105 | ||
106 | // Load the tasks configuration macros for all included wagons | |
107 | //===================================================================== | |
108 | if (iESDfilter) { | |
109 | gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C"); | |
110 | AliAnalysisTaskESDfilter *esdfilter = AddTaskESDFilter(useKFILTER); | |
111 | ||
112 | if (iAODTagCreation) { | |
113 | // use this line if AddTaskTagCreation.C is available in the grid aliroot version | |
114 | if(!strcmp(analysisMode, "LOCAL")){ | |
115 | gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskTagCreation.C"); | |
116 | } else { | |
117 | // uncomment this line if AddTaskTagCreation.C is available in the grid aliroot version | |
118 | // gROOT->LoadMacro("$ALICE_ROOT/PWG3/muon/AddTaskTagCreation.C"); | |
119 | // otherwise temporary: (and AddTaskTagCreation.C must be also added in the jdl) | |
120 | gROOT->LoadMacro("AddTaskTagCreation.C"); | |
121 | } | |
122 | AliAnalysisTaskTagCreator *tagcreator = AddTaskTagCreation(); | |
123 | } | |
124 | } | |
125 | ||
126 | // Run the analysis | |
127 | //===================================================================== | |
128 | if (mgr->InitAnalysis()) { | |
129 | mgr->PrintStatus(); | |
130 | if(usePLUGIN) mgr->StartAnalysis("GRID"); | |
131 | else mgr->StartAnalysis("local", chain,nev); | |
132 | } | |
133 | } | |
134 | ||
135 | //______________________________________________________________________________ | |
136 | Bool_t LoadCommonLibraries(const char *mode) | |
137 | { | |
138 | // Load common analysis libraries. | |
139 | Int_t imode = -1; | |
140 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
141 | if (!strcmp(mode, "PROOF")) imode = 1; | |
142 | if (!strcmp(mode, "GRID")) imode = 2; | |
143 | if (!gSystem->Getenv("ALICE_ROOT")) { | |
144 | ::Error("LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); | |
145 | return kFALSE; | |
146 | } | |
147 | Bool_t success = kTRUE; | |
148 | // ROOT libraries | |
149 | gSystem->Load("libTree.so"); | |
150 | gSystem->Load("libGeom.so"); | |
151 | gSystem->Load("libVMC.so"); | |
152 | gSystem->Load("libPhysics.so"); | |
153 | ||
154 | // Load framework classes. Par option ignored here. | |
155 | switch (imode) { | |
156 | case 0: | |
157 | case 2: | |
158 | success &= LoadLibrary("libSTEERBase.so", mode); | |
159 | success &= LoadLibrary("libESD.so", mode); | |
160 | success &= LoadLibrary("libAOD.so", mode); | |
161 | success &= LoadLibrary("libANALYSIS.so", mode); | |
162 | success &= LoadLibrary("libANALYSISalice.so", mode); | |
163 | success &= LoadLibrary("libCORRFW.so", mode); | |
164 | gROOT->ProcessLine(".include $ALICE_ROOT/include"); | |
165 | break; | |
166 | case 1: | |
167 | Int_t ires = -1; | |
168 | if (!gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion); | |
169 | if (ires < 0) { | |
170 | success &= LoadLibrary("STEERBase", mode); | |
171 | success &= LoadLibrary("ESD", mode); | |
172 | success &= LoadLibrary("AOD", mode); | |
173 | success &= LoadLibrary("ANALYSIS", mode); | |
174 | success &= LoadLibrary("ANALYSISalice", mode); | |
175 | success &= LoadLibrary("CORRFW", mode); | |
176 | } else { | |
177 | ires = gProof->EnablePackage(AFversion); | |
178 | if (ires<0) success = kFALSE; | |
179 | } | |
180 | break; | |
181 | default: | |
182 | ::Error("LoadCommonLibraries", "Unknown run mode: %s", mode); | |
183 | return kFALSE; | |
184 | } | |
185 | if (success) { | |
186 | ::Info("LoadCommodLibraries", "Load common libraries: SUCCESS"); | |
187 | ::Info("LoadCommodLibraries", "Include path for Aclic compilation:\n%s", | |
188 | gSystem->GetIncludePath()); | |
189 | } else { | |
190 | ::Info("LoadCommodLibraries", "Load common libraries: FAILED"); | |
191 | } | |
192 | ||
193 | return success; | |
194 | } | |
195 | ||
196 | //______________________________________________________________________________ | |
197 | TChain *CreateChain(const char *mode, const char *plugin_mode) | |
198 | { | |
199 | // Create the input chain | |
200 | Int_t imode = -1; | |
201 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
202 | if (!strcmp(mode, "PROOF")) imode = 1; | |
203 | if (!strcmp(mode, "GRID")) imode = 2; | |
204 | TChain *chain = NULL; | |
205 | // Local chain | |
206 | switch (imode) { | |
207 | case 0: | |
208 | if (!strlen(dataset)) { | |
209 | // Local ESD | |
210 | chain = new TChain("esdTree"); | |
211 | if (gSystem->AccessPathName("/n60raid3/alice/roberta/MCBranch/AliESDs.root")) | |
212 | ::Error("CreateChain", "File: AliESDs.root not in ./data dir"); | |
213 | else chain->Add("/n60raid3/alice/roberta/MCBranch/AliESDs.root"); | |
214 | } else { | |
215 | // Interactive ESD | |
216 | chain = CreateChainSingle(dataset, "esdTree"); | |
217 | } | |
218 | break; | |
219 | case 1: | |
220 | break; | |
221 | case 2: | |
222 | TString treeName = "esdTree"; | |
223 | chain = CreateChainSingle("wn.xml", treeName); | |
224 | break; | |
225 | default: | |
226 | } | |
227 | if (chain && chain->GetNtrees()) return chain; | |
228 | return NULL; | |
229 | } | |
230 | ||
231 | //______________________________________________________________________________ | |
232 | Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE) | |
233 | { | |
234 | // Load a module library in a given mode. Reports success. | |
235 | Int_t imode = -1; | |
236 | Int_t result; | |
237 | TString smodule(module); | |
238 | if (!strcmp(mode, "LOCAL")) imode = 0; | |
239 | if (!strcmp(mode, "PROOF")) imode = 1; | |
240 | if (!strcmp(mode, "GRID")) imode = 2; | |
241 | TString mod(module); | |
242 | if (!mod.Length()) { | |
243 | ::Error("LoadLibrary", "Empty module name"); | |
244 | return kFALSE; | |
245 | } | |
246 | // If a library is specified, just load it | |
247 | if (smodule.EndsWith(".so")) { | |
248 | mod.Remove(mod.Index(".so")); | |
249 | result = gSystem->Load(mod); | |
250 | if (result < 0) { | |
251 | ::Error("LoadLibrary", "Could not load library %s", module); | |
252 | return kFALSE; | |
253 | } | |
254 | if (rec) anaLibs += Form("%s.so ",mod.Data()); | |
255 | return kTRUE; | |
256 | } | |
257 | // Check if the library is already loaded | |
258 | if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0) | |
259 | return kTRUE; | |
260 | switch (imode) { | |
261 | case 0: | |
262 | case 2: | |
263 | result = gSystem->Load(Form("lib%s.so", module)); | |
264 | if (rec) anaLibs += Form("lib%s.so ", module); | |
265 | break; | |
266 | case 1: | |
267 | result = gProof->UploadPackage(module); | |
268 | if (result<0) { | |
269 | result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module))); | |
270 | if (result<0) { | |
271 | ::Error("LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module); | |
272 | return kFALSE; | |
273 | } | |
274 | } | |
275 | result = gProof->EnablePackage(module); | |
276 | break; | |
277 | default: | |
278 | return kFALSE; | |
279 | } | |
280 | if (result < 0) { | |
281 | ::Error("LoadLibrary", "Could not load module %s", module); | |
282 | return kFALSE; | |
283 | } | |
284 | return kTRUE; | |
285 | } | |
286 | ||
287 | //______________________________________________________________________________ | |
288 | TChain* CreateChainSingle(const char* xmlfile, const char *treeName) | |
289 | { | |
290 | printf("*******************************\n"); | |
291 | printf("*** Getting the ESD Chain ***\n"); | |
292 | printf("*******************************\n"); | |
293 | TAlienCollection * myCollection = TAlienCollection::Open(xmlfile); | |
294 | ||
295 | if (!myCollection) { | |
296 | ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ; | |
297 | return NULL ; | |
298 | } | |
299 | ||
300 | TChain* chain = new TChain(treeName); | |
301 | myCollection->Reset() ; | |
302 | while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ; | |
303 | chain->ls(); | |
304 | return chain; | |
305 | } | |
306 | ||
307 | //______________________________________________________________________________ | |
308 | Bool_t LoadAnalysisLibraries(const char *mode) | |
309 | { | |
310 | // Load common analysis libraries. | |
311 | Bool_t success = kTRUE; | |
312 | if (!LoadLibrary("PWG3base", mode, kTRUE) || | |
313 | !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE; | |
314 | ::Info("LoadAnalysisLibraries", "Load other libraries: SUCCESS"); | |
315 | return kTRUE; | |
316 | } | |
317 |