Belle II Software development
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
28namespace Belle2 {
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 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "11"});
193 return std::get<double>(pidFunction(part));
194 }
195
196 double CDCdEdx_chiMu(const Particle* part)
197 {
198 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "13"});
199 return std::get<double>(pidFunction(part));
200 }
201
202 double CDCdEdx_chiPi(const Particle* part)
203 {
204 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "211"});
205 return std::get<double>(pidFunction(part));
206 }
207
208 double CDCdEdx_chiK(const Particle* part)
209 {
210 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "321"});
211 return std::get<double>(pidFunction(part));
212 }
213
214 double CDCdEdx_chiP(const Particle* part)
215 {
216 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "2212"});
217 return std::get<double>(pidFunction(part));
218 }
219
220 double CDCdEdx_chiD(const Particle* part)
221 {
222 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "1000010020"});
223 return std::get<double>(pidFunction(part));
224 }
225
226//Variables for SVD dedx
227 double SVD_p(const Particle* part)
228 {
229 const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
230 if (!dedxTrack) {
231 return -999.0;
232 } else {
233 return dedxTrack->getMomentum();
234 }
235 }
236
237 double SVD_pTrue(const Particle* part)
238 {
239 const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
240 if (!dedxTrack) {
241 return -999.0;
242 } else {
243 return dedxTrack->getTrueMomentum();
244 }
245 }
246
247 double SVDdedx(const Particle* part)
248 {
249 const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
250 if (!dedxTrack) {
251 return -999.0;
252 } else {
253 return dedxTrack->getDedx(Const::EDetector::SVD);
254 }
255 }
256
257 double SVD_CosTheta(const Particle* part)
258 {
259 const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
260 if (!dedxTrack) {
261 return -999.0;
262 } else {
263 return dedxTrack->getCosTheta();
264 }
265 }
266 double SVD_nHits(const Particle* part)
267 {
268 const VXDDedxTrack* dedxTrack = getSVDDedxFromParticle(part);
269 if (!dedxTrack) {
270 return -999.0;
271 } else {
272 return dedxTrack->size();
273 }
274 }
275
276 VARIABLE_GROUP("Dedx");
277 //CDC variables
278 REGISTER_VARIABLE("CDCdEdx", CDCdedx, "CDC dE/dx truncated mean");
279 REGISTER_VARIABLE("CDCdEdxnosat", CDCdedxnosat,
280 "CDC dE/dx truncated mean without saturation correction (NA for current track level MC)");
281 REGISTER_VARIABLE("pCDC", pCDC, "Momentum valid in the CDC");
282 REGISTER_VARIABLE("costhCDC", costhCDC, "costheta valid in the CDC");
283 REGISTER_VARIABLE("CDCdEdx_nhits", CDCdEdx_nhits, "total hits of dedx track");
284 REGISTER_VARIABLE("CDCdEdx_lnhits", CDCdEdx_lnhits, "layer hits for dedx track");
285 REGISTER_VARIABLE("CDCdEdx_lnhitsused", CDCdEdx_lnhitsused, "truncated hits of dedx track");
286
287 REGISTER_METAVARIABLE("CDCdEdx_PIDvars(var,PDG) var (= chi or pmean or preso) and PDG is of charged particles", CDCdEdx_PIDvars,
288 "advance CDC dEdx PID related variables for charged particle", Manager::VariableDataType::c_double);
289
290 REGISTER_VARIABLE("CDCdEdx_chiE", CDCdEdx_chiE, "Chi value of electrons from CDC dEdx");
291 REGISTER_VARIABLE("CDCdEdx_chiMu", CDCdEdx_chiMu, "Chi value of muons from CDC dEdx");
292 REGISTER_VARIABLE("CDCdEdx_chiPi", CDCdEdx_chiPi, "Chi value of pions from CDC dEdx");
293 REGISTER_VARIABLE("CDCdEdx_chiK", CDCdEdx_chiK, "Chi value of kaons from CDC dEdx");
294 REGISTER_VARIABLE("CDCdEdx_chiP", CDCdEdx_chiP, "Chi value of protons from CDC dEdx");
295 REGISTER_VARIABLE("CDCdEdx_chiD", CDCdEdx_chiD, "Chi value of duetrons from CDC dEdx");
296
297 //SVD variables
298 REGISTER_VARIABLE("SVDdEdx", SVDdedx, "SVD dE/dx truncated mean");
299 REGISTER_VARIABLE("pSVD", SVD_p, "momentum valid in the SVD");
300 REGISTER_VARIABLE("SVD_pTrue", SVD_pTrue, "true MC momentum valid in the SVD");
301 REGISTER_VARIABLE("SVD_CosTheta", SVD_CosTheta, "cos(theta) of the track valid in the SVD");
302 REGISTER_VARIABLE("SVD_nHits", SVD_nHits, "number of hits of the track valid in the SVD");
303
304 }
306}
Debug output for CDCDedxPID module.
Definition: CDCDedxTrack.h:25
static const ChargedStable muon
muon particle
Definition: Const.h:660
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
static const ChargedStable proton
proton particle
Definition: Const.h:663
static const ChargedStable kaon
charged kaon particle
Definition: Const.h:662
static const ChargedStable electron
electron particle
Definition: Const.h:659
static const ChargedStable deuteron
deuteron particle
Definition: Const.h:664
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
CDCDedxTrack const * getDedxFromParticle(Particle const *particle)
CDC dEdx value from particle.
VXDDedxTrack const * getSVDDedxFromParticle(Particle const *particle)
SVD dEdx value from particle.
Abstract base class for different kinds of events.