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