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