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;
67 enableHitSkipping{
pset.getParameter<
bool>(
"enableHitSkipping")},
68 requireExactMatchCount{
pset.getParameter<
bool>(
"requireExactMatchCount")},
69 useParamMagFieldIfDefined{
pset.getParameter<
bool>(
"useParamMagFieldIfDefined")},
70 minNrHits{
pset.getParameter<std::vector<unsigned int> >(
"minNrHits")},
72 matchingCuts{makeMatchingCuts(
pset.getParameter<std::vector<edm::ParameterSet> >(
"matchingCuts"))} {
75 <<
" TrajSeedMatcher::TrajSeedMatcher minNrHitsValidLayerBins should be 1 less than minNrHits when its "
84 magField_{iSetup.getData(cfg_.magFieldToken)},
85 magFieldParam_{iSetup.getData(cfg_.paramMagFieldToken)},
87 navSchool_{iSetup.getData(cfg_.navSchoolToken)},
88 detLayerGeom_{iSetup.getData(cfg_.detLayerGeomToken)},
89 forwardPropagator_(
alongMomentum, kElectronMass_, &magField_),
94 desc.
add<
bool>(
"useRecoVertex",
false);
95 desc.
add<
bool>(
"enableHitSkipping",
false);
96 desc.
add<
bool>(
"requireExactMatchCount",
true);
97 desc.
add<
bool>(
"useParamMagFieldIfDefined",
true);
101 desc.
add<std::vector<int> >(
"minNrHitsValidLayerBins", {4});
102 desc.
add<std::vector<unsigned int> >(
"minNrHits", {2, 3});
120 defaults.addParameter<
double>(
"dPhiMax", 0.04);
121 defaults.addParameter<
double>(
"dRZMax", 0.09);
122 defaults.addParameter<
double>(
"dRZMaxLowEtThres", 0.09);
123 defaults.addParameter<std::vector<double> >(
"dRZMaxLowEtEtaBins", std::vector<double>{1., 1.5});
124 defaults.addParameter<std::vector<double> >(
"dRZMaxLowEt", std::vector<double>{0.09, 0.09, 0.09});
125 defaults.addParameter<
int>(
"version", 1);
136 std::vector<SeedWithInfo> matchedSeeds;
143 std::vector<SCHitMatch> matchedHitsNeg =
processSeed(
seed, candPos, vprim,
energy, scTrajStateOnSurfNeg);
144 std::vector<SCHitMatch> matchedHitsPos =
processSeed(
seed, candPos, vprim,
energy, scTrajStateOnSurfPos);
146 int nrValidLayersPos = 0;
147 int nrValidLayersNeg = 0;
148 if (matchedHitsNeg.size() >= 2) {
151 if (matchedHitsPos.size() >= 2) {
155 int nrValidLayers =
std::max(nrValidLayersNeg, nrValidLayersPos);
157 bool matchCountPasses;
161 matchCountPasses = matchedHitsNeg.size() == nrHitsRequired || matchedHitsPos.size() == nrHitsRequired;
163 matchCountPasses = matchedHitsNeg.size() >= nrHitsRequired || matchedHitsPos.size() >= nrHitsRequired;
165 if (matchCountPasses) {
166 matchedSeeds.push_back({
seed, matchedHitsPos, matchedHitsNeg, nrValidLayers});
178 const float candEta = candPos.
eta();
182 std::vector<SCHitMatch> matchedHits;
191 auto const&
recHit = *(
seed.recHits().first + hitNr);
197 const bool doFirstMatch = matchedHits.empty();
199 auto const& trajState = doFirstMatch
206 auto const& vtxForMatchObject = doFirstMatch ? vprim :
vertex;
207 auto match = makeSCHitMatch(vtxForMatchObject, trajState,
recHit, candEt, candEta, candPos.
phi(),
charge, 1);
210 matchedHits.push_back(
match);
218 prevHitPos =
match.hitPos;
228 auto sq = [](
float x) {
return x *
x; };
232 const double r1Diff = calRDiff(primeVtxPos, hitPos);
233 const double r2Diff = calRDiff(hitPos, candPos);
234 return hitPos.
z() - r1Diff * (candPos.
z() - hitPos.
z()) / r2Diff;
240 auto& trajStateFromVtxCache =
243 auto key =
hit.det()->gdetIndex();
244 auto res = trajStateFromVtxCache.find(
key);
245 if (
res != trajStateFromVtxCache.end())
249 auto val = trajStateFromVtxCache.emplace(
key,
propagator.propagate(initialState,
hit.det()->surface()));
250 return val.first->second;
258 auto& trajStateFromPointCache =
261 auto key = std::make_pair(
hit.det()->gdetIndex(),
point);
262 auto res = trajStateFromPointCache.find(
key);
263 if (
res != trajStateFromPointCache.end())
267 auto val = trajStateFromPointCache.emplace(
key,
propagator.propagate(initialState,
hit.det()->surface()));
268 return val.first->second;
292 throw cms::Exception(
"LogicError") <<
" Error, attempting to apply selection to hit " << hitNr
306 auto firstMatchFreeTraj =
314 if (detLayer ==
nullptr)
321 int nrValidLayers = 1;
322 int nrPixInLayers = 0;
323 int nrPixOutLayers = 0;
324 for (
auto layer : inLayers) {
331 for (
auto layer : outLayers) {
338 return nrValidLayers;
343 const Propagator& propToLayerFromState)
const {
349 const std::vector<GeometricSearchDet::DetWithState>& detWithState =
351 if (detWithState.empty())
354 DetId id = detWithState.front().first->geographicalId();
372 const std::vector<SCHitMatch>& posCharge,
373 const std::vector<SCHitMatch>& negCharge,
375 : seed_(
seed), nrValidLayers_(nrValidLayers) {
376 size_t nrHitsMax =
std::max(posCharge.size(), negCharge.size());
377 for (
size_t hitNr = 0; hitNr < nrHitsMax; hitNr++) {
378 DetId detIdPos = hitNr < posCharge.size() ? posCharge[hitNr].detId :
DetId(0);
382 DetId detIdNeg = hitNr < negCharge.size() ? negCharge[hitNr].detId :
DetId(0);
386 if (detIdPos != detIdNeg && (detIdPos.
rawId() != 0 && detIdNeg.
rawId() != 0)) {
388 <<
" error in " << __FILE__ <<
", " << __LINE__
389 <<
" hits to be combined have different detIDs, this should not be possible and nothing good will come of it";
397 : dPhiMax_(
pset.getParameter<double>(
"dPhiMax")),
398 dRZMax_(
pset.getParameter<double>(
"dRZMax")),
399 dRZMaxLowEtThres_(
pset.getParameter<double>(
"dRZMaxLowEtThres")),
400 dRZMaxLowEtEtaBins_(
pset.getParameter<
std::vector<double> >(
"dRZMaxLowEtEtaBins")),
401 dRZMaxLowEt_(
pset.getParameter<
std::vector<double> >(
"dRZMaxLowEt")) {
403 throw cms::Exception(
"InvalidConfig") <<
" dRZMaxLowEtEtaBins should be 1 less than dRZMaxLowEt when its "
409 if (dPhiMax_ >= 0 &&
std::abs(scHitMatch.
dPhi) > dPhiMax_)
412 const float dRZMax = getDRZCutValue(scHitMatch.
et, scHitMatch.
eta);
413 if (dRZMax_ >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
420 if (scEt >= dRZMaxLowEtThres_)
423 const float absEta =
std::abs(scEta);
424 for (
size_t etaNr = 0; etaNr < dRZMaxLowEtEtaBins_.size(); etaNr++) {
425 if (absEta < dRZMaxLowEtEtaBins_[etaNr])
426 return dRZMaxLowEt_[etaNr];
428 return dRZMaxLowEt_.back();
433 : dPhiHighEt_(
pset.getParameter<
std::vector<double> >(
"dPhiMaxHighEt")),
434 dPhiHighEtThres_(
pset.getParameter<
std::vector<double> >(
"dPhiMaxHighEtThres")),
435 dPhiLowEtGrad_(
pset.getParameter<
std::vector<double> >(
"dPhiMaxLowEtGrad")),
436 dRZHighEt_(
pset.getParameter<
std::vector<double> >(
"dRZMaxHighEt")),
437 dRZHighEtThres_(
pset.getParameter<
std::vector<double> >(
"dRZMaxHighEtThres")),
438 dRZLowEtGrad_(
pset.getParameter<
std::vector<double> >(
"dRZMaxLowEtGrad")),
439 etaBins_(
pset.getParameter<
std::vector<double> >(
"etaBins")) {
440 auto binSizeCheck = [](
size_t sizeEtaBins,
const std::vector<double>& vec,
const std::string&
name) {
441 if (vec.size() != sizeEtaBins + 1) {
443 <<
" when constructing TrajSeedMatcher::MatchingCutsV2 " <<
name <<
" has " << vec.size()
444 <<
" bins, it should be equal to #bins of etaBins+1" << sizeEtaBins + 1;
456 size_t binNr = getBinNr(scHitMatch.
eta);
457 float dPhiMax = getCutValue(scHitMatch.
et, dPhiHighEt_[binNr], dPhiHighEtThres_[binNr], dPhiLowEtGrad_[binNr]);
460 float dRZMax = getCutValue(scHitMatch.
et, dRZHighEt_[binNr], dRZHighEtThres_[binNr], dRZLowEtGrad_[binNr]);
461 if (dRZMax >= 0 &&
std::abs(scHitMatch.
dRZ) > dRZMax)
470 for (
size_t etaNr = 0; etaNr < etaBins_.size(); etaNr++) {
471 if (absEta < etaBins_[etaNr])
474 return etaBins_.size();