]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis/scripts/runFMDjob.C
Transition PWG2/FORWARD -> PWGLF
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis / scripts / runFMDjob.C
CommitLineData
243bd029 1//____________________________________________________________________
2a9e98ee 2/**
3 * Run an FMD corrections job.
4 *
5 * @param runMode Running mode (full, test, terminate, submit, offline)
6 * @param anaType What to do (background, collector, sharing)
7 * @param dataDir Input data directory
8 * @param anaSource Analysis source (if any)
2a9e98ee 9 * @param anaName Analysis name
10 * @param colSys Collision system (p-p, Pb-Pb, A-A)
11 * @param cmsNNGeV Center of mass energy per nucleon in GeV
12 * @param bkG Magnetic field in kilo gaus
13 * @param aliceTag AliROOT tag to use
14 * @param rootTag ROOT tag to use
15 * @param apiTag API tag to use
16 */
17void
18runFMDjob(const TString& runMode = "",
19 const TString& anaType = "background",
20 const TString& dataDir = "",
21 const TString& anaSource = "",
2a9e98ee 22 const TString& anaName = "",
23 const TString& colSys = "p-p",
24 Float_t cmsNNGeV = 900,
25 Float_t bkG = 5,
26 const TString& aliceTag = "v4-21-04-AN",
27 const TString& rootTag = "v5-27-06b",
28 const TString& apiTag = "V1.1x")
29{
243bd029 30 // --- Load libraries needed -------------------------------------
31 gSystem->Load("libANALYSIS");
32 gSystem->Load("libANALYSISalice");
33 gSystem->Load("libPWG2forward");
34 gSystem->AddIncludePath("-I$ALICE_ROOT/PWG2/FORWARD/analysis");
35
2a9e98ee 36 // --- Some initial checks and setup -------------------------------
37 TString outFileName = anaName;
38 outFileName.ToLower();
39 outFileName += ".root";
2a9e98ee 40
41 // --- Manager setup -----------------------------------------------
42 // Create the analysis manager
43 AliAnalysisManager *mgr = new AliAnalysisManager(anaName.Data());
44
2a9e98ee 45
46 // --- ESD setup ---------------------------------------------------
47 // Connect the EDS's to the manager and switch off unused branches
48 AliESDInputHandler* esdH = new AliESDInputHandler();
49 esdH->SetInactiveBranches("AliESDACORDE "
50 "AliRawDataErrorLogs "
51 "CaloClusters "
52 "Cascades "
53 "EMCALCells "
54 "EMCALTrigger "
55 "ESDfriend "
56 "Kinks "
57 "Cascades "
58 "ALIESDACORDE "
59 "MuonTracks "
60 "TrdTracks");
61 mgr->SetInputEventHandler(esdH);
62
63 // --- Task setup --------------------------------------------------
64 // Configure the analysis manager to the specific task
2a9e98ee 65 TString type = anaType.ToLower();
243bd029 66 TString addLibs;
2a9e98ee 67 if (type.Contains("background"))
243bd029 68 addLibs = AddBackgroundTask(outFileName);
2a9e98ee 69 else if (type.Contains("collector"))
243bd029 70 addLibs = AddCollectorTask(outFileName, colSys, cmsNNGeV, bkG);
2a9e98ee 71 else if (type.Contains("sharing"))
243bd029 72 addLibs = AddSharingTask(outFileName, colsys, cmsNNGeV, bkG);
2a9e98ee 73 else {
74 Error("runFMDjob", "Unknown type '%s', please fix this macro",
75 anaType);
76 return;
77 }
243bd029 78
79 // --- AliEN handler setup -----------------------------------------
80 // Create and configure the alien handler plugin, and connect to manager
81 if (!CreateAlienHandler(runMode,
82 dataDir,
83 anaSource,
84 addLibs,
85 anaName,
86 outFileName,
87 aliceTag,
88 rootTag,
89 apiTag)) {
90 Error("runFMDjob", "Failed to set up alien handler");
91 return;
92 }
93 mgr->SetGridHandler(alienHandler);
2a9e98ee 94
95 // --- final job setup and execution -------------------------------
96 // Enable debug printouts
97 mgr->SetDebugLevel(2);
98
99 if (!mgr->InitAnalysis()) {
100 Error("runFMDjob", "Failed to initialise the train");
101 return;
102 }
103 mgr->PrintStatus();
104 mgr->StartAnalysis("grid");
105
106 // --- We are done -------------------------------------------------
107 Info("runFMDjob", "Job is done");
108}
109
243bd029 110
2a9e98ee 111//____________________________________________________________________
243bd029 112/**
113 * Create a background correction task
114 *
115 * @param outFileName
116 *
117 * @return A list of additional files that should be uploaded
118 */
2a9e98ee 119void
120AddBackgroundTask(const TString& outFileName)
121{
243bd029 122 AliAnalysisManager* mgr = AliAnalysisManager::Instance();
123
2a9e98ee 124 // --- Make and configure task -------------------------------------
125 AliFMDAnalysisTaskGenerateCorrection *task =
126 new AliFMDAnalysisTaskGenerateCorrection("background");
127 task->SetNbinsEta(200);
128 mgr->AddTask(task);
129
130 // --- Add the MC handler ------------------------------------------
131 AliMCEventHandler* mcHandler = new AliMCEventHandler();
132 mgr->SetMCtruthEventHandler(mcHandler);
133
134 // --- Create and connect container for input ----------------------
135 AliAnalysisDataContainer *cin_esd = mgr->GetCommonInputContainer();
136 mgr->ConnectInput(task, 0, cin_esd);
137
138 // --- Create and connect containers for output --------------------
139 const char* outList[] = { "Hits", "Primaries", "vertex", "Correction", 0 };
140 const char** ptr = outList;
141 Int_t i = 1;
142 while (*ptr) {
143 AliAnalysisDataContainer* outCont =
144 mgr->CreateContainer(*ptr, TList::Class(),
145 AliAnalysisManager::kOutputContainer,
146 outFileName.Data());
147 mgr->ConnectOutput(task, i, outCont);
148 i++;
149 ptr++;
150 }
243bd029 151
152 return "";
2a9e98ee 153}
154
155
156//_______________________________________________________________
157/**
158 * Create and add collector task.
159 *
160 * @param outFileName Output file name
161 * @param col Collision system (one of "p-p", "Pb-Pb", or "A-A")
162 * @param cmsNNGeV Center of mass energy per nucleon in GeV
163 * @param bkG Magnetic field in kilo gauss
243bd029 164 *
165 * @return A list of additional files that should be uploaded
2a9e98ee 166 */
167void AddCollectorTask(const TString& outFileName,
168 const TString& col,
169 Float_t cmsNNGeV,
170 Float_t bkG)
171{
243bd029 172 AliAnalysisManager* mgr = AliAnalysisManager::Instance();
173
2a9e98ee 174 // --- Initialize the analysis parameters --------------------------
175 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
176 pars->SetCollisionSystem(col);
177 pars->SetEnergy(cmsNNGeV);
178 pars->SetMagField(bkG);
179 pars->SetBackgroundPath("./");
180 pars->Init(kTRUE,AliFMDAnaParameters::kBackgroundCorrection);
243bd029 181 TString bgFile = pars->GetPath(AliFMDAnaParameters::GetBackgroundID());
182
2a9e98ee 183 // --- Create and add our task -------------------------------------
184 AliFMDAnalysisTaskCollector *task =
185 new AliFMDAnalysisTaskCollector("collector");
186 mgr->AddTask(task);
187
188 // --- Add the MC handler ------------------------------------------
189 AliMCEventHandler* mcHandler = new AliMCEventHandler();
190 mgr->SetMCtruthEventHandler(mcHandler);
191
192 // --- Create containers for input/output --------------------------
193 AliAnalysisDataContainer *cin_esd = mgr->GetCommonInputContainer();
194 AliAnalysisDataContainer *cout_fmd1 =
195 mgr->CreateContainer("energyDist",
196 TList::Class(),
197 AliAnalysisManager::kOutputContainer,
198 outFileName.Data());
199
200 // --- Connect input/output ----------------------------------------
201 mgr->ConnectInput(task, 0, cin_esd);
202 mgr->ConnectOutput(task, 1, cout_fmd1);
243bd029 203
204 return bgFile;
2a9e98ee 205}
206
207//_______________________________________________________________
208/**
209 * Create and add sharing task.
210 *
211 * @param outFileName Output file name
212 * @param col Collision system (one of "p-p", "Pb-Pb", or "A-A")
213 * @param cmsNNGeV Center of mass energy per nucleon in GeV
214 * @param bkG Magnetic field in kilo gauss
243bd029 215 *
216 * @return A list of additional files that should be uploaded
2a9e98ee 217 */
243bd029 218TString
219AddSharingTask(const TString& outFileName,
220 const TString& col,
221 Float_t cmsNNGeV,
222 Float_t bkG)
2a9e98ee 223{
243bd029 224 AliAnalysisManager* mgr = AliAnalysisManager::Instance();
225
2a9e98ee 226 // --- Initialize the analysis parameters --------------------------
227 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
228 pars->SetCollisionSystem(col);
229 pars->SetEnergy(cmsNNGeV);
230 pars->SetMagField(bkG);
231 pars->SetBackgroundPath("./");
232 pars->SetEnergyPath("./");
233 pars->SetEventSelectionPath("./");
234 pars->Init(kTRUE,
235 AliFMDAnaParameters::kBackgroundCorrection|
236 AliFMDAnaParameters::kEnergyDistributions|
237 AliFMDAnaParameters::kEventSelectionEfficiency);
243bd029 238 TString files;
239 files.Append(pars->GetPath(AliFMDAnaParameters::GetBackgroundID()));
240 files.Append(" ");
241 files.Append(pars->GetPath(AliFMDAnaParameters::GetEdistID()));
242 files.Append(" ");
243 files.Append(pars->GetPath(AliFMDAnaParameters::GetEventSelectionEffID()));
2a9e98ee 244
245 // --- Create and add our task -------------------------------------
246 AliFMDAnalysisTaskSE *task = new AliFMDAnalysisTaskSE("sharing");
247 mgr->AddTask(task);
248
249 // --- Add the MC handler ------------------------------------------
250 AliMCEventHandler* mcHandler = new AliMCEventHandler();
251 mgr->SetMCtruthEventHandler(mcHandler);
252
253
254
255 // --- Create and connect containers for output --------------------
256 AliAnalysisDataContainer *cout_fmd =
257 mgr->CreateContainer("BackgroundCorrected", TList::Class(),
258 AliAnalysisManager::kOutputContainer,outputfile);
259
260 mgr->ConnectInput(taskfmd, 0, mgr->GetCommonInputContainer());
261 mgr->ConnectOutput(taskfmd, 1, cout_fmd);
243bd029 262
263 return files;
2a9e98ee 264}
265
266//____________________________________________________________________
267/**
268 * Create an AliAnalysisGrid parameter object
269 *
270 * @param runMode Running mode (full, test, terminate, submit, offline)
271 * @param dataDir Input data directory
272 * @param anaSource Possible source to compile on worker node
273 * (must also be compiled and addet to train on
274 * submitter machine)
275 * @param addLibs Extra libraries to add
276 * @param anaName Analysis name (i.e., script created)
277 * @param outFileName Output file name
278 *
279 * @return Valid object or null
280 */
243bd029 281Bool_t
2a9e98ee 282CreateAlienHandler(const TString& runMode,
283 const TString& dataDir,
284 const TString& anaSource,
285 const TString& addLibs,
286 const TString& anaName,
287 const TString& outFileName,
288 const TString& aliceTag,
289 const TString& rootTag,
290 const TString& apiTag)
291{
292 AliAnalysisAlien *plugin = new AliAnalysisAlien();
293
294 // Overwrite all generated files, datasets and output
295 // results from a previous session
296 plugin->SetOverwriteMode();
297
298 // Set the running mode
299 plugin->SetRunMode(runMode.Data());
300
301 // Add path to our headers
302 plugin->AddIncludePath("-I$ALICE_ROOT/PWG2/FORWARD/analysis");
303
304 // Set versions of used packages
305 plugin->SetAPIVersion(apiTag);
306 plugin->SetROOTVersion(rootTag);
307 plugin->SetAliROOTVersion(aliceTag);
308
309 // Define production directory LFN
310 plugin->SetGridDataDir(dataDir.Data());
311
312 // Set data search pattern
313 plugin->SetDataPattern("AliESDs.root");
314
315 // Use ESD tags (same applies for AOD's)
316 //plugin->SetDataPattern("*tag.root");
317
318 // ...then add run numbers to be considered
319 // If not set all runs proccessed
320 //plugin->AddRunNumber(126437);
321
322 // Set events to run over for each file !!!
323 //plugin->SetRunRange(0, 10);
324
325 // Define alien work directory where all files will be copied.
326 // Relative to alien $HOME.
327 plugin->SetGridWorkingDir("work");
328
329 // Declare alien output directory. Relative to working directory.
330 TString outputDir = anaName;
331 outputDir += "_out";
332 plugin->SetGridOutputDir(outputDir.Data());
333
334 // Declare the analysis source files names separated by blancs.
335 // To be compiled runtime using ACLiC on the worker nodes.
336 if (!anaSource.IsNull())
337 plugin->SetAnalysisSource(anaSource.Data());
338
339 // Declare all libraries (other than the default ones for the framework.
340 // These will be loaded by the generated analysis macro.
341 // Add all extra files (task .cxx/.h) here.
342 if (!addLibs.IsNull())
343 plugin->SetAdditionalLibs(addLibs.Data());
344
345 // No need for output file names. Procedure is automatic.
346 // It's works better this way
347 plugin->SetDefaultOutputs(kFALSE);
348 plugin->SetOutputFiles(outFileName.Data());
349
350 // Set a name for the generated analysis macro (default MyAnalysis.C).
351 // Make this unique !!!
352 TString macroName = anaName;
353 macroName += "Task.C";
354 plugin->SetAnalysisMacro(macroName.Data());
355
356 // Optionally set maximum number of input files/subjob (default 100,
357 // put 0 to ignore)
358 plugin->SetSplitMaxInputFileNumber(100);
359
360 // Optionally set number of failed jobs that will trigger killing
361 // waiting sub-jobs.
362 plugin->SetMaxInitFailed(5);
363
364 // Optionally resubmit threshold.
365 plugin->SetMasterResubmitThreshold(90);
366
367 // Optionally set time to live (default 30000 sec)
368 plugin->SetTTL(20000);
369
370 // Optionally set input format (default xml-single)
371 plugin->SetInputFormat("xml-single");
372
373 // Optionally modify the name of the generated JDL (default analysis.jdl)
374 TString jdlName = anaName;
375 jdlName += ".jdl";
376 plugin->SetJDLName(jdlName.Data());
377
378 // Optionally modify job price (default 1)
379 plugin->SetPrice(1);
380
381 // Optionally modify split mode (default 'se')
382 plugin->SetSplitMode("se");
383
243bd029 384 // connect to manager
385 AliAnalysisManager* mgr = AliAnalysisManager::Instance();
386 mgr->SetGridHandler(alienHandler);
387
388 return kTRUE
2a9e98ee 389}
390//____________________________________________________________________
391//
392// EOF
393//