2 // =====================
3 // This macro can be used to run EMCal analysis within the EMCal part of the Jet Framework.
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"
10 // -> Analyze AODs (up to 96 files) locally given in files_aod.txt
11 // dataType = "AOD", useGrid = kFALSE, numLocalFiles = 96
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.
20 // Authors: R. Haake, S. Aiola, M. Verweij
25 AliAnalysisGrid* 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);
29 //______________________________________________________________________________
30 void runEMCalAnalysis(
31 Bool_t useGrid = kTRUE, // local or grid
32 const char* gridMode = "test", // set the grid run mode (can be "full", "test", "offline", "submit" or "terminate")
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)
37 UInt_t numLocalFiles = 1, // number of files analyzed locally
38 const char* runPeriod = "LHC11h", // set the run period (used on grid)
39 const char* uniqueName = "EMCal_LEGOTrainTest", // sets base string for the name of the task on the grid
40 UInt_t pSel = AliVEvent::kAny, // used event selection for every task except for the analysis tasks
41 Bool_t useTender = kTRUE, // trigger, if tender, track and cluster selection should be used (always)
42 Bool_t isMC = kFALSE, // trigger, if MC handler should be used
43 // Here you have to specify additional code files you want to use but that are not in aliroot
44 const char* addCXXs = "",
45 const char* addHs = "",
47 // These two settings depend on the dataset and your quotas on the AliEN services
48 Int_t maxFilesPerWorker = 4,
49 Int_t workerTTL = 7200
54 // Some pre-settings and constants
55 enum AlgoType {kKT, kANTIKT};
56 enum JetType {kFULLJETS, kCHARGEDJETS, kNEUTRALJETS};
57 gSystem->SetFPEMask();
58 gSystem->Setenv("ETRAIN_ROOT", ".");
59 gSystem->Setenv("ETRAIN_PERIOD", runPeriod);
60 // change this objects to strings
61 TString usedData(dataType);
62 TString additionalCXXs(addCXXs);
63 TString additionalHs(addHs);
64 cout << dataType << " analysis chosen" << endl;
67 cout << "-- using AliEn grid.\n";
68 if (usedData == "sESD")
70 cout << "Skimmed ESD analysis not available on the grid!" << endl;
75 cout << "-- using local analysis.\n";
78 // Load necessary libraries
81 // Create analysis manager
82 AliAnalysisManager* mgr = new AliAnalysisManager(uniqueName);
84 // Check type of input and create handler for it
85 TString localFiles("-1");
88 localFiles = "files_aod.txt";
89 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddAODHandler.C");
90 AliAODInputHandler* aodH = AddAODHandler();
92 else if((usedData == "ESD") || (usedData == "sESD"))
94 if (usedData == "ESD")
95 localFiles = "files_esd.txt";
97 localFiles = "files_sesd.txt";
99 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/train/AddESDHandler.C");
100 AliESDInputHandler* esdH = AddESDHandler();
104 cout << "Data type not recognized! You have to specify ESD, AOD, or sESD!\n";
108 cout << "Using " << localFiles.Data() << " as input file list.\n";
110 // Create MC handler, if MC is demanded
111 if (isMC && (usedData != "AOD"))
113 AliMCEventHandler* mcH = new AliMCEventHandler();
114 mcH->SetPreReadMode(AliMCEventHandler::kLmPreRead);
115 mcH->SetReadTR(kTRUE);
116 mgr->SetMCtruthEventHandler(mcH);
119 // ################# Now: Add some basic tasks
121 // Physics selection task
122 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalPhysicsSelection.C");
123 AliPhysicsSelectionTask *physSelTask = AddTaskEmcalPhysicsSelection(kTRUE, kTRUE, pSel, 5, 5, 10, kTRUE, -1, -1, -1, -1);
127 cout << "no physSelTask";
132 if (usedData == "ESD") {
133 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
134 AliCentralitySelectionTask *centralityTask = AddTaskCentrality(kTRUE);
137 // Compatibility task, only needed for skimmed ESD
138 if (usedData == "sESD") {
139 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalCompat.C");
140 AliEmcalCompatTask *comptask = AddTaskEmcalCompat();
144 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalSetup.C");
145 AliEmcalSetupTask *setupTask = AddTaskEmcalSetup();
146 setupTask->SetGeoPath("$ALICE_ROOT/OADB/EMCAL");
150 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalPreparation.C");
151 //adjust pass when running locally. On grid give empty string, will be picked up automatically from path to ESD/AOD file
152 AliAnalysisTaskSE *clusm = AddTaskEmcalPreparation(runPeriod,"pass1");
155 // Names of the different objects passed around; these are the default names; added here mostly for documentation purposes
156 // rhoName is only set if the background subtraction is switched on (doBkg)
157 TString tracksName = "AODFilterTracks";
158 TString clustersName = "EmcCaloClusters";
160 // ################# Now: Call jet preparation macro (picotracks, hadronic corrected caloclusters, ...)
161 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskMatchingChain.C");
162 AddTaskMatchingChain(runPeriod,pSel,
163 clustersName,1.,kTRUE,
166 // ################# Now: Add analysis task
167 // Here you can put in your AddTaskMacro for your task
168 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/AddTaskEmcalSample.C");
169 AliAnalysisTaskEmcalSample* anaTask = AddTaskEmcalSample(tracksName, clustersName, 4);
171 // Set the physics selection for all given tasks
172 TObjArray *toptasks = mgr->GetTasks();
173 for (Int_t i=0; i<toptasks->GetEntries(); ++i)
175 AliAnalysisTaskSE *task = dynamic_cast<AliAnalysisTaskSE*>(toptasks->At(i));
178 if (task->InheritsFrom("AliPhysicsSelectionTask"))
180 ::Info("setPSel", "Set physics selection for %s (%s)", task->GetName(), task->ClassName());
181 task->SelectCollisionCandidates(pSel);
184 mgr->SetUseProgressBar(1, 25);
186 if (!mgr->InitAnalysis())
191 { // GRID CALCULATION
193 AliAnalysisGrid *plugin = CreateAlienHandler(uniqueName, gridDir, gridMode, runNumbers, pattern, additionalCXXs, additionalHs, maxFilesPerWorker, workerTTL, isMC);
194 mgr->SetGridHandler(plugin);
197 cout << "Starting GRID Analysis...";
198 mgr->SetDebugLevel(0);
199 mgr->StartAnalysis("grid",10);
202 { // LOCAL CALCULATION
205 if (usedData == "AOD")
207 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/CreateAODChain.C");
208 chain = CreateAODChain(localFiles.Data(), numLocalFiles);
211 { // ESD or skimmed ESD
212 gROOT->LoadMacro("$ALICE_ROOT/PWG/EMCAL/macros/CreateESDChain.C");
213 chain = CreateESDChain(localFiles.Data(), numLocalFiles);
217 cout << "Starting LOCAL Analysis...";
218 mgr->SetDebugLevel(2);
219 mgr->StartAnalysis("local", chain);
223 //______________________________________________________________________________
226 // Load common libraries (better too many than too few)
227 gSystem->Load("libTree");
228 gSystem->Load("libVMC");
229 gSystem->Load("libGeom");
230 gSystem->Load("libGui");
231 gSystem->Load("libXMLParser");
232 gSystem->Load("libMinuit");
233 gSystem->Load("libMinuit2");
234 gSystem->Load("libProof");
235 gSystem->Load("libPhysics");
236 gSystem->Load("libSTEERBase");
237 gSystem->Load("libESD");
238 gSystem->Load("libAOD");
239 gSystem->Load("libOADB");
240 gSystem->Load("libANALYSIS");
241 gSystem->Load("libCDB");
242 gSystem->Load("libRAWDatabase");
243 gSystem->Load("libSTEER");
244 gSystem->Load("libEVGEN");
245 gSystem->Load("libANALYSISalice");
246 gSystem->Load("libCORRFW");
247 gSystem->Load("libTOFbase");
248 //gSystem->Load("libTOFrec");
249 gSystem->Load("libRAWDatabase");
250 gSystem->Load("libRAWDatarec");
251 gSystem->Load("libTPCbase");
252 gSystem->Load("libTPCrec");
253 gSystem->Load("libITSbase");
254 gSystem->Load("libITSrec");
255 gSystem->Load("libTRDbase");
256 gSystem->Load("libTender");
257 gSystem->Load("libSTAT");
258 gSystem->Load("libTRDrec");
259 gSystem->Load("libHMPIDbase");
260 gSystem->Load("libPWGPP");
261 gSystem->Load("libPWGHFbase");
262 gSystem->Load("libPWGDQdielectron");
263 gSystem->Load("libPWGHFhfe");
264 gSystem->Load("libEMCALUtils");
265 gSystem->Load("libPHOSUtils");
266 gSystem->Load("libPWGCaloTrackCorrBase");
267 gSystem->Load("libEMCALraw");
268 gSystem->Load("libEMCALbase");
269 gSystem->Load("libEMCALrec");
270 gSystem->Load("libTRDbase");
271 gSystem->Load("libVZERObase");
272 gSystem->Load("libVZEROrec");
273 gSystem->Load("libTender");
274 gSystem->Load("libTenderSupplies");
275 gSystem->Load("libPWGTools");
276 gSystem->Load("libPWGEMCAL");
277 gSystem->Load("libESDfilter");
278 gSystem->Load("libPWGGAEMCALTasks");
279 gSystem->Load("libPWGCFCorrelationsBase");
280 gSystem->Load("libPWGCFCorrelationsDPhi");
283 gSystem->AddIncludePath("-Wno-deprecated");
284 gSystem->AddIncludePath("-I$ALICE_ROOT -I$ALICE_ROOT/include -I$ALICE_ROOT/EMCAL");
285 gSystem->AddIncludePath("-I$ALICE_ROOT/PWGDQ/dielectron -I$ALICE_ROOT/PWGHF/hfe");
288 AliAnalysisGrid* CreateAlienHandler(const char* uniqueName, const char* gridDir, const char* gridMode, const char* runNumbers,
289 const char* pattern, TString additionalCode, TString additionalHeaders, Int_t maxFilesPerWorker,
290 Int_t workerTTL, Bool_t isMC)
293 TString tmpName(uniqueName);
295 // Only add current date and time when not in terminate mode! In this case the exact name has to be supplied by the user
296 if(strcmp(gridMode, "terminate"))
299 tmpName += currentTime.GetDate();
301 tmpName += currentTime.GetTime();
304 TString tmpAdditionalLibs("");
305 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 %s %s",additionalCode.Data(),additionalHeaders.Data());
308 TString macroName("");
309 TString execName("");
311 macroName = Form("%s.C", tmpName.Data());
312 execName = Form("%s.sh", tmpName.Data());
313 jdlName = Form("%s.jdl", tmpName.Data());
315 AliAnalysisAlien *plugin = new AliAnalysisAlien();
316 plugin->SetOverwriteMode();
317 plugin->SetRunMode(gridMode);
319 // Here you can set the (Ali)ROOT version you want to use
320 plugin->SetAPIVersion("V1.1x");
321 plugin->SetROOTVersion("v5-34-08-6");
322 plugin->SetAliROOTVersion("vAN-20140525");
324 plugin->SetGridDataDir(gridDir); // e.g. "/alice/sim/LHC10a6"
325 plugin->SetDataPattern(pattern); //dir structure in run directory
327 plugin->SetRunPrefix("000");
329 plugin->AddRunList(runNumbers);
331 plugin->SetGridWorkingDir(Form("work/%s",tmpName.Data()));
332 plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
334 plugin->SetAnalysisSource(additionalCode.Data());
335 plugin->SetAdditionalLibs(tmpAdditionalLibs.Data());
337 plugin->SetDefaultOutputs(kTRUE);
338 //plugin->SetMergeExcludes("");
339 plugin->SetAnalysisMacro(macroName.Data());
340 plugin->SetSplitMaxInputFileNumber(maxFilesPerWorker);
341 plugin->SetExecutable(execName.Data());
342 plugin->SetTTL(workerTTL);
343 plugin->SetInputFormat("xml-single");
344 plugin->SetJDLName(jdlName.Data());
346 plugin->SetSplitMode("se");
347 plugin->SetNtestFiles(1);