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 <cdc/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 <cdc/dataobjects/CDCDedxTrack.h>
22
23#include <TString.h>
24
25namespace Belle2 {
30
35 {
36 const Track* track = particle->getTrack();
37 if (!track) {
38 return nullptr;
39 }
40
41 const CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
42 if (!dedxTrack) {
43 return nullptr;
44 }
45
46 return dedxTrack;
47 }
48
49 namespace Variable {
50
51 double CDCdedx(const Particle* part)
52 {
53 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
54 if (!dedxTrack) {
55 return -999.0;
56 } else {
57 return dedxTrack->getDedx();
58 }
59 }
60
61 double CDCdedxnosat(const Particle* part)
62 {
63 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
64 if (!dedxTrack) {
65 return -999.0;
66 } else {
67 return dedxTrack->getDedxNoSat();
68 }
69 }
70
71 double pCDC(const Particle* part)
72 {
73 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
74 if (!dedxTrack) {
75 return -999.0;
76 } else {
77 return dedxTrack->getMomentum();
78 }
79 }
80
81 double costhCDC(const Particle* part)
82 {
83 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
84 if (!dedxTrack) {
85 return -999.0;
86 } else {
87 return dedxTrack->getCosTheta();
88 }
89 }
90
91
92 double CDCdEdx_nhits(const Particle* part)
93 {
94 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
95 if (!dedxTrack) {
96 return -999.0;
97 } else {
98 return dedxTrack->size();
99 }
100 }
101
102 double CDCdEdx_lnhits(const Particle* part)
103 {
104 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
105 if (!dedxTrack) {
106 return -999.0;
107 } else {
108 return dedxTrack->getNLayerHits();
109 }
110 }
111
112 double CDCdEdx_lnhitsused(const Particle* part)
113 {
114 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
115 if (!dedxTrack) {
116 return -999.0;
117 } else {
118 return dedxTrack->getNLayerHitsUsed();
119 }
120 }
121
122 Manager::FunctionPtr CDCdEdx_PIDvars(const std::vector<std::string>& arguments)
123 {
124 if (arguments.size() < 2) {
125 B2ERROR("Min two arguments required to get variables related chi, predicted mean and reso");
126 return nullptr;
127 }
128
129 TString var = "";
130 try {
131 var = arguments[0];
132 } catch (std::invalid_argument& e) {
133 B2ERROR("First argument of variable must be a variable name (chi or pmean or preso)");
134 return nullptr;
135 }
136
137 int pdgCode;
138 try {
139 pdgCode = Belle2::convertString<int>(arguments[1]);
140 } catch (std::invalid_argument& e) {
141 B2ERROR("Second argument of variable must be a PDG code");
142 return nullptr;
143 }
144
145 int index = -999;
146 if (abs(pdgCode) == Const::electron.getPDGCode())index = 0;
147 else if (abs(pdgCode) == Const::muon.getPDGCode())index = 1;
148 else if (abs(pdgCode) == Const::pion.getPDGCode())index = 2;
149 else if (abs(pdgCode) == Const::kaon.getPDGCode())index = 3;
150 else if (abs(pdgCode) == Const::proton.getPDGCode())index = 4;
151 else if (abs(pdgCode) == Const::deuteron.getPDGCode())index = 5;
152
153 auto func = [index, var](const Particle * part) -> double {
154 const CDCDedxTrack* dedxTrack = getDedxFromParticle(part);
155 if (!dedxTrack)
156 {
157 return std::numeric_limits<float>::quiet_NaN();
158 } else
159 {
160 if (var == "chi") return dedxTrack->getChi(index);
161 else if (var == "pmean") return dedxTrack->getPmean(index);
162 else if (var == "preso") return dedxTrack->getPreso(index);
163 else return std::numeric_limits<float>::quiet_NaN();
164 }
165 };
166 return func;
167 }
168
169 double CDCdEdx_chiE(const Particle* part)
170 {
171 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "11"});
172 return std::get<double>(pidFunction(part));
173 }
174
175 double CDCdEdx_chiMu(const Particle* part)
176 {
177 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "13"});
178 return std::get<double>(pidFunction(part));
179 }
180
181 double CDCdEdx_chiPi(const Particle* part)
182 {
183 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "211"});
184 return std::get<double>(pidFunction(part));
185 }
186
187 double CDCdEdx_chiK(const Particle* part)
188 {
189 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "321"});
190 return std::get<double>(pidFunction(part));
191 }
192
193 double CDCdEdx_chiP(const Particle* part)
194 {
195 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "2212"});
196 return std::get<double>(pidFunction(part));
197 }
198
199 double CDCdEdx_chiD(const Particle* part)
200 {
201 static Manager::FunctionPtr pidFunction = CDCdEdx_PIDvars({"chi", "1000010020"});
202 return std::get<double>(pidFunction(part));
203 }
204
205 VARIABLE_GROUP("CDC dEdx");
206
207 REGISTER_VARIABLE("CDCdEdx", CDCdedx, "CDC dE/dx truncated mean");
208 REGISTER_VARIABLE("CDCdEdxnosat", CDCdedxnosat,
209 "CDC dE/dx truncated mean without saturation correction (NA for current track level MC)");
210 REGISTER_VARIABLE("pCDC", pCDC, "Momentum valid in the CDC");
211 REGISTER_VARIABLE("costhCDC", costhCDC, "costheta valid in the CDC");
212 REGISTER_VARIABLE("CDCdEdx_nhits", CDCdEdx_nhits, "total hits of dedx track");
213 REGISTER_VARIABLE("CDCdEdx_lnhits", CDCdEdx_lnhits, "layer hits for dedx track");
214 REGISTER_VARIABLE("CDCdEdx_lnhitsused", CDCdEdx_lnhitsused, "truncated hits of dedx track");
215
216 REGISTER_METAVARIABLE("CDCdEdx_PIDvars(var,PDG) var (= chi or pmean or preso) and PDG is of charged particles", CDCdEdx_PIDvars,
217 "advance CDC dEdx PID related variables for charged particle", Manager::VariableDataType::c_double);
218
219 REGISTER_VARIABLE("CDCdEdx_chiE", CDCdEdx_chiE, "Chi value of electrons from CDC dEdx");
220 REGISTER_VARIABLE("CDCdEdx_chiMu", CDCdEdx_chiMu, "Chi value of muons from CDC dEdx");
221 REGISTER_VARIABLE("CDCdEdx_chiPi", CDCdEdx_chiPi, "Chi value of pions from CDC dEdx");
222 REGISTER_VARIABLE("CDCdEdx_chiK", CDCdEdx_chiK, "Chi value of kaons from CDC dEdx");
223 REGISTER_VARIABLE("CDCdEdx_chiP", CDCdEdx_chiP, "Chi value of protons from CDC dEdx");
224 REGISTER_VARIABLE("CDCdEdx_chiD", CDCdEdx_chiD, "Chi value of duetrons from CDC dEdx");
225 }
227}
Debug output for CDCDedxPID module.
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:76
Class that bundles various TrackFitResults.
Definition Track.h:25
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
Definition Manager.h:112
CDCDedxTrack const * getDedxFromParticle(Particle const *particle)
CDC dEdx value from particle.
T convertString(const std::string &str)
Converts a string to type T (one of float, double, long double, int, long int, unsigned long int).
Abstract base class for different kinds of events.