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