]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/macros/AODtrain.C
Merge branch 'TPCdev' of https://git.cern.ch/reps/AliRoot into TPCdev
[u/mrichter/AliRoot.git] / ANALYSIS / macros / AODtrain.C
1 // ### Settings that make sense when using the Alien plugin
2 //==============================================================================
3 Int_t       runOnData          = 0;       // Set to 1 if processing real data
4 Int_t       iCollision         = 0;       // 0=pp, 1=Pb-Pb
5 Int_t       run_flag           = 1100;    // year (2011 = 1100)
6 //==============================================================================
7 Bool_t      doCDBconnect        =1;
8 Bool_t      usePhysicsSelection = kTRUE; // use physics selection
9 Bool_t      useTender           = kFALSE; // use tender wagon
10 Bool_t      useCentrality       = kFALSE; // centrality
11 Bool_t      useV0tender         = kFALSE;  // use V0 correction in tender
12 Bool_t      useDBG              = kTRUE;  // activate debugging
13 Bool_t      useMC               = kFALSE;  // use MC info
14 Bool_t      useKFILTER          = kFALSE;  // use Kinematics filter
15 Bool_t      useTR               = kFALSE;  // use track references
16 Bool_t      useCORRFW           = kFALSE; // do not change
17 Bool_t      useAODTAGS          = kFALSE; // use AOD tags
18 Bool_t      useSysInfo          = kFALSE; // use sys info
19
20 // ### Analysis modules to be included. Some may not be yet fully implemented.
21 //==============================================================================
22 Int_t       iAODhandler        = 1;      // Analysis produces an AOD or dAOD's
23 Int_t       iESDfilter         = 1;      // ESD to AOD filter (barrel + muon tracks)
24 Int_t       iESDfilterReVtx    = -1;     // Request revertexing in ESD filtering
25 Int_t       iMUONcopyAOD       = 1;      // Task that copies only muon events in a separate AOD (PWG3)
26 Int_t       iJETAN             = 0;      // Jet analysis (PWG4)
27 Int_t       iJETANdelta        = 0;      // Jet delta AODs
28 Int_t       iPWGHFvertexing     = 1;      // Vertexing HF task (PWG3)
29 Int_t       iPWGDQJPSIfilter    = 0;      // JPSI filtering (PWG3)
30 Int_t       iPWGHFd2h           = 1;      // D0->2 hadrons (PWG3)
31 Int_t       iPWGPP               =1;      // high pt filter task
32 Int_t       iPWGLFForward       = 1;      // Forward mult task (PWGLF)
33 Bool_t doPIDResponse  = 1;
34 Bool_t doPIDqa        = 1; //new
35
36 // ### Configuration macros used for each module
37 //==============================================================================
38  TString configPWGHFd2h = (iCollision==0)?"$ALICE_ROOT/PWGHF/vertexingHF/ConfigVertexingHF.C"
39                           :"$ALICE_ROOT/PWGHF/vertexingHF/ConfigVertexingHF_highmult.C";
40                           
41 Double_t  cutsESDfilterReVtx[21] =
42 {1.00e-01,1.00e-01,5.00e-01,3.00e+00,1.00e+00,
43 3.00e+00,1.00e+02,1.00e+03,3.00e+00,3.00e+01,
44 6.00e+00,4.00e+00,7.00e+00,1.00e+03,5.00e+00,
45 5.00e-02,1.00e-03,2.00e+00,1.00e+01,1.00e+00,
46 -5.00e+01};
47
48
49                                              
50 // Temporaries.
51 void AODmerge();
52 void AddAnalysisTasks();
53 Bool_t LoadCommonLibraries();
54 Bool_t LoadAnalysisLibraries();
55 Bool_t LoadLibrary(const char *);
56 TChain *CreateChain();
57 const char *cdbPath = "raw://";
58 Int_t run_number = 0;
59
60 //______________________________________________________________________________
61 void AODtrain(Int_t merge=0)
62 {
63 // Main analysis train macro.
64
65   if (merge || doCDBconnect) {
66     TGrid::Connect("alien://");
67     if (!gGrid || !gGrid->IsConnected()) {
68       ::Error("QAtrain", "No grid connection");
69       return;
70     }
71   }
72   // Set temporary merging directory to current one
73   gSystem->Setenv("TMPDIR", gSystem->pwd());
74   // Set temporary compilation directory to current one
75   gSystem->SetBuildDir(gSystem->pwd(), kTRUE);
76    printf("==================================================================\n");
77    printf("===========    RUNNING FILTERING TRAIN   ==========\n");
78    printf("==================================================================\n");
79    printf("=  Configuring analysis train for:                               =\n");
80    if (usePhysicsSelection)   printf("=  Physics selection                                                =\n");
81    if (useTender)    printf("=  TENDER                                                        =\n");
82    if (iESDfilter)   printf("=  ESD filter                                                    =\n");
83    if (iMUONcopyAOD) printf("=  MUON copy AOD                                                 =\n");
84    if (iJETAN)       printf("=  Jet analysis                                                  =\n");
85    if (iJETANdelta)  printf("=     Jet delta AODs                                             =\n");
86    if (iPWGHFvertexing) printf("=  PWGHF vertexing                                                =\n");
87    if (iPWGDQJPSIfilter) printf("=  PWGDQ j/psi filter                                             =\n");
88    if (iPWGHFd2h) printf("=  PWGHF D0->2 hadrons QA                                     =\n");
89
90    // Load common libraries and set include path
91    if (!LoadCommonLibraries()) {
92       ::Error("AnalysisTrain", "Could not load common libraries");
93       return;
94    }
95     
96    // Make the analysis manager and connect event handlers
97    AliAnalysisManager *mgr  = new AliAnalysisManager("Analysis Train", "Production train");
98    if (useSysInfo) mgr->SetNSysInfo(100);
99    // Load analysis specific libraries
100    if (!LoadAnalysisLibraries()) {
101       ::Error("AnalysisTrain", "Could not load analysis libraries");
102       return;
103    }   
104
105    // Create input handler (input container created automatically)
106    // ESD input handler
107    AliESDInputHandler *esdHandler = new AliESDInputHandler();
108    mgr->SetInputEventHandler(esdHandler);       
109    // Monte Carlo handler
110    if (useMC) {
111       AliMCEventHandler* mcHandler = new AliMCEventHandler();
112       mgr->SetMCtruthEventHandler(mcHandler);
113       mcHandler->SetReadTR(useTR); 
114    }   
115    // AOD output container, created automatically when setting an AOD handler
116    if (iAODhandler) {
117       // AOD output handler
118       AliAODHandler* aodHandler   = new AliAODHandler();
119       aodHandler->SetOutputFileName("AliAOD.root");
120       mgr->SetOutputEventHandler(aodHandler);
121    }
122    // Debugging if needed
123    if (useDBG) mgr->SetDebugLevel(3);
124
125    AddAnalysisTasks(cdbPath);
126    if (merge) {
127       AODmerge();
128       mgr->InitAnalysis();
129       mgr->SetGridHandler(new AliAnalysisAlien);
130       mgr->StartAnalysis("gridterminate",0);
131       return;
132    }   
133    // Run the analysis                                                                                                                     
134    //
135    TChain *chain = CreateChain();
136    if (!chain) return;
137                                                                                                                                                    
138    TStopwatch timer;
139    timer.Start();
140    mgr->SetSkipTerminate(kTRUE);
141    if (mgr->InitAnalysis()) {
142       mgr->PrintStatus();
143       mgr->StartAnalysis("local", chain);
144    }
145    timer.Print();
146 }                                                                                                                                          
147                                                                                                                                             
148 //______________________________________________________________________________                                                           
149 void AddAnalysisTasks(const char *cdb_location){                                                                                                                                          
150   // Add all analysis task wagons to the train                                                                                               
151    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();                                                                     
152
153   //
154   // Tender and supplies. Needs to be called for every event.
155   //
156    AliAnalysisManager::SetCommonFileName("AODQA.root");
157    if (useTender) {
158       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/TenderSupplies/AddTaskTender.C");
159       // IF V0 tender needed, put kTRUE below
160       AliAnalysisTaskSE *tender = AddTaskTender(useV0tender);
161 //      tender->SetDebugLevel(2);
162    }
163    //
164   // PIDResponse(JENS)
165   //
166   if (doPIDResponse) {
167     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C"); 
168     AliAnalysisTaskPIDResponse *PIDResponse = AddTaskPIDResponse();
169 //    PIDResponse->SelectCollisionCandidates(AliVEvent::kAny);
170   }  
171  
172   //
173   // PIDqa(JENS)
174   //
175   if (doPIDqa) {
176     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDqa.C");
177     AliAnalysisTaskPIDqa *PIDQA = AddTaskPIDqa();
178     PIDQA->SelectCollisionCandidates(AliVEvent::kAny);
179   }  
180   // CDB connection
181   //
182   if (doCDBconnect && !useTender) {
183     gROOT->LoadMacro("$ALICE_ROOT/PWGPP/PilotTrain/AddTaskCDBconnect.C");
184     AliTaskCDBconnect *taskCDB = AddTaskCDBconnect(cdb_location, run_number);
185     if (!taskCDB) return;
186     AliCDBManager *cdb = AliCDBManager::Instance();
187     cdb->SetDefaultStorage(cdb_location);
188 //    taskCDB->SetRunNumber(run_number);
189   }    
190  
191    if (usePhysicsSelection) {
192    // Physics selection task
193       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
194       mgr->RegisterExtraFile("event_stat.root");
195       AliPhysicsSelectionTask *physSelTask = AddTaskPhysicsSelection(useMC);
196 //      AliOADBPhysicsSelection * oadbDefaultPbPb = CreateOADBphysicsSelection();      
197 //      physSelTask->GetPhysicsSelection()->SetCustomOADBObjects(oadbDefaultPbPb,0,0);
198       mgr->AddStatisticsTask(AliVEvent::kAny);
199    }
200    
201
202 //Jacek
203    if (iPWGPP) {
204       gROOT->LoadMacro("$ALICE_ROOT/PWGPP/macros/AddTaskFilteredTree.C");
205       AddTaskFilteredTree("FilterEvents_Trees.root");
206    }   
207    
208    // Centrality (only Pb-Pb)
209    if (useCentrality) {
210       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
211       AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
212       //taskCentrality->SelectCollisionCandidates(AliVEvent::kAny);
213    }
214    
215 // --- PWGLF - Forward (cholm@nbi.dk) -----------------------------
216    if (iPWGLFForward && usePhysicsSelection) { 
217         gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/AddTaskForwardMult.C");
218      UShort_t pwglfForwardSys = 0; // iCollision+1; // pp:1, PbPb:2, pPb:3
219      UShort_t pwglfSNN        = 0;            // GeV, 0==unknown
220      Short_t  pwglfField      = 0;
221      AddTaskForwardMult(useMC && useTR,        // Need track-refs 
222                         pwglfForwardSys,       // Collision system
223                         pwglfSNN, 
224                         pwglfField);
225         gROOT->LoadMacro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/AddTaskCentralMult.C");
226         AddTaskCentralMult(useMC, pwglfForwardSys, pwglfSNN, pwglfField);
227    }
228  
229     
230
231    if (iESDfilter) {
232       //  ESD filter task configuration.
233       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/ESDfilter/macros/AddTaskESDFilter.C");
234       AliAnalysisTaskESDfilter *taskesdfilter = 0;
235        if (iMUONcopyAOD) {
236            printf("Registering delta AOD file\n");
237            mgr->RegisterExtraFile("AliAOD.Muons.root");
238            mgr->RegisterExtraFile("AliAOD.Dimuons.root");
239            taskesdfilter = AddTaskESDFilter(useKFILTER, kTRUE, kFALSE, kFALSE /*usePhysicsSelection*/,kFALSE,kTRUE,kFALSE,kFALSE,run_flag);
240        } else {
241          taskesdfilter = AddTaskESDFilter(useKFILTER, kFALSE, kFALSE, kFALSE /*usePhysicsSelection*/,kFALSE,kTRUE,kFALSE,kFALSE,run_flag); // others
242        }   
243        if (iESDfilterReVtx>=0 && taskesdfilter) taskesdfilter->SetRefitVertexTracks(iESDfilterReVtx, cutsESDfilterReVtx);
244        taskesdfilter->Dump();
245        return; 
246      }      
247               
248 //      if (iMUONcopyAOD) {
249 //         printf("Registering delta AOD file\n");
250 //         mgr->RegisterExtraFile("AliAOD.Muons.root");
251 //          mgr->RegisterExtraFile("AliAOD.Dimuons.root");
252 //      }
253 //      AliAnalysisTaskESDfilter *taskesdfilter = 
254 //                 AddTaskESDFilter(useKFILTER, 
255 //                                  iMUONcopyAOD,         // write Muon AOD
256 //                                  kFALSE,               // write dimuon AOD 
257 //                                  kFALSE,               // usePhysicsSelection 
258 //                                  kFALSE,               // centrality OBSOLETE
259 //                                  kTRUE,                // enable TPS only tracks
260 //                                  kFALSE,               // disable cascades
261 //                                  kFALSE,               // disable kinks
262 //                                  run_flag);            // run flag (YY00)
263 //        mgr->RegisterExtraFile("AliAOD.Dimuons.root");
264 //   }   
265
266 // ********** PWG3 wagons ******************************************************           
267    // PWGHF vertexing
268    if (iPWGHFvertexing) {
269       gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/macros/AddTaskVertexingHF.C");
270       if (!iPWGHFd2h) TFile::Cp(gSystem->ExpandPathName(configPWGHFd2h.Data()), "file:ConfigVertexingHF.C");
271       AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
272       if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
273       else mgr->RegisterExtraFile("AliAOD.VertexingHF.root");
274       taskvertexingHF->SelectCollisionCandidates(0);
275    }   
276       
277    // PWGDQ JPSI filtering (only pp)
278    if (iPWGDQJPSIfilter && (iCollision==0)) {
279       gROOT->LoadMacro("$ALICE_ROOT/PWGDQ/dielectron/macros/AddTaskJPSIFilter.C");
280       AliAnalysisTaskSE *taskJPSIfilter = AddTaskJPSIFilter();
281       if (!taskJPSIfilter) ::Warning("AnalysisTrainNew", "AliAnalysisTaskDielectronFilter cannot run for this train conditions - EXCLUDED");
282       else mgr->RegisterExtraFile("AliAOD.Dielectron.root");
283       taskJPSIfilter->SelectCollisionCandidates(0);
284    }   
285
286    // PWGHF D2h
287    if (iPWGHFd2h) {   
288      gROOT->LoadMacro("$ALICE_ROOT/PWGHF/vertexingHF/AddD2HTrain.C");
289      TFile::Cp(gSystem->ExpandPathName(configPWGHFd2h.Data()), "file:ConfigVertexingHF.C");
290      AddD2HTrain(kFALSE, 1,0,0,0,0,0,0,0,0,0,0);                                 
291    }
292    
293    // ********** PWG4 wagons ******************************************************
294    // Jet analysis
295
296    // Configurations flags, move up?
297    TString kDeltaAODJetName = "AliAOD.Jets.root"; //
298    Bool_t  kIsPbPb = (iCollision==0)?false:true; // can be more intlligent checking the name of the data set
299    TString kDefaultJetBackgroundBranch = "";
300    TString kJetSubtractBranches = "";
301    UInt_t kHighPtFilterMask = 272;// from esd filter
302    UInt_t iPhysicsSelectionFlag = 0;
303    if (iJETAN) {
304      gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJets.C");
305      // Default jet reconstructor running on ESD's
306      AliAnalysisTaskJets *taskjets = AddTaskJets("AOD","UA1",0.4,kHighPtFilterMask,1.,0); // no background subtraction     
307      if (!taskjets) ::Fatal("AnalysisTrainNew", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
308      if(kDeltaAODJetName.Length()>0) taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
309      if (iJETANdelta) {
310         //            AddTaskJetsDelta("AliAOD.Jets.root"); // need to modify this accordingly in the add task jets
311         mgr->RegisterExtraFile(kDeltaAODJetName.Data());
312         TString cTmp("");
313         if(kIsPbPb){
314           // UA1 intrinsic background subtraction
315           taskjets = AddTaskJets("AOD","UA1",0.4,kHighPtFilterMask,1.,2); // background subtraction
316           if(kDeltaAODJetName.Length()>0)taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
317        }
318        // SICONE 
319        taskjets = AddTaskJets("AOD","SISCONE",0.4,kHighPtFilterMask,0.15,0); //no background subtration to be done later....                                                                                  
320        if(kDeltaAODJetName.Length()>0)taskjets->SetNonStdOutputFile(kDeltaAODJetName.Data());
321        cTmp = taskjets->GetNonStdBranch();
322        if(cTmp.Length()>0)kJetSubtractBranches += Form("%s ",cTmp.Data());
323          
324        // Add the clusters..
325        gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJetCluster.C");
326        AliAnalysisTaskJetCluster *taskCl = 0;
327        Float_t fCenUp = 0;
328        Float_t fCenLo = 0;
329        Float_t fTrackEtaWindow = 0.9;
330        taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"KT",0.4,0,1, kDeltaAODJetName.Data(),0.15,fTrackEtaWindow,0); // this one is for the background and random jets, random cones with no skip                                                                                 
331        taskCl->SetBackgroundCalc(kTRUE);
332        taskCl->SetNRandomCones(10);
333        taskCl->SetCentralityCut(fCenLo,fCenUp);
334        taskCl->SetGhostEtamax(fTrackEtaWindow);
335        kDefaultJetBackgroundBranch = Form("%s_%s",AliAODJetEventBackground::StdBranchName(),taskCl->GetJetOutputBranch());
336
337        taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"ANTIKT",0.4,2,1,kDeltaAODJetName.Data(),0.15);
338        taskCl->SetCentralityCut(fCenLo,fCenUp);
339        if(kIsPbPb)taskCl->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
340        taskCl->SetNRandomCones(10);
341        kJetSubtractBranches += Form("%s ",taskCl->GetJetOutputBranch());
342
343        taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelectionFlag,"ANTIKT",0.2,0,1,kDeltaAODJetName.Data(),0.15);
344        taskCl->SetCentralityCut(fCenLo,fCenUp);
345        if(kIsPbPb)taskCl->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
346        kJetSubtractBranches += Form("%s ",taskCl->GetJetOutputBranch());
347          
348        // DO THE BACKGROUND SUBTRACTION
349        if(kIsPbPb&&kJetSubtractBranches.Length()){
350          gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/AddTaskJetBackgroundSubtract.C");
351          AliAnalysisTaskJetBackgroundSubtract *taskSubtract = 0;
352          taskSubtract = AddTaskJetBackgroundSubtract(kJetSubtractBranches,1,"B0","B%d");
353          taskSubtract->SetBackgroundBranch(kDefaultJetBackgroundBranch.Data());
354          if(kDeltaAODJetName.Length()>0)taskSubtract->SetNonStdOutputFile(kDeltaAODJetName.Data());
355        }
356      } 
357    }
358 }
359 //______________________________________________________________________________
360 Bool_t LoadCommonLibraries()
361 {
362 // Load common analysis libraries.
363    if (!gSystem->Getenv("ALICE_ROOT")) {
364       ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); 
365       return kFALSE;
366    }   
367    Bool_t success = kTRUE;
368    // Load framework classes. Par option ignored here.
369    success &= LoadLibrary("libSTEERBase.so");
370    success &= LoadLibrary("libESD.so");
371    success &= LoadLibrary("libAOD.so");
372    success &= LoadLibrary("libANALYSIS.so");
373    success &= LoadLibrary("libOADB.so");
374    success &= LoadLibrary("libANALYSISalice.so");
375      success &= LoadLibrary("libESDfilter.so");
376    success &= LoadLibrary("libCORRFW.so");
377    gROOT->ProcessLine(".include $ALICE_ROOT/include");
378    if (success) {
379       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    SUCCESS");
380       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
381               gSystem->GetIncludePath());
382    } else {           
383       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    FAILED");
384    }   
385    return success;
386 }
387
388 //______________________________________________________________________________
389 Bool_t LoadAnalysisLibraries()
390 {
391 // Load common analysis libraries.
392    if (useTender || doCDBconnect) {
393       if (!LoadLibrary("TENDER") ||
394           !LoadLibrary("TENDERSupplies")) return kFALSE;
395    }       
396    // CDBconnect
397    if (doCDBconnect && !useTender) {
398       if (!LoadLibrary("PWGPP")) return kFALSE;
399    }
400           
401    if (iESDfilter || iPWGMuonTrain) {
402       if (!LoadLibrary("PWGmuon")) return kFALSE;
403    }   
404    // JETAN
405    if (iJETAN) {
406       if (!LoadLibrary("JETAN")) return kFALSE;
407    }
408    if (iJETANdelta) {
409       if (!LoadLibrary("JETAN") ||
410           !LoadLibrary("CGAL") ||
411           !LoadLibrary("fastjet") ||
412           !LoadLibrary("siscone") ||
413           !LoadLibrary("SISConePlugin") ||
414           !LoadLibrary("FASTJETAN")) return kFALSE;
415    }  
416    // PWG2 FORWARD
417    if (iPWGLFForward) {
418       //if (!LoadLibrary("PWGLFforward", mode, kTRUE)) return kFALSE;
419      if (!LoadLibrary("PWGLFforward2")) return kFALSE;
420   }   
421    
422    // PWG3 Vertexing HF
423    if (iPWGHFvertexing || iPWGHFd2h) {
424       if (!LoadLibrary("PWGflowBase") ||
425           !LoadLibrary("PWGflowTasks") ||
426           !LoadLibrary("PWGTRD") ||
427           !LoadLibrary("PWGHFvertexingHF")) return kFALSE;
428    }    
429  //    if (iPWGHFvertexing || iPWG3d2h) {
430  //     if (!LoadLibrary("PWG3base") ||
431  //         !LoadLibrary("PWGHFvertexingHF")) return kFALSE;
432  //  }   
433    // PWG3 dielectron
434    if (iPWGDQJPSIfilter) {
435       if (!LoadLibrary("PWGDQdielectron")) return kFALSE;
436    }   
437    
438    ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries:   SUCCESS");
439    return kTRUE;
440 }
441
442 //______________________________________________________________________________
443 Bool_t LoadLibrary(const char *module)
444 {
445 // Load a module library in a given mode. Reports success.
446    Int_t result;
447    TString mod(module);
448    if (!mod.Length()) {
449       ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
450       return kFALSE;
451    }   
452    // If a library is specified, just load it
453    if (mod.EndsWith(".so")) {
454       mod.Remove(mod.Index(".so"));
455       result = gSystem->Load(mod);
456       if (result < 0) {
457          ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
458          return kFALSE;
459       }
460       return kTRUE;
461    } 
462    // Check if the library is already loaded
463    if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0) return kTRUE;    
464    result = gSystem->Load(Form("lib%s.so", module));
465    if (result < 0) {
466       ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
467       return kFALSE;
468    }
469    return kTRUE;
470 }           
471
472
473 //______________________________________________________________________________
474 TChain *CreateChain()
475 {
476 // Create the input chain
477    chain = new TChain("esdTree");
478    if (gSystem->AccessPathName("AliESDs.root")) 
479       ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
480    else 
481        chain->Add("AliESDs.root");
482    if (chain->GetNtrees()) return chain;
483    return NULL;
484 }   
485
486 //______________________________________________________________________________
487 void AODmerge()
488 {
489 // Merging method. No staging and no terminate phase.
490   TStopwatch timer;
491   timer.Start();
492   TString outputDir = "wn.xml";
493   TString outputFiles = "EventStat_temp.root,AODQA.root,AliAOD.root,AliAOD.VertexingHF.root,FilterEvents_Trees.root,AliAOD.Muons.root,AliAOD.Jets.root";
494   TString mergeExcludes = "";
495   TObjArray *list = outputFiles.Tokenize(",");
496   TIter *iter = new TIter(list);
497   TObjString *str;
498   TString outputFile;
499   Bool_t merged = kTRUE;
500   while((str=(TObjString*)iter->Next())) {
501     outputFile = str->GetString();
502     // Skip already merged outputs
503     if (!gSystem->AccessPathName(outputFile)) {
504        printf("Output file <%s> found. Not merging again.",outputFile.Data());
505        continue;
506     }
507     if (mergeExcludes.Contains(outputFile.Data())) continue;
508     merged = AliAnalysisAlien::MergeOutput(outputFile, outputDir, 10, 0);
509     if (!merged) {
510        printf("ERROR: Cannot merge %s\n", outputFile.Data());
511        continue;
512     }
513   }
514   // all outputs merged, validate
515   ofstream out;
516   out.open("outputs_valid", ios::out);
517   out.close();
518   timer.Print();
519 }