8 #include <Math/DistFunc.h>
18 return PowN<
N / 2>::op(t) * PowN<(
N + 1) / 2>::op(t);
47 return PowN<4>::op(t);
49 return PowN<3>::op(t);
51 return PowN<8>::op(t);
53 return PowN<2>::op(t);
55 return PowN<5>::op(t);
57 return PowN<6>::op(t);
59 return PowN<7>::op(t);
61 return PowN<0>::op(t);
63 return PowN<1>::op(t);
74 useForestFromDB_ =
true;
79 mvavars_indices.clear();
80 for (
unsigned i = 0;
i < forestVars_.size();
i++) {
83 if (v ==
"chi2perdofperlayer")
85 if (v ==
"dxyperdxyerror")
87 if (v ==
"dzperdzerror")
91 if (v ==
"lostmidfrac")
99 if (v ==
"chi2n_no1dmod")
103 if (v ==
"nlayerslost")
105 if (v ==
"nlayers3d")
116 <<
"Unknown forest variable " << v <<
". Please make sure it's in the list of supported variables\n";
118 mvavars_indices.push_back(ind);
126 useVertices_(cfg.getParameter<bool>(
"useVertices")),
127 useVtxError_(cfg.getParameter<bool>(
"useVtxError"))
134 if (cfg.
exists(
"applyPixelMergingCuts"))
145 if (cfg.
exists(
"useAnyMVA"))
148 if (cfg.
exists(
"mvaType"))
150 if (cfg.
exists(
"GBRForestLabel"))
152 if (cfg.
exists(
"GBRForestVars")) {
156 if (cfg.
exists(
"GBRForestFileName")) {
165 std::vector<edm::ParameterSet> trkSelectors(cfg.
getParameter<std::vector<edm::ParameterSet>>(
"trackSelectors"));
169 res_par_.reserve(trkSelectors.size());
172 d0_par1_.reserve(trkSelectors.size());
173 dz_par1_.reserve(trkSelectors.size());
174 d0_par2_.reserve(trkSelectors.size());
175 dz_par2_.reserve(trkSelectors.size());
177 max_d0_.reserve(trkSelectors.size());
178 max_z0_.reserve(trkSelectors.size());
179 nSigmaZ_.reserve(trkSelectors.size());
194 min_eta_.reserve(trkSelectors.size());
195 max_eta_.reserve(trkSelectors.size());
196 useMVA_.reserve(trkSelectors.size());
198 min_MVA_.reserve(trkSelectors.size());
201 produces<edm::ValueMap<float>>(
"MVAVals");
203 for (
unsigned int i = 0;
i < trkSelectors.size();
i++) {
209 res_par_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"res_par"));
210 chi2n_par_.push_back(trkSelectors[
i].getParameter<double>(
"chi2n_par"));
212 d0_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par1"));
213 dz_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par1"));
214 d0_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par2"));
215 dz_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par2"));
219 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
220 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
221 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
223 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers"));
224 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers"));
225 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
226 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
229 keepAllTracks_.push_back(trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
230 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
231 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
233 ? trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn")
236 ? trkSelectors[
i].getParameter<double>(
"max_lostHitFraction")
238 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ? trkSelectors[
i].getParameter<double>(
"min_eta")
240 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ? trkSelectors[
i].getParameter<double>(
"max_eta")
245 if (!qualityStr.empty()) {
252 <<
"You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit")
253 <<
" as it is 'undefQuality' or unknown.\n";
256 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
257 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
263 name_.push_back(trkSelectors[i].getParameter<std::string>(
"name"));
268 if (!pfName.empty()) {
269 bool foundPF =
false;
270 for (
unsigned int j = 0;
j <
i;
j++)
276 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in HIMultiTrackSelector "
277 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
281 pixel_pTMinCut_.push_back(trkSelectors[i].getParameter<std::vector<double>>(
"pixel_pTMinCut"));
282 pixel_pTMaxCut_.push_back(trkSelectors[i].getParameter<std::vector<double>>(
"pixel_pTMaxCut"));
286 produces<edm::ValueMap<int>>(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
288 bool thisMVA =
false;
289 if (trkSelectors[i].exists(
"useMVA"))
290 thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
294 if (trkSelectors[i].exists(
"minMVA"))
295 minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
319 using namespace reco;
341 unsigned int trkSize = srcTracks.size();
342 std::vector<int> selTracksSave(
qualityToSet_.size() * trkSize, 0);
344 std::vector<float> mvaVals_(srcTracks.size(), -99.f);
348 std::vector<int> selTracks(trkSize, 0);
349 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
352 std::vector<Point> points;
353 std::vector<float> vterr, vzerr;
359 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
360 const Track &trk = *it;
363 LogTrace(
"TrackSelection") <<
"ready to check track with pt=" << trk.
pt();
369 selTracks[current] = -1;
375 mvaVal = mvaVals_[current];
376 ok =
select(
i, vertexBeamSpot, srcHits, trk, points, vterr, vzerr, mvaVal);
378 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" NOT selected";
380 selTracks[current] = -1;
384 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" selected";
388 selTracks[current] = selTracksSave[
preFilter_[
i] * trkSize + current];
393 selTracks[current] = (selTracks[current] | (1 <<
qualityToSet_[
i]));
398 selTracks[current] = (selTracks[current] | (1 << TrackBase::tight));
401 if (!points.empty()) {
403 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
405 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
406 selTracks[current] = (selTracks[current] | (1 << TrackBase::highPuritySetWithPV));
411 for (
unsigned int j = 0;
j < trkSize;
j++)
412 selTracksSave[
j +
i * trkSize] = selTracks[
j];
413 filler.insert(hSrcTrack, selTracks.begin(), selTracks.end());
425 const std::vector<Point> &points,
426 std::vector<float> &vterr,
427 std::vector<float> &vzerr,
428 double mvaVal)
const {
440 if (tk.
ndof() < 1E-5)
461 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " <<
nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
469 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
472 float chi2n_no1Dmod =
chi2n;
475 auto ith = tk.
extra()->firstRecHit();
477 for (; ith < edh; ++ith) {
482 if (count1dhits > 0) {
485 chi2n = (chi2 + count1dhits) /
float(ndof + count1dhits);
508 int minLost =
std::min(lostIn, lostOut);
541 float nomdzE = nomd0E * (std::cosh(
eta));
549 bool primaryVertexZCompatibility(
false);
550 bool primaryVertexD0Compatibility(
false);
552 if (points.empty()) {
555 primaryVertexZCompatibility =
true;
558 primaryVertexD0Compatibility =
true;
562 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
563 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
564 if (primaryVertexZCompatibility && primaryVertexD0Compatibility)
569 float dzErrPV =
std::sqrt(dzE * dzE + vzerr[
iv] * vzerr[
iv]);
570 float d0ErrPV =
std::sqrt(d0E * d0E + vterr[iv] * vterr[iv]);
574 primaryVertexZCompatibility =
true;
577 primaryVertexD0Compatibility =
true;
579 if (
abs(dzPV) < dzCut)
580 primaryVertexZCompatibility =
true;
581 if (
abs(d0PV) < d0Cut)
582 primaryVertexD0Compatibility =
true;
584 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
593 if (
abs(
d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
595 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
596 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
598 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
602 <<
" d0 compatibility? " << primaryVertexD0Compatibility <<
" z compatibility? "
603 << primaryVertexZCompatibility;
606 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
614 std::vector<Point> &points,
615 std::vector<float> &vterr,
616 std::vector<float> &vzerr)
const {
618 using namespace reco;
620 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
621 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" " << it->chi2() <<
" " << it->ndof()
622 <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
626 points.push_back(it->position());
627 vterr.push_back(
sqrt(it->yError() * it->xError()));
628 vzerr.push_back(it->zError());
629 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
639 std::vector<float> &mvaVals_,
643 using namespace reco;
649 assert(mvaVals_.size() == srcTracks.size());
656 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
661 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
672 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
673 const Track &trk = *it;
686 auto ith = trk.
extra()->firstRecHit();
688 for (; ith < edh; ++ith) {
693 if (count1dhits > 0) {
696 chi2n1d = (chi2 + count1dhits) /
float(ndof + count1dhits);
699 mvavalues[
chi2n] = chi2n1d;
701 mvavalues[
eta] = trk.
eta();
717 dxyE =
sqrt(trk.
dxyError() * trk.
dxyError() + vertices[vtxind].xError() * vertices[vtxind].yError());
719 dzE =
sqrt(trk.
dzError() * trk.
dzError() + vertices[vtxind].zError() * vertices[vtxind].zError());
726 std::vector<float> gbrValues;
739 mvaVals_[current] = gbrVal;
741 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
std::vector< std::string > name_
std::vector< std::vector< double > > dz_par2_
virtual int dimension() const =0
double d0Error() const
error on d0
std::vector< uint32_t > max_lostLayers_
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
~HIMultiTrackSelector() override
destructor
std::vector< std::vector< double > > dz_par1_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< double > chi2n_no1Dmod_par_
bool applyPixelMergingCuts_
std::vector< uint32_t > min_hits_bypass_
const TrackExtraRef & extra() const
reference to "extra" object
Quality qualityByName(std::string const &name)
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< std::vector< double > > pixel_pTMaxCut_
double dxyError() const
error on dxy
#define DEFINE_FWK_MODULE(type)
std::vector< uint32_t > min_nhits_
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
std::vector< bool > useMVA_
std::vector< Track > TrackCollection
collection of Tracks
double etaError() const
error on eta
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr) const
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< int32_t > max_minMissHitOutOrIn_
std::vector< uint32_t > min_3Dlayers_
int pixelLayersWithMeasurement() const
void beginStream(edm::StreamID) final
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
int trackerLayersWithMeasurement() const
std::vector< double > min_eta_
int numberOfLostTrackerHits(HitCategory category) const
std::vector< double > max_eta_
bool getData(T &iHolder) const
std::vector< double > max_d0NoPV_
double eta() const
pseudorapidity of momentum vector
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
edm::EDGetTokenT< reco::VertexCollection > vertices_
double chi2() const
chi-squared of the fit
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
std::vector< bool > setQualityBit_
do I have to set a quality bit?
double ndof() const
number of degrees of freedom of the fit
double pt() const
track transverse momentum
std::vector< std::vector< double > > d0_par1_
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
std::vector< int32_t > vtxNumber_
vertex cuts
Abs< T >::type abs(const T &t)
std::vector< double > max_z0_
unsigned short numberOfValidHits() const
number of valid hits found
edm::EDGetTokenT< TrackingRecHitCollection > hSrc_
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
std::vector< double > nSigmaZ_
std::vector< double > max_d0_
Impact parameter absolute cuts.
std::vector< bool > applyAdaptedPVCuts_
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< double > max_relpterr_
std::vector< int > mvavars_indices
std::vector< std::vector< double > > d0_par2_
void processMVA(edm::Event &evt, const edm::EventSetup &es, std::vector< float > &mvaVals_, const reco::VertexCollection &hVtx) const
static constexpr float d0
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
std::vector< std::string > forestVars_
double sigmaZ() const
sigma z
std::vector< int32_t > max_lostHitFraction_
T getParameter(std::string const &) const
std::vector< double > chi2n_par_
std::vector< std::vector< double > > res_par_
edm::EDGetTokenT< reco::BeamSpot > beamspot_
std::vector< bool > applyAbsCutsIfNoPV_
int trackerLayersWithoutMeasurement(HitCategory category) const
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
std::vector< std::vector< double > > pixel_pTMinCut_
static int position[264][3]
HIMultiTrackSelector()
constructor
std::vector< double > max_z0NoPV_
std::vector< bool > keepAllTracks_
const Point & position() const
position
Log< level::Warning, false > LogWarning
edm::ESGetToken< GBRForest, GBRWrapperRcd > forestToken_
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
std::vector< double > min_MVA_
double GetClassifier(const float *vector) const
std::vector< unsigned int > preFilter_
std::vector< reco::TrackBase::TrackQuality > qualityToSet_
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