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