Belle II Software  release-08-01-10
DedxVariables.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 // needed to build variables here
10 #include <reconstruction/variables/DedxVariables.h>
11 #include <analysis/VariableManager/Manager.h>
12 
13 // framework - DataStore
14 #include <framework/gearbox/Const.h>
15 #include <framework/logging/Logger.h>
16 #include <framework/utilities/Conversion.h>
17 
18 // dataobjects
19 #include <analysis/dataobjects/Particle.h>
20 #include <mdst/dataobjects/Track.h>
21 #include <reconstruction/dataobjects/CDCDedxTrack.h>
22 #include <reconstruction/dataobjects/VXDDedxTrack.h>
23 
24 #include <TString.h>
25 
26 #include <cmath>
27 
28 namespace Belle2 {
37  CDCDedxTrack const* getDedxFromParticle(Particle const* particle)
38  {
39  const Track* track = particle->getTrack();
40  if (!track) {
41  return nullptr;
42  }
43 
44  const CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
45  if (!dedxTrack) {
46  return nullptr;
47  }
48 
49  return dedxTrack;
50  }
51 
56  {
57  const Track* track = particle->getTrack();
58  if (!track) {
59  return nullptr;
60  }
61 
62  const VXDDedxTrack* dedxTrack = track->getRelatedTo<VXDDedxTrack>();
63  if (!dedxTrack) {
64  return nullptr;
65  }
66  return dedxTrack;
67  }
68 
69 
70  namespace Variable {
71 
72  double CDCdedx(const Particle* part)
73  {
74  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
75  if (!dedxTrack) {
76  return -999.0;
77  } else {
78  return dedxTrack->getDedx();
79  }
80  }
81 
82  double CDCdedxnosat(const Particle* part)
83  {
84  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
85  if (!dedxTrack) {
86  return -999.0;
87  } else {
88  return dedxTrack->getDedxNoSat();
89  }
90  }
91 
92  double pCDC(const Particle* part)
93  {
94  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
95  if (!dedxTrack) {
96  return -999.0;
97  } else {
98  return dedxTrack->getMomentum();
99  }
100  }
101 
102  double costhCDC(const Particle* part)
103  {
104  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
105  if (!dedxTrack) {
106  return -999.0;
107  } else {
108  return dedxTrack->getCosTheta();
109  }
110  }
111 
112 
113  double CDCdEdx_nhits(const Particle* part)
114  {
115  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
116  if (!dedxTrack) {
117  return -999.0;
118  } else {
119  return dedxTrack->size();
120  }
121  }
122 
123  double CDCdEdx_lnhits(const Particle* part)
124  {
125  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
126  if (!dedxTrack) {
127  return -999.0;
128  } else {
129  return dedxTrack->getNLayerHits();
130  }
131  }
132 
133  double CDCdEdx_lnhitsused(const Particle* part)
134  {
135  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
136  if (!dedxTrack) {
137  return -999.0;
138  } else {
139  return dedxTrack->getNLayerHitsUsed();
140  }
141  }
142 
143  Manager::FunctionPtr CDCdEdx_PIDvars(const std::vector<std::string>& arguments)
144  {
145  if (arguments.size() < 2) {
146  B2ERROR("Min two arguments required to get variables related chi, predicted mean and reso");
147  return nullptr;
148  }
149 
150  TString var = "";
151  try {
152  var = arguments[0];
153  } catch (std::invalid_argument& e) {
154  B2ERROR("First argument of variable must be a variable name (chi or pmean or preso)");
155  return nullptr;
156  }
157 
158  int pdgCode;
159  try {
160  pdgCode = Belle2::convertString<int>(arguments[1]);
161  } catch (std::invalid_argument& e) {
162  B2ERROR("Second argument of variable must be a PDG code");
163  return nullptr;
164  }
165 
166  int index = -999;
167  if (abs(pdgCode) == Const::electron.getPDGCode())index = 0;
168  else if (abs(pdgCode) == Const::muon.getPDGCode())index = 1;
169  else if (abs(pdgCode) == Const::pion.getPDGCode())index = 2;
170  else if (abs(pdgCode) == Const::kaon.getPDGCode())index = 3;
171  else if (abs(pdgCode) == Const::proton.getPDGCode())index = 4;
172  else if (abs(pdgCode) == Const::deuteron.getPDGCode())index = 5;
173 
174  auto func = [index, var](const Particle * part) -> double {
175  const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
176  if (!dedxTrack)
177  {
178  return std::numeric_limits<float>::quiet_NaN();
179  } else
180  {
181  if (var == "chi") return dedxTrack->getChi(index);
182  else if (var == "pmean") return dedxTrack->getPmean(index);
183  else if (var == "preso") return dedxTrack->getPreso(index);
184  else return std::numeric_limits<float>::quiet_NaN();
185  }
186  };
187  return func;
188  }
189 
190  double CDCdEdx_chiE(const Particle* part)
191  {
192  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 11)")->function(part));
193  }
194 
195  double CDCdEdx_chiMu(const Particle* part)
196  {
197  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 13)")->function(part));
198  }
199 
200  double CDCdEdx_chiPi(const Particle* part)
201  {
202  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 211)")->function(part));
203  }
204 
205  double CDCdEdx_chiK(const Particle* part)
206  {
207  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 321)")->function(part));
208  }
209 
210  double CDCdEdx_chiP(const Particle* part)
211  {
212  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 2212)")->function(part));
213  }
214 
215  double CDCdEdx_chiD(const Particle* part)
216  {
217  return std::get<double>(Manager::Instance().getVariable("CDCdEdx_PIDvars(chi, 1000010020)")->function(part));
218  }
219 
220 //Variables for SVD dedx
221  double SVD_p(const Particle* part)
222  {
223  const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
224  if (!dedxTrack) {
225  return -999.0;
226  } else {
227  return dedxTrack->getMomentum();
228  }
229  }
230 
231  double SVD_pTrue(const Particle* part)
232  {
233  const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
234  if (!dedxTrack) {
235  return -999.0;
236  } else {
237  return dedxTrack->getTrueMomentum();
238  }
239  }
240 
241  double SVDdedx(const Particle* part)
242  {
243  const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
244  if (!dedxTrack) {
245  return -999.0;
246  } else {
247  return dedxTrack->getDedx(Const::EDetector::SVD);
248  }
249  }
250 
251  double SVD_CosTheta(const Particle* part)
252  {
253  const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
254  if (!dedxTrack) {
255  return -999.0;
256  } else {
257  return dedxTrack->getCosTheta();
258  }
259  }
260  double SVD_nHits(const Particle* part)
261  {
262  const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
263  if (!dedxTrack) {
264  return -999.0;
265  } else {
266  return dedxTrack->size();
267  }
268  }
269 
270  VARIABLE_GROUP("Dedx");
271  //CDC variables
272  REGISTER_VARIABLE("CDCdEdx", CDCdedx, "CDC dE/dx truncated mean");
273  REGISTER_VARIABLE("CDCdEdxnosat", CDCdedxnosat,
274  "CDC dE/dx truncated mean without saturation correction (NA for current track level MC)");
275  REGISTER_VARIABLE("pCDC", pCDC, "Momentum valid in the CDC");
276  REGISTER_VARIABLE("costhCDC", costhCDC, "costheta valid in the CDC");
277  REGISTER_VARIABLE("CDCdEdx_nhits", CDCdEdx_nhits, "total hits of dedx track");
278  REGISTER_VARIABLE("CDCdEdx_lnhits", CDCdEdx_lnhits, "layer hits for dedx track");
279  REGISTER_VARIABLE("CDCdEdx_lnhitsused", CDCdEdx_lnhitsused, "truncated hits of dedx track");
280 
281  REGISTER_METAVARIABLE("CDCdEdx_PIDvars(var,PDG) var (= chi or pmean or preso) and PDG is of charged particles", CDCdEdx_PIDvars,
282  "advance CDC dEdx PID related variables for charged particle", Manager::VariableDataType::c_double);
283 
284  REGISTER_VARIABLE("CDCdEdx_chiE", CDCdEdx_chiE, "Chi value of electrons from CDC dEdx");
285  REGISTER_VARIABLE("CDCdEdx_chiMu", CDCdEdx_chiMu, "Chi value of muons from CDC dEdx");
286  REGISTER_VARIABLE("CDCdEdx_chiPi", CDCdEdx_chiPi, "Chi value of pions from CDC dEdx");
287  REGISTER_VARIABLE("CDCdEdx_chiK", CDCdEdx_chiK, "Chi value of kaons from CDC dEdx");
288  REGISTER_VARIABLE("CDCdEdx_chiP", CDCdEdx_chiP, "Chi value of protons from CDC dEdx");
289  REGISTER_VARIABLE("CDCdEdx_chiD", CDCdEdx_chiD, "Chi value of duetrons from CDC dEdx");
290 
291  //SVD variables
292  REGISTER_VARIABLE("SVDdEdx", SVDdedx, "SVD dE/dx truncated mean");
293  REGISTER_VARIABLE("pSVD", SVD_p, "momentum valid in the SVD");
294  REGISTER_VARIABLE("SVD_pTrue", SVD_pTrue, "true MC momentum valid in the SVD");
295  REGISTER_VARIABLE("SVD_CosTheta", SVD_CosTheta, "cos(theta) of the track valid in the SVD");
296  REGISTER_VARIABLE("SVD_nHits", SVD_nHits, "number of hits of the track valid in the SVD");
297 
298  }
300 }
Debug output for CDCDedxPID module.
Definition: CDCDedxTrack.h:25
static const ChargedStable muon
muon particle
Definition: Const.h:651
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
static const ChargedStable proton
proton particle
Definition: Const.h:654
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:653
static const ChargedStable electron
electron particle
Definition: Const.h:650
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:655
Class to store reconstructed particles.
Definition: Particle.h:75
Class that bundles various TrackFitResults.
Definition: Track.h:25
Debug output for VXDDedxPID module.
Definition: VXDDedxTrack.h:27
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
Definition: Manager.h:113
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
VXDDedxTrack const * getSVDDedxFromParticle(Particle const *particle)
SVD dEdx value from particle.
CDCDedxTrack const * getDedxFromParticle(Particle const *particle)
CDC dEdx value from particle.
Abstract base class for different kinds of events.