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