Revert to previous usage of VATT.
[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");
8be7acf2 456 AliAnalysisTaskFragmentationFunction *taskFrag = 0;
457 if(kUseAODMC){
458 taskFrag = AddTaskFragmentationFunction(1<<1,kHighPtFilterMask);
459 taskFrag = AddTaskFragmentationFunction(1<<2,kHighPtFilterMask);
460 taskFrag = AddTaskFragmentationFunction(1<<3,kHighPtFilterMask);
c2658535 461 taskFrag = AddTaskFragmentationFunction(1<<11); // w/o acceptance cuts
462 taskFrag = AddTaskFragmentationFunction(1<<12); // with acceptance cuts
463 // anti-kt
464 taskFrag = AddTaskFragmentationFunction(1<<21); // w/o acceptance cuts
465 taskFrag = AddTaskFragmentationFunction(1<<22); // with acceptance cuts
466
8be7acf2 467 }
468 else{
469 taskFrag = AddTaskFragmentationFunction(1<<0,kHighPtFilterMask);
c2658535 470 taskFrag = AddTaskFragmentationFunction(1<<10,kHighPtFilterMask);
471 taskFrag = AddTaskFragmentationFunction(1<<20,kHighPtFilterMask);
8be7acf2 472 }
473
aba42fcb 474 if (!taskFrag) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskFragmentationFunction cannot run for this train conditions - EXCLUDED");
c166d299 475 }
476
c580ebbb 477
9f77f0ce 478 if(iPWG4JetChem){
479 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetChem.C");
480 AliAnalysisTask *taskChem = AddTaskJetChem();
c580ebbb 481 if (!taskChem) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetChem cannot run for this train conditions - EXCLUDED");
482 }
483
484
c38e3b95 485 if(iPWG4JetServices){
486 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
487 AliAnalysisTaskJetServices *taskjetServ = 0;
488 taskjetServ = AddTaskJetServices();
489 if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
53c63663 490 if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
8be7acf2 491 else taskjetServ->SetRunRange(100000,150000);
c28abe00 492 if(!kIsMC) taskjetServ->SetRealData(kTRUE);
dc6a7461 493 taskjetServ->SetUsePhysicsSelection((Bool_t)iPhysicsSelection);
9f77f0ce 494 taskjetServ->SetDebugLevel(0);
c38e3b95 495 }
496
c38e3b95 497 if(iPWG4JetSpectrum){
498 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
499 AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
b53f2e4f 500 if(iPWG4JetSpectrum&1){
17d96675 501 taskjetSpectrum = AddTaskJetSpectrum2("jets","","",kHighPtFilterMask,iPhysicsSelection);
e6993a52 502 if(!iAODanalysis){
d3af0232 503 // taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection); // tmp hack to give it a different name
4d5d766e 504 // taskjetSpectrum = AddTaskJetSpectrum2("jets","64",64,iPhysicsSelection);
46534866 505
5ad2b067 506 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","clustersAOD_ANTIKT04","",kHighPtFilterMask,iPhysicsSelection);
507
f2dd0695 508 if(kIsMC){
17d96675 509
510 UInt_t eventSelection = AliAnalysisHelperJetTasks::kIsPileUp|AliAnalysisHelperJetTasks::kVertexIn;
511 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
512 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
513 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC2_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
514
515 eventSelection = AliAnalysisHelperJetTasks::kIsCosmic|AliAnalysisHelperJetTasks::kVertexIn;
516 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
517 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
518
519 eventSelection = AliAnalysisHelperJetTasks::kNone;
520 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC2_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
521 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","jetsAODMC_FASTJET04","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
46534866 522
523 }
524 else{
17d96675 525 UInt_t eventSelection = AliAnalysisHelperJetTasks::kIsPileUp|AliAnalysisHelperJetTasks::kVertexIn;
526 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
527 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
528
529 eventSelection = AliAnalysisHelperJetTasks::kIsCosmic|AliAnalysisHelperJetTasks::kVertexIn;
530 if(iPhysicsSelection)eventSelection |= AliAnalysisHelperJetTasks::kPhysicsSelection;
531 taskjetSpectrum = AddTaskJetSpectrum2("jetsAOD_FASTJET04","","",kHighPtFilterMask,iPhysicsSelection,eventSelection);
f2dd0695 532 }
e6993a52 533 }
d2e6cdd5 534 if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
17d96675 535 // taskjetSpectrum->SetDebugLevel(1);
b53f2e4f 536 }
d2e6cdd5 537
e6993a52 538 if(iPWG4JetSpectrum&2){
539 UInt_t selection = 0;
17d96675 540 if(!iAODanalysis){
541 selection = 0xffffff;
542 // switch off 07 radii
543 selection &= ~(1<<6)&~(1<<11)&~(1<<12)&~(1<<13)&~(1<<14);
544 }
e6993a52 545 else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
e0c120d9 546 AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection,0,kTRUE);
e6993a52 547 }
c38e3b95 548 }
58ef946c 549 if(iPWG4JCORRAN){
550 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJCORRANTask.C");
4721d8c5 551 AliJCORRANTask* corran = AddTaskJCORRAN(kDeltaAODJCORRANName.Data(),0);
58ef946c 552 if(!corran)::Warning("AnalysisTrainPWG4Jets", "AliJCORRANTask cannot run for this train conditions - EXCLUDED");
4721d8c5 553 else{
554 if(kDeltaAODJCORRANName.Length()>0)mgr->RegisterExtraFile(kDeltaAODJCORRANName.Data());
555 }
58ef946c 556 }
557
c38e3b95 558 if(iPWG4UE){
559 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
560 AliAnalysisTaskUE *taskUE = 0;
561 if(iPWG4UE&1)taskUE = AddTaskUE();
562 if(iPWG4UE&2){
94ee88d4 563 taskUE =AddTaskUE("jetsAOD_CDF04","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
17d96675 564 // taskUE =AddTaskUE("jetsAOD_CDF07","CDF", "LJ", "TRANSV","MSP");
94ee88d4 565 taskUE =AddTaskUE("jetsAOD_SISCONE04","CDF", "LJ", "TRANSV","MSP");
17d96675 566 // taskUE =AddTaskUE("jetsAOD_SISCONE07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
94ee88d4 567 taskUE =AddTaskUE("jetsAOD_ICDF","CDF","LJ","TRANSV","MSP");
568 taskUE =AddTaskUE("jetsAOD_FASTKT04","CDF", "LJ", "TRANSV","MSP");
17d96675 569 // taskUE =AddTaskUE("jetsAOD_FASTKT07","CDF", "LJ", "TRANSV","MSP"); //finder not yet in train
58ef946c 570 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta05", "TRANSV","MSP");
571 taskUE =AddTaskUE("jetsAOD_NONE","CDF", "MP_eta09", "TRANSV","MSP");
c38e3b95 572 }
2bb1f4ca 573
c38e3b95 574 if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
575 }
e0c120d9 576
577 if(iPWG4LeadingUE){
578 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskLeadingTrackUE.C");
579 AliAnalysisTaskLeadingTrackUE *taskLeadingUE = AddTaskLeadingTrackUE(kUseMC);
580 if (!taskLeadingUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTasLeadingTrackkUE cannot run for this train conditions - EXCLUDED");
581 taskLeadingUE->SetFilterBit(64);
582 }
583
584
9748e967 585 if(iPWG4CorrectionsUE){
586 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCorrectionsUE.C");
587 AliAnalysisTaskCorrectionsUE *taskCorrectionsUE = 0;
588 if(iPWG4CorrectionsUE&1)taskCorrectionsUE = AddTaskCorrectionsUE("jetsAOD_NONE","CDF","MP_eta05","TRANSV","MSP",kFALSE);
589 if (!taskCorrectionsUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCorrectionsUE cannot run for this train conditions - EXCLUDED");
590 }
c38e3b95 591
592 if(iPWG4ThreeJets){
593 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
594 AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
595 if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
596 }
c38e3b95 597 if(iPWG4PtQAMC){
598 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
b1cd0099 599 AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC(kGridDataSet.Data());
c38e3b95 600 if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
601 }
602
603 if(iPWG4PtQATPC){
604 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
10295ac3 605 AliPWG4HighPtQATPConly *taskQATPC = 0;
b1cd0099 606 if(iPWG4PtQATPC&1)taskQATPC = AddTaskPWG4HighPtQATPConly(kGridDataSet.Data(),1);
607 if(iPWG4PtQATPC&2)taskQATPC = AddTaskPWG4HighPtQATPConly(kGridDataSet.Data(),2);
10295ac3 608
609 if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
c38e3b95 610 }
3878a941 611
1f329128 612 if(iPWG4Cosmics){
613 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4CosmicCandidates.C");
614
615 AliPWG4CosmicCandidates *taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(0);
616 taskPWG4CosmicCandidates = AddTaskPWG4CosmicCandidates(1);
617
618 if (!taskPWG4CosmicCandidates) ::Warning("AnalysisTrainPWG4Jets", "AddTaskPWG4CosmicCandidates cannot run for this train conditions - EXCLUDED");
619 }
620
621
c38e3b95 622 if(iPWG4PtSpectra){
623 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
b1cd0099 624 AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra(kGridDataSet.Data());
c38e3b95 625 if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
626 }
b53f2e4f 627 if(iPWG4KMeans){
628 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
629 AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
630 if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
631 }
632
c38e3b95 633 if(iPWG4PartCorr){
634 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
14526afb 635 AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
c38e3b95 636 if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
14526afb 637 AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
c38e3b95 638 if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
4721d8c5 639 if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data());
121e4bd5 640 }
641
d2e6cdd5 642 if(iPWG4CaloQA){
643 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
9748e967 644 AliAnalysisTaskParticleCorrelation *taskcaloQA = AddTaskCalorimeterQA("ESD",kFALSE,kIsMC,kCaloQAOutputFileName.Data());
d2e6cdd5 645 if(!taskcaloQA)::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation QA cannot run - EXCLUDED");
aba42fcb 646 // if(kCaloQAOutputFileName.Length()>0)mgr->RegisterExtraFile(kCaloQAOutputFileName.Data());
d2e6cdd5 647 }
648
d2e6cdd5 649 if(iPWG4JetCorr){
650 // using namespace JetCorrelHD;
d3af0232 651 TString cdir = gSystem->WorkingDirectory();
652 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
d2e6cdd5 653 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCorrel.C");
654 AliAnalysisTaskJetCorrel *taskjetcorr = AddTaskJetCorrel();
d3af0232 655 gSystem->ChangeDirectory(cdir);
c166d299 656 if (!taskjetcorr) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJetCorrel cannot run for this train conditions - EXCLUDED");
d2e6cdd5 657 }
658
911a740f 659 if(iPWG4Tagged){
660 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
661 AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
58ef946c 662 taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS
911a740f 663 if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons cannot run for this train conditions - EXCLUDED");
664 }
121e4bd5 665 if (iPWG4omega3pi) {
666 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
667 AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
668 if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
669 for these train conditions - EXCLUDED");
670 }
671
53c63663 672 // PWG4 gamma conversion analysis
673 if (iPWG4GammaConv) {
674 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
675 TString cdir = gSystem->WorkingDirectory();
676 gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
677 // TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
58ef946c 678 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
679 // TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
4d5d766e 680 TString gcArguments = "-run-on-train -run-jet -run-omega-meson -run-neutralmeson -no-aod";
681 TString kGCAnalysisCutSelectionId="900356200010031";
682 gcArguments.Append(Form(" -set-cut-selection %s ",kGCAnalysisCutSelectionId.Data()));
53c63663 683 if(!kIsMC)gcArguments += " -mc-off";
684 AliAnalysisTaskGammaConversion * taskGammaConversion = AddTaskGammaConversion(gcArguments,mgr->GetCommonInputContainer());
685 gSystem->ChangeDirectory(cdir);
121e4bd5 686 taskGammaConversion->SelectCollisionCandidates();
53c63663 687 if (!taskGammaConversion) ::Warning("AnalysisTrainNew", "AliAnalysisTaskGammaConversion cannot run for these train conditions - EXCLUDED");
688 }
689
17d96675 690 if (iPWG4CaloConv) {
691 gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskCaloConv.C");
692 AliAnalysisTaskCaloConv * taskCaloConv = AddTaskCaloConv();
693 if (!taskCaloConv) ::Warning("AnalysisTrainNew", "AliAnalysisTaskCaloConv cannot run for these train conditions - EXCLUDED");
694 }
695
696
3878a941 697
c38e3b95 698 //==========================================================================
699 // FOR THE REST OF THE TASKS THE MACRO AddTaskXXX() is not yet implemented/
700 // Run the analysis
701 //
702 if (kPluginUse) {
703 AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
704 AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
705 }
706
707 if (mgr->InitAnalysis()) {
708 mgr->PrintStatus();
709 // if (kSaveTrain || strlen(config_file)) gSystem->ChangeDirectory(kTrainName);
e84da0a5 710 if (!strcmp(plugin_mode,"submit")&&smode=="GRID"){
c38e3b95 711 TString alien_workdir = gGrid->GetHomeDirectory();
712 if (iAODanalysis) alien_workdir += "analysisAOD";
713 else alien_workdir += "analysisESD";
3878a941 714 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
c38e3b95 715 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
e84da0a5 716 printf("=== AnalysisTrainPWG4Jets:: Registering jdl in the work directory alien://%s/%s, should be done by the manager! ===\n",
c38e3b95 717 alien_workdir.Data(),gridhandler->GetGridOutputDir());
58ef946c 718
719 TString dest;
720 dest = Form("%s/%s/%s.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
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.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
4721d8c5 726
727
728 TString dest;
729 dest = Form("%s/%s/%s_merge.jdl",alien_workdir.Data(),gridhandler->GetGridOutputDir(),kTrainName.Data());
730 if(AliAnalysisAlien::FileExists(dest.Data())){
731 // Printf("%s exist on grid removing...",dest.Data());
732 // gGrid->Rm(dest.Data());
733 }
734 TFile::Cp(Form("file:%s_merge.jdl",kTrainName.Data()),Form("alien://%s",dest.Data()));
735
58ef946c 736
73b7619a 737 dest = Form("%s/rootfiles/STEER/LQ1dRef_v1.root",gGrid->GetHomeDirectory());
58ef946c 738 if(AliAnalysisAlien::FileExists(dest.Data())){
739 Printf("%s exist on grid removing...",dest.Data());
740 gGrid->Rm(dest.Data());
741 }
742 TFile::Cp(Form("file:%s/STEER/LQ1dRef_v1.root",
9748e967 743 gSystem->ExpandPathName("$ALICE_ROOT")),Form("alien://%s",dest.Data()));
c38e3b95 744 }
3878a941 745 AliLog::SetGlobalLogLevel(AliLog::kError);
c166d299 746 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
747 TFile * fM = TFile::Open("manager_local.root","RECREATE");
748 mgr->Write();
749 fM->Close();
750 }
46534866 751
752 // grmpf, aliroot error handler overwrites root
753 gErrorIgnoreLevel = kErrorIgnoreLevel;
754 if(gErrorIgnoreLevel>3000) AliLog::SetGlobalLogLevel(AliLog::kFatal);
c38e3b95 755 StartAnalysis(smode, chain);
4a6f59cb 756 if((kUseSysInfo>0&&smode=="LOCAL")||!strcmp(plugin_mode, "test")){
757 for(int i = 0;i < mgr->GetTopTasks()->GetEntries();i++){
758 mgr->ProfileTask(i);
759 }
760 }
c38e3b95 761 if (!strcmp(plugin_mode, "offline")&&smode=="GRID"){
e84da0a5 762 // Offline mode path files
763 // PatchJDL();
764 PatchAnalysisMacro();
765 }
c38e3b95 766
e84da0a5 767 if (kSaveTrain && smode=="GRID") {
768 AliAnalysisAlien *gridhandler = (AliAnalysisAlien*)mgr->GetGridHandler();
769 TString alien_workdir = gGrid->GetHomeDirectory();
770 if (iAODanalysis) alien_workdir += "analysisAOD";
3878a941 771 else alien_workdir += "analysisESD";
772 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
e84da0a5 773 // kGridOutdir = gridhandler->GetGridOutputDir();
774 printf("=== Registering ConfigTrain.C in the work directory <%s> ===\n",
c38e3b95 775 alien_workdir.Data());
e84da0a5 776 if (AliAnalysisAlien::FileExists(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data())))
777 gGrid->Rm(Form("%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
778 if (strcmp(plugin_mode, "test"))
779 TFile::Cp(Form("file:%sConfig.C",kTrainName.Data()), Form("alien://%s/%sConfig.C", alien_workdir.Data(), kTrainName.Data()));
780 }
781 }
c38e3b95 782}
783
784//______________________________________________________________________________
785void StartAnalysis(const char *mode, TChain *chain) {
786// Start analysis.
787 Int_t imode = -1;
788 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
789 if (!strcmp(mode, "LOCAL")) imode = 0;
790 if (!strcmp(mode, "PROOF")) imode = 1;
791 if (!strcmp(mode, "GRID")) imode = 2;
792 switch (imode) {
793 case 0:
794 if (!chain) {
795 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
796 return;
797 }
82ebd295 798 mgr->StartAnalysis(mode, chain,kNumberOfEvents);
c38e3b95 799 return;
800 case 1:
801 if (!kProofDataSet.Length()) {
802 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "kProofDataSet is empty");
803 return;
804 }
805 mgr->StartAnalysis(mode, kProofDataSet, kProofEvents,kProofOffset);
806 return;
807 case 2:
808 if (kPluginUse) {
809 if (!mgr->GetGridHandler()) {
810 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Grid plugin not initialized");
811 return;
812 }
ebad39a9 813 mgr->StartAnalysis("grid",chain,kNumberOfEvents);
c38e3b95 814 } else {
815 if (!chain) {
816 ::Error("AnalysisTrainPWG4Jets.C::StartAnalysis", "Cannot create the chain");
817 return;
818 }
819 mgr->StartAnalysis(mode, chain);
ebad39a9 820 mgr->StartAnalysis(mode, chain,kNumberOfEvents);
c38e3b95 821 }
822 return;
823 }
824}
825
826//______________________________________________________________________________
827void CheckModuleFlags(const char *mode) {
828// Checks selected modules and insure compatibility
829 Int_t imode = -1;
830 if (!strcmp(mode, "LOCAL")) imode = 0;
831 if (!strcmp(mode, "PROOF")) imode = 1;
832 if (!strcmp(mode, "GRID")) imode = 2;
833
834
e84da0a5 835 if (kUseCPAR) {
836 kPluginAliRootVersion = ""; // NO aliroot if we use CPAR
837 }
c38e3b95 838
839 if (imode==1) {
840 if (!kUsePAR) {
841 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PAR files enabled due to PROOF analysis");
842 kUsePAR = kTRUE;
843 }
844 }
845 if (imode != 2) {
846 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AliEn plugin disabled since not in GRID mode");
847 kPluginUse = kFALSE;
848 }
849
850
851 if(!kIsMC){
852 // switch off anthin related to MC
853 kUseMC = 0;
854 kUseAODMC = 0;
855 kUseTR = kFALSE;
856 }
857
858 if (iAODanalysis) {
859 // AOD analysis
860 if (kUseMC)
861 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "MC usage disabled in analysis on AOD's");
862 if (kUseAODTags)
863 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "AOD tags usage disabled in analysis on AOD's");
864 kUseMC = kFALSE;
865 kUseTR = kFALSE;
866 kUseAODTags = kFALSE;
867 if (iESDfilter)
868 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "ESD filter disabled in analysis on AOD's");
869 iESDfilter = 0;
e84da0a5 870 if (iPhysicsSelection)
871 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "Physics Selection disabled in analysis on AOD's");
872 iPhysicsSelection = 0;
c38e3b95 873 if (!iAODhandler) {
874 if (iJETAN)
875 ::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "JETAN disabled in analysis on AOD's without AOD handler");
876 iJETAN = 0;
877 iDIJETAN = 0;
878 }
879 // Disable tasks that do not work yet on AOD data
58ef946c 880 if(iPWG4JCORRAN)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 JCORRAN disabled in analysis on AOD's");
4d62ae1a 881 iPWG4JCORRAN = 0;
c38e3b95 882 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
883 iPWG4PtQAMC = 0;
884 if( iPWG4PtQATPC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtTPC disabled in analysis on AOD's");
885 iPWG4PtQATPC = 0;
1f329128 886 if( iPWG4Cosmics)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Comics disabled in analysis on AOD's");
887 iPWG4Cosmics = 0;
888
c38e3b95 889 if( iPWG4PtSpectra)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis on AOD's");
890 iPWG4PtSpectra = 0;
b53f2e4f 891 if(iPWG4KMeans)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4KMeans disabled on AOD's");
892 iPWG4KMeans = 0;
d2e6cdd5 893 if (iPWG4JetCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4Jetcorr disabled on AOD's");
894 iPWG4JetCorr = 0;
c38e3b95 895 if (iPWG4PartCorr)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4partcorr disabled on AOD's");
896 iPWG4PartCorr = 0;
d2e6cdd5 897 if (iPWG4CaloQA)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4CaloQA disabled on AOD's");
898 iPWG4CaloQA = 0;
911a740f 899 if (iPWG4Tagged)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4tagged disabled on AOD's");
900 iPWG4Tagged = 0;
121e4bd5 901 if (iPWG4omega3pi)
902 ::Info("AnalysisTrainNew.C::CheckModuleFlags", "PWG4omega3pi disabled on AOD's");
903 iPWG4omega3pi = 0;
c38e3b95 904 if(iPWG1QASym)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG1 QA Sym disabled in analysis on AOD's");
53c63663 905 if (iPWG4GammaConv)::Info("AnalysisPWG4Jets.C::CheckModuleFlags", "PWG4gammaconv disabled on AOD's");
906 iPWG4GammaConv = 0;
c38e3b95 907 iPWG1QASym = 0;
908 } else {
909 // ESD analysis
910 if (!kUseMC){
911 kUseTR = kFALSE;
912
913 if(kUseKinefilter)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 Kine Filter disabled in analysis without MC");
914 kUseKinefilter = kFALSE;
915 if( iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 PtQAMC disabled in analysis without MC");
916 iPWG4PtQAMC = 0;
9748e967 917 if( iPWG4CorrectionsUE)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "PWG4 CorrectionsUE disabled in analysis without MC");
918 iPWG4CorrectionsUE = 0;
c38e3b95 919 }
920 if (!kUseTR) {
c166d299 921 if(iPWG4PtQAMC)::Info("AnalysisTrainPWG4Jets.C::CheckModuleFlags", "iPWG4QATPCMC disabled if not reading track references");
b03b08a3 922 iPWG4PtQAMC = 0;
c38e3b95 923 }
e84da0a5 924 if (iJETAN){
925 iESDfilter=1;
926 }
c38e3b95 927 if (!iESDfilter){
928 kUseKinefilter = kFALSE;
929 kUseMuonfilter = kFALSE;
930 }
931 if(!iJETAN){
9748e967 932 iPWG4JetSpectrum = iPWG4UE = iPWG4CorrectionsUE = iPWG4ThreeJets = iDIJETAN = 0;
c38e3b95 933 }
934 }
e0c120d9 935 iPWG4JetTasks = iPWG4JetServices||iPWG4JetSpectrum||iPWG4UE||iPWG4LeadingUE||iPWG4PtQAMC||iPWG4PtSpectra||iPWG4PtQATPC||iPWG4Cosmics||iPWG4ThreeJets||iPWG4JetChem||iPWG4Fragmentation;
d2e6cdd5 936 iPWG4PartCorrLibs = iPWG4PartCorr||iPWG4Tagged||iPWG4CaloQA;
17d96675 937 iPWG4GammaConvLib = iPWG4GammaConv||iPWG4CaloConv;
938
939
940 iEMCUtilLibs = iPWG4PartCorrLibs||iPWG4JCORRAN||iPWG4GammaConvLib;
e6993a52 941 iJETANLib = iPWG4JetTasks||iJETAN||iDIJETAN;
17d96675 942
c38e3b95 943 if (iESDfilter) {iAODhandler=1;}
944 if (kUseKinefilter && !kUseMC) kUseKinefilter = kFALSE;
945 if (kUseAODTags && !iAODhandler) kUseAODTags = kFALSE;
946
947
948
949}
950
951//______________________________________________________________________________
952Bool_t Connect(const char *mode) {
953// Connect <username> to the back-end system.
954 Int_t imode = -1;
955 if (!strcmp(mode, "LOCAL")) imode = 0;
956 if (!strcmp(mode, "PROOF")) imode = 1;
957 if (!strcmp(mode, "GRID")) imode = 2;
958 TString username = gSystem->Getenv("alien_API_USER");
959 switch (imode) {
960 case 0:
961 break;
962 case 1:
963 if (!username.Length()) {
964 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
965 1. Have called: alien-token-init <username>\n \
966 2. Have called: >source /tmp/gclient_env_$UID");
967 return kFALSE;
968 }
969 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to PROOF cluster <%s>",
970 username.Data(), kProofCluster.Data());
971 gEnv->SetValue("XSec.GSI.DelegProxy", "2");
972// TProof::Open(Form("%s@%s:31093", username.Data(), kProofCluster.Data()));
973 TProof::Open(Form("%s@%s", username.Data(), kProofCluster.Data()));
974 if (!gProof) {
975 if (strcmp(gSystem->Getenv("XrdSecGSISRVNAMES"), "lxfsrd0506.cern.ch"))
976 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Environment XrdSecGSISRVNAMES different from lxfsrd0506.cern.ch");
977 return kFALSE;
978 }
979 if(kProofClearPackages)gProof->ClearPackages();
980
981 if(kProofSaveToAlien){
982 TGrid::Connect("alien://");
983 if (gGrid) {
984 TString homedir = gGrid->GetHomeDirectory();
985 TString workdir = homedir + kTrainName;
986 if (!gGrid->Cd(workdir)) {
987 gGrid->Cd(homedir);
988 if (gGrid->Mkdir(workdir)) {
989 gGrid->Cd(kTrainName);
990 ::Info("AnalysisTrainPWG4Jets::Connect()", "Directory %s created", gGrid->Pwd());
991 }
992 }
993 gGrid->Mkdir("proof_output");
994 gGrid->Cd("proof_output");
995 kProofOutdir = Form("alien://%s", gGrid->Pwd());
996 }
997 }
998 break;
999 case 2:
1000 if (!username.Length()) {
1001 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode), "Make sure you:\n \
1002 1. Have called: alien-token-init <username>\n \
1003 2. Have called: >source /tmp/gclient_env_$UID");
1004 return kFALSE;
1005 }
1006 if (kPluginUse && !gSystem->Getenv("alien_CLOSE_SE")) {
1007 ::Error(Form("AnalysisTrainPWG4Jets.C::Connect <%s>", mode),
1008 "When using the AliEn plugin it is preferable to define the \
1009 variable alien_CLOSE_SE in your environment.");
1010 return kFALSE;
1011 }
1012 ::Info("AnalysisTrainPWG4Jets.C::Connect", "Connecting user <%s> to AliEn ...",
1013 username.Data());
1014 TGrid::Connect("alien://");
1015 if (!gGrid || !gGrid->IsConnected()) return kFALSE;
1016 break;
1017 default:
1018 ::Error("AnalysisTrainPWG4Jets.C::Connect", "Unknown run mode: %s", mode);
1019 return kFALSE;
1020 }
1021 ::Info("AnalysisTrainPWG4Jets.C::Connect","Connected in %s mode", mode);
1022 return kTRUE;
1023}
1024
1025//______________________________________________________________________________
1026Bool_t LoadCommonLibraries(const char *mode)
1027{
1028// Load common analysis libraries.
1029 Int_t imode = -1;
1030 if (!strcmp(mode, "LOCAL")) imode = 0;
1031 if (!strcmp(mode, "PROOF")) imode = 1;
1032 if (!strcmp(mode, "GRID")) imode = 2;
1033 if (!gSystem->Getenv("ALICE_ROOT")) {
ebad39a9 1034 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Analysis train requires that ALICE_ROOT is set to pick up Configurations");
c38e3b95 1035 return kFALSE;
1036 }
1037 Bool_t success = kTRUE;
1038 // ROOT libraries
1039 gSystem->Load("libTree.so");
1040 gSystem->Load("libGeom.so");
1041 gSystem->Load("libVMC.so");
1042 gSystem->Load("libPhysics.so");
1043
1044 // Load framework classes. Par option ignored here.
1045 switch (imode) {
1046 case 0:
1047 case 2:
1048 if (kUseCPAR) {
1049 success &= LoadLibrary("STEERBase", mode, kTRUE);
1050 success &= LoadLibrary("ESD", mode, kTRUE);
1051 success &= LoadLibrary("AOD", mode, kTRUE);
1052 success &= LoadLibrary("ANALYSIS", mode, kTRUE);
1053 success &= LoadLibrary("ANALYSISalice", mode, kTRUE);
1054 success &= LoadLibrary("CORRFW", mode, kTRUE);
1055 } else {
1056 success &= LoadLibrary("libSTEERBase.so", mode);
1057 success &= LoadLibrary("libESD.so", mode);
1058 success &= LoadLibrary("libAOD.so", mode);
1059 success &= LoadLibrary("libANALYSIS.so", mode);
1060 success &= LoadLibrary("libANALYSISalice.so", mode);
1061 success &= LoadLibrary("libCORRFW.so", mode);
1062 gROOT->ProcessLine(".include $ALICE_ROOT/include");
1063 }
1064 break;
1065 case 1:
1066 Int_t ires = -1;
1067 if (kProofUseAFPAR && !gSystem->AccessPathName(kProofAFversion)) ires = gProof->UploadPackage(kProofAFversion);
1068 if (ires < 0) {
1069 success &= LoadLibrary("STEERBase", mode);
1070 success &= LoadLibrary("ESD", mode);
1071 success &= LoadLibrary("AOD", mode);
1072 success &= LoadLibrary("ANALYSIS", mode);
1073 success &= LoadLibrary("ANALYSISalice", mode);
1074 success &= LoadLibrary("CORRFW", mode);
1075 } else {
1076 ires = gProof->EnablePackage(kProofAFversion);
1077 if (ires<0) success = kFALSE;
1078 success &= LoadLibrary("CORRFW", mode);
1079 }
1080 break;
1081 default:
1082 ::Error("AnalysisTrainPWG4Jets.C::LoadCommonLibraries", "Unknown run mode: %s", mode);
1083 return kFALSE;
1084 }
1085 if (success) {
1086 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: SUCCESS");
1087 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Include path for Aclic compilation:\n%s",
1088 gSystem->GetIncludePath());
1089 } else {
1090 ::Info("AnalysisTrainPWG4Jets.C::LoadCommodLibraries", "Load common libraries: FAILED");
1091 }
1092
1093 return success;
1094}
1095
1096//______________________________________________________________________________
1097Bool_t LoadAnalysisLibraries(const char *mode)
1098{
1099// Load common analysis libraries.
9748e967 1100 Bool_t success = kTRUE;
c38e3b95 1101 if (iESDfilter) {
1102 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
1103 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
1104 }
1105 // JETAN
e6993a52 1106 if (iJETANLib) {
b53f2e4f 1107 // this part needs some rework in case we do not need the fastjed finders for processing
1108 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 1109 if (!strcmp(mode, "PROOF")){
ef1e462f 1110 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 1111 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
1112 // problem when loading siscone copiled with different gcc version??
1113 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
1114 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
1115 }
b53f2e4f 1116 if(!kUsePAR){
e84da0a5 1117 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
1118 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
1119 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
1120 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
1121 }
1122 else{
1123 // par files plus FASTJET needs some extra work... need to change
1124 // the loading sequence in the auto generated .C file
1125 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
1126 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
1127 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
1128 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
1129 }
c38e3b95 1130 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
1131 }
1132 if(iPWG4JetTasks){
c38e3b95 1133 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
1134 }
58ef946c 1135
c38e3b95 1136 if(iPWG1QASym){
99bfd7f7 1137 if (!LoadSource(Form("%s/PWG1/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
c38e3b95 1138 }
121e4bd5 1139 if(iPWG4TmpSourceSara){
c166d299 1140 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 1141 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1142 }
58ef946c 1143
9f77f0ce 1144 /*
1145 if(iPWG4JetChem){
c580ebbb 1146 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1147 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskJetChem.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1148 }
9f77f0ce 1149 */
c166d299 1150
4721d8c5 1151 if(iEMCUtilLibs){
1152 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
1153 !LoadLibrary("PHOSUtils", mode, kTRUE)) return kFALSE;
1154 }
1155
911a740f 1156 if (iPWG4PartCorrLibs) {
4721d8c5 1157 if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c38e3b95 1158 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
1159 }
4721d8c5 1160 if(iPWG4JCORRAN){
1161 // PWG4 particle correlations
1162 if(!LoadLibrary("PWG4JCORRAN",mode,kTRUE))return kFALSE;
1163 }
d2e6cdd5 1164 if (iPWG4JetCorr) {
1165 if (!LoadLibrary("PWG4JetCorrel", mode, kTRUE)) return kFALSE;
1166 }
121e4bd5 1167 if (iPWG4omega3pi) {
1168 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
1169 }
17d96675 1170 if (iPWG4GammaConvLib) {
53c63663 1171 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
1172 }
c38e3b95 1173
1174 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
1175 return kTRUE;
1176}
1177
1178//______________________________________________________________________________
1179Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
1180{
1181// Load a module library in a given mode. Reports success.
1182 Int_t imode = -1;
1183 Int_t result;
1184 TString smodule(module);
1185 if (!strcmp(mode, "LOCAL")) imode = 0;
1186 if (!strcmp(mode, "PROOF")) imode = 1;
1187 if (!strcmp(mode, "GRID")) imode = 2;
1188 TString mod(module);
1189 if (!mod.Length()) {
1190 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
1191 return kFALSE;
1192 }
1193 // If a library is specified, just load it
1194 if (smodule.EndsWith(".so")) {
1195 mod.Remove(mod.Index(".so"));
1196 result = gSystem->Load(mod);
1197 if (result < 0) {
1198 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
1199 return kFALSE;
1200 }
1201 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 1202 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 1203 return kTRUE;
1204 }
1205 // Check if the library is already loaded
1206 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
1207 return kTRUE;
1208 switch (imode) {
1209 case 0:
1210 case 2:
1211 if (kUsePAR) {
1212 result = SetupPar(module);
1213 if (rec) anaPars += Form("%s.par ", module);
1214 } else {
1215 result = gSystem->Load(Form("lib%s.so", module));
1216 if (rec) anaLibs += Form("lib%s.so ", module);
1217 }
1218 break;
1219 case 1:
1220 if(!gSystem->AccessPathName(module)){
1221 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
1222 gSystem->Exec(Form("rm -rf %s",module));
1223 }
1224 result = gProof->UploadPackage(module);
1225 if (result<0) {
1226 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
1227 if (result<0) {
1228 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
1229 return kFALSE;
1230 }
1231 }
1232 result = gProof->EnablePackage(module);
1233 break;
1234 default:
1235 return kFALSE;
1236 }
1237 if (result < 0) {
1238 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
1239 return kFALSE;
1240 }
1241 return kTRUE;
1242}
1243
1244
1245
1246//______________________________________________________________________________
1247Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
1248{
1249// Load a module library in a given mode. Reports success.
1250 Int_t imode = -1;
1251 Int_t result = -1;
1252 if (!strcmp(mode, "LOCAL")) imode = 0;
1253 if (!strcmp(mode, "PROOF")) imode = 1;
1254 if (!strcmp(mode, "GRID")) imode = 2;
1255 TString ssource(source);
1256 TString basename = gSystem->BaseName(ssource.Data());
1257 if (!ssource.Length()) {
1258 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
1259 return kFALSE;
1260 }
4d62ae1a 1261 // we have a source code so compile it
c38e3b95 1262 if (ssource.EndsWith(".cxx")) {
1263 // need to copy it here other wise the path is also used on grid...
1264 ssource.Remove(ssource.Index(".cxx"));
1265 basename.Remove(basename.Index(".cxx"));
1266 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
1267 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
1268 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
1269 // Path to code
1270 // only needed for local compilation, in grid and proof mode
1271 // the task headers are uploaded
1272 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
1273 // Printf("LoadSources:: Including path %s",path.Data());
1274 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
1275 Printf("LoadSources:: Loading... path %s",basename.Data());
1276 switch (imode) {
1277 case 0:
b53f2e4f 1278 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1279 break;
1280 case 1:
b53f2e4f 1281 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1282 break;
1283 case 2:
b53f2e4f 1284 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1285 if (rec){
1286 // what we want to compile
1287 anaSources += Form("%s.cxx ",basename.Data());
1288 // what we need as input...
1289 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
1290 }
1291 break;
1292 default:
1293 return kFALSE;
1294 }
1295 }
1296 if (result < 0) {
1297 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
1298 return kFALSE;
1299 }
1300 return kTRUE;
1301}
1302
1303
1304//______________________________________________________________________________
1305TChain *CreateChain(const char *mode, const char *plugin_mode)
1306{
1307// Create the input chain
1308 Int_t imode = -1;
1309 if (!strcmp(mode, "LOCAL")) imode = 0;
1310 if (!strcmp(mode, "PROOF")) imode = 1;
1311 if (!strcmp(mode, "GRID")) imode = 2;
1312 TChain *chain = NULL;
1313 // Local chain
1314 switch (imode) {
1315 case 0:
1316 if (iAODanalysis) {
1317 if (!kLocalXMLDataset.Length()) {
1318 // Local AOD
1319 chain = new TChain("aodTree");
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 AOD
1331 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1332 }
1333 } else {
1334 if (!kLocalXMLDataset.Length()) {
1335 // Local ESD
1336 chain = new TChain("esdTree");
1337 TString line;
1338 ifstream in;
1339 in.open(kLocalDataList.Data());
1340 while (in.good()) {
1341 in >> line;
1342 if (line.Length() == 0) continue;
1343 cout << " line = " << line << endl;
1344 chain->Add(line.Data());
1345 }
1346 } else {
1347 // Interactive ESD
1348 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1349 }
1350 }
1351 break;
1352 case 1:
1353 break;
1354 case 2:
1355 if (kPluginUse) {
1356// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1357// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1358 } else {
1359 TString treeName = "esdTree";
1360 if (iAODanalysis) treeName = "aodTree";
1361 chain = CreateChainSingle("wn.xml", treeName);
1362 }
1363 break;
1364 default:
1365 }
1366 if (chain && chain->GetNtrees()) return chain;
1367 return NULL;
1368}
1369
1370//______________________________________________________________________________
1371TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1372{
1373 printf("*******************************\n");
1374 printf("*** Getting the ESD Chain ***\n");
1375 printf("*******************************\n");
1376 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1377
1378 if (!myCollection) {
1379 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1380 return NULL ;
1381 }
1382
1383 TChain* chain = new TChain(treeName);
1384 myCollection->Reset() ;
1385 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1386 chain->ls();
1387 return chain;
1388}
1389
1390//______________________________________________________________________________
1391Int_t SetupPar(char* pararchivename)
1392{
1393 if (!pararchivename || !strlen(pararchivename)) return -1;
1394 char processline[1024];
1395 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1396 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1397 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
9748e967 1398 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1399 Form("%s.par",pararchivename));
c38e3b95 1400 } else {
1401 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1402 return -1;
1403 }
1404 }
1405 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1406 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1407
1408 TString ocwd = gSystem->WorkingDirectory();
1409 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1410
1411 // check for BUILD.sh and execute
1412 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1413 printf("*******************************\n");
1414 printf("*** Building PAR archive ***\n");
1415 printf("*******************************\n");
1416 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1417 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1418 return -1;
1419 }
1420 }
1421
1422 // check for SETUP.C and execute
1423 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1424 printf("*******************************\n");
1425 printf("*** Setup PAR archive ***\n");
1426 printf("*******************************\n");
1427 gROOT->Macro("PROOF-INF/SETUP.C");
1428 }
1429 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1430 return 0;
1431}
1432
1433//______________________________________________________________________________
1434AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1435{
1436// Check if user has a valid token, otherwise make one. This has limitations.
1437// One can always follow the standard procedure of calling alien-token-init then
1438// source /tmp/gclient_env_$UID in the current shell.
1439 if (!AliAnalysisGrid::CreateToken()) return NULL;
1440 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1441// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1442 plugin->SetRunMode(plugin_mode);
1443 if (kPluginUseProductionMode) plugin->SetProductionMode();
1444 plugin->SetJobTag(kJobTag);
e0c120d9 1445 plugin->SetNtestFiles(1);
c38e3b95 1446// plugin->SetPreferedSE("ALICE::NIHAM::File");
1447// Set versions of used packages
e84da0a5 1448 plugin->SetAPIVersion("V1.1x");
1449 // plugin->SetAPIVersion("V1.0x");
1450// plugin->SetAPIVersion("V2.4");
c38e3b95 1451 plugin->SetROOTVersion(kPluginRootVersion);
1452 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1453// Declare input data to be processed.
1454// Method 1: Create automatically XML collections using alien 'find' command.
1455// Define production directory LFN
1456 plugin->SetGridDataDir(kGridDatadir.Data());
1457// Set data search pattern
1458 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1459 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1460// ...then add run numbers to be considered
1461// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1462 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1463 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1464 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1465 }
1466
1467 if(kGridLocalRunList.Length()>0){
1468 ifstream in1;
1469 in1.open(kGridLocalRunList.Data());
1470 int iRun;
9a5c5b1e 1471
1472 /*
e84da0a5 1473 char c;
1474 char cLine[250];
1475 while(!in1.eof()){
1476 c = in1.get();
1477 if ( (c >= '0') && (c <= '9') )
1478 {
1479 in1.putback (c);
1480 in1>>iRun;
1481 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1482 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1483 }
1484 else
1485 {
1486 in1.putback (c);
1487 in1.getline(cLine,250);
9a5c5b1e 1488
1489 }
1490 }
1491 */
9748e967 1492
1493 Int_t nRun = 0;
9a5c5b1e 1494
1495 // just use run numbers, negatives will be excluded
1496 while(in1>>iRun){
9748e967 1497
4d5d766e 1498 if(iRun>=0&&(nRun<kGridMaxRunsFromList)){
9a5c5b1e 1499 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1500 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
9748e967 1501 nRun++;
9a5c5b1e 1502 }
1503 else{
1504 Printf("AnalysisTrainPWG4Jets Skipping run number from File %d", iRun);
e84da0a5 1505 }
c38e3b95 1506 }
1507 }
1508
1509// Method 2: Declare existing data files (raw collections, xml collections, root file)
1510// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1511// XML collections added via this method can be combined with the first method if
1512// the content is compatible (using or not tags)
1513// plugin->AddDataFile("tag.xml");
1514// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1515// Define alien work directory where all files will be copied. Relative to alien $HOME.
3878a941 1516 TString alien_workdir = "";
1517
1518 if (iAODanalysis) alien_workdir += "analysisAOD";
1519 else alien_workdir += "analysisESD";
1520 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
1521 plugin->SetGridWorkingDir(alien_workdir.Data());
1522
c38e3b95 1523 // Declare alien output directory. Relative to working directory.
1524 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1525 plugin->SetGridOutputDir(kGridOutdir);
1526
1527 // Add external packages
1528 if (iJETAN||iDIJETAN) {
23adcac8 1529 plugin->AddExternalPackage("boost::v1_43_0");
1530 plugin->AddExternalPackage("cgal::v3.6");
1531 plugin->AddExternalPackage("fastjet::v2.4.2");
c38e3b95 1532 }
1533
1534
1535 // set extra libs before par file compilation
1536 anaLibs += kGridExtraFiles;
1537 anaLibs = anaLibs.Strip();
e84da0a5 1538 Printf("anaLibs %s",anaLibs.Data());
1539 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1540
1541 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1542 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1543
1544 TString ana_sources = "";
1545 TString ana_add = "";
1546 if (kUsePAR && anaPars.Length()) {
1547 printf("%s\n", anaPars.Data());
1548 TObjArray *arr;
1549 TObjString *objstr;
1550 arr = anaPars.Tokenize(" ");
1551 TIter next(arr);
1552 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1553 delete arr;
1554 }
1555
1556// Declare the analysis source files names separated by blancs. To be compiled runtime
1557// using ACLiC on the worker nodes.
1558 ana_sources = anaSources.Strip();
1559// Declare all libraries (other than the default ones for the framework. These will be
1560// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1561
1562 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1563 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
4721d8c5 1564 // Declare the output file names separated by blancs.
1565 // (can be like: file.root or file.root@ALICE::Niham::File)
c38e3b95 1566 plugin->SetMergeExcludes(kGridMergeExclude);
1567 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1568 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
9a5c5b1e 1569 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
4721d8c5 1570 // Use fastread option
9a5c5b1e 1571 plugin->SetFastReadOption(kPluginFastReadOption);
4721d8c5 1572 // UseOverwrite mode
9a5c5b1e 1573 plugin->SetOverwriteMode(kPluginOverwriteMode);
4721d8c5 1574 // Optionally define the files to be archived.
1575 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
dc6a7461 1576 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
c38e3b95 1577
1578 // Put default output files to archive
1579 TString listhists = "";
1580 TString listaods = "";
1581 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1582 TIter next(mgr->GetOutputs());
1583 AliAnalysisDataContainer *output;
1584 while ((output=(AliAnalysisDataContainer*)next())) {
1585 const char *filename = output->GetFileName();
1586 if (!(strcmp(filename, "default"))) {
53c63663 1587 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1588 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1589 if (listaods.Length()) listaods += " ";
c38e3b95 1590 listaods += filename;
c38e3b95 1591 } else {
e84da0a5 1592 if(!listhists.Contains(filename)){
1593 if (listhists.Length()) listhists += " ";
c38e3b95 1594 listhists += filename;
1595 }
1596 }
1597 }
53c63663 1598
53c63663 1599 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1600 if (listaods.Length()) listaods += " ";
53c63663 1601 listaods += mgr->GetExtraFiles();
c38e3b95 1602 }
53c63663 1603
1604 // if we do not fill the aod we do not need to store it
4721d8c5 1605 // kGridMergeExclude = listaods;
e84da0a5 1606
4721d8c5 1607 if(kSaveAOD!=0){
1608 TString outputFiles = "";
1609 outputFiles += mgr->GetExtraFiles();
1610 if (listhists.Length()) outputFiles += " ";
1611 outputFiles += listhists;
e84da0a5 1612 plugin->SetDefaultOutputs(kFALSE);
4721d8c5 1613 Printf("%s:%d Starting with the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1614 // remove
1615 // no harm done when we try to remove something that is not there :)
1616 if(!(kSaveAOD&(1<<0))){
1617 outputFiles.ReplaceAll("AliAOD.root ","");
1618 listaods.ReplaceAll("AliAOD.root ","");
1619 }
1620 if(!(kSaveAOD&(1<<1))){
1621 if(kDeltaAODJetName.Length())outputFiles.ReplaceAll(kDeltaAODJetName.Data(),"");
1622 if(kDeltaAODJetName.Length())listaods.ReplaceAll(kDeltaAODJetName.Data(),"");
1623
1624 }
1625 if(!(kSaveAOD&(1<<2))){
1626 if(kDeltaAODPartCorrName.Length())outputFiles.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1627 if(kDeltaAODPartCorrName.Length())listaods.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1628 }
1629 if(!(kSaveAOD&(1<<3))){
1630 if(kDeltaAODJCORRANName.Length())outputFiles.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1631 if(kDeltaAODJCORRANName.Length())listaods.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1632 }
1633
1634 //
1635 Printf("%s:%d Saving the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1636 plugin->SetOutputFiles(outputFiles.Data());
e84da0a5 1637 }
53c63663 1638
4721d8c5 1639 TString outputArchive;
4d5d766e 1640 outputArchive = Form("log_archive.zip:std*@%s","disk=1");
e84da0a5 1641 listaods.ReplaceAll(" ", ",");
1642 listhists.ReplaceAll(" ", ",");
4d5d766e 1643 if (listhists.Length()){
1644 outputArchive += " ";
1645 outputArchive += "root_archive.zip:";
1646 outputArchive += listhists;
1647 if (listaods.Length()){
1648 outputArchive += ",";
1649 outputArchive += listaods;
1650 }
1651 outputArchive += Form("@%s", kGridOutputStorages.Data());
1652 }
1653 else{
1654
1655 if (listaods.Length()){
1656 // we have only aod'ish output
1657 outputArchive += " ";
1658 outputArchive += "root_archive.zip:";
1659 outputArchive += listaods;
1660 outputArchive += Form("@%s", kGridOutputStorages.Data());
1661 }
1662 else{
1663 // no other outputs than std..
c38e3b95 1664 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
4d5d766e 1665 }
c38e3b95 1666 }
4d5d766e 1667
17d96675 1668 plugin->SetDefaultOutputs(kFALSE);
c38e3b95 1669 plugin->SetOutputArchive(outputArchive);
17d96675 1670
4721d8c5 1671
4d5d766e 1672 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
c38e3b95 1673 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
4d5d766e 1674 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
c38e3b95 1675 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
4d5d766e 1676 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1677 plugin->SetMaxInitFailed(5);
1678 // Optionally resubmit threshold.
1679 // plugin->SetMasterResubmitThreshold(90);
1680 // Optionally set time to live (default 30000 sec)
17d96675 1681 plugin->SetTTL(50400); // 14h...
4d5d766e 1682 // Optionally set input format (default xml-single)
c38e3b95 1683 plugin->SetInputFormat("xml-single");
4d5d766e 1684 // Optionally modify the name of the generated JDL (default analysis.jdl)
c38e3b95 1685 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
4d5d766e 1686 // Optionally modify the executable name (default analysis.sh)
c38e3b95 1687 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
4d5d766e 1688 // Optionally modify job price (default 1)
c38e3b95 1689 plugin->SetPrice(1);
4d5d766e 1690 // Optionally modify split mode (default 'se')
c38e3b95 1691 plugin->SetSplitMode("se");
1692 return plugin;
1693}
1694
1695//______________________________________________________________________________
1696void WriteConfig()
1697{
1698// Write train configuration in a file. The file name has the format:
1699// train_[trainName]_ddMonthyyyy_time.C
1700 if (kUseDate) {
1701 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1702 ifstream fdate("date.tmp");
1703 if (!fdate.is_open()) {
1704 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1705 return;
1706 }
1707 const char date[64];
1708 fdate.getline(date,64);
1709 fdate.close();
1710 gSystem->Exec("rm date.tmp");
1711 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1712 } else {
1713 kTrainName = Form("train_%s", kTrainName.Data());
1714 }
1715 TString cdir = gSystem->WorkingDirectory();
1716 gSystem->MakeDirectory(kTrainName);
1717 gSystem->ChangeDirectory(kTrainName);
1718 ofstream out;
1719 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1720 if (out.bad()) {
1721 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1722 return;
1723 }
1724 out << "{" << endl;
1725 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1726 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1727 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1728 if (kProofUseAFPAR)
1729 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1730 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1731 out << " kPluginUse = " << kPluginUse << ";" << endl;
1732 out << " kUsePAR = " << kUsePAR << ";" << endl;
1733 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1734 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1735 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1736 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1737 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1738 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1739 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1740 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1741 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1742 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1743 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1744 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1745 out << " kUseDebug = " << kUseDebug << ";" << endl;
1746 out << " kUseMC = " << kUseMC << ";" << endl;
1747 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1748 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1749 out << " kUseTR = " << kUseTR << ";" << endl;
1750 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1751 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1752 out << " // Analysis modules" << endl;
1753 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1754 out << " iAODhandler = " << iAODhandler << ";" << endl;
1755 out << " iESDfilter = " << iESDfilter << ";" << endl;
1756 out << " iJETAN = " << iJETAN << ";" << endl;
1757 out << "// Configuration fot the wagons" << endl;
1758 out << "}" << endl;
1759 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1760 gSystem->ChangeDirectory(cdir);
1761}
1762
1763//______________________________________________________________________________
1764Bool_t LoadConfig(const char *filename)
1765{
1766// Read train configuration from file
1767 if (gSystem->AccessPathName(filename)) {
1768 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1769 return kFALSE;
1770 }
1771 gROOT->ProcessLine(Form(".x %s", filename));
1772 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1773 return kTRUE;
1774}
1775
1776Bool_t PatchJDL(){
1777 Printf(">>> Patching JDL");
1778 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1779 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1780 TGridJDL *jdl = gridHandler->GetGridJDL();
1781 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1782 gridHandler->WriteJDL(kFALSE);
0971dabc 1783 Printf("<<< Patching JDL");
c38e3b95 1784 return kTRUE;
1785}
1786
1787Bool_t PatchAnalysisMacro(){
4721d8c5 1788 Printf(">>> Patching AnalysisMacro");
1789 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
c38e3b95 1790
1791 ifstream in1;
1792 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1793 char cLine[250];
1794 TString st;
1795 while(in1.getline(cLine,250)){
1796 st += cLine;
1797 st += "\n";
1798 }
4721d8c5 1799 Int_t index= -1;
c38e3b95 1800 index = st.Index("gSystem->Load(\"libPhysics\");");
1801 index += strlen("gSystem->Load(\"libPhysics\");");
4721d8c5 1802 /*
c38e3b95 1803 TObjArray *arr;
1804 TObjString *objstr;
1805 arr = anaLibs.Tokenize(" ");
1806 TIter next(arr);
4721d8c5 1807
c38e3b95 1808 add += "\n\n // added by CKB \n";
1809 while ((objstr=(TObjString*)next())){
e84da0a5 1810 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1811 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1812 }
1813 delete arr;
4721d8c5 1814 */
3878a941 1815 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
4721d8c5 1816 TString add = "";
1817
1818 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1819 add += "\n\n // added by CKB \n";
46534866 1820 if(kErrorIgnoreLevel>0)add += Form("gErrorIgnoreLevel = %d;\n",kErrorIgnoreLevel);
23adcac8 1821 add += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1822 if(gGrid&&kPluginAliRootVersion.Length()==0){
1823 add += "\n // Dirty hack for TRD reference data \n";
1824 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1825 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1826 add += "\"); \n";
c38e3b95 1827 }
4721d8c5 1828 add += "// BKC \n\n";
1829 st.Insert(index,add.Data());
e84da0a5 1830
1831 if(kUseDebug){
23adcac8 1832 // st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
e84da0a5 1833 }
1834
4721d8c5 1835 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1836 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1837 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1838 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1839 }
c166d299 1840
46534866 1841 if(AliLog::GetGlobalLogLevel()==AliLog::kFatal){
1842 index = st.Index("AliLog::SetGlobal"); // ncomment setting of log level, do my own
1843 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1844 st.Insert(index,"AliLog::SetGlobalLogLevel(AliLog::kFatal);// CKB \n // CKB comment out for own setting \n //");
1845 }
1846
c38e3b95 1847 ofstream out;
1848 out.open(Form("%s.C", kTrainName.Data()));
1849 if (out.bad()) {
1850 return kFALSE;
1851 }
1852 out << st << endl;
1853 Printf("<<< Patching AnalysisMacro");
4721d8c5 1854
1855
1856
1857
1858
1859 Printf(">>> Patching Merge Macro");
1860 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1861
1862 ifstream in2;
1863 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1864 TString st2;
1865 while(in2.getline(cLine,250)){
1866 st2 += cLine;
1867 st2 += "\n";
1868 }
1869 index = st2.Index("gSystem->Load(\"libPhysics\");");
1870 index += strlen("gSystem->Load(\"libPhysics\");");
1871 TString add2 = "";
23adcac8 1872 add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1873 if(gGrid&&kPluginAliRootVersion.Length()==0){
1874 add2 += "\n // Dirty hack for TRD reference data \n";
1875 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1876 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1877 add2 += "\"); \n";
1878 }
1879 add2 += "// BKC \n\n";
1880 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1881 st2.Insert(index,add.Data());
1882
1883
1884 if(kUseDebug){
23adcac8 1885 // st2.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
4721d8c5 1886 }
1887
1888 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
46534866 1889 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncomment $ALICE_ROOT include for par files
4721d8c5 1890 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1891 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1892 }
1893
1894 // do not exclude the extra files from merign, this is done explicitly in this train script
1895 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1896 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1897 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1898
1899
1900 ofstream out2;
1901 out2.open(Form("%s_merge.C", kTrainName.Data()));
1902 if (out2.bad()) {
1903 return kFALSE;
1904 }
1905 out2 << st2 << endl;
1906 Printf("<<< Patching Merging Macro");
1907
1908
1909
c38e3b95 1910 return kTRUE;
1911
1912}