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