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