]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/trains/MakeAODTrain.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / trains / MakeAODTrain.C
CommitLineData
39fd42ed 1/**
2 * @file MakeAODTrain.C
3 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
4 * @date Tue Jul 12 10:05:30 2011
5 *
6 * @brief Run first pass analysis - make AOD tree
7 *
8 * @ingroup pwglf_forward_trains_specific
9 */
10#include "TrainSetup.C"
11#include <sstream>
12
13//====================================================================
14/**
15 * Analysis train to make Forward and Central multiplicity
16 *
17 *
18 * @ingroup pwglf_forward_aod
19 * @ingroup pwglf_forward_trains_specific
20 */
21class MakeAODTrain : public TrainSetup
22{
23public:
24 /**
25 * Constructor.
26 *
27 * @param name Name of train (free form)
28 */
29 MakeAODTrain(const TString& name)
30 : TrainSetup(name)
31 {
8449e3e0 32 fOptions.Add("run", "NUMBER", "Run number for corrs", 0);
5b494540 33 fOptions.Add("sys", "SYSTEM", "1:pp, 2:PbPb, 3:pPb", 0);
34 fOptions.Add("snn", "ENERGY", "Center of mass energy in GeV", 0);
35 fOptions.Add("field", "STRENGTH","L3 field strength in kG", 0);
39fd42ed 36 fOptions.Add("forward-config", "FILE", "Forward configuration",
37 "ForwardAODConfig.C");
5b494540 38 fOptions.Add("central-config", "FILE", "Central configuration",
39fd42ed 39 "CentralAODConfig.C");
40 fOptions.Add("cent", "Use centrality");
41 fOptions.Add("tpc-ep", "Use TPC event plane");
42 fOptions.Add("satelitte", "Use satelitte interactions");
43 fOptions.Add("corr", "DIR", "Corrections dir", "");
cec82c73 44 fOptions.Add("secmap", "Use secondary maps to correct", false);
a5195188 45 fOptions.Add("mc-tracks", "Enable MC track filter", false);
46 fOptions.Add("max-strips", "NUMBER",
47 "Maximum consequtive strips (MC)", 2);
39fd42ed 48 fOptions.Set("type", "ESD");
49 }
50protected:
51 /**
52 * Create the tasks
53 *
39fd42ed 54 * @param mgr Analysis manager
55 */
56 void CreateTasks(AliAnalysisManager* mgr)
57 {
58 // --- Output file name ------------------------------------------
59 AliAnalysisManager::SetCommonFileName("forward.root");
60
61 // --- Load libraries/pars ---------------------------------------
78ac7e09 62 fRailway->LoadLibrary("PWGLFforward2");
39fd42ed 63
64 // --- Set load path ---------------------------------------------
65 gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2",
66 gROOT->GetMacroPath()));
67 gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/ANALYSIS/macros",
68 gROOT->GetMacroPath()));
69
70 // --- Check if this is MC ---------------------------------------
71 Bool_t mc = mgr->GetMCtruthEventHandler() != 0;
72
73 // --- Add TPC eventplane task
78ac7e09 74 if (fOptions.Has("tpc-ep")) CoupleCar("AddTaskEventplane.C","");
39fd42ed 75
76 // --- Task to copy header information ---------------------------
78ac7e09 77 CoupleCar("AddTaskCopyHeader.C", "");
39fd42ed 78
79 // --- Get options -----------------------------------------------
a5195188 80 ULong_t run = fOptions.AsInt("run", 0);
81 UShort_t sys = fOptions.AsInt("sys", 0);
82 UShort_t sNN = fOptions.AsInt("snn", 0);
83 UShort_t fld = fOptions.AsInt("field", 0);
84 UShort_t mSt = fOptions.AsInt("max-strips", 2);
85 Bool_t sec = fOptions.Has("secmap");
86 TString cor = "";
39fd42ed 87 if (fOptions.Has("corr")) cor = fOptions.Get("corr");
88
89 // --- Add the task ----------------------------------------------
90 TString fwdConfig = fOptions.Get("forward-config");
78ac7e09 91 AliAnalysisTask* fwd = CoupleCar("AddTaskForwardMult.C",
92 Form("%d,%ld,%d,%d,%d,\"%s\",\"%s\"",
93 mc, run, sys, sNN, fld,
94 fwdConfig.Data(), cor.Data()));
a5195188 95 if (!fwd)
78ac7e09 96 Fatal("CoupleCars", "Failed to add forward task");
a5195188 97
98 gROOT->ProcessLine(Form("((AliForwardMultiplicityBase*)%p)"
cec82c73 99 "->GetCorrections().SetUseSecondaryMap(%d)",
a5195188 100 fwd, sec));
101 if (mc) {
102 gROOT->ProcessLine(Form("((AliForwardMCMultiplicityTask*)%p)"
103 "->GetTrackDensity()"
104 ".SetMaxConsequtiveStrips(%d)",
105 fwd, mSt));
106 }
78ac7e09 107 fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(), fwdConfig), true);
39fd42ed 108
109 // --- Add the task ----------------------------------------------
110 TString cenConfig = fOptions.Get("central-config");
78ac7e09 111 AliAnalysisTask* cen = CoupleCar("AddTaskCentralMult.C",
1ae3885d 112 Form("%d,%ld,%d,%d,%d,\"%s\",\"%s\"",
78ac7e09 113 mc, run, sys, sNN, fld,
114 cenConfig.Data(), cor.Data()));
115 if (cen)
116 fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(), cenConfig), true);
39fd42ed 117
118 // --- Add MC particle task --------------------------------------
78ac7e09 119 if (mc && fOptions.Has("mc-tracks"))
120 CoupleCar("AddTaskMCParticleFilter.C","");
39fd42ed 121
8449e3e0 122 if (!cor.IsNull()) {
78ac7e09 123 if (fwd)
124 fRailway->LoadAux(Form("%s/fmd_corrections.root",cor.Data()), true);
125 if (cen)
126 fRailway->LoadAux(Form("%s/spd_corrections.root",cor.Data()), true);
8449e3e0 127 }
39fd42ed 128 }
129 //__________________________________________________________________
130 /**
131 * Create physics selection , and add to manager
132 *
133 * @param mc Whether this is for MC
134 * @param mgr Manager
135 */
136 void CreatePhysicsSelection(Bool_t mc, AliAnalysisManager* mgr)
137 {
138 TrainSetup::CreatePhysicsSelection(mc, mgr);
139
140 // --- Get input event handler -----------------------------------
141 AliInputEventHandler* ih =
142 dynamic_cast<AliInputEventHandler*>(mgr->GetInputEventHandler());
143 if (!ih)
144 Fatal("CreatePhysicsSelection", "Couldn't get input handler (%p)", ih);
145
146 // --- Get Physics selection -------------------------------------
147 AliPhysicsSelection* ps =
148 dynamic_cast<AliPhysicsSelection*>(ih->GetEventSelection());
149 if (!ps)
150 Fatal("CreatePhysicsSelection", "Couldn't get PhysicsSelection (%p)",ps);
151
39fd42ed 152 // --- Ignore trigger class when selecting events. This means ---
153 // --- that we get offline+(A,C,E) events too --------------------
154 // ps->SetSkipTriggerClassSelection(true);
155 }
156 //__________________________________________________________________
157 /**
158 * Create the centrality selection only if requested
159 *
160 * @param mc Monte-Carlo truth flag
161 * @param mgr Manager
162 */
78ac7e09 163 void CreateCentralitySelection(Bool_t mc)
39fd42ed 164 {
165 if (!fOptions.Has("cent")) return;
78ac7e09 166 TrainSetup::CreateCentralitySelection(mc);
39fd42ed 167 }
168 //__________________________________________________________________
169 const char* ClassName() const { return "MakeAODTrain"; }
170 //__________________________________________________________________
171 /**
172 * Overloaded to create new dNdeta.C and dndeta.sh in the output
173 * directory
174 *
175 * @param asShellScript
176 */
177 void SaveSetup(Bool_t asShellScript)
178 {
179 TrainSetup::SaveSetup(asShellScript);
9ba73450 180 SaveSummarize();
181 SavedNdeta(asShellScript);
39fd42ed 182
78ac7e09 183 if (!fRailway || fRailway->Mode() != Railway::kGrid) return;
9ba73450 184
185 SaveDownloadAODs();
186 }
187 void SavedNdeta(Bool_t asShellScript)
188 {
78ac7e09 189 if (!fRailway) {
39fd42ed 190 Warning("MakeAODTrain::SaveSetup",
5b494540 191 "Cannot make dNdeta.C script without helper");
39fd42ed 192 return;
193 }
194
bfab35d9 195 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
196 Bool_t mc = mgr && (mgr->GetMCtruthEventHandler() != 0);
78ac7e09 197 OptionList uopts(fRailway->Options());
bfab35d9 198 OptionList opts(fOptions);
199 TString cls("MakedNdetaTrain");
200 TString name(fName);
7095962e
CHC
201 Int_t sys = fOptions.AsInt("sys", 0);
202 if (name.Contains("aod")) name.ReplaceAll("aod", "dndeta");
203 else name.Append("_dndeta");
bfab35d9 204 opts.Remove("run");
39fd42ed 205 opts.Remove("sys");
206 opts.Remove("snn");
207 opts.Remove("field");
208 opts.Remove("bare-ps");
209 opts.Remove("tpc-ep");
210 opts.Remove("corr");
9ba73450 211 opts.Add("satellite", "Restrict analysis to satellite events", false);
bfab35d9 212 opts.Add("trig", "TRIGGER", "Trigger type", "INEL");
39fd42ed 213 opts.Add("vzMin", "CENTIMETER", "Lower bound on Ip Z", -10.);
214 opts.Add("vzMax", "CENTIMETER", "Upper bound on Ip Z", +10.);
4a4a2e6b 215 opts.Add("scheme", "FLAGS", "Normalization scheme", "TRIGGER,EVENT");
39fd42ed 216 opts.Add("trigEff", "EFFICIENCY", "Trigger efficiency", 1.);
217 opts.Add("trigEff0", "EFFICIENCY", "0-bin trigger efficiency", 1.);
78ac7e09 218 opts.Add("mc", "Also analyse MC truth", fRailway->IsMC());
9ba73450 219 opts.Add("truth-config", "FILE", "MC-Truth configuration", "");
39fd42ed 220
221 // Rewrite our URL
78ac7e09 222 TString outString = fRailway->OutputLocation();
39fd42ed 223 if (outString.IsNull()) outString = fEscapedName;
224 TUrl outUrl(outString);
225
9ba73450 226 if (uopts.Find("pattern")) // && outString.EndsWith("AliAOD.root"))
7095962e 227 uopts.Set("pattern", "*/AliAOD.root");
39fd42ed 228 if (uopts.Find("concat")) uopts.Set("concat", true);
229
230 std::stringstream s;
231 uopts.Store(s, "", "&", false, true);
232 outUrl.SetOptions(s.str().c_str());
233
9ba73450 234 const char* defConfig="$ALICE_ROOT/PWGLF/FORWARD/analysis2/dNdetaConfig.C";
39fd42ed 235 opts.Set("url", outUrl.GetUrl());
236 opts.Set("type", "AOD");
9ba73450 237 opts.Set("forward-config",defConfig);
238 opts.Set("central-config",defConfig);
239 opts.Set("truth-config",defConfig);
bfab35d9 240 if (!fDatimeString.IsNull()) opts.Set("date", fDatimeString);
241
7095962e 242 if (sys != 1) {
9ba73450 243 opts.Set("cent", "default");
244 opts.Set("trig", "INEL");
245 opts.Set("scheme", "default");
7095962e
CHC
246 SaveSetupROOT("dNdeta", cls, name, opts, &uopts);
247 if (asShellScript)
248 SaveSetupShell("dndeta", cls, name, opts, &uopts);
249 }
250 else {
251 name.ReplaceAll("dndeta", "dndeta_inel");
252 SaveSetupROOT("dNdetaINEL", cls, name, opts, &uopts);
253 if (asShellScript)
254 SaveSetupShell("dndeta_inel", cls, name, opts, &uopts);
255
256 name.ReplaceAll("inel", "nsd");
257 opts.Set("trig", "V0AND");
7095962e
CHC
258 SaveSetupROOT("dNdetaNSD", cls, name, opts, &uopts);
259 if (asShellScript)
260 SaveSetupShell("dndeta_nsd", cls, name, opts, &uopts);
261
262 name.ReplaceAll("nsd", "inelgt0");
263 opts.Set("trig", "INELGT0");
7095962e
CHC
264 SaveSetupROOT("dNdetaINELGt0", cls, name, opts, &uopts);
265 if (asShellScript)
266 SaveSetupShell("dndeta_inelgt0", cls, name, opts, &uopts);
267 }
39fd42ed 268 }
bfab35d9 269 /**
270 * Write a ROOT script to draw summary
271 *
272 */
273 void SaveSummarize()
274 {
275 std::ofstream f("Summarize.C");
276 if (!f) {
277 Error("SaveSummarize", "Failed to open Summarize.C script");
278 return;
279 }
280 f << "// Generated by " << ClassName() << "\n"
281 << "// WHAT is a bit mask of\n"
282 << "// 0x001 Event inspector\n"
283 << "// 0x002 Sharing filter\n"
284 << "// 0x004 Density calculator\n"
285 << "// 0x008 Corrector\n"
286 << "// 0x010 Histogram collector\n"
287 << "// 0x020 Analysis step cartoon\n"
288 << "// 0x040 Results\n"
d4a5ea4a 289 << "// 0x080 Central\n"
bfab35d9 290 << "// 0x100 Landscape\n"
d4a5ea4a 291 << "// 0x200 Pause\n"
bfab35d9 292 << "//\n"
293 << "void Summarize(const char* filename=\"forward.root\",\n"
9aba161a 294 << " UShort_t what=0x1FF)\n"
bfab35d9 295 << "{\n"
296 << " const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
297 << " gROOT->LoadMacro(Form(\"%s/DrawAODSummary.C\",fwd));\n"
298 << " DrawAODSummary(filename,what);\n"
299 << "}\n"
300 << "// EOF" << std::endl;
301 f.close();
302 }
303 /**
304 * Make a ROOT Script to download the generated AODs
305 *
306 */
39fd42ed 307 void SaveDownloadAODs()
308 {
309 std::ofstream f("DownloadAODs.C");
310 if (!f) {
311 Error("SaveDownloadAODs", "Failed to open DownloadAODs.C");
312 return;
313 }
314 f << "// Generated by " << ClassName() << "\n"
6ef58b54 315 << "void DownloadAODs(Bool_t force=false)\n"
39fd42ed 316 << "{\n"
317 << " if (!TGrid::Connect(\"alien://\")) {\n"
318 << " Error(\"DownloadAODs\",\"Failed to connect to AliEn\");\n"
319 << " return;\n"
320 << " }\n\n"
78ac7e09 321 << " TString dir(\"" << fRailway->OutputPath() << "\");\n"
39fd42ed 322 << " TString pat(\"*/AliAOD.root\");\n"
323 << " TGridResult* r = gGrid->Query(dir,pat);\n"
324 << " if (!r) {\n"
325 << " Error(\"DownloadAODs\",\"No result from query\");\n"
326 << " return;\n"
327 << " }\n\n"
328 << " Int_t n = r->GetEntries();\n"
91b3e533 329 << " Printf(\"=== Got a total of %d AOD files\",n);\n"
39fd42ed 330 << " for (Int_t i = 0; i < n; i++) {\n"
331 << " TString path(r->GetKey(i, \"turl\"));\n"
91b3e533 332 << " TString dir(gSystem->DirName(path));\n"
333 << " TString sub(gSystem->BaseName(dir));\n"
334 << " TString subsub(gSystem->BaseName(gSystem->DirName(dir)));\n"
335 << " TString out = TString::Format(\"AliAOD_%s_%s.root\",\n"
336 << " subsub.Data(),sub.Data());\n"
6ef58b54 337 << " if (!gSystem->AccessPathName(out.Data()) && !force) {\n"
338 << " Printf(\"=== Already have %s\",out.Data());\n"
339 << " continue;\n"
340 << " }\n"
91b3e533 341 << " Printf(\"=== Getting %s %s (%3d/%3d)\",\n"
342 << " subsub.Data(),sub.Data(),i,n);\n"
39fd42ed 343 << " if (!TFile::Cp(path, out)) {\n"
344 << " Warning(\"DownloadAODs\",\"Failed to copy %s -> %s\",\n"
345 << " path.Data(), out.Data());\n"
346 << " continue;\n"
347 << " }\n"
348 << " }\n"
349 << "}\n"
350 << "// EOF\n"
351 << std::endl;
352 f.close();
353 }
91b3e533 354 void PostShellCode(std::ostream& f)
355 {
356 f << " echo \"=== Summarizing results ...\"\n"
357 << " aliroot -l -b -q ${prefix}Summarize.C\n"
358 << std::endl;
359 }
39fd42ed 360};
361//
362// EOF
363//