Bug in array initialization corrected
[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
672f1183 15\r
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
24 Int_t iDIJETAN = 1;\r
25 Int_t iPWG4SPECTRUM = 1;\r
26 Int_t iPWG4UE = 1;\r
27 Int_t iPWG4PID = 1;\r
28\r
29 if (iAODanalysis) {\r
30 useMC = kFALSE;\r
31 readTR = kFALSE;\r
32 iESDfilter = 0;\r
33 iMUONfilter = 0;\r
34 } \r
35 if (iJETAN) iESDfilter=1;\r
36 if (iESDfilter) iAODhandler=1;\r
37 \r
38 // Dataset from CAF\r
39 TString dataset(ds);\r
40 TChain *chain = 0;\r
41 // CKB quick hack for local analysis\r
42 gROOT->LoadMacro("CreateESDChain.C");\r
43 TChain *chain = CreateESDChain("tmp.txt",1000);\r
44\r
45 \r
46 printf("==================================================================\n");\r
47 printf("=========== RUNNING ANALYSIS TRAIN IN CAF MODE =============\n");\r
48 printf("==================================================================\n");\r
49 if (iAODanalysis) printf("= AOD analysis on dataset: %s\n", dataset.Data());\r
50 else printf("= ESD analysis on dataset: %s\n", dataset.Data());\r
51 if (iESDfilter) printf("= ESD filter =\n");\r
52 if (iJETAN) printf("= Jet analysis from AOD =\n");\r
53 if (iJETANESD) printf("= Jet analysis from ESD =\n");\r
54 if (iJETANMC) printf("= Jet analysis from Kinematics =\n");\r
55 if (iDIJETAN) printf("= DiJet analysis =\n");\r
56 if (iPWG4SPECTRUM)printf("= PWG4 Jet spectrum analysis =\n");\r
57 if (iPWG4UE) printf("= PWG4 UE =\n");\r
58 printf("==================================================================\n");\r
59 if (useMC) printf(":: use MC TRUE\n");\r
60 else printf(":: use MC FALSE\n");\r
61 if (readTR) printf(":: read TR TRUE\n");\r
62 else printf(":: read TR FALSE\n");\r
63 if (debug) printf(":: debugging TRUE\n");\r
64 else printf(":: debugging FALSE\n");\r
672f1183 65 \r
0651dd18 66 // Load common libraries\r
67 gSystem->Load("libTree.so");\r
68 gSystem->Load("libGeom.so");\r
69 gSystem->Load("libVMC.so");\r
70 gSystem->Load("libPhysics.so");\r
71 \r
72\r
73 // Reset user processes if CAF if not responding anymore\r
74 // TProof::Reset("alicecaf"); \r
75 // One may enable a different ROOT version on CAF\r
76 \r
77 const char* proofNode = "localhost";\r
78 \r
79 // Connect to proof\r
80 if(bPROOF){\r
81 TProof::Mgr(proofNode)->ShowROOTVersions();\r
82 // TProof::Mgr(proofNode)->SetROOTVersion("v5-21-01-alice_dbg");\r
83 TProof::Open(proofNode); \r
84 \r
85 // Clear packages if changing ROOT version on CAF or local\r
86 // gProof->ClearPackages();\r
87 // Enable proof debugging if needed\r
88 // gProof->SetLogLevel(5);\r
89 // To debug the train in PROOF mode, type in a root session:\r
90 // root[0] TProof::Mgr("lxb6064")->GetSessionLogs()->Display("*",0,10000);\r
91 // Common packages\r
92 // --- Enable the STEERBase Package\r
93 gProof->UploadPackage("${ALICE_ROOT}/STEERBase.par");\r
94 gProof->EnablePackage("STEERBase");\r
95 // --- Enable the ESD Package\r
96 gProof->UploadPackage("${ALICE_ROOT}/ESD.par");\r
97 gProof->EnablePackage("ESD");\r
98 // --- Enable the AOD Package\r
99 gProof->UploadPackage("${ALICE_ROOT}/AOD.par");\r
100 gProof->EnablePackage("AOD");\r
101 // --- Enable the ANALYSIS Package\r
102 gProof->UploadPackage("${ALICE_ROOT}/ANALYSIS.par");\r
103 gProof->EnablePackage("ANALYSIS");\r
104 // --- Enable the ANALYSISalice Package\r
105 gProof->UploadPackage("${ALICE_ROOT}/ANALYSISalice.par");\r
106 gProof->EnablePackage("ANALYSISalice");\r
107 \r
108 \r
109 // --- Enable the JETAN Package\r
110 if (iJETAN||iJETANESD||iJETANMC) {\r
111 gProof->UploadPackage("${ALICE_ROOT}/JETAN.par");\r
112 gProof->EnablePackage("JETAN");\r
113 } \r
114 // --- Enable particle correlation analysis\r
115 if (iPWG4UE||iPWG4SPECTRUM) {\r
116 gProof->UploadPackage("${ALICE_ROOT}/PWG4JetTasks.par");\r
117 gProof->EnablePackage("PWG4JetTasks");\r
118 } \r
119 \r
120 }\r
121 else{\r
672f1183 122\r
0651dd18 123 // \r
124 // We are local or on grid\r
125 // access remote files in lcoal case as well so open alien conection\r
672f1183 126\r
0651dd18 127 /*\r
128 printf("*** Connect to AliEn ***\n");\r
129 TGrid::Connect("alien://");\r
672f1183 130\r
0651dd18 131 chain = CreateChainFromCollection("wn.xml","esdTree",2); \r
132 */\r
672f1183 133\r
0651dd18 134 gSystem->Load("libSTEERBase");\r
135 gSystem->Load("libESD");\r
136 gSystem->Load("libAOD");\r
137 gSystem->Load("libANALYSIS");\r
138 gSystem->Load("libANALYSISalice");\r
139 \r
140 \r
141 // --- Enable the JETAN Package\r
142 if (iJETAN||iJETANESD||iJETANMC) gSystem->Load("libJETAN");\r
143 // --- Enable particle correlation analysis\r
144 if (iPWG4UE||iPWG4SPECTRUM)gSystem->Load("libPWG4JetTasks"); \r
145 }\r
672f1183 146\r
147\r
148 // Make the analysis manager\r
149 AliAnalysisManager *mgr = new AliAnalysisManager("Analysis Train", "A test setup for the analysis train");\r
150 if (iAODanalysis) {\r
151 // AOD input handler\r
152 AliAODInputHandler *aodH = new AliAODInputHandler();\r
153 mgr->SetInputEventHandler(aodH);\r
154 } else { \r
155 // ESD input handler\r
156 AliESDInputHandler *esdHandler = new AliESDInputHandler();\r
157 mgr->SetInputEventHandler(esdHandler);\r
158// esdHandler->SetInactiveBranches("FMD CaloCluster");\r
159 }\r
160 // Monte Carlo handler\r
161 if (useMC && !iAODanalysis) {\r
162 AliMCEventHandler* mcHandler = new AliMCEventHandler();\r
163 mgr->SetMCtruthEventHandler(mcHandler);\r
164 mcHandler->SetReadTR(readTR); \r
165 } \r
166 // Top container for input \r
0651dd18 167 AliAnalysisDataContainer *cinput = 0;\r
672f1183 168 \r
0651dd18 169 if(bOLD){\r
170 cinput = mgr->CreateContainer("cInput",TChain::Class(),AliAnalysisManager::kInputContainer);\r
171 } \r
172 else { \r
173 cinput = mgr->GetCommonInputContainer();\r
174 }\r
672f1183 175 // This container is managed by the AOD handler\r
176 AliAnalysisDataContainer *cout_aod = 0;\r
177 if (iAODhandler) {\r
178 // AOD output handler\r
179 AliAODHandler* aodHandler = new AliAODHandler();\r
180 aodHandler->SetFillAOD(kFALSE);\r
181 mgr->SetOutputEventHandler(aodHandler); \r
182 aodHandler->SetOutputFileName(Form("AliAODs_pwg4_%07d-%07d.root",nOffset,nOffset+nEvents));\r
0651dd18 183 if(bOLD){\r
184 cout_aod = mgr->CreateContainer("cAOD", TTree::Class(),AliAnalysisManager::kOutputContainer, "default");\r
185 }\r
186 else{\r
187 cout_aod = mgr->GetCommonOutputContainer();\r
188 }\r
672f1183 189 cout_aod->SetSpecialOutput();\r
190 } \r
191\r
192 // Debugging if needed\r
193 if (debug) mgr->SetDebugLevel(0);\r
0651dd18 194 // AliLog::EnableDebug(kTRUE);\r
672f1183 195 AliLog::SetGlobalLogLevel(0);\r
196\r
197\r
198 if (iESDfilter && !iAODanalysis) {\r
0651dd18 199 gROOT->LoadMacro("AddTaskESDfilter.C");\r
200 AliAnalysisTaskESDfilter *esdfilter = 0;\r
bebe25a4 201 if(bOLD)esdfilter = AddTaskESDfilter(mgr,cinput,cout_aod);\r
0651dd18 202 else esdfilter = AddTaskESDfilter();\r
672f1183 203 } \r
204 // Jet analysis from the AOD\r
672f1183 205 if (iJETAN) {\r
0651dd18 206 gROOT->LoadMacro("AddTaskJets.C");\r
207 AliAnalysisTaskJets *jetanaAOD = 0;\r
208 if(bOLD)jetanaAOD = AddTaskJets("AOD","UA1",mgr,cinput);\r
209 else AliAnalysisTaskJets *jetanaAOD = AddTaskJets("AOD","UA1");\r
672f1183 210 } \r
211 // JETANALYSIS from the ESD\r
212 if (iJETANESD && !iAODanalysis) {\r
0651dd18 213 gROOT->LoadMacro("AddTaskJets.C");\r
214 AliAnalysisTaskJets *jetanaESD = 0;\r
215 if(bOLD)jetanaESD = AddTaskJets("ESD","UA1",mgr,cinput);\r
216 else jetanaESD = AddTaskJets("ESD","UA1");\r
217 jetanaESD->SetDebugLevel(10);\r
218 jetanaESD->SetNonStdBranch("jetsESD"); \r
672f1183 219 } \r
220 // Jet analysisMC\r
672f1183 221 if (iJETANMC && useMC) {\r
0651dd18 222 gROOT->LoadMacro("AddTaskJets.C");\r
223 AliAnalysisTaskJets *jetanaMC = 0;\r
224 if(bOLD)jetanaMC = AddTaskJets("MC","UA1",mgr,cinput);\r
225 else jetanaMC = AddTaskJets("MC","UA1");\r
226 jetanaMC->SetDebugLevel(10);\r
227 jetanaMC->SetNonStdBranch("jetsMC");\r
672f1183 228 } \r
229 // Dijet analysis\r
230 if(iDIJETAN){\r
0651dd18 231 gROOT->LoadMacro("AddTaskDiJets.C");\r
232 AliAnalysisTaskDiJets *dijetana = 0;\r
233 if(bOLD) dijetana = AddTaskDiJets(mgr,cinput);\r
234 else dijetana = AddTaskDiJets();\r
672f1183 235 }\r
672f1183 236 if (iPWG4SPECTRUM) {\r
0651dd18 237 gROOT->LoadMacro("AddTaskJetSpectrum.C");\r
238 AliAnalysisTaskJetSpectrum* pwg4spec = 0;\r
239 if(bOLD)pwg4spec = AddTaskJetSpectrum(mgr,cinput);\r
240 else pwg4spec = AddTaskJetSpectrum();\r
672f1183 241 } \r
672f1183 242 if (iPWG4UE) {\r
0651dd18 243 gROOT->LoadMacro("AddTaskUE.C");\r
244 AliAnalysisTaskUE* ueana = 0;\r
245 if(bOLD)ueana = AddTaskUE(mgr,cinput);\r
246 else ueana = AddTaskUE();\r
672f1183 247 } \r
0651dd18 248 if(iPWG4PID){\r
249 gROOT->LoadMacro("AddTaskPWG4PidDetEx.C");\r
250 AliAnalysisTaskPWG4PidDetEx *taskPid = 0;\r
251 if(bOLD)taskPid = AddTaskPWG4PidDetEx(mgr,cinput);\r
252 else taskPid = AddTaskPWG4PidDetEx();\r
253 taskPid->SetDebugLevel(10);\r
254 }\r
672f1183 255 // Run the analysis\r
256 // \r
257 if (mgr->InitAnalysis()) {\r
258 mgr->PrintStatus();\r
259 if(bPROOF)mgr->StartAnalysis("proof",dataset.Data(), nEvents,nOffset);\r
260 else mgr->StartAnalysis("local",chain);\r
261 } \r
262}\r
0651dd18 263TChain *CreateChainFromCollection(const char* xmlfile, const char *treeName="esdTree",Int_t nFiles = 0)\r
264{\r
265// Create a chain from an alien collection. \r
266 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);\r
267\r
268 if (!myCollection) {\r
269 ::Error("CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;\r
270 return NULL ;\r
271 }\r
272\r
273 TChain* chain = new TChain(treeName);\r
274 myCollection->Reset() ;\r
275 Int_t iCount = 0;\r
276 while ( myCollection->Next() ){\r
277 if(nFiles!=0)iCount++;\r
278 if(iCount > nFiles)break;\r
279 chain->Add(myCollection->GetTURL("")) ;\r
280 Printf("Adding %s",myCollection->GetTURL(""));\r
281 }\r
282 chain->ls();\r
283 return chain;\r
284}\r