AliPhysics  a5cd6b6 (a5cd6b6)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeTrackletTrain.C
Go to the documentation of this file.
1 #include "TrainSetup.C"
2 #ifndef __CINT__
3 #include <AliESDInputHandlerRP.h>
4 // #include <AliMixInputEventHandler.h>
5 // #include <AliMixEventPool.h>
6 // #include <AliMixEventCutObj.h>
7 #include <TMacro.h>
8 #else
10 #endif
11 
34 {
40  MakeTrackletTrain(const char* name)
41  : TrainSetup(name)
42  {
43  // Define all our options here
44  fOptions.Add("trig", "NAME", "Trigger to use", "V0AND");
45  fOptions.Add("cent", "METHOD","Centrality selector", "V0M");
46  fOptions.Add("cent-bins", "Bins", "Centrality bins",
47  "0-5-10-20-30-40-50-60-70-80");
48  fOptions.Add("check-reco", "Check reconstruction", false);
49  fOptions.Add("sig-n-dev", "X", "Cut on weighted distance", 25.);
50  fOptions.Add("scale-dtheta", "Scale dTheta", true);
51  fOptions.Add("cut-dtheta", "Cut dTheta", false);
52  fOptions.Add("dphi", "X", "dPhi window", 0.06);
53  fOptions.Add("dtheta", "X", "dTheta window", 0.025);
54  fOptions.Add("phi-shift", "X", "Bending shift", 0.0045);
55  fOptions.Add("outlier-phi", "X", "Phi outlier cut", 0.005);
56  fOptions.Add("outlier-z-eta", "X", "Z-Eta outlier cut", 0.05);
57  fOptions.Add("phi-rot", "X", "Rotation BG angle", TMath::Pi());
58  fOptions.Add("inj-scale", "X", "Injection BG scale", 1.);
59  fOptions.Add("remove-outliers", "Whether to remove outliers",true);
60  fOptions.Add("sig-dphi-s", "X", "Cut on dPhi-phiBent", -1.);
61  fOptions.Add("sig-n-std", "X", "Cut on weighted distance", 1.5);
62  fOptions.Add("mc-v0-scale", "X", "Scaling of MC V0", 1.);
63  fOptions.Add("eta-min", "ETA", "Least eta", -2);
64  fOptions.Add("eta-max", "ETA", "Largest eta", +2);
65  fOptions.Add("deta", "WIDTH", "Eta bin width", 0.25);
66  fOptions.Add("ipz-min", "CM", "Least IPz", -15);
67  fOptions.Add("ipz-max", "CM", "Largest IPz", +15);
68  fOptions.Add("fill-reco", "Fill with new reco", true);
69  fOptions.Add("create-inj", "Create injection BG", true);
70  fOptions.Add("create-rot", "Create rotation BG", false);
71  fOptions.Add("reweight", "OPTIONS","','-seperates list", "");
72  fOptions.SetDescription("Run tracklet analysis on ESD data files to "
73  "extract dNch/deta. The train should be run on "
74  "both real data and simulated data. When "
75  "processing simulated data, it is possible to "
76  "reweigh the particles according to predefined "
77  "histograms in pT. These histograms should "
78  "be stored in separate files. The option to "
79  "select reweighting is 'reweight', which is "
80  "a comma separated list of options:\n"
81  "- pt, pid, str: Reweigh according to pT, PID or "
82  "weak decays\n"
83  "- up, down: Vary reweight up or down\n"
84  "- pi, K, p: For PID reweigh of particular specie");
85 
86  }
97  AliVEventHandler* CreateInputHandler(UShort_t type, Bool_t needRec=false)
98  {
99 
100  Bool_t fill_reco = fOptions.AsBool("fill-reco");;
101  Bool_t create_inj = fOptions.AsBool("create-inj");;
102  Bool_t create_rot = fOptions.AsBool("create-rot");;
103  needRec = fill_reco || create_inj || create_rot || needRec;
104 
105  Info("CreateInputHandler",
106  "fill_reco=%d create_inj=%d create_rot=%d needRec=%d",
107  fill_reco, create_inj, create_rot, needRec);
108  return TrainSetup::CreateInputHandler(type, needRec);
109  }
119  AliVEventHandler* CreateMCHandler(UShort_t type, bool mc)
120  {
121  AliMCEventHandler* ret =
122  static_cast<AliMCEventHandler*>(TrainSetup::CreateMCHandler(type,mc));
123  if (ret) ret->SetPreReadMode(AliMCEventHandler::kLmPreRead);
124  return ret;
125  }
132  virtual AliVEventHandler* CreateOutputHandler(UShort_t)
133  {
134  return 0;
135  }
167  {
168  TString sel = fOptions.AsString("reweight");
169  sel.ToLower();
170  if (sel.IsNull() || sel.BeginsWith("no"))
171  return;
172 
173  TList files;
174  Int_t what = 0;
175  Int_t opt = 0;
176  TObjArray* tokens = sel.Tokenize(", ");
177  TIter next(tokens);
178  TObjString* ostr;
179  // First find what should be done
180  while ((ostr = static_cast<TObjString*>(next()))) {
181  const TString& token = ostr->String();
182 
183  if (token.EqualTo("pt")) {
184  what |= 0x1;
185  files.Add(new TObjString("REWEIGHTpt.root"));
186  Printf("Will reweigh in pT");
187  }
188  else if (token.EqualTo("pid")) {
189  what |= 0x2;
190  Printf("Will reweigh particle species");
191  }
192  else if (token.EqualTo("str")) {
193  what |= 0x4;
194  Printf("Will reweight particles from strange weak decays");
195  }
196  }
197  if (what == 0x0) return;
198 
199  // Now figure out how to do it
200  next.Reset();
201  TString part;
202  while ((ostr = static_cast<TObjString*>(next()))) {
203  const TString& token = ostr->String();
204  Int_t aOpt = TMath::Abs(opt);
205  if (token.EqualTo("up") || token.EqualTo("+"))
206  opt = (aOpt==0 ? +1 : +aOpt);
207  else if (token.EqualTo("down") || token.EqualTo("-"))
208  opt = (aOpt==0 ? -1 : -aOpt);
209  else if (token.EqualTo("pi") || token.EqualTo("pion")){
210  opt = 1; part = "pi";
211  }
212  else if (token.EqualTo("k") || token.EqualTo("kaon")) {
213  opt = 2; part = "ka";
214  }
215  else if (token.EqualTo("p") || token.EqualTo("proton")) {
216  opt = 3; part = "pr";
217  }
218  }
219  if (opt != 0)
220  Printf("Will reweigh %s (%c30%% for pT<0.05)",
221  opt < 0 ? "down" : "up", opt < 0 ? '-' : '+');
222  if (what & 0x2) {
223  if (!part.IsNull()) {
224  Printf("Will reweight %s in particular", part.Data());
225  part.Prepend("_");
226  part.Append(opt < 0 ? "-" : "+");
227  }
228  files.Add(new TObjString(Form("REWEIGHTpid%s.root", part.Data())));
229  }
230  if (what & 0x4)
231  files.Add(new TObjString(Form("REWEIGHTstr%s.root",
232  opt == -1 ? "-" :
233  opt == +1 ? "+" : "")));
234  delete tokens;
235 
236  Printf("Setting reweighing flag=0x%x with option=%d", what, opt);
237  SetOnTask(task, "ReweightStack", what);
238  SetOnTask(task, "ReweightFlag", opt);
239 
240  TIter nextF(&files);
241  while ((ostr = static_cast<TObjString*>(nextF()))) {
242  Printf("Loading reweighting file %s", ostr->GetName());
243  fRailway->LoadAux(ostr->GetName());
244  }
245  }
255  {
256  // Enable these lines to load the code from PWGUD directory.
257  // These do not seem to be up-to-speed with the latest
258  // developments, so for now, we use private scripts - sigh!
259  //
260  // Note, PWGLF also has these scripts, but it is not clear that
261  // they are anymore current than the ones in PWGUD.
262  //
263  // gROOT->SetMacroPath(Form("%s:$ALICE_PHYSICS/PWGUD/multVScentPbPb",
264  // gROOT->GetMacroPath()));
265  // gSystem->AddIncludePath("-I$ALICE_PHYSICS/PWGUD/multVScentPbPb");
266  Info("CreateTasks", "Loading code");
267  fRailway->LoadSource("FixPaths.C");
268  // fRailway->LoadAux("AliITSMultRecBg.h");
269  fRailway->LoadAux("AliTrackletTaskMulti.h");
270  // fRailway->LoadSource("AliITSMultRecBg.cxx");
271  fRailway->LoadSource("AliTrackletTaskMulti.cxx");
272 
273  // --- Create the task using interpreter -------------------------
274  Bool_t mc = mgr->GetMCtruthEventHandler() != 0;
275  const char* cls = "AliTrackletTaskMulti";
276  Long_t ret = gROOT->ProcessLine(Form("new %s(\"%s\")",cls,cls));
277  AliAnalysisTaskSE* task =reinterpret_cast<AliAnalysisTaskSE*>(ret);
278  if (!task) return 0;
279 
280  // --- Add task to train -----------------------------------------
281  mgr->AddTask(task);
282 
283  // --- Figure out the trigger options ----------------------------
284  TString trg = fOptions.Get("trig");
285  trg.ToUpper();
286  UInt_t sel = AliVEvent::kINT7;
287  if (trg.EqualTo("MB")) sel = AliVEvent::kMB;
288  else if (trg.EqualTo("V0AND")) sel = AliVEvent::kINT7;
289  else if (trg.EqualTo("V0OR")) sel = AliVEvent::kCINT5;
290  else if (trg.EqualTo("ANY")) sel = AliVEvent::kAny;
291 
292  // --- Fix up some options ---------------------------------------
293  Double_t sig_dphi_s = fOptions.AsDouble("sig-dphi-s",-1);
294  Double_t sig_n_std = fOptions.AsDouble("sig-n-std",1.5);
295  Double_t dphi = fOptions.AsDouble("dphi",0.06);
296  if (sig_dphi_s<0) fOptions.Set("sig-dphi-s", TMath::Sqrt(sig_n_std)*dphi);
297 
298  // --- Set various options on task -------------------------------
299  task->SelectCollisionCandidates(sel);
300  SetOnTask(task, "UseMC", mc);
301  SetOnTask(task, "TriggerSelection", sel);
302  FromOption(task, "UseCentralityVar", "cent", "");
303  FromOption(task, "CheckReconstructables", "check-reco", false);
304  FromOption(task, "NStdDev", "sig-n-dev", 25.);
305  FromOption(task, "ScaleDThetaBySin2T", "scale-dtheta", false);
306  FromOption(task, "CutOnDThetaX", "cut-dtheta", false);
307  FromOption(task, "PhiWindow", "dphi", 0.06);
308  FromOption(task, "ThetaWindow", "dtheta", 0.025);
309  FromOption(task, "PhiShift", "phi-shift", 0.0045);
310  FromOption(task, "PhiOverlapCut", "outlier-phi", 0.005);
311  FromOption(task, "ZetaOverlapCut", "outlier-z-eta",0.05);
312  FromOption(task, "PhiRot", "phi-rot", TMath::Pi());
313  FromOption(task, "InjScale", "inj-scale", 1.);
314  FromOption(task, "RemoveOverlaps", "remove-outliers",false);
315  FromOption(task, "DPhiSCut", "sig-dphi-s", -1.);
316  FromOption(task, "NStdCut", "sig-n-std", 1.5);
317  FromOption(task, "ScaleMCV0", "mc-v0-scale", 1.);
318  FromOption(task, "EtaMin", "eta-min", -2.);
319  FromOption(task, "EtaMax", "eta-max", +2.);
320  FromOption(task, "EtaBinWidth", "deta", +2.5);
321  FromOption(task, "ZVertexMin", "ipz-min", -15.);
322  FromOption(task, "ZVertexMax", "ipz-max", +15.);
323  FromOption(task, "DoNormalReco", "fill-reco", false);
324  FromOption(task, "DoInjection", "create-inj", false);
325  FromOption(task, "DoRotation", "create-rot", false);
326  SetupReweighting(task);
327 
328  // --- Set centrality bins ---------------------------------------
329  TString centBins = fOptions.AsString("cent-bins");
330  TObjArray* tokens = centBins.Tokenize("-");
331  TArrayD array(tokens->GetEntries());
332  for (Int_t i = 0; i < array.GetSize(); i++) {
333  TObjString* ostr = static_cast<TObjString*>(tokens->At(i));
334  TString& str = ostr->String();
335  array[i] = str.Atof();
336  }
337  gROOT->ProcessLine(Form("((%s)%p)->SetCentPercentiles((Double_t*)%p,%d)",
338  cls, task, array.GetArray(), array.GetSize()-1));
339 
340  // --- Connect I/O -----------------------------------------------
341  AliAnalysisDataContainer *out =
342  mgr->CreateContainer("clist", TList::Class(),
343  AliAnalysisManager::kOutputContainer,
344  (mc ? "trmc.root" : "trdt.root"));
345  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
346  mgr->ConnectOutput(task,1,out);
347 
348  return task;
349  }
356  {
357  AliAnalysisTaskSE* task = CreateTask(mgr);
358  if (!task) {
359  Fatal("", "Failed to create the task");
360  return;
361  }
362 
363 #if 0
364  gSystem->RedirectOutput("settings.txt");
365  Printf("=== Settings for %s train === ", mc ? "mc" : "dt");
366  task->Dump();
367  gSystem->RedirectOutput(0);
368 #endif
369 
370  }
376  const char* ClassName() const { return "MakeTrackletTrain"; }
377 };
378 //
379 // EOF
380 //
Double_t AsDouble(const TString &name, Double_t def=0) const
Definition: Option.C:673
virtual AliVEventHandler * CreateInputHandler(UShort_t type, Bool_t esdRecPoints=false)
Definition: TrainSetup.C:539
return jsonbuilder str().c_str()
void SetupReweighting(AliAnalysisTaskSE *task)
double Double_t
Definition: External.C:58
MakeTrackletTrain(const char *name)
Railway * fRailway
Definition: TrainSetup.C:1667
Bool_t AsBool(const TString &name) const
Definition: Option.C:631
TSystem * gSystem
AliVEventHandler * CreateInputHandler(UShort_t type, Bool_t needRec=false)
virtual AliVEventHandler * CreateMCHandler(UShort_t, bool mc)
Definition: TrainSetup.C:583
const char * AsString(const TString &name, const TString &def="") const
Definition: Option.C:687
AliVEventHandler * CreateMCHandler(UShort_t type, bool mc)
const TString & Get(const TString &name) const
Definition: Option.C:596
const char * ClassName() const
virtual AliVEventHandler * CreateOutputHandler(UShort_t)
int Int_t
Definition: External.C:63
void CreateTasks(AliAnalysisManager *mgr)
unsigned int UInt_t
Definition: External.C:33
void Set(const TString &name, const TString &value)
Definition: Option.C:736
AliAnalysisTaskSE * CreateTask(AliAnalysisManager *mgr)
void SetDescription(const TString &d)
Definition: Option.C:359
Base classs for train specifications.
Option * Add(const TString &name, const TString &arg, const TString &desc, const TString &val="")
Definition: Option.C:421
virtual Bool_t LoadAux(const TString &name, Bool_t copy=false)
Definition: Railway.C:255
void FromOption(AliAnalysisTaskSE *task, const char *what, const char *opt, Double_t defval)
Definition: TrainSetup.C:1229
OptionList fOptions
Definition: TrainSetup.C:1666
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
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