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