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