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";
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 for (
auto layer : inLayers) {
332 for (
auto layer : outLayers) {
338 return nrValidLayers;
343 const Propagator& propToLayerFromState)
const {
349 const std::vector<GeometricSearchDet::DetWithState>& detWithState =
350 layer.compatibleDets(hitSurState, propToLayerFromState,
estimator);
351 if (detWithState.empty())
354 DetId id = detWithState.front().first->geographicalId();
372 : dPhiMax_(
pset.getParameter<double>(
"dPhiMax")),
373 dRZMax_(
pset.getParameter<double>(
"dRZMax")),
374 dRZMaxLowEtThres_(
pset.getParameter<double>(
"dRZMaxLowEtThres")),
375 dRZMaxLowEtEtaBins_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEtEtaBins")),
376 dRZMaxLowEt_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEt")) {
378 throw cms::Exception(
"InvalidConfig") <<
" dRZMaxLowEtEtaBins should be 1 less than dRZMaxLowEt when its " 384 if (dPhiMax_ >= 0 &&
std::abs(scHitMatch.
dPhi) > dPhiMax_)
387 const float dRZMax = getDRZCutValue(scHitMatch.
et, scHitMatch.
eta);
388 if (dRZMax_ >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
395 if (scEt >= dRZMaxLowEtThres_)
398 const float absEta =
std::abs(scEta);
399 for (
size_t etaNr = 0; etaNr < dRZMaxLowEtEtaBins_.size(); etaNr++) {
400 if (absEta < dRZMaxLowEtEtaBins_[etaNr])
401 return dRZMaxLowEt_[etaNr];
403 return dRZMaxLowEt_.back();
408 : dPhiHighEt_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxHighEt")),
409 dPhiHighEtThres_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxHighEtThres")),
410 dPhiLowEtGrad_(
pset.getParameter<
std::
vector<double> >(
"dPhiMaxLowEtGrad")),
411 dRZHighEt_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxHighEt")),
412 dRZHighEtThres_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxHighEtThres")),
413 dRZLowEtGrad_(
pset.getParameter<
std::
vector<double> >(
"dRZMaxLowEtGrad")),
414 etaBins_(
pset.getParameter<
std::
vector<double> >(
"etaBins")) {
415 auto binSizeCheck = [](
size_t sizeEtaBins,
const std::vector<double>& vec,
const std::string&
name) {
416 if (vec.size() != sizeEtaBins + 1) {
418 <<
" when constructing TrajSeedMatcher::MatchingCutsV2 " <<
name <<
" has " << vec.size()
419 <<
" bins, it should be equal to #bins of etaBins+1" << sizeEtaBins + 1;
431 size_t binNr = getBinNr(scHitMatch.
eta);
432 float dPhiMax = getCutValue(scHitMatch.
et, dPhiHighEt_[binNr], dPhiHighEtThres_[binNr], dPhiLowEtGrad_[binNr]);
435 float dRZMax = getCutValue(scHitMatch.
et, dRZHighEt_[binNr], dRZHighEtThres_[binNr], dRZLowEtGrad_[binNr]);
436 if (dRZMax >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
445 for (
size_t etaNr = 0; etaNr < etaBins_.size(); etaNr++) {
446 if (absEta < etaBins_[etaNr])
449 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
uint32_t cc[maxCellsPerHit]
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)
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