23 auto makeMatchingCuts(std::vector<edm::ParameterSet>
const&
cutsPSets) {
24 std::vector<std::unique_ptr<TrajSeedMatcher::MatchingCuts> >
matchingCuts;
27 int version = cutPSet.getParameter<
int>(
"version");
30 matchingCuts.emplace_back(std::make_unique<TrajSeedMatcher::MatchingCutsV1>(cutPSet));
33 matchingCuts.emplace_back(std::make_unique<TrajSeedMatcher::MatchingCutsV2>(cutPSet));
36 throw cms::Exception(
"InvalidConfig") <<
" Error TrajSeedMatcher::TrajSeedMatcher pixel match cuts version " 37 <<
version <<
" not recognised" << std::endl;
57 const std::vector<TrajSeedMatcher::MatchInfo> makeMatchInfoVector(
58 std::vector<TrajSeedMatcher::SCHitMatch>
const& posCharge,
59 std::vector<TrajSeedMatcher::SCHitMatch>
const& negCharge) {
60 std::vector<TrajSeedMatcher::MatchInfo> matchInfos;
61 size_t nrHitsMax =
std::max(posCharge.size(), negCharge.size());
62 for (
size_t hitNr = 0; hitNr < nrHitsMax; hitNr++) {
63 DetId detIdPos = hitNr < posCharge.size() ? posCharge[hitNr].detId :
DetId(0);
67 DetId detIdNeg = hitNr < negCharge.size() ? negCharge[hitNr].detId :
DetId(0);
71 if (detIdPos != detIdNeg && (detIdPos.
rawId() != 0 && detIdNeg.
rawId() != 0)) {
72 cms::Exception(
"LogicError") <<
" error in " << __FILE__ <<
", " << __LINE__
73 <<
" hits to be combined have different detIDs, this should not be possible and " 74 "nothing good will come of it";
76 DetId detId = detIdPos.
rawId() != 0 ? detIdPos : detIdNeg;
77 matchInfos.push_back({detId, dRZPos, dRZNeg, dPhiPos, dPhiNeg});
84 : magFieldToken{cc.esConsumes()},
92 minNrHits{
pset.getParameter<std::vector<unsigned int> >(
"minNrHits")},
94 matchingCuts{makeMatchingCuts(
pset.getParameter<std::vector<edm::ParameterSet> >(
"matchingCuts"))} {
97 <<
" TrajSeedMatcher::TrajSeedMatcher minNrHitsValidLayerBins should be 1 less than minNrHits when its " 108 vprim_(vprim.x(), vprim.y(), vprim.z()),
110 magField_{iSetup.getData(cfg_.magFieldToken)},
111 magFieldParam_{iSetup.getData(cfg_.paramMagFieldToken)},
113 navSchool_{iSetup.getData(cfg_.navSchoolToken)},
114 detLayerGeom_{iSetup.getData(cfg_.detLayerGeomToken)},
115 forwardPropagator_(
alongMomentum, kElectronMass_, &magField_),
120 desc.add<
bool>(
"useRecoVertex",
false);
121 desc.add<
bool>(
"enableHitSkipping",
false);
122 desc.add<
bool>(
"requireExactMatchCount",
true);
123 desc.add<
bool>(
"useParamMagFieldIfDefined",
true);
127 desc.add<std::vector<int> >(
"minNrHitsValidLayerBins", {4});
128 desc.add<std::vector<unsigned int> >(
"minNrHits", {2, 3});
146 defaults.addParameter<
double>(
"dPhiMax", 0.04);
147 defaults.addParameter<
double>(
"dRZMax", 0.09);
148 defaults.addParameter<
double>(
"dRZMaxLowEtThres", 0.09);
149 defaults.addParameter<std::vector<double> >(
"dRZMaxLowEtEtaBins", std::vector<double>{1., 1.5});
150 defaults.addParameter<std::vector<double> >(
"dRZMaxLowEt", std::vector<double>{0.09, 0.09, 0.09});
151 defaults.addParameter<
int>(
"version", 1);
159 std::vector<SeedWithInfo> matchedSeeds;
169 int nrValidLayersPos = 0;
170 int nrValidLayersNeg = 0;
171 if (matchedHitsNeg.size() >= 2) {
174 if (matchedHitsPos.size() >= 2) {
178 int nrValidLayers =
std::max(nrValidLayersNeg, nrValidLayersPos);
180 bool matchCountPasses;
184 matchCountPasses = matchedHitsNeg.size() == nrHitsRequired || matchedHitsPos.size() == nrHitsRequired;
186 matchCountPasses = matchedHitsNeg.size() >= nrHitsRequired || matchedHitsPos.size() >= nrHitsRequired;
188 if (matchCountPasses) {
189 matchedSeeds.push_back({
seed, makeMatchInfoVector(matchedHitsPos, matchedHitsNeg), nrValidLayers});
200 const float candEta = candPos.
eta();
204 std::vector<SCHitMatch>
matches;
209 for (
size_t iHit = 0;
212 auto const&
recHit = *(
seed.recHits().begin() + iHit);
218 const bool doFirstMatch =
matches.empty();
220 auto const& trajState = doFirstMatch
227 auto const& vtxForMatchObject = doFirstMatch ?
vprim_ :
vertex;
228 auto match = makeSCHitMatch(vtxForMatchObject, trajState,
recHit, candEt, candEta, candPos.
phi(),
charge, 1);
238 prevHitPos =
match.hitPos;
248 auto sq = [](
float x) {
return x *
x; };
252 const double r1Diff = calRDiff(primeVtxPos, hitPos);
253 const double r2Diff = calRDiff(hitPos, candPos);
254 return hitPos.
z() - r1Diff * (candPos.
z() - hitPos.
z()) / r2Diff;
260 auto& trajStateFromVtxCache =
263 auto key =
hit.det()->gdetIndex();
264 auto res = trajStateFromVtxCache.find(
key);
265 if (
res != trajStateFromVtxCache.end())
269 auto val = trajStateFromVtxCache.emplace(
key,
propagator.propagate(initialState,
hit.det()->surface()));
270 return val.first->second;
278 auto& trajStateFromPointCache =
281 auto key = std::make_pair(
hit.det()->gdetIndex(),
point);
282 auto res = trajStateFromPointCache.find(
key);
283 if (
res != trajStateFromPointCache.end())
287 auto val = trajStateFromPointCache.emplace(
key,
propagator.propagate(initialState,
hit.det()->surface()));
288 return val.first->second;
318 if (detLayer ==
nullptr)
325 int nrValidLayers = 1;
326 int nrPixInLayers = 0;
327 int nrPixOutLayers = 0;
328 for (
auto layer : inLayers) {
335 for (
auto layer : outLayers) {
342 return nrValidLayers;
347 const Propagator& propToLayerFromState)
const {
353 const std::vector<GeometricSearchDet::DetWithState>& detWithState =
354 layer.compatibleDets(hitSurState, propToLayerFromState,
estimator);
355 if (detWithState.empty())
358 DetId id = detWithState.front().first->geographicalId();
376 : dPhiMax_(
pset.getParameter<double>(
"dPhiMax")),
377 dRZMax_(
pset.getParameter<double>(
"dRZMax")),
378 dRZMaxLowEtThres_(
pset.getParameter<double>(
"dRZMaxLowEtThres")),
379 dRZMaxLowEtEtaBins_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEtEtaBins")),
380 dRZMaxLowEt_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEt")) {
382 throw cms::Exception(
"InvalidConfig") <<
" dRZMaxLowEtEtaBins should be 1 less than dRZMaxLowEt when its " 388 if (dPhiMax_ >= 0 &&
std::abs(scHitMatch.
dPhi) > dPhiMax_)
391 const float dRZMax = getDRZCutValue(scHitMatch.
et, scHitMatch.
eta);
392 if (dRZMax_ >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
399 if (scEt >= dRZMaxLowEtThres_)
402 const float absEta =
std::abs(scEta);
403 for (
size_t etaNr = 0; etaNr < dRZMaxLowEtEtaBins_.size(); etaNr++) {
404 if (absEta < dRZMaxLowEtEtaBins_[etaNr])
405 return dRZMaxLowEt_[etaNr];
407 return dRZMaxLowEt_.back();
412 : dPhiHighEt_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxHighEt")),
413 dPhiHighEtThres_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxHighEtThres")),
414 dPhiLowEtGrad_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxLowEtGrad")),
415 dRZHighEt_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxHighEt")),
416 dRZHighEtThres_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxHighEtThres")),
417 dRZLowEtGrad_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEtGrad")),
418 etaBins_(
pset.getParameter<
std::
vector<double> >(
"etaBins")) {
419 auto binSizeCheck = [](
size_t sizeEtaBins,
const std::vector<double>& vec,
const std::string&
name) {
420 if (vec.size() != sizeEtaBins + 1) {
422 <<
" when constructing TrajSeedMatcher::MatchingCutsV2 " <<
name <<
" has " << vec.size()
423 <<
" bins, it should be equal to #bins of etaBins+1" << sizeEtaBins + 1;
435 size_t binNr = getBinNr(scHitMatch.
eta);
436 float dPhiMax = getCutValue(scHitMatch.
et, dPhiHighEt_[binNr], dPhiHighEtThres_[binNr], dPhiLowEtGrad_[binNr]);
439 float dRZMax = getCutValue(scHitMatch.
et, dRZHighEt_[binNr], dRZHighEtThres_[binNr], dRZLowEtGrad_[binNr]);
440 if (dRZMax >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
449 for (
size_t etaNr = 0; etaNr < etaBins_.size(); etaNr++) {
450 if (absEta < etaBins_[etaNr])
453 return etaBins_.size();
std::vector< SCHitMatch > processSeed(const TrajectorySeed &seed, const GlobalPoint &candPos, const float energy, const TrajectoryStateOnSurface &initialTrajState)
MatchingCutsV1(const edm::ParameterSet &pset)
size_t getNrHitsRequired(const int nrValidLayers) const
IntGlobalPointPairUnorderedMap< TrajectoryStateOnSurface > trajStateFromPointNegChargeCache_
virtual const DetLayer * idToLayer(const DetId &detId) const
MatchingCutsV2(const edm::ParameterSet &pset)
float getDRZCutValue(const float scEt, const float scEta) const
std::vector< double > dRZLowEtGrad_
const bool requireExactMatchCount
const TrajectoryStateOnSurface & getTrajStateFromVtx(const TrackingRecHit &hit, const TrajectoryStateOnSurface &initialState, const PropagatorWithMaterial &propagator)
Configuration(const edm::ParameterSet &pset, edm::ConsumesCollector &&cc)
std::vector< double > dPhiLowEtGrad_
GlobalPoint position() const
Geom::Phi< T > phi() const
IntGlobalPointPairUnorderedMap< TrajectoryStateOnSurface > trajStateFromPointPosChargeCache_
Sin< T >::type sin(const T &t)
const GlobalTrajectoryParameters & globalParameters() const
Global3DPoint GlobalPoint
MeasurementDetWithData idToDet(const DetId &id) const
Previous MeasurementDetSystem interface.
size_t getBinNr(float eta) const
const std::vector< double > dRZMaxLowEt_
static float getZVtxFromExtrapolation(const GlobalPoint &primeVtxPos, const GlobalPoint &hitPos, const GlobalPoint &candPos)
const TrajectoryStateOnSurface & getTrajStateFromPoint(const TrackingRecHit &hit, const FreeTrajectoryState &initialState, const GlobalPoint &point, const PropagatorWithMaterial &propagator)
constexpr std::array< uint8_t, layerIndexSize > layer
const std::vector< std::unique_ptr< MatchingCuts > > matchingCuts
std::vector< TrajSeedMatcher::SeedWithInfo > operator()(const GlobalPoint &candPos, const float energy)
std::vector< double > etaBins_
const bool enableHitSkipping
TrajectorySeedCollection const & seeds_
PropagatorWithMaterial forwardPropagator_
Configuration const & cfg_
static edm::ParameterSetDescription makePSetDescription()
bool operator()(const SCHitMatch &scHitMatch) const override
std::vector< const DetLayer * > compatibleLayers(const DetLayer &detLayer, Args &&... args) const
Returns all layers compatible.
const std::vector< int > minNrHitsValidLayerBins
std::vector< TrajectorySeed > TrajectorySeedCollection
TrackCharge charge() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
NavigationSchool const & navSchool_
useParamMagFieldIfDefined
Abs< T >::type abs(const T &t)
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxPosChargeCache_
int getNrValidLayersAlongTraj(const SCHitMatch &hit1, const SCHitMatch &hit2, const GlobalPoint &candPos, const float energy, const int charge)
TrackCharge charge() const
std::vector< double > dPhiHighEt_
DetLayerGeometry const & detLayerGeom_
bool operator()(const SCHitMatch &scHitMatch) const override
const TrackingRecHit & hit
TrajSeedMatcher(TrajectorySeedCollection const &seeds, math::XYZPoint const &vprim, Configuration const &cfg, edm::EventSetup const &iSetup, MeasurementTrackerEvent const &measTkEvt)
const std::vector< double > dRZMaxLowEtEtaBins_
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
XYZPointD XYZPoint
point in space with cartesian internal representation
MeasurementTrackerEvent const & measTkEvt_
std::vector< double > dPhiHighEtThres_
auto ftsFromVertexToPoint(GlobalPoint const &point, GlobalPoint const &vertex, float energy, int charge) const
PropagatorWithMaterial backwardPropagator_
FreeTrajectoryState const * freeState(bool withErrors=true) const
static constexpr float kElectronMass_
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxNegChargeCache_
bool layerHasValidHits(const DetLayer &layer, const TrajectoryStateOnSurface &hitSurState, const Propagator &propToLayerFromState) const
const std::vector< unsigned int > minNrHits
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
*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
Geom::Theta< T > theta() const
std::vector< double > dRZHighEtThres_
std::vector< double > dRZHighEt_
TrajectoryStateOnSurface makeTrajStateOnSurface(const GlobalPoint &pos, const float energy, const int charge) const