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