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