1- Transverse quantities as a function of pt of highest track in the event instead...
[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
3878a941 276 if (kUseDebug){
277 mgr->SetDebugLevel(3);
278 }
279 mgr->SetDebugLevel(0);
280 AliLog::SetGlobalLogLevel(AliLog::kError);
c38e3b95 281 //==========================================================================
282 // Create the chain. In this example it is created only from ALIEN files but
283 // can be done to work in batch or grid mode as well.
284 TChain *chain = CreateChain(smode, plugin_mode);
285
286 //==========================================================================
287 // Load the tasks configuration macros for all wagons. These files are supposed now to be
288 // in the current workdir, but in AliEn they will be in the file catalog,
289 // mapped from AliRoot and pecified in the jdl input list.
290
291 // For now connection to top input container and common AOD output container
292 // is done in this macro, but in future these containers will be connected
293 // from each task configuration macro.
e84da0a5 294 if(iPhysicsSelection && !iAODanalysis){
d2e6cdd5 295 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
296 AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE);
e84da0a5 297 }
298
c38e3b95 299 if (iESDfilter && !iAODanalysis) {
300 // ESD filter task configuration.
301 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
302 AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
303 }
304
305 // AOD tags
306 if (kUseAODTags) {
307 AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
308 mgr->AddTask(tagTask);
309 AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag", TTree::Class(),
310 AliAnalysisManager::kOutputContainer, "AOD.tag.root");
311 mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
312 mgr->ConnectOutput(tagTask, 1, coutTags);
313 }
314
315 // Jet analysis
316 if (iJETAN) {
317 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
318 AliAnalysisTaskJets *taskjets = 0;
319 if(iJETAN&1)taskjets = AddTaskJets(kHighPtFilterMask);
b53f2e4f 320 if(iJETAN&2){
321 UInt_t selection = 0;
d2e6cdd5 322 if(!kFillAOD) selection = 0xffffff; //&~(1<<13);
b53f2e4f 323 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9;
324 AddTaskJetsDelta(kDeltaAODJetName.Data(),kHighPtFilterMask,kUseAODMC,selection);
325 }
c38e3b95 326 if (!taskjets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
327 }
328
329 if (iDIJETAN) {
330 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskDiJets.C");
331 AliAnalysisTaskDiJets *taskdijets = 0;
332 taskdijets = AddTaskDiJets();
333 if (!taskdijets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
334 }
335
c38e3b95 336 if(iPWG1QASym){
337 gROOT->LoadMacro("$ALICE_ROOT/prod/acrcaf/qa_pp/AddTaskQAsym.C");
338 AliAnalysisTaskQASym *taskQASym = AddTaskQAsym(-1);
339 if (!taskQASym) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQASym cannot run for this train conditions - EXCLUDED");
121e4bd5 340 }
c38e3b95 341
121e4bd5 342
343
344 if(iPWG4TmpSourceSara){
345 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskEta.C");
346 AliAnalysisTaskEta *taskEta = AddTaskEta();
347 if (!taskEta) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskEta cannot run for this train conditions - EXCLUDED");
c38e3b95 348 }
349
350 if(iPWG4JetServices){
351 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
352 AliAnalysisTaskJetServices *taskjetServ = 0;
353 taskjetServ = AddTaskJetServices();
354 if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
53c63663 355 if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
356 else taskjetServ->SetRunRange(104000,105000);
c28abe00 357 if(!kIsMC) taskjetServ->SetRealData(kTRUE);
b53f2e4f 358 if(!iPhysicsSelection)taskjetServ->SetUsePhysicsSelection(kFALSE);
c38e3b95 359 }
360
c38e3b95 361 if(iPWG4JetSpectrum){
362 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
363 AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
b53f2e4f 364 if(iPWG4JetSpectrum&1){
365 taskjetSpectrum = AddTaskJetSpectrum2("jets","",kHighPtFilterMask,iPhysicsSelection);
e6993a52 366 if(!iAODanalysis){
367 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection); // tmp hack to give it a different name
368 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);
369 }
d2e6cdd5 370 if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
3878a941 371 taskjetSpectrum->SetDebugLevel(1);
b53f2e4f 372 }
d2e6cdd5 373
e6993a52 374 if(iPWG4JetSpectrum&2){
375 UInt_t selection = 0;
376 if(!iAODanalysis) selection = 0xffffff;
377 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
378 AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
379 }
380 if(iJETAN&3&&!kFillAOD&!iAODanalysis){
565584e8 381 AddTaskJetSpectrum2("jetsAOD_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
b53f2e4f 382 AddTaskJetSpectrum2("jetsAOD_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
383 AddTaskJetSpectrum2("jetsAOD_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
384 AddTaskJetSpectrum2("jetsAOD_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
385 AddTaskJetSpectrum2("jetsAOD_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
565584e8 386 if(kIsMC){
387 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
565584e8 388 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
389 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
390 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
391 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
392 }
b53f2e4f 393 }
c38e3b95 394 }
c38e3b95 395 if(iPWG4UE){
396 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
397 AliAnalysisTaskUE *taskUE = 0;
398 if(iPWG4UE&1)taskUE = AddTaskUE();
399 if(iPWG4UE&2){
2bb1f4ca 400 taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV");
401 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","LJ","TRANSV");
402 taskUE = AddTaskUE("jetsAOD_UA1LO07","CDF","BB","TRANSV");
403 taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV");
404 taskUE = AddTaskUE("jetsAOD_FASTJET04","CDF","LJ","TRANSV");
405 taskUE = AddTaskUE("jetsAOD_SISCONE04","CDF","LJ","TRANSV");
d2e6cdd5 406 taskUE = AddTaskUE("jetsAOD_CDF07","ALICE","LJ","TRANSV");
407 taskUE = AddTaskUE("jetsAOD_UA1LO07","ALICE","LJ","TRANSV");
408 taskUE = AddTaskUE("jetsAOD_UA1LO07","ALICE","BB","TRANSV");
409 taskUE = AddTaskUE("jetsAOD_FASTKT04","ALICE","LJ","TRANSV");
410 taskUE = AddTaskUE("jetsAOD_FASTJET04","ALICE","LJ","TRANSV");
411 taskUE = AddTaskUE("jetsAOD_SISCONE04","ALICE","LJ","TRANSV");
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) {
687 // ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "iPWG2evchar disabled if not reading track references");
688 }
e84da0a5 689 if (iJETAN){
690 iESDfilter=1;
691 }
c38e3b95 692 if (!iESDfilter){
693 kUseKinefilter = kFALSE;
694 kUseMuonfilter = kFALSE;
695 }
696 if(!iJETAN){
697 iPWG4JetSpectrum = iPWG4UE = iPWG4ThreeJets = iDIJETAN = 0;
698 }
699 }
700 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4ThreeJets;
d2e6cdd5 701 iPWG4PartCorrLibs = iPWG4PartCorr||iPWG4Tagged||iPWG4CaloQA;
e6993a52 702 iJETANLib = iPWG4JetTasks||iJETAN||iDIJETAN;
c38e3b95 703 if (iESDfilter) {iAODhandler=1;}
704 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
705 if (kUseAODTags && !iAODhandler) kUseAODTags = kFALSE;
706
707
708
709}
710
711//______________________________________________________________________________
712Bool_t Connect(const char *mode) {
713// Connect <username> to the back-end system.
714 Int_t imode = -1;
715 if (!strcmp(mode, "LOCAL")) imode = 0;
716 if (!strcmp(mode, "PROOF")) imode = 1;
717 if (!strcmp(mode, "GRID")) imode = 2;
718 TString username = gSystem->Getenv("alien_API_USER");
719 switch (imode) {
720 case 0:
721 break;
722 case 1:
723 if (!username.Length()) {
724 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
725 1. Have called: alien-token-init <username>\n \
726 2. Have called: >source /tmp/gclient_env_$UID");
727 return kFALSE;
728 }
729 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
730 username.Data(), kProofCluster.Data());
731 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
732// TProof::Open(Form("%s@%s:31093", username.Data(), kProofCluster.Data()));
733 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
734 if (!gProof) {
735 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
736 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
737 return kFALSE;
738 }
739 if(kProofClearPackages)gProof->ClearPackages();
740
741 if(kProofSaveToAlien){
742 TGrid::Connect("alien://");
743 if (gGrid) {
744 TString homedir = gGrid->GetHomeDirectory();
745 TString workdir = homedir + kTrainName;
746 if (!gGrid->Cd(workdir)) {
747 gGrid->Cd(homedir);
748 if (gGrid->Mkdir(workdir)) {
749 gGrid->Cd(kTrainName);
750 ::Info("AnalysisTrainPWG4Jets::Connect()", "Directory %s created", gGrid->Pwd());
751 }
752 }
753 gGrid->Mkdir("proof_output");
754 gGrid->Cd("proof_output");
755 kProofOutdir = Form("alien://%s", gGrid->Pwd());
756 }
757 }
758 break;
759 case 2:
760 if (!username.Length()) {
761 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
762 1. Have called: alien-token-init <username>\n \
763 2. Have called: >source /tmp/gclient_env_$UID");
764 return kFALSE;
765 }
766 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
767 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode),
768 "When using the AliEn plugin it is preferable to define the \
769 variable alien_CLOSE_SE in your environment.");
770 return kFALSE;
771 }
772 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to AliEn ...",
773 username.Data());
774 TGrid::Connect("alien://");
775 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
776 break;
777 default:
778 ::Error("AnalysisTrainPWG4Jets.C::Connect", "Unknown run mode: %s", mode);
779 return kFALSE;
780 }
781 ::Info("AnalysisTrainPWG4Jets.C::Connect","Connected in %s mode", mode);
782 return kTRUE;
783}
784
785//______________________________________________________________________________
786Bool_t LoadCommonLibraries(const char *mode)
787{
788// Load common analysis libraries.
789 Int_t imode = -1;
790 if (!strcmp(mode, "LOCAL")) imode = 0;
791 if (!strcmp(mode, "PROOF")) imode = 1;
792 if (!strcmp(mode, "GRID")) imode = 2;
793 if (!gSystem->Getenv("ALICE_ROOT")) {
794 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
795 return kFALSE;
796 }
797 Bool_t success = kTRUE;
798 // ROOT libraries
799 gSystem->Load("libTree.so");
800 gSystem->Load("libGeom.so");
801 gSystem->Load("libVMC.so");
802 gSystem->Load("libPhysics.so");
803
804 // Load framework classes. Par option ignored here.
805 switch (imode) {
806 case 0:
807 case 2:
808 if (kUseCPAR) {
809 success &= LoadLibrary("STEERBase", mode, kTRUE);
810 success &= LoadLibrary("ESD", mode, kTRUE);
811 success &= LoadLibrary("AOD", mode, kTRUE);
812 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
813 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
814 success &= LoadLibrary("CORRFW", mode, kTRUE);
815 } else {
816 success &= LoadLibrary("libSTEERBase.so", mode);
817 success &= LoadLibrary("libESD.so", mode);
818 success &= LoadLibrary("libAOD.so", mode);
819 success &= LoadLibrary("libANALYSIS.so", mode);
820 success &= LoadLibrary("libANALYSISalice.so", mode);
821 success &= LoadLibrary("libCORRFW.so", mode);
822 gROOT->ProcessLine(".include $ALICE_ROOT/include");
823 }
824 break;
825 case 1:
826 Int_t ires = -1;
827 if (kProofUseAFPAR && !gSystem->AccessPathName(kProofAFversion)) ires = gProof->UploadPackage(kProofAFversion);
828 if (ires < 0) {
829 success &= LoadLibrary("STEERBase", mode);
830 success &= LoadLibrary("ESD", mode);
831 success &= LoadLibrary("AOD", mode);
832 success &= LoadLibrary("ANALYSIS", mode);
833 success &= LoadLibrary("ANALYSISalice", mode);
834 success &= LoadLibrary("CORRFW", mode);
835 } else {
836 ires = gProof->EnablePackage(kProofAFversion);
837 if (ires<0) success = kFALSE;
838 success &= LoadLibrary("CORRFW", mode);
839 }
840 break;
841 default:
842 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
843 return kFALSE;
844 }
845 if (success) {
846 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
847 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
848 gSystem->GetIncludePath());
849 } else {
850 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: FAILED");
851 }
852
853 return success;
854}
855
856//______________________________________________________________________________
857Bool_t LoadAnalysisLibraries(const char *mode)
858{
859// Load common analysis libraries.
860 Bool_t success = kTRUE;
861 if (iESDfilter) {
862 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
863 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
864 }
865 // JETAN
e6993a52 866 if (iJETANLib) {
b53f2e4f 867 // this part needs some rework in case we do not need the fastjed finders for processing
868 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 869 if (!strcmp(mode, "PROOF")){
ef1e462f 870 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 871 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
872 // problem when loading siscone copiled with different gcc version??
873 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
874 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
875 }
b53f2e4f 876 if(!kUsePAR){
e84da0a5 877 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
878 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
879 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
880 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
881 }
882 else{
883 // par files plus FASTJET needs some extra work... need to change
884 // the loading sequence in the auto generated .C file
885 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
886 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
887 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
888 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
889 }
c38e3b95 890 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
891 }
892 if(iPWG4JetTasks){
893 // PWG4 particle correlations
894 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
895 }
896 if(iPWG1QASym){
3878a941 897 if (!LoadSource(Form("%s/prod/acrcaf/qa_pp/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
c38e3b95 898 }
121e4bd5 899 if(iPWG4TmpSourceSara){
2bb1f4ca 900 // gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 901 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
902 }
911a740f 903 if (iPWG4PartCorrLibs) {
c38e3b95 904 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
905 !LoadLibrary("PHOSUtils", mode, kTRUE) ||
906 !LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
907 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
908 }
d2e6cdd5 909 if (iPWG4JetCorr) {
910 if (!LoadLibrary("PWG4JetCorrel", mode, kTRUE)) return kFALSE;
911 }
121e4bd5 912 if (iPWG4omega3pi) {
913 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
914 }
53c63663 915 if (iPWG4GammaConv) {
916 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
917 }
c38e3b95 918
919 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
920 return kTRUE;
921}
922
923//______________________________________________________________________________
924Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
925{
926// Load a module library in a given mode. Reports success.
927 Int_t imode = -1;
928 Int_t result;
929 TString smodule(module);
930 if (!strcmp(mode, "LOCAL")) imode = 0;
931 if (!strcmp(mode, "PROOF")) imode = 1;
932 if (!strcmp(mode, "GRID")) imode = 2;
933 TString mod(module);
934 if (!mod.Length()) {
935 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
936 return kFALSE;
937 }
938 // If a library is specified, just load it
939 if (smodule.EndsWith(".so")) {
940 mod.Remove(mod.Index(".so"));
941 result = gSystem->Load(mod);
942 if (result < 0) {
943 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
944 return kFALSE;
945 }
946 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 947 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 948 return kTRUE;
949 }
950 // Check if the library is already loaded
951 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
952 return kTRUE;
953 switch (imode) {
954 case 0:
955 case 2:
956 if (kUsePAR) {
957 result = SetupPar(module);
958 if (rec) anaPars += Form("%s.par ", module);
959 } else {
960 result = gSystem->Load(Form("lib%s.so", module));
961 if (rec) anaLibs += Form("lib%s.so ", module);
962 }
963 break;
964 case 1:
965 if(!gSystem->AccessPathName(module)){
966 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
967 gSystem->Exec(Form("rm -rf %s",module));
968 }
969 result = gProof->UploadPackage(module);
970 if (result<0) {
971 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
972 if (result<0) {
973 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
974 return kFALSE;
975 }
976 }
977 result = gProof->EnablePackage(module);
978 break;
979 default:
980 return kFALSE;
981 }
982 if (result < 0) {
983 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
984 return kFALSE;
985 }
986 return kTRUE;
987}
988
989
990
991//______________________________________________________________________________
992Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
993{
994// Load a module library in a given mode. Reports success.
995 Int_t imode = -1;
996 Int_t result = -1;
997 if (!strcmp(mode, "LOCAL")) imode = 0;
998 if (!strcmp(mode, "PROOF")) imode = 1;
999 if (!strcmp(mode, "GRID")) imode = 2;
1000 TString ssource(source);
1001 TString basename = gSystem->BaseName(ssource.Data());
1002 if (!ssource.Length()) {
1003 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
1004 return kFALSE;
1005 }
1006 // we have a source code so compile it
1007 if (ssource.EndsWith(".cxx")) {
1008 // need to copy it here other wise the path is also used on grid...
1009 ssource.Remove(ssource.Index(".cxx"));
1010 basename.Remove(basename.Index(".cxx"));
1011 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
1012 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
1013 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
1014 // Path to code
1015 // only needed for local compilation, in grid and proof mode
1016 // the task headers are uploaded
1017 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
1018 // Printf("LoadSources:: Including path %s",path.Data());
1019 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
1020 Printf("LoadSources:: Loading... path %s",basename.Data());
1021 switch (imode) {
1022 case 0:
b53f2e4f 1023 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1024 break;
1025 case 1:
b53f2e4f 1026 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1027 break;
1028 case 2:
b53f2e4f 1029 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1030 if (rec){
1031 // what we want to compile
1032 anaSources += Form("%s.cxx ",basename.Data());
1033 // what we need as input...
1034 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
1035 }
1036 break;
1037 default:
1038 return kFALSE;
1039 }
1040 }
1041 if (result < 0) {
1042 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
1043 return kFALSE;
1044 }
1045 return kTRUE;
1046}
1047
1048
1049//______________________________________________________________________________
1050TChain *CreateChain(const char *mode, const char *plugin_mode)
1051{
1052// Create the input chain
1053 Int_t imode = -1;
1054 if (!strcmp(mode, "LOCAL")) imode = 0;
1055 if (!strcmp(mode, "PROOF")) imode = 1;
1056 if (!strcmp(mode, "GRID")) imode = 2;
1057 TChain *chain = NULL;
1058 // Local chain
1059 switch (imode) {
1060 case 0:
1061 if (iAODanalysis) {
1062 if (!kLocalXMLDataset.Length()) {
1063 // Local AOD
1064 chain = new TChain("aodTree");
1065 TString line;
1066 ifstream in;
1067 in.open(kLocalDataList.Data());
1068 while (in.good()) {
1069 in >> line;
1070 if (line.Length() == 0) continue;
1071 // cout << " line = " << line << endl;
1072 chain->Add(line.Data());
1073 }
1074 } else {
1075 // Interactive AOD
1076 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1077 }
1078 } else {
1079 if (!kLocalXMLDataset.Length()) {
1080 // Local ESD
1081 chain = new TChain("esdTree");
1082 TString line;
1083 ifstream in;
1084 in.open(kLocalDataList.Data());
1085 while (in.good()) {
1086 in >> line;
1087 if (line.Length() == 0) continue;
1088 cout << " line = " << line << endl;
1089 chain->Add(line.Data());
1090 }
1091 } else {
1092 // Interactive ESD
1093 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1094 }
1095 }
1096 break;
1097 case 1:
1098 break;
1099 case 2:
1100 if (kPluginUse) {
1101// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1102// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1103 } else {
1104 TString treeName = "esdTree";
1105 if (iAODanalysis) treeName = "aodTree";
1106 chain = CreateChainSingle("wn.xml", treeName);
1107 }
1108 break;
1109 default:
1110 }
1111 if (chain && chain->GetNtrees()) return chain;
1112 return NULL;
1113}
1114
1115//______________________________________________________________________________
1116TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1117{
1118 printf("*******************************\n");
1119 printf("*** Getting the ESD Chain ***\n");
1120 printf("*******************************\n");
1121 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1122
1123 if (!myCollection) {
1124 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1125 return NULL ;
1126 }
1127
1128 TChain* chain = new TChain(treeName);
1129 myCollection->Reset() ;
1130 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1131 chain->ls();
1132 return chain;
1133}
1134
1135//______________________________________________________________________________
1136Int_t SetupPar(char* pararchivename)
1137{
1138 if (!pararchivename || !strlen(pararchivename)) return -1;
1139 char processline[1024];
1140 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1141 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1142 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
1143 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1144 Form("%s.par",pararchivename));
1145 } else {
1146 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1147 return -1;
1148 }
1149 }
1150 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1151 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1152
1153 TString ocwd = gSystem->WorkingDirectory();
1154 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1155
1156 // check for BUILD.sh and execute
1157 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1158 printf("*******************************\n");
1159 printf("*** Building PAR archive ***\n");
1160 printf("*******************************\n");
1161 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1162 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1163 return -1;
1164 }
1165 }
1166
1167 // check for SETUP.C and execute
1168 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1169 printf("*******************************\n");
1170 printf("*** Setup PAR archive ***\n");
1171 printf("*******************************\n");
1172 gROOT->Macro("PROOF-INF/SETUP.C");
1173 }
1174 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1175 return 0;
1176}
1177
1178//______________________________________________________________________________
1179AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1180{
1181// Check if user has a valid token, otherwise make one. This has limitations.
1182// One can always follow the standard procedure of calling alien-token-init then
1183// source /tmp/gclient_env_$UID in the current shell.
1184 if (!AliAnalysisGrid::CreateToken()) return NULL;
1185 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1186// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1187 plugin->SetRunMode(plugin_mode);
1188 if (kPluginUseProductionMode) plugin->SetProductionMode();
1189 plugin->SetJobTag(kJobTag);
1190 plugin->SetNtestFiles(2);
1191// plugin->SetPreferedSE("ALICE::NIHAM::File");
1192// Set versions of used packages
e84da0a5 1193 plugin->SetAPIVersion("V1.1x");
1194 // plugin->SetAPIVersion("V1.0x");
1195// plugin->SetAPIVersion("V2.4");
c38e3b95 1196 plugin->SetROOTVersion(kPluginRootVersion);
1197 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1198// Declare input data to be processed.
1199// Method 1: Create automatically XML collections using alien 'find' command.
1200// Define production directory LFN
1201 plugin->SetGridDataDir(kGridDatadir.Data());
1202// Set data search pattern
1203 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1204 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1205// ...then add run numbers to be considered
1206// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1207 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1208 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1209 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1210 }
1211
1212 if(kGridLocalRunList.Length()>0){
1213 ifstream in1;
1214 in1.open(kGridLocalRunList.Data());
1215 int iRun;
e84da0a5 1216 char c;
1217 char cLine[250];
1218 while(!in1.eof()){
1219 c = in1.get();
1220 if ( (c >= '0') && (c <= '9') )
1221 {
1222 in1.putback (c);
1223 in1>>iRun;
1224 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1225 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1226 }
1227 else
1228 {
1229 in1.putback (c);
1230 in1.getline(cLine,250);
1231 Printf("AnalysisTrainPWG4Jets Skipping run number from File %s", cLine);
1232 }
c38e3b95 1233 }
1234 }
1235
1236// Method 2: Declare existing data files (raw collections, xml collections, root file)
1237// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1238// XML collections added via this method can be combined with the first method if
1239// the content is compatible (using or not tags)
1240// plugin->AddDataFile("tag.xml");
1241// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1242// Define alien work directory where all files will be copied. Relative to alien $HOME.
3878a941 1243 TString alien_workdir = "";
1244
1245 if (iAODanalysis) alien_workdir += "analysisAOD";
1246 else alien_workdir += "analysisESD";
1247 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
1248 plugin->SetGridWorkingDir(alien_workdir.Data());
1249
c38e3b95 1250 // Declare alien output directory. Relative to working directory.
1251 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1252 plugin->SetGridOutputDir(kGridOutdir);
1253
1254 // Add external packages
1255 if (iJETAN||iDIJETAN) {
1256 plugin->AddExternalPackage("boost::v1_38_0");
1257 plugin->AddExternalPackage("cgal::v3.3.1");
1258 plugin->AddExternalPackage("fastjet::v2.4.0");
1259 }
1260
1261
1262 // set extra libs before par file compilation
1263 anaLibs += kGridExtraFiles;
1264 anaLibs = anaLibs.Strip();
e84da0a5 1265 Printf("anaLibs %s",anaLibs.Data());
1266 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1267
1268 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1269 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1270
1271 TString ana_sources = "";
1272 TString ana_add = "";
1273 if (kUsePAR && anaPars.Length()) {
1274 printf("%s\n", anaPars.Data());
1275 TObjArray *arr;
1276 TObjString *objstr;
1277 arr = anaPars.Tokenize(" ");
1278 TIter next(arr);
1279 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1280 delete arr;
1281 }
1282
1283// Declare the analysis source files names separated by blancs. To be compiled runtime
1284// using ACLiC on the worker nodes.
1285 ana_sources = anaSources.Strip();
1286// Declare all libraries (other than the default ones for the framework. These will be
1287// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1288
1289 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1290 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
1291// Declare the output file names separated by blancs.
1292// (can be like: file.root or file.root@ALICE::Niham::File)
1293 plugin->SetDefaultOutputs();
1294 plugin->SetMergeExcludes(kGridMergeExclude);
1295 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1296 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
1297// Optionally define the files to be archived.
1298// plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
1299
1300
1301 // Put default output files to archive
1302 TString listhists = "";
1303 TString listaods = "";
1304 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1305 TIter next(mgr->GetOutputs());
1306 AliAnalysisDataContainer *output;
1307 while ((output=(AliAnalysisDataContainer*)next())) {
1308 const char *filename = output->GetFileName();
1309 if (!(strcmp(filename, "default"))) {
53c63663 1310 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1311 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1312 if (listaods.Length()) listaods += " ";
c38e3b95 1313 listaods += filename;
c38e3b95 1314 } else {
e84da0a5 1315 if(!listhists.Contains(filename)){
1316 if (listhists.Length()) listhists += " ";
c38e3b95 1317 listhists += filename;
1318 }
1319 }
1320 }
53c63663 1321
c28abe00 1322 if(kUseSysInfo>0){
e84da0a5 1323 if (listhists.Length()) listhists += " ";
c28abe00 1324 listhists += "syswatch.root";
53c63663 1325 }
1326
e84da0a5 1327 if(kIsMC){
1328 if (listaods.Length()) listaods += " ";
1329 listaods += "pyxsec_hists.root";
1330 }
1331
1332
53c63663 1333 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1334 if (listaods.Length()) listaods += " ";
53c63663 1335 listaods += mgr->GetExtraFiles();
c38e3b95 1336 }
53c63663 1337
1338 // if we do not fill the aod we do not need to store it
e84da0a5 1339 kGridMergeExclude = listaods;
1340
1341 if(!kFillAOD){
1342 listaods="";
1343 plugin->SetDefaultOutputs(kFALSE);
1344 plugin->SetOutputFiles(listhists.Data());
1345 }
53c63663 1346
e84da0a5 1347
1348 listaods.ReplaceAll(" ", ",");
1349 listhists.ReplaceAll(" ", ",");
c38e3b95 1350 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());;
1351 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());;
53c63663 1352
c38e3b95 1353 if (!listhists.Length() && !listaods.Length()) {
1354 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
1355 }
53c63663 1356
e84da0a5 1357
53c63663 1358
b2d64ef3 1359 TString outputArchive = "log_archive.zip:stdout,stderr@ALICE::FZK::SE,ALICE::GSI::SE";
1360 if(kUseSysInfo>0)outputArchive = "log_archive.zip:stdout,stderr,syswatch.log@ALICE::FZK::SE,ALICE::GSI::SE";
c38e3b95 1361 if (listaods.Length()) {
1362 outputArchive += " ";
1363 outputArchive += listaods;
1364 }
1365 if (listhists.Length()) {
1366 outputArchive += " ";
1367 outputArchive += listhists;
1368 }
1369 plugin->SetOutputArchive(outputArchive);
1370// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1371 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1372// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1373 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1374// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1375// plugin->SetMaxInitFailed(5);
1376// Optionally resubmit threshold.
1377// plugin->SetMasterResubmitThreshold(90);
1378// Optionally set time to live (default 30000 sec)
1379 plugin->SetTTL(30000);
1380// Optionally set input format (default xml-single)
1381 plugin->SetInputFormat("xml-single");
1382// Optionally modify the name of the generated JDL (default analysis.jdl)
1383 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1384// Optionally modify the executable name (default analysis.sh)
1385 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1386// Optionally modify job price (default 1)
1387 plugin->SetPrice(1);
1388// Optionally modify split mode (default 'se')
1389 plugin->SetSplitMode("se");
1390 return plugin;
1391}
1392
1393//______________________________________________________________________________
1394void WriteConfig()
1395{
1396// Write train configuration in a file. The file name has the format:
1397// train_[trainName]_ddMonthyyyy_time.C
1398 if (kUseDate) {
1399 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1400 ifstream fdate("date.tmp");
1401 if (!fdate.is_open()) {
1402 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1403 return;
1404 }
1405 const char date[64];
1406 fdate.getline(date,64);
1407 fdate.close();
1408 gSystem->Exec("rm date.tmp");
1409 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1410 } else {
1411 kTrainName = Form("train_%s", kTrainName.Data());
1412 }
1413 TString cdir = gSystem->WorkingDirectory();
1414 gSystem->MakeDirectory(kTrainName);
1415 gSystem->ChangeDirectory(kTrainName);
1416 ofstream out;
1417 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1418 if (out.bad()) {
1419 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1420 return;
1421 }
1422 out << "{" << endl;
1423 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1424 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1425 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1426 if (kProofUseAFPAR)
1427 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1428 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1429 out << " kPluginUse = " << kPluginUse << ";" << endl;
1430 out << " kUsePAR = " << kUsePAR << ";" << endl;
1431 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1432 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1433 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1434 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1435 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1436 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1437 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1438 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1439 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1440 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1441 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1442 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1443 out << " kUseDebug = " << kUseDebug << ";" << endl;
1444 out << " kUseMC = " << kUseMC << ";" << endl;
1445 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1446 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1447 out << " kUseTR = " << kUseTR << ";" << endl;
1448 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1449 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1450 out << " // Analysis modules" << endl;
1451 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1452 out << " iAODhandler = " << iAODhandler << ";" << endl;
1453 out << " iESDfilter = " << iESDfilter << ";" << endl;
1454 out << " iJETAN = " << iJETAN << ";" << endl;
1455 out << "// Configuration fot the wagons" << endl;
1456 out << "}" << endl;
1457 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1458 gSystem->ChangeDirectory(cdir);
1459}
1460
1461//______________________________________________________________________________
1462Bool_t LoadConfig(const char *filename)
1463{
1464// Read train configuration from file
1465 if (gSystem->AccessPathName(filename)) {
1466 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1467 return kFALSE;
1468 }
1469 gROOT->ProcessLine(Form(".x %s", filename));
1470 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1471 return kTRUE;
1472}
1473
1474Bool_t PatchJDL(){
1475 Printf(">>> Patching JDL");
1476 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1477 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1478 TGridJDL *jdl = gridHandler->GetGridJDL();
1479 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1480 gridHandler->WriteJDL(kFALSE);
1481 Printf("<<< Patching JDL");
1482 return kTRUE;
1483}
1484
1485Bool_t PatchAnalysisMacro(){
1486 Printf(">>> Patching AnalysisMacro");
1487 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
1488
1489 ifstream in1;
1490 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1491 char cLine[250];
1492 TString st;
1493 while(in1.getline(cLine,250)){
1494 st += cLine;
1495 st += "\n";
1496 }
1497 Int_t index;
1498 index = st.Index("gSystem->Load(\"libPhysics\");");
1499 index += strlen("gSystem->Load(\"libPhysics\");");
e84da0a5 1500 if(iJETAN&&kUsePAR){
c38e3b95 1501 TObjArray *arr;
1502 TObjString *objstr;
1503 arr = anaLibs.Tokenize(" ");
1504 TIter next(arr);
1505 TString add = "";
1506 add += "\n\n // added by CKB \n";
1507 while ((objstr=(TObjString*)next())){
e84da0a5 1508 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1509 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1510 }
1511 delete arr;
3878a941 1512 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
c38e3b95 1513 add += "// BKC \n\n";
1514 st.Insert(index,add.Data());
1515 }
e84da0a5 1516
1517 if(kUseDebug){
1518 st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
1519 }
1520
c38e3b95 1521 ofstream out;
1522 out.open(Form("%s.C", kTrainName.Data()));
1523 if (out.bad()) {
1524 return kFALSE;
1525 }
1526 out << st << endl;
1527 Printf("<<< Patching AnalysisMacro");
1528 return kTRUE;
1529
1530}