Removed methods with manager and container as argument, obsolotewith new AF version...
[u/mrichter/AliRoot.git] / PWG4 / macros / AnalysisTrainCAF.C
CommitLineData
672f1183 1//______________________________________________________________________________\r
2void AnalysisTrainCAF(Int_t nEvents = 10000, Int_t nOffset = 0, char *ds = "/PWG4/kleinb/LHC08r_jetjet50")\r
3{\r
0651dd18 4 // Example of running analysis train in CAF. To run in debug mode:\r
5 // - export ROOTSYS=debug on your local client\r
6 // - un-comment gProof->ClearPackages()\r
7 // - un-comment lines with debugging info\r
672f1183 8\r
672f1183 9\r
0651dd18 10 Bool_t debug = kTRUE;\r
11 Bool_t useMC = kTRUE;\r
12 Bool_t readTR = kFALSE;\r
13 Bool_t bPROOF = kFALSE;\r
14 Bool_t bOLD = kFALSE; // a flag to be compatible with the older AF, to be removed ASA grid and proof are updated\r
ba146e16 15 Bool_t bLOCALPAR = kTRUE; // flag that swtiches on loading of local par files insead of loading libs, needed for grid and local testing\r
672f1183 16\r
17 \r
0651dd18 18 Int_t iAODanalysis = 0;\r
19 Int_t iAODhandler = 1;\r
20 Int_t iESDfilter = 1; // Only active if iAODanalysis=0\r
21 Int_t iJETAN = 1;\r
22 Int_t iJETANESD = 1;\r
23 Int_t iJETANMC = 1;\r
ba146e16 24 Int_t iJETANMC2 = 1;\r
0651dd18 25 Int_t iDIJETAN = 1;\r
26 Int_t iPWG4SPECTRUM = 1;\r
27 Int_t iPWG4UE = 1;\r
28 Int_t iPWG4PID = 1;\r
29\r
30 if (iAODanalysis) {\r
31 useMC = kFALSE;\r
32 readTR = kFALSE;\r
33 iESDfilter = 0;\r
34 iMUONfilter = 0;\r
35 } \r
36 if (iJETAN) iESDfilter=1;\r
37 if (iESDfilter) iAODhandler=1;\r
38 \r
39 // Dataset from CAF\r
40 TString dataset(ds);\r
41 TChain *chain = 0;\r
42 // CKB quick hack for local analysis\r
43 gROOT->LoadMacro("CreateESDChain.C");\r
44 TChain *chain = CreateESDChain("tmp.txt",1000);\r
45\r
46 \r
47 printf("==================================================================\n");\r
48 printf("=========== RUNNING ANALYSIS TRAIN IN CAF MODE =============\n");\r
49 printf("==================================================================\n");\r
50 if (iAODanalysis) printf("= AOD analysis on dataset: %s\n", dataset.Data());\r
51 else printf("= ESD analysis on dataset: %s\n", dataset.Data());\r
52 if (iESDfilter) printf("= ESD filter =\n");\r
53 if (iJETAN) printf("= Jet analysis from AOD =\n");\r
54 if (iJETANESD) printf("= Jet analysis from ESD =\n");\r
55 if (iJETANMC) printf("= Jet analysis from Kinematics =\n");\r
ba146e16 56 if (iJETANMC2) printf("= Jet analysis 2 from Kinematics =\n");\r
0651dd18 57 if (iDIJETAN) printf("= DiJet analysis =\n");\r
58 if (iPWG4SPECTRUM)printf("= PWG4 Jet spectrum analysis =\n");\r
59 if (iPWG4UE) printf("= PWG4 UE =\n");\r
60 printf("==================================================================\n");\r
61 if (useMC) printf(":: use MC TRUE\n");\r
62 else printf(":: use MC FALSE\n");\r
63 if (readTR) printf(":: read TR TRUE\n");\r
64 else printf(":: read TR FALSE\n");\r
65 if (debug) printf(":: debugging TRUE\n");\r
66 else printf(":: debugging FALSE\n");\r
672f1183 67 \r
0651dd18 68 // Load common libraries\r
69 gSystem->Load("libTree.so");\r
70 gSystem->Load("libGeom.so");\r
71 gSystem->Load("libVMC.so");\r
72 gSystem->Load("libPhysics.so");\r
73 \r
74\r
75 // Reset user processes if CAF if not responding anymore\r
76 // TProof::Reset("alicecaf"); \r
77 // One may enable a different ROOT version on CAF\r
78 \r
ba146e16 79 // const char* proofNode = "localhost";\r
80 const char* proofNode = "alicecaf";\r
0651dd18 81 \r
82 // Connect to proof\r
83 if(bPROOF){\r
84 TProof::Mgr(proofNode)->ShowROOTVersions();\r
85 // TProof::Mgr(proofNode)->SetROOTVersion("v5-21-01-alice_dbg");\r
86 TProof::Open(proofNode); \r
87 \r
88 // Clear packages if changing ROOT version on CAF or local\r
89 // gProof->ClearPackages();\r
90 // Enable proof debugging if needed\r
91 // gProof->SetLogLevel(5);\r
92 // To debug the train in PROOF mode, type in a root session:\r
93 // root[0] TProof::Mgr("lxb6064")->GetSessionLogs()->Display("*",0,10000);\r
94 // Common packages\r
95 // --- Enable the STEERBase Package\r
ba146e16 96 gProof->UploadPackage("STEERBase.par");\r
97 gProof->EnablePackage("STEERBase"); \r
98 // --- Enable the ESD Package \r
99 gProof->UploadPackage("ESD.par"); \r
100 gProof->EnablePackage("ESD"); \r
101 // --- Enable the AOD Package \r
102 gProof->UploadPackage("AOD.par"); \r
103 gProof->EnablePackage("AOD"); \r
104 // --- Enable the ANALYSIS Package \r
105 gProof->UploadPackage("ANALYSIS.par"); \r
106 gProof->EnablePackage("ANALYSIS"); \r
0651dd18 107 // --- Enable the ANALYSISalice Package\r
ba146e16 108 gProof->UploadPackage("ANALYSISalice.par");\r
0651dd18 109 gProof->EnablePackage("ANALYSISalice");\r
110 \r
111 \r
112 // --- Enable the JETAN Package\r
ba146e16 113 if (iJETAN||iJETANESD||iJETANMC||iJETANMC2) {\r
114 gProof->UploadPackage("JETAN.par");\r
0651dd18 115 gProof->EnablePackage("JETAN");\r
116 } \r
117 // --- Enable particle correlation analysis\r
118 if (iPWG4UE||iPWG4SPECTRUM) {\r
ba146e16 119 gProof->UploadPackage("PWG4JetTasks.par");\r
0651dd18 120 gProof->EnablePackage("PWG4JetTasks");\r
121 } \r
122 \r
123 }\r
124 else{\r
672f1183 125\r
0651dd18 126 // \r
127 // We are local or on grid\r
128 // access remote files in lcoal case as well so open alien conection\r
672f1183 129\r
0651dd18 130 /*\r
131 printf("*** Connect to AliEn ***\n");\r
132 TGrid::Connect("alien://");\r
672f1183 133\r
0651dd18 134 chain = CreateChainFromCollection("wn.xml","esdTree",2); \r
135 */\r
672f1183 136\r
ba146e16 137 if(bLOCALPAR){\r
138 SetupPar("STEERBase");\r
139 SetupPar("ESD"); \r
140 SetupPar("AOD"); \r
141 SetupPar("ANALYSIS"); \r
142 SetupPar("ANALYSISalice");\r
143 if (iJETAN||iJETANESD||iJETANMC||iJETANMC2)SetupPar("JETAN"); \r
144 if (iPWG4UE||iPWG4SPECTRUM)SetupPar("PWG4JetTasks");\r
145 }\r
146 else{\r
147 gSystem->Load("libSTEERBase");\r
148 gSystem->Load("libESD");\r
149 gSystem->Load("libAOD");\r
150 gSystem->Load("libANALYSIS");\r
151 gSystem->Load("libANALYSISalice"); \r
152 // --- Enable the JETAN Package\r
153 if (iJETAN||iJETANESD||iJETANMC||iJETANMC2) gSystem->Load("libJETAN");\r
154 // --- Enable particle correlation analysis\r
155 if (iPWG4UE||iPWG4SPECTRUM)gSystem->Load("libPWG4JetTasks"); \r
156 }\r
157\r
0651dd18 158 }\r
672f1183 159\r
160\r
161 // Make the analysis manager\r
162 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "A test setup for the analysis train");\r
163 if (iAODanalysis) {\r
164 // AOD input handler\r
165 AliAODInputHandler *aodH = new AliAODInputHandler();\r
166 mgr->SetInputEventHandler(aodH);\r
167 } else { \r
168 // ESD input handler\r
169 AliESDInputHandler *esdHandler = new AliESDInputHandler();\r
170 mgr->SetInputEventHandler(esdHandler);\r
171// esdHandler->SetInactiveBranches("FMD CaloCluster");\r
172 }\r
173 // Monte Carlo handler\r
174 if (useMC && !iAODanalysis) {\r
175 AliMCEventHandler* mcHandler = new AliMCEventHandler();\r
176 mgr->SetMCtruthEventHandler(mcHandler);\r
177 mcHandler->SetReadTR(readTR); \r
178 } \r
179 // Top container for input \r
0651dd18 180 AliAnalysisDataContainer *cinput = 0;\r
672f1183 181 \r
0651dd18 182 if(bOLD){\r
183 cinput = mgr->CreateContainer("cInput",TChain::Class(),AliAnalysisManager::kInputContainer);\r
184 } \r
185 else { \r
186 cinput = mgr->GetCommonInputContainer();\r
187 }\r
672f1183 188 // This container is managed by the AOD handler\r
189 AliAnalysisDataContainer *cout_aod = 0;\r
190 if (iAODhandler) {\r
191 // AOD output handler\r
192 AliAODHandler* aodHandler = new AliAODHandler();\r
193 aodHandler->SetFillAOD(kFALSE);\r
194 mgr->SetOutputEventHandler(aodHandler); \r
195 aodHandler->SetOutputFileName(Form("AliAODs_pwg4_%07d-%07d.root",nOffset,nOffset+nEvents));\r
0651dd18 196 if(bOLD){\r
197 cout_aod = mgr->CreateContainer("cAOD", TTree::Class(),AliAnalysisManager::kOutputContainer, "default");\r
198 }\r
199 else{\r
200 cout_aod = mgr->GetCommonOutputContainer();\r
201 }\r
672f1183 202 cout_aod->SetSpecialOutput();\r
203 } \r
204\r
205 // Debugging if needed\r
206 if (debug) mgr->SetDebugLevel(0);\r
0651dd18 207 // AliLog::EnableDebug(kTRUE);\r
672f1183 208 AliLog::SetGlobalLogLevel(0);\r
209\r
210\r
211 if (iESDfilter && !iAODanalysis) {\r
0651dd18 212 gROOT->LoadMacro("AddTaskESDfilter.C");\r
213 AliAnalysisTaskESDfilter *esdfilter = 0;\r
bebe25a4 214 if(bOLD)esdfilter = AddTaskESDfilter(mgr,cinput,cout_aod);\r
0651dd18 215 else esdfilter = AddTaskESDfilter();\r
672f1183 216 } \r
217 // Jet analysis from the AOD\r
672f1183 218 if (iJETAN) {\r
0651dd18 219 gROOT->LoadMacro("AddTaskJets.C");\r
220 AliAnalysisTaskJets *jetanaAOD = 0;\r
221 if(bOLD)jetanaAOD = AddTaskJets("AOD","UA1",mgr,cinput);\r
222 else AliAnalysisTaskJets *jetanaAOD = AddTaskJets("AOD","UA1");\r
672f1183 223 } \r
224 // JETANALYSIS from the ESD\r
225 if (iJETANESD && !iAODanalysis) {\r
0651dd18 226 gROOT->LoadMacro("AddTaskJets.C");\r
227 AliAnalysisTaskJets *jetanaESD = 0;\r
228 if(bOLD)jetanaESD = AddTaskJets("ESD","UA1",mgr,cinput);\r
229 else jetanaESD = AddTaskJets("ESD","UA1");\r
230 jetanaESD->SetDebugLevel(10);\r
231 jetanaESD->SetNonStdBranch("jetsESD"); \r
672f1183 232 } \r
233 // Jet analysisMC\r
ba146e16 234 if (iJETANMC && useMC){ \r
0651dd18 235 gROOT->LoadMacro("AddTaskJets.C");\r
236 AliAnalysisTaskJets *jetanaMC = 0;\r
ba146e16 237 if(bOLD)jetanaMC = AddTaskJets("MC","UA1MC",mgr,cinput);\r
238 else jetanaMC = AddTaskJets("MC","UA1MC");\r
0651dd18 239 jetanaMC->SetDebugLevel(10);\r
240 jetanaMC->SetNonStdBranch("jetsMC");\r
672f1183 241 } \r
ba146e16 242 if (iJETANMC2 && useMC){ \r
243 gROOT->LoadMacro("AddTaskJets.C");\r
244 AliAnalysisTaskJets *jetanaMC2 = 0;\r
245 if(bOLD)jetanaMC = AddTaskJets("MC2","UA1",mgr,cinput);\r
246 else jetanaMC = AddTaskJets("MC2","UA1");\r
247 jetanaMC->SetDebugLevel(10);\r
248 jetanaMC->SetNonStdBranch("jetsMC2");\r
249 } \r
672f1183 250 // Dijet analysis\r
251 if(iDIJETAN){\r
0651dd18 252 gROOT->LoadMacro("AddTaskDiJets.C");\r
253 AliAnalysisTaskDiJets *dijetana = 0;\r
254 if(bOLD) dijetana = AddTaskDiJets(mgr,cinput);\r
255 else dijetana = AddTaskDiJets();\r
672f1183 256 }\r
672f1183 257 if (iPWG4SPECTRUM) {\r
0651dd18 258 gROOT->LoadMacro("AddTaskJetSpectrum.C");\r
259 AliAnalysisTaskJetSpectrum* pwg4spec = 0;\r
260 if(bOLD)pwg4spec = AddTaskJetSpectrum(mgr,cinput);\r
261 else pwg4spec = AddTaskJetSpectrum();\r
672f1183 262 } \r
672f1183 263 if (iPWG4UE) {\r
0651dd18 264 gROOT->LoadMacro("AddTaskUE.C");\r
265 AliAnalysisTaskUE* ueana = 0;\r
266 if(bOLD)ueana = AddTaskUE(mgr,cinput);\r
267 else ueana = AddTaskUE();\r
672f1183 268 } \r
0651dd18 269 if(iPWG4PID){\r
270 gROOT->LoadMacro("AddTaskPWG4PidDetEx.C");\r
271 AliAnalysisTaskPWG4PidDetEx *taskPid = 0;\r
272 if(bOLD)taskPid = AddTaskPWG4PidDetEx(mgr,cinput);\r
273 else taskPid = AddTaskPWG4PidDetEx();\r
274 taskPid->SetDebugLevel(10);\r
275 }\r
672f1183 276 // Run the analysis\r
277 // \r
278 if (mgr->InitAnalysis()) {\r
279 mgr->PrintStatus();\r
280 if(bPROOF)mgr->StartAnalysis("proof",dataset.Data(), nEvents,nOffset);\r
281 else mgr->StartAnalysis("local",chain);\r
282 } \r
283}\r
0651dd18 284TChain *CreateChainFromCollection(const char* xmlfile, const char *treeName="esdTree",Int_t nFiles = 0)\r
285{\r
286// Create a chain from an alien collection. \r
287 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);\r
288\r
289 if (!myCollection) {\r
290 ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;\r
291 return NULL ;\r
292 }\r
293\r
294 TChain* chain = new TChain(treeName);\r
295 myCollection->Reset() ;\r
296 Int_t iCount = 0;\r
297 while ( myCollection->Next() ){\r
298 if(nFiles!=0)iCount++;\r
299 if(iCount > nFiles)break;\r
300 chain->Add(myCollection->GetTURL("")) ;\r
301 Printf("Adding %s",myCollection->GetTURL(""));\r
302 }\r
303 chain->ls();\r
304 return chain;\r
305}\r
ba146e16 306\r
307\r
308void SetupPar(char* pararchivename)\r
309{\r
310 //Load par files, create analysis libraries \r
311 //For testing, if par file already decompressed and modified \r
312 //classes then do not decompress. \r
313\r
314 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;\r
315 TString parpar(Form("%s.par", pararchivename)) ;\r
316 /*\r
317 if ( gSystem->AccessPathName(parpar.Data()) ) {\r
318 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;\r
319 TString processline(Form(".! make %s", parpar.Data())) ;\r
320 gROOT->ProcessLine(processline.Data()) ;\r
321 gSystem->ChangeDirectory(cdir) ;\r
322 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;\r
323 gROOT->ProcessLine(processline.Data()) ;\r
324 }\r
325 */\r
326\r
327 if (!gSystem->AccessPathName(pararchivename) ) {\r
328 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;\r
329 gROOT->ProcessLine(processline.Data());\r
330 }\r
331\r
332 TString ocwd = gSystem->WorkingDirectory();\r
333 gSystem->ChangeDirectory(pararchivename);\r
334\r
335 // check for BUILD.sh and execute \r
336 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {\r
337 printf("*******************************\n");\r
338 printf("*** Building PAR archive ***\n");\r
339 cout<<pararchivename<<endl;\r
340 printf("*******************************\n");\r
341\r
342 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {\r
343 Error("runProcess","Cannot Build the PAR Archive! - Abort!");\r
344 return -1;\r
345 }\r
346 }\r
347 // check for SETUP.C and execute \r
348 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {\r
349 printf("*******************************\n");\r
350 printf("*** Setup PAR archive ***\n");\r
351 cout<<pararchivename<<endl;\r
352 printf("*******************************\n");\r
353 gROOT->Macro("PROOF-INF/SETUP.C");\r
354 }\r
355\r
356 gSystem->ChangeDirectory(ocwd.Data());\r
357 printf("Current dir: %s\n", ocwd.Data());\r
358}\r