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