CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrajSeedMatcher.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_EgammaElectronAlgos_TrajSeedMatcher_h
2 #define RecoEgamma_EgammaElectronAlgos_TrajSeedMatcher_h
3 
4 //******************************************************************************
5 //
6 // Part of the refactorisation of of the E/gamma pixel matching for 2017 pixels
7 // This refactorisation converts the monolithic approach to a series of
8 // independent producer modules, with each modules performing a specific
9 // job as recommended by the 2017 tracker framework
10 //
11 //
12 // The module is based of PixelHitMatcher (the seed based functions) but
13 // extended to match on an arbitary number of hits rather than just doublets.
14 // It is also aware of how many layers the supercluster trajectory passed through
15 // and uses that information to determine how many hits to require
16 // Other than that, its a direct port and follows what PixelHitMatcher did
17 //
18 //
19 // Author : Sam Harper (RAL), 2017
20 //
21 //*******************************************************************************
22 
24 
27 
37 
38 namespace edm {
39  class EventSetup;
41  class ParameterSet;
43 } // namespace edm
44 
46 class TrackingRecHit;
47 
49 public:
50  class SCHitMatch {
51  public:
53  : detId_(0),
54  dRZ_(std::numeric_limits<float>::max()),
55  dPhi_(std::numeric_limits<float>::max()),
56  hit_(nullptr),
57  et_(0),
58  eta_(0),
59  phi_(0),
60  charge_(0),
61  nrClus_(0) {}
62 
63  //does not set charge,et,nrclus
64  SCHitMatch(const GlobalPoint& vtxPos, const TrajectoryStateOnSurface& trajState, const TrackingRecHit& hit);
65  ~SCHitMatch() = default;
66 
67  void setExtra(float et, float eta, float phi, int charge, int nrClus) {
68  et_ = et;
69  eta_ = eta;
70  phi_ = phi;
71  charge_ = charge;
72  nrClus_ = nrClus;
73  }
74 
75  int subdetId() const { return detId_.subdetId(); }
76  DetId detId() const { return detId_; }
77  float dRZ() const { return dRZ_; }
78  float dPhi() const { return dPhi_; }
79  const GlobalPoint& hitPos() const { return hitPos_; }
80  float et() const { return et_; }
81  float eta() const { return eta_; }
82  float phi() const { return phi_; }
83  int charge() const { return charge_; }
84  int nrClus() const { return nrClus_; }
85  const TrackingRecHit* hit() const { return hit_; }
86 
87  private:
90  float dRZ_;
91  float dPhi_;
92  const TrackingRecHit* hit_; //we do not own this
93  //extra quanities which are set later
94  float et_;
95  float eta_;
96  float phi_;
97  int charge_;
98  int nrClus_;
99  };
100 
101  struct MatchInfo {
102  public:
104  float dRZPos, dRZNeg;
105  float dPhiPos, dPhiNeg;
106 
107  MatchInfo(const DetId& iDetId, float iDRZPos, float iDRZNeg, float iDPhiPos, float iDPhiNeg)
108  : detId(iDetId), dRZPos(iDRZPos), dRZNeg(iDRZNeg), dPhiPos(iDPhiPos), dPhiNeg(iDPhiNeg) {}
109  };
110 
111  class SeedWithInfo {
112  public:
114  const std::vector<SCHitMatch>& posCharge,
115  const std::vector<SCHitMatch>& negCharge,
116  int nrValidLayers);
117  ~SeedWithInfo() = default;
118 
119  const TrajectorySeed& seed() const { return seed_; }
120  float dRZPos(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dRZPos); }
121  float dRZNeg(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dRZNeg); }
122  float dPhiPos(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dPhiPos); }
123  float dPhiNeg(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dPhiNeg); }
124  DetId detId(size_t hitNr) const { return hitNr < matchInfo_.size() ? matchInfo_[hitNr].detId : DetId(0); }
125  size_t nrMatchedHits() const { return matchInfo_.size(); }
126  const std::vector<MatchInfo>& matches() const { return matchInfo_; }
127  int nrValidLayers() const { return nrValidLayers_; }
128 
129  private:
130  float getVal(size_t hitNr, float MatchInfo::*val) const {
131  return hitNr < matchInfo_.size() ? matchInfo_[hitNr].*val : std::numeric_limits<float>::max();
132  }
133 
134  private:
136  std::vector<MatchInfo> matchInfo_;
138  };
139 
140  class MatchingCuts {
141  public:
143  virtual ~MatchingCuts() {}
144  virtual bool operator()(const SCHitMatch& scHitMatch) const = 0;
145  };
146 
147  class MatchingCutsV1 : public MatchingCuts {
148  public:
149  explicit MatchingCutsV1(const edm::ParameterSet& pset);
150  bool operator()(const SCHitMatch& scHitMatch) const override;
151 
152  private:
153  float getDRZCutValue(const float scEt, const float scEta) const;
154 
155  private:
156  const double dPhiMax_;
157  const double dRZMax_;
158  const double dRZMaxLowEtThres_;
159  const std::vector<double> dRZMaxLowEtEtaBins_;
160  const std::vector<double> dRZMaxLowEt_;
161  };
162 
163  class MatchingCutsV2 : public MatchingCuts {
164  public:
165  explicit MatchingCutsV2(const edm::ParameterSet& pset);
166  bool operator()(const SCHitMatch& scHitMatch) const override;
167 
168  private:
169  size_t getBinNr(float eta) const;
170  float getCutValue(float et, float highEt, float highEtThres, float lowEtGrad) const {
171  return highEt + std::min(0.f, et - highEtThres) * lowEtGrad;
172  }
173 
174  private:
175  std::vector<double> dPhiHighEt_, dPhiHighEtThres_, dPhiLowEtGrad_;
176  std::vector<double> dRZHighEt_, dRZHighEtThres_, dRZLowEtGrad_;
177  std::vector<double> etaBins_;
178  };
179 
180 public:
181  explicit TrajSeedMatcher(const edm::ParameterSet& pset);
182  ~TrajSeedMatcher() = default;
183 
184  static edm::ParameterSetDescription makePSetDescription();
185 
186  void doEventSetup(const edm::EventSetup& iSetup);
187 
188  std::vector<TrajSeedMatcher::SeedWithInfo> compatibleSeeds(const TrajectorySeedCollection& seeds,
189  const GlobalPoint& candPos,
190  const GlobalPoint& vprim,
191  const float energy);
192 
194 
195 private:
196  std::vector<SCHitMatch> processSeed(const TrajectorySeed& seed,
197  const GlobalPoint& candPos,
198  const GlobalPoint& vprim,
199  const float energy,
200  const TrajectoryStateOnSurface& initialTrajState);
201 
202  static float getZVtxFromExtrapolation(const GlobalPoint& primeVtxPos,
203  const GlobalPoint& hitPos,
204  const GlobalPoint& candPos);
205 
206  bool passTrajPreSel(const GlobalPoint& hitPos, const GlobalPoint& candPos) const;
207 
208  TrajSeedMatcher::SCHitMatch matchFirstHit(const TrajectorySeed& seed,
209  const TrajectoryStateOnSurface& trajState,
210  const GlobalPoint& vtxPos,
212 
213  TrajSeedMatcher::SCHitMatch match2ndToNthHit(const TrajectorySeed& seed,
214  const FreeTrajectoryState& trajState,
215  const size_t hitNr,
216  const GlobalPoint& prevHitPos,
217  const GlobalPoint& vtxPos,
218  const PropagatorWithMaterial& propagator);
219 
220  const TrajectoryStateOnSurface& getTrajStateFromVtx(const TrackingRecHit& hit,
221  const TrajectoryStateOnSurface& initialState,
222  const PropagatorWithMaterial& propagator);
223 
224  const TrajectoryStateOnSurface& getTrajStateFromPoint(const TrackingRecHit& hit,
225  const FreeTrajectoryState& initialState,
226  const GlobalPoint& point,
227  const PropagatorWithMaterial& propagator);
228 
229  TrajectoryStateOnSurface makeTrajStateOnSurface(const GlobalPoint& pos,
230  const GlobalPoint& vtx,
231  const float energy,
232  const int charge) const;
233  void clearCache();
234 
235  bool passesMatchSel(const SCHitMatch& hit, const size_t hitNr) const;
236 
237  int getNrValidLayersAlongTraj(const SCHitMatch& hit1,
238  const SCHitMatch& hit2,
239  const GlobalPoint& candPos,
240  const GlobalPoint& vprim,
241  const float energy,
242  const int charge);
243 
244  int getNrValidLayersAlongTraj(const DetId& hitId, const TrajectoryStateOnSurface& hitTrajState) const;
245 
246  bool layerHasValidHits(const DetLayer& layer,
247  const TrajectoryStateOnSurface& hitSurState,
248  const Propagator& propToLayerFromState) const;
249 
250  size_t getNrHitsRequired(const int nrValidLayers) const;
251 
252  //parameterised b-fields may not be valid for entire detector, just tracker volume
253  //however need we ecal so we auto select based on the position
254  const MagneticField& getMagField(const GlobalPoint& point) const {
255  return useParamMagFieldIfDefined_ && magFieldParam_->isDefined(point) ? *magFieldParam_ : *magField_;
256  }
257 
258 private:
259  static constexpr float kElectronMass_ = 0.000511;
260  static constexpr float kPhiCut_ = -0.801144; //cos(2.5)
261  std::unique_ptr<PropagatorWithMaterial> forwardPropagator_;
262  std::unique_ptr<PropagatorWithMaterial> backwardPropagator_;
263  unsigned long long cacheIDMagField_;
272 
277  std::vector<std::unique_ptr<MatchingCuts> > matchingCuts_;
278 
279  //these two varibles determine how hits we require
280  //based on how many valid layers we had
281  //right now we always need atleast two hits
282  //also highly dependent on the seeds you pass in
283  //which also require a given number of hits
284  const std::vector<unsigned int> minNrHits_;
285  const std::vector<int> minNrHitsValidLayerBins_;
286 
287  std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxPosChargeCache_;
288  std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxNegChargeCache_;
289 
292 };
293 
294 #endif
const GlobalPoint & hitPos() const
bool useParamMagFieldIfDefined_
IntGlobalPointPairUnorderedMap< TrajectoryStateOnSurface > trajStateFromPointNegChargeCache_
DetId detId(size_t hitNr) const
std::vector< double > dRZLowEtGrad_
std::vector< double > dPhiLowEtGrad_
const TrackingRecHit * hit() const
const MagneticField & getMagField(const GlobalPoint &point) const
edm::ESHandle< MagneticField > magFieldParam_
IntGlobalPointPairUnorderedMap< TrajectoryStateOnSurface > trajStateFromPointPosChargeCache_
edm::ESHandle< DetLayerGeometry > detLayerGeom_
#define nullptr
float dRZPos(size_t hitNr) const
std::unique_ptr< PropagatorWithMaterial > forwardPropagator_
const std::vector< MatchInfo > & matches() const
const std::vector< int > minNrHitsValidLayerBins_
const std::vector< double > dRZMaxLowEt_
void setMeasTkEvtHandle(edm::Handle< MeasurementTrackerEvent > handle)
edm::ESHandle< NavigationSchool > navSchool_
std::vector< double > etaBins_
unsigned long long cacheIDMagField_
float getVal(size_t hitNr, float MatchInfo::*val) const
std::vector< TrajectorySeed > TrajectorySeedCollection
edm::ESHandle< MagneticField > magField_
MatchInfo(const DetId &iDetId, float iDRZPos, float iDRZNeg, float iDPhiPos, float iDPhiNeg)
std::vector< MatchInfo > matchInfo_
virtual bool isDefined(const GlobalPoint &) const
True if the point is within the region where the concrete field.
Definition: MagneticField.h:40
std::vector< std::unique_ptr< MatchingCuts > > matchingCuts_
std::string paramMagFieldLabel_
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxPosChargeCache_
void setExtra(float et, float eta, float phi, int charge, int nrClus)
double f[11][100]
float dPhiPos(size_t hitNr) const
T min(T a, T b)
Definition: MathUtil.h:58
std::string navSchoolLabel_
const TrajectorySeed & seed() const
Definition: DetId.h:17
const std::vector< double > dRZMaxLowEtEtaBins_
std::unordered_map< std::pair< int, GlobalPoint >, T, HashIntGlobalPointPair > IntGlobalPointPairUnorderedMap
Definition: utils.h:20
edm::Handle< MeasurementTrackerEvent > measTkEvt_
HLT enums.
const TrackingRecHit * hit_
std::string detLayerGeomLabel_
float dRZNeg(size_t hitNr) const
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxNegChargeCache_
std::unique_ptr< PropagatorWithMaterial > backwardPropagator_
const TrajectorySeed & seed_
def move(src, dest)
Definition: eostools.py:511
#define constexpr
*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
Definition: invegas.h:5
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118
float dPhiNeg(size_t hitNr) const
float getCutValue(float et, float highEt, float highEtThres, float lowEtGrad) const
const std::vector< unsigned int > minNrHits_