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 }
69 
71 public:
72  class SCHitMatch {
73  public:
74  SCHitMatch():detId_(0),
75  dRZ_(std::numeric_limits<float>::max()),
76  dPhi_(std::numeric_limits<float>::max()),
77  hit_(nullptr),
78  et_(0),eta_(0),phi_(0),charge_(0),nrClus_(0){}
79 
80  //does not set charge,et,nrclus
81  SCHitMatch(const GlobalPoint& vtxPos,
82  const TrajectoryStateOnSurface& trajState,
83  const TrackingRecHit& hit
84  );
85  ~SCHitMatch()=default;
86 
87  void setExtra(float et, float eta, float phi, int charge, int nrClus){
88  et_=et;
89  eta_=eta;
90  phi_=phi;
91  charge_=charge;
92  nrClus_=nrClus;
93  }
94 
95  int subdetId()const{return detId_.subdetId();}
96  DetId detId()const{return detId_;}
97  float dRZ()const{return dRZ_;}
98  float dPhi()const{return dPhi_;}
99  const GlobalPoint& hitPos()const{return hitPos_;}
100  float et()const{return et_;}
101  float eta()const{return eta_;}
102  float phi()const{return phi_;}
103  int charge()const{return charge_;}
104  int nrClus()const{return nrClus_;}
105  const TrackingRecHit* hit()const{return hit_;}
106  private:
109  float dRZ_;
110  float dPhi_;
111  const TrackingRecHit* hit_; //we do not own this
112  //extra quanities which are set later
113  float et_;
114  float eta_;
115  float phi_;
116  int charge_;
117  int nrClus_;
118  };
119 
120 
121 
122  struct MatchInfo {
123  public:
125  float dRZPos,dRZNeg;
126  float dPhiPos,dPhiNeg;
127 
128  MatchInfo(const DetId& iDetId,
129  float iDRZPos, float iDRZNeg,
130  float iDPhiPos, float iDPhiNeg):
131  detId(iDetId),dRZPos(iDRZPos),dRZNeg(iDRZNeg),
132  dPhiPos(iDPhiPos),dPhiNeg(iDPhiNeg){}
133  };
134 
135  class SeedWithInfo {
136  public:
138  const std::vector<SCHitMatch>& posCharge,
139  const std::vector<SCHitMatch>& negCharge,
140  int nrValidLayers);
141  ~SeedWithInfo()=default;
142 
143  const TrajectorySeed& seed()const{return seed_;}
144  float dRZPos(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dRZPos);}
145  float dRZNeg(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dRZNeg);}
146  float dPhiPos(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dPhiPos);}
147  float dPhiNeg(size_t hitNr)const{return getVal(hitNr,&MatchInfo::dPhiNeg);}
148  DetId detId(size_t hitNr)const{return hitNr<matchInfo_.size() ? matchInfo_[hitNr].detId : DetId(0);}
149  size_t nrMatchedHits()const{return matchInfo_.size();}
150  const std::vector<MatchInfo>& matches()const{return matchInfo_;}
151  int nrValidLayers()const{return nrValidLayers_;}
152  private:
153  float getVal(size_t hitNr,float MatchInfo::*val)const{
154  return hitNr<matchInfo_.size() ? matchInfo_[hitNr].*val : std::numeric_limits<float>::max();
155  }
156 
157  private:
159  std::vector<MatchInfo> matchInfo_;
161  };
162 
163  class MatchingCuts {
164  public:
166  virtual ~MatchingCuts(){}
167  virtual bool operator()(const SCHitMatch& scHitMatch)const=0;
168  };
169 
170  class MatchingCutsV1 : public MatchingCuts {
171  public:
172  explicit MatchingCutsV1(const edm::ParameterSet& pset);
173  bool operator()(const SCHitMatch& scHitMatch)const override;
174  private:
175  float getDRZCutValue(const float scEt, const float scEta)const;
176  private:
177  const double dPhiMax_;
178  const double dRZMax_;
179  const double dRZMaxLowEtThres_;
180  const std::vector<double> dRZMaxLowEtEtaBins_;
181  const std::vector<double> dRZMaxLowEt_;
182  };
183 
184  class MatchingCutsV2 : public MatchingCuts {
185  public:
186  explicit MatchingCutsV2(const edm::ParameterSet& pset);
187  bool operator()(const SCHitMatch& scHitMatch)const override;
188  private:
189  size_t getBinNr(float eta)const;
190  float getCutValue(float et, float highEt, float highEtThres, float lowEtGrad)const{
191  return highEt + std::min(0.f,et-highEtThres)*lowEtGrad;
192  }
193  private:
194  std::vector<double> dPhiHighEt_,dPhiHighEtThres_,dPhiLowEtGrad_;
195  std::vector<double> dRZHighEt_,dRZHighEtThres_,dRZLowEtGrad_;
196  std::vector<double> etaBins_;
197  };
198 
199 
200 public:
201  explicit TrajSeedMatcher(const edm::ParameterSet& pset);
202  ~TrajSeedMatcher()=default;
203 
204  static edm::ParameterSetDescription makePSetDescription();
205 
206  void doEventSetup(const edm::EventSetup& iSetup);
207 
208  std::vector<TrajSeedMatcher::SeedWithInfo>
209  compatibleSeeds(const TrajectorySeedCollection& seeds, const GlobalPoint& candPos,
210  const GlobalPoint & vprim, const float energy);
211 
213 
214 private:
215 
216  std::vector<SCHitMatch> processSeed(const TrajectorySeed& seed, const GlobalPoint& candPos,
217  const GlobalPoint & vprim, const float energy, const int charge );
218 
219  static float getZVtxFromExtrapolation(const GlobalPoint& primeVtxPos, const GlobalPoint& hitPos,
220  const GlobalPoint& candPos);
221 
222  bool passTrajPreSel(const GlobalPoint& hitPos,const GlobalPoint& candPos)const;
223 
224  TrajSeedMatcher::SCHitMatch matchFirstHit(const TrajectorySeed& seed,
225  const TrajectoryStateOnSurface& trajState,
226  const GlobalPoint& vtxPos,
228 
229  TrajSeedMatcher::SCHitMatch match2ndToNthHit(const TrajectorySeed& seed,
230  const FreeTrajectoryState& trajState,
231  const size_t hitNr,
232  const GlobalPoint& prevHitPos,
233  const GlobalPoint& vtxPos,
234  const PropagatorWithMaterial& propagator);
235 
236  const TrajectoryStateOnSurface& getTrajStateFromVtx(const TrackingRecHit& hit,
237  const TrajectoryStateOnSurface& initialState,
238  const PropagatorWithMaterial& propagator);
239 
240  const TrajectoryStateOnSurface& getTrajStateFromPoint(const TrackingRecHit& hit,
241  const FreeTrajectoryState& initialState,
242  const GlobalPoint& point,
243  const PropagatorWithMaterial& propagator);
244 
245  void clearCache();
246 
247  bool passesMatchSel(const SCHitMatch& hit, const size_t hitNr)const;
248 
249  int getNrValidLayersAlongTraj(const SCHitMatch& hit1, const SCHitMatch& hit2,
250  const GlobalPoint& candPos,
251  const GlobalPoint & vprim,
252  const float energy, const int charge);
253 
254  int getNrValidLayersAlongTraj(const DetId& hitId,
255  const TrajectoryStateOnSurface& hitTrajState)const;
256 
257  bool layerHasValidHits(const DetLayer& layer,const TrajectoryStateOnSurface& hitSurState,
258  const Propagator& propToLayerFromState)const;
259 
260  size_t getNrHitsRequired(const int nrValidLayers)const;
261 
262 private:
263  static constexpr float kElectronMass_ = 0.000511;
264  static constexpr float kPhiCut_ = -0.801144;//cos(2.5)
265  std::unique_ptr<PropagatorWithMaterial> forwardPropagator_;
266  std::unique_ptr<PropagatorWithMaterial> backwardPropagator_;
267  unsigned long long cacheIDMagField_;
274 
276  std::vector<std::unique_ptr<MatchingCuts> > matchingCuts_;
277 
278  //these two varibles determine how hits we require
279  //based on how many valid layers we had
280  //right now we always need atleast two hits
281  //also highly dependent on the seeds you pass in
282  //which also require a given number of hits
283  const std::vector<unsigned int> minNrHits_;
284  const std::vector<int> minNrHitsValidLayerBins_;
285 
286  std::unordered_map<int,TrajectoryStateOnSurface> trajStateFromVtxPosChargeCache_;
287  std::unordered_map<int,TrajectoryStateOnSurface> trajStateFromVtxNegChargeCache_;
288 
289  std::unordered_map<std::pair<int,GlobalPoint>,TrajectoryStateOnSurface> trajStateFromPointPosChargeCache_;
290  std::unordered_map<std::pair<int,GlobalPoint>,TrajectoryStateOnSurface> trajStateFromPointNegChargeCache_;
291 
292 };
293 
294 #endif
const GlobalPoint & hitPos() const
std::unordered_map< std::pair< int, GlobalPoint >, TrajectoryStateOnSurface > trajStateFromPointNegChargeCache_
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxNegChargeCache_
DetId detId(size_t hitNr) const
std::vector< double > dRZLowEtGrad_
std::vector< double > dPhiLowEtGrad_
std::unordered_map< int, TrajectoryStateOnSurface > trajStateFromVtxPosChargeCache_
const TrackingRecHit * hit() const
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_
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
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::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< MatchInfo > matchInfo_
std::vector< std::unique_ptr< MatchingCuts > > matchingCuts_
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
int k[5][pyjets_maxn]
std::string navSchoolLabel_
const TrajectorySeed & seed() const
Definition: DetId.h:18
const std::vector< double > dRZMaxLowEtEtaBins_
edm::Handle< MeasurementTrackerEvent > measTkEvt_
std::size_t operator()(const std::pair< int, GlobalPoint > &g) const
et
define resolution functions of each parameter
HLT enums.
const TrackingRecHit * hit_
std::string detLayerGeomLabel_
float dRZNeg(size_t hitNr) const
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:142
float dPhiNeg(size_t hitNr) const
float getCutValue(float et, float highEt, float highEtThres, float lowEtGrad) const
const std::vector< unsigned int > minNrHits_