]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/macros/AnalysisTrainNew.C
New version of train macro and configuration
[u/mrichter/AliRoot.git] / ANALYSIS / macros / AnalysisTrainNew.C
1 //===================== ANALYSIS TRAIN =========================================
2 // To use: copy this macro to your work directory, modify the global part to match
3 // your needs, then run root.
4 //    root[0] .L AnalysisTrain.C
5 // Grid full mode as below (other modes: test, offline, submit, terminate)
6 //    root[1] AnalysisTrainNew("grid", "full")
7 // CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
8 //    root[2] AnalysisTrainNew("proof")
9 // Local mode requires AliESds.root or AliAOD.root in ./data directory
10 //    root[3] AnalysisTrainNew("local")
11 // In proof and grid modes, a token is needed and sourcing the produced environment file.
12 //
13 // If 'saveTrain' flag is set, the train will generate a directory name and run
14 // in this directory. A configuration file 'ConfigTrain.C' will be generated. 
15 // One can replay at any time the train via:
16 //    root[1] AnalysisTrainNew(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")
17
18 //==================   TRAIN NAME   ============================================
19 TString     train_name         = "TR004_LHC09a3ESD"; // *CHANGE ME* (no blancs or special characters)
20 TString     job_tag            = "ESD+MC analysis -> AOD + delta AOD + histograms"; // *CHANGE ME*
21 //==============================================================================
22
23 // ### Settings that make sense in PROOF only
24 //==============================================================================
25 TString     proof_cluster      = "alicecaf.cern.ch";
26 Bool_t      useAFPAR           = kFALSE;  // use AF special par file
27 TString     AFversion          = "AF-v4-17";
28 // Change CAF dataset here
29 TString     proof_dataset      = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
30 TString     proof_outdir       = "";
31
32 // ### Settings that make sense when using the Alien plugin
33 //==============================================================================
34 Bool_t      usePLUGIN          = kTRUE;   // do not change
35 Bool_t      useProductionMode  = kTRUE;   // use the plugin in production mode
36 // Usage of par files ONLY in grid mode and ONLY if the code is not available
37 // in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
38 // To refresh par files, remove the ones in the workdir, then do "make <target.par>" in 
39 // AliRoot.
40 Bool_t      usePAR             = kFALSE;  // use par files for extra libs
41 Bool_t      useCPAR            = kFALSE;  // use par files for common libs
42 TString     root_version       = "v20091109";  // *CHANGE ME IF MORE RECENT IN GRID*
43 TString     aliroot_version    = "v4-18-10-AN";  // *CHANGE ME IF MORE RECENT IN GRID*                                          
44 // Change production base directory here
45 TString     alien_datadir      = "/alice/sim/PDC_08b/LHC09a3";
46 // AliEn output directory. If blank will become output_<train_name>
47 TString     alien_outdir       = "/alice/sim/PDC_08b/LHC09a3/AOD";
48 // TString     alien_outdir       = "";
49 // Number of files merged in a chunk
50 Int_t       maxMergeFiles      = 50;
51 // Files that should not be merged
52 TString     mergeExclude       = "AliAOD.root AliAOD.VertexingHF.root AliAOD.Jets.root deltaAODPartCorr.root";
53 // Make replicas on the storages below
54 TString     outputStorages      = "ALICE::NIHAM::File,ALICE::CNAF::SE,ALICE::FZK::SE,ALICE::GSI::SE,ALICE::Legnaro::SE";
55 // Number of runs per master job
56 Int_t       nRunsPerMaster     = 10;
57 // Maximum number of files per job (gives size of AOD)
58 Int_t       nFilesPerJob       = 50;
59 // Set the run range
60 //Int_t       run_range[2]       =  {70000, 70220};  // LHC09a4   *CHANGE ME*
61 Int_t       run_range[2]       =  {90000, 90025};
62 // ### Settings that make sense only for local analysis
63 //==============================================================================
64 // Change local xml dataset for local interactive analysis
65 TString     local_xmldataset   = "";
66
67 // ### Other flags to steer the analysis
68 //==============================================================================
69 Bool_t      useDATE            = kFALSE; // use date in train name
70 Bool_t      useDBG             = kFALSE; // activate debugging
71 Bool_t      useMC              = kTRUE;  // use MC info
72 Bool_t      useTAGS            = kTRUE; // use ESD tags for selection
73 Bool_t      useKFILTER         = kTRUE; // use Kinematics filter
74 Bool_t      useTR              = kTRUE;  // use track references
75 Bool_t      useCORRFW          = kFALSE; // do not change
76 Bool_t      useAODTAGS         = kFALSE;  // use AOD tags
77 Bool_t      saveTrain          = kTRUE;  // save train configuration as: 
78 Bool_t      saveProofToAlien   = kFALSE; // save proof outputs in AliEn
79                                          // train_[trainName]_ddMonthyyyy_time.C
80 // ### Analysis modules to be included. Some may not be yet fully implemented.
81 //==============================================================================
82 Int_t       iAODanalysis       = 0;      // Analysis on input AOD's
83 Int_t       iAODhandler        = 1;      // Analysis produces an AOD or dAOD's
84 Int_t       iESDfilter         = 1;      // ESD to AOD filter (barrel + muon tracks)
85 Int_t       iMUONcopyAOD       = 0;      // Task that copies only muon events in a separate AOD (PWG3)
86 Int_t       iJETAN             = 1;      // Jet analysis (PWG4) - needs ESD filter
87 Int_t       iPWG4partcorr      = 1;      // Gamma-hadron correlations task (PWG4)
88 Int_t       iPWG4gammaconv     = 1;      // Gamma conversion analysis (PWG4)
89 Int_t       iPWG4omega3pi      = 1;      // Omega to 3 pi analysis (PWG4)
90 Int_t       iPWG3vertexing     = 1;      // Vertexing HF task (PWG2)
91 Int_t       iPWG3hfe           = 1;      // Electrons analysis (PWG3)
92 Int_t       iPWG3d2h           = 1;      // D0->2 hadrons (PWG3)
93 Int_t       iPWG2femto         = 1;      // Femtoscopy task (PWG2)
94 Int_t       iPWG2spectra       = 1;      // Spectra tasks (PWG2
95 Int_t        iPWG2protons      = 1;         // Proton-antiproton analysis
96 Int_t        iPWG2checkcascade = 1;         // Check cascades task
97 Int_t        iPWG2perfcascade  = 1;         // Check performance cascade
98 Int_t        iPWG2checkv0      = 1;         // Check V0 task
99 Int_t        iPWG2strange      = 1;         // Strangeness task
100 Int_t       iPWG2flow          = 1;      // Flow analysis tasks (PWG2)
101 Int_t       iPWG2res           = 1;      // Resonances task (PWG2)
102 Int_t        iPWG2rsneff       = 1;      // Resonances efficiency
103 Int_t       iPWG2kink          = 1;      // Kink analysis tasks (PWG2)
104 Int_t        iPWG2kinkESDMC    = 1;         // Kink ESD-MC comparison (PWG2)
105 Int_t        iPWG2kinklikesign = 1;         // Kink like-sign (PWG2)
106 Int_t        iPWG2kinkKstarESD = 1;      // Kink Kstar ESD (PWG2)
107 Int_t        iPWG2kinkKstarMC  = 1;      // Kink Kstar MC (PWG2)
108 Int_t        iPWG2kinkL1520ESD = 1;      // Kink L1520 ESD (PWG2)
109 Int_t        iPWG2kinkL1520MC  = 1;      // Kink L1520 MC (PWG2)
110 Int_t        iPWG2kinkPhiESD   = 1;      // Kink resonances Phi ESD (PWG2)
111 Int_t        iPWG2kinkPhiMC    = 1;      // Kink resonances Phi MC (PWG2)
112 Int_t       iPWG2evchar        = 1;      // Event characteristics (PWG2)
113 Int_t       iPWG2unicor        = 1;      // Unicor analysis (PWG2)
114 Int_t       iPWG2forward       = 1;      // FMD analysis (PWG2)
115
116 // ### Configuration macros used for each module
117 //==============================================================================
118 TString     configPWG2femto    = "$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/Train/Train3/ConfigFemtoAnalysis.C";
119 //TString     configPWG3d2h      = "$ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF_highmult.C";
120 TString     configPWG3d2h      = "$ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF_highmult.C";
121 // Temporaries.
122 TString anaPars = "";
123 TString anaLibs = "";
124 // Function signatures
125 class AliAnalysisAlien;
126
127 //______________________________________________________________________________
128 void AnalysisTrainNew(const char *analysis_mode="grid", 
129                       const char *plugin_mode="full",
130                       const char *config_file="")
131 {
132 // Main analysis train macro. If a configuration file is provided, all parameters
133 // are taken from there but may be altered by CheckModuleFlags.
134    if (strlen(config_file) && !LoadConfig(config_file)) return;
135    TString smode(analysis_mode);
136    smode.ToUpper();
137    // Check compatibility of selected modules
138    CheckModuleFlags(smode);
139    if (saveTrain)              WriteConfig();
140
141    printf("==================================================================\n");
142    printf("===========    RUNNING ANALYSIS TRAIN %s IN %s MODE   ==========\n", train_name.Data(),smode.Data());
143    printf("==================================================================\n");
144    printf("=  Configuring analysis train for:                               =\n");
145    if (iAODanalysis) printf("=  AOD analysis                                                  =\n");
146    else              printf("=  ESD analysis                                                  =\n");
147    if (iESDfilter)   printf("=  ESD filter                                                    =\n");
148    if (iMUONcopyAOD) printf("=  MUON copy AOD                                                 =\n");
149    if (iJETAN)       printf("=  Jet analysis                                                  =\n");
150    if (iPWG2spectra) {
151       printf("=  PWG2 SPECTRA tasks :                                          =\n");
152       if (iPWG2protons)      printf("=     PWG2 proton-antiproton                                     =\n");
153       if (iPWG2checkcascade) printf("=     PWG2 check cascades                                        =\n");
154       if (iPWG2perfcascade)  printf("=     PWG2 performance cascades                                  =\n");
155       if (iPWG2checkv0)      printf("=     PWG2 check V0                                              =\n");
156       if (iPWG2strange)      printf("=     PWG2 strangeness                                           =\n");
157    }   
158    if (iPWG2femto) {
159       printf("=  PWG2 femtoscopy                                               =\n");
160       printf("   +++ configured by: %s\n", configPWG2femto.Data());
161    }   
162    if (iPWG2flow)    printf("=  PWG2 flow                                                     =\n");
163    if (iPWG2res)     printf("=  PWG2 resonances                                               =\n");
164       if (iPWG2rsneff)    printf("=     PWG2 resonances efficiency                                    =\n");
165    if (iPWG2kink) {
166       printf("=  PWG2 kink analysis tasks:                                     =\n");
167       if (iPWG2kinkESDMC)    printf("=     PWG2 ESD-MC kinks                                          =\n");
168       if (iPWG2kinklikesign) printf("=     PWG2 kink like-sign analysis                               =\n");
169       if (iPWG2kinkKstarESD) printf("=     PWG2 kink Kstar ESD analysis                               =\n");
170       if (iPWG2kinkKstarMC)  printf("=     PWG2 kink Kstar MC analysis                                =\n");
171       if (iPWG2kinkL1520ESD) printf("=     PWG2 kink L1520 ESD analysis                               =\n");
172       if (iPWG2kinkL1520MC)  printf("=     PWG2 kink L1520 MC analysis                                =\n");
173       if (iPWG2kinkPhiESD) printf("=     PWG2 kink Phi ESD analysis                                 =\n");
174       if (iPWG2kinkPhiMC)  printf("=     PWG2 kink Phi MC analysis                                  =\n");
175   }   
176    if (iPWG2evchar)    printf("=  PWG2 event characteristics                                    =\n");
177    if (iPWG2unicor)    printf("=  PWG2 Unicor analysis                                          =\n");
178    if (iPWG2forward)   printf("=  PWG2 forward: sharing, density, bkg. correction, dNdEta       =\n");
179    if (iPWG3vertexing) printf("=  PWG3 vertexing                                                =\n");
180    if (iPWG3hfe)       printf("=  PWG3 electrons                                                =\n");
181    if (iPWG3d2h) {
182       printf("=  PWG3 D0->2 hadrons tasks                                      =\n");
183       printf("   +++ configured by: %s\n", configPWG3d2h.Data());
184    }         
185    if (iPWG4partcorr)  printf("=  PWG4 gamma-hadron, pi0 and gamma-jet correlations             =\n");
186    if (iPWG4gammaconv) printf("=  PWG4 gamma conversion                                         =\n");
187    if (iPWG4omega3pi)  printf("=  PWG4 omega to 3 pions                                         =\n");
188    printf("==================================================================\n");
189    printf(":: use MC truth      %d\n", (UInt_t)useMC);
190    printf(":: use KINE filter   %d\n", (UInt_t)useKFILTER);
191    printf(":: use track refs    %d\n", (UInt_t)useTR);
192    printf(":: use tags          %d\n", (UInt_t)useTAGS);
193    printf(":: use AOD tags      %d\n", (UInt_t)useAODTAGS);
194    printf(":: use debugging     %d\n", (UInt_t)useDBG);
195    printf(":: use PAR files     %d\n", (UInt_t)usePAR);
196    printf(":: use AliEn plugin  %d\n", (UInt_t)usePLUGIN);
197
198    //==========================================================================
199    // Connect to back-end system
200    if (!Connect(smode)) {
201       ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
202       return;
203    }   
204
205    // Load common libraries and set include path
206    if (!LoadCommonLibraries(smode)) {
207       ::Error("AnalysisTrain", "Could not load common libraries");
208       return;
209    }
210     
211    // Make the analysis manager and connect event handlers
212    AliAnalysisManager *mgr  = new AliAnalysisManager("Analysis Train", "Production train");
213    if (saveProofToAlien) mgr->SetSpecialOutputLocation(proof_outdir);
214    if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
215    // Load analysis specific libraries
216    if (!LoadAnalysisLibraries(smode)) {
217       ::Error("AnalysisTrain", "Could not load analysis libraries");
218       return;
219    }   
220
221    // Create input handler (input container created automatically)
222    if (iAODanalysis) {
223    // AOD input handler
224       AliAODInputHandler *aodH = new AliAODInputHandler();
225       if (iPWG3d2h) aodH->AddFriend("AliAOD.VertexingHF.root");
226       mgr->SetInputEventHandler(aodH);
227    } else {   
228    // ESD input handler
229       AliESDInputHandler *esdHandler = new AliESDInputHandler();
230       if (useTAGS) esdHandler->SetReadTags();
231       mgr->SetInputEventHandler(esdHandler);       
232    }
233    // Monte Carlo handler
234    if (useMC && !iAODanalysis) {
235       AliMCEventHandler* mcHandler = new AliMCEventHandler();
236       mgr->SetMCtruthEventHandler(mcHandler);
237       mcHandler->SetReadTR(useTR); 
238    }   
239    // AOD output container, created automatically when setting an AOD handler
240    if (iAODhandler) {
241       // AOD output handler
242       AliAODHandler* aodHandler   = new AliAODHandler();
243       aodHandler->SetOutputFileName("AliAOD.root");
244       mgr->SetOutputEventHandler(aodHandler);
245       if (iAODanalysis) {
246          aodHandler->SetFillAOD(kFALSE);
247          aodHandler->SetCreateNonStandardAOD();
248          if (iJETAN)         aodHandler->SetOutputFileName("AliAOD.Jets.root");
249 //         if (iPWG3vertexing) aodHandler->SetOutputFileName("AliAOD.VertexingHF.root");
250       } 
251    }
252    // Debugging if needed
253    if (useDBG) mgr->SetDebugLevel(3);
254
255    //==========================================================================
256    // Create the chain. In this example it is created only from ALIEN files but
257    // can be done to work in batch or grid mode as well.
258    TChain *chain = CreateChain(smode, plugin_mode);
259         
260    //==========================================================================
261    // Load the tasks configuration macros for all wagons. These files are supposed now to be
262    // in the current workdir, but in AliEn they will be in the file catalog, 
263    // mapped from AliRoot and pecified in the jdl input list.
264     
265    // For now connection to top input container and common AOD output container
266    // is done in this macro, but in future these containers will be connected
267    // from each task configuration macro.
268
269    if (iESDfilter && !iAODanalysis) {
270       //  ESD filter task configuration.
271       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
272       AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(useKFILTER);
273    }   
274
275    // AOD tags
276    if (useAODTAGS) {
277       AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
278       mgr->AddTask(tagTask);
279       AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag",  TTree::Class(), 
280                                            AliAnalysisManager::kOutputContainer, "AOD.tag.root");
281       mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
282       mgr->ConnectOutput(tagTask, 1, coutTags);
283    }   
284     
285 // ********** PWG2 wagons ******************************************************
286    AliAnalysisManager::SetCommonFileName("PWG2histograms.root");
287
288    // Proton analysis
289    if (iPWG2spectra) {
290       // protons
291       if (iPWG2protons) {
292         gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskProtons.C");
293         AliAnalysisTaskProtons *taskprotons = AddTaskProtons();
294         if (!taskprotons) ::Warning("AnalysisTrainNew", "AliAnalysisTaskProtons cannot run for this train conditions - EXCLUDED");
295       }  
296       // cascades
297       if (iPWG2checkcascade) {
298         gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckCascade.C");
299         AliAnalysisTaskCheckCascade *taskcheckcascade = AddTaskCheckCascade();      
300         if (!taskcheckcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckCascade cannot run for this train conditions - EXCLUDED");
301       }  
302       // v0's
303       if (iPWG2checkv0) {
304         gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckV0.C");
305         AliAnalysisTaskCheckV0 *taskcheckV0 = AddTaskCheckV0();
306         if (!taskcheckV0) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckV0 cannot run for this train conditions - EXCLUDED");
307       }  
308       // strangeness
309       if (iPWG2strange) {
310         gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskStrange.C");
311         AliAnalysisTaskStrange *taskstrange = AddTaskStrange();
312         if (!taskstrange) ::Warning("AnalysisTrainNew", "AliAnalysisTaskStrange cannot run for this train conditions - EXCLUDED");
313       }  
314       // performance cascades
315       if (iPWG2perfcascade) {
316         gROOT->LoadMacro("$ALICE_ROOT/PWG2/SPECTRA/macros/AddTaskCheckPerformanceCascade.C");
317         AliAnalysisTaskCheckPerformanceCascade *taskperfcascade = AddTaskCheckPerformanceCascade();
318         if (!taskperfcascade) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCheckPerformanceCascade cannot run for this train conditions - EXCLUDED");
319       }  
320    }   
321    
322    // Femtoscopy analysis modules
323    if (iPWG2femto) {
324       gROOT->LoadMacro("$ALICE_ROOT/PWG2/FEMTOSCOPY/macros/AddTaskFemto.C");
325       AliAnalysisTaskFemto *taskfemto = AddTaskFemto(configPWG2femto);
326       if (!taskfemto) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFemto cannot run for this train conditions - EXCLUDED");
327    }   
328
329    // Kink analysis
330    if (iPWG2kink) {
331       if (iPWG2kinkESDMC) {
332         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKink.C");
333         AliAnalysisKinkESDMC *taskkink1 = AddTaskKink();
334         if (!taskkink1) ::Warning("AnalysisTrainNew", "AliAnalysisKinkESDMC cannot run for this train conditions - EXCLUDED");
335       }   
336       if (iPWG2kinklikesign) {
337         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceLikeSign.C");
338         AliResonanceKinkLikeSign *taskkink2 = AddTaskKinkResonanceLikeSign();
339         if (!taskkink2) ::Warning("AnalysisTrainNew", "AliResonanceKinkLikeSign cannot run for this train conditions - EXCLUDED");
340       }  
341       if (iPWG2kinkKstarESD) {
342         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceKstarESD.C");
343         AliAnalysisTaskKinkResonance *taskkink3 = AddTaskKinkResonanceKstarESD();
344         if (!taskkink3) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonanceKstarESD cannot run for this train conditions - EXCLUDED");
345       }   
346       if (iPWG2kinkKstarMC) {
347         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceKstarMC.C");
348         AliAnalysisTaskKinkResonance *taskkink4 = AddTaskKinkResonanceKstarMC();
349         if (!taskkink4) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonanceKstarMC cannot run for this train conditions - EXCLUDED");
350       }   
351       if (iPWG2kinkL1520ESD) {
352         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceL1520ESD.C");
353         AliAnalysisTaskKinkResonance *taskkink5 = AddTaskKinkResonanceL1520ESD();
354         if (!taskkink5) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonanceL1520ESD cannot run for this train conditions - EXCLUDED");
355       }   
356       if (iPWG2kinkL1520MC) {
357         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonanceL1520MC.C");
358         AliAnalysisTaskKinkResonance *taskkink6 = AddTaskKinkResonanceL1520MC();
359         if (!taskkink6) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonanceL1520MC cannot run for this train conditions - EXCLUDED");
360       }   
361       if (iPWG2kinkPhiESD) {
362         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonancePhiESD.C");
363         AliAnalysisTaskKinkResonance *taskkink7 = AddTaskKinkResonancePhiESD();
364         if (!taskkink7) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonancePhiESD cannot run for this train conditions - EXCLUDED");
365       }   
366       if (iPWG2kinkPhiMC) {
367         gROOT->LoadMacro("$ALICE_ROOT/PWG2/KINK/macros/AddTaskKinkResonancePhiMC.C");
368         AliAnalysisTaskKinkResonance *taskkink8 = AddTaskKinkResonancePhiMC();
369         if (!taskkink8) ::Warning("AnalysisTrainNew", "AliAnalysisKinkResonancePhiMC cannot run for this train conditions - EXCLUDED");
370       }   
371    }   
372
373    // Event characterization
374    if (iPWG2evchar) {
375       gROOT->LoadMacro("$ALICE_ROOT/PWG2/EVCHAR/macros/AddTaskSPDdNdEta.C");
376       AliAnalysisTaskSPDdNdEta *taskspddndeta = AddTaskSPDdNdEta();
377       if (!taskspddndeta) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSPDdNdEta cannot run for this train conditions - EXCLUDED");
378       taskspddndeta->SetReadMC(useMC);
379    }   
380
381    // Unicor
382    if (iPWG2unicor) {
383       gROOT->LoadMacro("$ALICE_ROOT/PWG2/UNICOR/AddTaskUnicor.C");
384       AliAnalysisTaskUnicor *taskunicor = AddTaskUnicor();
385       if (!taskunicor) ::Warning("AnalysisTrainNew", "AliAnalysisTaskUnicor cannot run for this train conditions - EXCLUDED");
386    }   
387
388    // FMD
389    if (iPWG2forward) {
390       gROOT->LoadMacro("$ALICE_ROOT/PWG2/FORWARD/analysis/AddTaskFMD.C");
391       AliFMDAnalysisTaskSE *taskfmd = AddTaskFMD();
392       if (!taskfmd) ::Warning("AnalysisTrainNew", "AliFMDAnalysisTaskSE cannot run for this train conditions - EXCLUDED");
393    }   
394
395    // Flow analysis
396    if (iPWG2flow) {
397       gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskFlow.C");
398       Bool_t SP       = kTRUE;
399       Bool_t LYZ1SUM  = kTRUE;
400       Bool_t LYZ1PROD = kTRUE;
401       Bool_t LYZ2SUM  = kFALSE; 
402       Bool_t LYZ2PROD = kFALSE;
403       Bool_t LYZEP    = kFALSE; 
404       Bool_t GFC      = kTRUE;
405       Bool_t QC       = kTRUE;
406       Bool_t FQD      = kFALSE;
407       Bool_t MCEP     = kFALSE; //does not work yet 24/12/08
408       Bool_t kineFromESD = kTRUE;
409       Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
410       // Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
411       TString type = "AOD";
412       if (!iAODanalysis) type = "ESD";
413       // Boolean to fill/not fill the QA histograms
414       Bool_t QA = kTRUE;   
415       // Boolean to use/not use weights for the Q vector
416       Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
417       AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
418       if (!taskFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskFlowEvent cannot run for this train conditions - EXCLUDED");
419    }   
420
421    // PWG2 resonances
422    if (iPWG2res) {
423       gROOT->LoadMacro("$ALICE_ROOT/PWG2/RESONANCES/macros/train/AddAnalysisTaskRsn.C");
424       gROOT->LoadMacro("$ALICE_ROOT/PWG2/RESONANCES/macros/train/AddAnalysisTaskRsnEff.C");
425       TString path = gROOT->GetMacroPath();
426       path += ":$ALICE_ROOT/PWG2/RESONANCES/macros/train";
427       gROOT->SetMacroPath(path);
428       AddAnalysisTaskRsn(kTRUE);
429       AddAnalysisTaskRsnEff();
430    }   
431
432 // ********** PWG3 wagons ******************************************************
433    AliAnalysisManager::SetCommonFileName("PWG3histograms.root");
434            
435    // PWG3 vertexing
436    if (iPWG3vertexing) {
437       gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/AddTaskVertexingHF.C");
438       if (!iPWG3d2h) TFile::Cp(gSystem->ExpandPathName(configPWG3d2h.Data()), Form("%s/ConfigVertexingHF.C", train_name.Data()));
439       AliAnalysisTaskSEVertexingHF *taskvertexingHF = AddTaskVertexingHF();
440       if (!taskvertexingHF) ::Warning("AnalysisTrainNew", "AliAnalysisTaskSEVertexingHF cannot run for this train conditions - EXCLUDED");
441    }   
442       
443    // PWG3 electrons
444    if (iPWG3hfe) {
445       gROOT->LoadMacro("$ALICE_ROOT/PWG3/hfe/AddTaskHFE.C");
446       AliAnalysisTaskHFE *taskHFE = AddTaskHFE();
447       if (!taskHFE) ::Warning("AnalysisTrainNew", "AliAnalysisTaskHFE cannot run for this train conditions - EXCLUDED");
448    }   
449
450    // PWG3 D2h
451    if (iPWG3d2h) {
452       gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/AddD2HTrain.C");
453       TFile::Cp(gSystem->ExpandPathName(configPWG3d2h.Data()), Form("%s/ConfigVertexingHF.C", train_name.Data()));
454       AddD2HTrain();
455    }   
456       
457 // ********** PWG4 wagons ******************************************************
458    AliAnalysisManager::SetCommonFileName("PWG4histograms.root");
459
460     // Jet analysis
461    if (iJETAN) {
462       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
463       if (!iAODanalysis) {
464          // Default jet reconstructor running on ESD's
465          AliAnalysisTaskJets * taskjets = AddTaskJets();
466          if (!taskjets) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
467       } else {
468          // AOD-based analysis. Add all reconstructors to write into delta AOD's
469 //         AddTaskJetsDelta();
470          AliAnalysisTaskJets * taskjets = AddTaskJets();
471          taskjets->SetNonStdBranch("jetsAOD_UA1_04");
472       }      
473    }
474    // PWG4 hadron correlations
475    if (iPWG4partcorr) {
476       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
477       AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS");
478       if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
479       AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL");
480       if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
481    }   
482
483    // PWG4 gamma conversion analysis
484    if (iPWG4gammaconv) {
485       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
486       TString cdir = gSystem->WorkingDirectory();
487       gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
488       TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
489       AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
490       gSystem->ChangeDirectory(cdir);
491       if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
492    }   
493
494    // PWG4 omega to 3 pions analysis
495    if (iPWG4omega3pi) {
496       gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
497       AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
498       if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run for these train conditions - EXCLUDED");
499    }   
500
501    //==========================================================================
502    // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
503    // Run the analysis
504    //    
505    if (usePLUGIN) {
506       AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
507       AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
508    }
509       
510    if (mgr->InitAnalysis()) {
511       mgr->PrintStatus();
512       if (saveTrain || strlen(config_file)) gSystem->ChangeDirectory(train_name);
513       StartAnalysis(smode, chain);
514       if (saveTrain && smode=="GRID") {
515          AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
516          TString alien_workdir = gGrid->GetHomeDirectory();
517          if (iAODanalysis) alien_workdir += "analysisAOD";
518          else              alien_workdir += "analysisESD";
519          alien_outdir = gridhandler->GetGridOutputDir();
520          printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
521                 alien_workdir.Data());
522          if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), train_name.Data())))
523             gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), train_name.Data()));
524          if (strcmp(plugin_mode, "test"))
525             TFile::Cp(Form("file:%sConfig.C",train_name.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), train_name.Data()));
526       }
527    }
528 }
529
530 //______________________________________________________________________________
531 void StartAnalysis(const char *mode, TChain *chain) {
532 // Start analysis.
533    Int_t imode = -1;
534    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
535    if (!strcmp(mode, "LOCAL")) imode = 0;
536    if (!strcmp(mode, "PROOF")) imode = 1;
537    if (!strcmp(mode, "GRID"))  imode = 2;
538    switch (imode) {
539       case 0:
540          if (!chain) {
541             ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
542             return;
543          }   
544          mgr->StartAnalysis(mode, chain);
545          return;
546       case 1:
547          if (!proof_dataset.Length()) {
548             ::Error("AnalysisTrainNew.C::StartAnalysis", "proof_dataset is empty");
549             return;
550          }   
551          mgr->StartAnalysis(mode, proof_dataset, 1000);
552          return;
553       case 2:
554          if (usePLUGIN) {
555             if (!mgr->GetGridHandler()) {
556                ::Error("AnalysisTrainNew.C::StartAnalysis", "Grid plugin not initialized");
557                return;
558             }   
559             mgr->StartAnalysis("grid");
560          } else {
561             if (!chain) {
562                ::Error("AnalysisTrainNew.C::StartAnalysis", "Cannot create the chain");
563                return;
564             }   
565             mgr->StartAnalysis(mode, chain);
566          }   
567          return;
568    }      
569 }          
570     
571 //______________________________________________________________________________
572 void CheckModuleFlags(const char *mode) {
573 // Checks selected modules and insure compatibility
574    Int_t imode = -1;
575    if (!strcmp(mode, "LOCAL")) imode = 0;
576    if (!strcmp(mode, "PROOF")) imode = 1;
577    if (!strcmp(mode, "GRID"))  imode = 2;
578    if (imode==1) {
579       if (!usePAR) {
580          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
581          usePAR = kTRUE;
582       }   
583    }  
584    if (imode != 2) {
585       ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
586       usePLUGIN = kFALSE; 
587    }   
588    if (iAODanalysis) {
589    // AOD analysis
590       if (useMC)
591          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
592       if (useAODTAGS)
593          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
594       useMC = kFALSE;
595       useTR = kFALSE;
596       useAODTAGS = kFALSE;
597       if (iESDfilter)
598          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
599       iESDfilter   = 0;
600       if (!iAODhandler) {
601          if (iJETAN) 
602             ::Info("AnalysisTrainNew.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
603          iJETAN = 0;
604       }
605       // Disable tasks that do not work yet on AOD data
606       if (iPWG4gammaconv)
607          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4gammaconv disabled on AOD's without AOD handler");
608       iPWG4gammaconv = 0;   
609       if (iPWG2flow)
610          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2flow disabled on AOD's");
611          iPWG2flow = 0;
612       if (iPWG2femto)
613          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2femto disabled on AOD's");
614          iPWG2femto = 0;
615       if (iPWG2res)
616          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2res disabled on AOD's");
617          iPWG2res = 0;
618        if (iPWG2rsneff)
619          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2rsneff disabled on AOD's");
620          iPWG2rsneff = 0;
621      if (iPWG2kink)         
622          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2kink disabled in analysis on AOD's");
623          iPWG2kink = 0;
624       if (iPWG2unicor)         
625          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2unicor disabled in analysis on AOD's");
626          iPWG2unicor = 0;
627       if (iPWG2evchar)
628          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4evchar disabled on AOD's");
629          iPWG2evchar = 0;
630       if (iPWG2forward)         
631          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2forward disabled in analysis on AOD's");
632          iPWG2forward = 0;
633       if (iPWG3hfe)
634          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG3hfe disabled on AOD's");
635          iPWG3hfe = 0;
636       if (iPWG3vertexing)
637          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG3vertexing disabled on AOD's");
638 //         iPWG3vertexing = 0;
639       if (iPWG4omega3pi)
640          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
641          iPWG4omega3pi = 0;
642       if (iPWG4partcorr)
643          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
644          iPWG4partcorr = 0;
645    } else {   
646    // ESD analysis
647       iMUONcopyAOD = 0;
648       if (!useMC) useTR = kFALSE;
649       if (!useTR) {
650          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
651          iPWG2evchar = 0;
652       }   
653    }
654    if (!useMC) {
655       if (iPWG2perfcascade)
656          ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG2perfcascade disabled without MC info");
657       iPWG2perfcascade = 0;   
658    }   
659    if (iJETAN && !iAODanalysis) iESDfilter=1;
660    if (iESDfilter) {iAODhandler=1; useCORRFW = kTRUE;}
661    if (iPWG2spectra || iPWG2flow || iPWG3vertexing || iPWG3hfe || iPWG2res || iPWG2rsneff) useCORRFW = kTRUE;
662    if (useKFILTER && !useMC) useKFILTER = kFALSE;
663    if (useAODTAGS && !iAODhandler) useAODTAGS = kFALSE;
664 }
665
666 //______________________________________________________________________________
667 Bool_t Connect(const char *mode) {
668 // Connect <username> to the back-end system.
669    Int_t imode = -1;
670    if (!strcmp(mode, "LOCAL")) imode = 0;
671    if (!strcmp(mode, "PROOF")) imode = 1;
672    if (!strcmp(mode, "GRID"))  imode = 2;
673    TString username = gSystem->Getenv("alien_API_USER");
674    switch (imode) {
675       case 0:
676          break;
677       case 1:
678          if  (!username.Length()) {
679             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
680                            1. Have called: alien-token-init <username>\n \
681                            2. Have called: >source /tmp/gclient_env_$UID");
682             return kFALSE;
683          }
684          ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to PROOF cluster <%s>", 
685                 username.Data(), proof_cluster.Data());
686          gEnv->SetValue("XSec.GSI.DelegProxy", "2");
687 //         TProof::Open(Form("%s@%s:31093", username.Data(), proof_cluster.Data()));       
688          TProof::Open(Form("%s@%s", username.Data(), proof_cluster.Data()));       
689          if (!gProof) {
690             if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
691                ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
692             return kFALSE;
693          }
694          TGrid::Connect("alien://");
695          if (gGrid) {
696             TString homedir = gGrid->GetHomeDirectory();
697             TString workdir = homedir + train_name;
698             if (!gGrid->Cd(workdir)) {
699                gGrid->Cd(homedir);
700                if (gGrid->Mkdir(workdir)) {
701                   gGrid->Cd(train_name);
702                   ::Info("AnalysisTrainNew::Connect()", "Directory %s created", gGrid->Pwd());
703                }
704             }
705             gGrid->Mkdir("proof_output");
706             gGrid->Cd("proof_output");
707             proof_outdir = Form("alien://%s", gGrid->Pwd());
708          }   
709          break;
710       case 2:      
711          if  (!username.Length()) {
712             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), "Make sure you:\n \
713                            1. Have called: alien-token-init <username>\n \
714                            2. Have called: >source /tmp/gclient_env_$UID");
715             return kFALSE;
716          }
717          if (usePLUGIN && !gSystem->Getenv("alien_CLOSE_SE")) {
718             ::Error(Form("AnalysisTrainNew.C::Connect <%s>", mode), 
719                            "When using the AliEn plugin it is preferable to define the \
720                            variable alien_CLOSE_SE in your environment.");
721             return kFALSE;
722          }
723          ::Info("AnalysisTrainNew.C::Connect", "Connecting user <%s> to AliEn ...", 
724                 username.Data());
725          TGrid::Connect("alien://");
726          if (!gGrid || !gGrid->IsConnected()) return kFALSE;
727          break;
728       default:
729          ::Error("AnalysisTrainNew.C::Connect", "Unknown run mode: %s", mode);
730          return kFALSE;
731    }
732    ::Info("AnalysisTrainNew.C::Connect","Connected in %s mode", mode);
733    return kTRUE;
734 }
735
736 //______________________________________________________________________________
737 Bool_t LoadCommonLibraries(const char *mode)
738 {
739 // Load common analysis libraries.
740    Int_t imode = -1;
741    if (!strcmp(mode, "LOCAL")) imode = 0;
742    if (!strcmp(mode, "PROOF")) imode = 1;
743    if (!strcmp(mode, "GRID"))  imode = 2;
744    if (!gSystem->Getenv("ALICE_ROOT")) {
745       ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot"); 
746       return kFALSE;
747    }   
748    Bool_t success = kTRUE;
749    // ROOT libraries
750    gSystem->Load("libTree.so");
751    gSystem->Load("libGeom.so");
752    gSystem->Load("libVMC.so");
753    gSystem->Load("libPhysics.so");
754    
755    // Load framework classes. Par option ignored here.
756    switch (imode) {
757       case 0:
758       case 2:
759          if (useCPAR) {
760             success &= LoadLibrary("STEERBase", mode, kTRUE);
761             success &= LoadLibrary("ESD", mode, kTRUE);
762             success &= LoadLibrary("AOD", mode, kTRUE);
763             success &= LoadLibrary("ANALYSIS", mode, kTRUE);
764             success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
765             if (useCORRFW) success &= LoadLibrary("CORRFW", mode, kTRUE);
766          } else {   
767             success &= LoadLibrary("libSTEERBase.so", mode);
768             success &= LoadLibrary("libESD.so", mode);
769             success &= LoadLibrary("libAOD.so", mode);
770             success &= LoadLibrary("libANALYSIS.so", mode);
771             success &= LoadLibrary("libANALYSISalice.so", mode);
772             if (useCORRFW) success &= LoadLibrary("libCORRFW.so", mode);
773             gROOT->ProcessLine(".include $ALICE_ROOT/include");
774          }   
775          break;
776       case 1:
777          Int_t ires = -1;
778          if (useAFPAR && !gSystem->AccessPathName(AFversion)) ires = gProof->UploadPackage(AFversion);
779          if (ires < 0) {
780             success &= LoadLibrary("STEERBase", mode);
781             success &= LoadLibrary("ESD", mode);
782             success &= LoadLibrary("AOD", mode);
783             success &= LoadLibrary("ANALYSIS", mode);
784             success &= LoadLibrary("ANALYSISalice", mode);
785             if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
786          } else { 
787             ires = gProof->EnablePackage(AFversion);
788             if (ires<0) success = kFALSE;
789             if (useCORRFW) success &= LoadLibrary("CORRFW", mode);
790          }
791          break;         
792       default:
793          ::Error("AnalysisTrainNew.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
794          return kFALSE;
795    }
796    if (success) {
797       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    SUCCESS");
798       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
799               gSystem->GetIncludePath());
800    } else {           
801       ::Info("AnalysisTrainNew.C::LoadCommodLibraries", "Load common libraries:    FAILED");
802    }   
803       
804    return success;
805 }
806
807 //______________________________________________________________________________
808 Bool_t LoadAnalysisLibraries(const char *mode)
809 {
810 // Load common analysis libraries.
811    Bool_t success = kTRUE;
812    if (iESDfilter) {
813       if (!LoadLibrary("PWG3base", mode, kTRUE) ||
814           !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
815    }   
816    // JETAN
817    if (iJETAN) {
818       if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
819    }               
820    // PWG4 particle correlations
821    if (iPWG4partcorr) {   
822       if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
823           !LoadLibrary("PHOSUtils", mode, kTRUE) ||
824           !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
825           !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
826    }
827    // PWG4 gamma conversion
828    if (iPWG4gammaconv) {
829       if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
830    }      
831    // PWG4 omega to 3 pions
832    if (iPWG4omega3pi) {
833       if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
834    }      
835    // PWG2 task protons 
836    if (iPWG2spectra) {
837       if (!LoadLibrary("PWG2spectra", mode, kTRUE)) return kFALSE;
838    }
839    // PWG2 flow
840    if (iPWG2flow) {
841       if (!LoadLibrary("PWG2flowCommon", mode, kTRUE) ||
842           !LoadLibrary("PWG2flowTasks", mode, kTRUE)) return kFALSE;
843    }
844    // PWG2 resonances
845    if (iPWG2res || iPWG2rsneff) {
846       if (!LoadLibrary("PWG2resonances", mode, kTRUE)) return kFALSE;
847    }   
848    // PWG2 kink
849    if (iPWG2kink) {
850       if (!LoadLibrary("PWG2kink", mode, kTRUE)) return kFALSE;
851    }   
852    // PWG2 unicor
853    if (iPWG2unicor) {
854       if (!LoadLibrary("PWG2unicor", mode, kTRUE)) return kFALSE;
855    }   
856    // PWG2 evchar
857    if (iPWG2evchar) {
858       if (!LoadLibrary("PWG2evchar", mode, kTRUE)) return kFALSE;
859    }   
860    // PWG2 femtoscopy
861    if (iPWG2femto) {
862       if (!LoadLibrary("PWG2AOD", mode, kTRUE) ||
863           !LoadLibrary("PWG2femtoscopy", mode, kTRUE) ||
864           !LoadLibrary("PWG2femtoscopyUser", mode, kTRUE)) return kFALSE;
865 //      TFile::Cp(gSystem->ExpandPathName("$(ALICE_ROOT)/PWG2/FEMTOSCOPY/macros/ConfigFemtoAnalysis.C"), Form("%s/ConfigFemtoAnalysis.C", train_name.Data()));
866 //      anaLibs += "ConfigFemtoAnalysis.C ";
867    }   
868    // PWG2 FORWARD
869    if (iPWG2forward) {
870       if (!LoadLibrary("PWG2forward", mode, kTRUE)) return kFALSE;
871    }   
872    // PWG3 Vertexing HF
873    if (iPWG3vertexing || iPWG3d2h) {
874       if (!LoadLibrary("PWG3base", mode, kTRUE) ||
875           !LoadLibrary("PWG3vertexingHF", mode, kTRUE)) return kFALSE;
876    }   
877    // PWG3 hfe
878    if (iPWG3hfe) {
879       if (!LoadLibrary("PWG3hfe", mode, kTRUE)) return kFALSE;
880    }   
881    
882    ::Info("AnalysisTrainNew.C::LoadAnalysisLibraries", "Load other libraries:   SUCCESS");
883    return kTRUE;
884 }
885
886 //______________________________________________________________________________
887 Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
888 {
889 // Load a module library in a given mode. Reports success.
890    Int_t imode = -1;
891    Int_t result;
892    TString smodule(module);
893    if (!strcmp(mode, "LOCAL")) imode = 0;
894    if (!strcmp(mode, "PROOF")) imode = 1;
895    if (!strcmp(mode, "GRID"))  imode = 2;
896    TString mod(module);
897    if (!mod.Length()) {
898       ::Error("AnalysisTrainNew.C::LoadLibrary", "Empty module name");
899       return kFALSE;
900    }   
901    // If a library is specified, just load it
902    if (smodule.EndsWith(".so")) {
903       mod.Remove(mod.Index(".so"));
904       result = gSystem->Load(mod);
905       if (result < 0) {
906          ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load library %s", module);
907          return kFALSE;
908       }
909       if (rec) anaLibs += Form("%s.so ",mod.Data()); 
910       return kTRUE;
911    } 
912    // Check if the library is already loaded
913    if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
914       return kTRUE;    
915    switch (imode) {
916       case 0:
917       case 2:
918          if (usePAR) {
919             result = SetupPar(module);
920             if (rec) anaPars += Form("%s.par ", module);
921          } else {
922             result = gSystem->Load(Form("lib%s.so", module));
923             if (rec) anaLibs += Form("lib%s.so ", module);
924          }   
925          break;
926       case 1:
927          result = gProof->UploadPackage(module);
928          if (result<0) {
929             result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
930             if (result<0) {
931                ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
932                return kFALSE;
933             }
934          }   
935          result = gProof->EnablePackage(module);
936          break;
937       default:
938          return kFALSE;
939    }         
940    if (result < 0) {
941       ::Error("AnalysisTrainNew.C::LoadLibrary", "Could not load module %s", module);
942       return kFALSE;
943    }
944    return kTRUE;
945 }           
946
947
948 //______________________________________________________________________________
949 TChain *CreateChain(const char *mode, const char *plugin_mode)
950 {
951 // Create the input chain
952    Int_t imode = -1;
953    if (!strcmp(mode, "LOCAL")) imode = 0;
954    if (!strcmp(mode, "PROOF")) imode = 1;
955    if (!strcmp(mode, "GRID"))  imode = 2;
956    TChain *chain = NULL;
957    // Local chain
958    switch (imode) {
959       case 0:
960          if (iAODanalysis) {
961             if (!local_xmldataset.Length()) {
962                // Local AOD
963                chain = new TChain("aodTree");
964                if (gSystem->AccessPathName("data/AliAOD.root")) 
965                   ::Error("AnalysisTrainNew.C::CreateChain", "File: AliAOD.root not in ./data dir");
966                else {
967                   if (!saveTrain) chain->Add("data/AliAOD.root");
968                   else            chain->Add("../data/AliAOD.root");
969                }   
970             } else {
971                // Interactive AOD
972                chain = CreateChainSingle(local_xmldataset, "aodTree");
973             }
974          } else {      
975             if (!local_xmldataset.Length()) {
976                // Local ESD
977                chain = new TChain("esdTree");
978                if (gSystem->AccessPathName("data/AliESDs.root")) 
979                   ::Error("AnalysisTrainNew.C::CreateChain", "File: AliESDs.root not in ./data dir");
980                else {
981                   if (!saveTrain) chain->Add("data/AliESDs.root");
982                   else            chain->Add("../data/AliESDs.root");
983                }   
984             } else {
985                // Interactive ESD
986                chain = CreateChainSingle(local_xmldataset, "esdTree");
987             }   
988          }
989          break;
990       case 1:
991          break;
992       case 2:
993          if (usePLUGIN) {
994 //            AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
995 //            AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
996          } else {
997             TString           treeName = "esdTree";
998             if (iAODanalysis) treeName = "aodTree";
999             chain = CreateChainSingle("wn.xml", treeName);
1000          }
1001          break;      
1002       default:   
1003    }
1004    if (chain && chain->GetNtrees()) return chain;
1005    return NULL;
1006 }   
1007
1008 //______________________________________________________________________________
1009 TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1010 {
1011    printf("*******************************\n");
1012    printf("*** Getting the ESD Chain   ***\n");
1013    printf("*******************************\n");
1014    TAlienCollection * myCollection  = TAlienCollection::Open(xmlfile);
1015
1016    if (!myCollection) {
1017       ::Error("AnalysisTrainNew.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1018       return NULL ;
1019    }
1020
1021    TChain* chain = new TChain(treeName);
1022    myCollection->Reset() ;
1023    while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1024    chain->ls();
1025    return chain;
1026 }
1027
1028 //______________________________________________________________________________
1029 Int_t SetupPar(char* pararchivename)
1030 {
1031    if (!pararchivename || !strlen(pararchivename)) return -1;
1032    char processline[1024];
1033    if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1034       if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1035          ::Info("AnalysisTrainNew.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
1036          TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)), 
1037                    Form("%s.par",pararchivename));
1038       } else {
1039          ::Error("AnalysisTrainNew.C::SetupPar", "Cannot find %s.par", pararchivename);
1040          return -1;
1041       }   
1042    }
1043    if (usePLUGIN && saveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, train_name.Data()));
1044    gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1045
1046    TString ocwd = gSystem->WorkingDirectory();
1047    if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1048         
1049    // check for BUILD.sh and execute
1050    if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1051       printf("*******************************\n");
1052       printf("*** Building PAR archive    ***\n");
1053       printf("*******************************\n");          
1054       if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1055          Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1056          return -1;
1057       }
1058    }
1059
1060         // check for SETUP.C and execute
1061         if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1062             printf("*******************************\n");
1063             printf("*** Setup PAR archive       ***\n");
1064             printf("*******************************\n");
1065             gROOT->Macro("PROOF-INF/SETUP.C");
1066         }       
1067         if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1068    return 0;
1069 }
1070
1071 //______________________________________________________________________________
1072 AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1073 {
1074 // Check if user has a valid token, otherwise make one. This has limitations.
1075 // One can always follow the standard procedure of calling alien-token-init then
1076 //   source /tmp/gclient_env_$UID in the current shell.
1077    if (!AliAnalysisGrid::CreateToken()) return NULL;
1078    AliAnalysisAlien *plugin = new AliAnalysisAlien();
1079 // Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1080    plugin->SetRunMode(plugin_mode);
1081    if (useProductionMode) plugin->SetProductionMode();
1082    plugin->SetJobTag(job_tag);
1083    plugin->SetNtestFiles(1);
1084 //   plugin->SetPreferedSE("ALICE::NIHAM::File");
1085 // Set versions of used packages
1086    plugin->SetAPIVersion("V2.4");
1087    plugin->SetROOTVersion(root_version);
1088    plugin->SetAliROOTVersion(aliroot_version);
1089 // Declare input data to be processed.
1090 // Method 1: Create automatically XML collections using alien 'find' command.
1091 // Define production directory LFN
1092    plugin->SetGridDataDir(alien_datadir);
1093 // Set data search pattern
1094    if (iAODanalysis) plugin->SetDataPattern("*AliAOD.root");
1095    else              plugin->SetDataPattern("*ESD.tag.root");
1096 // ...then add run numbers to be considered
1097    if (!iAODanalysis) plugin->SetRunRange(run_range[0], run_range[1]);
1098 //   for (Int_t i=0; i<10; i++) {
1099 //      if (run_numbers[i]==0) break;
1100 //      plugin->AddRunNumber(run_numbers[i]);
1101 //   }   
1102 // Method 2: Declare existing data files (raw collections, xml collections, root file)
1103 // If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1104 // XML collections added via this method can be combined with the first method if
1105 // the content is compatible (using or not tags)
1106 //   plugin->AddDataFile("tag.xml");
1107 //   plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1108 // Define alien work directory where all files will be copied. Relative to alien $HOME.
1109    if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
1110    else              plugin->SetGridWorkingDir("analysisESD");
1111 // Declare alien output directory. Relative to working directory.
1112    if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1113    plugin->SetGridOutputDir(alien_outdir);
1114
1115    TString ana_sources = "";
1116    TString ana_add = "";
1117    if (usePAR && anaPars.Length()) {
1118       printf("%s\n", anaPars.Data());
1119       TObjArray *arr;
1120       TObjString *objstr;
1121       arr = anaPars.Tokenize(" ");
1122       TIter next(arr);
1123       while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1124       delete arr;
1125    } 
1126    
1127 // Declare the analysis source files names separated by blancs. To be compiled runtime
1128 // using ACLiC on the worker nodes.
1129    ana_sources = ana_sources.Strip();
1130 // Declare all libraries (other than the default ones for the framework. These will be
1131 // loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1132    anaLibs     = anaLibs.Strip();   
1133    if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1134    if (anaLibs.Length())     plugin->SetAdditionalLibs(anaLibs);
1135      
1136 // Declare the output file names separated by blancs.
1137 // (can be like: file.root or file.root@ALICE::Niham::File)
1138    plugin->SetDefaultOutputs();
1139    plugin->SetMergeExcludes(mergeExclude);
1140    plugin->SetMaxMergeFiles(maxMergeFiles);
1141    plugin->SetNrunsPerMaster(nRunsPerMaster);
1142 // Optionally define the files to be archived.
1143 //   plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
1144    
1145    
1146    // Put default output files to archive
1147    TString listhists = "";
1148    TString listaods  = "";
1149    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1150    TIter next(mgr->GetOutputs());
1151    AliAnalysisDataContainer *output;
1152    while ((output=(AliAnalysisDataContainer*)next())) {
1153       const char *filename = output->GetFileName();
1154       if (!(strcmp(filename, "default"))) {
1155          if (!mgr->GetOutputEventHandler()) continue;
1156          filename = mgr->GetOutputEventHandler()->GetOutputFileName();
1157          if (listaods.Length()) listaods += ",";
1158          listaods += filename;
1159       } else {
1160          if (listhists.Contains(filename)) continue;
1161          if (listhists.Length()) listhists += ",";
1162          listhists += filename;
1163       }
1164    }
1165    if (mgr->GetExtraFiles().Length()) {
1166       if (listaods.Length()) listaods += ",";
1167       listaods += mgr->GetExtraFiles();
1168       listaods.ReplaceAll(" ", ",");
1169    }
1170    if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), outputStorages.Data());;
1171    if (listaods.Length())  listaods  = Form("aod_archive.zip:%s@%s", listaods.Data(), outputStorages.Data());;
1172    if (!listhists.Length() && !listaods.Length()) {
1173       ::Fatal("AnalysisTrainNew", "No task output !");
1174    }
1175    TString outputArchive = "log_archive.zip:stdout,stderr@ALICE::CERN::SE";
1176    if (listaods.Length()) {
1177       outputArchive += " ";
1178       outputArchive += listaods;
1179    }   
1180    if (listhists.Length()) {
1181       outputArchive += " ";
1182       outputArchive += listhists;
1183    }   
1184 // Set friends
1185 //   if (iAODanalysis && iPWG3d2h) 
1186 //      plugin->SetFriendChainName("AliAOD.VertexingHF.root");
1187    plugin->SetOutputArchive(outputArchive);
1188 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1189    plugin->SetAnalysisMacro(Form("%s.C", train_name.Data()));
1190 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1191    plugin->SetSplitMaxInputFileNumber(nFilesPerJob);
1192 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1193 //   plugin->SetMaxInitFailed(5);
1194 // Optionally resubmit threshold.
1195 //   plugin->SetMasterResubmitThreshold(90);
1196 // Optionally set time to live (default 30000 sec)
1197    plugin->SetTTL(200000);
1198 // Optionally set input format (default xml-single)
1199    plugin->SetInputFormat("xml-single");
1200 // Optionally modify the name of the generated JDL (default analysis.jdl)
1201    plugin->SetJDLName(Form("%s.jdl", train_name.Data()));
1202 // Optionally modify the executable name (default analysis.sh)
1203    plugin->SetExecutable(Form("%s.sh", train_name.Data()));
1204 // Optionally modify job price (default 1)
1205    plugin->SetPrice(1);      
1206 // Optionally modify split mode (default 'se')    
1207    plugin->SetSplitMode("se");
1208    return plugin;
1209 }
1210
1211 //______________________________________________________________________________
1212 void WriteConfig()
1213 {
1214 // Write train configuration in a file. The file name has the format:
1215 // train_[trainName]_ddMonthyyyy_time.C
1216    if (useDATE) {
1217       gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1218       ifstream fdate("date.tmp");
1219       if (!fdate.is_open()) {
1220          ::Error("AnalysisTrainNew.C::Export","Could not generate file name");
1221          return;
1222       }
1223       const char date[64];
1224       fdate.getline(date,64);
1225       fdate.close();
1226       gSystem->Exec("rm date.tmp");
1227       train_name = Form("train_%s_%s", train_name.Data(), date);
1228    } else {
1229       train_name = Form("train_%s", train_name.Data());
1230    }   
1231    TString cdir = gSystem->WorkingDirectory();
1232    gSystem->MakeDirectory(train_name);
1233    gSystem->ChangeDirectory(train_name);
1234    ofstream out;
1235    out.open(Form("%sConfig.C",train_name.Data()), ios::out); 
1236    if (out.bad()) {
1237       ::Error("AnalysisTrainNew.C::Export", "Cannot open ConfigTrain.C for writing");
1238       return;
1239    }
1240    out << "{" << endl;
1241    out << "   train_name      = " << "\"" << train_name.Data() << "\";" << endl;
1242    out << "   proof_cluster   = " << "\"" << proof_cluster.Data() << "\";" << endl;
1243    out << "   useAFPAR        = " << useAFPAR << ";" << endl;
1244    if (useAFPAR) 
1245       out << "   AFversion       = " << AFversion.Data() << ";" << endl;
1246    out << "   proof_dataset   = " << "\"" << proof_dataset.Data() << "\";" << endl;
1247    out << "   usePLUGIN       = " << usePLUGIN << ";" << endl;
1248    out << "   usePAR          = " << usePAR << ";" << endl;
1249    out << "   useCPAR         = " << useCPAR << ";" << endl;
1250    out << "   root_version    = " << "\"" << root_version.Data() << "\";" << endl;
1251    out << "   aliroot_version = " << "\"" << aliroot_version.Data() << "\";" << endl;
1252    out << "   alien_datadir   = " << "\"" << alien_datadir.Data() << "\";" << endl;
1253    if (!alien_outdir.Length()) alien_outdir = Form("output_%s",train_name.Data());
1254    out << "   alien_outdir    = " << "\"" << alien_outdir.Data() << "\";" << endl;
1255    out << "   maxMergeFiles   = " << maxMergeFiles << ";" << endl;
1256    out << "   mergeExclude    = " << "\"" << mergeExclude.Data() << "\";" << endl;
1257    out << "   nRunsPerMaster  = " << nRunsPerMaster << ";" << endl;
1258    out << "   nFilesPerJob    = " << nFilesPerJob << ";" << endl;
1259 //   for (Int_t i=0; i<10; i++) {
1260 //      if (run_numbers[i]) 
1261 //         out << "   run_numbers[" << i << "]  = " << run_numbers[i] << ";" << endl;
1262 //   }
1263    out << "   run_range[0]    = " << run_range[0] << ";" << endl;
1264    out << "   run_range[1]    = " << run_range[1] << ";" << endl;
1265    out << "   useDBG          = " << useDBG << ";" << endl;
1266    out << "   useMC           = " << useMC << ";" << endl;
1267    out << "   useTAGS         = " << useTAGS << ";" << endl;
1268    out << "   useKFILTER      = " << useKFILTER << ";" << endl;
1269    out << "   useTR           = " << useTR << ";" << endl;
1270    out << "   useCORRFW       = " << useCORRFW << ";" << endl;
1271    out << "   useAODTAGS      = " << useAODTAGS << ";" << endl;
1272    out << "   saveTrain       = " << "kFALSE;" << endl << endl;
1273    out << "   // Analysis modules" << endl;
1274    out << "   iAODanalysis    = " << iAODanalysis << ";" << endl;
1275    out << "   iAODhandler     = " << iAODhandler << ";" << endl;
1276    out << "   iESDfilter      = " << iESDfilter << ";" << endl;
1277    out << "   iMUONcopyAOD    = " << iMUONcopyAOD << ";" << endl;
1278    out << "   iJETAN          = " << iJETAN << ";" << endl;
1279    out << "   iPWG4partcorr   = " << iPWG4partcorr << ";" << endl;
1280    out << "   iPWG4gammaconv  = " << iPWG4gammaconv << ";" << endl;
1281    out << "   iPWG4omega3pi   = " << iPWG4omega3pi << ";" << endl;
1282    out << "   iPWG3vertexing  = " << iPWG3vertexing << ";" << endl;   
1283    out << "   iPWG3hfe        = " << iPWG3hfe << ";" << endl;   
1284    out << "   iPWG3d2h        = " << iPWG3d2h << ";" << endl;   
1285    out << "   iPWG2femto      = " << iPWG2femto << ";" << endl;
1286    out << "   iPWG2spectra    = " << iPWG2spectra << ";" << endl;
1287    out << "     iPWG2protons      = " << iPWG2protons << ";" << endl;
1288    out << "     iPWG2checkcascade = " << iPWG2checkcascade << ";" << endl;
1289    out << "     iPWG2perfcascade  = " << iPWG2perfcascade << ";" << endl;
1290    out << "     iPWG2checkv0      = " << iPWG2checkv0 << ";" << endl;
1291    out << "     iPWG2strange      = " << iPWG2strange << ";" << endl;
1292    out << "   iPWG2flow       = " << iPWG2flow << ";" << endl;
1293    out << "   iPWG2res        = " << iPWG2res << ";" << endl;
1294    out << "     iPWG2rsneff   = " << iPWG2rsneff << ";" << endl;
1295    out << "   iPWG2kink       = " << iPWG2kink << ";" << endl;
1296    out << "     iPWG2kinkESDMC    = " << iPWG2kinkESDMC << ";" << endl;
1297    out << "     iPWG2kinklikesign = " << iPWG2kinklikesign << ";" << endl;
1298    out << "     iPWG2kinkKstarESD = " << iPWG2kinkKstarESD << ";" << endl;
1299    out << "     iPWG2kinkKstarMC  = " << iPWG2kinkKstarMC << ";" << endl;
1300    out << "     iPWG2kinkL1520ESD = " << iPWG2kinkL1520ESD << ";" << endl;
1301    out << "     iPWG2kinkL1520MC  = " << iPWG2kinkL1520MC << ";" << endl;
1302    out << "     iPWG2kinkPhiESD   = " << iPWG2kinkPhiESD << ";" << endl;
1303    out << "     iPWG2kinkPhiMC    = " << iPWG2kinkPhiMC << ";" << endl;
1304    out << "   iPWG2unicor     = " << iPWG2unicor << ";" << endl;
1305    out << "   iPWG2evchar     = " << iPWG2evchar << ";" << endl;
1306    out << "   iPWG2forward    = " << iPWG2forward << ";" << endl << endl;
1307    out << "// Configuration fot the wagons" << endl;
1308    out << "   configPWG2femto = \"" << configPWG2femto << "\";" << endl;
1309    out << "   configPWG3d2h   = \"" << configPWG3d2h << "\";" << endl;
1310    out << "}" << endl;
1311    ::Info("AnalysisTrainNew.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", train_name.Data()));
1312    gSystem->ChangeDirectory(cdir);
1313 }   
1314
1315 //______________________________________________________________________________
1316 Bool_t LoadConfig(const char *filename)
1317 {
1318 // Read train configuration from file
1319    if (gSystem->AccessPathName(filename)) {
1320       ::Error("AnalysisTrainNew.C::LoadConfig", "Config file name not found");
1321       return kFALSE;
1322    }   
1323    gROOT->ProcessLine(Form(".x %s", filename));
1324    ::Info("AnalysisTrainNew.C::LoadConfig", "Train configuration loaded from file %s", filename);
1325    return kTRUE;
1326 }