minor fixes, plotting ranges in eta
[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){
565584e8 369 AddTaskJetSpectrum2("jetsAOD_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
b53f2e4f 370 AddTaskJetSpectrum2("jetsAOD_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
371 AddTaskJetSpectrum2("jetsAOD_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
372 AddTaskJetSpectrum2("jetsAOD_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
373 AddTaskJetSpectrum2("jetsAOD_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
565584e8 374 if(kIsMC){
375 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
376 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
377 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
378 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
379 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
380 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
381 }
b53f2e4f 382 }
c38e3b95 383 if(kUseMC)taskjetSpectrum->SetAnalysisType( AliAnalysisTaskJetSpectrum2::kAnaMCESD);
e6993a52 384 taskjetSpectrum->SetDebugLevel(0);
c38e3b95 385 }
386
387 if(iPWG4UE){
388 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
389 AliAnalysisTaskUE *taskUE = 0;
390 if(iPWG4UE&1)taskUE = AddTaskUE();
391 if(iPWG4UE&2){
2bb1f4ca 392 taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV");
393 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","LJ","TRANSV");
394 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","BB","TRANSV");
395 taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV");
396 taskUE = AddTaskUE("jetsAOD_FASTJET04","CDF","LJ","TRANSV");
397 taskUE = AddTaskUE("jetsAOD_SISCONE04","CDF","LJ","TRANSV");
398
c38e3b95 399 }
2bb1f4ca 400
c38e3b95 401 if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
402 }
403
404 if(iPWG4ThreeJets){
405 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
406 AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
407 if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
408 }
409
410 if(iPWG4PtQAMC){
411 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
412 AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
413 if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
414 }
415
416 if(iPWG4PtQATPC){
417 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
418 AliPWG4HighPtQATPConly *taskQATPC = AddTaskPWG4HighPtQATPConly();
419 if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
420 }
421
422 if(iPWG4PtSpectra){
423 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
424 AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
425 if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
426 }
427
b53f2e4f 428 if(iPWG4KMeans){
429 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
430 AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
431 if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
432 }
433
c38e3b95 434 if(iPWG4PartCorr){
435 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
14526afb 436 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
c38e3b95 437 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
14526afb 438 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
c38e3b95 439 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
440 if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data()); // hmm this is written anyway.... but at least we do not register it...
121e4bd5 441 }
442
911a740f 443 if(iPWG4Tagged){
444 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
445 AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
446 // taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS
447 if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons cannot run for this train conditions - EXCLUDED");
448 }
449
121e4bd5 450 if (iPWG4omega3pi) {
451 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
452 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
453 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
454 for these train conditions - EXCLUDED");
455 }
456
c38e3b95 457
53c63663 458 // PWG4 gamma conversion analysis
459 if (iPWG4GammaConv) {
460 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
461 TString cdir = gSystem->WorkingDirectory();
462 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
463 // TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
b53f2e4f 464 TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz -bg-off";
53c63663 465 if(!kIsMC)gcArguments += " -mc-off";
466 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
467 gSystem->ChangeDirectory(cdir);
121e4bd5 468 taskGammaConversion->SelectCollisionCandidates();
53c63663 469 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
470 }
471
c38e3b95 472 //==========================================================================
473 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
474 // Run the analysis
475 //
476 if (kPluginUse) {
477 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
478 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
479 }
480
481 if (mgr->InitAnalysis()) {
482 mgr->PrintStatus();
483 // if (kSaveTrain || strlen(config_file)) gSystem->ChangeDirectory(kTrainName);
e84da0a5 484 if (!strcmp(plugin_mode,"submit")&&smode=="GRID"){
c38e3b95 485 TString alien_workdir = gGrid->GetHomeDirectory();
486 if (iAODanalysis) alien_workdir += "analysisAOD";
487 else alien_workdir += "analysisESD";
488 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
e84da0a5 489 printf("=== AnalysisTrainPWG4Jets:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
c38e3b95 490 alien_workdir.Data(),gridhandler->GetGridOutputDir());
491 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()), Form("alien://%s/%s/%s.jdl",alien_workdir.Data(),
492 gridhandler->GetGridOutputDir(),kTrainName.Data()));
493 }
494
495 StartAnalysis(smode, chain);
496 if (!strcmp(plugin_mode, "offline")&&smode=="GRID"){
e84da0a5 497 // Offline mode path files
498 // PatchJDL();
499 PatchAnalysisMacro();
500 }
c38e3b95 501
e84da0a5 502 if (kSaveTrain && smode=="GRID") {
503 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
504 TString alien_workdir = gGrid->GetHomeDirectory();
505 if (iAODanalysis) alien_workdir += "analysisAOD";
c38e3b95 506 else alien_workdir += "analysisESD";
e84da0a5 507 // kGridOutdir = gridhandler->GetGridOutputDir();
508 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
c38e3b95 509 alien_workdir.Data());
e84da0a5 510 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data())))
511 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
512 if (strcmp(plugin_mode, "test"))
513 TFile::Cp(Form("file:%sConfig.C",kTrainName.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
514 }
515 }
c38e3b95 516}
517
518//______________________________________________________________________________
519void StartAnalysis(const char *mode, TChain *chain) {
520// Start analysis.
521 Int_t imode = -1;
522 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
523 if (!strcmp(mode, "LOCAL")) imode = 0;
524 if (!strcmp(mode, "PROOF")) imode = 1;
525 if (!strcmp(mode, "GRID")) imode = 2;
526 switch (imode) {
527 case 0:
528 if (!chain) {
529 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
530 return;
531 }
532 mgr->StartAnalysis(mode, chain);
533 return;
534 case 1:
535 if (!kProofDataSet.Length()) {
536 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "kProofDataSet is empty");
537 return;
538 }
539 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
540 return;
541 case 2:
542 if (kPluginUse) {
543 if (!mgr->GetGridHandler()) {
544 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Grid plugin not initialized");
545 return;
546 }
547 mgr->StartAnalysis("grid");
548 } else {
549 if (!chain) {
550 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
551 return;
552 }
553 mgr->StartAnalysis(mode, chain);
554 }
555 return;
556 }
557}
558
559//______________________________________________________________________________
560void CheckModuleFlags(const char *mode) {
561// Checks selected modules and insure compatibility
562 Int_t imode = -1;
563 if (!strcmp(mode, "LOCAL")) imode = 0;
564 if (!strcmp(mode, "PROOF")) imode = 1;
565 if (!strcmp(mode, "GRID")) imode = 2;
566
567
e84da0a5 568 if (kUseCPAR) {
569 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
570 }
c38e3b95 571
572 if (imode==1) {
573 if (!kUsePAR) {
574 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
575 kUsePAR = kTRUE;
576 }
577 }
578 if (imode != 2) {
579 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
580 kPluginUse = kFALSE;
581 }
582
583
584 if(!kIsMC){
585 // switch off anthin related to MC
586 kUseMC = 0;
587 kUseAODMC = 0;
588 kUseTR = kFALSE;
589 }
590
591 if (iAODanalysis) {
592 // AOD analysis
593 if (kUseMC)
594 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
595 if (kUseAODTags)
596 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
597 kUseMC = kFALSE;
598 kUseTR = kFALSE;
599 kUseAODTags = kFALSE;
600 if (iESDfilter)
601 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
602 iESDfilter = 0;
e84da0a5 603 if (iPhysicsSelection)
604 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "Physics Selection disabled in analysis on AOD's");
605 iPhysicsSelection = 0;
c38e3b95 606 if (!iAODhandler) {
607 if (iJETAN)
608 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
609 iJETAN = 0;
610 iDIJETAN = 0;
611 }
612 // Disable tasks that do not work yet on AOD data
613 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
614 iPWG4PtQAMC = 0;
615 if( iPWG4PtQATPC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtTPC disabled in analysis on AOD's");
616 iPWG4PtQATPC = 0;
617 if( iPWG4PtSpectra)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
618 iPWG4PtSpectra = 0;
b53f2e4f 619 if(iPWG4KMeans)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4KMeans disabled on AOD's");
620 iPWG4KMeans = 0;
c38e3b95 621 if (iPWG4PartCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
622 iPWG4PartCorr = 0;
911a740f 623 if (iPWG4Tagged)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4tagged disabled on AOD's");
624 iPWG4Tagged = 0;
121e4bd5 625 if (iPWG4omega3pi)
626 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
627 iPWG4omega3pi = 0;
c38e3b95 628 if(iPWG1QASym)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG1 QA Sym disabled in analysis on AOD's");
53c63663 629 if (iPWG4GammaConv)::Info("AnalysisPWG4Jets.C::CheckModuleFlags", "PWG4gammaconv disabled on AOD's");
630 iPWG4GammaConv = 0;
c38e3b95 631 iPWG1QASym = 0;
632 } else {
633 // ESD analysis
634 if (!kUseMC){
635 kUseTR = kFALSE;
636
637 if(kUseKinefilter)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Kine Filter disabled in analysis without MC");
638 kUseKinefilter = kFALSE;
639 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis without MC");
640 iPWG4PtQAMC = 0;
641
642 }
643 if (!kUseTR) {
644 // ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
645 }
e84da0a5 646 if (iJETAN){
647 iESDfilter=1;
648 }
c38e3b95 649 if (!iESDfilter){
650 kUseKinefilter = kFALSE;
651 kUseMuonfilter = kFALSE;
652 }
653 if(!iJETAN){
654 iPWG4JetSpectrum = iPWG4UE = iPWG4ThreeJets = iDIJETAN = 0;
655 }
656 }
657 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4ThreeJets;
911a740f 658 iPWG4PartCorrLibs = iPWG4PartCorr||iPWG4Tagged;
e6993a52 659 iJETANLib = iPWG4JetTasks||iJETAN||iDIJETAN;
c38e3b95 660 if (iESDfilter) {iAODhandler=1;}
661 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
662 if (kUseAODTags && !iAODhandler) kUseAODTags = kFALSE;
663
664
665
666}
667
668//______________________________________________________________________________
669Bool_t Connect(const char *mode) {
670// Connect <username> to the back-end system.
671 Int_t imode = -1;
672 if (!strcmp(mode, "LOCAL")) imode = 0;
673 if (!strcmp(mode, "PROOF")) imode = 1;
674 if (!strcmp(mode, "GRID")) imode = 2;
675 TString username = gSystem->Getenv("alien_API_USER");
676 switch (imode) {
677 case 0:
678 break;
679 case 1:
680 if (!username.Length()) {
681 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
682 1. Have called: alien-token-init <username>\n \
683 2. Have called: >source /tmp/gclient_env_$UID");
684 return kFALSE;
685 }
686 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
687 username.Data(), kProofCluster.Data());
688 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
689// TProof::Open(Form("%s@%s:31093", username.Data(), kProofCluster.Data()));
690 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
691 if (!gProof) {
692 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
693 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
694 return kFALSE;
695 }
696 if(kProofClearPackages)gProof->ClearPackages();
697
698 if(kProofSaveToAlien){
699 TGrid::Connect("alien://");
700 if (gGrid) {
701 TString homedir = gGrid->GetHomeDirectory();
702 TString workdir = homedir + kTrainName;
703 if (!gGrid->Cd(workdir)) {
704 gGrid->Cd(homedir);
705 if (gGrid->Mkdir(workdir)) {
706 gGrid->Cd(kTrainName);
707 ::Info("AnalysisTrainPWG4Jets::Connect()", "Directory %s created", gGrid->Pwd());
708 }
709 }
710 gGrid->Mkdir("proof_output");
711 gGrid->Cd("proof_output");
712 kProofOutdir = Form("alien://%s", gGrid->Pwd());
713 }
714 }
715 break;
716 case 2:
717 if (!username.Length()) {
718 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
719 1. Have called: alien-token-init <username>\n \
720 2. Have called: >source /tmp/gclient_env_$UID");
721 return kFALSE;
722 }
723 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
724 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode),
725 "When using the AliEn plugin it is preferable to define the \
726 variable alien_CLOSE_SE in your environment.");
727 return kFALSE;
728 }
729 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to AliEn ...",
730 username.Data());
731 TGrid::Connect("alien://");
732 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
733 break;
734 default:
735 ::Error("AnalysisTrainPWG4Jets.C::Connect", "Unknown run mode: %s", mode);
736 return kFALSE;
737 }
738 ::Info("AnalysisTrainPWG4Jets.C::Connect","Connected in %s mode", mode);
739 return kTRUE;
740}
741
742//______________________________________________________________________________
743Bool_t LoadCommonLibraries(const char *mode)
744{
745// Load common analysis libraries.
746 Int_t imode = -1;
747 if (!strcmp(mode, "LOCAL")) imode = 0;
748 if (!strcmp(mode, "PROOF")) imode = 1;
749 if (!strcmp(mode, "GRID")) imode = 2;
750 if (!gSystem->Getenv("ALICE_ROOT")) {
751 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
752 return kFALSE;
753 }
754 Bool_t success = kTRUE;
755 // ROOT libraries
756 gSystem->Load("libTree.so");
757 gSystem->Load("libGeom.so");
758 gSystem->Load("libVMC.so");
759 gSystem->Load("libPhysics.so");
760
761 // Load framework classes. Par option ignored here.
762 switch (imode) {
763 case 0:
764 case 2:
765 if (kUseCPAR) {
766 success &= LoadLibrary("STEERBase", mode, kTRUE);
767 success &= LoadLibrary("ESD", mode, kTRUE);
768 success &= LoadLibrary("AOD", mode, kTRUE);
769 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
770 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
771 success &= LoadLibrary("CORRFW", mode, kTRUE);
772 } else {
773 success &= LoadLibrary("libSTEERBase.so", mode);
774 success &= LoadLibrary("libESD.so", mode);
775 success &= LoadLibrary("libAOD.so", mode);
776 success &= LoadLibrary("libANALYSIS.so", mode);
777 success &= LoadLibrary("libANALYSISalice.so", mode);
778 success &= LoadLibrary("libCORRFW.so", mode);
779 gROOT->ProcessLine(".include $ALICE_ROOT/include");
780 }
781 break;
782 case 1:
783 Int_t ires = -1;
784 if (kProofUseAFPAR && !gSystem->AccessPathName(kProofAFversion)) ires = gProof->UploadPackage(kProofAFversion);
785 if (ires < 0) {
786 success &= LoadLibrary("STEERBase", mode);
787 success &= LoadLibrary("ESD", mode);
788 success &= LoadLibrary("AOD", mode);
789 success &= LoadLibrary("ANALYSIS", mode);
790 success &= LoadLibrary("ANALYSISalice", mode);
791 success &= LoadLibrary("CORRFW", mode);
792 } else {
793 ires = gProof->EnablePackage(kProofAFversion);
794 if (ires<0) success = kFALSE;
795 success &= LoadLibrary("CORRFW", mode);
796 }
797 break;
798 default:
799 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
800 return kFALSE;
801 }
802 if (success) {
803 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
804 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
805 gSystem->GetIncludePath());
806 } else {
807 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: FAILED");
808 }
809
810 return success;
811}
812
813//______________________________________________________________________________
814Bool_t LoadAnalysisLibraries(const char *mode)
815{
816// Load common analysis libraries.
817 Bool_t success = kTRUE;
818 if (iESDfilter) {
819 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
820 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
821 }
822 // JETAN
e6993a52 823 if (iJETANLib) {
b53f2e4f 824 // this part needs some rework in case we do not need the fastjed finders for processing
825 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 826 if (!strcmp(mode, "PROOF")){
ef1e462f 827 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 828 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
829 // problem when loading siscone copiled with different gcc version??
830 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
831 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
832 }
b53f2e4f 833 if(!kUsePAR){
e84da0a5 834 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
835 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
836 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
837 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
838 }
839 else{
840 // par files plus FASTJET needs some extra work... need to change
841 // the loading sequence in the auto generated .C file
842 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
843 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
844 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
845 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
846 }
c38e3b95 847 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
848 }
849 if(iPWG4JetTasks){
850 // PWG4 particle correlations
851 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
852 }
853 if(iPWG1QASym){
854 if (!LoadSource(Form("%s/PWG1/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
855 }
121e4bd5 856 if(iPWG4TmpSourceSara){
2bb1f4ca 857 // gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 858 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
859 }
911a740f 860 if (iPWG4PartCorrLibs) {
c38e3b95 861 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
862 !LoadLibrary("PHOSUtils", mode, kTRUE) ||
863 !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
864 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
865 }
121e4bd5 866 if (iPWG4omega3pi) {
867 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
868 }
53c63663 869 if (iPWG4GammaConv) {
870 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
871 }
c38e3b95 872
873 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
874 return kTRUE;
875}
876
877//______________________________________________________________________________
878Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
879{
880// Load a module library in a given mode. Reports success.
881 Int_t imode = -1;
882 Int_t result;
883 TString smodule(module);
884 if (!strcmp(mode, "LOCAL")) imode = 0;
885 if (!strcmp(mode, "PROOF")) imode = 1;
886 if (!strcmp(mode, "GRID")) imode = 2;
887 TString mod(module);
888 if (!mod.Length()) {
889 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
890 return kFALSE;
891 }
892 // If a library is specified, just load it
893 if (smodule.EndsWith(".so")) {
894 mod.Remove(mod.Index(".so"));
895 result = gSystem->Load(mod);
896 if (result < 0) {
897 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
898 return kFALSE;
899 }
900 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 901 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 902 return kTRUE;
903 }
904 // Check if the library is already loaded
905 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
906 return kTRUE;
907 switch (imode) {
908 case 0:
909 case 2:
910 if (kUsePAR) {
911 result = SetupPar(module);
912 if (rec) anaPars += Form("%s.par ", module);
913 } else {
914 result = gSystem->Load(Form("lib%s.so", module));
915 if (rec) anaLibs += Form("lib%s.so ", module);
916 }
917 break;
918 case 1:
919 if(!gSystem->AccessPathName(module)){
920 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
921 gSystem->Exec(Form("rm -rf %s",module));
922 }
923 result = gProof->UploadPackage(module);
924 if (result<0) {
925 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
926 if (result<0) {
927 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
928 return kFALSE;
929 }
930 }
931 result = gProof->EnablePackage(module);
932 break;
933 default:
934 return kFALSE;
935 }
936 if (result < 0) {
937 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
938 return kFALSE;
939 }
940 return kTRUE;
941}
942
943
944
945//______________________________________________________________________________
946Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
947{
948// Load a module library in a given mode. Reports success.
949 Int_t imode = -1;
950 Int_t result = -1;
951 if (!strcmp(mode, "LOCAL")) imode = 0;
952 if (!strcmp(mode, "PROOF")) imode = 1;
953 if (!strcmp(mode, "GRID")) imode = 2;
954 TString ssource(source);
955 TString basename = gSystem->BaseName(ssource.Data());
956 if (!ssource.Length()) {
957 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
958 return kFALSE;
959 }
960 // we have a source code so compile it
961 if (ssource.EndsWith(".cxx")) {
962 // need to copy it here other wise the path is also used on grid...
963 ssource.Remove(ssource.Index(".cxx"));
964 basename.Remove(basename.Index(".cxx"));
965 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
966 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
967 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
968 // Path to code
969 // only needed for local compilation, in grid and proof mode
970 // the task headers are uploaded
971 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
972 // Printf("LoadSources:: Including path %s",path.Data());
973 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
974 Printf("LoadSources:: Loading... path %s",basename.Data());
975 switch (imode) {
976 case 0:
b53f2e4f 977 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 978 break;
979 case 1:
b53f2e4f 980 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 981 break;
982 case 2:
b53f2e4f 983 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 984 if (rec){
985 // what we want to compile
986 anaSources += Form("%s.cxx ",basename.Data());
987 // what we need as input...
988 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
989 }
990 break;
991 default:
992 return kFALSE;
993 }
994 }
995 if (result < 0) {
996 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
997 return kFALSE;
998 }
999 return kTRUE;
1000}
1001
1002
1003//______________________________________________________________________________
1004TChain *CreateChain(const char *mode, const char *plugin_mode)
1005{
1006// Create the input chain
1007 Int_t imode = -1;
1008 if (!strcmp(mode, "LOCAL")) imode = 0;
1009 if (!strcmp(mode, "PROOF")) imode = 1;
1010 if (!strcmp(mode, "GRID")) imode = 2;
1011 TChain *chain = NULL;
1012 // Local chain
1013 switch (imode) {
1014 case 0:
1015 if (iAODanalysis) {
1016 if (!kLocalXMLDataset.Length()) {
1017 // Local AOD
1018 chain = new TChain("aodTree");
1019 TString line;
1020 ifstream in;
1021 in.open(kLocalDataList.Data());
1022 while (in.good()) {
1023 in >> line;
1024 if (line.Length() == 0) continue;
1025 // cout << " line = " << line << endl;
1026 chain->Add(line.Data());
1027 }
1028 } else {
1029 // Interactive AOD
1030 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1031 }
1032 } else {
1033 if (!kLocalXMLDataset.Length()) {
1034 // Local ESD
1035 chain = new TChain("esdTree");
1036 TString line;
1037 ifstream in;
1038 in.open(kLocalDataList.Data());
1039 while (in.good()) {
1040 in >> line;
1041 if (line.Length() == 0) continue;
1042 cout << " line = " << line << endl;
1043 chain->Add(line.Data());
1044 }
1045 } else {
1046 // Interactive ESD
1047 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1048 }
1049 }
1050 break;
1051 case 1:
1052 break;
1053 case 2:
1054 if (kPluginUse) {
1055// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1056// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1057 } else {
1058 TString treeName = "esdTree";
1059 if (iAODanalysis) treeName = "aodTree";
1060 chain = CreateChainSingle("wn.xml", treeName);
1061 }
1062 break;
1063 default:
1064 }
1065 if (chain && chain->GetNtrees()) return chain;
1066 return NULL;
1067}
1068
1069//______________________________________________________________________________
1070TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1071{
1072 printf("*******************************\n");
1073 printf("*** Getting the ESD Chain ***\n");
1074 printf("*******************************\n");
1075 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1076
1077 if (!myCollection) {
1078 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1079 return NULL ;
1080 }
1081
1082 TChain* chain = new TChain(treeName);
1083 myCollection->Reset() ;
1084 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1085 chain->ls();
1086 return chain;
1087}
1088
1089//______________________________________________________________________________
1090Int_t SetupPar(char* pararchivename)
1091{
1092 if (!pararchivename || !strlen(pararchivename)) return -1;
1093 char processline[1024];
1094 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1095 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1096 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
1097 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1098 Form("%s.par",pararchivename));
1099 } else {
1100 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1101 return -1;
1102 }
1103 }
1104 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1105 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1106
1107 TString ocwd = gSystem->WorkingDirectory();
1108 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1109
1110 // check for BUILD.sh and execute
1111 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1112 printf("*******************************\n");
1113 printf("*** Building PAR archive ***\n");
1114 printf("*******************************\n");
1115 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1116 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1117 return -1;
1118 }
1119 }
1120
1121 // check for SETUP.C and execute
1122 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1123 printf("*******************************\n");
1124 printf("*** Setup PAR archive ***\n");
1125 printf("*******************************\n");
1126 gROOT->Macro("PROOF-INF/SETUP.C");
1127 }
1128 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1129 return 0;
1130}
1131
1132//______________________________________________________________________________
1133AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1134{
1135// Check if user has a valid token, otherwise make one. This has limitations.
1136// One can always follow the standard procedure of calling alien-token-init then
1137// source /tmp/gclient_env_$UID in the current shell.
1138 if (!AliAnalysisGrid::CreateToken()) return NULL;
1139 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1140// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1141 plugin->SetRunMode(plugin_mode);
1142 if (kPluginUseProductionMode) plugin->SetProductionMode();
1143 plugin->SetJobTag(kJobTag);
1144 plugin->SetNtestFiles(2);
1145// plugin->SetPreferedSE("ALICE::NIHAM::File");
1146// Set versions of used packages
e84da0a5 1147 plugin->SetAPIVersion("V1.1x");
1148 // plugin->SetAPIVersion("V1.0x");
1149// plugin->SetAPIVersion("V2.4");
c38e3b95 1150 plugin->SetROOTVersion(kPluginRootVersion);
1151 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1152// Declare input data to be processed.
1153// Method 1: Create automatically XML collections using alien 'find' command.
1154// Define production directory LFN
1155 plugin->SetGridDataDir(kGridDatadir.Data());
1156// Set data search pattern
1157 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1158 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1159// ...then add run numbers to be considered
1160// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1161 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1162 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1163 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1164 }
1165
1166 if(kGridLocalRunList.Length()>0){
1167 ifstream in1;
1168 in1.open(kGridLocalRunList.Data());
1169 int iRun;
e84da0a5 1170 char c;
1171 char cLine[250];
1172 while(!in1.eof()){
1173 c = in1.get();
1174 if ( (c >= '0') && (c <= '9') )
1175 {
1176 in1.putback (c);
1177 in1>>iRun;
1178 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1179 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1180 }
1181 else
1182 {
1183 in1.putback (c);
1184 in1.getline(cLine,250);
1185 Printf("AnalysisTrainPWG4Jets Skipping run number from File %s", cLine);
1186 }
c38e3b95 1187 }
1188 }
1189
1190// Method 2: Declare existing data files (raw collections, xml collections, root file)
1191// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1192// XML collections added via this method can be combined with the first method if
1193// the content is compatible (using or not tags)
1194// plugin->AddDataFile("tag.xml");
1195// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1196// Define alien work directory where all files will be copied. Relative to alien $HOME.
1197 if (iAODanalysis) plugin->SetGridWorkingDir("analysisAOD");
1198 else plugin->SetGridWorkingDir("analysisESD");
1199 // Declare alien output directory. Relative to working directory.
1200 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1201 plugin->SetGridOutputDir(kGridOutdir);
1202
1203 // Add external packages
1204 if (iJETAN||iDIJETAN) {
1205 plugin->AddExternalPackage("boost::v1_38_0");
1206 plugin->AddExternalPackage("cgal::v3.3.1");
1207 plugin->AddExternalPackage("fastjet::v2.4.0");
1208 }
1209
1210
1211 // set extra libs before par file compilation
1212 anaLibs += kGridExtraFiles;
1213 anaLibs = anaLibs.Strip();
e84da0a5 1214 Printf("anaLibs %s",anaLibs.Data());
1215 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1216
1217 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1218 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1219
1220 TString ana_sources = "";
1221 TString ana_add = "";
1222 if (kUsePAR && anaPars.Length()) {
1223 printf("%s\n", anaPars.Data());
1224 TObjArray *arr;
1225 TObjString *objstr;
1226 arr = anaPars.Tokenize(" ");
1227 TIter next(arr);
1228 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1229 delete arr;
1230 }
1231
1232// Declare the analysis source files names separated by blancs. To be compiled runtime
1233// using ACLiC on the worker nodes.
1234 ana_sources = anaSources.Strip();
1235// Declare all libraries (other than the default ones for the framework. These will be
1236// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1237
1238 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1239 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
1240// Declare the output file names separated by blancs.
1241// (can be like: file.root or file.root@ALICE::Niham::File)
1242 plugin->SetDefaultOutputs();
1243 plugin->SetMergeExcludes(kGridMergeExclude);
1244 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1245 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
1246// Optionally define the files to be archived.
1247// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
1248
1249
1250 // Put default output files to archive
1251 TString listhists = "";
1252 TString listaods = "";
1253 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1254 TIter next(mgr->GetOutputs());
1255 AliAnalysisDataContainer *output;
1256 while ((output=(AliAnalysisDataContainer*)next())) {
1257 const char *filename = output->GetFileName();
1258 if (!(strcmp(filename, "default"))) {
53c63663 1259 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1260 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1261 if (listaods.Length()) listaods += " ";
c38e3b95 1262 listaods += filename;
c38e3b95 1263 } else {
e84da0a5 1264 if(!listhists.Contains(filename)){
1265 if (listhists.Length()) listhists += " ";
c38e3b95 1266 listhists += filename;
1267 }
1268 }
1269 }
53c63663 1270
c28abe00 1271 if(kUseSysInfo>0){
e84da0a5 1272 if (listhists.Length()) listhists += " ";
c28abe00 1273 listhists += "syswatch.root";
53c63663 1274 }
1275
e84da0a5 1276 if(kIsMC){
1277 if (listaods.Length()) listaods += " ";
1278 listaods += "pyxsec_hists.root";
1279 }
1280
1281
53c63663 1282 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1283 if (listaods.Length()) listaods += " ";
53c63663 1284 listaods += mgr->GetExtraFiles();
c38e3b95 1285 }
53c63663 1286
1287 // if we do not fill the aod we do not need to store it
e84da0a5 1288 kGridMergeExclude = listaods;
1289
1290 if(!kFillAOD){
1291 listaods="";
1292 plugin->SetDefaultOutputs(kFALSE);
1293 plugin->SetOutputFiles(listhists.Data());
1294 }
53c63663 1295
e84da0a5 1296
1297 listaods.ReplaceAll(" ", ",");
1298 listhists.ReplaceAll(" ", ",");
c38e3b95 1299 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());;
1300 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());;
53c63663 1301
c38e3b95 1302 if (!listhists.Length() && !listaods.Length()) {
1303 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
1304 }
53c63663 1305
e84da0a5 1306
53c63663 1307
b2d64ef3 1308 TString outputArchive = "log_archive.zip:stdout,stderr@ALICE::FZK::SE,ALICE::GSI::SE";
1309 if(kUseSysInfo>0)outputArchive = "log_archive.zip:stdout,stderr,syswatch.log@ALICE::FZK::SE,ALICE::GSI::SE";
c38e3b95 1310 if (listaods.Length()) {
1311 outputArchive += " ";
1312 outputArchive += listaods;
1313 }
1314 if (listhists.Length()) {
1315 outputArchive += " ";
1316 outputArchive += listhists;
1317 }
1318 plugin->SetOutputArchive(outputArchive);
1319// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1320 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1321// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1322 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1323// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1324// plugin->SetMaxInitFailed(5);
1325// Optionally resubmit threshold.
1326// plugin->SetMasterResubmitThreshold(90);
1327// Optionally set time to live (default 30000 sec)
1328 plugin->SetTTL(30000);
1329// Optionally set input format (default xml-single)
1330 plugin->SetInputFormat("xml-single");
1331// Optionally modify the name of the generated JDL (default analysis.jdl)
1332 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1333// Optionally modify the executable name (default analysis.sh)
1334 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1335// Optionally modify job price (default 1)
1336 plugin->SetPrice(1);
1337// Optionally modify split mode (default 'se')
1338 plugin->SetSplitMode("se");
1339 return plugin;
1340}
1341
1342//______________________________________________________________________________
1343void WriteConfig()
1344{
1345// Write train configuration in a file. The file name has the format:
1346// train_[trainName]_ddMonthyyyy_time.C
1347 if (kUseDate) {
1348 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1349 ifstream fdate("date.tmp");
1350 if (!fdate.is_open()) {
1351 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1352 return;
1353 }
1354 const char date[64];
1355 fdate.getline(date,64);
1356 fdate.close();
1357 gSystem->Exec("rm date.tmp");
1358 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1359 } else {
1360 kTrainName = Form("train_%s", kTrainName.Data());
1361 }
1362 TString cdir = gSystem->WorkingDirectory();
1363 gSystem->MakeDirectory(kTrainName);
1364 gSystem->ChangeDirectory(kTrainName);
1365 ofstream out;
1366 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1367 if (out.bad()) {
1368 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1369 return;
1370 }
1371 out << "{" << endl;
1372 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1373 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1374 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1375 if (kProofUseAFPAR)
1376 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1377 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1378 out << " kPluginUse = " << kPluginUse << ";" << endl;
1379 out << " kUsePAR = " << kUsePAR << ";" << endl;
1380 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1381 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1382 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1383 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1384 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1385 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1386 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1387 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1388 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1389 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1390 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1391 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1392 out << " kUseDebug = " << kUseDebug << ";" << endl;
1393 out << " kUseMC = " << kUseMC << ";" << endl;
1394 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1395 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1396 out << " kUseTR = " << kUseTR << ";" << endl;
1397 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1398 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1399 out << " // Analysis modules" << endl;
1400 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1401 out << " iAODhandler = " << iAODhandler << ";" << endl;
1402 out << " iESDfilter = " << iESDfilter << ";" << endl;
1403 out << " iJETAN = " << iJETAN << ";" << endl;
1404 out << "// Configuration fot the wagons" << endl;
1405 out << "}" << endl;
1406 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1407 gSystem->ChangeDirectory(cdir);
1408}
1409
1410//______________________________________________________________________________
1411Bool_t LoadConfig(const char *filename)
1412{
1413// Read train configuration from file
1414 if (gSystem->AccessPathName(filename)) {
1415 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1416 return kFALSE;
1417 }
1418 gROOT->ProcessLine(Form(".x %s", filename));
1419 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1420 return kTRUE;
1421}
1422
1423Bool_t PatchJDL(){
1424 Printf(">>> Patching JDL");
1425 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1426 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1427 TGridJDL *jdl = gridHandler->GetGridJDL();
1428 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1429 gridHandler->WriteJDL(kFALSE);
1430 Printf("<<< Patching JDL");
1431 return kTRUE;
1432}
1433
1434Bool_t PatchAnalysisMacro(){
1435 Printf(">>> Patching AnalysisMacro");
1436 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
1437
1438 ifstream in1;
1439 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1440 char cLine[250];
1441 TString st;
1442 while(in1.getline(cLine,250)){
1443 st += cLine;
1444 st += "\n";
1445 }
1446 Int_t index;
1447 index = st.Index("gSystem->Load(\"libPhysics\");");
1448 index += strlen("gSystem->Load(\"libPhysics\");");
e84da0a5 1449 if(iJETAN&&kUsePAR){
c38e3b95 1450 TObjArray *arr;
1451 TObjString *objstr;
1452 arr = anaLibs.Tokenize(" ");
1453 TIter next(arr);
1454 TString add = "";
1455 add += "\n\n // added by CKB \n";
1456 while ((objstr=(TObjString*)next())){
e84da0a5 1457 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1458 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1459 }
1460 delete arr;
1461 add += "// BKC \n\n";
1462 st.Insert(index,add.Data());
1463 }
e84da0a5 1464
1465 if(kUseDebug){
1466 st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
1467 }
1468
c38e3b95 1469 ofstream out;
1470 out.open(Form("%s.C", kTrainName.Data()));
1471 if (out.bad()) {
1472 return kFALSE;
1473 }
1474 out << st << endl;
1475 Printf("<<< Patching AnalysisMacro");
1476 return kTRUE;
1477
1478}