AliPhysics  1168478 (1168478)
 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  UInt_t mb = AliVEvent::kINT1; // AliVEvent::kMB;
150  if (trg.EqualTo("MB")) sel = mb;
151  else if (trg.EqualTo("MBOR")) sel = mb;
152  else if (trg.EqualTo("INEL")) sel = mb;
153  else if (trg.EqualTo("INELGT0")) sel = mb;
154  else if (trg.EqualTo("V0AND")) sel = AliVEvent::kINT7;
155  else if (trg.EqualTo("NSD")) sel = AliVEvent::kINT7;
156  else if (trg.EqualTo("V0OR")) sel = AliVEvent::kCINT5;
157  else if (trg.EqualTo("ANY")) sel = AliVEvent::kAny;
158  task->SelectCollisionCandidates(sel);
159  Int_t minTrk = trg.EqualTo("INELGT0") ? 1 : 0;
160 
161  // --- Figure out calculation mode -------------------------------
162  TString calc = fOptions.Get("reweigh-calc"); calc.ToUpper();
163  UChar_t mcal = 0;
164  if (calc.BeginsWith("PROD")) mcal = 0;
165  else if (calc.BeginsWith("SQ")) mcal = 1;
166  else if (calc.BeginsWith("SUM")) mcal = 2;
167  else if (calc.BeginsWith("AV")) mcal = 3;
168 
169  // --- Set various options on task -------------------------------
170  const char* defCent = "0-5-10-20-30-40-50-60-70-80-90";
171  FromOption(task, "CentralityMethod","cent", "V0M");
172  FromOption(task, "CentralityAxis", "cent-bins", defCent);
173  FromOption(task, "EtaAxis", "eta-bins", "r16:2");
174  FromOption(task, "IPzAxis", "ipz-bins", "u15");
175  FromOption(task, "DeltaCut", "delta-cut", 1.5);
176  FromOption(task, "TailDelta", "tail-delta", 5.);
177  FromOption(task, "TailMaximum", "tail-max", -1);
178  FromOption(task, "MaxDelta", "max-delta", 25.);
179  FromOption(task, "DPhiShift", "dphi-shift", 0.0045);
180  FromOption(task, "ShiftedDPhiCut", "shifted-dphi-cut",-1.);
181  FromOption(task, "AbsMinCent", "abs-min-cent", -1.);
182  FromOption(task, "WeightMask", "reweigh-mask", 0xFF);
183  FromOption(task, "WeightVeto", "reweigh-veto", 0x0);
184  SetOnTask (task, "WeightCalc", mcal);
185  FromOption(task, "WeightInverse", "reweigh-inv", false);
186  FromOption(task, "TriggerEff", "trigEff", 0.);
187  SetOnTask (task, "MinEta1", minTrk);
188  // if (mc && we) {
189  // TUrl wurl(fOptions.AsString("reweight"));
190  // TFile* wfile = TFile::Open(wurl.GetFile());
191  // if (!wfile) {
192  // Warning("CreateTasks", "Failed to open weights file: %s",
193  // wurl.GetUrl());
194  // return;
195  // }
196  // TString wnam(wurl.GetAnchor());
197  // if (wnam.IsNull()) wnam = "weights";
198  // TObject* wobj = wfile->Get(wnam);
199  // if (!wobj) {
200  // Warning("CreateTasks", "Failed to get weights %s from file %s",
201  // wnam.Data(), wfile->GetName());
202  // return;
203  // }
204  // if (!wobj->IsA()->InheritsFrom("AliTrackletWeights")) {
205  // Warning("CreateTasks", "Object %s from file %s not an "
206  // "AliTrackletWeights but a %s",
207  // wnam.Data(), wfile->GetName(), wobj->ClassName());
208  // return;
209  // }
210  // SetOnTaskGeneric(task, "Weights",
211  // Form("((AliTrackletWeights*)%p)", wobj));
212  // }
213  Printf("Print the generated task");
214  task->Print("");
215  }
221  {
222  // --- Output file name ------------------------------------------
223  AliAnalysisManager::SetCommonFileName("forward_dndeta.root");
224 
225  // --- Load libraries/pars ---------------------------------------
226  fRailway->LoadLibrary("PWGLFforward2");
227  // fRailway->LoadLibrary("AOD");
228  // gSystem->ListLibraries();
229  // gSystem->Load("libAOD");
230 
231  // --- Set load path ---------------------------------------------
232  gROOT->SetMacroPath(Form("%s:$(ALICE_PHYSICS)/PWGLF/FORWARD/analysis2",
233  gROOT->GetMacroPath()));
234 
235  // --- Get parameters --------------------------------------------
236  Bool_t mc = fOptions.Has("mc");
237  TString fwdCfg = fOptions.Get("forward-config");
238  TString cenCfg = fOptions.Get("central-config");
239  TString mcCfg = fOptions.Get("truth-config");
240  if (!mc) mc = fRailway->IsMC();
241 
242  // --- Add the task ----------------------------------------------
243  CoupledNdetaCar("Forward", fwdCfg);
244  Bool_t noCentral = fOptions.Has("no-central");
245  if (!noCentral)
246  CoupledNdetaCar("Central", cenCfg);
247  if (mc) CoupledNdetaCar("MCTruth", mcCfg);
248  CoupleTrackletCar(mgr);
249 
250  }
251  //__________________________________________________________________
255  //__________________________________________________________________
256  // void CreateCentralitySelection(Bool_t) {}
262  AliVEventHandler* CreateMCHandler(UShort_t, bool) { return 0; }
263  //__________________________________________________________________
269  AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
270  //__________________________________________________________________
271  const char* ClassName() const { return "BothdNdetaTrain"; }
272  //__________________________________________________________________
278  void SaveSetup(Bool_t asShellScript)
279  {
280  TrainSetup::SaveSetup(asShellScript);
281 
282  SaveDraw();
283  SaveSummarize();
284  SaveCollect();
285  }
287  {
288  std::ofstream f("Summarize.C");
289  if (!f) {
290  Error("SaveSummarize", "Failed to open Summarize.C script");
291  return;
292  }
293  f << "// Generated by " << ClassName() << "\n"
294  << "// WHAT is a bit mask of\n"
295  << "// 0x001 Forward\n"
296  << "// 0x002 Central\n"
297  << "// 0x004 Sums\n"
298  << "// 0x008 Results\n"
299  << "// 0x010 Only min-bias (no centrality)\n"
300  << "// 0x080 Assume simulation results\n"
301  << "// 0x100 Landscape\n"
302  << "// 0x200 Pause\n"
303  << "// 0x400 Also draw single result canvas\n"
304  << "//\n"
305  << "void Summarize(const char* filename=\"forward_dndeta.root\",\n"
306  << " UShort_t what=0x10F)\n"
307  << "{\n"
308  << " const char* fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2\";\n"
309  << " gROOT->LoadMacro(Form(\"%s/DrawdNdetaSummary.C\",fwd));\n"
310  << " DrawdNdetaSummary(filename,what & 0x3FF);\n"
311  << "\n"
312  << " if (!(what & 0x400)) return;\n"
313  << " gROOT->SetMacroPath(Form(\"../:%s\",gROOT->GetMacroPath()));\n"
314  << " gROOT->Macro(\"Draw.C\");\n"
315  << "}\n"
316  << "// EOF" << std::endl;
317  f.close();
318  }
323  void SaveDraw()
324  {
325  std::ofstream o("Draw.C");
326  if (!o) {
327  Error("BothdNdetaTrain::SaveDraw", "Failed to open Draw.C");
328  return;
329  }
330 
331  o << "// Created by " << ClassName() << "\n"
332  << "// Will draw dN/deta results from produced file\n"
333  << "// \n"
334  << "void Draw(UShort_t rebin=5,\n"
335  << " Double_t eff=1,\n"
336  << " Bool_t raw=false,\n"
337  << " Bool_t cutEdges=false,\n"
338  << " const char* which=\"Forward\")\n"
339  << "{\n"
340  << " TString fwd=\"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dndeta\";\n"
341  << " gROOT->LoadMacro(Form(\"%s/ExtractGSEs.C\",fwd.Data()));\n"
342  << " ExtractGSEs(\"forward_dndeta.root\",\n"
343  << " rebin,eff,raw,cutEdges,which);\n"
344  << "}\n"
345  << "//\n"
346  << "// EOF\n"
347  << "//" << std::endl;
348  o.close();
349  }
350  void SaveCollect()
351  {
352  std::ofstream o("Collect.C");
353  if (!o) {
354  Error("BothdNdetaTrain::SavePost", "Failed to open Collect.C");
355  return;
356  }
357  o << "// Created by " << ClassName() << "\n"
358  << "// Will draw dN/deta results from produced files\n"
359  << "// \n"
360  << "void Collect(const char* other,\n"
361  << " const char* output,\n"
362  << " UInt_t proc=0x2,\n"
363  << " UInt_t viz=0x32f,\n"
364  << " UInt_t n=10)\n"
365  << "{\n"
366  << " TString fwd=\n"
367  << " \"$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/dndeta/tracklets3\";\n"
368  << " if (gSystem->Getenv(\"ANA_SRC\"))\n"
369  << " fwd = \"$ANA_SRC/dndeta/tracklets3\";\n"
370  << " gROOT->LoadMacro(Form(\"%s/Post.C\",fwd.Data()));\n"
371  << " const char* thisDir = \"" << fEscapedName << "\";\n";
372  if (fRailway->IsMC())
373  o << " Post(thisDir,other,output,proc,viz,n);\n";
374  else
375  o << " Post(other,thisDir,output,proc,viz,n);\n";
376  o << "}\n"
377  << "// EOF\n"
378  << std::endl;
379  o.close();
380  }
381  void PostShellCode(std::ostream& f)
382  {
383  f << " echo \"=== Summarizing results ...\"\n"
384  << " aliroot -l -b -q ${prefix}Summarize.C\n"
385  << " echo \"=== Draw results ...\"\n"
386  << " aliroot -l -b -q ${prefix}Draw.C\n"
387  << std::endl;
388  }
389 };
390 //
391 // EOF
392 //
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:1667
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
int Int_t
Definition: External.C:63
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:1472
void FromOption(AliAnalysisTaskSE *task, const char *what, const char *opt, Double_t defval)
Definition: TrainSetup.C:1229
Bool_t CoupledNdetaCar(const char *which, const char *cfg)
OptionList fOptions
Definition: TrainSetup.C:1666
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:1664
void SaveSetup(Bool_t asShellScript)
virtual AliAnalysisTaskSE * CoupleSECar(const TString &macro, const TString &args, UInt_t mask=0)
Definition: TrainSetup.C:876
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:1129