15 #include "CLHEP/Units/GlobalPhysicalConstants.h" 16 #include "CLHEP/Units/GlobalSystemOfUnits.h" 28 template <
class H,
class T>
37 static constexpr char sigmat0safeName[] =
"sigmat0safe";
67 vtxMaxSigmaT_(iConfig.getParameter<double>(
"vtxMaxSigmaT")),
68 maxDz_(iConfig.getParameter<double>(
"maxDz")),
69 maxDtSignificance_(iConfig.getParameter<double>(
"maxDtSignificance")),
70 minProbHeavy_(iConfig.getParameter<double>(
"minProbHeavy"))
72 produces<edm::ValueMap<float> >(
t0Name);
77 produces<edm::ValueMap<float> >(
probKName);
78 produces<edm::ValueMap<float> >(
probPName);
85 setComment(
"Input tracks collection");
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 path lengh from beamline to MTD");
97 setComment(
"Input ValueMap for track momentum magnitude (normally from refit with MTD hits)");
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)->
105 setComment(
"Maximum distance in time (normalized by uncertainty) for track-primary vertex association for particle id");
106 desc.
add<
double>(
"minProbHeavy", 0.75)->
107 setComment(
"Minimum probability for a particle to be a kaon or proton before reassigning the timestamp");
109 descriptions.
add(
"tofPIDProducer", desc);
112 template <
class H,
class T>
114 auto out = std::make_unique<edm::ValueMap<T>>();
116 filler.insert(handle, vec.begin(), vec.end());
124 constexpr double c_cm_ns = CLHEP::c_light*CLHEP::ns/CLHEP::cm;
129 const auto&
tracks = *tracksH;
133 const auto &t0In = *t0H;
137 const auto &tmtdIn = *tmtdH;
141 const auto &sigmat0In = *sigmat0H;
145 const auto &sigmatmtdIn = *sigmatmtdH;
149 const auto &pathLengthIn = *pathLengthH;
153 const auto &pIn = *pH;
157 const auto& vtxs = *vtxsH;
160 std::vector<float> t0OutRaw;
161 std::vector<float> sigmat0OutRaw;
162 std::vector<float> t0safeOutRaw;
163 std::vector<float> sigmat0safeOutRaw;
164 std::vector<float> probPiOutRaw;
165 std::vector<float> probKOutRaw;
166 std::vector<float> probPOutRaw;
169 for (
unsigned int itrack = 0; itrack<
tracks.size(); ++itrack) {
172 float t0 = t0In[trackref];
174 float sigmat0safe = sigmat0In[trackref];
175 float sigmatmtd = sigmatmtdIn[trackref];
176 float sigmat0 = sigmatmtd;
185 double rsigmat = 1./sigmatmtd;
189 int vtxidxmindz = -1;
190 int vtxidxminchisq = -1;
194 for (
unsigned int ivtx = 0; ivtx<vtxs.size(); ++ivtx) {
208 double dtsig = dt*rsigmat;
209 double chisq = dz*dz*rsigmazsq + dtsig*dtsig;
212 vtxidxminchisq = ivtx;
221 if (vtxidxmindz>=0 && !(vtxs[vtxidxmindz].tError()>0. && vtxs[vtxidxmindz].tError()<
vtxMaxSigmaT_)) {
222 vtxidx = vtxidxmindz;
224 else if (vtxidxminchisq>=0) {
225 vtxidx = vtxidxminchisq;
227 else if (vtxidxmindz>=0) {
228 vtxidx = vtxidxmindz;
233 if (vtxidx>=0 && vtxs[vtxidx].tError()>0. && vtxs[vtxidx].tError()<
vtxMaxSigmaT_) {
237 double dtnom =
std::abs(t0 - vtxnom.
t());
238 double dtsignom = dtnom*rsigmat;
239 double chisqnom = dznom*dznom*rsigmazsq + dtsignom*dtsignom;
246 sigmat0safe = sigmatmtd;
249 double tmtd = tmtdIn[trackref];
250 double pathlength = pathLengthIn[trackref];
251 double magp = pIn[trackref];
253 double gammasq_k = 1. + magp*magp/m_k/m_k;
254 double beta_k =
std::sqrt(1.-1./gammasq_k);
255 double t0_k = tmtd - pathlength/beta_k*c_inv;
257 double gammasq_p = 1. + magp*magp/m_p/m_p;
258 double beta_p =
std::sqrt(1.-1./gammasq_p);
259 double t0_p = tmtd - pathlength/beta_p*c_inv;
261 double chisqmin = chisqnom;
263 double chisqmin_pi = chisqnom;
277 double chisqdz = dz*dz*rsigmazsq;
280 double dtsig_k = dt_k*rsigmat;
281 double chisq_k = chisqdz + dtsig_k*dtsig_k;
284 chisqmin_k = chisq_k;
288 double dtsig_p = dt_p*rsigmat;
289 double chisq_p = chisqdz + dtsig_p*dtsig_p;
292 chisqmin_p = chisq_p;
299 sigmat0safe = sigmatmtd;
305 sigmat0safe = sigmatmtd;
312 double rawprob_pi =
exp(-0.5*chisqmin_pi);
313 double rawprob_k =
exp(-0.5*chisqmin_k);
314 double rawprob_p =
exp(-0.5*chisqmin_p);
316 double normprob = 1./(rawprob_pi + rawprob_k + rawprob_p);
318 prob_pi = rawprob_pi*normprob;
319 prob_k = rawprob_k*normprob;
320 prob_p = rawprob_p*normprob;
322 double prob_heavy = 1.-prob_pi;
332 t0OutRaw.push_back(t0);
333 sigmat0OutRaw.push_back(sigmat0);
334 t0safeOutRaw.push_back(t0safe);
335 sigmat0safeOutRaw.push_back(sigmat0safe);
336 probPiOutRaw.push_back(prob_pi);
337 probKOutRaw.push_back(prob_k);
338 probPOutRaw.push_back(prob_p);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< reco::VertexCollection > vtxsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< edm::ValueMap< float > > sigmat0Token_
std::vector< Track > TrackCollection
collection of Tracks
std::vector< Vertex > VertexCollection
collection of Vertex objects
edm::EDGetTokenT< edm::ValueMap< float > > pathLengthToken_
const Point & position() const
position
double maxDtSignificance_
TOFPIDProducer(const ParameterSet &pset)
void produce(edm::Event &ev, const edm::EventSetup &es) final
#define DEFINE_FWK_MODULE(type)
Abs< T >::type abs(const T &t)
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
edm::EDGetTokenT< edm::ValueMap< float > > tmtdToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static char sigmat0safeName[]
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
double dzError() const
error on dz
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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_
edm::EDGetTokenT< edm::ValueMap< float > > pToken_
static char sigmat0Name[]
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
void fillValueMap(edm::Event &iEvent, const edm::Handle< H > &handle, const std::vector< T > &vec, const std::string &name) const
double tError() const
error on t
double t() const
t coordinate