9 #include <Math/DistFunc.h> 19 useForestFromDB_ =
true;
25 beamspot_( consumes<
reco::
BeamSpot>( cfg.getParameter<
edm::InputTag>(
"beamspot" ) ) ),
26 useVertices_( cfg.getParameter<bool>(
"useVertices" ) ),
27 useVtxError_( cfg.getParameter<bool>(
"useVtxError" ) )
32 edm::LogWarning(
"MultiTRackSelector") <<
"you are executing buggy code, if intentional please help to fix it";
41 if(cfg.
exists(
"GBRForestFileName")){
46 std::vector<edm::ParameterSet> trkSelectors( cfg.
getParameter<std::vector< edm::ParameterSet> >(
"trackSelectors") );
50 res_par_.reserve(trkSelectors.size());
53 d0_par1_.reserve(trkSelectors.size());
54 dz_par1_.reserve(trkSelectors.size());
55 d0_par2_.reserve(trkSelectors.size());
56 dz_par2_.reserve(trkSelectors.size());
58 max_d0_.reserve(trkSelectors.size());
59 max_z0_.reserve(trkSelectors.size());
60 nSigmaZ_.reserve(trkSelectors.size());
73 min_eta_.reserve(trkSelectors.size());
74 max_eta_.reserve(trkSelectors.size());
75 useMVA_.reserve(trkSelectors.size());
78 min_MVA_.reserve(trkSelectors.size());
79 mvaType_.reserve(trkSelectors.size());
81 forest_.reserve(trkSelectors.size());
83 produces<edm::ValueMap<float> >(
"MVAVals");
86 produces<MVACollection>(
"MVAValues");
89 for (
unsigned int i=0;
i<trkSelectors.size();
i++) {
96 res_par_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"res_par") );
97 chi2n_par_.push_back( trkSelectors[
i].getParameter<double>(
"chi2n_par") );
99 d0_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par1"));
100 dz_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par1"));
101 d0_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par2"));
102 dz_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par2"));
106 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
107 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
108 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
110 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers") );
111 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers") );
112 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
113 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
116 keepAllTracks_.push_back( trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
117 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
118 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
120 trkSelectors[
i].existsAs<int32_t>(
"max_minMissHitOutOrIn") ?
121 trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn") : 99);
123 trkSelectors[
i].existsAs<double>(
"max_lostHitFraction") ?
124 trkSelectors[
i].getParameter<double>(
"max_lostHitFraction") : 1.0);
125 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ?
126 trkSelectors[
i].getParameter<double>(
"min_eta"):-9999);
127 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ?
128 trkSelectors[
i].getParameter<double>(
"max_eta"):9999);
132 if (qualityStr !=
"") {
134 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
138 "You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit") <<
" as it is 'undefQuality' or unknown.\n";
141 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
142 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
149 name_.push_back( trkSelectors[i].getParameter<std::string>(
"name") );
156 for (
unsigned int j=0; j<
i; j++)
157 if (
name_[j]==pfName ) {
162 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in MultiTrackSelector " 163 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
168 produces<edm::ValueMap<int> >(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
169 produces<QualityMaskCollection>(
name_[
i]).setBranchAlias(
name_[i] +
"QualityMasks");
171 bool thisMVA =
false;
172 if(trkSelectors[i].exists(
"useMVA"))thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
176 if(trkSelectors[i].exists(
"minMVA"))minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
178 mvaType_.push_back(trkSelectors[i].exists(
"mvaType") ? trkSelectors[i].getParameter<std::string>(
"mvaType") :
"Detached");
179 forestLabel_.push_back(trkSelectors[i].exists(
"GBRForestLabel") ? trkSelectors[i].getParameter<std::string>(
"GBRForestLabel") :
"MVASelectorIter0");
180 useMVAonly_.push_back(trkSelectors[i].exists(
"useMVAonly") ? trkSelectors[i].getParameter<bool>(
"useMVAonly") :
false);
199 for(
auto forest :
forest_)
delete forest;
219 using namespace reco;
227 edm::LogWarning(
"MultiTrackSelector")<<
"could not get Track collection";
245 edm::LogWarning(
"MultiTrackSelector")<<
"could not get Vertex collection";
248 unsigned int trkSize=srcTracks.size();
249 std::vector<int> selTracksSave(
qualityToSet_.size()*trkSize,0);
251 std::vector<Point> points;
252 std::vector<float> vterr, vzerr;
256 std::vector<float> mvaVals_(srcTracks.size(),-99.f);
258 std::vector<int> selTracks(trkSize,0);
259 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
266 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
267 const Track & trk = * it;
270 LogTrace(
"TrackSelection") <<
"ready to check track with pt="<< trk.
pt() ;
275 selTracks[current]=-1;
283 ok =
select(
i,vertexBeamSpot, srcHits, trk, points, vterr, vzerr,mvaVal);
285 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" NOT selected";
287 selTracks[current]=-1;
292 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" selected";
296 selTracks[current]=selTracksSave[
preFilter_[
i]*trkSize+current];
304 selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
307 selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
308 selTracks[current]=(selTracks[current] | (1<<TrackBase::tight));
310 if (!points.empty()) {
312 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++ ) selTracksSave[j+
i*trkSize]=selTracks[j];
322 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
328 auto quals = std::make_unique<QualityMaskCollection>(selTracks.begin(),selTracks.end());
338 const std::vector<Point> &points,
339 std::vector<float> &vterr,
340 std::vector<float> &vzerr,
341 double mvaVal)
const {
351 if ( tk.
ndof() < 1E-5 )
return false;
359 if(mvaVal < min_MVA_[tsNum])
return false;
371 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs " 375 if (nlayersLost > max_lostLayers_[tsNum])
return false;
376 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
379 float chi2n_no1Dmod =
chi2n;
382 auto ith = tk.
extra()->firstRecHit();
384 for (; ith<edh; ++ith) {
388 if (count1dhits > 0) {
391 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
395 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
410 int minLost =
std::min(lostIn,lostOut);
424 float nomdzE = nomd0E*(std::cosh(eta));
433 bool primaryVertexZCompatibility(
false);
434 bool primaryVertexD0Compatibility(
false);
436 if (points.empty()) {
440 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
444 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
445 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
446 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
450 float dzErrPV =
std::sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
451 float d0ErrPV =
std::sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
455 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
458 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
460 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
461 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
463 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
471 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
472 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
473 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
474 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
478 <<
" d0 compatibility? " << primaryVertexD0Compatibility
479 <<
" z compatibility? " << primaryVertexZCompatibility ;
482 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
491 std::vector<Point> &points,
492 std::vector<float> &vterr,
493 std::vector<float> &vzerr)
const {
495 using namespace reco;
497 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
499 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" " 500 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
504 points.push_back(it->position());
505 vterr.push_back(
sqrt(it->yError()*it->xError()));
506 vzerr.push_back(it->zError());
507 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
508 toTake--;
if (toTake == 0)
break;
518 using namespace reco;
525 assert(mvaVals_.size()==srcTracks.size());
533 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
539 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
542 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(),mvaVals_.end());
547 if(!
useMVA_[selIndex] && !writeIt)
return;
551 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
552 const Track & trk = * it;
554 auto tmva_ndof_ = trk.
ndof();
560 float chi2n_no1Dmod =
chi2n;
563 auto ith = trk.
extra()->firstRecHit();
565 for (; ith<edh; ++ith) {
569 if (count1dhits > 0) {
572 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
574 auto tmva_chi2n_ =
chi2n;
575 auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
576 auto tmva_eta_ = trk.
eta();
581 auto tmva_minlost_ =
std::min(lostIn,lostOut);
583 auto tmva_absd0_ = fabs(-trk.
dxy(beamspot.
position()));
584 auto tmva_absdz_ = fabs(trk.
dz(beamspot.
position()));
586 auto tmva_absd0PV_ = fabs(trk.
dxy(bestVertex));
587 auto tmva_absdzPV_ = fabs(trk.
dz(bestVertex));
588 auto tmva_pt_ = trk.
pt();
594 forest = forestHandle.
product();
598 gbrVals_[0] = tmva_pt_;
599 gbrVals_[1] = tmva_lostmidfrac_;
600 gbrVals_[2] = tmva_minlost_;
601 gbrVals_[3] = tmva_nhits_;
602 gbrVals_[4] = tmva_relpterr_;
603 gbrVals_[5] = tmva_eta_;
604 gbrVals_[6] = tmva_chi2n_no1dmod_;
605 gbrVals_[7] = tmva_chi2n_;
606 gbrVals_[8] = tmva_nlayerslost_;
607 gbrVals_[9] = tmva_nlayers3D_;
608 gbrVals_[10] = tmva_nlayers_;
609 gbrVals_[11] = tmva_ndof_;
610 gbrVals_[12] = tmva_absd0PV_;
611 gbrVals_[13] = tmva_absdzPV_;
612 gbrVals_[14] = tmva_absdz_;
613 gbrVals_[15] = tmva_absd0_;
615 if (
mvaType_[selIndex] ==
"Prompt"){
617 mvaVals_[current] = gbrVal;
619 float detachedGbrVals_[12];
620 for(
int jjj = 0; jjj < 12; jjj++)detachedGbrVals_[jjj] = gbrVals_[jjj];
622 mvaVals_[current] = gbrVal;
627 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
630 auto mvas = std::make_unique<MVACollection>(mvaVals_.begin(),mvaVals_.end());
638 Point p_dz(0,0,-99999);
639 float bestWeight = 0;
641 bool weightMatch =
false;
642 for(
auto const & vertex : vertices){
643 float w = vertex.trackWeight(track);
644 Point v_pos = vertex.position();
650 float dz = fabs(track.
get()->
dz(v_pos));
656 if(weightMatch)
return p;
std::vector< double > chi2n_no1Dmod_par_
value_type const * get() const
T getParameter(std::string const &) const
std::vector< uint32_t > min_nhits_
std::vector< double > chi2n_par_
std::vector< std::vector< double > > d0_par1_
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.
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_
#define DEFINE_FWK_MODULE(type)
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
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_
virtual ~MultiTrackSelector()
destructor
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_
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
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Abs< T >::type abs(const T &t)
std::vector< std::vector< double > > dz_par1_
unsigned short numberOfValidHits() const
number of valid hits found
std::vector< std::vector< double > > dz_par2_
std::vector< std::vector< double > > res_par_
std::vector< double > max_relpterr_
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
void beginStream(edm::StreamID) override final
std::vector< std::string > forestLabel_
int trackerLayersWithoutMeasurement(HitCategory category) const
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
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...
std::vector< std::vector< double > > d0_par2_
double GetClassifier(const float *vector) const
std::vector< double > max_d0_
Impact parameter absolute cuts.
std::vector< bool > useMVAonly_
T const * product() const
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< GBRForest * > forest_