AliPhysics  32b88a8 (32b88a8)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeAODTrain.C
Go to the documentation of this file.
1 
10 #include "TrainSetup.C"
11 #include <sstream>
12 
13 //====================================================================
21 class MakeAODTrain : public TrainSetup
22 {
23 public:
29  MakeAODTrain(const TString& name)
30  : TrainSetup(name)
31  {
32  fOptions.Add("run", "NUMBER", "Run number for corrs", 0);
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);
36  fOptions.Add("corr", "DIR", "Corrections dir", "");
37  fOptions.Add("dead", "FILE", "Additional dead-map script", "");
38  fOptions.Add("copy", "LIST", "',' separated list to copy","cent");
39  fOptions.Add("max-strips", "NUMBER",
40  "Maximum consequtive strips (MC)", 2);
41  fOptions.Add("forward-config", "FILE", "Forward configuration",
42  "ForwardAODConfig.C");
43  fOptions.Add("central-config", "FILE", "Central configuration",
44  "CentralAODConfig.C");
45  fOptions.Add("no-central","Do not at SPD cluster task",false);
46  fOptions.Add("cent", "Use centrality");
47  fOptions.Add("tpc-ep", "Use TPC event plane");
48  fOptions.Add("satelitte", "Use satelitte interactions");
49  fOptions.Add("secmap", "Use secondary maps to correct", false);
50  fOptions.Add("mc-tracks", "Enable MC track filter", false);
51  fOptions.Set("type", "ESD");
52  }
53 protected:
60  {
61  // --- Output file name ------------------------------------------
62  AliAnalysisManager::SetCommonFileName("forward.root");
63 
64  // --- Load libraries/pars ---------------------------------------
65  fRailway->LoadLibrary("PWGLFforward2");
66 
67  // --- Set load path ---------------------------------------------
68  gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2",
69  gROOT->GetMacroPath()));
70  gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/ANALYSIS/macros",
71  gROOT->GetMacroPath()));
72 
73  // --- Check if this is MC ---------------------------------------
74  Bool_t mc = mgr->GetMCtruthEventHandler() != 0;
75 
76  UInt_t mask = AliVEvent::kAny;
77  // --- Add TPC eventplane task
78  if (fOptions.Has("tpc-ep")) CoupleSECar("AddTaskEventplane.C","", mask);
79 
80  // --- Task to copy header information ---------------------------
81  TString cpy = fOptions.Get("copy");
82  Info("", "What to copy: %s", cpy.Data());
83  CoupleSECar("AddTaskCopyHeader.C", Form("\"%s\"", cpy.Data()), mask);
84 
85  // --- Get options -----------------------------------------------
86  ULong_t run = fOptions.AsInt("run", 0);
87  UShort_t sys = fOptions.AsInt("sys", 0);
88  UShort_t sNN = fOptions.AsInt("snn", 0);
89  UShort_t fld = fOptions.AsInt("field", 0);
90  UShort_t mSt = fOptions.AsInt("max-strips", 2);
91  Bool_t sec = fOptions.Has("secmap");
92  TString corr = "";
93  TString dead = "";
94  if (fOptions.Has("corr")) corr = fOptions.Get("corr");
95  if (fOptions.Has("dead")) dead = fOptions.Get("dead");
96 
97  // --- Add the task ----------------------------------------------
98  TString fwdConfig = fOptions.Get("forward-config");
100  CoupleSECar("AddTaskForwardMult.C",
101  Form("%d,%ld,%d,%d,%d,\"%s\",\"%s\",\"%s\"",
102  mc, run, sys, sNN, fld,
103  fwdConfig.Data(), corr.Data(),
104  dead.Data()), mask);
105  if (!fwd)
106  Fatal("CoupleCars", "Failed to add forward task");
107 
108  gROOT->ProcessLine(Form("((AliForwardMultiplicityBase*)%p)"
109  "->GetCorrections().SetUseSecondaryMap(%d)",
110  fwd, sec));
111  if (mc) {
112  gROOT->ProcessLine(Form("((AliForwardMCMultiplicityTask*)%p)"
113  "->GetTrackDensity()"
114  ".SetMaxConsequtiveStrips(%d)",
115  fwd, mSt));
116  }
117  fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(), fwdConfig), true);
118  if (!corr.IsNull())
119  fRailway->LoadAux(Form("%s/fmd_corrections.root",corr.Data()), true);
120  if (!dead.IsNull())
121  fRailway->LoadAux(Form("%s",dead.Data()), true);
122 
123  // --- Add the task ----------------------------------------------
124  Bool_t noCentral = fOptions.Has("no-central");
125  AliAnalysisTask* cen = 0;
126  TString cenConfig = "";
127  if (!noCentral) {
128  cenConfig = fOptions.Get("central-config");
129  cen = CoupleSECar("AddTaskCentralMult.C",
130  Form("%d,%ld,%d,%d,%d,\"%s\",\"%s\"",
131  mc, run, sys, sNN, fld,
132  cenConfig.Data(), corr.Data()), mask);
133  fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(),cenConfig),true);
134  if (!corr.IsNull())
135  fRailway->LoadAux(Form("%s/spd_corrections.root",corr.Data()), true);
136  gROOT->ProcessLine(Form("((AliCentralMultiplicityTask*)%p)"
137  "->SetUseSecondary(%d)",
138  cen, sec));
139  }
140 
141  // --- Add MC particle task --------------------------------------
142  if (mc && fOptions.Has("mc-tracks"))
143  CoupleSECar("AddTaskMCParticleFilter.C","", mask);
144  }
145  //__________________________________________________________________
152  {
153  if (!fOptions.Has("cent")) return;
155  }
156  //__________________________________________________________________
157  const char* ClassName() const { return "MakeAODTrain"; }
158  //__________________________________________________________________
165  void SaveSetup(Bool_t asShellScript)
166  {
167  TrainSetup::SaveSetup(asShellScript);
168  SaveSummarize();
169  SavedNdeta(asShellScript);
170 
171  if (!fRailway || fRailway->Mode() != Railway::kGrid) return;
172 
174  SaveMakeIndex();
175  }
176  void SavedNdeta(Bool_t asShellScript)
177  {
178  if (!fRailway) {
179  Warning("MakeAODTrain::SaveSetup",
180  "Cannot make dNdeta.C script without helper");
181  return;
182  }
183 
184  AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
185  Bool_t mc = mgr && (mgr->GetMCtruthEventHandler() != 0);
186  OptionList uopts(fRailway->Options());
187  OptionList opts(fOptions);
188  TString cls("MakedNdetaTrain");
189  TString name(fName);
190  Int_t sys = fOptions.AsInt("sys", 0);
191  if (name.Contains("aod")) name.ReplaceAll("aod", "dndeta");
192  else name.Append("_dndeta");
193  opts.Remove("run");
194  opts.Remove("sys");
195  opts.Remove("snn");
196  opts.Remove("field");
197  opts.Remove("tpc-ep");
198  opts.Remove("corr");
199  opts.Remove("max-strips");
200  opts.Remove("mc-tracks");
201  opts.Remove("secmap");
202  opts.Add("centBins", "BINS", "Centrality bins", "");
203  opts.Add("satellite", "Restrict analysis to satellite events", false);
204  opts.Add("trig", "TRIGGER", "Trigger type", "INEL");
205  opts.Add("filter", "FILTER", "Filter type", "OUTLIER|PILEUP-BIN");
206  opts.Add("vzMin", "CENTIMETER", "Lower bound on Ip Z", -10.);
207  opts.Add("vzMax", "CENTIMETER", "Upper bound on Ip Z", +10.);
208  opts.Add("scheme", "FLAGS", "Normalization scheme", "TRIGGER,EVENT");
209  opts.Add("trigEff", "EFFICIENCY", "Trigger efficiency", 1.);
210  opts.Add("trigEff0", "EFFICIENCY", "0-bin trigger efficiency", 1.);
211  opts.Add("mc", "Also analyse MC truth", fRailway->IsMC());
212  opts.Add("truth-config", "FILE", "MC-Truth configuration", "");
213  opts.Add("mean-ipz", "MU", "Mean of IPz dist.", 0);
214  opts.Add("var-ipz", "SIGMA", "Variance of IPz dist.", -1);
215 
216  // Rewrite our URL
217  TString outString = fRailway->OutputLocation();
218  if (outString.IsNull()) outString = fEscapedName;
219  TUrl outUrl(outString);
220 
221  if (uopts.Find("pattern")) // && outString.EndsWith("AliAOD.root"))
222  uopts.Set("pattern", "*/AliAOD.root");
223  // if (uopts.Find("concat")) uopts.Set("concat", true);
224  if (uopts.Find("par")) uopts.Set("par", "task");
225 
226  std::stringstream s;
227  uopts.Store(s, "", "&", false, true);
228  outUrl.SetOptions(s.str().c_str());
229 
230  const char* defConfig="$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dNdetaConfig.C";
231  opts.Set("url", outUrl.GetUrl());
232  opts.Set("type", "AOD");
233  opts.Set("forward-config",defConfig);
234  opts.Set("central-config",defConfig);
235  opts.Set("truth-config",defConfig);
236  if (!fDatimeString.IsNull()) opts.Set("date", fDatimeString);
237 
238  if (sys != 1) {
239  opts.Set("cent", "default");
240  opts.Set("trig", "INEL");
241  opts.Set("scheme", "default");
242  opts.Set("centBins", "default");
243  SaveSetupROOT("dNdeta", cls, name, opts, &uopts);
244  if (asShellScript)
245  SaveSetupShell("dndeta", cls, name, opts, &uopts);
246  }
247  else {
248  name.ReplaceAll("dndeta", "dndeta_inel");
249  SaveSetupROOT("dNdetaINEL", cls, name, opts, &uopts);
250  if (asShellScript)
251  SaveSetupShell("dndeta_inel", cls, name, opts, &uopts);
252 
253  name.ReplaceAll("inel", "nsd");
254  opts.Set("trig", "V0AND");
255  SaveSetupROOT("dNdetaNSD", cls, name, opts, &uopts);
256  if (asShellScript)
257  SaveSetupShell("dndeta_nsd", cls, name, opts, &uopts);
258 
259  name.ReplaceAll("nsd", "inelgt0");
260  opts.Set("trig", "INELGT0");
261  SaveSetupROOT("dNdetaINELGt0", cls, name, opts, &uopts);
262  if (asShellScript)
263  SaveSetupShell("dndeta_inelgt0", cls, name, opts, &uopts);
264  }
265  }
271  {
272  std::ofstream f("Summarize.C");
273  if (!f) {
274  Error("SaveSummarize", "Failed to open Summarize.C script");
275  return;
276  }
277  f << "// Generated by " << ClassName() << "\n"
278  << "// WHAT is a bit mask of\n"
279  << "// 0x001 Event inspector\n"
280  << "// 0x002 Sharing filter\n"
281  << "// 0x004 Density calculator\n"
282  << "// 0x008 Corrector\n"
283  << "// 0x010 Histogram collector\n"
284  << "// 0x020 Analysis step cartoon\n"
285  << "// 0x040 Results\n"
286  << "// 0x080 Central\n"
287  << "// 0x100 Landscape\n"
288  << "// 0x200 Pause\n"
289  << "//\n"
290  << "void Summarize(const char* filename=\"forward.root\",\n"
291  << " UShort_t what=0x1FF)\n"
292  << "{\n"
293  << " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
294  << " gROOT->LoadMacro(Form(\"%s/DrawAODSummary.C\",fwd));\n"
295  << " DrawAODSummary(filename,what);\n"
296  << "}\n"
297  << "// EOF" << std::endl;
298  f.close();
299  }
305  {
306  std::ofstream f("DownloadAODs.C");
307  if (!f) {
308  Error("SaveDownloadAODs", "Failed to open DownloadAODs.C");
309  return;
310  }
311  f << "// Generated by " << ClassName() << "\n"
312  << "void DownloadAODs(Bool_t force=false)\n"
313  << "{\n"
314  << " if (!TGrid::Connect(\"alien://\")) {\n"
315  << " Error(\"DownloadAODs\",\"Failed to connect to AliEn\");\n"
316  << " return;\n"
317  << " }\n\n"
318  << " TString dir(\"" << fRailway->OutputPath() << "\");\n"
319  << " TString pat(\"*/AliAOD.root\");\n"
320  << " TGridResult* r = gGrid->Query(dir,pat);\n"
321  << " if (!r) {\n"
322  << " Error(\"DownloadAODs\",\"No result from query\");\n"
323  << " return;\n"
324  << " }\n\n"
325  << " Int_t n = r->GetEntries();\n"
326  << " Printf(\"=== Got a total of %d AOD files\",n);\n"
327  << " for (Int_t i = 0; i < n; i++) {\n"
328  << " TString path(r->GetKey(i, \"turl\"));\n"
329  << " TString dir(gSystem->DirName(path));\n"
330  << " TString sub(gSystem->BaseName(dir));\n"
331  << " TString subsub(gSystem->BaseName(gSystem->DirName(dir)));\n"
332  << " TString out = TString::Format(\"AliAOD_%s_%s.root\",\n"
333  << " subsub.Data(),sub.Data());\n"
334  << " if (!gSystem->AccessPathName(out.Data()) && !force) {\n"
335  << " Printf(\"=== Already have %s\",out.Data());\n"
336  << " continue;\n"
337  << " }\n"
338  << " Printf(\"=== Getting %s %s (%3d/%3d)\",\n"
339  << " subsub.Data(),sub.Data(),i,n);\n"
340  << " if (!TFile::Cp(path, out)) {\n"
341  << " Warning(\"DownloadAODs\",\"Failed to copy %s -> %s\",\n"
342  << " path.Data(), out.Data());\n"
343  << " continue;\n"
344  << " }\n"
345  << " }\n"
346  << "}\n"
347  << "// EOF\n"
348  << std::endl;
349  f.close();
350  }
352  {
353  std::ofstream out("MakeIndex.C");
354  out << "// Made by " << ClassName() << "\n"
355  << "void MakeIndex() {\n"
356  << " gROOT->LoadMacro(\"$ALICE_PHYSICS/PWGLF/FORWARD/trains/CreateIndex.C\"\);\n"
357  << " CreateIndex(\".\",\"aodTree\"\);\n"
358  << "}\n"
359  << "// EOD" << std::endl;
360  out.close();
361  }
362  void PostShellCode(std::ostream& f)
363  {
364  f << " echo \"=== Summarizing results ...\"\n"
365  << " aliroot -l -b -q ${prefix}Summarize.C\n"
366  << std::endl;
367  }
368 };
369 //
370 // EOF
371 //
virtual void CreateCentralitySelection(Bool_t mc)
Definition: TrainSetup.C:758
void SaveDownloadAODs()
Definition: MakeAODTrain.C:304
TString fDatimeString
Definition: TrainSetup.C:1662
Railway * fRailway
Definition: TrainSetup.C:1664
TString fName
Definition: TrainSetup.C:1660
void SaveSetup(Bool_t asShellScript)
Definition: MakeAODTrain.C:165
TSystem * gSystem
void SaveMakeIndex()
Definition: MakeAODTrain.C:351
const char * ClassName() const
Definition: MakeAODTrain.C:157
Int_t AsInt(const TString &name, Int_t def=0) const
Definition: Option.C:645
static void SaveSetupShell(const TString &out, const TString &cls, const TString &name, const OptionList &opts, const OptionList *uopts)
Definition: TrainSetup.C:1493
Definition: External.C:92
const TString & Get(const TString &name) const
Definition: Option.C:596
virtual UShort_t Mode() const =0
Bool_t Has(const TString &name) const
Definition: Option.C:584
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
void CreateTasks(AliAnalysisManager *mgr)
Definition: MakeAODTrain.C:59
const OptionList & Options() const
Definition: Railway.C:454
MakeAODTrain(const TString &name)
Definition: MakeAODTrain.C:29
void Set(const TString &name, const TString &value)
Definition: Option.C:736
virtual Bool_t IsMC() const
Definition: Railway.C:354
unsigned long ULong_t
Definition: External.C:38
Base classs for train specifications.
Option * Add(const TString &name, const TString &arg, const TString &desc, const TString &val="")
Definition: Option.C:421
const char * fwd
virtual TString OutputLocation() const
Definition: Railway.C:369
void SaveSummarize()
Definition: MakeAODTrain.C:270
virtual void SaveSetup(Bool_t asShellScript)
Definition: TrainSetup.C:1469
virtual Bool_t LoadAux(const TString &name, Bool_t copy=false)
Definition: Railway.C:255
void SavedNdeta(Bool_t asShellScript)
Definition: MakeAODTrain.C:176
OptionList fOptions
Definition: TrainSetup.C:1663
virtual TString OutputPath() const
Definition: Railway.C:361
unsigned short UShort_t
Definition: External.C:28
void PostShellCode(std::ostream &f)
Definition: MakeAODTrain.C:362
bool Bool_t
Definition: External.C:53
TString fEscapedName
Definition: TrainSetup.C:1661
virtual AliAnalysisTaskSE * CoupleSECar(const TString &macro, const TString &args, UInt_t mask=0)
Definition: TrainSetup.C:873
virtual Bool_t LoadLibrary(const TString &name, Bool_t slave=true, Bool_t forcePar=false)=0
void CreateCentralitySelection(Bool_t mc)
Definition: MakeAODTrain.C:151
static void SaveSetupROOT(const TString &out, const TString &cls, const TString &name, const OptionList &opts, const OptionList *uopts)
Definition: TrainSetup.C:1534