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