-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathTrajSeedMatcher.cc
450 lines (395 loc) · 22.1 KB
/
TrajSeedMatcher.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#include "RecoEgamma/EgammaElectronAlgos/interface/TrajSeedMatcher.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/PerpendicularBoundPlaneBuilder.h"
#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
#include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
#include "TrackingTools/TrajectoryState/interface/ftsFromVertexToPoint.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/ElectronUtilities.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
constexpr float TrajSeedMatcher::kElectronMass_;
namespace {
auto makeMatchingCuts(std::vector<edm::ParameterSet> const& cutsPSets) {
std::vector<std::unique_ptr<TrajSeedMatcher::MatchingCuts> > matchingCuts;
for (const auto& cutPSet : cutsPSets) {
int version = cutPSet.getParameter<int>("version");
switch (version) {
case 1:
matchingCuts.emplace_back(std::make_unique<TrajSeedMatcher::MatchingCutsV1>(cutPSet));
break;
case 2:
matchingCuts.emplace_back(std::make_unique<TrajSeedMatcher::MatchingCutsV2>(cutPSet));
break;
default:
throw cms::Exception("InvalidConfig") << " Error TrajSeedMatcher::TrajSeedMatcher pixel match cuts version "
<< version << " not recognised" << std::endl;
}
}
return matchingCuts;
}
TrajSeedMatcher::SCHitMatch makeSCHitMatch(const GlobalPoint& vtxPos,
const TrajectoryStateOnSurface& trajState,
const TrackingRecHit& hit,
float et,
float eta,
float phi,
int charge,
int nrClus) {
EleRelPointPair pointPair(hit.globalPosition(), trajState.globalParameters().position(), vtxPos);
float dRZ = hit.geographicalId().subdetId() == PixelSubdetector::PixelBarrel ? pointPair.dZ() : pointPair.dPerp();
return {hit.geographicalId(), hit.globalPosition(), dRZ, pointPair.dPhi(), hit, et, eta, phi, charge, nrClus};
}
const std::vector<TrajSeedMatcher::MatchInfo> makeMatchInfoVector(
std::vector<TrajSeedMatcher::SCHitMatch> const& posCharge,
std::vector<TrajSeedMatcher::SCHitMatch> const& negCharge) {
std::vector<TrajSeedMatcher::MatchInfo> matchInfos;
size_t nrHitsMax = std::max(posCharge.size(), negCharge.size());
for (size_t hitNr = 0; hitNr < nrHitsMax; hitNr++) {
DetId detIdPos = hitNr < posCharge.size() ? posCharge[hitNr].detId : DetId(0);
float dRZPos = hitNr < posCharge.size() ? posCharge[hitNr].dRZ : std::numeric_limits<float>::max();
float dPhiPos = hitNr < posCharge.size() ? posCharge[hitNr].dPhi : std::numeric_limits<float>::max();
DetId detIdNeg = hitNr < negCharge.size() ? negCharge[hitNr].detId : DetId(0);
float dRZNeg = hitNr < negCharge.size() ? negCharge[hitNr].dRZ : std::numeric_limits<float>::max();
float dPhiNeg = hitNr < negCharge.size() ? negCharge[hitNr].dPhi : std::numeric_limits<float>::max();
if (detIdPos != detIdNeg && (detIdPos.rawId() != 0 && detIdNeg.rawId() != 0)) {
cms::Exception("LogicError") << " error in " << __FILE__ << ", " << __LINE__
<< " hits to be combined have different detIDs, this should not be possible and "
"nothing good will come of it";
}
DetId detId = detIdPos.rawId() != 0 ? detIdPos : detIdNeg;
matchInfos.push_back({detId, dRZPos, dRZNeg, dPhiPos, dPhiNeg});
}
return matchInfos;
}
}; // namespace
TrajSeedMatcher::Configuration::Configuration(const edm::ParameterSet& pset, edm::ConsumesCollector&& cc)
: magFieldToken{cc.esConsumes()},
paramMagFieldToken{cc.esConsumes(pset.getParameter<edm::ESInputTag>("paramMagField"))},
navSchoolToken{cc.esConsumes(pset.getParameter<edm::ESInputTag>("navSchool"))},
detLayerGeomToken{cc.esConsumes(pset.getParameter<edm::ESInputTag>("detLayerGeom"))},
useRecoVertex{pset.getParameter<bool>("useRecoVertex")},
enableHitSkipping{pset.getParameter<bool>("enableHitSkipping")},
requireExactMatchCount{pset.getParameter<bool>("requireExactMatchCount")},
useParamMagFieldIfDefined{pset.getParameter<bool>("useParamMagFieldIfDefined")},
minNrHits{pset.getParameter<std::vector<unsigned int> >("minNrHits")},
minNrHitsValidLayerBins{pset.getParameter<std::vector<int> >("minNrHitsValidLayerBins")},
matchingCuts{makeMatchingCuts(pset.getParameter<std::vector<edm::ParameterSet> >("matchingCuts"))} {
if (minNrHitsValidLayerBins.size() + 1 != minNrHits.size()) {
throw cms::Exception("InvalidConfig")
<< " TrajSeedMatcher::TrajSeedMatcher minNrHitsValidLayerBins should be 1 less than minNrHits when its "
<< minNrHitsValidLayerBins.size() << " vs " << minNrHits.size();
}
}
TrajSeedMatcher::TrajSeedMatcher(TrajectorySeedCollection const& seeds,
math::XYZPoint const& vprim,
TrajSeedMatcher::Configuration const& cfg,
edm::EventSetup const& iSetup,
MeasurementTrackerEvent const& measTkEvt)
: seeds_{seeds},
vprim_(vprim.x(), vprim.y(), vprim.z()),
cfg_{cfg},
magField_{iSetup.getData(cfg_.magFieldToken)},
magFieldParam_{iSetup.getData(cfg_.paramMagFieldToken)},
measTkEvt_{measTkEvt},
navSchool_{iSetup.getData(cfg_.navSchoolToken)},
detLayerGeom_{iSetup.getData(cfg_.detLayerGeomToken)},
forwardPropagator_(alongMomentum, kElectronMass_, &magField_),
backwardPropagator_(oppositeToMomentum, kElectronMass_, &magField_) {}
edm::ParameterSetDescription TrajSeedMatcher::makePSetDescription() {
edm::ParameterSetDescription desc;
desc.add<bool>("useRecoVertex", false);
desc.add<bool>("enableHitSkipping", false);
desc.add<bool>("requireExactMatchCount", true);
desc.add<bool>("useParamMagFieldIfDefined", true);
desc.add<edm::ESInputTag>("paramMagField", edm::ESInputTag{"", "ParabolicMf"});
desc.add<edm::ESInputTag>("navSchool", edm::ESInputTag{"", "SimpleNavigationSchool"});
desc.add<edm::ESInputTag>("detLayerGeom", edm::ESInputTag{"", "hltESPGlobalDetLayerGeometry"});
desc.add<std::vector<int> >("minNrHitsValidLayerBins", {4});
desc.add<std::vector<unsigned int> >("minNrHits", {2, 3});
edm::ParameterSetDescription cutsDesc;
auto cutDescCases = 1 >> (edm::ParameterDescription<double>("dPhiMax", 0.04, true) and
edm::ParameterDescription<double>("dRZMax", 0.09, true) and
edm::ParameterDescription<double>("dRZMaxLowEtThres", 20., true) and
edm::ParameterDescription<std::vector<double> >("dRZMaxLowEtEtaBins", {1., 1.5}, true) and
edm::ParameterDescription<std::vector<double> >("dRZMaxLowEt", {0.09, 0.15, 0.09}, true)) or
2 >> (edm::ParameterDescription<std::vector<double> >("dPhiMaxHighEt", {0.003}, true) and
edm::ParameterDescription<std::vector<double> >("dPhiMaxHighEtThres", {0.0}, true) and
edm::ParameterDescription<std::vector<double> >("dPhiMaxLowEtGrad", {0.0}, true) and
edm::ParameterDescription<std::vector<double> >("dRZMaxHighEt", {0.005}, true) and
edm::ParameterDescription<std::vector<double> >("dRZMaxHighEtThres", {30}, true) and
edm::ParameterDescription<std::vector<double> >("dRZMaxLowEtGrad", {-0.002}, true) and
edm::ParameterDescription<std::vector<double> >("etaBins", {}, true));
cutsDesc.ifValue(edm::ParameterDescription<int>("version", 1, true), std::move(cutDescCases));
edm::ParameterSet defaults;
defaults.addParameter<double>("dPhiMax", 0.04);
defaults.addParameter<double>("dRZMax", 0.09);
defaults.addParameter<double>("dRZMaxLowEtThres", 0.09);
defaults.addParameter<std::vector<double> >("dRZMaxLowEtEtaBins", std::vector<double>{1., 1.5});
defaults.addParameter<std::vector<double> >("dRZMaxLowEt", std::vector<double>{0.09, 0.09, 0.09});
defaults.addParameter<int>("version", 1);
desc.addVPSet("matchingCuts", cutsDesc, std::vector<edm::ParameterSet>{defaults, defaults, defaults});
return desc;
}
std::vector<TrajSeedMatcher::SeedWithInfo> TrajSeedMatcher::operator()(const GlobalPoint& candPos, const float energy) {
clearCache();
std::vector<SeedWithInfo> matchedSeeds;
//these are super expensive functions
TrajectoryStateOnSurface scTrajStateOnSurfNeg = makeTrajStateOnSurface(candPos, energy, -1);
TrajectoryStateOnSurface scTrajStateOnSurfPos = makeTrajStateOnSurface(candPos, energy, 1);
for (const auto& seed : seeds_) {
std::vector<SCHitMatch> matchedHitsNeg = processSeed(seed, candPos, energy, scTrajStateOnSurfNeg);
std::vector<SCHitMatch> matchedHitsPos = processSeed(seed, candPos, energy, scTrajStateOnSurfPos);
int nrValidLayersPos = 0;
int nrValidLayersNeg = 0;
if (matchedHitsNeg.size() >= 2) {
nrValidLayersNeg = getNrValidLayersAlongTraj(matchedHitsNeg[0], matchedHitsNeg[1], candPos, energy, -1);
}
if (matchedHitsPos.size() >= 2) {
nrValidLayersPos = getNrValidLayersAlongTraj(matchedHitsPos[0], matchedHitsPos[1], candPos, energy, +1);
}
int nrValidLayers = std::max(nrValidLayersNeg, nrValidLayersPos);
size_t nrHitsRequired = getNrHitsRequired(nrValidLayers);
bool matchCountPasses;
if (cfg_.requireExactMatchCount) {
// If the input seed collection is not cross-cleaned, an exact match is necessary to
// prevent redundant seeds.
matchCountPasses = matchedHitsNeg.size() == nrHitsRequired || matchedHitsPos.size() == nrHitsRequired;
} else {
matchCountPasses = matchedHitsNeg.size() >= nrHitsRequired || matchedHitsPos.size() >= nrHitsRequired;
}
if (matchCountPasses) {
matchedSeeds.push_back({seed, makeMatchInfoVector(matchedHitsPos, matchedHitsNeg), nrValidLayers});
}
}
return matchedSeeds;
}
std::vector<TrajSeedMatcher::SCHitMatch> TrajSeedMatcher::processSeed(const TrajectorySeed& seed,
const GlobalPoint& candPos,
const float energy,
const TrajectoryStateOnSurface& initialTrajState) {
//next try passing these variables in once...
const float candEta = candPos.eta();
const float candEt = energy * std::sin(candPos.theta());
const int charge = initialTrajState.charge();
std::vector<SCHitMatch> matches;
FreeTrajectoryState firstMatchFreeTraj;
GlobalPoint prevHitPos;
GlobalPoint vertex;
const auto nCuts = cfg_.matchingCuts.size();
for (size_t iHit = 0;
matches.size() < nCuts && iHit < seed.nHits() && (cfg_.enableHitSkipping || iHit == matches.size());
iHit++) {
auto const& recHit = *(seed.recHits().begin() + iHit);
if (!recHit.isValid()) {
continue;
}
const bool doFirstMatch = matches.empty();
auto const& trajState = doFirstMatch
? getTrajStateFromVtx(recHit, initialTrajState, backwardPropagator_)
: getTrajStateFromPoint(recHit, firstMatchFreeTraj, prevHitPos, forwardPropagator_);
if (!trajState.isValid()) {
continue;
}
auto const& vtxForMatchObject = doFirstMatch ? vprim_ : vertex;
auto match = makeSCHitMatch(vtxForMatchObject, trajState, recHit, candEt, candEta, candPos.phi(), charge, 1);
if ((*cfg_.matchingCuts[matches.size()])(match)) {
matches.push_back(match);
if (doFirstMatch) {
//now we can figure out the z vertex
double zVertex = cfg_.useRecoVertex ? vprim_.z() : getZVtxFromExtrapolation(vprim_, match.hitPos, candPos);
vertex = GlobalPoint(vprim_.x(), vprim_.y(), zVertex);
firstMatchFreeTraj = ftsFromVertexToPoint(match.hitPos, vertex, energy, charge);
}
prevHitPos = match.hitPos;
}
}
return matches;
}
// compute the z vertex from the candidate position and the found pixel hit
float TrajSeedMatcher::getZVtxFromExtrapolation(const GlobalPoint& primeVtxPos,
const GlobalPoint& hitPos,
const GlobalPoint& candPos) {
auto sq = [](float x) { return x * x; };
auto calRDiff = [sq](const GlobalPoint& p1, const GlobalPoint& p2) {
return std::sqrt(sq(p2.x() - p1.x()) + sq(p2.y() - p1.y()));
};
const double r1Diff = calRDiff(primeVtxPos, hitPos);
const double r2Diff = calRDiff(hitPos, candPos);
return hitPos.z() - r1Diff * (candPos.z() - hitPos.z()) / r2Diff;
}
const TrajectoryStateOnSurface& TrajSeedMatcher::getTrajStateFromVtx(const TrackingRecHit& hit,
const TrajectoryStateOnSurface& initialState,
const PropagatorWithMaterial& propagator) {
auto& trajStateFromVtxCache =
initialState.charge() == 1 ? trajStateFromVtxPosChargeCache_ : trajStateFromVtxNegChargeCache_;
auto key = hit.det()->gdetIndex();
auto res = trajStateFromVtxCache.find(key);
if (res != trajStateFromVtxCache.end())
return res->second;
else { //doesnt exist, need to make it
//FIXME: check for efficiency
auto val = trajStateFromVtxCache.emplace(key, propagator.propagate(initialState, hit.det()->surface()));
return val.first->second;
}
}
const TrajectoryStateOnSurface& TrajSeedMatcher::getTrajStateFromPoint(const TrackingRecHit& hit,
const FreeTrajectoryState& initialState,
const GlobalPoint& point,
const PropagatorWithMaterial& propagator) {
auto& trajStateFromPointCache =
initialState.charge() == 1 ? trajStateFromPointPosChargeCache_ : trajStateFromPointNegChargeCache_;
auto key = std::make_pair(hit.det()->gdetIndex(), point);
auto res = trajStateFromPointCache.find(key);
if (res != trajStateFromPointCache.end())
return res->second;
else { //doesnt exist, need to make it
//FIXME: check for efficiency
auto val = trajStateFromPointCache.emplace(key, propagator.propagate(initialState, hit.det()->surface()));
return val.first->second;
}
}
TrajectoryStateOnSurface TrajSeedMatcher::makeTrajStateOnSurface(const GlobalPoint& pos,
const float energy,
const int charge) const {
auto freeTS = ftsFromVertexToPoint(pos, vprim_, energy, charge);
return TrajectoryStateOnSurface(freeTS, *PerpendicularBoundPlaneBuilder{}(freeTS.position(), freeTS.momentum()));
}
void TrajSeedMatcher::clearCache() {
trajStateFromVtxPosChargeCache_.clear();
trajStateFromVtxNegChargeCache_.clear();
trajStateFromPointPosChargeCache_.clear();
trajStateFromPointNegChargeCache_.clear();
}
int TrajSeedMatcher::getNrValidLayersAlongTraj(
const SCHitMatch& hit1, const SCHitMatch& hit2, const GlobalPoint& candPos, const float energy, const int charge) {
double zVertex = cfg_.useRecoVertex ? vprim_.z() : getZVtxFromExtrapolation(vprim_, hit1.hitPos, candPos);
GlobalPoint vertex(vprim_.x(), vprim_.y(), zVertex);
auto firstMatchFreeTraj = ftsFromVertexToPoint(hit1.hitPos, vertex, energy, charge);
auto const& secondHitTraj = getTrajStateFromPoint(hit2.hit, firstMatchFreeTraj, hit1.hitPos, forwardPropagator_);
return getNrValidLayersAlongTraj(hit2.hit.geographicalId(), secondHitTraj);
}
int TrajSeedMatcher::getNrValidLayersAlongTraj(const DetId& hitId, const TrajectoryStateOnSurface& hitTrajState) const {
const DetLayer* detLayer = detLayerGeom_.idToLayer(hitId);
if (detLayer == nullptr)
return 0;
const FreeTrajectoryState& hitFreeState = *hitTrajState.freeState();
auto const inLayers = navSchool_.compatibleLayers(*detLayer, hitFreeState, oppositeToMomentum);
const auto outLayers = navSchool_.compatibleLayers(*detLayer, hitFreeState, alongMomentum);
int nrValidLayers = 1; //because our current hit is also valid and wont be included in the count otherwise
for (auto layer : inLayers) {
if (GeomDetEnumerators::isTrackerPixel(layer->subDetector())) {
if (layerHasValidHits(*layer, hitTrajState, backwardPropagator_))
nrValidLayers++;
}
}
for (auto layer : outLayers) {
if (GeomDetEnumerators::isTrackerPixel(layer->subDetector())) {
if (layerHasValidHits(*layer, hitTrajState, forwardPropagator_))
nrValidLayers++;
}
}
return nrValidLayers;
}
bool TrajSeedMatcher::layerHasValidHits(const DetLayer& layer,
const TrajectoryStateOnSurface& hitSurState,
const Propagator& propToLayerFromState) const {
//FIXME: do not hardcode with werid magic numbers stolen from ancient tracking code
//its taken from https://cmssdt.cern.ch/dxr/CMSSW/source/RecoTracker/TrackProducer/interface/TrackProducerBase.icc#165
//which inspires this code
Chi2MeasurementEstimator estimator(30., -3.0, 0.5, 2.0, 0.5, 1.e12); // same as defauts....
const std::vector<GeometricSearchDet::DetWithState>& detWithState =
layer.compatibleDets(hitSurState, propToLayerFromState, estimator);
if (detWithState.empty())
return false;
else {
DetId id = detWithState.front().first->geographicalId();
MeasurementDetWithData measDet = measTkEvt_.idToDet(id);
if (measDet.isActive())
return true;
else
return false;
}
}
size_t TrajSeedMatcher::getNrHitsRequired(const int nrValidLayers) const {
for (size_t binNr = 0; binNr < cfg_.minNrHitsValidLayerBins.size(); binNr++) {
if (nrValidLayers < cfg_.minNrHitsValidLayerBins[binNr])
return cfg_.minNrHits[binNr];
}
return cfg_.minNrHits.back();
}
TrajSeedMatcher::MatchingCutsV1::MatchingCutsV1(const edm::ParameterSet& pset)
: dPhiMax_(pset.getParameter<double>("dPhiMax")),
dRZMax_(pset.getParameter<double>("dRZMax")),
dRZMaxLowEtThres_(pset.getParameter<double>("dRZMaxLowEtThres")),
dRZMaxLowEtEtaBins_(pset.getParameter<std::vector<double> >("dRZMaxLowEtEtaBins")),
dRZMaxLowEt_(pset.getParameter<std::vector<double> >("dRZMaxLowEt")) {
if (dRZMaxLowEtEtaBins_.size() + 1 != dRZMaxLowEt_.size()) {
throw cms::Exception("InvalidConfig") << " dRZMaxLowEtEtaBins should be 1 less than dRZMaxLowEt when its "
<< dRZMaxLowEtEtaBins_.size() << " vs " << dRZMaxLowEt_.size();
}
}
bool TrajSeedMatcher::MatchingCutsV1::operator()(const TrajSeedMatcher::SCHitMatch& scHitMatch) const {
if (dPhiMax_ >= 0 && std::abs(scHitMatch.dPhi) > dPhiMax_)
return false;
const float dRZMax = getDRZCutValue(scHitMatch.et, scHitMatch.eta);
if (dRZMax_ >= 0 && std::abs(scHitMatch.dRZ) > dRZMax)
return false;
return true;
}
float TrajSeedMatcher::MatchingCutsV1::getDRZCutValue(const float scEt, const float scEta) const {
if (scEt >= dRZMaxLowEtThres_)
return dRZMax_;
else {
const float absEta = std::abs(scEta);
for (size_t etaNr = 0; etaNr < dRZMaxLowEtEtaBins_.size(); etaNr++) {
if (absEta < dRZMaxLowEtEtaBins_[etaNr])
return dRZMaxLowEt_[etaNr];
}
return dRZMaxLowEt_.back();
}
}
TrajSeedMatcher::MatchingCutsV2::MatchingCutsV2(const edm::ParameterSet& pset)
: dPhiHighEt_(pset.getParameter<std::vector<double> >("dPhiMaxHighEt")),
dPhiHighEtThres_(pset.getParameter<std::vector<double> >("dPhiMaxHighEtThres")),
dPhiLowEtGrad_(pset.getParameter<std::vector<double> >("dPhiMaxLowEtGrad")),
dRZHighEt_(pset.getParameter<std::vector<double> >("dRZMaxHighEt")),
dRZHighEtThres_(pset.getParameter<std::vector<double> >("dRZMaxHighEtThres")),
dRZLowEtGrad_(pset.getParameter<std::vector<double> >("dRZMaxLowEtGrad")),
etaBins_(pset.getParameter<std::vector<double> >("etaBins")) {
auto binSizeCheck = [](size_t sizeEtaBins, const std::vector<double>& vec, const std::string& name) {
if (vec.size() != sizeEtaBins + 1) {
throw cms::Exception("InvalidConfig")
<< " when constructing TrajSeedMatcher::MatchingCutsV2 " << name << " has " << vec.size()
<< " bins, it should be equal to #bins of etaBins+1" << sizeEtaBins + 1;
}
};
binSizeCheck(etaBins_.size(), dPhiHighEt_, "dPhiMaxHighEt");
binSizeCheck(etaBins_.size(), dPhiHighEtThres_, "dPhiMaxHighEtThres");
binSizeCheck(etaBins_.size(), dPhiLowEtGrad_, "dPhiMaxLowEtGrad");
binSizeCheck(etaBins_.size(), dRZHighEt_, "dRZMaxHighEt");
binSizeCheck(etaBins_.size(), dRZHighEtThres_, "dRZMaxHighEtThres");
binSizeCheck(etaBins_.size(), dRZLowEtGrad_, "dRZMaxLowEtGrad");
}
bool TrajSeedMatcher::MatchingCutsV2::operator()(const TrajSeedMatcher::SCHitMatch& scHitMatch) const {
size_t binNr = getBinNr(scHitMatch.eta);
float dPhiMax = getCutValue(scHitMatch.et, dPhiHighEt_[binNr], dPhiHighEtThres_[binNr], dPhiLowEtGrad_[binNr]);
if (dPhiMax >= 0 && std::abs(scHitMatch.dPhi) > dPhiMax)
return false;
float dRZMax = getCutValue(scHitMatch.et, dRZHighEt_[binNr], dRZHighEtThres_[binNr], dRZLowEtGrad_[binNr]);
if (dRZMax >= 0 && std::abs(scHitMatch.dRZ) > dRZMax)
return false;
return true;
}
//eta bins is exactly 1 smaller than the vectors which will be accessed by this bin nr
size_t TrajSeedMatcher::MatchingCutsV2::getBinNr(float eta) const {
const float absEta = std::abs(eta);
for (size_t etaNr = 0; etaNr < etaBins_.size(); etaNr++) {
if (absEta < etaBins_[etaNr])
return etaNr;
}
return etaBins_.size();
}