Changed directroy naming for common out output
[u/mrichter/AliRoot.git] / PWG4 / macros / AnalysisTrainPWG4Jets.C
CommitLineData
c38e3b95 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)
121e4bd5 6// root[1] AnalysisTrainPWG-244Jets("grid", "full")
c38e3b95 7// CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
8// root[2] AnalysisTrainPWG4Jets("proof")
9// Local mode requires AliESds.root or AliAOD.root in ./data directory
10// root[3] AnalysisTrainPWG4Jets("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] AnalysisTrainPWG4Jets(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")
17
18// For Usage with fastjet run in "offline" first and then "submit"
19// jdl and analysismacro are automatically patched after "offline" mode
20
21// =============================================================================
22// ### General Steering variables
23// =============================================================================
24//== general setup variables
25TString kTrainName = "testAnalysis"; // *CHANGE ME* (no blancs or special characters)
26TString kJobTag = "PWG4 Jet Tasks analysis train configured"; // *CHANGE ME*
27
28// Usage of par files ONLY in grid mode and ONLY if the code is not available
29// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
30// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in
31// AliRoot.
32Bool_t kUsePAR = kFALSE; // use par files for extra libs
33Bool_t kUseCPAR = kFALSE; // use par files for common libs
34Bool_t kFillAOD = kFALSE; // switch of AOD filling for on the fly analysis
35
36//== general input and output variables
37Int_t iAODanalysis = 1; // Analysis on input AOD's
38Int_t iAODhandler = 1; // Analysis produces an AOD or dAOD's
39Int_t iESDfilter = 0; // ESD to AOD filter (barrel + muon tracks)
e84da0a5 40Int_t iPhysicsSelection = 1; // ESD to AOD filter (barrel + muon tracks)
c38e3b95 41Bool_t kUseKinefilter = kFALSE; // use Kinematics filter
42Bool_t kUseMuonfilter = kFALSE; // use Kinematics filter
43TString kCommonOutputFileName = "PWG4_JetTasksOutput.root";
44
45
46//== general process variables
47
48// ### Other flags to steer the analysis
49//==============================================================================
50Bool_t kUseDate = kFALSE; // use date in train name
51Bool_t kUseDebug = kTRUE; // activate debugging
c28abe00 52Int_t kUseSysInfo = 0; // activate debugging
c38e3b95 53Bool_t kUseMC = kTRUE; // use MC info
54Bool_t kIsMC = kTRUE; // is MC info, if false it overwrites Use(AOD)MC
55Bool_t kUseAODMC = kTRUE; // use MC infA
56Bool_t kUseESDTags = kFALSE; // use ESD tags for selection
57Bool_t kUseTR = kFALSE; // use track references
58Bool_t kUseAODTags = kFALSE; // use AOD tags
59Bool_t kSaveTrain = kFALSE; // save train configuration as:
60
61// ### Analysis modules to be included. Some may not be yet fully implemented.
62//==============================================================================
63Int_t iJETAN = 1; // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets, 3 wrtie both
64Int_t iDIJETAN = 1;
e6993a52 65Int_t iJETANLib = 1;
c38e3b95 66Int_t iPWG1QASym = 0; // Eva's QA task compiled on the fly...
67Int_t iPWG4JetTasks = 0; // all jet tasks flag for lib laoding
68Int_t iPWG4JetServices = 0; // jet spectrum analysis
69Int_t iPWG4JetSpectrum = 0; // jet spectrum analysis
70Int_t iPWG4UE = 0; // Underlying Event analysis
121e4bd5 71Int_t iPWG4TmpSourceSara = 0; // Underlying Event analysis
c38e3b95 72Int_t iPWG4PtQAMC = 0; // Marta's QA tasks
73Int_t iPWG4PtSpectra = 0; // Marta's QA tasks
74Int_t iPWG4PtQATPC = 0; // Marta's QA tasks
75Int_t iPWG4ThreeJets = 0; // Sona's thrust task
b53f2e4f 76Int_t iPWG4KMeans = 0; // Andreas' KMeans task
c38e3b95 77Int_t iPWG4PartCorr = 0; // Gustavo's part corr analysis
121e4bd5 78Int_t iPWG4omega3pi = 0; // Omega to 3 pi analysis (PWG4)
53c63663 79Int_t iPWG4GammaConv = 0; // Gamma Conversio
c38e3b95 80Int_t kHighPtFilterMask = 16; // change depending on the used AOD Filter
e6993a52 81TString kDeltaAODJetName = "AliAOD.Jets.root";
53c63663 82TString kDeltaAODPartCorrName = "deltaAODPartCorr.root";
c38e3b95 83
84
85//==============================================================================
86// ### PROOF Steering varibales
87//==============================================================================
88//== proof setup variables
89TString kProofCluster = "alicecaf.cern.ch";
90Bool_t kProofUseAFPAR = kFALSE; // use AF special par file
91TString kProofAFversion = "AF-v4-17";
92//== proof input and output variables
93TString kProofDataSet = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
94Bool_t kProofSaveToAlien = kFALSE; // save proof outputs in AliEn train_[trainName]_ddMonthyyyy_time.C
95TString kProofOutdir = "";
96Bool_t kProofClearPackages = kFALSE;
97Int_t kProofEvents = 10000;
98Int_t kProofOffset = 0;
99//== proof process variables
100
101
102//==============================================================================
103// ### Grid plugin Steering varibiables
104//==============================================================================
105//== grid plugin setup variables
106Bool_t kPluginUse = kTRUE; // do not change
107Bool_t kPluginUseProductionMode = kFALSE; // use the plugin in production mode
e84da0a5 108TString kPluginRootVersion = "v5-25-04-3"; // *CHANGE ME IF MORE RECENT IN GRID*
121e4bd5 109TString kPluginAliRootVersion = "v4-18-15-AN"; // *CHANGE ME IF MORE RECENT IN GRID*
c38e3b95 110// TString kPluginExecutableCommand = "root -b -q";
111TString kPluginExecutableCommand = "source /Users/kleinb/setup_32bit_aliroot_trunk_clean_root_trunk.sh; alienroot -b -q ";
112// == grid plugin input and output variables
113TString kGridDatadir = "/alice/sim/PDC_08b/LHC09a1/AOD/";
114TString kGridLocalRunList = "";
115TString kGridOutdir = ""; // AliEn output directory. If blank will become output_<kTrainName>
116Int_t kGridRunRange[2] = {0, -1}; // Set the run range
117TString kGridRunPattern = "%03d"; // important for leading zeroes!!
118TString kGridPassPattern = "";
119TString kGridExtraFiles = ""; // files that will be added to the input list in the JDL...
120Int_t kGridMaxMergeFiles = 50; // Number of files merged in a chunkgridrunragn
121TString kGridMergeExclude = "AliAOD.root"; // Files that should not be merged
122TString kGridOutputStorages = "ALICE::NIHAM::File,ALICE::CNAF::SE,ALICE::FZK::SE,ALICE::GSI::SE,ALICE::Legnaro::SE"; // Make replicas on the storages
123// == grid process variables
c28abe00 124Int_t kGridRunsPerMaster = 100; // Number of runs per master job
e84da0a5 125Int_t kGridFilesPerJob = 100; // Maximum number of files per job (gives size of AOD)
c38e3b95 126
127//==============================================================================
128// ### Local Steering variables
129//==============================================================================
130//== local setup variables
131//== local input and output variables
132TString kLocalXMLDataset = ""; // Change local xml dataset for local interactive analysis
133TString kLocalDataList = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
134// == local process variables
135
136
137
138// Temporaries.
139TString anaPars = "";
140TString anaLibs = "";
e84da0a5 141TString anaLibsExtra = "";
c38e3b95 142TString anaSources = "";
143// Function signatures
144class AliAnalysisAlien;
145
146//______________________________________________________________________________
147void AnalysisTrainPWG4Jets(const char *analysis_mode="local",
148 const char *plugin_mode="",
149 const char *config_file="",Int_t iOffset = 0)
150{
151// Main analysis train macro. If a configuration file is provided, all parameters
152// are taken from there but may be altered by CheckModuleFlags.
153 if (strlen(config_file) && !LoadConfig(config_file)) return;
154 if(iOffset)kProofOffset = iOffset;
155 TString smode(analysis_mode);
156 smode.ToUpper();
157 if (kSaveTrain)WriteConfig();
158 // Check compatibility of selected modules
159 CheckModuleFlags(smode);
e84da0a5 160 // gROOT->ProcessLine(".trace");
c38e3b95 161
162 printf("==================================================================\n");
163 printf("=========== RUNNING ANALYSIS TRAIN %s IN %s MODE ==========\n", kTrainName.Data(),smode.Data());
164 printf("==================================================================\n");
165 printf("= Configuring analysis train for: =\n");
166 if (iAODanalysis) printf("= AOD analysis =\n");
167 else printf("= ESD analysis =\n");
e84da0a5 168 if (iPhysicsSelection) printf("= Physics selection =\n");
c38e3b95 169 if (iESDfilter) printf("= ESD filter =\n");
170 if (iJETAN) printf("= Jet analysis =\n");
171 printf("==================================================================\n");
172 printf(":: use MC truth %d\n", (UInt_t)kUseMC);
173 printf(":: use KINE filter %d\n", (UInt_t)kUseKinefilter);
174 printf(":: use track refs %d\n", (UInt_t)kUseTR);
175 printf(":: use tags %d\n", (UInt_t)kUseESDTags);
176 printf(":: use AOD tags %d\n", (UInt_t)kUseAODTags);
177 printf(":: use debugging %d\n", (UInt_t)kUseDebug);
178 printf(":: use PAR files %d\n", (UInt_t)kUsePAR);
179 printf(":: use AliEn plugin %d\n", (UInt_t)kPluginUse);
53c63663 180 printf(":: use PWG1 QA sym %d\n", iPWG1QASym);
121e4bd5 181 printf(":: use PWG4 Source Sara %d\n",iPWG4TmpSourceSara);
53c63663 182 printf(":: use PWG4 Jet tasks %d\n",iPWG4JetTasks);
183 printf(":: use PWG4 Jet Services %d\n",iPWG4JetServices);
184 printf(":: use PWG4 Jet Spectrum %d\n",iPWG4JetSpectrum);
185 printf(":: use PWG4 UE %d \n",iPWG4UE);
186 printf(":: use PWG4 Pt QA MC %d\n",iPWG4PtQAMC);
187 printf(":: use PWG4 Pt Spectra %d\n",iPWG4PtSpectra);
188 printf(":: use PWG4 Pt QA TPC %d\n",iPWG4PtQATPC);
189 printf(":: use PWG4 Three Jets %d\n",iPWG4ThreeJets);
b53f2e4f 190 printf(":: use PWG4 KMeans %d\n",iPWG4KMeans);
53c63663 191 printf(":: use PWG4 Part Corr %d\n",iPWG4PartCorr);
121e4bd5 192 printf(":: use PWG4 omega to 3 pions %d\n",iPWG4omega3pi);
193
53c63663 194 printf(":: use PWG4 Gamma Conv %d\n",iPWG4GammaConv);
195 printf(":: use HighPt FilterMask %d\n",kHighPtFilterMask);
196
c38e3b95 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
e84da0a5 212 AliAnalysisManager *mgr = new AliAnalysisManager("PWG4Train", "pwg4 mini train");
c38e3b95 213 if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
214 if (kProofSaveToAlien) mgr->SetSpecialOutputLocation(kProofOutdir);
215 if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
53c63663 216 if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
c38e3b95 217 // Load analysis specific libraries
218 if (!LoadAnalysisLibraries(smode)) {
219 ::Error("AnalysisTrain", "Could not load analysis libraries");
220 return;
221 }
222
223 // Create input handler (input container created automatically)
224 if (iAODanalysis) {
225 // AOD input handler
226 AliAODInputHandler *aodH = new AliAODInputHandler();
227 mgr->SetInputEventHandler(aodH);
e6993a52 228 if (iPWG4JetTasks) aodH->AddFriend(Form("deltas/%s",kDeltaAODJetName.Data()));
229 if (iPWG4PartCorr) aodH->AddFriend(Form("deltas/%s"kDeltaAODJetName.Data()));
c38e3b95 230 } else {
231 // ESD input handler
232 AliESDInputHandler *esdHandler = new AliESDInputHandler();
233 if (kUseESDTags) esdHandler->SetReadTags();
234 mgr->SetInputEventHandler(esdHandler);
235 }
236 // Monte Carlo handler
237 if (kUseMC && !iAODanalysis) {
238 AliMCEventHandler* mcHandler = new AliMCEventHandler();
239 mgr->SetMCtruthEventHandler(mcHandler);
240 mcHandler->SetReadTR(kUseTR);
241 }
242 // AOD output container, created automatically when setting an AOD handler
243 if (iAODhandler) {
244 // AOD output handler
245 AliAODHandler* aodHandler = new AliAODHandler();
246 aodHandler->SetOutputFileName("AliAOD.root");
247 aodHandler->SetFillAOD(kFillAOD);
248
249 mgr->SetOutputEventHandler(aodHandler);
121e4bd5 250 //
c38e3b95 251 if (iAODanalysis) {
252
253 // aodHandler->SetCreateNonStandardAOD();
254 // if (iJETAN)aodHandler->SetOutputFileName(kDeltaAODJetName.Data());
255 }
256 AliAnalysisDataContainer * cout_aod = mgr->GetCommonOutputContainer();
257 cout_aod->SetSpecialOutput();
258 }
259 // Debugging if needed
260 if (kUseDebug) mgr->SetDebugLevel(3);
261
262 //==========================================================================
263 // Create the chain. In this example it is created only from ALIEN files but
264 // can be done to work in batch or grid mode as well.
265 TChain *chain = CreateChain(smode, plugin_mode);
266
267 //==========================================================================
268 // Load the tasks configuration macros for all wagons. These files are supposed now to be
269 // in the current workdir, but in AliEn they will be in the file catalog,
270 // mapped from AliRoot and pecified in the jdl input list.
271
272 // For now connection to top input container and common AOD output container
273 // is done in this macro, but in future these containers will be connected
274 // from each task configuration macro.
275
e84da0a5 276 if(iPhysicsSelection && !iAODanalysis){
277 gROOT->LoadMacro("$ALICE_ROOT/PWG1/PilotTrain/AddTaskPhysicsSelection.C");
b2d64ef3 278 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kTRUE);
e84da0a5 279 if(kIsMC)physSelTask->GetPhysicsSelection()->SetAnalyzeMC();
280 physSelTask->GetPhysicsSelection()->AddBackgroundIdentification(new AliBackgroundSelection());
281 }
282
c38e3b95 283 if (iESDfilter && !iAODanalysis) {
284 // ESD filter task configuration.
285 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
286 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
287 }
288
289 // AOD tags
290 if (kUseAODTags) {
291 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
292 mgr->AddTask(tagTask);
293 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
294 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
295 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
296 mgr->ConnectOutput(tagTask, 1, coutTags);
297 }
298
299 // Jet analysis
300 if (iJETAN) {
301 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
302 AliAnalysisTaskJets *taskjets = 0;
303 if(iJETAN&1)taskjets = AddTaskJets(kHighPtFilterMask);
b53f2e4f 304 if(iJETAN&2){
305 UInt_t selection = 0;
306 if(!kFillAOD) selection = 0xffffff;
307 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9;
308 AddTaskJetsDelta(kDeltaAODJetName.Data(),kHighPtFilterMask,kUseAODMC,selection);
309 }
c38e3b95 310 if (!taskjets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
311 }
312
313 if (iDIJETAN) {
314 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskDiJets.C");
315 AliAnalysisTaskDiJets *taskdijets = 0;
316 taskdijets = AddTaskDiJets();
317 if (!taskdijets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
318 }
319
320
321 if(iPWG1QASym){
322 gROOT->LoadMacro("$ALICE_ROOT/prod/acrcaf/qa_pp/AddTaskQAsym.C");
323 AliAnalysisTaskQASym *taskQASym = AddTaskQAsym(-1);
324 if (!taskQASym) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQASym cannot run for this train conditions - EXCLUDED");
121e4bd5 325 }
c38e3b95 326
121e4bd5 327
328
329 if(iPWG4TmpSourceSara){
330 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskEta.C");
331 AliAnalysisTaskEta *taskEta = AddTaskEta();
332 if (!taskEta) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskEta cannot run for this train conditions - EXCLUDED");
c38e3b95 333 }
334
121e4bd5 335
c38e3b95 336 if(iPWG4JetServices){
337 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
338 AliAnalysisTaskJetServices *taskjetServ = 0;
339 taskjetServ = AddTaskJetServices();
340 if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
53c63663 341 if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
342 else taskjetServ->SetRunRange(104000,105000);
c28abe00 343 if(!kIsMC) taskjetServ->SetRealData(kTRUE);
b53f2e4f 344 if(!iPhysicsSelection)taskjetServ->SetUsePhysicsSelection(kFALSE);
c38e3b95 345 }
346
347
348 if(iPWG4JetSpectrum){
349 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
350 AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
b53f2e4f 351 if(iPWG4JetSpectrum&1){
352 taskjetSpectrum = AddTaskJetSpectrum2("jets","",kHighPtFilterMask,iPhysicsSelection);
e6993a52 353 if(!iAODanalysis){
354 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection); // tmp hack to give it a different name
355 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);
356 }
b53f2e4f 357 }
c38e3b95 358 if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
e6993a52 359 if(iPWG4JetSpectrum&2){
360 UInt_t selection = 0;
361 if(!iAODanalysis) selection = 0xffffff;
362 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
363 AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
364 }
365 if(iJETAN&3&&!kFillAOD&!iAODanalysis){
b53f2e4f 366 AddTaskJetSpectrum2("jetsAOD_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
367 AddTaskJetSpectrum2("jetsAOD_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
368 AddTaskJetSpectrum2("jetsAOD_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
369 AddTaskJetSpectrum2("jetsAOD_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
370 }
c38e3b95 371 if(kUseMC)taskjetSpectrum->SetAnalysisType( AliAnalysisTaskJetSpectrum2::kAnaMCESD);
e6993a52 372 taskjetSpectrum->SetDebugLevel(0);
c38e3b95 373 }
374
375 if(iPWG4UE){
376 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
377 AliAnalysisTaskUE *taskUE = 0;
378 if(iPWG4UE&1)taskUE = AddTaskUE();
379 if(iPWG4UE&2){
2bb1f4ca 380 taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV");
381 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","LJ","TRANSV");
382 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","BB","TRANSV");
383 taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV");
384 taskUE = AddTaskUE("jetsAOD_FASTJET04","CDF","LJ","TRANSV");
385 taskUE = AddTaskUE("jetsAOD_SISCONE04","CDF","LJ","TRANSV");
386
c38e3b95 387 }
2bb1f4ca 388
c38e3b95 389 if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
390 }
391
392 if(iPWG4ThreeJets){
393 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
394 AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
395 if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
396 }
397
398 if(iPWG4PtQAMC){
399 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
400 AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
401 if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
402 }
403
404 if(iPWG4PtQATPC){
405 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
406 AliPWG4HighPtQATPConly *taskQATPC = AddTaskPWG4HighPtQATPConly();
407 if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
408 }
409
410 if(iPWG4PtSpectra){
411 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
412 AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
413 if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
414 }
415
b53f2e4f 416 if(iPWG4KMeans){
417 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
418 AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
419 if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
420 }
421
c38e3b95 422 if(iPWG4PartCorr){
423 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
424 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kUseMC,kFALSE,kIsMC);
425 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
426 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kUseMC,kFALSE,kIsMC);
427 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
428 if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data()); // hmm this is written anyway.... but at least we do not register it...
121e4bd5 429 }
430
431 if (iPWG4omega3pi) {
432 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
433 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
434 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
435 for these train conditions - EXCLUDED");
436 }
437
c38e3b95 438
53c63663 439 // PWG4 gamma conversion analysis
440 if (iPWG4GammaConv) {
441 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
442 TString cdir = gSystem->WorkingDirectory();
443 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
444 // TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
b53f2e4f 445 TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz -bg-off";
53c63663 446 if(!kIsMC)gcArguments += " -mc-off";
447 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
448 gSystem->ChangeDirectory(cdir);
121e4bd5 449 taskGammaConversion->SelectCollisionCandidates();
53c63663 450 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
451 }
452
c38e3b95 453 //==========================================================================
454 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
455 // Run the analysis
456 //
457 if (kPluginUse) {
458 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
459 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
460 }
461
462 if (mgr->InitAnalysis()) {
463 mgr->PrintStatus();
464 // if (kSaveTrain || strlen(config_file)) gSystem->ChangeDirectory(kTrainName);
e84da0a5 465 if (!strcmp(plugin_mode,"submit")&&smode=="GRID"){
c38e3b95 466 TString alien_workdir = gGrid->GetHomeDirectory();
467 if (iAODanalysis) alien_workdir += "analysisAOD";
468 else alien_workdir += "analysisESD";
469 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
e84da0a5 470 printf("=== AnalysisTrainPWG4Jets:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
c38e3b95 471 alien_workdir.Data(),gridhandler->GetGridOutputDir());
472 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()), Form("alien://%s/%s/%s.jdl",alien_workdir.Data(),
473 gridhandler->GetGridOutputDir(),kTrainName.Data()));
474 }
475
476 StartAnalysis(smode, chain);
477 if (!strcmp(plugin_mode, "offline")&&smode=="GRID"){
e84da0a5 478 // Offline mode path files
479 // PatchJDL();
480 PatchAnalysisMacro();
481 }
c38e3b95 482
e84da0a5 483 if (kSaveTrain && smode=="GRID") {
484 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
485 TString alien_workdir = gGrid->GetHomeDirectory();
486 if (iAODanalysis) alien_workdir += "analysisAOD";
c38e3b95 487 else alien_workdir += "analysisESD";
e84da0a5 488 // kGridOutdir = gridhandler->GetGridOutputDir();
489 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
c38e3b95 490 alien_workdir.Data());
e84da0a5 491 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data())))
492 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
493 if (strcmp(plugin_mode, "test"))
494 TFile::Cp(Form("file:%sConfig.C",kTrainName.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
495 }
496 }
c38e3b95 497}
498
499//______________________________________________________________________________
500void StartAnalysis(const char *mode, TChain *chain) {
501// Start analysis.
502 Int_t imode = -1;
503 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
504 if (!strcmp(mode, "LOCAL")) imode = 0;
505 if (!strcmp(mode, "PROOF")) imode = 1;
506 if (!strcmp(mode, "GRID")) imode = 2;
507 switch (imode) {
508 case 0:
509 if (!chain) {
510 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
511 return;
512 }
513 mgr->StartAnalysis(mode, chain);
514 return;
515 case 1:
516 if (!kProofDataSet.Length()) {
517 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "kProofDataSet is empty");
518 return;
519 }
520 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
521 return;
522 case 2:
523 if (kPluginUse) {
524 if (!mgr->GetGridHandler()) {
525 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Grid plugin not initialized");
526 return;
527 }
528 mgr->StartAnalysis("grid");
529 } else {
530 if (!chain) {
531 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
532 return;
533 }
534 mgr->StartAnalysis(mode, chain);
535 }
536 return;
537 }
538}
539
540//______________________________________________________________________________
541void CheckModuleFlags(const char *mode) {
542// Checks selected modules and insure compatibility
543 Int_t imode = -1;
544 if (!strcmp(mode, "LOCAL")) imode = 0;
545 if (!strcmp(mode, "PROOF")) imode = 1;
546 if (!strcmp(mode, "GRID")) imode = 2;
547
548
e84da0a5 549 if (kUseCPAR) {
550 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
551 }
c38e3b95 552
553 if (imode==1) {
554 if (!kUsePAR) {
555 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
556 kUsePAR = kTRUE;
557 }
558 }
559 if (imode != 2) {
560 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
561 kPluginUse = kFALSE;
562 }
563
564
565 if(!kIsMC){
566 // switch off anthin related to MC
567 kUseMC = 0;
568 kUseAODMC = 0;
569 kUseTR = kFALSE;
570 }
571
572 if (iAODanalysis) {
573 // AOD analysis
574 if (kUseMC)
575 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
576 if (kUseAODTags)
577 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
578 kUseMC = kFALSE;
579 kUseTR = kFALSE;
580 kUseAODTags = kFALSE;
581 if (iESDfilter)
582 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
583 iESDfilter = 0;
e84da0a5 584 if (iPhysicsSelection)
585 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "Physics Selection disabled in analysis on AOD's");
586 iPhysicsSelection = 0;
c38e3b95 587 if (!iAODhandler) {
588 if (iJETAN)
589 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
590 iJETAN = 0;
591 iDIJETAN = 0;
592 }
593 // Disable tasks that do not work yet on AOD data
594 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
595 iPWG4PtQAMC = 0;
596 if( iPWG4PtQATPC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtTPC disabled in analysis on AOD's");
597 iPWG4PtQATPC = 0;
598 if( iPWG4PtSpectra)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
599 iPWG4PtSpectra = 0;
b53f2e4f 600 if(iPWG4KMeans)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4KMeans disabled on AOD's");
601 iPWG4KMeans = 0;
c38e3b95 602 if (iPWG4PartCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
603 iPWG4PartCorr = 0;
121e4bd5 604 if (iPWG4omega3pi)
605 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
606 iPWG4omega3pi = 0;
c38e3b95 607 if(iPWG1QASym)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG1 QA Sym disabled in analysis on AOD's");
53c63663 608 if (iPWG4GammaConv)::Info("AnalysisPWG4Jets.C::CheckModuleFlags", "PWG4gammaconv disabled on AOD's");
609 iPWG4GammaConv = 0;
c38e3b95 610 iPWG1QASym = 0;
611 } else {
612 // ESD analysis
613 if (!kUseMC){
614 kUseTR = kFALSE;
615
616 if(kUseKinefilter)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Kine Filter disabled in analysis without MC");
617 kUseKinefilter = kFALSE;
618 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis without MC");
619 iPWG4PtQAMC = 0;
620
621 }
622 if (!kUseTR) {
623 // ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
624 }
e84da0a5 625 if (iJETAN){
626 iESDfilter=1;
627 }
c38e3b95 628 if (!iESDfilter){
629 kUseKinefilter = kFALSE;
630 kUseMuonfilter = kFALSE;
631 }
632 if(!iJETAN){
633 iPWG4JetSpectrum = iPWG4UE = iPWG4ThreeJets = iDIJETAN = 0;
634 }
635 }
636 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4ThreeJets;
e6993a52 637 iJETANLib = iPWG4JetTasks||iJETAN||iDIJETAN;
c38e3b95 638 if (iESDfilter) {iAODhandler=1;}
639 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
640 if (kUseAODTags && !iAODhandler) kUseAODTags = kFALSE;
641
642
643
644}
645
646//______________________________________________________________________________
647Bool_t Connect(const char *mode) {
648// Connect <username> to the back-end system.
649 Int_t imode = -1;
650 if (!strcmp(mode, "LOCAL")) imode = 0;
651 if (!strcmp(mode, "PROOF")) imode = 1;
652 if (!strcmp(mode, "GRID")) imode = 2;
653 TString username = gSystem->Getenv("alien_API_USER");
654 switch (imode) {
655 case 0:
656 break;
657 case 1:
658 if (!username.Length()) {
659 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
660 1. Have called: alien-token-init <username>\n \
661 2. Have called: >source /tmp/gclient_env_$UID");
662 return kFALSE;
663 }
664 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
665 username.Data(), kProofCluster.Data());
666 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
667// TProof::Open(Form("%s@%s:31093", username.Data(), kProofCluster.Data()));
668 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
669 if (!gProof) {
670 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
671 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
672 return kFALSE;
673 }
674 if(kProofClearPackages)gProof->ClearPackages();
675
676 if(kProofSaveToAlien){
677 TGrid::Connect("alien://");
678 if (gGrid) {
679 TString homedir = gGrid->GetHomeDirectory();
680 TString workdir = homedir + kTrainName;
681 if (!gGrid->Cd(workdir)) {
682 gGrid->Cd(homedir);
683 if (gGrid->Mkdir(workdir)) {
684 gGrid->Cd(kTrainName);
685 ::Info("AnalysisTrainPWG4Jets::Connect()", "Directory %s created", gGrid->Pwd());
686 }
687 }
688 gGrid->Mkdir("proof_output");
689 gGrid->Cd("proof_output");
690 kProofOutdir = Form("alien://%s", gGrid->Pwd());
691 }
692 }
693 break;
694 case 2:
695 if (!username.Length()) {
696 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
697 1. Have called: alien-token-init <username>\n \
698 2. Have called: >source /tmp/gclient_env_$UID");
699 return kFALSE;
700 }
701 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
702 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode),
703 "When using the AliEn plugin it is preferable to define the \
704 variable alien_CLOSE_SE in your environment.");
705 return kFALSE;
706 }
707 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to AliEn ...",
708 username.Data());
709 TGrid::Connect("alien://");
710 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
711 break;
712 default:
713 ::Error("AnalysisTrainPWG4Jets.C::Connect", "Unknown run mode: %s", mode);
714 return kFALSE;
715 }
716 ::Info("AnalysisTrainPWG4Jets.C::Connect","Connected in %s mode", mode);
717 return kTRUE;
718}
719
720//______________________________________________________________________________
721Bool_t LoadCommonLibraries(const char *mode)
722{
723// Load common analysis libraries.
724 Int_t imode = -1;
725 if (!strcmp(mode, "LOCAL")) imode = 0;
726 if (!strcmp(mode, "PROOF")) imode = 1;
727 if (!strcmp(mode, "GRID")) imode = 2;
728 if (!gSystem->Getenv("ALICE_ROOT")) {
729 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
730 return kFALSE;
731 }
732 Bool_t success = kTRUE;
733 // ROOT libraries
734 gSystem->Load("libTree.so");
735 gSystem->Load("libGeom.so");
736 gSystem->Load("libVMC.so");
737 gSystem->Load("libPhysics.so");
738
739 // Load framework classes. Par option ignored here.
740 switch (imode) {
741 case 0:
742 case 2:
743 if (kUseCPAR) {
744 success &= LoadLibrary("STEERBase", mode, kTRUE);
745 success &= LoadLibrary("ESD", mode, kTRUE);
746 success &= LoadLibrary("AOD", mode, kTRUE);
747 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
748 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
749 success &= LoadLibrary("CORRFW", mode, kTRUE);
750 } else {
751 success &= LoadLibrary("libSTEERBase.so", mode);
752 success &= LoadLibrary("libESD.so", mode);
753 success &= LoadLibrary("libAOD.so", mode);
754 success &= LoadLibrary("libANALYSIS.so", mode);
755 success &= LoadLibrary("libANALYSISalice.so", mode);
756 success &= LoadLibrary("libCORRFW.so", mode);
757 gROOT->ProcessLine(".include $ALICE_ROOT/include");
758 }
759 break;
760 case 1:
761 Int_t ires = -1;
762 if (kProofUseAFPAR && !gSystem->AccessPathName(kProofAFversion)) ires = gProof->UploadPackage(kProofAFversion);
763 if (ires < 0) {
764 success &= LoadLibrary("STEERBase", mode);
765 success &= LoadLibrary("ESD", mode);
766 success &= LoadLibrary("AOD", mode);
767 success &= LoadLibrary("ANALYSIS", mode);
768 success &= LoadLibrary("ANALYSISalice", mode);
769 success &= LoadLibrary("CORRFW", mode);
770 } else {
771 ires = gProof->EnablePackage(kProofAFversion);
772 if (ires<0) success = kFALSE;
773 success &= LoadLibrary("CORRFW", mode);
774 }
775 break;
776 default:
777 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
778 return kFALSE;
779 }
780 if (success) {
781 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
782 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
783 gSystem->GetIncludePath());
784 } else {
785 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: FAILED");
786 }
787
788 return success;
789}
790
791//______________________________________________________________________________
792Bool_t LoadAnalysisLibraries(const char *mode)
793{
794// Load common analysis libraries.
795 Bool_t success = kTRUE;
796 if (iESDfilter) {
797 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
798 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
799 }
800 // JETAN
e6993a52 801 if (iJETANLib) {
b53f2e4f 802 // this part needs some rework in case we do not need the fastjed finders for processing
803 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 804 if (!strcmp(mode, "PROOF")){
ef1e462f 805 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 806 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
807 // problem when loading siscone copiled with different gcc version??
808 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
809 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
810 }
b53f2e4f 811 if(!kUsePAR){
e84da0a5 812 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
813 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
814 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
815 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
816 }
817 else{
818 // par files plus FASTJET needs some extra work... need to change
819 // the loading sequence in the auto generated .C file
820 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
821 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
822 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
823 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
824 }
c38e3b95 825 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
826 }
827 if(iPWG4JetTasks){
828 // PWG4 particle correlations
829 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
830 }
831 if(iPWG1QASym){
832 if (!LoadSource(Form("%s/PWG1/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
833 }
121e4bd5 834 if(iPWG4TmpSourceSara){
2bb1f4ca 835 // gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 836 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
837 }
c38e3b95 838 if (iPWG4PartCorr) {
839 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
840 !LoadLibrary("PHOSUtils", mode, kTRUE) ||
841 !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
842 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
843 }
121e4bd5 844 if (iPWG4omega3pi) {
845 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
846 }
53c63663 847 if (iPWG4GammaConv) {
848 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
849 }
c38e3b95 850
851 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
852 return kTRUE;
853}
854
855//______________________________________________________________________________
856Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
857{
858// Load a module library in a given mode. Reports success.
859 Int_t imode = -1;
860 Int_t result;
861 TString smodule(module);
862 if (!strcmp(mode, "LOCAL")) imode = 0;
863 if (!strcmp(mode, "PROOF")) imode = 1;
864 if (!strcmp(mode, "GRID")) imode = 2;
865 TString mod(module);
866 if (!mod.Length()) {
867 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
868 return kFALSE;
869 }
870 // If a library is specified, just load it
871 if (smodule.EndsWith(".so")) {
872 mod.Remove(mod.Index(".so"));
873 result = gSystem->Load(mod);
874 if (result < 0) {
875 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
876 return kFALSE;
877 }
878 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 879 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 880 return kTRUE;
881 }
882 // Check if the library is already loaded
883 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
884 return kTRUE;
885 switch (imode) {
886 case 0:
887 case 2:
888 if (kUsePAR) {
889 result = SetupPar(module);
890 if (rec) anaPars += Form("%s.par ", module);
891 } else {
892 result = gSystem->Load(Form("lib%s.so", module));
893 if (rec) anaLibs += Form("lib%s.so ", module);
894 }
895 break;
896 case 1:
897 if(!gSystem->AccessPathName(module)){
898 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
899 gSystem->Exec(Form("rm -rf %s",module));
900 }
901 result = gProof->UploadPackage(module);
902 if (result<0) {
903 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
904 if (result<0) {
905 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
906 return kFALSE;
907 }
908 }
909 result = gProof->EnablePackage(module);
910 break;
911 default:
912 return kFALSE;
913 }
914 if (result < 0) {
915 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
916 return kFALSE;
917 }
918 return kTRUE;
919}
920
921
922
923//______________________________________________________________________________
924Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
925{
926// Load a module library in a given mode. Reports success.
927 Int_t imode = -1;
928 Int_t result = -1;
929 if (!strcmp(mode, "LOCAL")) imode = 0;
930 if (!strcmp(mode, "PROOF")) imode = 1;
931 if (!strcmp(mode, "GRID")) imode = 2;
932 TString ssource(source);
933 TString basename = gSystem->BaseName(ssource.Data());
934 if (!ssource.Length()) {
935 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
936 return kFALSE;
937 }
938 // we have a source code so compile it
939 if (ssource.EndsWith(".cxx")) {
940 // need to copy it here other wise the path is also used on grid...
941 ssource.Remove(ssource.Index(".cxx"));
942 basename.Remove(basename.Index(".cxx"));
943 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
944 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
945 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
946 // Path to code
947 // only needed for local compilation, in grid and proof mode
948 // the task headers are uploaded
949 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
950 // Printf("LoadSources:: Including path %s",path.Data());
951 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
952 Printf("LoadSources:: Loading... path %s",basename.Data());
953 switch (imode) {
954 case 0:
b53f2e4f 955 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 956 break;
957 case 1:
b53f2e4f 958 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 959 break;
960 case 2:
b53f2e4f 961 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 962 if (rec){
963 // what we want to compile
964 anaSources += Form("%s.cxx ",basename.Data());
965 // what we need as input...
966 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
967 }
968 break;
969 default:
970 return kFALSE;
971 }
972 }
973 if (result < 0) {
974 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
975 return kFALSE;
976 }
977 return kTRUE;
978}
979
980
981//______________________________________________________________________________
982TChain *CreateChain(const char *mode, const char *plugin_mode)
983{
984// Create the input chain
985 Int_t imode = -1;
986 if (!strcmp(mode, "LOCAL")) imode = 0;
987 if (!strcmp(mode, "PROOF")) imode = 1;
988 if (!strcmp(mode, "GRID")) imode = 2;
989 TChain *chain = NULL;
990 // Local chain
991 switch (imode) {
992 case 0:
993 if (iAODanalysis) {
994 if (!kLocalXMLDataset.Length()) {
995 // Local AOD
996 chain = new TChain("aodTree");
997 TString line;
998 ifstream in;
999 in.open(kLocalDataList.Data());
1000 while (in.good()) {
1001 in >> line;
1002 if (line.Length() == 0) continue;
1003 // cout << " line = " << line << endl;
1004 chain->Add(line.Data());
1005 }
1006 } else {
1007 // Interactive AOD
1008 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1009 }
1010 } else {
1011 if (!kLocalXMLDataset.Length()) {
1012 // Local ESD
1013 chain = new TChain("esdTree");
1014 TString line;
1015 ifstream in;
1016 in.open(kLocalDataList.Data());
1017 while (in.good()) {
1018 in >> line;
1019 if (line.Length() == 0) continue;
1020 cout << " line = " << line << endl;
1021 chain->Add(line.Data());
1022 }
1023 } else {
1024 // Interactive ESD
1025 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1026 }
1027 }
1028 break;
1029 case 1:
1030 break;
1031 case 2:
1032 if (kPluginUse) {
1033// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1034// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1035 } else {
1036 TString treeName = "esdTree";
1037 if (iAODanalysis) treeName = "aodTree";
1038 chain = CreateChainSingle("wn.xml", treeName);
1039 }
1040 break;
1041 default:
1042 }
1043 if (chain && chain->GetNtrees()) return chain;
1044 return NULL;
1045}
1046
1047//______________________________________________________________________________
1048TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1049{
1050 printf("*******************************\n");
1051 printf("*** Getting the ESD Chain ***\n");
1052 printf("*******************************\n");
1053 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1054
1055 if (!myCollection) {
1056 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1057 return NULL ;
1058 }
1059
1060 TChain* chain = new TChain(treeName);
1061 myCollection->Reset() ;
1062 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1063 chain->ls();
1064 return chain;
1065}
1066
1067//______________________________________________________________________________
1068Int_t SetupPar(char* pararchivename)
1069{
1070 if (!pararchivename || !strlen(pararchivename)) return -1;
1071 char processline[1024];
1072 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1073 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1074 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
1075 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1076 Form("%s.par",pararchivename));
1077 } else {
1078 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1079 return -1;
1080 }
1081 }
1082 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1083 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1084
1085 TString ocwd = gSystem->WorkingDirectory();
1086 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1087
1088 // check for BUILD.sh and execute
1089 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1090 printf("*******************************\n");
1091 printf("*** Building PAR archive ***\n");
1092 printf("*******************************\n");
1093 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1094 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1095 return -1;
1096 }
1097 }
1098
1099 // check for SETUP.C and execute
1100 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1101 printf("*******************************\n");
1102 printf("*** Setup PAR archive ***\n");
1103 printf("*******************************\n");
1104 gROOT->Macro("PROOF-INF/SETUP.C");
1105 }
1106 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1107 return 0;
1108}
1109
1110//______________________________________________________________________________
1111AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1112{
1113// Check if user has a valid token, otherwise make one. This has limitations.
1114// One can always follow the standard procedure of calling alien-token-init then
1115// source /tmp/gclient_env_$UID in the current shell.
1116 if (!AliAnalysisGrid::CreateToken()) return NULL;
1117 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1118// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1119 plugin->SetRunMode(plugin_mode);
1120 if (kPluginUseProductionMode) plugin->SetProductionMode();
1121 plugin->SetJobTag(kJobTag);
1122 plugin->SetNtestFiles(2);
1123// plugin->SetPreferedSE("ALICE::NIHAM::File");
1124// Set versions of used packages
e84da0a5 1125 plugin->SetAPIVersion("V1.1x");
1126 // plugin->SetAPIVersion("V1.0x");
1127// plugin->SetAPIVersion("V2.4");
c38e3b95 1128 plugin->SetROOTVersion(kPluginRootVersion);
1129 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1130// Declare input data to be processed.
1131// Method 1: Create automatically XML collections using alien 'find' command.
1132// Define production directory LFN
1133 plugin->SetGridDataDir(kGridDatadir.Data());
1134// Set data search pattern
1135 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1136 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1137// ...then add run numbers to be considered
1138// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1139 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1140 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1141 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1142 }
1143
1144 if(kGridLocalRunList.Length()>0){
1145 ifstream in1;
1146 in1.open(kGridLocalRunList.Data());
1147 int iRun;
e84da0a5 1148 char c;
1149 char cLine[250];
1150 while(!in1.eof()){
1151 c = in1.get();
1152 if ( (c >= '0') && (c <= '9') )
1153 {
1154 in1.putback (c);
1155 in1>>iRun;
1156 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1157 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1158 }
1159 else
1160 {
1161 in1.putback (c);
1162 in1.getline(cLine,250);
1163 Printf("AnalysisTrainPWG4Jets Skipping run number from File %s", cLine);
1164 }
c38e3b95 1165 }
1166 }
1167
1168// Method 2: Declare existing data files (raw collections, xml collections, root file)
1169// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1170// XML collections added via this method can be combined with the first method if
1171// the content is compatible (using or not tags)
1172// plugin->AddDataFile("tag.xml");
1173// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1174// Define alien work directory where all files will be copied. Relative to alien $HOME.
1175 if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
1176 else plugin->SetGridWorkingDir("analysisESD");
1177 // Declare alien output directory. Relative to working directory.
1178 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1179 plugin->SetGridOutputDir(kGridOutdir);
1180
1181 // Add external packages
1182 if (iJETAN||iDIJETAN) {
1183 plugin->AddExternalPackage("boost::v1_38_0");
1184 plugin->AddExternalPackage("cgal::v3.3.1");
1185 plugin->AddExternalPackage("fastjet::v2.4.0");
1186 }
1187
1188
1189 // set extra libs before par file compilation
1190 anaLibs += kGridExtraFiles;
1191 anaLibs = anaLibs.Strip();
e84da0a5 1192 Printf("anaLibs %s",anaLibs.Data());
1193 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1194
1195 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1196 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1197
1198 TString ana_sources = "";
1199 TString ana_add = "";
1200 if (kUsePAR && anaPars.Length()) {
1201 printf("%s\n", anaPars.Data());
1202 TObjArray *arr;
1203 TObjString *objstr;
1204 arr = anaPars.Tokenize(" ");
1205 TIter next(arr);
1206 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1207 delete arr;
1208 }
1209
1210// Declare the analysis source files names separated by blancs. To be compiled runtime
1211// using ACLiC on the worker nodes.
1212 ana_sources = anaSources.Strip();
1213// Declare all libraries (other than the default ones for the framework. These will be
1214// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1215
1216 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1217 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
1218// Declare the output file names separated by blancs.
1219// (can be like: file.root or file.root@ALICE::Niham::File)
1220 plugin->SetDefaultOutputs();
1221 plugin->SetMergeExcludes(kGridMergeExclude);
1222 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1223 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
1224// Optionally define the files to be archived.
1225// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
1226
1227
1228 // Put default output files to archive
1229 TString listhists = "";
1230 TString listaods = "";
1231 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1232 TIter next(mgr->GetOutputs());
1233 AliAnalysisDataContainer *output;
1234 while ((output=(AliAnalysisDataContainer*)next())) {
1235 const char *filename = output->GetFileName();
1236 if (!(strcmp(filename, "default"))) {
53c63663 1237 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1238 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1239 if (listaods.Length()) listaods += " ";
c38e3b95 1240 listaods += filename;
c38e3b95 1241 } else {
e84da0a5 1242 if(!listhists.Contains(filename)){
1243 if (listhists.Length()) listhists += " ";
c38e3b95 1244 listhists += filename;
1245 }
1246 }
1247 }
53c63663 1248
c28abe00 1249 if(kUseSysInfo>0){
e84da0a5 1250 if (listhists.Length()) listhists += " ";
c28abe00 1251 listhists += "syswatch.root";
53c63663 1252 }
1253
e84da0a5 1254 if(kIsMC){
1255 if (listaods.Length()) listaods += " ";
1256 listaods += "pyxsec_hists.root";
1257 }
1258
1259
53c63663 1260 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1261 if (listaods.Length()) listaods += " ";
53c63663 1262 listaods += mgr->GetExtraFiles();
c38e3b95 1263 }
53c63663 1264
1265 // if we do not fill the aod we do not need to store it
e84da0a5 1266 kGridMergeExclude = listaods;
1267
1268 if(!kFillAOD){
1269 listaods="";
1270 plugin->SetDefaultOutputs(kFALSE);
1271 plugin->SetOutputFiles(listhists.Data());
1272 }
53c63663 1273
e84da0a5 1274
1275 listaods.ReplaceAll(" ", ",");
1276 listhists.ReplaceAll(" ", ",");
c38e3b95 1277 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());;
1278 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());;
53c63663 1279
c38e3b95 1280 if (!listhists.Length() && !listaods.Length()) {
1281 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
1282 }
53c63663 1283
e84da0a5 1284
53c63663 1285
b2d64ef3 1286 TString outputArchive = "log_archive.zip:stdout,stderr@ALICE::FZK::SE,ALICE::GSI::SE";
1287 if(kUseSysInfo>0)outputArchive = "log_archive.zip:stdout,stderr,syswatch.log@ALICE::FZK::SE,ALICE::GSI::SE";
c38e3b95 1288 if (listaods.Length()) {
1289 outputArchive += " ";
1290 outputArchive += listaods;
1291 }
1292 if (listhists.Length()) {
1293 outputArchive += " ";
1294 outputArchive += listhists;
1295 }
1296 plugin->SetOutputArchive(outputArchive);
1297// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1298 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1299// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1300 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1301// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1302// plugin->SetMaxInitFailed(5);
1303// Optionally resubmit threshold.
1304// plugin->SetMasterResubmitThreshold(90);
1305// Optionally set time to live (default 30000 sec)
1306 plugin->SetTTL(30000);
1307// Optionally set input format (default xml-single)
1308 plugin->SetInputFormat("xml-single");
1309// Optionally modify the name of the generated JDL (default analysis.jdl)
1310 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1311// Optionally modify the executable name (default analysis.sh)
1312 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1313// Optionally modify job price (default 1)
1314 plugin->SetPrice(1);
1315// Optionally modify split mode (default 'se')
1316 plugin->SetSplitMode("se");
1317 return plugin;
1318}
1319
1320//______________________________________________________________________________
1321void WriteConfig()
1322{
1323// Write train configuration in a file. The file name has the format:
1324// train_[trainName]_ddMonthyyyy_time.C
1325 if (kUseDate) {
1326 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1327 ifstream fdate("date.tmp");
1328 if (!fdate.is_open()) {
1329 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1330 return;
1331 }
1332 const char date[64];
1333 fdate.getline(date,64);
1334 fdate.close();
1335 gSystem->Exec("rm date.tmp");
1336 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1337 } else {
1338 kTrainName = Form("train_%s", kTrainName.Data());
1339 }
1340 TString cdir = gSystem->WorkingDirectory();
1341 gSystem->MakeDirectory(kTrainName);
1342 gSystem->ChangeDirectory(kTrainName);
1343 ofstream out;
1344 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1345 if (out.bad()) {
1346 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1347 return;
1348 }
1349 out << "{" << endl;
1350 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1351 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1352 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1353 if (kProofUseAFPAR)
1354 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1355 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1356 out << " kPluginUse = " << kPluginUse << ";" << endl;
1357 out << " kUsePAR = " << kUsePAR << ";" << endl;
1358 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1359 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1360 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1361 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1362 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1363 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1364 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1365 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1366 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1367 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1368 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1369 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1370 out << " kUseDebug = " << kUseDebug << ";" << endl;
1371 out << " kUseMC = " << kUseMC << ";" << endl;
1372 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1373 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1374 out << " kUseTR = " << kUseTR << ";" << endl;
1375 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1376 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1377 out << " // Analysis modules" << endl;
1378 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1379 out << " iAODhandler = " << iAODhandler << ";" << endl;
1380 out << " iESDfilter = " << iESDfilter << ";" << endl;
1381 out << " iJETAN = " << iJETAN << ";" << endl;
1382 out << "// Configuration fot the wagons" << endl;
1383 out << "}" << endl;
1384 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1385 gSystem->ChangeDirectory(cdir);
1386}
1387
1388//______________________________________________________________________________
1389Bool_t LoadConfig(const char *filename)
1390{
1391// Read train configuration from file
1392 if (gSystem->AccessPathName(filename)) {
1393 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1394 return kFALSE;
1395 }
1396 gROOT->ProcessLine(Form(".x %s", filename));
1397 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1398 return kTRUE;
1399}
1400
1401Bool_t PatchJDL(){
1402 Printf(">>> Patching JDL");
1403 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1404 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1405 TGridJDL *jdl = gridHandler->GetGridJDL();
1406 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1407 gridHandler->WriteJDL(kFALSE);
1408 Printf("<<< Patching JDL");
1409 return kTRUE;
1410}
1411
1412Bool_t PatchAnalysisMacro(){
1413 Printf(">>> Patching AnalysisMacro");
1414 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
1415
1416 ifstream in1;
1417 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1418 char cLine[250];
1419 TString st;
1420 while(in1.getline(cLine,250)){
1421 st += cLine;
1422 st += "\n";
1423 }
1424 Int_t index;
1425 index = st.Index("gSystem->Load(\"libPhysics\");");
1426 index += strlen("gSystem->Load(\"libPhysics\");");
e84da0a5 1427 if(iJETAN&&kUsePAR){
c38e3b95 1428 TObjArray *arr;
1429 TObjString *objstr;
1430 arr = anaLibs.Tokenize(" ");
1431 TIter next(arr);
1432 TString add = "";
1433 add += "\n\n // added by CKB \n";
1434 while ((objstr=(TObjString*)next())){
e84da0a5 1435 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1436 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1437 }
1438 delete arr;
1439 add += "// BKC \n\n";
1440 st.Insert(index,add.Data());
1441 }
e84da0a5 1442
1443 if(kUseDebug){
1444 st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
1445 }
1446
c38e3b95 1447 ofstream out;
1448 out.open(Form("%s.C", kTrainName.Data()));
1449 if (out.bad()) {
1450 return kFALSE;
1451 }
1452 out << st << endl;
1453 Printf("<<< Patching AnalysisMacro");
1454 return kTRUE;
1455
1456}