10 #include <Math/DistFunc.h>
16 MultiTrackSelector::MultiTrackSelector()
25 beamspot_( consumes<
reco::
BeamSpot>( cfg.getParameter<edm::InputTag>(
"beamspot" ) ) ),
26 useVertices_( cfg.getParameter<bool>(
"useVertices" ) ),
27 useVtxError_( cfg.getParameter<bool>(
"useVtxError" ) )
47 if(cfg.
exists(
"GBRForestFileName")){
54 std::vector<edm::ParameterSet> trkSelectors( cfg.
getParameter<std::vector< edm::ParameterSet> >(
"trackSelectors") );
58 res_par_.reserve(trkSelectors.size());
61 d0_par1_.reserve(trkSelectors.size());
62 dz_par1_.reserve(trkSelectors.size());
63 d0_par2_.reserve(trkSelectors.size());
64 dz_par2_.reserve(trkSelectors.size());
66 max_d0_.reserve(trkSelectors.size());
67 max_z0_.reserve(trkSelectors.size());
68 nSigmaZ_.reserve(trkSelectors.size());
81 min_eta_.reserve(trkSelectors.size());
82 max_eta_.reserve(trkSelectors.size());
83 useMVA_.reserve(trkSelectors.size());
85 min_MVA_.reserve(trkSelectors.size());
88 produces<edm::ValueMap<float> >(
"MVAVals");
90 for (
unsigned int i=0;
i<trkSelectors.size();
i++) {
97 res_par_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"res_par") );
98 chi2n_par_.push_back( trkSelectors[
i].getParameter<double>(
"chi2n_par") );
100 d0_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par1"));
101 dz_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par1"));
102 d0_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par2"));
103 dz_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par2"));
107 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
108 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
109 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
111 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers") );
112 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers") );
113 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
114 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
117 keepAllTracks_.push_back( trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
118 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
119 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
121 trkSelectors[
i].existsAs<int32_t>(
"max_minMissHitOutOrIn") ?
122 trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn") : 99);
124 trkSelectors[
i].existsAs<double>(
"max_lostHitFraction") ?
125 trkSelectors[
i].getParameter<double>(
"max_lostHitFraction") : 1.0);
126 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ?
127 trkSelectors[
i].getParameter<double>(
"min_eta"):-9999);
128 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ?
129 trkSelectors[
i].getParameter<double>(
"max_eta"):9999);
133 if (qualityStr !=
"") {
139 "You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit") <<
" as it is 'undefQuality' or unknown.\n";
142 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
143 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
150 name_.push_back( trkSelectors[i].getParameter<std::string>(
"name") );
157 for (
unsigned int j=0;
j<
i;
j++)
163 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in MultiTrackSelector "
164 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
169 produces<edm::ValueMap<int> >(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
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");
198 using namespace reco;
215 unsigned int trkSize=srcTracks.size();
216 std::vector<int> selTracksSave(
qualityToSet_.size()*trkSize,0);
221 std::vector<int> selTracks(trkSize,0);
222 auto_ptr<edm::ValueMap<int> > selTracksValueMap = auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
225 std::vector<Point> points;
226 std::vector<float> vterr, vzerr;
231 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
232 const Track & trk = * it;
235 LogTrace(
"TrackSelection") <<
"ready to check track with pt="<< trk.
pt() ;
248 ok =
select(
i,vertexBeamSpot, trk, points, vterr, vzerr,mvaVal);
250 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" NOT selected";
257 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" selected";
275 if (!points.empty()) {
286 for (
unsigned int j=0;
j< trkSize;
j++ ) selTracksSave[
j+
i*trkSize]=selTracks[
j];
287 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
299 const std::vector<Point> &points,
300 std::vector<float> &vterr,
301 std::vector<float> &vzerr,
308 if ( tk.
ndof() < 1E-5 )
return false;
315 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
320 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
323 float chi2n_no1Dmod = chi2n;
329 if (
typeid(*hit) ==
typeid(SiStripRecHit1D)) ++count1dhits;
332 if (count1dhits > 0) {
333 float chi2 = tk.
chi2();
334 float ndof = tk.
ndof();
335 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
339 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
356 int minLost =
std::min(lostIn,lostOut);
368 if(mvaVal <
min_MVA_[tsNum])
return false;
382 float nomdzE = nomd0E*(std::cosh(
eta));
391 bool primaryVertexZCompatibility(
false);
392 bool primaryVertexD0Compatibility(
false);
394 if (points.empty()) {
396 if (
abs(dz) < hypot(vertexBeamSpot.
sigmaZ()*
nSigmaZ_[tsNum],dzCut) ) primaryVertexZCompatibility =
true;
398 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
402 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
403 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
404 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
408 float dzErrPV =
sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
409 float d0ErrPV =
sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
413 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
416 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
418 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
419 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
421 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
429 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
430 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
431 if (
abs(dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
432 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
436 <<
" d0 compatibility? " << primaryVertexD0Compatibility
437 <<
" z compatibility? " << primaryVertexZCompatibility ;
440 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
449 std::vector<Point> &points,
450 std::vector<float> &vterr,
451 std::vector<float> &vzerr) {
453 using namespace reco;
455 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
457 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" "
458 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
462 points.push_back(it->position());
463 vterr.push_back(
sqrt(it->yError()*it->xError()));
464 vzerr.push_back(it->zError());
465 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
466 toTake--;
if (toTake == 0)
break;
476 using namespace reco;
483 auto_ptr<edm::ValueMap<float> >mvaValValueMap = auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
490 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
495 evt.
put(mvaValValueMap,
"MVAVals");
513 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
514 const Track & trk = * it;
520 float chi2n_no1Dmod = chi2n;
526 if (
typeid(*hit) ==
typeid(SiStripRecHit1D)) ++count1dhits;
529 if (count1dhits > 0) {
530 float chi2 = trk.
chi2();
531 float ndof = trk.
ndof();
532 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
561 evt.
put(mvaValValueMap,
"MVAVals");
float tmva_chi2n_no1dmod_
std::vector< double > chi2n_par_
T getParameter(std::string const &) const
std::vector< double > max_d0NoPV_
std::vector< double > max_d0_
Impact parameter absolute cuts.
double d0Error() const
error on d0
std::vector< std::vector< double > > dz_par1_
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 > > d0_par1_
int numberOfLostTrackerHits() const
std::vector< std::vector< double > > d0_par2_
std::vector< bool > applyAbsCutsIfNoPV_
std::vector< double > max_z0NoPV_
std::vector< Track > TrackCollection
collection of Tracks
bool exists(std::string const ¶meterName) const
checks if a parameter exists
int pixelLayersWithMeasurement() const
int trackerLayersWithoutMeasurement() 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< uint32_t > min_3Dlayers_
std::vector< bool > useMVA_
std::vector< int32_t > vtxNumber_
vertex cuts
std::vector< double > nSigmaZ_
std::vector< std::string > name_
const HitPattern & trackerExpectedHitsOuter() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers after the last...
double eta() const
pseudorapidity of momentum vector
std::vector< bool > keepAllTracks_
const T & max(const T &a, const T &b)
double chi2() const
chi-squared of the fit
std::vector< std::vector< double > > res_par_
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
virtual ~MultiTrackSelector()
destructor
void processMVA(edm::Event &evt, const edm::EventSetup &es)
double pt() const
track transverse momentum
std::vector< uint32_t > min_nhits_
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Abs< T >::type abs(const T &t)
std::vector< unsigned int > preFilter_
const HitPattern & trackerExpectedHitsInner() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers before the fir...
unsigned short numberOfValidHits() const
number of valid hits found
std::vector< double > max_eta_
std::vector< double > max_relpterr_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
MultiTrackSelector()
constructor
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
std::vector< uint32_t > min_hits_bypass_
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr)
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
virtual void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
std::vector< double > min_MVA_
static TrackQuality qualityByName(const std::string &name)
std::vector< double > chi2n_no1Dmod_par_
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
double sigmaZ() const
sigma z
edm::EDGetTokenT< reco::BeamSpot > beamspot_
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
T const * product() const
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)
return class, or -1 if rejected
std::vector< TrackBase::TrackQuality > qualityToSet_
std::vector< bool > setQualityBit_
do I have to set a quality bit?
edm::EDGetTokenT< reco::VertexCollection > vertices_
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
double dzPV(const LorentzVector &vtx, const LorentzVector &p4, const LorentzVector &pv)
std::vector< double > max_z0_
unsigned short found() const
Number of valid hits on track.
const Point & position() const
position
std::vector< uint32_t > max_lostLayers_
std::vector< double > mvaVals_
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 > min_eta_
std::vector< std::vector< double > > dz_par2_
int numberOfValidStripLayersWithMonoAndStereo(uint32_t stripdet, uint32_t layer) const
std::vector< int32_t > max_minMissHitOutOrIn_
std::vector< bool > applyAdaptedPVCuts_
std::vector< int32_t > max_lostHitFraction_
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
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.