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;
66 mvavars_indices.clear();
67 for (
unsigned i=0;
i<forestVars_.size();
i++)
77 if (v==
"nhits") ind=
nhits;
78 if (v==
"eta") ind=
eta;
80 if (v==
"chi2n") ind=
chi2n ;
84 if (v==
"ndof") ind=
ndof ;
87 if (ind==-1)
edm::LogWarning(
"HIMultiTrackSelector") <<
"Unknown forest variable "<<v<<
". Please make sure it's in the list of supported variables\n";
89 mvavars_indices.push_back(ind);
97 beamspot_( consumes<
reco::
BeamSpot>( cfg.getParameter<
edm::InputTag>(
"beamspot" ) ) ),
98 useVertices_( cfg.getParameter<
bool>(
"useVertices" ) ),
99 useVtxError_( cfg.getParameter<
bool>(
"useVtxError" ) )
105 if(cfg.
exists(
"applyPixelMergingCuts"))
120 if(cfg.
exists(
"GBRForestVars")) {
124 if(cfg.
exists(
"GBRForestFileName")){
130 std::vector<edm::ParameterSet> trkSelectors( cfg.
getParameter<std::vector< edm::ParameterSet> >(
"trackSelectors") );
134 res_par_.reserve(trkSelectors.size());
137 d0_par1_.reserve(trkSelectors.size());
138 dz_par1_.reserve(trkSelectors.size());
139 d0_par2_.reserve(trkSelectors.size());
140 dz_par2_.reserve(trkSelectors.size());
142 max_d0_.reserve(trkSelectors.size());
143 max_z0_.reserve(trkSelectors.size());
144 nSigmaZ_.reserve(trkSelectors.size());
159 min_eta_.reserve(trkSelectors.size());
160 max_eta_.reserve(trkSelectors.size());
161 useMVA_.reserve(trkSelectors.size());
163 min_MVA_.reserve(trkSelectors.size());
166 produces<edm::ValueMap<float> >(
"MVAVals");
168 for (
unsigned int i=0;
i<trkSelectors.size();
i++) {
175 res_par_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"res_par") );
176 chi2n_par_.push_back( trkSelectors[
i].getParameter<double>(
"chi2n_par") );
178 d0_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par1"));
179 dz_par1_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par1"));
180 d0_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"d0_par2"));
181 dz_par2_.push_back(trkSelectors[
i].getParameter< std::vector<double> >(
"dz_par2"));
185 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
186 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
187 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
189 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers") );
190 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers") );
191 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
192 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
195 keepAllTracks_.push_back( trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
196 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
197 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
199 trkSelectors[
i].existsAs<int32_t>(
"max_minMissHitOutOrIn") ?
200 trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn") : 99);
202 trkSelectors[
i].existsAs<double>(
"max_lostHitFraction") ?
203 trkSelectors[
i].getParameter<double>(
"max_lostHitFraction") : 1.0);
204 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ?
205 trkSelectors[
i].getParameter<double>(
"min_eta"):-9999);
206 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ?
207 trkSelectors[
i].getParameter<double>(
"max_eta"):9999);
211 if (!qualityStr.empty()) {
213 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
217 "You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit") <<
" as it is 'undefQuality' or unknown.\n";
220 max_d0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_d0NoPV"));
221 max_z0NoPV_.push_back(trkSelectors[i].getParameter<double>(
"max_z0NoPV"));
228 name_.push_back( trkSelectors[i].getParameter<std::string>(
"name") );
233 if (!pfName.empty()) {
235 for (
unsigned int j=0; j<
i; j++)
236 if (
name_[j]==pfName ) {
241 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in HIMultiTrackSelector " 242 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
248 pixel_pTMinCut_.push_back(trkSelectors[i].getParameter< std::vector<double> >(
"pixel_pTMinCut"));
249 pixel_pTMaxCut_.push_back(trkSelectors[i].getParameter< std::vector<double> >(
"pixel_pTMaxCut"));
253 produces<edm::ValueMap<int> >(
name_[
i]).setBranchAlias(
name_[i] +
"TrackQuals");
255 bool thisMVA =
false;
256 if(trkSelectors[i].exists(
"useMVA"))thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
260 if(trkSelectors[i].exists(
"minMVA"))minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
292 using namespace reco;
315 unsigned int trkSize=srcTracks.size();
316 std::vector<int> selTracksSave(
qualityToSet_.size()*trkSize,0);
318 std::vector<float> mvaVals_(srcTracks.size(),-99.f);
322 std::vector<int> selTracks(trkSize,0);
323 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
326 std::vector<Point>
points;
327 std::vector<float> vterr, vzerr;
332 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
333 const Track & trk = * it;
336 LogTrace(
"TrackSelection") <<
"ready to check track with pt="<< trk.
pt() ;
342 selTracks[current]=-1;
349 ok =
select(
i,vertexBeamSpot, srcHits, trk, points, vterr, vzerr,mvaVal);
351 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" NOT selected";
353 selTracks[current]=-1;
358 LogTrace(
"TrackSelection") <<
"track with pt="<< trk.
pt() <<
" selected";
362 selTracks[current]=selTracksSave[
preFilter_[
i]*trkSize+current];
370 selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
373 selTracks[current]=(selTracks[current] | (1<<TrackBase::loose));
374 selTracks[current]=(selTracks[current] | (1<<TrackBase::tight));
377 if (!points.empty()) {
379 selTracks[current]=(selTracks[current] | (1<<TrackBase::looseSetWithPV));
382 selTracks[current]=(selTracks[current] | (1<<TrackBase::looseSetWithPV));
383 selTracks[current]=(selTracks[current] | (1<<TrackBase::highPuritySetWithPV));
388 for (
unsigned int j=0; j< trkSize; j++ ) selTracksSave[j+
i*trkSize]=selTracks[j];
389 filler.insert(hSrcTrack, selTracks.begin(),selTracks.end());
402 const std::vector<Point> &
points,
403 std::vector<float> &vterr,
404 std::vector<float> &vzerr,
405 double mvaVal)
const {
415 if ( tk.
ndof() < 1E-5 )
return false;
422 if(mvaVal <
min_MVA_[tsNum])
return false;
else return true;
434 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " << nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs " 438 if (nlayersLost > max_lostLayers_[tsNum])
return false;
439 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
442 float chi2n_no1Dmod =
chi2n;
445 auto ith = tk.
extra()->firstRecHit();
447 for (; ith<edh; ++ith) {
451 if (count1dhits > 0) {
454 chi2n = (chi2+count1dhits)/
float(ndof+count1dhits);
458 if (chi2n >
chi2n_par_[tsNum]*nlayers)
return false;
473 int minLost =
std::min(lostIn,lostOut);
504 float nomdzE = nomd0E*(std::cosh(eta));
513 bool primaryVertexZCompatibility(
false);
514 bool primaryVertexD0Compatibility(
false);
516 if (points.empty()) {
520 if (
abs(d0) < d0Cut) primaryVertexD0Compatibility =
true;
524 for (std::vector<Point>::const_iterator
point = points.begin(),
end = points.end();
point !=
end; ++
point) {
525 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
526 if(primaryVertexZCompatibility && primaryVertexD0Compatibility)
break;
530 float dzErrPV =
std::sqrt(dzE*dzE+vzerr[iv]*vzerr[iv]);
531 float d0ErrPV =
std::sqrt(d0E*d0E+vterr[iv]*vterr[iv]);
535 abs(dzPV) <
max_z0_[tsNum]) primaryVertexZCompatibility =
true;
538 abs(d0PV) <
max_d0_[tsNum]) primaryVertexD0Compatibility =
true;
540 if (
abs(dzPV) < dzCut) primaryVertexZCompatibility =
true;
541 if (
abs(d0PV) < d0Cut) primaryVertexD0Compatibility =
true;
543 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " << dzCut <<
" " << d0Cut;
551 if (
abs(d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
return false;
552 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
553 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
return false;
554 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
558 <<
" d0 compatibility? " << primaryVertexD0Compatibility
559 <<
" z compatibility? " << primaryVertexZCompatibility ;
562 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
571 std::vector<Point> &
points,
572 std::vector<float> &vterr,
573 std::vector<float> &vzerr)
const {
575 using namespace reco;
577 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
579 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" " 580 << it->chi2() <<
" " << it->ndof() <<
" " << TMath::Prob(it->chi2(),
static_cast<int32_t
>(it->ndof()));
584 points.push_back(it->position());
585 vterr.push_back(
sqrt(it->yError()*it->xError()));
586 vzerr.push_back(it->zError());
587 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
588 toTake--;
if (toTake == 0)
break;
598 using namespace reco;
604 assert(mvaVals_.size()==srcTracks.size());
612 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
618 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
628 for (TrackCollection::const_iterator it = srcTracks.begin(), ed = srcTracks.end(); it != ed; ++it, ++current) {
629 const Track & trk = * it;
642 auto ith = trk.
extra()->firstRecHit();
644 for (; ith<edh; ++ith) {
648 if (count1dhits > 0) {
651 chi2n1d = (chi2+count1dhits)/
float(ndof+count1dhits);
654 mvavalues[
chi2n] = chi2n1d;
656 mvavalues[
eta] = trk.
eta();
680 std::vector<float> gbrValues;
692 forest = forestHandle.
product();
696 mvaVals_[current] = gbrVal;
698 mvaFiller.insert(hSrcTrack,mvaVals_.begin(),mvaVals_.end());
std::vector< std::string > name_
T getParameter(std::string const &) const
double d0Error() const
error on d0
std::vector< uint32_t > max_lostLayers_
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
~HIMultiTrackSelector() override
destructor
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool applyPixelMergingCuts_
std::vector< uint32_t > min_hits_bypass_
const TrackExtraRef & extra() const
reference to "extra" object
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 > > pixel_pTMaxCut_
double dxyError() const
error on dxy
#define DEFINE_FWK_MODULE(type)
std::vector< uint32_t > min_nhits_
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
std::vector< bool > useMVA_
std::vector< std::vector< double > > dz_par1_
std::vector< Track > TrackCollection
collection of Tracks
std::vector< double > chi2n_par_
double etaError() const
error on eta
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr) 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< std::vector< double > > res_par_
std::vector< int32_t > max_minMissHitOutOrIn_
std::vector< double > chi2n_no1Dmod_par_
std::vector< uint32_t > min_3Dlayers_
int pixelLayersWithMeasurement() const
void beginStream(edm::StreamID) final
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual void run(edm::Event &evt, const edm::EventSetup &es) const
int trackerLayersWithMeasurement() const
std::vector< double > min_eta_
int numberOfLostTrackerHits(HitCategory category) const
std::vector< double > max_eta_
std::vector< std::vector< double > > d0_par2_
std::vector< double > max_d0NoPV_
std::vector< std::vector< double > > d0_par1_
double eta() const
pseudorapidity of momentum vector
int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
edm::EDGetTokenT< reco::VertexCollection > vertices_
double chi2() const
chi-squared of the fit
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
std::vector< bool > setQualityBit_
do I have to set a quality bit?
double ndof() const
number of degrees of freedom of the fit
virtual int dimension() const =0
double pt() const
track transverse momentum
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
std::vector< int32_t > vtxNumber_
vertex cuts
Abs< T >::type abs(const T &t)
std::vector< double > max_z0_
unsigned short numberOfValidHits() const
number of valid hits found
edm::EDGetTokenT< TrackingRecHitCollection > hSrc_
std::vector< std::vector< double > > dz_par2_
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
std::vector< double > nSigmaZ_
std::vector< double > max_d0_
Impact parameter absolute cuts.
std::vector< bool > applyAdaptedPVCuts_
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< double > max_relpterr_
std::vector< int > mvavars_indices
void processMVA(edm::Event &evt, const edm::EventSetup &es, std::vector< float > &mvaVals_, const reco::VertexCollection &hVtx) const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
std::vector< std::string > forestVars_
double sigmaZ() const
sigma z
std::vector< int32_t > max_lostHitFraction_
edm::EDGetTokenT< reco::BeamSpot > beamspot_
std::vector< bool > applyAbsCutsIfNoPV_
int trackerLayersWithoutMeasurement(HitCategory category) const
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
std::vector< std::vector< double > > pixel_pTMinCut_
static int position[264][3]
HIMultiTrackSelector()
constructor
std::vector< double > max_z0NoPV_
std::vector< bool > keepAllTracks_
const Point & position() const
position
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< double > min_MVA_
double GetClassifier(const float *vector) const
std::vector< unsigned int > preFilter_
T const * product() const
std::vector< reco::TrackBase::TrackQuality > qualityToSet_
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