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