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