9 #include <Math/DistFunc.h>
17 useForestFromDB_ =
true;
23 beamspot_( consumes<
reco::
BeamSpot>( cfg.getParameter<edm::InputTag>(
"beamspot" ) ) ),
24 useVertices_( cfg.getParameter<bool>(
"useVertices" ) ),
25 useVtxError_( cfg.getParameter<bool>(
"useVtxError" ) )
43 if(cfg.
exists(
"GBRForestFileName")){
50 std::vector<edm::ParameterSet> trkSelectors( cfg.
getParameter<std::vector< edm::ParameterSet> >(
"trackSelectors") );
54 res_par_.reserve(trkSelectors.size());
57 d0_par1_.reserve(trkSelectors.size());
58 dz_par1_.reserve(trkSelectors.size());
59 d0_par2_.reserve(trkSelectors.size());
60 dz_par2_.reserve(trkSelectors.size());
62 max_d0_.reserve(trkSelectors.size());
63 max_z0_.reserve(trkSelectors.size());
64 nSigmaZ_.reserve(trkSelectors.size());
77 min_eta_.reserve(trkSelectors.size());
78 max_eta_.reserve(trkSelectors.size());
79 useMVA_.reserve(trkSelectors.size());
81 min_MVA_.reserve(trkSelectors.size());
84 produces<edm::ValueMap<float> >(
"MVAVals");
86 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].existsAs<int32_t>(
"max_minMissHitOutOrIn") ?
118 trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn") : 99);
120 trkSelectors[
i].existsAs<double>(
"max_lostHitFraction") ?
121 trkSelectors[
i].getParameter<double>(
"max_lostHitFraction") : 1.0);
122 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ?
123 trkSelectors[
i].getParameter<double>(
"min_eta"):-9999);
124 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ?
125 trkSelectors[
i].getParameter<double>(
"max_eta"):9999);
129 if (qualityStr !=
"") {
131 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
135 "You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit") <<
" as it is 'undefQuality' or unknown.\n";
138 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
139 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
146 name_.push_back( trkSelectors[i].getParameter<std::string>(
"name") );
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");
165 produces<edm::ValueMap<int> >(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
167 bool thisMVA =
false;
168 if(trkSelectors[i].exists(
"useMVA"))thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
172 if(trkSelectors[i].exists(
"minMVA"))minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
204 using namespace reco;
221 unsigned int trkSize=srcTracks.size();
222 std::vector<int> selTracksSave(
qualityToSet_.size()*trkSize,0);
224 std::vector<float> mvaVals_(srcTracks.size(),-99.f);
228 std::vector<int> selTracks(trkSize,0);
229 auto_ptr<edm::ValueMap<int> > selTracksValueMap = auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
232 std::vector<Point> points;
233 std::vector<float> vterr, vzerr;
238 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
239 const Track & trk = * it;
242 LogTrace(
"TrackSelection") <<
"ready to check track with pt="<< trk.
pt() ;
255 ok =
select(
i,vertexBeamSpot, trk, points, vterr, vzerr,mvaVal);
257 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" NOT selected";
264 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" selected";
282 if (!points.empty()) {
284 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::looseSetWithPV));
287 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::looseSetWithPV));
288 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::highPuritySetWithPV));
293 for (
unsigned int j=0;
j< trkSize;
j++ ) selTracksSave[
j+
i*trkSize]=selTracks[
j];
294 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
306 const std::vector<Point> &points,
307 std::vector<float> &vterr,
308 std::vector<float> &vzerr,
309 double mvaVal)
const {
315 if ( tk.
ndof() < 1E-5 )
return false;
322 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
327 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
330 float chi2n_no1Dmod = chi2n;
339 if (count1dhits > 0) {
340 float chi2 = tk.
chi2();
341 float ndof = tk.
ndof();
342 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
346 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
363 int minLost =
std::min(lostIn,lostOut);
375 if(mvaVal <
min_MVA_[tsNum])
return false;
389 float nomdzE = nomd0E*(std::cosh(
eta));
398 bool primaryVertexZCompatibility(
false);
399 bool primaryVertexD0Compatibility(
false);
401 if (points.empty()) {
403 if (
abs(dz) < hypot(vertexBeamSpot.
sigmaZ()*
nSigmaZ_[tsNum],dzCut) ) primaryVertexZCompatibility =
true;
405 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
409 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
410 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
411 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
415 float dzErrPV =
sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
416 float d0ErrPV =
sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
420 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
423 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
425 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
426 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
428 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
436 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
437 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
438 if (
abs(dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
439 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
443 <<
" d0 compatibility? " << primaryVertexD0Compatibility
444 <<
" z compatibility? " << primaryVertexZCompatibility ;
447 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
456 std::vector<Point> &points,
457 std::vector<float> &vterr,
458 std::vector<float> &vzerr)
const {
460 using namespace reco;
462 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
464 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" "
465 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
469 points.push_back(it->position());
470 vterr.push_back(
sqrt(it->yError()*it->xError()));
471 vzerr.push_back(it->zError());
472 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
473 toTake--;
if (toTake == 0)
break;
483 using namespace reco;
489 assert(mvaVals_.size()==srcTracks.size());
491 auto_ptr<edm::ValueMap<float> >mvaValValueMap = auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
497 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
499 evt.
put(mvaValValueMap,
"MVAVals");
505 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
506 const Track & trk = * it;
507 auto tmva_ndof_ = trk.
ndof();
513 float chi2n_no1Dmod = chi2n;
518 if ((*hit).dimension()==1) ++count1dhits;
520 if (count1dhits > 0) {
521 float chi2 = trk.
chi2();
522 float ndof = trk.
ndof();
523 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
525 auto tmva_chi2n_ = chi2n;
526 auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
527 auto tmva_eta_ = trk.
eta();
532 auto tmva_minlost_ =
std::min(lostIn,lostOut);
536 gbrVals_[0] = tmva_lostmidfrac_;
537 gbrVals_[1] = tmva_minlost_;
538 gbrVals_[2] = tmva_nhits_;
539 gbrVals_[3] = tmva_relpterr_;
540 gbrVals_[4] = tmva_eta_;
541 gbrVals_[5] = tmva_chi2n_no1dmod_;
542 gbrVals_[6] = tmva_chi2n_;
543 gbrVals_[7] = tmva_nlayerslost_;
544 gbrVals_[8] = tmva_nlayers3D_;
545 gbrVals_[9] = tmva_nlayers_;
546 gbrVals_[10] = tmva_ndof_;
553 forest = forestHandle.
product();
559 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
561 evt.
put(mvaValValueMap,
"MVAVals");
std::vector< double > chi2n_no1Dmod_par_
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_
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
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_
void beginStream(edm::StreamID) overridefinal
#define DEFINE_FWK_MODULE(type)
std::vector< uint32_t > min_hits_bypass_
std::vector< Track > TrackCollection
collection of Tracks
bool exists(std::string const ¶meterName) const
checks if a parameter exists
int pixelLayersWithMeasurement() const
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
int trackerLayersWithoutMeasurement(HitCategory category) const
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
std::vector< double > nSigmaZ_
std::vector< unsigned int > preFilter_
bool select(unsigned tsNum, const reco::BeamSpot &vertexBeamSpot, 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
virtual ~MultiTrackSelector()
destructor
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_
const T & max(const T &a, const T &b)
std::vector< double > min_eta_
double chi2() const
chi-squared of the fit
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
double ndof() const
number of degrees of freedom of the fit
int trackerLayersWithMeasurement() const
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_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
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
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 processMVA(edm::Event &evt, const edm::EventSetup &es, std::vector< float > &mvaVals_) const
T const * product() const
double dzPV(const LorentzVector &vtx, const LorentzVector &p4, const LorentzVector &pv)
unsigned short found() const
Number of valid hits on track.
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.
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_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.