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