10 #include <Math/DistFunc.h>
16 MultiTrackSelector::MultiTrackSelector()
24 src_( cfg.getParameter<edm::InputTag>(
"src" ) ),
25 beamspot_( cfg.getParameter<edm::InputTag>(
"beamspot" ) ),
26 useVertices_( cfg.getParameter<bool>(
"useVertices" ) ),
27 useVtxError_( cfg.getParameter<bool>(
"useVtxError" ) ),
28 vertices_( useVertices_ ? cfg.getParameter<edm::InputTag>(
"vertices" ) : edm::InputTag(
"NONE"))
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";
268 if (!points.empty()) {
278 for (
unsigned int j=0;
j< trkSize;
j++ ) selTracksSave[
j+
i*trkSize]=selTracks[
j];
279 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
291 const std::vector<Point> &points,
292 std::vector<float> &vterr,
293 std::vector<float> &vzerr,
300 if ( tk.
ndof() < 1E-5 )
return false;
307 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
312 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
315 float chi2n_no1Dmod = chi2n;
321 if (
typeid(*hit) ==
typeid(SiStripRecHit1D)) ++count1dhits;
324 if (count1dhits > 0) {
325 float chi2 = tk.
chi2();
326 float ndof = tk.
ndof();
327 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
331 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
341 float relpterr = float(tk.
ptError())/pt;
348 int minLost =
std::min(lostIn,lostOut);
360 if(mvaVal <
min_MVA_[tsNum])
return false;
374 float nomdzE = nomd0E*(std::cosh(
eta));
383 bool primaryVertexZCompatibility(
false);
384 bool primaryVertexD0Compatibility(
false);
386 if (points.empty()) {
388 if (
abs(dz) < hypot(vertexBeamSpot.
sigmaZ()*
nSigmaZ_[tsNum],dzCut) ) primaryVertexZCompatibility =
true;
390 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
394 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
395 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
396 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
400 float dzErrPV =
sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
401 float d0ErrPV =
sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
405 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
408 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
410 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
411 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
413 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
421 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
422 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
423 if (
abs(dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
424 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
428 <<
" d0 compatibility? " << primaryVertexD0Compatibility
429 <<
" z compatibility? " << primaryVertexZCompatibility ;
432 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
441 std::vector<Point> &points,
442 std::vector<float> &vterr,
443 std::vector<float> &vzerr) {
445 using namespace reco;
447 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
449 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" "
450 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
454 points.push_back(it->position());
455 vterr.push_back(
sqrt(it->yError()*it->xError()));
456 vzerr.push_back(it->zError());
457 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
458 toTake--;
if (toTake == 0)
break;
468 using namespace reco;
475 auto_ptr<edm::ValueMap<float> >mvaValValueMap = auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
482 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
487 evt.
put(mvaValValueMap,
"MVAVals");
505 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
506 const Track & trk = * it;
512 float chi2n_no1Dmod = chi2n;
518 if (
typeid(*hit) ==
typeid(SiStripRecHit1D)) ++count1dhits;
521 if (count1dhits > 0) {
522 float chi2 = trk.
chi2();
523 float ndof = trk.
ndof();
524 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
553 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)
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_
int numberOfValidStripLayersWithMonoAndStereo() const
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)
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.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
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)
edm::InputTag src_
source collection label
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
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?
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
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_
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.