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