AliPhysics  6cf2591 (6cf2591)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BothdNdetaTrain.C
Go to the documentation of this file.
1 
12 #include "TrainSetup.C"
13 #include <TF1.h>
14 
15 //====================================================================
24 {
25 public:
31  BothdNdetaTrain(const char* name)
32  : TrainSetup(name)
33  {
34  fOptions.Add("trig", "TYPE", "Trigger type", "INEL");
35  fOptions.Add("filter", "TYPE", "Filter type","OUTLIER|PILEUP-BIN");
36  fOptions.Add("cent", "ESTIMATOR", "Use centrality", "none");
37  fOptions.Add("cent-bins", "BINS", "Centrality bins", "default");
38  fOptions.Add("abs-min-cent", "PERCENT", "Absolute least centrality", -1.);
39  fOptions.Add("ipz-bins", "BINS", "IPz bins", "u15");
40  fOptions.Add("eta-bins", "BINS", "Eta bins", "r16:-2:+2");
41  // For forward
42  fOptions.Add("scheme", "SCHEME","Normalization scheme","EVENT,TRIGGER");
43  fOptions.Add("trigEff", "EFFICIENCY","Trigger efficiency", 1.);
44  fOptions.Add("trigEff0", "EFFICIENCY","0-bin trigger effeciency", 1.);
45  fOptions.Add("satellite", "Restrict analysis to satellite events",false);
46  fOptions.Add("mean-ipz", "MU", "Mean of IPz dist.", 0);
47  fOptions.Add("var-ipz", "SIGMA", "Variance of IPz dist.", -1);
48  fOptions.Add("forward-config","FILE", "Forward configuration",
49  "dNdetaConfig.C");
50  // For simulations
51  fOptions.Add("mc", "Also make dN/deta for MC truth", false);
52  fOptions.Add("truth-config", "FILE", "MC-Truth configuration",
53  "dNdetaConfig.C");
54  // For SPD clusters
55  fOptions.Add("central-config","FILE", "Central configuration",
56  "dNdetaConfig.C");
57  fOptions.Add("no-central", "Do not at SPD cluster task", false);
58  // For SPD tracklets
59  fOptions.Add("max-delta", "X", "Cut on weighted distance",25.);
60  fOptions.Add("tail-delta", "X", "Tail cut on distance", 5.);
61  fOptions.Add("tail-max", "X", "Tail cut on distance", -1.);
62  fOptions.Add("delta-cut", "X", "Cut on weighted distance",1.5);
63  fOptions.Add("dphi-shift", "RADIANS","Bending shift", 0.0045);
64  fOptions.Add("shifted-dphi-cut", "RADIANS", "Cut on dPhi-phiBent", -1.);
65  fOptions.Add("reweigh", "FILE", "File with weights", "");
66  fOptions.Add("reweigh-calc", "MODE", "prod,square,sum", "prod");
67  fOptions.Add("reweigh-mask", "MASK", "Tracklet mask for weighing", 0xFF);
68  fOptions.Add("reweigh-veto", "VETO", "Tracklet veto for weighing", 0x0);
69  fOptions.Add("reweigh-inv", "W -> 1/W", false);
70 
71  }
72 protected:
73  Bool_t CoupledNdetaCar(const char* which,
74  const char* cfg)
75  {
76  UInt_t mask = AliVEvent::kAny;
77  AliAnalysisTaskSE* tsk = CoupleSECar("AddTaskdNdeta.C",
78  Form("\"%s\",\"%s\"", which, cfg),
79  mask);
80  if (!tsk) {
81  Printf("Failed to add task via AddTaskdNdeta.C(%s,%s)", cfg);
82  return false;
83  }
84  FromOption(tsk, "TriggerMask", "trig", "INEL");
85  FromOption(tsk, "FilterMask", "filter", "OUTLIER|PILEUP-BIN");
86  FromOption(tsk, "NormalizationScheme", "scheme", "EVENT,TRIGGER");
87  FromOption(tsk, "CentralityMethod", "cent", "default");
88  FromOption(tsk, "CentralityAxis", "cent-bins", "default");
89  FromOption(tsk, "IPzAxis", "ipz-bins", "u10");
90  FromOption(tsk, "TriggerEff", "trigEff", 1.);
91  FromOption(tsk, "TriggerEff0", "trigEff0", 1.);
92  FromOption(tsk, "SatelliteVertices", "satellite", false);
93  FromOption(tsk, "AbsMinCent", "abs-min-cent",-1.);
94 
95  if (!TString(which).BeginsWith("forward",TString::kIgnoreCase)) return true;
96 
97  Double_t muIpz = fOptions.AsDouble("mean-ipz",0);
98  Double_t sigmaIpz = fOptions.AsDouble("var-ipz",-1);
99  if (sigmaIpz <= 0) return true;
100 
101  TF1* f=new TF1("ipZw","TMath::Gaus(x,[0],[1],1)/TMath::Gaus(x,[2],[3],1)");
102  f->SetParNames("#mu_{emp}","#sigma_{emp}","#mu_{this}","#sigma_{this}");
103  f->SetParameters(0.592,6.836,muIpz,sigmaIpz);
104  // f->SetParErrors(0.023,0.029,eMuIpz,eSigmaIpz);
105 
106  Printf("Created re-weight function");
107  f->Print();
108 
109  gROOT
110  ->ProcessLine(Form("((AliBasedNdetaTask*)%p)->SetIpzReweight((TF1*)%p);",
111  tsk, f));
112  return true;
113 
114  }
121  {
122  AliAnalysisManager::SetCommonFileName("tracklet_dndeta.root");
123  TString fwd(gSystem->Getenv("ANA_SRC"));
124  if (fwd.IsNull()) fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
125  gROOT->SetMacroPath(Form("%s:%s/dndeta/tracklets3",
126  gROOT->GetMacroPath(), fwd.Data()));
127  gSystem->AddIncludePath(Form("-I%s/dndeta/tracklets3", fwd.Data()));
128 
129  Info("CreateTasks", "Loading code");
130  fRailway->LoadSource("FixPaths.C");
131  fRailway->LoadSource("AliAODSimpleHeader.C");
132  fRailway->LoadSource("AliAODTracklet.C");
133  fRailway->LoadSource("AliTrackletWeights.C");
134  fRailway->LoadSource("AliTrackletAODUtils.C");
135  fRailway->LoadSource("AliTrackletAODdNdeta.C");
136 
137  // --- Create the task using interpreter -------------------------
138  Bool_t mc = fOptions.Has("mc");
139  if (!mc) mc = fRailway->IsMC();
140  Long_t ret =
141  gROOT->ProcessLine(Form("AliTrackletAODdNdeta::Create(%d,\"%s\")",mc,
142  fOptions.AsString("reweigh")));
143  AliAnalysisTaskSE* task = reinterpret_cast<AliAnalysisTaskSE*>(ret);
144  if (!task) return;
145 
146  // --- Figure out the trigger options ----------------------------
147  TString trg = fOptions.Get("trig"); trg.ToUpper();
148  UInt_t sel = AliVEvent::kINT7;
149  if (trg.EqualTo("MB")) sel = AliVEvent::kMB;
150  else if (trg.EqualTo("V0AND")) sel = AliVEvent::kINT7;
151  else if (trg.EqualTo("V0OR")) sel = AliVEvent::kCINT5;
152  else if (trg.EqualTo("ANY")) sel = AliVEvent::kAny;
153  task->SelectCollisionCandidates(sel);
154 
155  // --- Figure out calculation mode -------------------------------
156  TString calc = fOptions.Get("reweigh-calc"); calc.ToUpper();
157  UChar_t mcal = 0;
158  if (calc.BeginsWith("PROD")) mcal = 0;
159  else if (calc.BeginsWith("SQ")) mcal = 1;
160  else if (calc.BeginsWith("SUM")) mcal = 2;
161  else if (calc.BeginsWith("AV")) mcal = 3;
162 
163  // --- Set various options on task -------------------------------
164  const char* defCent = "0-5-10-20-30-40-50-60-70-80-90";
165  FromOption(task, "CentralityMethod","cent", "V0M");
166  FromOption(task, "CentralityAxis", "cent-bins", defCent);
167  FromOption(task, "EtaAxis", "eta-bins", "r16:2");
168  FromOption(task, "IPzAxis", "ipz-bins", "u15");
169  FromOption(task, "DeltaCut", "delta-cut", 1.5);
170  FromOption(task, "TailDelta", "tail-delta", 5.);
171  FromOption(task, "TailMaximum", "tail-max", -1);
172  FromOption(task, "MaxDelta", "max-delta", 25.);
173  FromOption(task, "DPhiShift", "dphi-shift", 0.0045);
174  FromOption(task, "ShiftedDPhiCut", "shifted-dphi-cut",-1.);
175  FromOption(task, "AbsMinCent", "abs-min-cent", -1.);
176  FromOption(task, "WeightMask", "reweigh-mask", 0xFF);
177  FromOption(task, "WeightVeto", "reweigh-veto", 0x0);
178  SetOnTask (task, "WeightCalc", mcal);
179  FromOption(task, "WeightInverse", "reweigh-inv", false);
180  // if (mc && we) {
181  // TUrl wurl(fOptions.AsString("reweight"));
182  // TFile* wfile = TFile::Open(wurl.GetFile());
183  // if (!wfile) {
184  // Warning("CreateTasks", "Failed to open weights file: %s",
185  // wurl.GetUrl());
186  // return;
187  // }
188  // TString wnam(wurl.GetAnchor());
189  // if (wnam.IsNull()) wnam = "weights";
190  // TObject* wobj = wfile->Get(wnam);
191  // if (!wobj) {
192  // Warning("CreateTasks", "Failed to get weights %s from file %s",
193  // wnam.Data(), wfile->GetName());
194  // return;
195  // }
196  // if (!wobj->IsA()->InheritsFrom("AliTrackletWeights")) {
197  // Warning("CreateTasks", "Object %s from file %s not an "
198  // "AliTrackletWeights but a %s",
199  // wnam.Data(), wfile->GetName(), wobj->ClassName());
200  // return;
201  // }
202  // SetOnTaskGeneric(task, "Weights",
203  // Form("((AliTrackletWeights*)%p)", wobj));
204  // }
205  Printf("Print the generated task");
206  task->Print("");
207  }
213  {
214  // --- Output file name ------------------------------------------
215  AliAnalysisManager::SetCommonFileName("forward_dndeta.root");
216 
217  // --- Load libraries/pars ---------------------------------------
218  fRailway->LoadLibrary("PWGLFforward2");
219  // fRailway->LoadLibrary("AOD");
220  // gSystem->ListLibraries();
221  // gSystem->Load("libAOD");
222 
223  // --- Set load path ---------------------------------------------
224  gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2",
225  gROOT->GetMacroPath()));
226 
227  // --- Get parameters --------------------------------------------
228  Bool_t mc = fOptions.Has("mc");
229  TString fwdCfg = fOptions.Get("forward-config");
230  TString cenCfg = fOptions.Get("central-config");
231  TString mcCfg = fOptions.Get("truth-config");
232  if (!mc) mc = fRailway->IsMC();
233 
234  // --- Add the task ----------------------------------------------
235  CoupledNdetaCar("Forward", fwdCfg);
236  Bool_t noCentral = fOptions.Has("no-central");
237  if (!noCentral)
238  CoupledNdetaCar("Central", cenCfg);
239  if (mc) CoupledNdetaCar("MCTruth", mcCfg);
240  CoupleTrackletCar(mgr);
241 
242  }
243  //__________________________________________________________________
247  //__________________________________________________________________
248  // void CreateCentralitySelection(Bool_t) {}
254  AliVEventHandler* CreateMCHandler(UShort_t, bool) { return 0; }
255  //__________________________________________________________________
261  AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
262  //__________________________________________________________________
263  const char* ClassName() const { return "BothdNdetaTrain"; }
264  //__________________________________________________________________
270  void SaveSetup(Bool_t asShellScript)
271  {
272  TrainSetup::SaveSetup(asShellScript);
273 
274  SaveDraw();
275  SaveSummarize();
276  SaveCollect();
277  }
279  {
280  std::ofstream f("Summarize.C");
281  if (!f) {
282  Error("SaveSummarize", "Failed to open Summarize.C script");
283  return;
284  }
285  f << "// Generated by " << ClassName() << "\n"
286  << "// WHAT is a bit mask of\n"
287  << "// 0x001 Forward\n"
288  << "// 0x002 Central\n"
289  << "// 0x004 Sums\n"
290  << "// 0x008 Results\n"
291  << "// 0x010 Only min-bias (no centrality)\n"
292  << "// 0x080 Assume simulation results\n"
293  << "// 0x100 Landscape\n"
294  << "// 0x200 Pause\n"
295  << "// 0x400 Also draw single result canvas\n"
296  << "//\n"
297  << "void Summarize(const char* filename=\"forward_dndeta.root\",\n"
298  << " UShort_t what=0x10F)\n"
299  << "{\n"
300  << " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
301  << " gROOT->LoadMacro(Form(\"%s/DrawdNdetaSummary.C\",fwd));\n"
302  << " DrawdNdetaSummary(filename,what & 0x3FF);\n"
303  << "\n"
304  << " if (!(what & 0x400)) return;\n"
305  << " gROOT->SetMacroPath(Form(\"../:%s\",gROOT->GetMacroPath()));\n"
306  << " gROOT->Macro(\"Draw.C\");\n"
307  << "}\n"
308  << "// EOF" << std::endl;
309  f.close();
310  }
315  void SaveDraw()
316  {
317  std::ofstream o("Draw.C");
318  if (!o) {
319  Error("BothdNdetaTrain::SaveDraw", "Failed to open Draw.C");
320  return;
321  }
322 
323  o << "// Created by " << ClassName() << "\n"
324  << "// Will draw dN/deta results from produced file\n"
325  << "// \n"
326  << "void Draw(UShort_t rebin=5,\n"
327  << " Double_t eff=1,\n"
328  << " Bool_t raw=false,\n"
329  << " Bool_t cutEdges=false,\n"
330  << " const char* which=\"Forward\")\n"
331  << "{\n"
332  << " TString fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dndeta\";\n"
333  << " gROOT->LoadMacro(Form(\"%s/ExtractGSEs.C\",fwd.Data()));\n"
334  << " ExtractGSEs(\"forward_dndeta.root\",\n"
335  << " rebin,eff,raw,cutEdges,which);\n"
336  << "}\n"
337  << "//\n"
338  << "// EOF\n"
339  << "//" << std::endl;
340  o.close();
341  }
342  void SaveCollect()
343  {
344  std::ofstream o("Collect.C");
345  if (!o) {
346  Error("BothdNdetaTrain::SavePost", "Failed to open Collect.C");
347  return;
348  }
349  o << "// Created by " << ClassName() << "\n"
350  << "// Will draw dN/deta results from produced files\n"
351  << "// \n"
352  << "void Collect(const char* other,\n"
353  << " const char* output,\n"
354  << " UInt_t proc=0x2,\n"
355  << " UInt_t viz=0x32f,\n"
356  << " UInt_t n=10)\n"
357  << "{\n"
358  << " TString fwd=\n"
359  << " \"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dndeta/tracklets3\";\n"
360  << " if (gSystem->GetEnv(\"ANA_SRC\"))\n"
361  << " fwd = \"$ANA_SRC/dndeta/trackldwets3\";\n"
362  << " gROOT->LoadMacro(Form(\"%s/Post.C\",fwd.Data()));\n"
363  << " const char* thisDir = \"" << fEscapedName << "\";\n";
364  if (fRailway->IsMC())
365  o << " Post(thisDir,other,output,proc,viz,n);\n";
366  else
367  o << " Post(other,thisDir,output,proc,viz,n);\n";
368  o << "}\n"
369  << "// EOF\n"
370  << std::endl;
371  o.close();
372  }
373  void PostShellCode(std::ostream& f)
374  {
375  f << " echo \"=== Summarizing results ...\"\n"
376  << " aliroot -l -b -q ${prefix}Summarize.C\n"
377  << " echo \"=== Draw results ...\"\n"
378  << " aliroot -l -b -q ${prefix}Draw.C\n"
379  << std::endl;
380  }
381 };
382 //
383 // EOF
384 //
Double_t AsDouble(const TString &name, Double_t def=0) const
Definition: Option.C:673
double Double_t
Definition: External.C:58
Railway * fRailway
Definition: TrainSetup.C:1666
TSystem * gSystem
void CreateTasks(AliAnalysisManager *mgr)
AliVEventHandler * CreateOutputHandler(UShort_t)
const char * AsString(const TString &name, const TString &def="") const
Definition: Option.C:687
BothdNdetaTrain(const char *name)
const TString & Get(const TString &name) const
Definition: Option.C:596
AliVEventHandler * CreateMCHandler(UShort_t, bool)
const char * ClassName() const
Bool_t Has(const TString &name) const
Definition: Option.C:584
unsigned int UInt_t
Definition: External.C:33
void CoupleTrackletCar(AliAnalysisManager *mgr)
virtual Bool_t IsMC() const
Definition: Railway.C:354
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 void SaveSetup(Bool_t asShellScript)
Definition: TrainSetup.C:1471
void FromOption(AliAnalysisTaskSE *task, const char *what, const char *opt, Double_t defval)
Definition: TrainSetup.C:1228
Bool_t CoupledNdetaCar(const char *which, const char *cfg)
OptionList fOptions
Definition: TrainSetup.C:1665
unsigned short UShort_t
Definition: External.C:28
void PostShellCode(std::ostream &f)
bool Bool_t
Definition: External.C:53
TString fEscapedName
Definition: TrainSetup.C:1663
void SaveSetup(Bool_t asShellScript)
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
virtual Bool_t LoadSource(const TString &name, bool copy=false)
Definition: Railway.C:231
void SetOnTask(AliAnalysisTaskSE *task, const char *what, UInt_t val)
Definition: TrainSetup.C:1128