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