AliPhysics  781d0c7 (781d0c7)
 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.Remove("dead");
203  opts.Add("abs-min-cent","PERCENT", "Absolute least centrality",-1.);
204  opts.Add("cent-bins", "BINS", "Centrality bins", "");
205  opts.Add("satellite", "Restrict analysis to satellite events", false);
206  opts.Add("trig", "TRIGGER", "Trigger type", "INEL");
207  opts.Add("filter", "FILTER", "Filter type", "OUTLIER|PILEUP-BIN");
208  opts.Add("ipz-bins", "BINS", "Lower bound on Ip Z", "u10");
209  opts.Add("scheme", "FLAGS", "Normalization scheme", "TRIGGER,EVENT");
210  opts.Add("trigEff", "EFFICIENCY","Trigger efficiency", 1.);
211  opts.Add("trigEff0", "EFFICIENCY","0-bin trigger efficiency", 1.);
212  opts.Add("mc", "Also analyse MC truth", fRailway->IsMC());
213  opts.Add("truth-config","FILE", "MC-Truth configuration", "");
214  opts.Add("mean-ipz", "MU", "Mean of IPz dist.", 0);
215  opts.Add("var-ipz", "SIGMA", "Variance of IPz dist.", -1);
216 
217  // Rewrite our URL
218  TString outString = fRailway->OutputLocation();
219  if (outString.IsNull()) outString = fEscapedName;
220  TUrl outUrl(outString);
221 
222  if (uopts.Find("pattern")) // && outString.EndsWith("AliAOD.root"))
223  uopts.Set("pattern", "*/AliAOD.root");
224  // if (uopts.Find("concat")) uopts.Set("concat", true);
225  if (uopts.Find("par")) uopts.Set("par", "task");
226 
227  std::stringstream s;
228  uopts.Store(s, "", "&", false, true);
229  outUrl.SetOptions(s.str().c_str());
230 
231  const char* defConfig="$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dNdetaConfig.C";
232  opts.Set("url", outUrl.GetUrl());
233  opts.Set("type", "AOD");
234  opts.Set("forward-config",defConfig);
235  opts.Set("central-config",defConfig);
236  opts.Set("truth-config",defConfig);
237  if (!fDatimeString.IsNull()) opts.Set("date", fDatimeString);
238 
239  if (sys != 1) {
240  opts.Set("cent", "default");
241  opts.Set("trig", "V0AND");
242  opts.Set("scheme", "default");
243  opts.Set("centBins", "default");
244  SaveSetupROOT("dNdeta", cls, name, opts, &uopts);
245  if (asShellScript)
246  SaveSetupShell("dndeta", cls, name, opts, &uopts);
247  }
248  else {
249  name.ReplaceAll("dndeta", "dndeta_inel");
250  SaveSetupROOT("dNdetaINEL", cls, name, opts, &uopts);
251  if (asShellScript)
252  SaveSetupShell("dndeta_inel", cls, name, opts, &uopts);
253 
254  name.ReplaceAll("inel", "nsd");
255  opts.Set("trig", "V0AND");
256  SaveSetupROOT("dNdetaNSD", cls, name, opts, &uopts);
257  if (asShellScript)
258  SaveSetupShell("dndeta_nsd", cls, name, opts, &uopts);
259 
260  name.ReplaceAll("nsd", "inelgt0");
261  opts.Set("trig", "INELGT0");
262  SaveSetupROOT("dNdetaINELGt0", cls, name, opts, &uopts);
263  if (asShellScript)
264  SaveSetupShell("dndeta_inelgt0", cls, name, opts, &uopts);
265  }
266  }
272  {
273  std::ofstream f("Summarize.C");
274  if (!f) {
275  Error("SaveSummarize", "Failed to open Summarize.C script");
276  return;
277  }
278  f << "// Generated by " << ClassName() << "\n"
279  << "// WHAT is a bit mask of\n"
280  << "// 0x001 Event inspector\n"
281  << "// 0x002 Sharing filter\n"
282  << "// 0x004 Density calculator\n"
283  << "// 0x008 Corrector\n"
284  << "// 0x010 Histogram collector\n"
285  << "// 0x020 Analysis step cartoon\n"
286  << "// 0x040 Results\n"
287  << "// 0x080 Central\n"
288  << "// 0x100 Landscape\n"
289  << "// 0x200 Pause\n"
290  << "//\n"
291  << "void Summarize(const char* filename=\"forward.root\",\n"
292  << " UShort_t what=0x1FF)\n"
293  << "{\n"
294  << " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
295  << " gROOT->LoadMacro(Form(\"%s/DrawAODSummary.C\",fwd));\n"
296  << " DrawAODSummary(filename,what);\n"
297  << "}\n"
298  << "// EOF" << std::endl;
299  f.close();
300  }
306  {
307  std::ofstream f("DownloadAODs.C");
308  if (!f) {
309  Error("SaveDownloadAODs", "Failed to open DownloadAODs.C");
310  return;
311  }
312  f << "// Generated by " << ClassName() << "\n"
313  << "void DownloadAODs(Bool_t force=false)\n"
314  << "{\n"
315  << " if (!TGrid::Connect(\"alien://\")) {\n"
316  << " Error(\"DownloadAODs\",\"Failed to connect to AliEn\");\n"
317  << " return;\n"
318  << " }\n\n"
319  << " TString dir(\"" << fRailway->OutputPath() << "\");\n"
320  << " TString pat(\"*/AliAOD.root\");\n"
321  << " TGridResult* r = gGrid->Query(dir,pat);\n"
322  << " if (!r) {\n"
323  << " Error(\"DownloadAODs\",\"No result from query\");\n"
324  << " return;\n"
325  << " }\n\n"
326  << " Int_t n = r->GetEntries();\n"
327  << " Printf(\"=== Got a total of %d AOD files\",n);\n"
328  << " for (Int_t i = 0; i < n; i++) {\n"
329  << " TString path(r->GetKey(i, \"turl\"));\n"
330  << " TString dir(gSystem->DirName(path));\n"
331  << " TString sub(gSystem->BaseName(dir));\n"
332  << " TString subsub(gSystem->BaseName(gSystem->DirName(dir)));\n"
333  << " TString out = TString::Format(\"AliAOD_%s_%s.root\",\n"
334  << " subsub.Data(),sub.Data());\n"
335  << " if (!gSystem->AccessPathName(out.Data()) && !force) {\n"
336  << " Printf(\"=== Already have %s\",out.Data());\n"
337  << " continue;\n"
338  << " }\n"
339  << " Printf(\"=== Getting %s %s (%3d/%3d)\",\n"
340  << " subsub.Data(),sub.Data(),i,n);\n"
341  << " if (!TFile::Cp(path, out)) {\n"
342  << " Warning(\"DownloadAODs\",\"Failed to copy %s -> %s\",\n"
343  << " path.Data(), out.Data());\n"
344  << " continue;\n"
345  << " }\n"
346  << " }\n"
347  << "}\n"
348  << "// EOF\n"
349  << std::endl;
350  f.close();
351  }
353  {
354  std::ofstream out("MakeIndex.C");
355  out << "// Made by " << ClassName() << "\n"
356  << "void MakeIndex() {\n"
357  << " gROOT->LoadMacro(\"$ALICE_PHYSICS/PWGLF/FORWARD/trains/CreateIndex.C\");\n"
358  << " CreateIndex(\".\",\"aodTree\");\n"
359  << "}\n"
360  << "// EOD" << std::endl;
361  out.close();
362  }
363  void PostShellCode(std::ostream& f)
364  {
365  f << " echo \"=== Summarizing results ...\"\n"
366  << " aliroot -l -b -q ${prefix}Summarize.C\n"
367  << std::endl;
368  }
369 };
370 //
371 // EOF
372 //
virtual void CreateCentralitySelection(Bool_t mc)
Definition: TrainSetup.C:759
void SaveDownloadAODs()
Definition: MakeAODTrain.C:305
TString fDatimeString
Definition: TrainSetup.C:1664
Railway * fRailway
Definition: TrainSetup.C:1666
TString fName
Definition: TrainSetup.C:1662
void SaveSetup(Bool_t asShellScript)
Definition: MakeAODTrain.C:165
TSystem * gSystem
void SaveMakeIndex()
Definition: MakeAODTrain.C:352
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:1495
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:271
virtual void SaveSetup(Bool_t asShellScript)
Definition: TrainSetup.C:1471
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:1665
virtual TString OutputPath() const
Definition: Railway.C:361
unsigned short UShort_t
Definition: External.C:28
void PostShellCode(std::ostream &f)
Definition: MakeAODTrain.C:363
bool Bool_t
Definition: External.C:53
TString fEscapedName
Definition: TrainSetup.C:1663
virtual AliAnalysisTaskSE * CoupleSECar(const TString &macro, const TString &args, UInt_t mask=0)
Definition: TrainSetup.C:875
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:1536