From Stefano: Add missing macro to display AliEveBeamsInfo object.
[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";
b0a36f28 680 TString gcArguments = "-run-on-train -run-jet -run-omega-meson -use-own-xyz -run-neutralmeson -no-aod";
4d5d766e 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) {
b0a36f28 1102 /*
c38e3b95 1103 if (!LoadLibrary("PWG3base", mode, kTRUE) ||
1104 !LoadLibrary("PWG3muon", mode, kTRUE)) return kFALSE;
b0a36f28 1105 */
c38e3b95 1106 }
1107 // JETAN
e6993a52 1108 if (iJETANLib) {
b53f2e4f 1109 // this part needs some rework in case we do not need the fastjed finders for processing
1110 if (!LoadLibrary("JETAN", mode, kTRUE)) return kFALSE;
c38e3b95 1111 if (!strcmp(mode, "PROOF")){
ef1e462f 1112 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libCGAL.so\"\)", kTRUE);
c38e3b95 1113 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libfastjet.so\"\)", kTRUE);
1114 // problem when loading siscone copiled with different gcc version??
1115 // gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libsiscone.so\"\)", kTRUE);
1116 gProof->Exec("gSystem->Load\(\"/afs/cern.ch/user/d/dperrino/public/libSISConePlugin.so\"\)", kTRUE);
1117 }
b53f2e4f 1118 if(!kUsePAR){
e84da0a5 1119 if (!LoadLibrary("CGAL", mode, kTRUE)) return kFALSE;
1120 if (!LoadLibrary("fastjet", mode, kTRUE)) return kFALSE;
1121 if (!LoadLibrary("siscone", mode, kTRUE)) return kFALSE;
1122 if (!LoadLibrary("SISConePlugin", mode, kTRUE)) return kFALSE;
1123 }
1124 else{
1125 // par files plus FASTJET needs some extra work... need to change
1126 // the loading sequence in the auto generated .C file
1127 if (!LoadLibrary("libCGAL.so", mode, kTRUE)) return kFALSE;
1128 if (!LoadLibrary("libfastjet.so", mode, kTRUE)) return kFALSE;
1129 if (!LoadLibrary("libsiscone.so", mode, kTRUE)) return kFALSE;
1130 if (!LoadLibrary("libSISConePlugin.so", mode, kTRUE)) return kFALSE;
1131 }
c38e3b95 1132 if (!LoadLibrary("FASTJETAN", mode, kTRUE)) return kFALSE;
1133 }
1134 if(iPWG4JetTasks){
c38e3b95 1135 if (!LoadLibrary("PWG4JetTasks", mode, kTRUE)) return kFALSE;
1136 }
58ef946c 1137
c38e3b95 1138 if(iPWG1QASym){
99bfd7f7 1139 if (!LoadSource(Form("%s/PWG1/AliAnalysisTaskQASym.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
c38e3b95 1140 }
121e4bd5 1141 if(iPWG4TmpSourceSara){
c166d299 1142 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
121e4bd5 1143 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskEta.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1144 }
58ef946c 1145
9f77f0ce 1146 /*
1147 if(iPWG4JetChem){
c580ebbb 1148 if(!kUsePAR)gSystem->AddIncludePath("-I$ALICE_ROOT/include/JetTasks"); // ugly hack!!
1149 if(!LoadSource(Form("%s/PWG4/JetTasks/AliAnalysisTaskJetChem.cxx",gSystem->ExpandPathName("$ALICE_ROOT")), mode, kTRUE))return kFALSE;
1150 }
9f77f0ce 1151 */
c166d299 1152
4721d8c5 1153 if(iEMCUtilLibs){
1154 if (!LoadLibrary("EMCALUtils", mode, kTRUE) ||
1155 !LoadLibrary("PHOSUtils", mode, kTRUE)) return kFALSE;
1156 }
1157
911a740f 1158 if (iPWG4PartCorrLibs) {
4721d8c5 1159 if (!LoadLibrary("PWG4PartCorrBase", mode, kTRUE) ||
c38e3b95 1160 !LoadLibrary("PWG4PartCorrDep", mode, kTRUE)) return kFALSE;
1161 }
4721d8c5 1162 if(iPWG4JCORRAN){
1163 // PWG4 particle correlations
1164 if(!LoadLibrary("PWG4JCORRAN",mode,kTRUE))return kFALSE;
1165 }
d2e6cdd5 1166 if (iPWG4JetCorr) {
1167 if (!LoadLibrary("PWG4JetCorrel", mode, kTRUE)) return kFALSE;
1168 }
121e4bd5 1169 if (iPWG4omega3pi) {
1170 if (!LoadLibrary("PWG4omega3pi", mode, kTRUE)) return kFALSE;
1171 }
17d96675 1172 if (iPWG4GammaConvLib) {
53c63663 1173 if (!LoadLibrary("PWG4GammaConv", mode, kTRUE)) return kFALSE;
1174 }
c38e3b95 1175
1176 ::Info("AnalysisTrainPWG4Jets.C::LoadAnalysisLibraries", "Load other libraries: SUCCESS");
1177 return kTRUE;
1178}
1179
1180//______________________________________________________________________________
1181Bool_t LoadLibrary(const char *module, const char *mode, Bool_t rec=kFALSE)
1182{
1183// Load a module library in a given mode. Reports success.
1184 Int_t imode = -1;
1185 Int_t result;
1186 TString smodule(module);
1187 if (!strcmp(mode, "LOCAL")) imode = 0;
1188 if (!strcmp(mode, "PROOF")) imode = 1;
1189 if (!strcmp(mode, "GRID")) imode = 2;
1190 TString mod(module);
1191 if (!mod.Length()) {
1192 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Empty module name");
1193 return kFALSE;
1194 }
1195 // If a library is specified, just load it
1196 if (smodule.EndsWith(".so")) {
1197 mod.Remove(mod.Index(".so"));
1198 result = gSystem->Load(mod);
1199 if (result < 0) {
1200 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load library %s", module);
1201 return kFALSE;
1202 }
1203 if (rec) anaLibs += Form("%s.so ",mod.Data());
e84da0a5 1204 if (rec) anaLibsExtra += Form("%s.so ",mod.Data());
c38e3b95 1205 return kTRUE;
1206 }
1207 // Check if the library is already loaded
1208 if (strlen(gSystem->GetLibraries(Form("%s.so", module), "", kFALSE)) > 0)
1209 return kTRUE;
1210 switch (imode) {
1211 case 0:
1212 case 2:
1213 if (kUsePAR) {
1214 result = SetupPar(module);
1215 if (rec) anaPars += Form("%s.par ", module);
1216 } else {
1217 result = gSystem->Load(Form("lib%s.so", module));
1218 if (rec) anaLibs += Form("lib%s.so ", module);
1219 }
1220 break;
1221 case 1:
1222 if(!gSystem->AccessPathName(module)){
1223 ::Info("AnalysisTrainPWG4Jets.C::LoadLibrary", "Removing directory %s",module);
1224 gSystem->Exec(Form("rm -rf %s",module));
1225 }
1226 result = gProof->UploadPackage(module);
1227 if (result<0) {
1228 result = gProof->UploadPackage(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", module)));
1229 if (result<0) {
1230 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not find module %s.par in current directory nor in $ALICE_ROOT", module);
1231 return kFALSE;
1232 }
1233 }
1234 result = gProof->EnablePackage(module);
1235 break;
1236 default:
1237 return kFALSE;
1238 }
1239 if (result < 0) {
1240 ::Error("AnalysisTrainPWG4Jets.C::LoadLibrary", "Could not load module %s", module);
1241 return kFALSE;
1242 }
1243 return kTRUE;
1244}
1245
1246
1247
1248//______________________________________________________________________________
1249Bool_t LoadSource(const char *source, const char *mode, Bool_t rec=kFALSE)
1250{
1251// Load a module library in a given mode. Reports success.
1252 Int_t imode = -1;
1253 Int_t result = -1;
1254 if (!strcmp(mode, "LOCAL")) imode = 0;
1255 if (!strcmp(mode, "PROOF")) imode = 1;
1256 if (!strcmp(mode, "GRID")) imode = 2;
1257 TString ssource(source);
1258 TString basename = gSystem->BaseName(ssource.Data());
1259 if (!ssource.Length()) {
1260 ::Error("AnalysisTrainPWG4Jets.C::LoadSource", "Empty task name");
1261 return kFALSE;
1262 }
4d62ae1a 1263 // we have a source code so compile it
c38e3b95 1264 if (ssource.EndsWith(".cxx")) {
1265 // need to copy it here other wise the path is also used on grid...
1266 ssource.Remove(ssource.Index(".cxx"));
1267 basename.Remove(basename.Index(".cxx"));
1268 Printf("LoadSources:: Copying... path %s{cxx,h}",ssource.Data());
1269 gSystem->Exec(Form("cp %s.cxx . ",ssource.Data()));
1270 gSystem->Exec(Form("cp %s.h . ",ssource.Data()));
1271 // Path to code
1272 // only needed for local compilation, in grid and proof mode
1273 // the task headers are uploaded
1274 // path.Remove(path.Index(gSystem->BaseName(path.Data())));
1275 // Printf("LoadSources:: Including path %s",path.Data());
1276 // if(path.Length()>0)gROOT->ProcessLine(Form(".include %s",path.Data()));
1277 Printf("LoadSources:: Loading... path %s",basename.Data());
1278 switch (imode) {
1279 case 0:
b53f2e4f 1280 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1281 break;
1282 case 1:
b53f2e4f 1283 result = gProof->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1284 break;
1285 case 2:
b53f2e4f 1286 result = gROOT->LoadMacro(Form("%s.cxx++g",basename.Data()));
c38e3b95 1287 if (rec){
1288 // what we want to compile
1289 anaSources += Form("%s.cxx ",basename.Data());
1290 // what we need as input...
1291 anaLibs += Form("%s.cxx %s.h ",basename.Data(),basename.Data());
1292 }
1293 break;
1294 default:
1295 return kFALSE;
1296 }
1297 }
1298 if (result < 0) {
1299 ::Error("AnalysisTrainPWG4Jets.C::LoadSources", "Could not load source %s", source);
1300 return kFALSE;
1301 }
1302 return kTRUE;
1303}
1304
1305
1306//______________________________________________________________________________
1307TChain *CreateChain(const char *mode, const char *plugin_mode)
1308{
1309// Create the input chain
1310 Int_t imode = -1;
1311 if (!strcmp(mode, "LOCAL")) imode = 0;
1312 if (!strcmp(mode, "PROOF")) imode = 1;
1313 if (!strcmp(mode, "GRID")) imode = 2;
1314 TChain *chain = NULL;
1315 // Local chain
1316 switch (imode) {
1317 case 0:
1318 if (iAODanalysis) {
1319 if (!kLocalXMLDataset.Length()) {
1320 // Local AOD
1321 chain = new TChain("aodTree");
1322 TString line;
1323 ifstream in;
1324 in.open(kLocalDataList.Data());
1325 while (in.good()) {
1326 in >> line;
1327 if (line.Length() == 0) continue;
1328 // cout << " line = " << line << endl;
1329 chain->Add(line.Data());
1330 }
1331 } else {
1332 // Interactive AOD
1333 chain = CreateChainSingle(kLocalXMLDataset, "aodTree");
1334 }
1335 } else {
1336 if (!kLocalXMLDataset.Length()) {
1337 // Local ESD
1338 chain = new TChain("esdTree");
1339 TString line;
1340 ifstream in;
1341 in.open(kLocalDataList.Data());
1342 while (in.good()) {
1343 in >> line;
1344 if (line.Length() == 0) continue;
1345 cout << " line = " << line << endl;
1346 chain->Add(line.Data());
1347 }
1348 } else {
1349 // Interactive ESD
1350 chain = CreateChainSingle(kLocalXMLDataset, "esdTree");
1351 }
1352 }
1353 break;
1354 case 1:
1355 break;
1356 case 2:
1357 if (kPluginUse) {
1358// AliAnalysisGrid *alienHandler = CreateAlienHandler(plugin_mode);
1359// AliAnalysisManager::GetAnalysisManager()->SetGridHandler(alienHandler);
1360 } else {
1361 TString treeName = "esdTree";
1362 if (iAODanalysis) treeName = "aodTree";
1363 chain = CreateChainSingle("wn.xml", treeName);
1364 }
1365 break;
1366 default:
1367 }
1368 if (chain && chain->GetNtrees()) return chain;
1369 return NULL;
1370}
1371
1372//______________________________________________________________________________
1373TChain* CreateChainSingle(const char* xmlfile, const char *treeName)
1374{
1375 printf("*******************************\n");
1376 printf("*** Getting the ESD Chain ***\n");
1377 printf("*******************************\n");
1378 TAlienCollection * myCollection = TAlienCollection::Open(xmlfile);
1379
1380 if (!myCollection) {
1381 ::Error("AnalysisTrainPWG4Jets.C::CreateChainSingle", "Cannot create an AliEn collection from %s", xmlfile) ;
1382 return NULL ;
1383 }
1384
1385 TChain* chain = new TChain(treeName);
1386 myCollection->Reset() ;
1387 while ( myCollection->Next() ) chain->Add(myCollection->GetTURL("")) ;
1388 chain->ls();
1389 return chain;
1390}
1391
1392//______________________________________________________________________________
1393Int_t SetupPar(char* pararchivename)
1394{
1395 if (!pararchivename || !strlen(pararchivename)) return -1;
1396 char processline[1024];
1397 if (gSystem->AccessPathName(Form("%s.par", pararchivename))) {
1398 if (!gSystem->AccessPathName(Form("%s/%s.par", gSystem->Getenv("ALICE_ROOT"),pararchivename))) {
1399 ::Info("AnalysisTrainPWG4Jets.C::SetupPar", "Getting %s.par from $ALICE_ROOT", pararchivename);
9748e967 1400 TFile::Cp(gSystem->ExpandPathName(Form("$ALICE_ROOT/%s.par", pararchivename)),
1401 Form("%s.par",pararchivename));
c38e3b95 1402 } else {
1403 ::Error("AnalysisTrainPWG4Jets.C::SetupPar", "Cannot find %s.par", pararchivename);
1404 return -1;
1405 }
1406 }
1407 if (kPluginUse && kSaveTrain) gSystem->Exec(Form("ln -s ../%s.par %s",pararchivename, kTrainName.Data()));
1408 gSystem->Exec(Form("tar xvzf %s.par", pararchivename));
1409
1410 TString ocwd = gSystem->WorkingDirectory();
1411 if (!gSystem->ChangeDirectory(pararchivename)) return -1;
1412
1413 // check for BUILD.sh and execute
1414 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
1415 printf("*******************************\n");
1416 printf("*** Building PAR archive ***\n");
1417 printf("*******************************\n");
1418 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
1419 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
1420 return -1;
1421 }
1422 }
1423
1424 // check for SETUP.C and execute
1425 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
1426 printf("*******************************\n");
1427 printf("*** Setup PAR archive ***\n");
1428 printf("*******************************\n");
1429 gROOT->Macro("PROOF-INF/SETUP.C");
1430 }
1431 if (!gSystem->ChangeDirectory(ocwd.Data())) return -1;
1432 return 0;
1433}
1434
1435//______________________________________________________________________________
1436AliAnalysisAlien* CreateAlienHandler(const char *plugin_mode)
1437{
1438// Check if user has a valid token, otherwise make one. This has limitations.
1439// One can always follow the standard procedure of calling alien-token-init then
1440// source /tmp/gclient_env_$UID in the current shell.
1441 if (!AliAnalysisGrid::CreateToken()) return NULL;
1442 AliAnalysisAlien *plugin = new AliAnalysisAlien();
1443// Set the run mode (can be "full", "test", "offline", "submit" or "terminate")
1444 plugin->SetRunMode(plugin_mode);
1445 if (kPluginUseProductionMode) plugin->SetProductionMode();
1446 plugin->SetJobTag(kJobTag);
e0c120d9 1447 plugin->SetNtestFiles(1);
c38e3b95 1448// plugin->SetPreferedSE("ALICE::NIHAM::File");
1449// Set versions of used packages
e84da0a5 1450 plugin->SetAPIVersion("V1.1x");
1451 // plugin->SetAPIVersion("V1.0x");
1452// plugin->SetAPIVersion("V2.4");
c38e3b95 1453 plugin->SetROOTVersion(kPluginRootVersion);
1454 plugin->SetAliROOTVersion(kPluginAliRootVersion);
1455// Declare input data to be processed.
1456// Method 1: Create automatically XML collections using alien 'find' command.
1457// Define production directory LFN
1458 plugin->SetGridDataDir(kGridDatadir.Data());
1459// Set data search pattern
1460 if (iAODanalysis) plugin->SetDataPattern(" *AliAOD.root");
1461 else plugin->SetDataPattern(Form(" %s/*/*ESD.tag.root",kGridPassPattern.Data()));
1462// ...then add run numbers to be considered
1463// plugin->SetRunRange(kGridRunRange[0], kGridRunRange[1]);
1464 for (Int_t i=kGridRunRange[0]; i<=kGridRunRange[1]; i++) {
1465 Printf("AnalysisTrainPWG4Jets Adding run number %s", Form(kGridRunPattern.Data(),i));
1466 plugin->AddRunNumber(Form(kGridRunPattern.Data(),i));
1467 }
1468
1469 if(kGridLocalRunList.Length()>0){
1470 ifstream in1;
1471 in1.open(kGridLocalRunList.Data());
1472 int iRun;
9a5c5b1e 1473
1474 /*
e84da0a5 1475 char c;
1476 char cLine[250];
1477 while(!in1.eof()){
1478 c = in1.get();
1479 if ( (c >= '0') && (c <= '9') )
1480 {
1481 in1.putback (c);
1482 in1>>iRun;
1483 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1484 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
1485 }
1486 else
1487 {
1488 in1.putback (c);
1489 in1.getline(cLine,250);
9a5c5b1e 1490
1491 }
1492 }
1493 */
9748e967 1494
1495 Int_t nRun = 0;
9a5c5b1e 1496
1497 // just use run numbers, negatives will be excluded
1498 while(in1>>iRun){
9748e967 1499
4d5d766e 1500 if(iRun>=0&&(nRun<kGridMaxRunsFromList)){
9a5c5b1e 1501 Printf("AnalysisTrainPWG4Jets Adding run number from File %s", Form(kGridRunPattern.Data(),iRun));
1502 plugin->AddRunNumber(Form(kGridRunPattern.Data(),iRun));
9748e967 1503 nRun++;
9a5c5b1e 1504 }
1505 else{
1506 Printf("AnalysisTrainPWG4Jets Skipping run number from File %d", iRun);
e84da0a5 1507 }
c38e3b95 1508 }
1509 }
1510
1511// Method 2: Declare existing data files (raw collections, xml collections, root file)
1512// If no path mentioned data is supposed to be in the work directory (see SetGridWorkingDir())
1513// XML collections added via this method can be combined with the first method if
1514// the content is compatible (using or not tags)
1515// plugin->AddDataFile("tag.xml");
1516// plugin->AddDataFile("/alice/data/2008/LHC08c/000057657/raw/Run57657.Merged.RAW.tag.root");
1517// Define alien work directory where all files will be copied. Relative to alien $HOME.
3878a941 1518 TString alien_workdir = "";
1519
1520 if (iAODanalysis) alien_workdir += "analysisAOD";
1521 else alien_workdir += "analysisESD";
1522 if(kGridDataSet.Length()>0)alien_workdir += Form("/%s",kGridDataSet.Data());
1523 plugin->SetGridWorkingDir(alien_workdir.Data());
1524
c38e3b95 1525 // Declare alien output directory. Relative to working directory.
1526 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1527 plugin->SetGridOutputDir(kGridOutdir);
1528
1529 // Add external packages
1530 if (iJETAN||iDIJETAN) {
23adcac8 1531 plugin->AddExternalPackage("boost::v1_43_0");
1532 plugin->AddExternalPackage("cgal::v3.6");
1533 plugin->AddExternalPackage("fastjet::v2.4.2");
c38e3b95 1534 }
1535
1536
1537 // set extra libs before par file compilation
1538 anaLibs += kGridExtraFiles;
1539 anaLibs = anaLibs.Strip();
e84da0a5 1540 Printf("anaLibs %s",anaLibs.Data());
1541 Printf("anaLibsExtra %s",anaLibsExtra.Data());
1542
1543 if (anaLibs.Length()) plugin->SetAdditionalLibs(anaLibs.Data());
1544 if (anaLibsExtra.Length()) plugin->SetAdditionalRootLibs(anaLibsExtra.Data());
c38e3b95 1545
1546 TString ana_sources = "";
1547 TString ana_add = "";
1548 if (kUsePAR && anaPars.Length()) {
1549 printf("%s\n", anaPars.Data());
1550 TObjArray *arr;
1551 TObjString *objstr;
1552 arr = anaPars.Tokenize(" ");
1553 TIter next(arr);
1554 while ((objstr=(TObjString*)next())) plugin->EnablePackage(objstr->GetString());
1555 delete arr;
1556 }
1557
1558// Declare the analysis source files names separated by blancs. To be compiled runtime
1559// using ACLiC on the worker nodes.
1560 ana_sources = anaSources.Strip();
1561// Declare all libraries (other than the default ones for the framework. These will be
1562// loaded by the generated analysis macro. Add all extra files (task .cxx/.h) here.
1563
1564 if (ana_sources.Length()) plugin->SetAnalysisSource(ana_sources);
1565 plugin->SetExecutableCommand(kPluginExecutableCommand.Data());
4721d8c5 1566 // Declare the output file names separated by blancs.
1567 // (can be like: file.root or file.root@ALICE::Niham::File)
c38e3b95 1568 plugin->SetMergeExcludes(kGridMergeExclude);
1569 plugin->SetMaxMergeFiles(kGridMaxMergeFiles);
1570 plugin->SetNrunsPerMaster(kGridRunsPerMaster);
9a5c5b1e 1571 plugin->SetMergeViaJDL(kPluginMergeViaJDL);
4721d8c5 1572 // Use fastread option
9a5c5b1e 1573 plugin->SetFastReadOption(kPluginFastReadOption);
4721d8c5 1574 // UseOverwrite mode
9a5c5b1e 1575 plugin->SetOverwriteMode(kPluginOverwriteMode);
4721d8c5 1576 // Optionally define the files to be archived.
1577 // plugin->SetOutputArchive("log_archive.zip:stdout,stderr@ALICE::NIHAM::File root_archive.zip:AliAOD.root,AOD.tag.root@ALICE::NIHAM::File");
dc6a7461 1578 plugin->SetOutputToRunNo(kPluginOutputToRunNumber); // write the output to subdirs named after run number
c38e3b95 1579
1580 // Put default output files to archive
1581 TString listhists = "";
1582 TString listaods = "";
1583 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1584 TIter next(mgr->GetOutputs());
1585 AliAnalysisDataContainer *output;
1586 while ((output=(AliAnalysisDataContainer*)next())) {
1587 const char *filename = output->GetFileName();
1588 if (!(strcmp(filename, "default"))) {
53c63663 1589 if (!mgr->GetOutputEventHandler()) continue;
c38e3b95 1590 filename = mgr->GetOutputEventHandler()->GetOutputFileName();
e84da0a5 1591 if (listaods.Length()) listaods += " ";
c38e3b95 1592 listaods += filename;
c38e3b95 1593 } else {
e84da0a5 1594 if(!listhists.Contains(filename)){
1595 if (listhists.Length()) listhists += " ";
c38e3b95 1596 listhists += filename;
1597 }
1598 }
1599 }
53c63663 1600
53c63663 1601 if (mgr->GetExtraFiles().Length()) {
e84da0a5 1602 if (listaods.Length()) listaods += " ";
53c63663 1603 listaods += mgr->GetExtraFiles();
c38e3b95 1604 }
53c63663 1605
1606 // if we do not fill the aod we do not need to store it
4721d8c5 1607 // kGridMergeExclude = listaods;
e84da0a5 1608
4721d8c5 1609 if(kSaveAOD!=0){
1610 TString outputFiles = "";
1611 outputFiles += mgr->GetExtraFiles();
1612 if (listhists.Length()) outputFiles += " ";
1613 outputFiles += listhists;
e84da0a5 1614 plugin->SetDefaultOutputs(kFALSE);
4721d8c5 1615 Printf("%s:%d Starting with the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1616 // remove
1617 // no harm done when we try to remove something that is not there :)
1618 if(!(kSaveAOD&(1<<0))){
1619 outputFiles.ReplaceAll("AliAOD.root ","");
1620 listaods.ReplaceAll("AliAOD.root ","");
1621 }
1622 if(!(kSaveAOD&(1<<1))){
1623 if(kDeltaAODJetName.Length())outputFiles.ReplaceAll(kDeltaAODJetName.Data(),"");
1624 if(kDeltaAODJetName.Length())listaods.ReplaceAll(kDeltaAODJetName.Data(),"");
1625
1626 }
1627 if(!(kSaveAOD&(1<<2))){
1628 if(kDeltaAODPartCorrName.Length())outputFiles.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1629 if(kDeltaAODPartCorrName.Length())listaods.ReplaceAll(kDeltaAODPartCorrName.Data(),"");
1630 }
1631 if(!(kSaveAOD&(1<<3))){
1632 if(kDeltaAODJCORRANName.Length())outputFiles.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1633 if(kDeltaAODJCORRANName.Length())listaods.ReplaceAll(kDeltaAODJCORRANName.Data(),"");
1634 }
1635
1636 //
1637 Printf("%s:%d Saving the files %s",(char*)__FILE__,__LINE__,outputFiles.Data());
1638 plugin->SetOutputFiles(outputFiles.Data());
e84da0a5 1639 }
53c63663 1640
4721d8c5 1641 TString outputArchive;
4d5d766e 1642 outputArchive = Form("log_archive.zip:std*@%s","disk=1");
e84da0a5 1643 listaods.ReplaceAll(" ", ",");
1644 listhists.ReplaceAll(" ", ",");
4d5d766e 1645 if (listhists.Length()){
1646 outputArchive += " ";
1647 outputArchive += "root_archive.zip:";
1648 outputArchive += listhists;
1649 if (listaods.Length()){
1650 outputArchive += ",";
1651 outputArchive += listaods;
1652 }
1653 outputArchive += Form("@%s", kGridOutputStorages.Data());
1654 }
1655 else{
1656
1657 if (listaods.Length()){
1658 // we have only aod'ish output
1659 outputArchive += " ";
1660 outputArchive += "root_archive.zip:";
1661 outputArchive += listaods;
1662 outputArchive += Form("@%s", kGridOutputStorages.Data());
1663 }
1664 else{
1665 // no other outputs than std..
c38e3b95 1666 ::Fatal("AnalysisTrainPWG4Jets", "No task output !");
4d5d766e 1667 }
c38e3b95 1668 }
4d5d766e 1669
17d96675 1670 plugin->SetDefaultOutputs(kFALSE);
c38e3b95 1671 plugin->SetOutputArchive(outputArchive);
17d96675 1672
4721d8c5 1673
4d5d766e 1674 // Optionally set a name for the generated analysis macro (default MyAnalysis.C)
c38e3b95 1675 plugin->SetAnalysisMacro(Form("%s.C", kTrainName.Data()));
4d5d766e 1676 // Optionally set maximum number of input files/subjob (default 100, put 0 to ignore)
c38e3b95 1677 plugin->SetSplitMaxInputFileNumber(kGridFilesPerJob);
4d5d766e 1678 // Optionally set number of failed jobs that will trigger killing waiting sub-jobs.
1679 plugin->SetMaxInitFailed(5);
1680 // Optionally resubmit threshold.
1681 // plugin->SetMasterResubmitThreshold(90);
1682 // Optionally set time to live (default 30000 sec)
17d96675 1683 plugin->SetTTL(50400); // 14h...
4d5d766e 1684 // Optionally set input format (default xml-single)
c38e3b95 1685 plugin->SetInputFormat("xml-single");
4d5d766e 1686 // Optionally modify the name of the generated JDL (default analysis.jdl)
c38e3b95 1687 plugin->SetJDLName(Form("%s.jdl", kTrainName.Data()));
4d5d766e 1688 // Optionally modify the executable name (default analysis.sh)
c38e3b95 1689 plugin->SetExecutable(Form("%s.sh", kTrainName.Data()));
4d5d766e 1690 // Optionally modify job price (default 1)
c38e3b95 1691 plugin->SetPrice(1);
4d5d766e 1692 // Optionally modify split mode (default 'se')
c38e3b95 1693 plugin->SetSplitMode("se");
1694 return plugin;
1695}
1696
1697//______________________________________________________________________________
1698void WriteConfig()
1699{
1700// Write train configuration in a file. The file name has the format:
1701// train_[trainName]_ddMonthyyyy_time.C
1702 if (kUseDate) {
1703 gSystem->Exec("date +%d%b%Y_%Hh%M > date.tmp");
1704 ifstream fdate("date.tmp");
1705 if (!fdate.is_open()) {
1706 ::Error("AnalysisTrainPWG4Jets.C::Export","Could not generate file name");
1707 return;
1708 }
1709 const char date[64];
1710 fdate.getline(date,64);
1711 fdate.close();
1712 gSystem->Exec("rm date.tmp");
1713 kTrainName = Form("train_%s_%s", kTrainName.Data(), date);
1714 } else {
1715 kTrainName = Form("train_%s", kTrainName.Data());
1716 }
1717 TString cdir = gSystem->WorkingDirectory();
1718 gSystem->MakeDirectory(kTrainName);
1719 gSystem->ChangeDirectory(kTrainName);
1720 ofstream out;
1721 out.open(Form("%sConfig.C",kTrainName.Data()), ios::out);
1722 if (out.bad()) {
1723 ::Error("AnalysisTrainPWG4Jets.C::Export", "Cannot open ConfigTrain.C for writing");
1724 return;
1725 }
1726 out << "{" << endl;
1727 out << " kTrainName = " << "\"" << kTrainName.Data() << "\";" << endl;
1728 out << " kProofCluster = " << "\"" << kProofCluster.Data() << "\";" << endl;
1729 out << " kProofUseAFPAR = " << kProofUseAFPAR << ";" << endl;
1730 if (kProofUseAFPAR)
1731 out << " kProofAFversion = " << kProofAFversion.Data() << ";" << endl;
1732 out << " kProofDataSet = " << "\"" << kProofDataSet.Data() << "\";" << endl;
1733 out << " kPluginUse = " << kPluginUse << ";" << endl;
1734 out << " kUsePAR = " << kUsePAR << ";" << endl;
1735 out << " kUseCPAR = " << kUseCPAR << ";" << endl;
1736 out << " kPluginRootVersion = " << "\"" << kPluginRootVersion.Data() << "\";" << endl;
1737 out << " kPluginAliRootVersion = " << "\"" << kPluginAliRootVersion.Data() << "\";" << endl;
1738 out << " kGridDatadir = " << "\"" << kGridDatadir.Data() << "\";" << endl;
1739 if (!kGridOutdir.Length()) kGridOutdir = Form("output_%s",kTrainName.Data());
1740 out << " kGridOutdir = " << "\"" << kGridOutdir.Data() << "\";" << endl;
1741 out << " kGridMaxMergeFiles = " << kGridMaxMergeFiles << ";" << endl;
1742 out << " kGridMergeExclude = " << "\"" << kGridMergeExclude.Data() << "\";" << endl;
1743 out << " kGridRunsPerMaster = " << kGridRunsPerMaster << ";" << endl;
1744 out << " kGridFilesPerJob = " << kGridFilesPerJob << ";" << endl;
1745 out << " kGridRunRange[0] = " << kGridRunRange[0] << ";" << endl;
1746 out << " kGridRunRange[1] = " << kGridRunRange[1] << ";" << endl;
1747 out << " kUseDebug = " << kUseDebug << ";" << endl;
1748 out << " kUseMC = " << kUseMC << ";" << endl;
1749 out << " kUseESDTags = " << kUseESDTags << ";" << endl;
1750 out << " kUseKinefilter = " << kUseKinefilter << ";" << endl;
1751 out << " kUseTR = " << kUseTR << ";" << endl;
1752 out << " kUseAODTags = " << kUseAODTags << ";" << endl;
1753 out << " kSaveTrain = " << "kFALSE;" << endl << endl;
1754 out << " // Analysis modules" << endl;
1755 out << " iAODanalysis = " << iAODanalysis << ";" << endl;
1756 out << " iAODhandler = " << iAODhandler << ";" << endl;
1757 out << " iESDfilter = " << iESDfilter << ";" << endl;
1758 out << " iJETAN = " << iJETAN << ";" << endl;
1759 out << "// Configuration fot the wagons" << endl;
1760 out << "}" << endl;
1761 ::Info("AnalysisTrainPWG4Jets.C::WriteConfig", "Train configuration wrote to file %s", Form("config_%s.C", kTrainName.Data()));
1762 gSystem->ChangeDirectory(cdir);
1763}
1764
1765//______________________________________________________________________________
1766Bool_t LoadConfig(const char *filename)
1767{
1768// Read train configuration from file
1769 if (gSystem->AccessPathName(filename)) {
1770 ::Error("AnalysisTrainPWG4Jets.C::LoadConfig", "Config file name not found");
1771 return kFALSE;
1772 }
1773 gROOT->ProcessLine(Form(".x %s", filename));
1774 ::Info("AnalysisTrainPWG4Jets.C::LoadConfig", "Train configuration loaded from file %s", filename);
1775 return kTRUE;
1776}
1777
1778Bool_t PatchJDL(){
1779 Printf(">>> Patching JDL");
1780 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1781 AliAnalysisAlien* gridHandler = (AliAnalysisAlien*)mgr->GetGridHandler();
1782 TGridJDL *jdl = gridHandler->GetGridJDL();
1783 if(iJETAN)jdl->AddToPackages("fastjet","v2.4.0");
1784 gridHandler->WriteJDL(kFALSE);
0971dabc 1785 Printf("<<< Patching JDL");
c38e3b95 1786 return kTRUE;
1787}
1788
1789Bool_t PatchAnalysisMacro(){
4721d8c5 1790 Printf(">>> Patching AnalysisMacro");
1791 gSystem->Exec(Form("mv %s.C %s.C_tmp",kTrainName.Data(),kTrainName.Data()));
c38e3b95 1792
1793 ifstream in1;
1794 in1.open(Form("%s.C_tmp", kTrainName.Data()));
1795 char cLine[250];
1796 TString st;
1797 while(in1.getline(cLine,250)){
1798 st += cLine;
1799 st += "\n";
1800 }
4721d8c5 1801 Int_t index= -1;
c38e3b95 1802 index = st.Index("gSystem->Load(\"libPhysics\");");
1803 index += strlen("gSystem->Load(\"libPhysics\");");
4721d8c5 1804 /*
c38e3b95 1805 TObjArray *arr;
1806 TObjString *objstr;
1807 arr = anaLibs.Tokenize(" ");
1808 TIter next(arr);
4721d8c5 1809
c38e3b95 1810 add += "\n\n // added by CKB \n";
1811 while ((objstr=(TObjString*)next())){
e84da0a5 1812 if(objstr->GetString().Contains("PWG3"))continue;
c38e3b95 1813 if(objstr->GetString().EndsWith(".so"))add += Form("gSystem->Load(\"%s\");\n",objstr->GetString().Data());
1814 }
1815 delete arr;
4721d8c5 1816 */
3878a941 1817 // add += Form("AliLog::SetGlobalLogLevel(%d);\n",AliLog::GetGlobalLogLevel());
4721d8c5 1818 TString add = "";
1819
1820 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1821 add += "\n\n // added by CKB \n";
46534866 1822 if(kErrorIgnoreLevel>0)add += Form("gErrorIgnoreLevel = %d;\n",kErrorIgnoreLevel);
23adcac8 1823 add += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1824 if(gGrid&&kPluginAliRootVersion.Length()==0){
1825 add += "\n // Dirty hack for TRD reference data \n";
1826 add += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1827 add += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1828 add += "\"); \n";
c38e3b95 1829 }
4721d8c5 1830 add += "// BKC \n\n";
1831 st.Insert(index,add.Data());
e84da0a5 1832
1833 if(kUseDebug){
23adcac8 1834 // st.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
e84da0a5 1835 }
1836
4721d8c5 1837 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
1838 index = st.Index("gSystem->AddIncludePath(\"-I$"); // uncommen $ALICE_ROOT include for par files
1839 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1840 st.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1841 }
c166d299 1842
46534866 1843 if(AliLog::GetGlobalLogLevel()==AliLog::kFatal){
1844 index = st.Index("AliLog::SetGlobal"); // ncomment setting of log level, do my own
1845 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1846 st.Insert(index,"AliLog::SetGlobalLogLevel(AliLog::kFatal);// CKB \n // CKB comment out for own setting \n //");
1847 }
1848
c38e3b95 1849 ofstream out;
1850 out.open(Form("%s.C", kTrainName.Data()));
1851 if (out.bad()) {
1852 return kFALSE;
1853 }
1854 out << st << endl;
1855 Printf("<<< Patching AnalysisMacro");
4721d8c5 1856
1857
1858
1859
1860
1861 Printf(">>> Patching Merge Macro");
1862 gSystem->Exec(Form("mv %s_merge.C %s_merge.C_tmp",kTrainName.Data(),kTrainName.Data()));
1863
1864 ifstream in2;
1865 in2.open(Form("%s_merge.C_tmp", kTrainName.Data()));
1866 TString st2;
1867 while(in2.getline(cLine,250)){
1868 st2 += cLine;
1869 st2 += "\n";
1870 }
1871 index = st2.Index("gSystem->Load(\"libPhysics\");");
1872 index += strlen("gSystem->Load(\"libPhysics\");");
1873 TString add2 = "";
23adcac8 1874 add2 += "\n gSystem->AddIncludePath(\"./\"); \n";
4721d8c5 1875 if(gGrid&&kPluginAliRootVersion.Length()==0){
1876 add2 += "\n // Dirty hack for TRD reference data \n";
1877 add2 += "\n gSystem->Setenv(\"ALICE_ROOT\",\"";
1878 add2 += Form("alien://%s/rootfiles/",gGrid->GetHomeDirectory());
1879 add2 += "\"); \n";
1880 }
1881 add2 += "// BKC \n\n";
1882 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1883 st2.Insert(index,add.Data());
1884
1885
1886 if(kUseDebug){
23adcac8 1887 // st2.Insert(index,"\n gROOT->ProcessLine(\".trace\"); // CKB \n");
4721d8c5 1888 }
1889
1890 if(kUseCPAR&&kPluginAliRootVersion.Length()==0){
46534866 1891 index = st2.Index("gSystem->AddIncludePath(\"-I$"); // uncomment $ALICE_ROOT include for par files
4721d8c5 1892 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1893 st2.Insert(index,"// CKB comment out whehn no aliroot is provided \n //");
1894 }
1895
1896 // do not exclude the extra files from merign, this is done explicitly in this train script
1897 index = st2.Index("mergeExcludes +="); // uncommen $ALICE_ROOT include for par files
1898 if(index<0)Printf("%s:%d index out of bounds",(char*)__FILE__,__LINE__);
1899 st2.Insert(index,"// CKB comment out, handled explicitly by the train macro \n //");
1900
1901
1902 ofstream out2;
1903 out2.open(Form("%s_merge.C", kTrainName.Data()));
1904 if (out2.bad()) {
1905 return kFALSE;
1906 }
1907 out2 << st2 << endl;
1908 Printf("<<< Patching Merging Macro");
1909
1910
1911
c38e3b95 1912 return kTRUE;
1913
1914}