15 #include <CLHEP/Units/GlobalPhysicalConstants.h> 16 #include <CLHEP/Units/SystemOfUnits.h> 27 template <
class H,
class T>
30 const std::vector<T>& vec,
39 static constexpr char sigmat0safeName[] =
"sigmat0safe";
81 trackMTDTimeQualityToken_(
83 vtxMaxSigmaT_(iConfig.getParameter<double>(
"vtxMaxSigmaT")),
84 maxDz_(iConfig.getParameter<double>(
"maxDz")),
85 maxDtSignificance_(iConfig.getParameter<double>(
"maxDtSignificance")),
86 minProbHeavy_(iConfig.getParameter<double>(
"minProbHeavy")),
87 fixedT0Error_(iConfig.getParameter<double>(
"fixedT0Error")),
88 probPion_(iConfig.getParameter<double>(
"probPion")),
89 probKaon_(iConfig.getParameter<double>(
"probKaon")),
90 probProton_(iConfig.getParameter<double>(
"probProton")),
91 minTrackTimeQuality_(iConfig.getParameter<double>(
"minTrackTimeQuality")),
92 MVASel_(iConfig.getParameter<
bool>(
"MVASel")),
93 vertexReassignment_(iConfig.getParameter<
bool>(
"vertexReassignment")) {
94 produces<edm::ValueMap<float>>(
t0Name);
99 produces<edm::ValueMap<float>>(
probKName);
100 produces<edm::ValueMap<float>>(
probPName);
108 ->setComment(
"Input ValueMap for track time at beamline");
110 ->setComment(
"Input ValueMap for track time at MTD");
112 ->setComment(
"Input ValueMap for track time uncertainty at beamline");
114 ->setComment(
"Input ValueMap for track time uncertainty at MTD");
116 ->setComment(
"Input ValueMap for track tof as kaon");
118 ->setComment(
"Input ValueMap for track tof as proton");
120 ->setComment(
"Input ValueMap for track sigma(tof) as pion");
122 ->setComment(
"Input ValueMap for track sigma(tof) as kaon");
124 ->setComment(
"Input ValueMap for track sigma(tof) as proton");
126 ->setComment(
"Input primary vertex collection");
128 ->setComment(
"Track MVA quality value");
129 desc.add<
double>(
"vtxMaxSigmaT", 0.025)
130 ->setComment(
"Maximum primary vertex time uncertainty for use in particle id [ns]");
131 desc.add<
double>(
"maxDz", 0.1)
132 ->setComment(
"Maximum distance in z for track-primary vertex association for particle id [cm]");
133 desc.add<
double>(
"maxDtSignificance", 5.0)
135 "Maximum distance in time (normalized by uncertainty) for track-primary vertex association for particle id");
136 desc.add<
double>(
"minProbHeavy", 0.75)
137 ->setComment(
"Minimum probability for a particle to be a kaon or proton before reassigning the timestamp");
138 desc.add<
double>(
"fixedT0Error", 0.)->setComment(
"Use a fixed T0 uncertainty [ns]");
139 desc.add<
double>(
"probPion", 1.)->setComment(
"A priori probability pions");
140 desc.add<
double>(
"probKaon", 1.)->setComment(
"A priori probability kaons");
141 desc.add<
double>(
"probProton", 1.)->setComment(
"A priori probability for protons");
142 desc.add<
double>(
"minTrackTimeQuality", 0.8)->setComment(
"Minimum MVA Quality selection on tracks");
143 desc.add<
bool>(
"MVASel",
false)->setComment(
"Use MVA Quality selection");
144 desc.add<
bool>(
"vertexReassignment",
true)->setComment(
"Track-vertex reassignment");
146 descriptions.
add(
"tofPIDProducer",
desc);
149 template <
class H,
class T>
152 const std::vector<T>& vec,
154 auto out = std::make_unique<edm::ValueMap<T>>();
164 const auto&
tracks = *tracksH;
189 std::vector<float> t0OutRaw;
190 std::vector<float> sigmat0OutRaw;
191 std::vector<float> t0safeOutRaw;
192 std::vector<float> sigmat0safeOutRaw;
193 std::vector<float> probPiOutRaw;
194 std::vector<float> probKOutRaw;
195 std::vector<float> probPOutRaw;
198 for (
unsigned int itrack = 0; itrack <
tracks.size(); ++itrack) {
201 float t0 = t0In[trackref];
203 float sigmat0safe = sigmat0In[trackref];
205 float sigmat0 = sigmatmtd;
206 float sigmatofpi = sigmatofpiIn[trackref];
207 float sigmatofk = sigmatofkIn[trackref];
208 float sigmatofp = sigmatofpIn[trackref];
214 float trackMVAQual = trackMVAQualIn[trackref];
217 double rsigmazsq = 1. /
track.dzError() /
track.dzError();
218 std::array<double, 3> rsigmat = {{1. /
std::sqrt(sigmatmtd * sigmatmtd + sigmatofpi * sigmatofpi),
219 1. /
std::sqrt(sigmatmtd * sigmatmtd + sigmatofk * sigmatofk),
220 1. /
std::sqrt(sigmatmtd * sigmatmtd + sigmatofp * sigmatofp)}};
224 int vtxidxmindz = -1;
225 int vtxidxminchisq = -1;
229 for (
unsigned int ivtx = 0; ivtx < vtxs.size(); ++ivtx) {
231 float w =
vtx.trackWeight(trackref);
243 double dtsig =
dt * rsigmat[0];
244 double chisq =
dz *
dz * rsigmazsq + dtsig * dtsig;
247 vtxidxminchisq = ivtx;
256 if (vtxidxmindz >= 0 && !(vtxs[vtxidxmindz].tError() > 0. && vtxs[vtxidxmindz].tError() <
vtxMaxSigmaT_)) {
257 vtxidx = vtxidxmindz;
258 }
else if (vtxidxminchisq >= 0) {
259 vtxidx = vtxidxminchisq;
260 }
else if (vtxidxmindz >= 0) {
261 vtxidx = vtxidxmindz;
266 if (vtxidx >= 0 && vtxs[vtxidx].tError() > 0. && vtxs[vtxidx].tError() <
vtxMaxSigmaT_) {
271 double dtsignom = dtnom * rsigmat[0];
272 double chisqnom = dznom * dznom * rsigmazsq + dtsignom * dtsignom;
279 sigmat0safe = 1. / rsigmat[0];
280 sigmat0 = sigmat0safe;
283 double tmtd = tmtdIn[trackref];
284 double t0_k = tmtd - tofkIn[trackref];
285 double t0_p = tmtd - tofpIn[trackref];
287 double chisqmin = chisqnom;
289 double chisqmin_pi = chisqnom;
293 for (
unsigned int ivtx = 0; ivtx < vtxs.size(); ++ivtx) {
296 if (ivtx != (
unsigned int)vtxidx)
308 double chisqdz =
dz *
dz * rsigmazsq;
311 double dtsig_k = dt_k * rsigmat[1];
312 double chisq_k = chisqdz + dtsig_k * dtsig_k;
315 chisqmin_k = chisq_k;
319 double dtsig_p = dt_p * rsigmat[2];
320 double chisq_p = chisqdz + dtsig_p * dtsig_p;
323 chisqmin_p = chisq_p;
330 sigmat0safe = 1. / rsigmat[1];
331 sigmat0 = sigmat0safe;
337 sigmat0safe = 1. / rsigmat[2];
338 sigmat0 = sigmat0safe;
344 double rawprob_pi =
probPion_ *
exp(-0.5 * chisqmin_pi);
348 double normprob = 1. / (rawprob_pi + rawprob_k + rawprob_p);
350 prob_pi = rawprob_pi * normprob;
351 prob_k = rawprob_k * normprob;
352 prob_p = rawprob_p * normprob;
354 double prob_heavy = 1. - prob_pi;
362 t0OutRaw.push_back(
t0);
363 sigmat0OutRaw.push_back(sigmat0);
364 t0safeOutRaw.push_back(t0safe);
365 sigmat0safeOutRaw.push_back(sigmat0safe);
366 probPiOutRaw.push_back(prob_pi);
367 probKOutRaw.push_back(prob_k);
368 probPOutRaw.push_back(prob_p);
edm::EDGetTokenT< reco::VertexCollection > vtxsToken_
const Point & position() const
position
edm::EDGetTokenT< edm::ValueMap< float > > sigmat0Token_
std::vector< Track > TrackCollection
collection of Tracks
const double minProbHeavy_
std::vector< Vertex > VertexCollection
const double fixedT0Error_
edm::EDGetTokenT< edm::ValueMap< float > > tofkToken_
static constexpr char t0Name[]
TOFPIDProducer(const ParameterSet &pset)
void produce(edm::Event &ev, const edm::EventSetup &es) final
static constexpr char t0safeName[]
edm::EDGetTokenT< edm::ValueMap< float > > trackMTDTimeQualityToken_
const double vtxMaxSigmaT_
static constexpr char sigmat0safeName[]
Abs< T >::type abs(const T &t)
void fillValueMap(edm::Event &iEvent, const edm::Handle< H > &handle, const std::vector< T > &vec, const std::string &name) const
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< edm::ValueMap< float > > sigmatofpToken_
edm::EDGetTokenT< edm::ValueMap< float > > tmtdToken_
edm::EDGetTokenT< edm::ValueMap< float > > tofpToken_
edm::EDGetTokenT< edm::ValueMap< float > > sigmatofpiToken_
const bool vertexReassignment_
static constexpr char sigmat0Name[]
static constexpr char probKName[]
static constexpr char probPName[]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const double minTrackTimeQuality_
double t() const
t coordinate
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< edm::ValueMap< float > > t0Token_
edm::EDGetTokenT< edm::ValueMap< float > > sigmatofkToken_
edm::EDGetTokenT< edm::ValueMap< float > > sigmatmtdToken_
const double maxDtSignificance_
static constexpr char probPiName[]
edm::EDGetTokenT< reco::TrackCollection > tracksToken_