9 #include <Math/DistFunc.h> 23 useVertices_(cfg.getParameter<
bool>(
"useVertices")),
24 useVtxError_(cfg.getParameter<
bool>(
"useVtxError"))
30 edm::LogWarning(
"MultiTRackSelector") <<
"you are executing buggy code, if intentional please help to fix it";
36 if (cfg.
exists(
"useAnyMVA"))
40 if (cfg.
exists(
"GBRForestFileName")) {
45 std::vector<edm::ParameterSet> trkSelectors(cfg.
getParameter<std::vector<edm::ParameterSet>>(
"trackSelectors"));
49 res_par_.reserve(trkSelectors.size());
52 d0_par1_.reserve(trkSelectors.size());
53 dz_par1_.reserve(trkSelectors.size());
54 d0_par2_.reserve(trkSelectors.size());
55 dz_par2_.reserve(trkSelectors.size());
57 max_d0_.reserve(trkSelectors.size());
58 max_z0_.reserve(trkSelectors.size());
59 nSigmaZ_.reserve(trkSelectors.size());
72 min_eta_.reserve(trkSelectors.size());
73 max_eta_.reserve(trkSelectors.size());
74 useMVA_.reserve(trkSelectors.size());
77 min_MVA_.reserve(trkSelectors.size());
78 mvaType_.reserve(trkSelectors.size());
80 forest_.reserve(trkSelectors.size());
82 produces<edm::ValueMap<float>>(
"MVAVals");
85 produces<MVACollection>(
"MVAValues");
87 for (
unsigned int i = 0;
i < trkSelectors.size();
i++) {
93 res_par_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"res_par"));
94 chi2n_par_.push_back(trkSelectors[
i].getParameter<double>(
"chi2n_par"));
96 d0_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par1"));
97 dz_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par1"));
98 d0_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par2"));
99 dz_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par2"));
103 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
104 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
105 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
107 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers"));
108 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers"));
109 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
110 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
113 keepAllTracks_.push_back(trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
114 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
115 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
117 ? trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn")
120 ? trkSelectors[
i].getParameter<double>(
"max_lostHitFraction")
122 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ? trkSelectors[
i].getParameter<double>(
"min_eta")
124 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ? trkSelectors[
i].getParameter<double>(
"max_eta")
129 if (!qualityStr.empty()) {
131 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
136 <<
"You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit")
137 <<
" as it is 'undefQuality' or unknown.\n";
140 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
141 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
147 name_.push_back(trkSelectors[i].getParameter<std::string>(
"name"));
152 if (!pfName.empty()) {
153 bool foundPF =
false;
154 for (
unsigned int j = 0;
j <
i;
j++)
160 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in MultiTrackSelector " 161 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
165 produces<edm::ValueMap<int>>(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
166 produces<QualityMaskCollection>(
name_[
i]).setBranchAlias(
name_[i] +
"QualityMasks");
168 bool thisMVA =
false;
169 if (trkSelectors[i].exists(
"useMVA"))
170 thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
174 if (trkSelectors[i].exists(
"minMVA"))
175 minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
177 mvaType_.push_back(trkSelectors[i].exists(
"mvaType") ? trkSelectors[i].getParameter<std::string>(
"mvaType")
179 forestLabel_.push_back(trkSelectors[i].exists(
"GBRForestLabel")
180 ? trkSelectors[i].getParameter<std::string>(
"GBRForestLabel")
181 :
"MVASelectorIter0");
182 useMVAonly_.push_back(trkSelectors[i].exists(
"useMVAonly") ? trkSelectors[i].getParameter<bool>(
"useMVAonly")
217 using namespace reco;
225 edm::LogWarning(
"MultiTrackSelector") <<
"could not get Track collection";
242 edm::LogWarning(
"MultiTrackSelector") <<
"could not get Vertex collection";
245 unsigned int trkSize = srcTracks.size();
246 std::vector<int> selTracksSave(
qualityToSet_.size() * trkSize, 0);
248 std::vector<Point>
points;
249 std::vector<float> vterr, vzerr;
254 std::vector<float> mvaVals_(srcTracks.size(), -99.f);
255 processMVA(evt, es, vertexBeamSpot, *(hVtx.
product()),
i, mvaVals_,
i == 0 ?
true :
false);
256 std::vector<int> selTracks(trkSize, 0);
257 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
265 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
266 const Track& trk = *it;
269 LogTrace(
"TrackSelection") <<
"ready to check track with pt=" << trk.
pt();
274 selTracks[current] = -1;
281 mvaVal = mvaVals_[current];
282 ok =
select(
i, vertexBeamSpot, srcHits, trk, points, vterr, vzerr, mvaVal);
284 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" NOT selected";
286 selTracks[current] = -1;
290 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" selected";
294 selTracks[current] = selTracksSave[
preFilter_[
i] * trkSize + current];
299 selTracks[current] = (selTracks[current] | (1 <<
qualityToSet_[
i]));
301 selTracks[current] = (selTracks[current] | (1 << TrackBase::loose));
303 selTracks[current] = (selTracks[current] | (1 << TrackBase::loose));
304 selTracks[current] = (selTracks[current] | (1 << TrackBase::tight));
306 if (!points.empty()) {
308 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
310 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
311 selTracks[current] = (selTracks[current] | (1 << TrackBase::highPuritySetWithPV));
316 for (
unsigned int j = 0;
j < trkSize;
j++)
317 selTracksSave[
j +
i * trkSize] = selTracks[
j];
318 filler.insert(hSrcTrack, selTracks.begin(), selTracks.end());
323 for (
auto&
q : selTracks)
325 auto quals = std::make_unique<QualityMaskCollection>(selTracks.begin(), selTracks.end());
334 const std::vector<Point>&
points,
335 std::vector<float>& vterr,
336 std::vector<float>& vzerr,
337 double mvaVal)
const {
349 if (tk.
ndof() < 1E-5)
358 if (mvaVal < min_MVA_[tsNum])
370 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs " 376 if (nlayersLost > max_lostLayers_[tsNum])
378 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
381 float chi2n_no1Dmod =
chi2n;
384 auto ith = tk.
extra()->firstRecHit();
386 for (; ith < edh; ++ith) {
391 if (count1dhits > 0) {
394 chi2n = (chi2 + count1dhits) /
float(ndof + count1dhits);
417 int minLost =
std::min(lostIn, lostOut);
431 float nomdzE = nomd0E * (std::cosh(eta));
439 bool primaryVertexZCompatibility(
false);
440 bool primaryVertexD0Compatibility(
false);
442 if (points.empty()) {
445 primaryVertexZCompatibility =
true;
448 primaryVertexD0Compatibility =
true;
452 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
453 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
454 if (primaryVertexZCompatibility && primaryVertexD0Compatibility)
459 float dzErrPV =
std::sqrt(dzE * dzE + vzerr[iv] * vzerr[iv]);
460 float d0ErrPV =
std::sqrt(d0E * d0E + vterr[iv] * vterr[iv]);
464 primaryVertexZCompatibility =
true;
467 primaryVertexD0Compatibility =
true;
469 if (
abs(dzPV) < dzCut)
470 primaryVertexZCompatibility =
true;
471 if (
abs(d0PV) < d0Cut)
472 primaryVertexD0Compatibility =
true;
474 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " <<
d0Cut;
483 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
485 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
486 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
488 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
492 <<
" d0 compatibility? " << primaryVertexD0Compatibility <<
" z compatibility? " 493 << primaryVertexZCompatibility;
496 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
504 std::vector<Point>&
points,
505 std::vector<float>& vterr,
506 std::vector<float>& vzerr)
const {
508 using namespace reco;
510 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
511 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" " << it->chi2() <<
" " << it->ndof()
512 <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
516 points.push_back(it->position());
517 vterr.push_back(
sqrt(it->yError() * it->xError()));
518 vzerr.push_back(it->zError());
519 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
532 std::vector<float>& mvaVals_,
533 bool writeIt)
const {
536 using namespace reco;
543 assert(mvaVals_.size() == srcTracks.size());
550 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
555 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
558 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(), mvaVals_.end());
563 if (!
useMVA_[selIndex] && !writeIt)
567 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
568 const Track& trk = *it;
570 auto tmva_ndof_ = trk.
ndof();
572 auto tmva_nlayers3D_ =
576 float chi2n_no1Dmod =
chi2n;
579 auto ith = trk.
extra()->firstRecHit();
581 for (; ith < edh; ++ith) {
586 if (count1dhits > 0) {
589 chi2n = (chi2 + count1dhits) /
float(ndof + count1dhits);
591 auto tmva_chi2n_ =
chi2n;
592 auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
593 auto tmva_eta_ = trk.
eta();
598 auto tmva_minlost_ =
std::min(lostIn, lostOut);
600 auto tmva_absd0_ = fabs(-trk.
dxy(beamspot.
position()));
601 auto tmva_absdz_ = fabs(trk.
dz(beamspot.
position()));
603 auto tmva_absd0PV_ = fabs(trk.
dxy(bestVertex));
604 auto tmva_absdzPV_ = fabs(trk.
dz(bestVertex));
605 auto tmva_pt_ = trk.
pt();
611 forest = forestHandle.
product();
615 gbrVals_[0] = tmva_pt_;
616 gbrVals_[1] = tmva_lostmidfrac_;
617 gbrVals_[2] = tmva_minlost_;
618 gbrVals_[3] = tmva_nhits_;
619 gbrVals_[4] = tmva_relpterr_;
620 gbrVals_[5] = tmva_eta_;
621 gbrVals_[6] = tmva_chi2n_no1dmod_;
622 gbrVals_[7] = tmva_chi2n_;
623 gbrVals_[8] = tmva_nlayerslost_;
624 gbrVals_[9] = tmva_nlayers3D_;
625 gbrVals_[10] = tmva_nlayers_;
626 gbrVals_[11] = tmva_ndof_;
627 gbrVals_[12] = tmva_absd0PV_;
628 gbrVals_[13] = tmva_absdzPV_;
629 gbrVals_[14] = tmva_absdz_;
630 gbrVals_[15] = tmva_absd0_;
632 if (
mvaType_[selIndex] ==
"Prompt") {
634 mvaVals_[current] = gbrVal;
636 float detachedGbrVals_[12];
637 for (
int jjj = 0; jjj < 12; jjj++)
638 detachedGbrVals_[jjj] = gbrVals_[jjj];
640 mvaVals_[current] = gbrVal;
645 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
648 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(), mvaVals_.end());
655 Point p_dz(0, 0, -99999);
656 float bestWeight = 0;
658 bool weightMatch =
false;
659 for (
auto const&
vertex : vertices) {
660 float w =
vertex.trackWeight(track);
662 if (w > bestWeight) {
667 float dz = fabs(track.
get()->
dz(v_pos));
value_type const * get() const
T getParameter(std::string const &) const
std::vector< uint32_t > min_nhits_
std::vector< double > max_d0NoPV_
double d0Error() const
error on d0
std::vector< double > max_z0_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
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_
MultiTrackSelector()
constructor
const TrackExtraRef & extra() const
reference to "extra" object
std::vector< bool > useMVA_
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< bool > keepAllTracks_
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Point getBestVertex(const reco::TrackBaseRef, const reco::VertexCollection) const
std::vector< uint32_t > min_hits_bypass_
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
std::vector< Track > TrackCollection
collection of Tracks
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< bool > applyAdaptedPVCuts_
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
std::vector< Vertex > VertexCollection
collection of Vertex objects
std::vector< double > chi2n_no1Dmod_par_
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
std::vector< double > nSigmaZ_
std::vector< std::string > mvaType_
std::vector< unsigned int > preFilter_
int pixelLayersWithMeasurement() const
edm::EDGetTokenT< TrackingRecHitCollection > hSrc_
int trackerLayersWithMeasurement() const
edm::EDGetTokenT< reco::VertexCollection > vertices_
std::vector< uint32_t > min_3Dlayers_
int numberOfLostTrackerHits(HitCategory category) const
std::vector< uint32_t > max_lostLayers_
std::vector< GBRForest * > forest_
#define DEFINE_FWK_MODULE(type)
double eta() const
pseudorapidity of momentum vector
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
std::vector< int32_t > max_lostHitFraction_
edm::EDGetTokenT< reco::BeamSpot > beamspot_
std::vector< double > min_eta_
double chi2() const
chi-squared of the fit
double ndof() const
number of degrees of freedom of the fit
virtual int dimension() const =0
std::vector< bool > setQualityBit_
do I have to set a quality bit?
double pt() const
track transverse momentum
std::vector< std::vector< double > > dz_par1_
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Abs< T >::type abs(const T &t)
unsigned short numberOfValidHits() const
number of valid hits found
std::vector< std::vector< double > > d0_par1_
std::vector< double > max_relpterr_
void beginStream(edm::StreamID) final
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
std::vector< int32_t > vtxNumber_
vertex cuts
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr) const
T const * product() const
std::vector< reco::TrackBase::TrackQuality > qualityToSet_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
double sigmaZ() const
sigma z
std::vector< std::string > forestLabel_
int trackerLayersWithoutMeasurement(HitCategory category) const
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_
const Point & position() const
position
std::vector< int32_t > max_minMissHitOutOrIn_
std::vector< double > min_MVA_
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
double GetClassifier(const float *vector) const
std::vector< double > max_d0_
Impact parameter absolute cuts.
std::vector< bool > useMVAonly_
T const * product() const
std::vector< std::vector< double > > res_par_
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
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_
std::vector< std::vector< double > > d0_par2_