TENDER becomes Tender
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / macros / runEMCalJetAnalysis.C
CommitLineData
8628b70c 1// runEMCalJetAnalysis.C
2// =====================
3// This macro can be used to run a jet analysis within the EMCal Jet Framework.
4//
5// Examples:
6// -> Analyze ESDs from the pA pilot run on the AliEn grid with your task in AnaClass.cxx/.h
7// dataType = "ESD", useGrid = kTRUE, pattern = "*ESDs/pass2/*ESDs.root", addCXXs = "AnaClass.cxx",
8// addHs = "AnaClass.h", gridDir = "/alice/data/2012/LHC12g", gridMode = "full", runNumbers = "188359 188362"
9//
10// -> Analyze AODs (up to 96 files) locally given in files_aod.txt
11// dataType = "AOD", useGrid = kFALSE, numLocalFiles = 96
12//
13// MERGING ON ALIEN
14// ++++++++++++++++
15// If you run on the grid, you can monitor the jobs with alimonitor.cern.ch. When enough of them are in DONE state,
16// you have to merge the output. This can be done automatically, if you just change the gridMode to "terminate" and
17// give the EXACT name of the task whose output should be merged in uniqueName.
18//
19//
20// Authors: R. Haake, S. Aiola
21
22#include <ctime>
23#include "TGrid.h"
24
25AliAnalysisGrid* CreateAlienHandler(const char* uniqueName, const char* gridDir, const char* gridMode, const char* runNumbers,
26 const char* pattern, TString additionalCode, TString additionalHeaders, Int_t maxFilesPerWorker,
27 Int_t workerTTL, Bool_t isMC);
28
29//______________________________________________________________________________
30void runEMCalJetAnalysis(
d4f91bbd 31 Bool_t useGrid = kTRUE, // local or grid
8628b70c 32 const char* gridMode = "test", // set the grid run mode (can be "full", "test", "offline", "submit" or "terminate")
d4f91bbd 33 const char* dataType = "AOD", // set the analysis type, AOD, ESD or sESD
34 const char* pattern = "*ESDs/pass2/AOD145/*AOD.root", // file pattern (here one can specify subdirs like passX etc.) (used on grid)
35 const char* gridDir = "/alice/data/2011/LHC11h_2", // dir on alien, where the files live (used on grid)
36 const char* runNumbers = "167903 167915", // considered run numbers (used on grid)
8628b70c 37 UInt_t numLocalFiles = 50, // number of files analyzed locally
d4f91bbd 38 const char* runPeriod = "LHC11h", // set the run period (used on grid)
50c26926 39 const char* uniqueName = "EMCalJF_LEGOTrainTest", // sets base string for the name of the train on the grid
40 UInt_t pSel = AliVEvent::kAny, // used event selection for every task
d8a15971 41 Bool_t useTender = kTRUE, // trigger, if tender, track and cluster selection should be used (always)
95449deb 42 Bool_t isMC = kFALSE, // trigger, if MC handler should be used
50c26926 43 Bool_t doBkg = kTRUE,
8628b70c 44 // Here you have to specify additional code files you want to use but that are not in aliroot
45 const char* addCXXs = "",
46 const char* addHs = "",
47
48 // These two settings depend on the dataset and your quotas on the AliEN services
49 Int_t maxFilesPerWorker = 4,
50 Int_t workerTTL = 7200
51
52 )
53{
54
55 // Some pre-settings and constants
8628b70c 56 enum AlgoType {kKT, kANTIKT};
57 enum JetType {kFULLJETS, kCHARGEDJETS, kNEUTRALJETS};
58 gSystem->SetFPEMask();
59 gSystem->Setenv("ETRAIN_ROOT", ".");
60 gSystem->Setenv("ETRAIN_PERIOD", runPeriod);
61 // change this objects to strings
62 TString usedData(dataType);
63 TString additionalCXXs(addCXXs);
64 TString additionalHs(addHs);
65 cout << dataType << " analysis chosen" << endl;
66 if (useGrid)
67 {
68 cout << "-- using AliEn grid.\n";
69 if (usedData == "sESD")
70 {
71 cout << "Skimmed ESD analysis not available on the grid!" << endl;
72 return;
73 }
74 }
75 else
76 cout << "-- using local analysis.\n";
77
78
79 // Load necessary libraries
80 LoadLibs();
81
82 // Create analysis manager
83 AliAnalysisManager* mgr = new AliAnalysisManager(uniqueName);
84
85 // Check type of input and create handler for it
86 TString localFiles("-1");
87 if(usedData == "AOD")
88 {
89 localFiles = "files_aod.txt";
90 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddAODHandler.C");
91 AliAODInputHandler* aodH = AddAODHandler();
92 }
93 else if((usedData == "ESD") || (usedData == "sESD"))
94 {
95 if (usedData == "ESD")
96 localFiles = "files_esd.txt";
97 else
98 localFiles = "files_sesd.txt";
99
100 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddESDHandler.C");
101 AliESDInputHandler* esdH = AddESDHandler();
102 }
103 else
104 {
105 cout << "Data type not recognized! You have to specify ESD, AOD, or sESD!\n";
106 }
d8a15971 107
8628b70c 108 if(!useGrid)
109 cout << "Using " << localFiles.Data() << " as input file list.\n";
110
111 // Create MC handler, if MC is demanded
12eb4ac1 112 if (isMC && (usedData != "AOD"))
8628b70c 113 {
114 AliMCEventHandler* mcH = new AliMCEventHandler();
115 mcH->SetPreReadMode(AliMCEventHandler::kLmPreRead);
116 mcH->SetReadTR(kTRUE);
117 mgr->SetMCtruthEventHandler(mcH);
118 }
119
120 // ################# Now: Add some basic tasks
121
122 // Physics selection task
ec289988 123 if(!isMC) {
124 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalPhysicsSelection.C");
125 AliPhysicsSelectionTask *physSelTask = AddTaskEmcalPhysicsSelection(kTRUE, kTRUE, pSel, 5, 5, 10, kTRUE, -1, -1, -1, -1);
126 if (!physSelTask) {
127 cout << "no physSelTask but running on data" << endl;
128 return;
129 }
8628b70c 130 }
131
132 // Centrality task
133 if (usedData == "ESD") {
134 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
135 AliCentralitySelectionTask *centralityTask = AddTaskCentrality(kTRUE);
136 }
137
138 // Compatibility task, only needed for skimmed ESD
139 if (usedData == "sESD") {
140 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalCompat.C");
141 AliEmcalCompatTask *comptask = AddTaskEmcalCompat();
142 }
143
144 // Setup task
145 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalSetup.C");
146 AliEmcalSetupTask *setupTask = AddTaskEmcalSetup();
7030f36f 147 setupTask->SetGeoPath("$ALICE_ROOT/OADB/EMCAL");
8628b70c 148
8628b70c 149 // Tender Supplies
d8a15971 150 if (useTender) {
151 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalPreparation.C");
152 //adjust pass when running locally. On grid give empty string, will be picked up automatically from path to ESD/AOD file
153 AliAnalysisTaskSE *clusm = AddTaskEmcalPreparation(runPeriod,"pass1");
8628b70c 154 }
155
d4f91bbd 156 // Names of the different objects passed around; these are the default names; added here mostly for documentation purposes
50c26926 157 // rhoName is only set if the background calculation is switched on (doBkg)
d4f91bbd 158 TString tracksName = "PicoTracks";
d8a15971 159 TString clustersName = "EmcCaloClusters";
d4f91bbd 160 TString clustersCorrName = "CaloClustersCorr";
161 TString rhoName = "";
162
8628b70c 163 // ################# Now: Call jet preparation macro (picotracks, hadronic corrected caloclusters, ...)
8628b70c 164 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/EMCALJetTasks/macros/AddTaskJetPreparation.C");
50c26926 165 TString particlesMCName = "";
166 if(isMC) particlesMCName = "MCParticlesSelected";
167 AddTaskJetPreparation(runPeriod, tracksName, particlesMCName.Data(), clustersName, clustersCorrName);
8628b70c 168
169 // ################# Now: Add jet finders+analyzers
8628b70c 170 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/EMCALJetTasks/macros/AddTaskEmcalJet.C");
d4f91bbd 171 AliEmcalJetTask* jetFinderTask = AddTaskEmcalJet(tracksName, clustersCorrName, kANTIKT, 0.2, kCHARGEDJETS, 0.150, 0.300);
172
173 if (doBkg) {
174 rhoName = "Rho";
50c26926 175 AliEmcalJetTask* jetFinderTaskKT = AddTaskEmcalJet(tracksName, clustersCorrName, kKT, 0.2, kCHARGEDJETS, 0.150, 0.300);
d4f91bbd 176
50c26926 177 TString kTpcKtJetsName = jetFinderTaskKT->GetName();
d4f91bbd 178 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/EMCALJetTasks/macros/AddTaskRho.C");
179 rhotask = (AliAnalysisTaskRho*) AddTaskRho(kTpcKtJetsName, tracksName, clustersCorrName, rhoName, 0.2, "TPC", 0.01, 0, 0, 2, kTRUE);
180 //rhotask__->SetScaleFunction(sfunc);
181 //rhotask->SelectCollisionCandidates(kPhysSel);
182 rhotask->SetHistoBins(100,0,250);
183 }
8628b70c 184 // Here you can put in your AddTaskMacro for your task
185 gROOT->LoadMacro("$ALICE_ROOT/PWGJE/EMCALJetTasks/macros/AddTaskEmcalJetSample.C");
d4f91bbd 186 AliAnalysisTaskEmcalJetSample* anaTask = 0;
187 AddTaskEmcalJetSample(tracksName, clustersCorrName, jetFinderTask->GetName(), rhoName, 4);
8628b70c 188
189 // Set the physics selection for all given tasks
190 TObjArray *toptasks = mgr->GetTasks();
191 for (Int_t i=0; i<toptasks->GetEntries(); ++i)
192 {
193 AliAnalysisTaskSE *task = dynamic_cast<AliAnalysisTaskSE*>(toptasks->At(i));
194 if (!task)
195 continue;
196 if (task->InheritsFrom("AliPhysicsSelectionTask"))
197 continue;
198 ::Info("setPSel", "Set physics selection for %s (%s)", task->GetName(), task->ClassName());
199 task->SelectCollisionCandidates(pSel);
200 }
201
202 mgr->SetUseProgressBar(1, 25);
203
204 if (!mgr->InitAnalysis())
205 return;
206 mgr->PrintStatus();
207
208 if (useGrid)
209 { // GRID CALCULATION
210
211 AliAnalysisGrid *plugin = CreateAlienHandler(uniqueName, gridDir, gridMode, runNumbers, pattern, additionalCXXs, additionalHs, maxFilesPerWorker, workerTTL, isMC);
212 mgr->SetGridHandler(plugin);
213
214 // start analysis
215 cout << "Starting GRID Analysis...";
216 mgr->SetDebugLevel(0);
217 mgr->StartAnalysis("grid");
218 }
219 else
220 { // LOCAL CALCULATION
221
222 TChain* chain = 0;
223 if (usedData == "AOD")
224 {
225 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/CreateAODChain.C");
226 chain = CreateAODChain(localFiles.Data(), numLocalFiles);
227 }
228 else
229 { // ESD or skimmed ESD
230 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/CreateESDChain.C");
231 chain = CreateESDChain(localFiles.Data(), numLocalFiles);
232 }
233
234 // start analysis
235 cout << "Starting LOCAL Analysis...";
236 mgr->SetDebugLevel(2);
237 mgr->StartAnalysis("local", chain);
238 }
239}
240
241//______________________________________________________________________________
242void LoadLibs()
243{
244 // Load common libraries (better too many than too few)
245 gSystem->Load("libTree");
246 gSystem->Load("libVMC");
247 gSystem->Load("libGeom");
248 gSystem->Load("libGui");
249 gSystem->Load("libXMLParser");
250 gSystem->Load("libMinuit");
251 gSystem->Load("libMinuit2");
252 gSystem->Load("libProof");
253 gSystem->Load("libPhysics");
254 gSystem->Load("libSTEERBase");
255 gSystem->Load("libESD");
256 gSystem->Load("libAOD");
257 gSystem->Load("libOADB");
258 gSystem->Load("libANALYSIS");
259 gSystem->Load("libCDB");
260 gSystem->Load("libRAWDatabase");
261 gSystem->Load("libSTEER");
262 gSystem->Load("libEVGEN");
263 gSystem->Load("libANALYSISalice");
264 gSystem->Load("libCORRFW");
265 gSystem->Load("libTOFbase");
266 //gSystem->Load("libTOFrec");
267 gSystem->Load("libRAWDatabase.so");
268 gSystem->Load("libRAWDatarec.so");
269 gSystem->Load("libTPCbase.so");
270 gSystem->Load("libTPCrec.so");
271 gSystem->Load("libITSbase.so");
272 gSystem->Load("libITSrec.so");
273 gSystem->Load("libTRDbase.so");
af472fff 274 gSystem->Load("libTender.so");
8628b70c 275 gSystem->Load("libSTAT.so");
276 gSystem->Load("libTRDrec.so");
277 gSystem->Load("libHMPIDbase.so");
278 gSystem->Load("libPWGPP.so");
279 gSystem->Load("libPWGHFbase");
280 gSystem->Load("libPWGDQdielectron");
281 gSystem->Load("libPWGHFhfe");
282 gSystem->Load("libEMCALUtils");
283 gSystem->Load("libPHOSUtils");
284 gSystem->Load("libPWGCaloTrackCorrBase");
285 gSystem->Load("libEMCALraw");
286 gSystem->Load("libEMCALbase");
287 gSystem->Load("libEMCALrec");
288 gSystem->Load("libTRDbase");
289 gSystem->Load("libVZERObase");
290 gSystem->Load("libVZEROrec");
af472fff 291 gSystem->Load("libTender");
292 gSystem->Load("libTenderSupplies");
0764884d 293 gSystem->Load("libPWGTools");
8628b70c 294 gSystem->Load("libPWGEMCAL");
3c91145c 295 gSystem->Load("libESDfilter");
8628b70c 296 gSystem->Load("libPWGGAEMCALTasks");
8628b70c 297 gSystem->Load("libPWGCFCorrelationsBase");
298 gSystem->Load("libPWGCFCorrelationsDPhi");
299
300 //load CGAL, Fastjet and SISCone
301 gSystem->Load("libCGAL");
302 gSystem->Load("libfastjet");
0764884d 303 //For FastJet 3.x use siscon*,fastjetplugins for 2.x use SISConePlugin
04332ed6 304 // gSystem->Load("libSISConePlugin");
305 // gSystem->Load("libCDFConesPlugin");
306 gSystem->Load("libsiscone");
307 gSystem->Load("libsiscone_spherical");
308 gSystem->Load("libfastjetplugins");
309 gSystem->Load("libfastjettools");
ab06b52b 310 gSystem->Load("libfastjetcontribfragile");
04332ed6 311 //
8628b70c 312 gSystem->Load("libJETAN");
b9b2c3f8 313// gSystem->Load("libFASTJETAN");
8628b70c 314 gSystem->Load("libPWGJEEMCALJetTasks");
315
316
317 // include paths
318 gSystem->AddIncludePath("-Wno-deprecated");
319 gSystem->AddIncludePath("-I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/EMCAL");
320 gSystem->AddIncludePath("-I$ALICE_ROOT/PWGDQ/dielectron -I$ALICE_ROOT/PWGHF/hfe");
321 gSystem->AddIncludePath("-I$ALICE_ROOT/JETAN -I$ALICE_ROOT/JETAN/fastjet");
322}
323
324AliAnalysisGrid* CreateAlienHandler(const char* uniqueName, const char* gridDir, const char* gridMode, const char* runNumbers,
325 const char* pattern, TString additionalCode, TString additionalHeaders, Int_t maxFilesPerWorker,
326 Int_t workerTTL, Bool_t isMC)
327{
328 TDatime currentTime;
329 TString tmpName(uniqueName);
330
331 // Only add current date and time when not in terminate mode! In this case the exact name has to be supplied by the user
332 if(strcmp(gridMode, "terminate"))
333 {
334 tmpName += "_";
335 tmpName += currentTime.GetDate();
336 tmpName += "_";
337 tmpName += currentTime.GetTime();
338 }
339
340 TString tmpAdditionalLibs("");
af472fff 341 tmpAdditionalLibs = Form("libTree.so libVMC.so libGeom.so libGui.so libXMLParser.so libMinuit.so libMinuit2.so libProof.so libPhysics.so libSTEERBase.so libESD.so libAOD.so libOADB.so libANALYSIS.so libCDB.so libRAWDatabase.so libSTEER.so libANALYSISalice.so libCORRFW.so libTOFbase.so libRAWDatabase.so libRAWDatarec.so libTPCbase.so libTPCrec.so libITSbase.so libITSrec.so libTRDbase.so libTender.so libSTAT.so libTRDrec.so libHMPIDbase.so libPWGPP.so libPWGHFbase.so libPWGDQdielectron.so libPWGHFhfe.so libEMCALUtils.so libPHOSUtils.so libPWGCaloTrackCorrBase.so libEMCALraw.so libEMCALbase.so libEMCALrec.so libTRDbase.so libVZERObase.so libVZEROrec.so libTender.so libTenderSupplies.so libESDfilter.so libPWGTools.so libPWGEMCAL.so libPWGGAEMCALTasks.so libPWGCFCorrelationsBase.so libPWGCFCorrelationsDPhi.so libCGAL.so libJETAN.so libfastjet.so libsiscone.so libsiscone_spherical.so libfastjetplugins.so libfastjettools.so libfastjetcontribfragile.so libPWGJE.so libPWGmuon.so libPWGJEEMCALJetTasks.so %s %s",additionalCode.Data(),additionalHeaders.Data());
8628b70c 342
343
344 TString macroName("");
345 TString execName("");
346 TString jdlName("");
347 macroName = Form("%s.C", tmpName.Data());
348 execName = Form("%s.sh", tmpName.Data());
349 jdlName = Form("%s.jdl", tmpName.Data());
350
351 AliAnalysisAlien *plugin = new AliAnalysisAlien();
352 plugin->SetOverwriteMode();
353 plugin->SetRunMode(gridMode);
354
355 // Here you can set the (Ali)ROOT version you want to use
356 plugin->SetAPIVersion("V1.1x");
d4f91bbd 357 plugin->SetROOTVersion("v5-34-08-6");
358 plugin->SetAliROOTVersion("vAN-20140525");
8628b70c 359
360 plugin->SetGridDataDir(gridDir); // e.g. "/alice/sim/LHC10a6"
361 plugin->SetDataPattern(pattern); //dir structure in run directory
362 if (!isMC)
363 plugin->SetRunPrefix("000");
364
365 plugin->AddRunList(runNumbers);
366
367 plugin->SetGridWorkingDir(Form("work/%s",tmpName.Data()));
368 plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
369
370 plugin->SetAnalysisSource(additionalCode.Data());
371 plugin->SetAdditionalLibs(tmpAdditionalLibs.Data());
372 plugin->AddExternalPackage("boost::v1_43_0");
373 plugin->AddExternalPackage("cgal::v3.6");
374 plugin->AddExternalPackage("fastjet::v2.4.2");
375
376 plugin->SetDefaultOutputs(kTRUE);
377 //plugin->SetMergeExcludes("");
378 plugin->SetAnalysisMacro(macroName.Data());
379 plugin->SetSplitMaxInputFileNumber(maxFilesPerWorker);
380 plugin->SetExecutable(execName.Data());
381 plugin->SetTTL(workerTTL);
382 plugin->SetInputFormat("xml-single");
383 plugin->SetJDLName(jdlName.Data());
384 plugin->SetPrice(1);
385 plugin->SetSplitMode("se");
386
387 return plugin;
388}