CMS 3D CMS Logo

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 //
7 // Part of the refactorisation of of the E/gamma pixel matching for 2017 pixels
8 // This refactorisation converts the monolithic approach to a series of
9 // independent producer modules, with each modules performing a specific
10 // job as recommended by the 2017 tracker framework
11 //
12 //
13 // The module is based of PixelHitMatcher (the seed based functions) but
14 // extended to match on an arbitary number of hits rather than just doublets.
15 // It is also aware of how many layers the supercluster trajectory passed through
16 // and uses that information to determine how many hits to require
17 // Other than that, its a direct port and follows what PixelHitMatcher did
18 //
19 //
20 // Author : Sam Harper (RAL), 2017
21 //
22 //*******************************************************************************
23 
24 
25 
26 
28 
31 
40 
41 #include <unordered_map>
42 
43 namespace edm{
44  class EventSetup;
46  class ParameterSet;
48 }
49 
51 class TrackingRecHit;
52 
53 
54 //stolen from PixelHitMatcher
55 //decide if its evil or not later
56 //actually I think the answer is, yes, yes its evil
57 //maybe replace with less evil?
58 namespace std{
59  template<>
60  struct hash<std::pair<int,GlobalPoint> > {
61  std::size_t operator()(const std::pair<int,GlobalPoint>& g) const {
62  auto h1 = std::hash<unsigned long long>()((unsigned long long)g.first);
63  unsigned long long k; memcpy(&k, &g.second,sizeof(k));
64  auto h2 = std::hash<unsigned long long>()(k);
65  return h1 ^ (h2 << 1);
66  }
67  };
68  template<>
69  struct equal_to<std::pair<int,GlobalPoint> > : public std::binary_function<std::pair<int,GlobalPoint>,std::pair<int,GlobalPoint>,bool> {
70  bool operator()(const std::pair<int,GlobalPoint>& a,
71  const std::pair<int,GlobalPoint>& b) const {
72  return (a.first == b.first) & (a.second == b.second);
73  }
74  };
75 }
76 
78 public:
79  class HitInfo {
80  public:
81  HitInfo():detId_(0),
82  dRZ_(std::numeric_limits<float>::max()),
83  dPhi_(std::numeric_limits<float>::max()),
84  hit_(nullptr){}
85 
86  HitInfo(const GlobalPoint& vtxPos,
87  const TrajectoryStateOnSurface& trajState,
88  const TrackingRecHit& hit);
89  ~HitInfo()=default;
90 
91  int subdetId()const{return detId_.subdetId();}
92  DetId detId()const{return detId_;}
93  float dRZ()const{return dRZ_;}
94  float dPhi()const{return dPhi_;}
95  const GlobalPoint& pos()const{return pos_;}
96  const TrackingRecHit* hit()const{return hit_;}
97  private:
100  float dRZ_;
101  float dPhi_;
102  const TrackingRecHit* hit_; //we do not own this
103  };
104 
105  struct MatchInfo {
106  public:
108  float dRZPos,dRZNeg;
109  float dPhiPos,dPhiNeg;
110 
111  MatchInfo(const DetId& iDetId,
112  float iDRZPos,float iDRZNeg,
113  float iDPhiPos,float iDPhiNeg):
114  detId(iDetId),dRZPos(iDRZPos),dRZNeg(iDRZNeg),
115  dPhiPos(iDPhiPos),dPhiNeg(iDPhiNeg){}
116  };
117 
118  class SeedWithInfo {
119  public:
121  const std::vector<HitInfo>& posCharge,
122  const std::vector<HitInfo>& negCharge,
123  int nrValidLayers);
124  ~SeedWithInfo()=default;
125 
126  const TrajectorySeed& seed()const{return seed_;}
127  float dRZPos(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dRZPos);}
128  float dRZNeg(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dRZNeg);}
129  float dPhiPos(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dPhiPos);}
130  float dPhiNeg(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dPhiNeg);}
131  DetId detId(size_t hitNr)const{return hitNr<matchInfo_.size() ? matchInfo_[hitNr].detId : DetId(0);}
132  size_t nrMatchedHits()const{return matchInfo_.size();}
133  const std::vector<MatchInfo>& matches()const{return matchInfo_;}
134  int nrValidLayers()const{return nrValidLayers_;}
135  private:
136  float getVal(size_t hitNr,float MatchInfo::*val)const{
137  return hitNr<matchInfo_.size() ? matchInfo_[hitNr].*val : std::numeric_limits<float>::max();
138  }
139 
140  private:
142  std::vector<MatchInfo> matchInfo_;
144  };
145 
146  class MatchingCuts {
147  public:
148  explicit MatchingCuts(const edm::ParameterSet& pset);
149  bool operator()(const HitInfo& hit,const float scEt,const float scEta)const;
150  private:
151  float getDRZCutValue(const float scEt,const float scEta)const;
152  private:
153  const double dPhiMax_;
154  const double dRZMax_;
155  const double dRZMaxLowEtThres_;
156  const std::vector<double> dRZMaxLowEtEtaBins_;
157  const std::vector<double> dRZMaxLowEt_;
158  };
159 
160 public:
161  explicit TrajSeedMatcher(const edm::ParameterSet& pset);
162  ~TrajSeedMatcher()=default;
163 
164  static edm::ParameterSetDescription makePSetDescription();
165 
166  void doEventSetup(const edm::EventSetup& iSetup);
167 
168  std::vector<TrajSeedMatcher::SeedWithInfo>
169  compatibleSeeds(const TrajectorySeedCollection& seeds, const GlobalPoint& candPos,
170  const GlobalPoint & vprim, const float energy);
171 
173 
174 private:
175 
176  std::vector<HitInfo> processSeed(const TrajectorySeed& seed, const GlobalPoint& candPos,
177  const GlobalPoint & vprim, const float energy, const int charge );
178 
179  static float getZVtxFromExtrapolation(const GlobalPoint& primeVtxPos,const GlobalPoint& hitPos,
180  const GlobalPoint& candPos);
181 
182  bool passTrajPreSel(const GlobalPoint& hitPos,const GlobalPoint& candPos)const;
183 
184  TrajSeedMatcher::HitInfo matchFirstHit(const TrajectorySeed& seed,
185  const TrajectoryStateOnSurface& trajState,
186  const GlobalPoint& vtxPos,
188 
189  TrajSeedMatcher::HitInfo match2ndToNthHit(const TrajectorySeed& seed,
190  const FreeTrajectoryState& trajState,
191  const size_t hitNr,
192  const GlobalPoint& prevHitPos,
193  const GlobalPoint& vtxPos,
194  const PropagatorWithMaterial& propagator);
195 
196  const TrajectoryStateOnSurface& getTrajStateFromVtx(const TrackingRecHit& hit,const TrajectoryStateOnSurface& initialState,const PropagatorWithMaterial& propagator);
197  const TrajectoryStateOnSurface& getTrajStateFromPoint(const TrackingRecHit& hit,const FreeTrajectoryState& initialState,const GlobalPoint& point,const PropagatorWithMaterial& propagator);
198 
199  void clearCache();
200 
201  bool passesMatchSel(const HitInfo& hit,const size_t hitNr,const float scEt,const float scEta)const;
202  int getNrValidLayersAlongTraj(const HitInfo& hit1,const HitInfo& hit2,
203  const GlobalPoint& candPos,
204  const GlobalPoint & vprim,
205  const float energy, const int charge);
206 
207  int getNrValidLayersAlongTraj(const DetId& hitId,
208  const TrajectoryStateOnSurface& hitTrajState)const;
209 
210  bool layerHasValidHits(const DetLayer& layer,const TrajectoryStateOnSurface& hitSurState,
211  const Propagator& propToLayerFromState)const;
212 
213  size_t getNrHitsRequired(const int nrValidLayers)const;
214 
215 private:
216  static constexpr float kElectronMass_ = 0.000511;
217  static constexpr float kPhiCut_ = -0.801144;//cos(2.5)
218  std::unique_ptr<PropagatorWithMaterial> forwardPropagator_;
219  std::unique_ptr<PropagatorWithMaterial> backwardPropagator_;
220  unsigned long long cacheIDMagField_;
227 
229  std::vector<MatchingCuts> matchingCuts_;
230 
231  //these two varibles determine how hits we require
232  //based on how many valid layers we had
233  //right now we always need atleast two hits
234  //also highly dependent on the seeds you pass in
235  //which also require a given number of hits
236  const std::vector<unsigned int> minNrHits_;
237  const std::vector<int> minNrHitsValidLayerBins_;
238 
239  std::unordered_map<int,TrajectoryStateOnSurface> trajStateFromVtxPosChargeCache_;
240  std::unordered_map<int,TrajectoryStateOnSurface> trajStateFromVtxNegChargeCache_;
241 
242  std::unordered_map<std::pair<int,GlobalPoint>,TrajectoryStateOnSurface> trajStateFromPointPosChargeCache_;
243  std::unordered_map<std::pair<int,GlobalPoint>,TrajectoryStateOnSurface> trajStateFromPointNegChargeCache_;
244 
245 };
246 
247 #endif
std::unordered_map< std::pair< int, GlobalPoint >, TrajectoryStateOnSurface > trajStateFromPointNegChargeCache_
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxNegChargeCache_
DetId detId(size_t hitNr) const
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxPosChargeCache_
edm::ESHandle< DetLayerGeometry > detLayerGeom_
float dRZPos(size_t hitNr) const
std::unique_ptr< PropagatorWithMaterial > forwardPropagator_
const std::vector< MatchInfo > & matches() const
const std::vector< int > minNrHitsValidLayerBins_
bool operator()(const std::pair< int, GlobalPoint > &a, const std::pair< int, GlobalPoint > &b) const
#define nullptr
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 g
Definition: Activities.doc:4
#define constexpr
void setMeasTkEvtHandle(edm::Handle< MeasurementTrackerEvent > handle)
edm::ESHandle< NavigationSchool > navSchool_
unsigned long long cacheIDMagField_
float getVal(size_t hitNr, float MatchInfo::*val) const
std::unordered_map< std::pair< int, GlobalPoint >, TrajectoryStateOnSurface > trajStateFromPointPosChargeCache_
std::vector< TrajectorySeed > TrajectorySeedCollection
edm::ESHandle< MagneticField > magField_
MatchInfo(const DetId &iDetId, float iDRZPos, float iDRZNeg, float iDPhiPos, float iDPhiNeg)
std::vector< MatchingCuts > matchingCuts_
std::vector< MatchInfo > matchInfo_
float dPhiPos(size_t hitNr) const
const std::vector< double > dRZMaxLowEtEtaBins_
const GlobalPoint & pos() const
int k[5][pyjets_maxn]
std::string navSchoolLabel_
const TrajectorySeed & seed() const
Definition: DetId.h:18
const TrackingRecHit * hit_
edm::Handle< MeasurementTrackerEvent > measTkEvt_
double b
Definition: hdecay.h:120
std::size_t operator()(const std::pair< int, GlobalPoint > &g) const
const TrackingRecHit * hit() const
HLT enums.
const std::vector< double > dRZMaxLowEt_
double a
Definition: hdecay.h:121
std::string detLayerGeomLabel_
float dRZNeg(size_t hitNr) const
std::unique_ptr< PropagatorWithMaterial > backwardPropagator_
const TrajectorySeed & seed_
def move(src, dest)
Definition: eostools.py:510
*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:142
float dPhiNeg(size_t hitNr) const
const std::vector< unsigned int > minNrHits_