9 #include <Math/DistFunc.h>
18 static T op(
T t) {
return PowN<
N/2>::op(t)*PowN<(
N+1)/2>::op(t);}
23 static T op(
T t) {
return T(1);}
28 static T op(
T t) {
return t;}
33 static T op(
T t) {
return t*
t;}
39 case 4:
return PowN<4>::op(t);
40 case 3:
return PowN<3>::op(t);
41 case 8:
return PowN<8>::op(t);
42 case 2:
return PowN<2>::op(t);
43 case 5:
return PowN<5>::op(t);
44 case 6:
return PowN<6>::op(t);
45 case 7:
return PowN<7>::op(t);
46 case 0:
return PowN<0>::op(t);
47 case 1:
return PowN<1>::op(t);
60 useForestFromDB_ =
true;
68 useVertices_( cfg.getParameter<bool>(
"useVertices" ) ),
69 useVtxError_( cfg.getParameter<bool>(
"useVtxError" ) )
74 edm::LogWarning(
"MultiTRackSelector") <<
"you are executing buggy code, if intentional please help to fix it";
89 if(cfg.
exists(
"GBRForestFileName")){
96 std::vector<edm::ParameterSet> trkSelectors( cfg.
getParameter<std::vector< edm::ParameterSet> >(
"trackSelectors") );
100 res_par_.reserve(trkSelectors.size());
103 d0_par1_.reserve(trkSelectors.size());
104 dz_par1_.reserve(trkSelectors.size());
105 d0_par2_.reserve(trkSelectors.size());
106 dz_par2_.reserve(trkSelectors.size());
108 max_d0_.reserve(trkSelectors.size());
109 max_z0_.reserve(trkSelectors.size());
110 nSigmaZ_.reserve(trkSelectors.size());
123 min_eta_.reserve(trkSelectors.size());
124 max_eta_.reserve(trkSelectors.size());
125 useMVA_.reserve(trkSelectors.size());
127 min_MVA_.reserve(trkSelectors.size());
130 produces<edm::ValueMap<float> >(
"MVAVals");
132 for (
unsigned int i=0;
i<trkSelectors.size();
i++) {
139 res_par_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"res_par") );
140 chi2n_par_.push_back( trkSelectors[
i].getParameter<double>(
"chi2n_par") );
142 d0_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par1"));
143 dz_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par1"));
144 d0_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par2"));
145 dz_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par2"));
149 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
150 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
151 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
153 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers") );
154 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers") );
155 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
156 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
159 keepAllTracks_.push_back( trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
160 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
161 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
163 trkSelectors[
i].existsAs<int32_t>(
"max_minMissHitOutOrIn") ?
164 trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn") : 99);
166 trkSelectors[
i].existsAs<double>(
"max_lostHitFraction") ?
167 trkSelectors[
i].getParameter<double>(
"max_lostHitFraction") : 1.0);
168 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ?
169 trkSelectors[
i].getParameter<double>(
"min_eta"):-9999);
170 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ?
171 trkSelectors[
i].getParameter<double>(
"max_eta"):9999);
175 if (qualityStr !=
"") {
177 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
181 "You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit") <<
" as it is 'undefQuality' or unknown.\n";
184 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
185 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
192 name_.push_back( trkSelectors[i].getParameter<std::string>(
"name") );
199 for (
unsigned int j=0;
j<
i;
j++)
205 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in MultiTrackSelector "
206 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
211 produces<edm::ValueMap<int> >(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
213 bool thisMVA =
false;
214 if(trkSelectors[i].exists(
"useMVA"))thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
218 if(trkSelectors[i].exists(
"minMVA"))minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
250 using namespace reco;
273 unsigned int trkSize=srcTracks.size();
274 std::vector<int> selTracksSave(
qualityToSet_.size()*trkSize,0);
276 std::vector<float> mvaVals_(srcTracks.size(),-99.f);
280 std::vector<int> selTracks(trkSize,0);
281 auto_ptr<edm::ValueMap<int> > selTracksValueMap = auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
284 std::vector<Point> points;
285 std::vector<float> vterr, vzerr;
290 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
291 const Track & trk = * it;
294 LogTrace(
"TrackSelection") <<
"ready to check track with pt="<< trk.
pt() ;
307 ok =
select(
i,vertexBeamSpot, srcHits, trk, points, vterr, vzerr,mvaVal);
309 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" NOT selected";
316 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" selected";
334 if (!points.empty()) {
336 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::looseSetWithPV));
339 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::looseSetWithPV));
340 selTracks[
current]=(selTracks[
current] | (1<<TrackBase::highPuritySetWithPV));
345 for (
unsigned int j=0;
j< trkSize;
j++ ) selTracksSave[
j+
i*trkSize]=selTracks[
j];
346 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
359 const std::vector<Point> &points,
360 std::vector<float> &vterr,
361 std::vector<float> &vzerr,
362 double mvaVal)
const {
372 if ( tk.
ndof() < 1E-5 )
return false;
379 if(mvaVal <
min_MVA_[tsNum])
return false;
391 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
396 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
399 float chi2n_no1Dmod = chi2n;
402 auto ith = tk.
extra()->firstRecHit();
404 for (; ith<edh; ++ith) {
408 if (count1dhits > 0) {
409 float chi2 = tk.
chi2();
410 float ndof = tk.
ndof();
411 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
415 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
430 int minLost =
std::min(lostIn,lostOut);
444 float nomdzE = nomd0E*(std::cosh(
eta));
453 bool primaryVertexZCompatibility(
false);
454 bool primaryVertexD0Compatibility(
false);
456 if (points.empty()) {
458 if (
abs(dz) < hypot(vertexBeamSpot.
sigmaZ()*
nSigmaZ_[tsNum],dzCut) ) primaryVertexZCompatibility =
true;
460 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
464 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
465 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
466 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
470 float dzErrPV =
std::sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
471 float d0ErrPV =
std::sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
475 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
478 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
480 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
481 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
483 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
491 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
492 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
493 if (
abs(dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
494 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
498 <<
" d0 compatibility? " << primaryVertexD0Compatibility
499 <<
" z compatibility? " << primaryVertexZCompatibility ;
502 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
511 std::vector<Point> &points,
512 std::vector<float> &vterr,
513 std::vector<float> &vzerr)
const {
515 using namespace reco;
517 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
519 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" "
520 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
524 points.push_back(it->position());
525 vterr.push_back(
sqrt(it->yError()*it->xError()));
526 vzerr.push_back(it->zError());
527 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
528 toTake--;
if (toTake == 0)
break;
538 using namespace reco;
544 assert(mvaVals_.size()==srcTracks.size());
552 auto_ptr<edm::ValueMap<float> >mvaValValueMap = auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
558 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
560 evt.
put(mvaValValueMap,
"MVAVals");
566 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++
current) {
567 const Track & trk = * it;
568 auto tmva_ndof_ = trk.
ndof();
574 float chi2n_no1Dmod = chi2n;
577 auto ith = trk.
extra()->firstRecHit();
579 for (; ith<edh; ++ith) {
583 if (count1dhits > 0) {
584 float chi2 = trk.
chi2();
585 float ndof = trk.
ndof();
586 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
588 auto tmva_chi2n_ = chi2n;
589 auto tmva_chi2n_no1dmod_ = chi2n_no1Dmod;
590 auto tmva_eta_ = trk.
eta();
595 auto tmva_minlost_ =
std::min(lostIn,lostOut);
599 gbrVals_[0] = tmva_lostmidfrac_;
600 gbrVals_[1] = tmva_minlost_;
601 gbrVals_[2] = tmva_nhits_;
602 gbrVals_[3] = tmva_relpterr_;
603 gbrVals_[4] = tmva_eta_;
604 gbrVals_[5] = tmva_chi2n_no1dmod_;
605 gbrVals_[6] = tmva_chi2n_;
606 gbrVals_[7] = tmva_nlayerslost_;
607 gbrVals_[8] = tmva_nlayers3D_;
608 gbrVals_[9] = tmva_nlayers_;
609 gbrVals_[10] = tmva_ndof_;
616 forest = forestHandle.
product();
622 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
624 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_
virtual int dimension() const =0
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
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_
void beginStream(edm::StreamID) overridefinal
#define DEFINE_FWK_MODULE(type)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
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< 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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
double ndof() const
number of degrees of freedom of the fit
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
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
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.
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_