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 =
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();