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