15 #include "CLHEP/Units/GlobalPhysicalConstants.h" 16 #include "CLHEP/Units/GlobalSystemOfUnits.h" 27 template <
class H,
class T>
30 const std::vector<T>& vec,
36 static constexpr
char t0Name[] =
"t0";
37 static constexpr
char sigmat0Name[] =
"sigmat0";
38 static constexpr
char t0safeName[] =
"t0safe";
39 static constexpr
char sigmat0safeName[] =
"sigmat0safe";
40 static constexpr
char probPiName[] =
"probPi";
41 static constexpr
char probKName[] =
"probK";
42 static constexpr
char probPName[] =
"probP";
68 vtxMaxSigmaT_(iConfig.getParameter<double>(
"vtxMaxSigmaT")),
69 maxDz_(iConfig.getParameter<double>(
"maxDz")),
70 maxDtSignificance_(iConfig.getParameter<double>(
"maxDtSignificance")),
71 minProbHeavy_(iConfig.getParameter<double>(
"minProbHeavy")),
72 fixedT0Error_(iConfig.getParameter<double>(
"fixedT0Error")) {
73 produces<edm::ValueMap<float>>(
t0Name);
78 produces<edm::ValueMap<float>>(
probKName);
79 produces<edm::ValueMap<float>>(
probPName);
87 ->setComment(
"Input ValueMap for track time at beamline");
89 ->setComment(
"Input ValueMap for track time at MTD");
91 ->setComment(
"Input ValueMap for track time uncertainty at beamline");
93 ->setComment(
"Input ValueMap for track time uncertainty at MTD");
95 ->setComment(
"Input ValueMap for track tof as kaon");
97 ->setComment(
"Input ValueMap for track tof as proton");
99 ->setComment(
"Input primary vertex collection");
100 desc.add<
double>(
"vtxMaxSigmaT", 0.025)
101 ->setComment(
"Maximum primary vertex time uncertainty for use in particle id [ns]");
102 desc.add<
double>(
"maxDz", 0.1)
103 ->setComment(
"Maximum distance in z for track-primary vertex association for particle id [cm]");
104 desc.add<
double>(
"maxDtSignificance", 5.0)
106 "Maximum distance in time (normalized by uncertainty) for track-primary vertex association for particle id");
107 desc.add<
double>(
"minProbHeavy", 0.75)
108 ->setComment(
"Minimum probability for a particle to be a kaon or proton before reassigning the timestamp");
109 desc.add<
double>(
"fixedT0Error", 0.)->setComment(
"Use a fixed T0 uncertainty [ns]");
111 descriptions.
add(
"tofPIDProducer",
desc);
114 template <
class H,
class T>
117 const std::vector<T>& vec,
119 auto out = std::make_unique<edm::ValueMap<T>>();
129 const auto&
tracks = *tracksH;
146 std::vector<float> t0OutRaw;
147 std::vector<float> sigmat0OutRaw;
148 std::vector<float> t0safeOutRaw;
149 std::vector<float> sigmat0safeOutRaw;
150 std::vector<float> probPiOutRaw;
151 std::vector<float> probKOutRaw;
152 std::vector<float> probPOutRaw;
155 for (
unsigned int itrack = 0; itrack <
tracks.size(); ++itrack) {
158 float t0 = t0In[trackref];
160 float sigmat0safe = sigmat0In[trackref];
162 float sigmat0 = sigmatmtd;
169 double rsigmazsq = 1. /
track.dzError() /
track.dzError();
170 double rsigmat = 1. / sigmatmtd;
174 int vtxidxmindz = -1;
175 int vtxidxminchisq = -1;
179 for (
unsigned int ivtx = 0; ivtx < vtxs.size(); ++ivtx) {
181 float w =
vtx.trackWeight(trackref);
193 double dtsig =
dt * rsigmat;
194 double chisq =
dz *
dz * rsigmazsq + dtsig * dtsig;
197 vtxidxminchisq = ivtx;
206 if (vtxidxmindz >= 0 && !(vtxs[vtxidxmindz].tError() > 0. && vtxs[vtxidxmindz].tError() <
vtxMaxSigmaT_)) {
207 vtxidx = vtxidxmindz;
208 }
else if (vtxidxminchisq >= 0) {
209 vtxidx = vtxidxminchisq;
210 }
else if (vtxidxmindz >= 0) {
211 vtxidx = vtxidxmindz;
216 if (vtxidx >= 0 && vtxs[vtxidx].tError() > 0. && vtxs[vtxidx].tError() <
vtxMaxSigmaT_) {
221 double dtsignom = dtnom * rsigmat;
222 double chisqnom = dznom * dznom * rsigmazsq + dtsignom * dtsignom;
229 sigmat0safe = sigmatmtd;
232 double tmtd = tmtdIn[trackref];
233 double t0_k = tmtd - tofkIn[trackref];
234 double t0_p = tmtd - tofpIn[trackref];
236 double chisqmin = chisqnom;
238 double chisqmin_pi = chisqnom;
252 double chisqdz =
dz *
dz * rsigmazsq;
255 double dtsig_k = dt_k * rsigmat;
256 double chisq_k = chisqdz + dtsig_k * dtsig_k;
259 chisqmin_k = chisq_k;
263 double dtsig_p = dt_p * rsigmat;
264 double chisq_p = chisqdz + dtsig_p * dtsig_p;
267 chisqmin_p = chisq_p;
274 sigmat0safe = sigmatmtd;
280 sigmat0safe = sigmatmtd;
286 double rawprob_pi =
exp(-0.5 * chisqmin_pi);
287 double rawprob_k =
exp(-0.5 * chisqmin_k);
288 double rawprob_p =
exp(-0.5 * chisqmin_p);
290 double normprob = 1. / (rawprob_pi + rawprob_k + rawprob_p);
292 prob_pi = rawprob_pi * normprob;
293 prob_k = rawprob_k * normprob;
294 prob_p = rawprob_p * normprob;
296 double prob_heavy = 1. - prob_pi;
304 t0OutRaw.push_back(
t0);
305 sigmat0OutRaw.push_back(sigmat0);
306 t0safeOutRaw.push_back(t0safe);
307 sigmat0safeOutRaw.push_back(sigmat0safe);
308 probPiOutRaw.push_back(prob_pi);
309 probKOutRaw.push_back(prob_k);
310 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
std::vector< Vertex > VertexCollection
double maxDtSignificance_
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[]
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_
static constexpr char sigmat0Name[]
static constexpr char probKName[]
static constexpr char probPName[]
auto const & tracks
cannot be loose
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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_
static constexpr char probPiName[]
edm::EDGetTokenT< reco::TrackCollection > tracksToken_