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