15 #include "CLHEP/Units/GlobalPhysicalConstants.h" 16 #include "CLHEP/Units/GlobalSystemOfUnits.h" 27 template <
class H,
class T>
30 const std::vector<T>& vec,
39 static constexpr char sigmat0safeName[] =
"sigmat0safe";
75 trackMTDTimeQualityToken_(
77 vtxMaxSigmaT_(iConfig.getParameter<double>(
"vtxMaxSigmaT")),
78 maxDz_(iConfig.getParameter<double>(
"maxDz")),
79 maxDtSignificance_(iConfig.getParameter<double>(
"maxDtSignificance")),
80 minProbHeavy_(iConfig.getParameter<double>(
"minProbHeavy")),
81 fixedT0Error_(iConfig.getParameter<double>(
"fixedT0Error")),
82 probPion_(iConfig.getParameter<double>(
"probPion")),
83 probKaon_(iConfig.getParameter<double>(
"probKaon")),
84 probProton_(iConfig.getParameter<double>(
"probProton")),
85 minTrackTimeQuality_(iConfig.getParameter<double>(
"minTrackTimeQuality")),
86 MVASel_(iConfig.getParameter<
bool>(
"MVASel")),
87 vertexReassignment_(iConfig.getParameter<
bool>(
"vertexReassignment")) {
88 produces<edm::ValueMap<float>>(
t0Name);
93 produces<edm::ValueMap<float>>(
probKName);
94 produces<edm::ValueMap<float>>(
probPName);
102 ->setComment(
"Input ValueMap for track time at beamline");
104 ->setComment(
"Input ValueMap for track time at MTD");
106 ->setComment(
"Input ValueMap for track time uncertainty at beamline");
108 ->setComment(
"Input ValueMap for track time uncertainty at MTD");
110 ->setComment(
"Input ValueMap for track tof as kaon");
112 ->setComment(
"Input ValueMap for track tof as proton");
114 ->setComment(
"Input primary vertex collection");
116 ->setComment(
"Track MVA quality value");
117 desc.add<
double>(
"vtxMaxSigmaT", 0.025)
118 ->setComment(
"Maximum primary vertex time uncertainty for use in particle id [ns]");
119 desc.add<
double>(
"maxDz", 0.1)
120 ->setComment(
"Maximum distance in z for track-primary vertex association for particle id [cm]");
121 desc.add<
double>(
"maxDtSignificance", 5.0)
123 "Maximum distance in time (normalized by uncertainty) for track-primary vertex association for particle id");
124 desc.add<
double>(
"minProbHeavy", 0.75)
125 ->setComment(
"Minimum probability for a particle to be a kaon or proton before reassigning the timestamp");
126 desc.add<
double>(
"fixedT0Error", 0.)->setComment(
"Use a fixed T0 uncertainty [ns]");
127 desc.add<
double>(
"probPion", 1.)->setComment(
"A priori probability pions");
128 desc.add<
double>(
"probKaon", 1.)->setComment(
"A priori probability kaons");
129 desc.add<
double>(
"probProton", 1.)->setComment(
"A priori probability for protons");
130 desc.add<
double>(
"minTrackTimeQuality", 0.8)->setComment(
"Minimum MVA Quality selection on tracks");
131 desc.add<
bool>(
"MVASel",
false)->setComment(
"Use MVA Quality selection");
132 desc.add<
bool>(
"vertexReassignment",
true)->setComment(
"Track-vertex reassignment");
134 descriptions.
add(
"tofPIDProducer",
desc);
137 template <
class H,
class T>
140 const std::vector<T>& vec,
142 auto out = std::make_unique<edm::ValueMap<T>>();
152 const auto&
tracks = *tracksH;
171 std::vector<float> t0OutRaw;
172 std::vector<float> sigmat0OutRaw;
173 std::vector<float> t0safeOutRaw;
174 std::vector<float> sigmat0safeOutRaw;
175 std::vector<float> probPiOutRaw;
176 std::vector<float> probKOutRaw;
177 std::vector<float> probPOutRaw;
180 for (
unsigned int itrack = 0; itrack <
tracks.size(); ++itrack) {
183 float t0 = t0In[trackref];
185 float sigmat0safe = sigmat0In[trackref];
187 float sigmat0 = sigmatmtd;
193 float trackMVAQual = trackMVAQualIn[trackref];
196 double rsigmazsq = 1. /
track.dzError() /
track.dzError();
197 double rsigmat = 1. / sigmatmtd;
201 int vtxidxmindz = -1;
202 int vtxidxminchisq = -1;
206 for (
unsigned int ivtx = 0; ivtx < vtxs.size(); ++ivtx) {
208 float w =
vtx.trackWeight(trackref);
220 double dtsig =
dt * rsigmat;
221 double chisq =
dz *
dz * rsigmazsq + dtsig * dtsig;
224 vtxidxminchisq = ivtx;
233 if (vtxidxmindz >= 0 && !(vtxs[vtxidxmindz].tError() > 0. && vtxs[vtxidxmindz].tError() <
vtxMaxSigmaT_)) {
234 vtxidx = vtxidxmindz;
235 }
else if (vtxidxminchisq >= 0) {
236 vtxidx = vtxidxminchisq;
237 }
else if (vtxidxmindz >= 0) {
238 vtxidx = vtxidxmindz;
243 if (vtxidx >= 0 && vtxs[vtxidx].tError() > 0. && vtxs[vtxidx].tError() <
vtxMaxSigmaT_) {
248 double dtsignom = dtnom * rsigmat;
249 double chisqnom = dznom * dznom * rsigmazsq + dtsignom * dtsignom;
256 sigmat0safe = sigmatmtd;
259 double tmtd = tmtdIn[trackref];
260 double t0_k = tmtd - tofkIn[trackref];
261 double t0_p = tmtd - tofpIn[trackref];
263 double chisqmin = chisqnom;
265 double chisqmin_pi = chisqnom;
269 for (
unsigned int ivtx = 0; ivtx < vtxs.size(); ++ivtx) {
272 if (ivtx != (
unsigned int)vtxidx)
284 double chisqdz =
dz *
dz * rsigmazsq;
287 double dtsig_k = dt_k * rsigmat;
288 double chisq_k = chisqdz + dtsig_k * dtsig_k;
291 chisqmin_k = chisq_k;
295 double dtsig_p = dt_p * rsigmat;
296 double chisq_p = chisqdz + dtsig_p * dtsig_p;
299 chisqmin_p = chisq_p;
306 sigmat0safe = sigmatmtd;
312 sigmat0safe = sigmatmtd;
318 double rawprob_pi =
probPion_ *
exp(-0.5 * chisqmin_pi);
322 double normprob = 1. / (rawprob_pi + rawprob_k + rawprob_p);
324 prob_pi = rawprob_pi * normprob;
325 prob_k = rawprob_k * normprob;
326 prob_p = rawprob_p * normprob;
328 double prob_heavy = 1. - prob_pi;
336 t0OutRaw.push_back(
t0);
337 sigmat0OutRaw.push_back(sigmat0);
338 t0safeOutRaw.push_back(t0safe);
339 sigmat0safeOutRaw.push_back(sigmat0safe);
340 probPiOutRaw.push_back(prob_pi);
341 probKOutRaw.push_back(prob_k);
342 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 > > tmtdToken_
edm::EDGetTokenT< edm::ValueMap< float > > tofpToken_
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 > > sigmatmtdToken_
const double maxDtSignificance_
static constexpr char probPiName[]
edm::EDGetTokenT< reco::TrackCollection > tracksToken_