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