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