8 #include <Math/DistFunc.h> 22 useVertices_(
cfg.getParameter<
bool>(
"useVertices")),
23 useVtxError_(
cfg.getParameter<
bool>(
"useVtxError"))
29 edm::LogWarning(
"MultiTRackSelector") <<
"you are executing buggy code, if intentional please help to fix it";
35 if (
cfg.exists(
"useAnyMVA"))
39 if (
cfg.exists(
"GBRForestFileName")) {
44 std::vector<edm::ParameterSet> trkSelectors(
cfg.getParameter<std::vector<edm::ParameterSet>>(
"trackSelectors"));
48 res_par_.reserve(trkSelectors.size());
51 d0_par1_.reserve(trkSelectors.size());
52 dz_par1_.reserve(trkSelectors.size());
53 d0_par2_.reserve(trkSelectors.size());
54 dz_par2_.reserve(trkSelectors.size());
56 max_d0_.reserve(trkSelectors.size());
57 max_z0_.reserve(trkSelectors.size());
58 nSigmaZ_.reserve(trkSelectors.size());
71 min_eta_.reserve(trkSelectors.size());
72 max_eta_.reserve(trkSelectors.size());
73 useMVA_.reserve(trkSelectors.size());
76 min_MVA_.reserve(trkSelectors.size());
77 mvaType_.reserve(trkSelectors.size());
79 forest_.reserve(trkSelectors.size());
81 produces<edm::ValueMap<float>>(
"MVAVals");
84 produces<MVACollection>(
"MVAValues");
86 for (
unsigned int i = 0;
i < trkSelectors.size();
i++) {
92 res_par_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"res_par"));
93 chi2n_par_.push_back(trkSelectors[
i].getParameter<double>(
"chi2n_par"));
95 d0_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par1"));
96 dz_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par1"));
97 d0_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par2"));
98 dz_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par2"));
102 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
103 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
104 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
106 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers"));
107 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers"));
108 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
109 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
112 keepAllTracks_.push_back(trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
113 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
114 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
116 ? trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn")
119 ? trkSelectors[
i].getParameter<double>(
"max_lostHitFraction")
121 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ? trkSelectors[
i].getParameter<double>(
"min_eta")
123 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ? trkSelectors[
i].getParameter<double>(
"max_eta")
128 if (!qualityStr.empty()) {
135 <<
"You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit")
136 <<
" as it is 'undefQuality' or unknown.\n";
139 max_d0NoPV_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0NoPV"));
140 max_z0NoPV_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0NoPV"));
146 name_.push_back(trkSelectors[
i].getParameter<std::string>(
"name"));
151 if (!pfName.empty()) {
152 bool foundPF =
false;
153 for (
unsigned int j = 0;
j <
i;
j++)
159 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in MultiTrackSelector " 160 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
164 produces<edm::ValueMap<int>>(
name_[
i]).setBranchAlias(
name_[
i] +
"TrackQuals");
165 produces<QualityMaskCollection>(
name_[
i]).setBranchAlias(
name_[
i] +
"QualityMasks");
167 bool thisMVA =
false;
168 if (trkSelectors[
i].exists(
"useMVA"))
169 thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
173 if (trkSelectors[
i].exists(
"minMVA"))
174 minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
176 mvaType_.push_back(trkSelectors[
i].exists(
"mvaType") ? trkSelectors[
i].getParameter<std::string>(
"mvaType")
178 forestLabel_.push_back(trkSelectors[
i].exists(
"GBRForestLabel")
179 ? trkSelectors[
i].getParameter<std::string>(
"GBRForestLabel")
180 :
"MVASelectorIter0");
181 useMVAonly_.push_back(trkSelectors[
i].exists(
"useMVAonly") ? trkSelectors[
i].getParameter<bool>(
"useMVAonly")
222 using namespace reco;
230 edm::LogWarning(
"MultiTrackSelector") <<
"could not get Track collection";
247 edm::LogWarning(
"MultiTrackSelector") <<
"could not get Vertex collection";
251 std::vector<int> selTracksSave(
qualityToSet_.size() * trkSize, 0);
253 std::vector<Point>
points;
254 std::vector<float> vterr, vzerr;
259 std::vector<float> mvaVals_(
srcTracks.size(), -99.f);
260 processMVA(evt, es, vertexBeamSpot, *(hVtx.
product()),
i, mvaVals_,
i == 0 ?
true :
false);
261 std::vector<int> selTracks(trkSize, 0);
262 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
274 LogTrace(
"TrackSelection") <<
"ready to check track with pt=" << trk.
pt();
279 selTracks[current] = -1;
286 mvaVal = mvaVals_[current];
287 ok =
select(
i, vertexBeamSpot, srcHits, trk,
points, vterr, vzerr, mvaVal);
289 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" NOT selected";
291 selTracks[current] = -1;
295 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" selected";
299 selTracks[current] = selTracksSave[
preFilter_[
i] * trkSize + current];
304 selTracks[current] = (selTracks[current] | (1 <<
qualityToSet_[
i]));
309 selTracks[current] = (selTracks[current] | (1 << TrackBase::tight));
313 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
315 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
316 selTracks[current] = (selTracks[current] | (1 << TrackBase::highPuritySetWithPV));
321 for (
unsigned int j = 0;
j < trkSize;
j++)
322 selTracksSave[
j +
i * trkSize] = selTracks[
j];
323 filler.insert(hSrcTrack, selTracks.begin(), selTracks.end());
328 for (
auto&
q : selTracks)
330 auto quals = std::make_unique<QualityMaskCollection>(selTracks.begin(), selTracks.end());
339 const std::vector<Point>&
points,
340 std::vector<float>& vterr,
341 std::vector<float>& vzerr,
342 double mvaVal)
const {
354 if (tk.
ndof() < 1E-5)
375 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " <<
nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs " 383 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
386 float chi2n_no1Dmod =
chi2n;
389 auto ith = tk.
extra()->firstRecHit();
391 for (; ith < edh; ++ith) {
393 if (
hit.dimension() == 1)
396 if (count1dhits > 0) {
422 int minLost =
std::min(lostIn, lostOut);
436 float nomdzE = nomd0E * (std::cosh(
eta));
444 bool primaryVertexZCompatibility(
false);
445 bool primaryVertexD0Compatibility(
false);
450 primaryVertexZCompatibility =
true;
453 primaryVertexD0Compatibility =
true;
458 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
459 if (primaryVertexZCompatibility && primaryVertexD0Compatibility)
464 float dzErrPV =
std::sqrt(dzE * dzE + vzerr[
iv] * vzerr[
iv]);
465 float d0ErrPV =
std::sqrt(d0E * d0E + vterr[
iv] * vterr[
iv]);
469 primaryVertexZCompatibility =
true;
472 primaryVertexD0Compatibility =
true;
475 primaryVertexZCompatibility =
true;
477 primaryVertexD0Compatibility =
true;
479 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " <<
dzCut <<
" " <<
d0Cut;
488 if (
abs(
d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
490 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
491 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
493 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
497 <<
" d0 compatibility? " << primaryVertexD0Compatibility <<
" z compatibility? " 498 << primaryVertexZCompatibility;
501 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
509 std::vector<Point>&
points,
510 std::vector<float>& vterr,
511 std::vector<float>& vzerr)
const {
513 using namespace reco;
515 for (VertexCollection::const_iterator
it = vtxs.begin(), ed = vtxs.end();
it != ed; ++
it) {
516 LogDebug(
"SelectVertex") <<
" select vertex with z position " <<
it->z() <<
" " <<
it->chi2() <<
" " <<
it->ndof()
517 <<
" " << TMath::Prob(
it->chi2(),
static_cast<int32_t
>(
it->ndof()));
522 vterr.push_back(
sqrt(
it->yError() *
it->xError()));
523 vzerr.push_back(
it->zError());
524 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " <<
it->z();
537 std::vector<float>& mvaVals_,
538 bool writeIt)
const {
541 using namespace reco;
555 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
560 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
563 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(), mvaVals_.end());
568 if (!
useMVA_[selIndex] && !writeIt)
575 auto tmva_ndof_ = trk.
ndof();
577 auto tmva_nlayers3D_ =
581 float chi2n_no1Dmod =
chi2n;
584 auto ith = trk.
extra()->firstRecHit();
586 for (; ith < edh; ++ith) {
588 if (
hit.dimension() == 1)
591 if (count1dhits > 0) {
596 auto tmva_chi2n_ =
chi2n;
597 auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
598 auto tmva_eta_ = trk.
eta();
603 auto tmva_minlost_ =
std::min(lostIn, lostOut);
605 auto tmva_absd0_ = fabs(-trk.
dxy(
beamspot.position()));
606 auto tmva_absdz_ = fabs(trk.
dz(
beamspot.position()));
608 auto tmva_absd0PV_ = fabs(trk.
dxy(bestVertex));
609 auto tmva_absdzPV_ = fabs(trk.
dz(bestVertex));
610 auto tmva_pt_ = trk.
pt();
618 gbrVals_[0] = tmva_pt_;
619 gbrVals_[1] = tmva_lostmidfrac_;
620 gbrVals_[2] = tmva_minlost_;
621 gbrVals_[3] = tmva_nhits_;
622 gbrVals_[4] = tmva_relpterr_;
623 gbrVals_[5] = tmva_eta_;
624 gbrVals_[6] = tmva_chi2n_no1dmod_;
625 gbrVals_[7] = tmva_chi2n_;
626 gbrVals_[8] = tmva_nlayerslost_;
627 gbrVals_[9] = tmva_nlayers3D_;
628 gbrVals_[10] = tmva_nlayers_;
629 gbrVals_[11] = tmva_ndof_;
630 gbrVals_[12] = tmva_absd0PV_;
631 gbrVals_[13] = tmva_absdzPV_;
632 gbrVals_[14] = tmva_absdz_;
633 gbrVals_[15] = tmva_absd0_;
635 if (
mvaType_[selIndex] ==
"Prompt") {
637 mvaVals_[current] = gbrVal;
639 float detachedGbrVals_[12];
640 for (
int jjj = 0; jjj < 12; jjj++)
641 detachedGbrVals_[jjj] = gbrVals_[jjj];
643 mvaVals_[current] = gbrVal;
648 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
651 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(), mvaVals_.end());
658 Point p_dz(0, 0, -99999);
659 float bestWeight = 0;
661 bool weightMatch =
false;
665 if (
w > bestWeight) {
670 float dz = fabs(
track.get()->dz(v_pos));
int numberOfLostTrackerHits(HitCategory category) const
std::vector< uint32_t > min_nhits_
std::vector< double > max_d0NoPV_
std::vector< double > max_z0_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
~MultiTrackSelector() override
destructor
std::vector< std::string > name_
std::vector< double > max_z0NoPV_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
MultiTrackSelector()
constructor
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
unsigned short numberOfValidHits() const
number of valid hits found
const Point & position() const
position
std::vector< bool > useMVA_
Quality qualityByName(std::string const &name)
std::vector< bool > keepAllTracks_
int trackerLayersWithMeasurement() const
std::vector< uint32_t > min_hits_bypass_
T const * product() const
std::vector< Track > TrackCollection
collection of Tracks
std::vector< bool > applyAdaptedPVCuts_
std::vector< Vertex > VertexCollection
collection of Vertex objects
std::vector< double > chi2n_no1Dmod_par_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< double > nSigmaZ_
std::vector< std::string > mvaType_
std::vector< unsigned int > preFilter_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
edm::EDGetTokenT< TrackingRecHitCollection > hSrc_
edm::EDGetTokenT< reco::VertexCollection > vertices_
std::vector< uint32_t > min_3Dlayers_
double pt() const
track transverse momentum
double ndof() const
number of degrees of freedom of the fit
std::vector< uint32_t > max_lostLayers_
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
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...
std::vector< GBRForest * > forest_
std::vector< int32_t > max_lostHitFraction_
edm::EDGetTokenT< reco::BeamSpot > beamspot_
std::vector< double > min_eta_
double dzError() const
error on dz
Point getBestVertex(const reco::TrackBaseRef, const reco::VertexCollection) const
std::vector< bool > setQualityBit_
do I have to set a quality bit?
std::vector< std::vector< double > > dz_par1_
Abs< T >::type abs(const T &t)
void processMVA(edm::Event &evt, const edm::EventSetup &es, const reco::BeamSpot &beamspot, const reco::VertexCollection &vertices, int selIndex, std::vector< float > &mvaVals_, bool writeIt=false) const
#define DEFINE_FWK_MODULE(type)
std::vector< std::vector< double > > d0_par1_
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr) const
bool select(unsigned tsNum, const reco::BeamSpot &vertexBeamSpot, const TrackingRecHitCollection &recHits, const reco::Track &tk, const std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr, double mvaVal) const
return class, or -1 if rejected
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
std::vector< double > max_relpterr_
void beginStream(edm::StreamID) final
double eta() const
pseudorapidity of momentum vector
std::vector< int32_t > vtxNumber_
vertex cuts
static constexpr float d0
double GetClassifier(const float *vector) const
int trackerLayersWithoutMeasurement(HitCategory category) const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
double sigmaZ() const
sigma z
std::vector< reco::TrackBase::TrackQuality > qualityToSet_
std::vector< edm::ESGetToken< GBRForest, GBRWrapperRcd > > forestToken_
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
double chi2() const
chi-squared of the fit
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
std::vector< std::string > forestLabel_
Structure Point Contains parameters of Gaussian fits to DMRs.
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
std::vector< std::vector< double > > dz_par2_
std::vector< bool > applyAbsCutsIfNoPV_
int pixelLayersWithMeasurement() const
std::vector< int32_t > max_minMissHitOutOrIn_
std::vector< double > min_MVA_
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
double d0Error() const
error on d0
std::vector< double > max_d0_
Impact parameter absolute cuts.
std::vector< bool > useMVAonly_
std::vector< std::vector< double > > res_par_
Power< A, B >::type pow(const A &a, const B &b)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
std::vector< double > max_eta_
std::vector< double > chi2n_par_
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
const TrackExtraRef & extra() const
reference to "extra" object
std::vector< std::vector< double > > d0_par2_