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