fixed usage of selection mask and fixed typo in histogram name
[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
66Long_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
89Int_t iPWG4TmpSourceFrag = 0; // Bastian's Fragmentation function not in svn
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);
e84da0a5 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);
224 printf(printMask,"PWG4 Source BB",iPWG4TmpSourceFrag);
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.
354 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
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
c166d299 424 if(iPWG4TmpSourceFrag){
425 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskFragFunc.C");
426 UInt_t selection = 1<<2;
427 AliAnalysisTaskFragFunc *taskFrag = AddTaskFragFunc(kHighPtFilterMask, kUseAODMC,iPhysicsSelection, selection);
428 if (!taskFrag) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskFragFunc cannot run for this train conditions - EXCLUDED");
429 }
430
c580ebbb 431
9f77f0ce 432 if(iPWG4JetChem){
433 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetChem.C");
434 AliAnalysisTask *taskChem = AddTaskJetChem();
c580ebbb 435 if (!taskChem) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetChem cannot run for this train conditions - EXCLUDED");
436 }
437
438
c38e3b95 439 if(iPWG4JetServices){
440 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
441 AliAnalysisTaskJetServices *taskjetServ = 0;
442 taskjetServ = AddTaskJetServices();
443 if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
53c63663 444 if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
0971dabc 445 else taskjetServ->SetRunRange(104000,125000);
c28abe00 446 if(!kIsMC) taskjetServ->SetRealData(kTRUE);
dc6a7461 447 taskjetServ->SetUsePhysicsSelection((Bool_t)iPhysicsSelection);
9f77f0ce 448 taskjetServ->SetDebugLevel(0);
c38e3b95 449 }
450
c38e3b95 451 if(iPWG4JetSpectrum){
452 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
453 AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
b53f2e4f 454 if(iPWG4JetSpectrum&1){
17d96675 455 taskjetSpectrum = AddTaskJetSpectrum2("jets","","",kHighPtFilterMask,iPhysicsSelection);
e6993a52 456 if(!iAODanalysis){
d3af0232 457 // taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection); // tmp hack to give it a different name
58ef946c 458 // taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);
46534866 459
f2dd0695 460 if(kIsMC){
17d96675 461
462 UInt_t eventSelection = AliAnalysisHelperJetTasks::kIsPileUp|AliAnalysisHelperJetTasks::kVertexIn;
463 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
464 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
465 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC2_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
466
467 eventSelection = AliAnalysisHelperJetTasks::kIsCosmic|AliAnalysisHelperJetTasks::kVertexIn;
468 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
469 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
470
471 eventSelection = AliAnalysisHelperJetTasks::kNone;
472 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC2_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
473 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
46534866 474
475 }
476 else{
17d96675 477 UInt_t eventSelection = AliAnalysisHelperJetTasks::kIsPileUp|AliAnalysisHelperJetTasks::kVertexIn;
478 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
479 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
480
481 eventSelection = AliAnalysisHelperJetTasks::kIsCosmic|AliAnalysisHelperJetTasks::kVertexIn;
482 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
483 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
f2dd0695 484 }
e6993a52 485 }
d2e6cdd5 486 if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
17d96675 487 // taskjetSpectrum->SetDebugLevel(1);
b53f2e4f 488 }
d2e6cdd5 489
e6993a52 490 if(iPWG4JetSpectrum&2){
491 UInt_t selection = 0;
17d96675 492 if(!iAODanalysis){
493 selection = 0xffffff;
494 // switch off 07 radii
495 selection &= ~(1<<6)&~(1<<11)&~(1<<12)&~(1<<13)&~(1<<14);
496 }
e6993a52 497 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
498 AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
499 }
c38e3b95 500 }
58ef946c 501 if(iPWG4JCORRAN){
502 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJCORRANTask.C");
4721d8c5 503 AliJCORRANTask* corran = AddTaskJCORRAN(kDeltaAODJCORRANName.Data(),0);
58ef946c 504 if(!corran)::Warning("AnalysisTrainPWG4Jets", "AliJCORRANTask cannot run for this train conditions - EXCLUDED");
4721d8c5 505 else{
506 if(kDeltaAODJCORRANName.Length()>0)mgr->RegisterExtraFile(kDeltaAODJCORRANName.Data());
507 }
58ef946c 508 }
509
c38e3b95 510 if(iPWG4UE){
511 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
512 AliAnalysisTaskUE *taskUE = 0;
513 if(iPWG4UE&1)taskUE = AddTaskUE();
514 if(iPWG4UE&2){
94ee88d4 515 taskUE =AddTaskUE("jetsAOD_CDF04","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
17d96675 516 // taskUE =AddTaskUE("jetsAOD_CDF07","CDF", "LJ", "TRANSV","MSP");
94ee88d4 517 taskUE =AddTaskUE("jetsAOD_SISCONE04","CDF", "LJ", "TRANSV","MSP");
17d96675 518 // taskUE =AddTaskUE("jetsAOD_SISCONE07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
94ee88d4 519 taskUE =AddTaskUE("jetsAOD_ICDF","CDF","LJ","TRANSV","MSP");
520 taskUE =AddTaskUE("jetsAOD_FASTKT04","CDF", "LJ", "TRANSV","MSP");
17d96675 521 // taskUE =AddTaskUE("jetsAOD_FASTKT07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
58ef946c 522 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta05", "TRANSV","MSP");
523 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta09", "TRANSV","MSP");
c38e3b95 524 }
2bb1f4ca 525
c38e3b95 526 if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
527 }
9748e967 528 if(iPWG4CorrectionsUE){
529 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCorrectionsUE.C");
530 AliAnalysisTaskCorrectionsUE *taskCorrectionsUE = 0;
531 if(iPWG4CorrectionsUE&1)taskCorrectionsUE = AddTaskCorrectionsUE("jetsAOD_NONE","CDF","MP_eta05","TRANSV","MSP",kFALSE);
532 if (!taskCorrectionsUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCorrectionsUE cannot run for this train conditions - EXCLUDED");
533 }
c38e3b95 534
535 if(iPWG4ThreeJets){
536 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
537 AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
538 if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
539 }
c38e3b95 540 if(iPWG4PtQAMC){
541 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
542 AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
543 if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
544 }
545
546 if(iPWG4PtQATPC){
547 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
10295ac3 548 AliPWG4HighPtQATPConly *taskQATPC = 0;
549 if(iPWG4PtQATPC&1)taskQATPC = AddTaskPWG4HighPtQATPConly(1);
550 if(iPWG4PtQATPC&2)taskQATPC = AddTaskPWG4HighPtQATPConly(2);
551
552 if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
c38e3b95 553 }
3878a941 554
1f329128 555 if(iPWG4Cosmics){
556 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4CosmicCandidates.C");
557
558 AliPWG4CosmicCandidates *taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(0);
559 taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(1);
560
561 if (!taskPWG4CosmicCandidates) ::Warning("AnalysisTrainPWG4Jets", "AddTaskPWG4CosmicCandidates cannot run for this train conditions - EXCLUDED");
562 }
563
564
c38e3b95 565 if(iPWG4PtSpectra){
566 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
567 AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
568 if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
569 }
b53f2e4f 570 if(iPWG4KMeans){
571 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
572 AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
573 if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
574 }
575
d2e6cdd5 576 if(iPWG4Cluster){
577 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCluster.C");
578 AliAnalysisTaskJetCluster *taskCl = 0;
6408fe42 579 if(iPWG4Cluster&1){
580 taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"KT");
6408fe42 581 }
d2e6cdd5 582 if(iPWG4Cluster&2){
583 UInt_t selection = 0;
584 if(!iAODanalysis) selection = 0xffffff;
585 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
17d96675 586 selection&=~(1<<4); // exluded R = .04 already the dafault
6408fe42 587 AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"KT",selection);
0971dabc 588 }
589 if(iPWG4Cluster&4){
590 UInt_t selection = 0;
17d96675 591 if(!iAODanalysis){
592 selection = 0xffffff;
593 selection &= ~(1<<1)&~(1<<3)&~(1<<5)&~(1<<7)&~(1<<9);
594 }
0971dabc 595 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
58ef946c 596 AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"ANTIKT",selection);
d2e6cdd5 597 }
0971dabc 598
599
d2e6cdd5 600 if (!taskCl) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCluster cannot run for this train conditions - EXCLUDED");
601
602 }
c38e3b95 603 if(iPWG4PartCorr){
604 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
14526afb 605 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
c38e3b95 606 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
14526afb 607 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
c38e3b95 608 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
4721d8c5 609 if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data());
121e4bd5 610 }
611
d2e6cdd5 612 if(iPWG4CaloQA){
613 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
9748e967 614 AliAnalysisTaskParticleCorrelation *taskcaloQA = AddTaskCalorimeterQA("ESD",kFALSE,kIsMC,kCaloQAOutputFileName.Data());
d2e6cdd5 615 if(!taskcaloQA)::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation QA cannot run - EXCLUDED");
9748e967 616 if(kCaloQAOutputFileName.Length()>0)mgr->RegisterExtraFile(kCaloQAOutputFileName.Data());
d2e6cdd5 617 }
618
d2e6cdd5 619 if(iPWG4JetCorr){
620 // using namespace JetCorrelHD;
d3af0232 621 TString cdir = gSystem->WorkingDirectory();
622 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
d2e6cdd5 623 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCorrel.C");
624 AliAnalysisTaskJetCorrel *taskjetcorr = AddTaskJetCorrel();
d3af0232 625 gSystem->ChangeDirectory(cdir);
c166d299 626 if (!taskjetcorr) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJetCorrel cannot run for this train conditions - EXCLUDED");
d2e6cdd5 627 }
628
911a740f 629 if(iPWG4Tagged){
630 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
631 AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
58ef946c 632 taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS
911a740f 633 if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons cannot run for this train conditions - EXCLUDED");
634 }
121e4bd5 635 if (iPWG4omega3pi) {
636 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
637 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
638 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
639 for these train conditions - EXCLUDED");
640 }
641
53c63663 642 // PWG4 gamma conversion analysis
643 if (iPWG4GammaConv) {
644 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
645 TString cdir = gSystem->WorkingDirectory();
646 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
647 // TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
58ef946c 648 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
649 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
82ebd295 650 TString gcArguments = "-run-on-train -run-jet -run-omega-meson -run-neutralmeson";
651 TString kGCAnalysisCutSelectionId="9002111000";
652 gcArguments.Append(Form("-set-cut-selection %s ",kGCAnalysisCutSelectionId.Data()));
53c63663 653 if(!kIsMC)gcArguments += " -mc-off";
654 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
655 gSystem->ChangeDirectory(cdir);
121e4bd5 656 taskGammaConversion->SelectCollisionCandidates();
53c63663 657 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
658 }
659
17d96675 660 if (iPWG4CaloConv) {
661 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCaloConv.C");
662 AliAnalysisTaskCaloConv * taskCaloConv = AddTaskCaloConv();
663 if (!taskCaloConv) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCaloConv cannot run for these train conditions - EXCLUDED");
664 }
665
666
3878a941 667
c38e3b95 668 //==========================================================================
669 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
670 // Run the analysis
671 //
672 if (kPluginUse) {
673 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
674 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
675 }
676
677 if (mgr->InitAnalysis()) {
678 mgr->PrintStatus();
679 // if (kSaveTrain || strlen(config_file)) gSystem->ChangeDirectory(kTrainName);
e84da0a5 680 if (!strcmp(plugin_mode,"submit")&&smode=="GRID"){
c38e3b95 681 TString alien_workdir = gGrid->GetHomeDirectory();
682 if (iAODanalysis) alien_workdir += "analysisAOD";
683 else alien_workdir += "analysisESD";
3878a941 684 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
c38e3b95 685 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
e84da0a5 686 printf("=== AnalysisTrainPWG4Jets:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
c38e3b95 687 alien_workdir.Data(),gridhandler->GetGridOutputDir());
58ef946c 688
689 TString dest;
690 dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
691 if(AliAnalysisAlien::FileExists(dest.Data())){
692 // Printf("%s exist on grid removing...",dest.Data());
693 // gGrid->Rm(dest.Data());
694 }
695 TFile::Cp(Form("file:%s.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
4721d8c5 696
697
698 TString dest;
699 dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
700 if(AliAnalysisAlien::FileExists(dest.Data())){
701 // Printf("%s exist on grid removing...",dest.Data());
702 // gGrid->Rm(dest.Data());
703 }
704 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
705
58ef946c 706
73b7619a 707 dest = Form("%s/rootfiles/STEER/LQ1dRef_v1.root",gGrid->GetHomeDirectory());
58ef946c 708 if(AliAnalysisAlien::FileExists(dest.Data())){
709 Printf("%s exist on grid removing...",dest.Data());
710 gGrid->Rm(dest.Data());
711 }
712 TFile::Cp(Form("file:%s/STEER/LQ1dRef_v1.root",
9748e967 713 gSystem->ExpandPathName("$ALICE_ROOT")),Form("alien://%s",dest.Data()));
c38e3b95 714 }
3878a941 715 AliLog::SetGlobalLogLevel(AliLog::kError);
c166d299 716 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
717 TFile * fM = TFile::Open("manager_local.root","RECREATE");
718 mgr->Write();
719 fM->Close();
720 }
46534866 721
722 // grmpf, aliroot error handler overwrites root
723 gErrorIgnoreLevel = kErrorIgnoreLevel;
724 if(gErrorIgnoreLevel>3000) AliLog::SetGlobalLogLevel(AliLog::kFatal);
c38e3b95 725 StartAnalysis(smode, chain);
4a6f59cb 726 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
727 for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
728 mgr->ProfileTask(i);
729 }
730 }
c38e3b95 731 if (!strcmp(plugin_mode, "offline")&&smode=="GRID"){
e84da0a5 732 // Offline mode path files
733 // PatchJDL();
734 PatchAnalysisMacro();
735 }
c38e3b95 736
e84da0a5 737 if (kSaveTrain && smode=="GRID") {
738 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
739 TString alien_workdir = gGrid->GetHomeDirectory();
740 if (iAODanalysis) alien_workdir += "analysisAOD";
3878a941 741 else alien_workdir += "analysisESD";
742 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
e84da0a5 743 // kGridOutdir = gridhandler->GetGridOutputDir();
744 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
c38e3b95 745 alien_workdir.Data());
e84da0a5 746 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data())))
747 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
748 if (strcmp(plugin_mode, "test"))
749 TFile::Cp(Form("file:%sConfig.C",kTrainName.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
750 }
751 }
c38e3b95 752}
753
754//______________________________________________________________________________
755void StartAnalysis(const char *mode, TChain *chain) {
756// Start analysis.
757 Int_t imode = -1;
758 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
759 if (!strcmp(mode, "LOCAL")) imode = 0;
760 if (!strcmp(mode, "PROOF")) imode = 1;
761 if (!strcmp(mode, "GRID")) imode = 2;
762 switch (imode) {
763 case 0:
764 if (!chain) {
765 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
766 return;
767 }
82ebd295 768 mgr->StartAnalysis(mode, chain,kNumberOfEvents);
c38e3b95 769 return;
770 case 1:
771 if (!kProofDataSet.Length()) {
772 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "kProofDataSet is empty");
773 return;
774 }
775 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
776 return;
777 case 2:
778 if (kPluginUse) {
779 if (!mgr->GetGridHandler()) {
780 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Grid plugin not initialized");
781 return;
782 }
783 mgr->StartAnalysis("grid");
784 } else {
785 if (!chain) {
786 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
787 return;
788 }
789 mgr->StartAnalysis(mode, chain);
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 }
1f329128 904 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4Cosmics||iPWG4ThreeJets||iPWG4JetChem;
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")) {
1003 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that analysis libraries are compiled with a local AliRoot");
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 }
c166d299 1112 if(iPWG4TmpSourceFrag){
1113 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1114 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskFragFunc.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1115 }
9f77f0ce 1116
58ef946c 1117
9f77f0ce 1118 /*
1119 if(iPWG4JetChem){
c580ebbb 1120 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1121 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskJetChem.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1122 }
9f77f0ce 1123 */
c166d299 1124
4721d8c5 1125 if(iEMCUtilLibs){
1126 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
1127 !LoadLibrary("PHOSUtils", mode, kTRUE)) return kFALSE;
1128 }
1129
911a740f 1130 if (iPWG4PartCorrLibs) {
4721d8c5 1131 if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c38e3b95 1132 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
1133 }
4721d8c5 1134 if(iPWG4JCORRAN){
1135 // PWG4 particle correlations
1136 if(!LoadLibrary("PWG4JCORRAN",mode,kTRUE))return kFALSE;
1137 }
d2e6cdd5 1138 if (iPWG4JetCorr) {
1139 if (!LoadLibrary("PWG4JetCorrel", mode, kTRUE)) return kFALSE;
1140 }
121e4bd5 1141 if (iPWG4omega3pi) {
1142 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
1143 }
17d96675 1144 if (iPWG4GammaConvLib) {
53c63663 1145 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
1146 }
c38e3b95 1147
1148 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
1149 return kTRUE;
1150}
1151
1152//______________________________________________________________________________
1153Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
1154{
1155// Load a module library in a given mode. Reports success.
1156 Int_t imode = -1;
1157 Int_t result;
1158 TString smodule(module);
1159 if (!strcmp(mode, "LOCAL")) imode = 0;
1160 if (!strcmp(mode, "PROOF")) imode = 1;
1161 if (!strcmp(mode, "GRID")) imode = 2;
1162 TString mod(module);
1163 if (!mod.Length()) {
1164 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
1165 return kFALSE;
1166 }
1167 // If a library is specified, just load it
1168 if (smodule.EndsWith(".so")) {
1169 mod.Remove(mod.Index(".so"));
1170 result = gSystem->Load(mod);
1171 if (result < 0) {
1172 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
1173 return kFALSE;
1174 }
1175 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 1176 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 1177 return kTRUE;
1178 }
1179 // Check if the library is already loaded
1180 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
1181 return kTRUE;
1182 switch (imode) {
1183 case 0:
1184 case 2:
1185 if (kUsePAR) {
1186 result = SetupPar(module);
1187 if (rec) anaPars += Form("%s.par ", module);
1188 } else {
1189 result = gSystem->Load(Form("lib%s.so", module));
1190 if (rec) anaLibs += Form("lib%s.so ", module);
1191 }
1192 break;
1193 case 1:
1194 if(!gSystem->AccessPathName(module)){
1195 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
1196 gSystem->Exec(Form("rm -rf %s",module));
1197 }
1198 result = gProof->UploadPackage(module);
1199 if (result<0) {
1200 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
1201 if (result<0) {
1202 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
1203 return kFALSE;
1204 }
1205 }
1206 result = gProof->EnablePackage(module);
1207 break;
1208 default:
1209 return kFALSE;
1210 }
1211 if (result < 0) {
1212 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
1213 return kFALSE;
1214 }
1215 return kTRUE;
1216}
1217
1218
1219
1220//______________________________________________________________________________
1221Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
1222{
1223// Load a module library in a given mode. Reports success.
1224 Int_t imode = -1;
1225 Int_t result = -1;
1226 if (!strcmp(mode, "LOCAL")) imode = 0;
1227 if (!strcmp(mode, "PROOF")) imode = 1;
1228 if (!strcmp(mode, "GRID")) imode = 2;
1229 TString ssource(source);
1230 TString basename = gSystem->BaseName(ssource.Data());
1231 if (!ssource.Length()) {
1232 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
1233 return kFALSE;
1234 }
4d62ae1a 1235 // we have a source code so compile it
c38e3b95 1236 if (ssource.EndsWith(".cxx")) {
1237 // need to copy it here other wise the path is also used on grid...
1238 ssource.Remove(ssource.Index(".cxx"));
1239 basename.Remove(basename.Index(".cxx"));
1240 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
1241 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
1242 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
1243 // Path to code
1244 // only needed for local compilation, in grid and proof mode
1245 // the task headers are uploaded
1246 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
1247 // Printf("LoadSources:: Including path %s",path.Data());
1248 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
1249 Printf("LoadSources:: Loading... path %s",basename.Data());
1250 switch (imode) {
1251 case 0:
b53f2e4f 1252 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1253 break;
1254 case 1:
b53f2e4f 1255 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1256 break;
1257 case 2:
b53f2e4f 1258 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1259 if (rec){
1260 // what we want to compile
1261 anaSources += Form("%s.cxx ",basename.Data());
1262 // what we need as input...
1263 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
1264 }
1265 break;
1266 default:
1267 return kFALSE;
1268 }
1269 }
1270 if (result < 0) {
1271 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
1272 return kFALSE;
1273 }
1274 return kTRUE;
1275}
1276
1277
1278//______________________________________________________________________________
1279TChain *CreateChain(const char *mode, const char *plugin_mode)
1280{
1281// Create the input chain
1282 Int_t imode = -1;
1283 if (!strcmp(mode, "LOCAL")) imode = 0;
1284 if (!strcmp(mode, "PROOF")) imode = 1;
1285 if (!strcmp(mode, "GRID")) imode = 2;
1286 TChain *chain = NULL;
1287 // Local chain
1288 switch (imode) {
1289 case 0:
1290 if (iAODanalysis) {
1291 if (!kLocalXMLDataset.Length()) {
1292 // Local AOD
1293 chain = new TChain("aodTree");
1294 TString line;
1295 ifstream in;
1296 in.open(kLocalDataList.Data());
1297 while (in.good()) {
1298 in >> line;
1299 if (line.Length() == 0) continue;
1300 // cout << " line = " << line << endl;
1301 chain->Add(line.Data());
1302 }
1303 } else {
1304 // Interactive AOD
1305 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1306 }
1307 } else {
1308 if (!kLocalXMLDataset.Length()) {
1309 // Local ESD
1310 chain = new TChain("esdTree");
1311 TString line;
1312 ifstream in;
1313 in.open(kLocalDataList.Data());
1314 while (in.good()) {
1315 in >> line;
1316 if (line.Length() == 0) continue;
1317 cout << " line = " << line << endl;
1318 chain->Add(line.Data());
1319 }
1320 } else {
1321 // Interactive ESD
1322 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1323 }
1324 }
1325 break;
1326 case 1:
1327 break;
1328 case 2:
1329 if (kPluginUse) {
1330// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1331// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1332 } else {
1333 TString treeName = "esdTree";
1334 if (iAODanalysis) treeName = "aodTree";
1335 chain = CreateChainSingle("wn.xml", treeName);
1336 }
1337 break;
1338 default:
1339 }
1340 if (chain && chain->GetNtrees()) return chain;
1341 return NULL;
1342}
1343
1344//______________________________________________________________________________
1345TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1346{
1347 printf("*******************************\n");
1348 printf("*** Getting the ESD Chain ***\n");
1349 printf("*******************************\n");
1350 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1351
1352 if (!myCollection) {
1353 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1354 return NULL ;
1355 }
1356
1357 TChain* chain = new TChain(treeName);
1358 myCollection->Reset() ;
1359 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1360 chain->ls();
1361 return chain;
1362}
1363
1364//______________________________________________________________________________
1365Int_t SetupPar(char* pararchivename)
1366{
1367 if (!pararchivename || !strlen(pararchivename)) return -1;
1368 char processline[1024];
1369 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1370 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1371 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
9748e967 1372 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1373 Form("%s.par",pararchivename));
c38e3b95 1374 } else {
1375 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1376 return -1;
1377 }
1378 }
1379 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1380 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1381
1382 TString ocwd = gSystem->WorkingDirectory();
1383 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1384
1385 // check for BUILD.sh and execute
1386 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1387 printf("*******************************\n");
1388 printf("*** Building PAR archive ***\n");
1389 printf("*******************************\n");
1390 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1391 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1392 return -1;
1393 }
1394 }
1395
1396 // check for SETUP.C and execute
1397 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1398 printf("*******************************\n");
1399 printf("*** Setup PAR archive ***\n");
1400 printf("*******************************\n");
1401 gROOT->Macro("PROOF-INF/SETUP.C");
1402 }
1403 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1404 return 0;
1405}
1406
1407//______________________________________________________________________________
1408AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1409{
1410// Check if user has a valid token, otherwise make one. This has limitations.
1411// One can always follow the standard procedure of calling alien-token-init then
1412// source /tmp/gclient_env_$UID in the current shell.
1413 if (!AliAnalysisGrid::CreateToken()) return NULL;
1414 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1415// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1416 plugin->SetRunMode(plugin_mode);
1417 if (kPluginUseProductionMode) plugin->SetProductionMode();
1418 plugin->SetJobTag(kJobTag);
1419 plugin->SetNtestFiles(2);
1420// plugin->SetPreferedSE("ALICE::NIHAM::File");
1421// Set versions of used packages
e84da0a5 1422 plugin->SetAPIVersion("V1.1x");
1423 // plugin->SetAPIVersion("V1.0x");
1424// plugin->SetAPIVersion("V2.4");
c38e3b95 1425 plugin->SetROOTVersion(kPluginRootVersion);
1426 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1427// Declare input data to be processed.
1428// Method 1: Create automatically XML collections using alien 'find' command.
1429// Define production directory LFN
1430 plugin->SetGridDataDir(kGridDatadir.Data());
1431// Set data search pattern
1432 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1433 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1434// ...then add run numbers to be considered
1435// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1436 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1437 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1438 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1439 }
1440
1441 if(kGridLocalRunList.Length()>0){
1442 ifstream in1;
1443 in1.open(kGridLocalRunList.Data());
1444 int iRun;
9a5c5b1e 1445
1446 /*
e84da0a5 1447 char c;
1448 char cLine[250];
1449 while(!in1.eof()){
1450 c = in1.get();
1451 if ( (c >= '0') && (c <= '9') )
1452 {
1453 in1.putback (c);
1454 in1>>iRun;
1455 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1456 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1457 }
1458 else
1459 {
1460 in1.putback (c);
1461 in1.getline(cLine,250);
9a5c5b1e 1462
1463 }
1464 }
1465 */
9748e967 1466
1467 Int_t nRun = 0;
9a5c5b1e 1468
1469 // just use run numbers, negatives will be excluded
1470 while(in1>>iRun){
9748e967 1471
1472 if(iRun>0&&(nRun<kGridMaxRunsFromList)){
9a5c5b1e 1473 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1474 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
9748e967 1475 nRun++;
9a5c5b1e 1476 }
1477 else{
1478 Printf("AnalysisTrainPWG4Jets Skipping run number from File %d", iRun);
e84da0a5 1479 }
c38e3b95 1480 }
1481 }
1482
1483// Method 2: Declare existing data files (raw collections, xml collections, root file)
1484// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1485// XML collections added via this method can be combined with the first method if
1486// the content is compatible (using or not tags)
1487// plugin->AddDataFile("tag.xml");
1488// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1489// Define alien work directory where all files will be copied. Relative to alien $HOME.
3878a941 1490 TString alien_workdir = "";
1491
1492 if (iAODanalysis) alien_workdir += "analysisAOD";
1493 else alien_workdir += "analysisESD";
1494 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
1495 plugin->SetGridWorkingDir(alien_workdir.Data());
1496
c38e3b95 1497 // Declare alien output directory. Relative to working directory.
1498 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1499 plugin->SetGridOutputDir(kGridOutdir);
1500
1501 // Add external packages
1502 if (iJETAN||iDIJETAN) {
23adcac8 1503 plugin->AddExternalPackage("boost::v1_43_0");
1504 plugin->AddExternalPackage("cgal::v3.6");
1505 plugin->AddExternalPackage("fastjet::v2.4.2");
c38e3b95 1506 }
1507
1508
1509 // set extra libs before par file compilation
1510 anaLibs += kGridExtraFiles;
1511 anaLibs = anaLibs.Strip();
e84da0a5 1512 Printf("anaLibs %s",anaLibs.Data());
1513 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1514
1515 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1516 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1517
1518 TString ana_sources = "";
1519 TString ana_add = "";
1520 if (kUsePAR && anaPars.Length()) {
1521 printf("%s\n", anaPars.Data());
1522 TObjArray *arr;
1523 TObjString *objstr;
1524 arr = anaPars.Tokenize(" ");
1525 TIter next(arr);
1526 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1527 delete arr;
1528 }
1529
1530// Declare the analysis source files names separated by blancs. To be compiled runtime
1531// using ACLiC on the worker nodes.
1532 ana_sources = anaSources.Strip();
1533// Declare all libraries (other than the default ones for the framework. These will be
1534// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1535
1536 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1537 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
4721d8c5 1538 // Declare the output file names separated by blancs.
1539 // (can be like: file.root or file.root@ALICE::Niham::File)
c38e3b95 1540 plugin->SetMergeExcludes(kGridMergeExclude);
1541 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1542 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
9a5c5b1e 1543 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
4721d8c5 1544 // Use fastread option
9a5c5b1e 1545 plugin->SetFastReadOption(kPluginFastReadOption);
4721d8c5 1546 // UseOverwrite mode
9a5c5b1e 1547 plugin->SetOverwriteMode(kPluginOverwriteMode);
4721d8c5 1548 // Optionally define the files to be archived.
1549 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
dc6a7461 1550 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
c38e3b95 1551
1552 // Put default output files to archive
1553 TString listhists = "";
1554 TString listaods = "";
1555 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1556 TIter next(mgr->GetOutputs());
1557 AliAnalysisDataContainer *output;
1558 while ((output=(AliAnalysisDataContainer*)next())) {
1559 const char *filename = output->GetFileName();
1560 if (!(strcmp(filename, "default"))) {
53c63663 1561 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1562 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1563 if (listaods.Length()) listaods += " ";
c38e3b95 1564 listaods += filename;
c38e3b95 1565 } else {
e84da0a5 1566 if(!listhists.Contains(filename)){
1567 if (listhists.Length()) listhists += " ";
c38e3b95 1568 listhists += filename;
1569 }
1570 }
1571 }
53c63663 1572
53c63663 1573 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1574 if (listaods.Length()) listaods += " ";
53c63663 1575 listaods += mgr->GetExtraFiles();
c38e3b95 1576 }
53c63663 1577
1578 // if we do not fill the aod we do not need to store it
4721d8c5 1579 // kGridMergeExclude = listaods;
e84da0a5 1580
4721d8c5 1581 if(kSaveAOD!=0){
1582 TString outputFiles = "";
1583 outputFiles += mgr->GetExtraFiles();
1584 if (listhists.Length()) outputFiles += " ";
1585 outputFiles += listhists;
e84da0a5 1586 plugin->SetDefaultOutputs(kFALSE);
4721d8c5 1587 Printf("%s:%d Starting with the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1588 // remove
1589 // no harm done when we try to remove something that is not there :)
1590 if(!(kSaveAOD&(1<<0))){
1591 outputFiles.ReplaceAll("AliAOD.root ","");
1592 listaods.ReplaceAll("AliAOD.root ","");
1593 }
1594 if(!(kSaveAOD&(1<<1))){
1595 if(kDeltaAODJetName.Length())outputFiles.ReplaceAll(kDeltaAODJetName.Data(),"");
1596 if(kDeltaAODJetName.Length())listaods.ReplaceAll(kDeltaAODJetName.Data(),"");
1597
1598 }
1599 if(!(kSaveAOD&(1<<2))){
1600 if(kDeltaAODPartCorrName.Length())outputFiles.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1601 if(kDeltaAODPartCorrName.Length())listaods.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1602 }
1603 if(!(kSaveAOD&(1<<3))){
1604 if(kDeltaAODJCORRANName.Length())outputFiles.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1605 if(kDeltaAODJCORRANName.Length())listaods.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1606 }
1607
1608 //
1609 Printf("%s:%d Saving the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1610 plugin->SetOutputFiles(outputFiles.Data());
e84da0a5 1611 }
53c63663 1612
4721d8c5 1613 TString outputArchive;
17841481 1614 outputArchive = Form("log_archive.zip:std*@%s",kGridOutputStorages.Data());
e84da0a5 1615 listaods.ReplaceAll(" ", ",");
1616 listhists.ReplaceAll(" ", ",");
4721d8c5 1617 if (listhists.Length()) listhists = Form("hist_archive.zip:%s@%s", listhists.Data(), kGridOutputStorages.Data());
1618 if (listaods.Length()) listaods = Form("aod_archive.zip:%s@%s", listaods.Data(), kGridOutputStorages.Data());
53c63663 1619
c38e3b95 1620 if (!listhists.Length() && !listaods.Length()) {
1621 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
1622 }
4721d8c5 1623
c38e3b95 1624 if (listaods.Length()) {
1625 outputArchive += " ";
1626 outputArchive += listaods;
1627 }
1628 if (listhists.Length()) {
1629 outputArchive += " ";
1630 outputArchive += listhists;
1631 }
17d96675 1632 plugin->SetDefaultOutputs(kFALSE);
c38e3b95 1633 plugin->SetOutputArchive(outputArchive);
17d96675 1634
4721d8c5 1635
c38e3b95 1636// Optionally set a name for the generated analysis macro (default MyAnalysis.C)
1637 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
1638// Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
1639 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
1640// Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1641// plugin->SetMaxInitFailed(5);
1642// Optionally resubmit threshold.
1643// plugin->SetMasterResubmitThreshold(90);
1644// Optionally set time to live (default 30000 sec)
17d96675 1645 plugin->SetTTL(50400); // 14h...
c38e3b95 1646// Optionally set input format (default xml-single)
1647 plugin->SetInputFormat("xml-single");
1648// Optionally modify the name of the generated JDL (default analysis.jdl)
1649 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
1650// Optionally modify the executable name (default analysis.sh)
1651 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
1652// Optionally modify job price (default 1)
1653 plugin->SetPrice(1);
1654// Optionally modify split mode (default 'se')
1655 plugin->SetSplitMode("se");
1656 return plugin;
1657}
1658
1659//______________________________________________________________________________
1660void WriteConfig()
1661{
1662// Write train configuration in a file. The file name has the format:
1663// train_[trainName]_ddMonthyyyy_time.C
1664 if (kUseDate) {
1665 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1666 ifstream fdate("date.tmp");
1667 if (!fdate.is_open()) {
1668 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1669 return;
1670 }
1671 const char date[64];
1672 fdate.getline(date,64);
1673 fdate.close();
1674 gSystem->Exec("rm date.tmp");
1675 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1676 } else {
1677 kTrainName = Form("train_%s", kTrainName.Data());
1678 }
1679 TString cdir = gSystem->WorkingDirectory();
1680 gSystem->MakeDirectory(kTrainName);
1681 gSystem->ChangeDirectory(kTrainName);
1682 ofstream out;
1683 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1684 if (out.bad()) {
1685 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1686 return;
1687 }
1688 out << "{" << endl;
1689 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1690 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1691 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1692 if (kProofUseAFPAR)
1693 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1694 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1695 out << " kPluginUse = " << kPluginUse << ";" << endl;
1696 out << " kUsePAR = " << kUsePAR << ";" << endl;
1697 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1698 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1699 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1700 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1701 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1702 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1703 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1704 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1705 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1706 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1707 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1708 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1709 out << " kUseDebug = " << kUseDebug << ";" << endl;
1710 out << " kUseMC = " << kUseMC << ";" << endl;
1711 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1712 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1713 out << " kUseTR = " << kUseTR << ";" << endl;
1714 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1715 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1716 out << " // Analysis modules" << endl;
1717 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1718 out << " iAODhandler = " << iAODhandler << ";" << endl;
1719 out << " iESDfilter = " << iESDfilter << ";" << endl;
1720 out << " iJETAN = " << iJETAN << ";" << endl;
1721 out << "// Configuration fot the wagons" << endl;
1722 out << "}" << endl;
1723 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1724 gSystem->ChangeDirectory(cdir);
1725}
1726
1727//______________________________________________________________________________
1728Bool_t LoadConfig(const char *filename)
1729{
1730// Read train configuration from file
1731 if (gSystem->AccessPathName(filename)) {
1732 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1733 return kFALSE;
1734 }
1735 gROOT->ProcessLine(Form(".x %s", filename));
1736 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1737 return kTRUE;
1738}
1739
1740Bool_t PatchJDL(){
1741 Printf(">>> Patching JDL");
1742 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1743 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1744 TGridJDL *jdl = gridHandler->GetGridJDL();
1745 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1746 gridHandler->WriteJDL(kFALSE);
0971dabc 1747 Printf("<<< Patching JDL");
c38e3b95 1748 return kTRUE;
1749}
1750
1751Bool_t PatchAnalysisMacro(){
4721d8c5 1752 Printf(">>> Patching AnalysisMacro");
1753 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
c38e3b95 1754
1755 ifstream in1;
1756 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1757 char cLine[250];
1758 TString st;
1759 while(in1.getline(cLine,250)){
1760 st += cLine;
1761 st += "\n";
1762 }
4721d8c5 1763 Int_t index= -1;
c38e3b95 1764 index = st.Index("gSystem->Load(\"libPhysics\");");
1765 index += strlen("gSystem->Load(\"libPhysics\");");
4721d8c5 1766 /*
c38e3b95 1767 TObjArray *arr;
1768 TObjString *objstr;
1769 arr = anaLibs.Tokenize(" ");
1770 TIter next(arr);
4721d8c5 1771
c38e3b95 1772 add += "\n\n // added by CKB \n";
1773 while ((objstr=(TObjString*)next())){
e84da0a5 1774 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1775 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1776 }
1777 delete arr;
4721d8c5 1778 */
3878a941 1779 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
4721d8c5 1780 TString add = "";
1781
1782 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1783 add += "\n\n // added by CKB \n";
46534866 1784 if(kErrorIgnoreLevel>0)add += Form("gErrorIgnoreLevel = %d;\n",kErrorIgnoreLevel);
23adcac8 1785 add += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1786 if(gGrid&&kPluginAliRootVersion.Length()==0){
1787 add += "\n // Dirty hack for TRD reference data \n";
1788 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1789 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1790 add += "\"); \n";
c38e3b95 1791 }
4721d8c5 1792 add += "// BKC \n\n";
1793 st.Insert(index,add.Data());
e84da0a5 1794
1795 if(kUseDebug){
23adcac8 1796 // st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
e84da0a5 1797 }
1798
4721d8c5 1799 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1800 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1801 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1802 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1803 }
c166d299 1804
46534866 1805 if(AliLog::GetGlobalLogLevel()==AliLog::kFatal){
1806 index = st.Index("AliLog::SetGlobal"); // ncomment setting of log level, do my own
1807 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1808 st.Insert(index,"AliLog::SetGlobalLogLevel(AliLog::kFatal);// CKB \n // CKB comment out for own setting \n //");
1809 }
1810
c38e3b95 1811 ofstream out;
1812 out.open(Form("%s.C", kTrainName.Data()));
1813 if (out.bad()) {
1814 return kFALSE;
1815 }
1816 out << st << endl;
1817 Printf("<<< Patching AnalysisMacro");
4721d8c5 1818
1819
1820
1821
1822
1823 Printf(">>> Patching Merge Macro");
1824 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1825
1826 ifstream in2;
1827 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1828 TString st2;
1829 while(in2.getline(cLine,250)){
1830 st2 += cLine;
1831 st2 += "\n";
1832 }
1833 index = st2.Index("gSystem->Load(\"libPhysics\");");
1834 index += strlen("gSystem->Load(\"libPhysics\");");
1835 TString add2 = "";
23adcac8 1836 add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1837 if(gGrid&&kPluginAliRootVersion.Length()==0){
1838 add2 += "\n // Dirty hack for TRD reference data \n";
1839 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1840 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1841 add2 += "\"); \n";
1842 }
1843 add2 += "// BKC \n\n";
1844 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1845 st2.Insert(index,add.Data());
1846
1847
1848 if(kUseDebug){
23adcac8 1849 // st2.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
4721d8c5 1850 }
1851
1852 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
46534866 1853 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncomment $ALICE_ROOT include for par files
4721d8c5 1854 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1855 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1856 }
1857
1858 // do not exclude the extra files from merign, this is done explicitly in this train script
1859 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1860 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1861 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1862
1863
1864 ofstream out2;
1865 out2.open(Form("%s_merge.C", kTrainName.Data()));
1866 if (out2.bad()) {
1867 return kFALSE;
1868 }
1869 out2 << st2 << endl;
1870 Printf("<<< Patching Merging Macro");
1871
1872
1873
c38e3b95 1874 return kTRUE;
1875
1876}