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