CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HitPairGeneratorFromLayerPair.cc
Go to the documentation of this file.
3 
7 
13 
15 
16 using namespace GeomDetEnumerators;
17 using namespace std;
18 
20 
21 namespace {
22  template<class T> inline T sqr( T t) {return t*t;}
23 }
24 
25 
31 
33  unsigned int inner,
34  unsigned int outer,
35  LayerCacheType* layerCache,
36  unsigned int nSize,
37  unsigned int max)
38  : HitPairGenerator(nSize),
39  theLayerCache(*layerCache), theOuterLayer(outer), theInnerLayer(inner)
40 {
42 }
43 
44 
45 // devirtualizer
46 #include<tuple>
47 namespace {
48 
49  template<typename Algo>
50  struct Kernel {
51  using Base = HitRZCompatibility;
52  void set(Base const * a) {
53  assert( a->algo()==Algo::me);
54  checkRZ=reinterpret_cast<Algo const *>(a);
55  }
56 
57  void operator()(int b, int e, const RecHitsSortedInPhi & innerHitsMap, bool * ok) const {
58  constexpr float nSigmaRZ = 3.46410161514f; // std::sqrt(12.f);
59  for (int i=b; i!=e; ++i) {
60  Range allowed = checkRZ->range(innerHitsMap.u[i]);
61  float vErr = nSigmaRZ * innerHitsMap.dv[i];
62  Range hitRZ(innerHitsMap.v[i]-vErr, innerHitsMap.v[i]+vErr);
63  Range crossRange = allowed.intersection(hitRZ);
64  ok[i-b] = ! crossRange.empty() ;
65  }
66  }
67  Algo const * checkRZ;
68 
69  };
70 
71 
72  template<typename ... Args> using Kernels = std::tuple<Kernel<Args>...>;
73 
74 }
75 
76 
78  const TrackingRegion & region, OrderedHitPairs & result,
79  const edm::Event& iEvent, const edm::EventSetup& iSetup) {
80 
81  auto const & ds = doublets(region, iEvent, iSetup);
82  for (std::size_t i=0; i!=ds.size(); ++i) {
83  result.push_back( OrderedHitPair( ds.hit(i,HitDoublets::inner),ds.hit(i,HitDoublets::outer) ));
84  }
85  if (theMaxElement!=0 && result.size() >= theMaxElement){
86  result.clear();
87  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
88  }
89 }
90 
91 
93  const edm::Event & iEvent, const edm::EventSetup& iSetup) {
94 
95  typedef OrderedHitPair::InnerRecHit InnerHit;
96  typedef OrderedHitPair::OuterRecHit OuterHit;
98 
99  Layer innerLayerObj = innerLayer();
100  Layer outerLayerObj = outerLayer();
101 
102  const RecHitsSortedInPhi & innerHitsMap = theLayerCache(innerLayerObj, region, iEvent, iSetup);
103  if (innerHitsMap.empty()) return HitDoublets(innerHitsMap,innerHitsMap);
104 
105  const RecHitsSortedInPhi& outerHitsMap = theLayerCache(outerLayerObj, region, iEvent, iSetup);
106  if (outerHitsMap.empty()) return HitDoublets(innerHitsMap,outerHitsMap);
107 
108  HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
109 
110  InnerDeltaPhi deltaPhi(*outerLayerObj.detLayer(), *innerLayerObj.detLayer(), region, iSetup);
111 
112  // std::cout << "layers " << theInnerLayer.detLayer()->seqNum() << " " << outerLayer.detLayer()->seqNum() << std::endl;
113 
114  // constexpr float nSigmaRZ = std::sqrt(12.f);
115  constexpr float nSigmaPhi = 3.f;
116  for (int io = 0; io!=int(outerHitsMap.theHits.size()); ++io) {
117  Hit const & ohit = outerHitsMap.theHits[io].hit();
118  PixelRecoRange<float> phiRange = deltaPhi(outerHitsMap.x[io],
119  outerHitsMap.y[io],
120  outerHitsMap.z[io],
121  nSigmaPhi*outerHitsMap.drphi[io]
122  );
123 
124  if (phiRange.empty()) continue;
125 
126  const HitRZCompatibility *checkRZ = region.checkRZ(innerLayerObj.detLayer(), ohit, iSetup, outerLayerObj.detLayer(),
127  outerHitsMap.rv(io),outerHitsMap.z[io],
128  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
129  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]
130  );
131  if(!checkRZ) continue;
132 
133  Kernels<HitZCheck,HitRCheck,HitEtaCheck> kernels;
134 
135  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
136  LogDebug("HitPairGeneratorFromLayerPair")<<
137  "preparing for combination of: "<< innerRange[1]-innerRange[0]+innerRange[3]-innerRange[2]
138  <<" inner and: "<< outerHitsMap.theHits.size()<<" outter";
139  for(int j=0; j<3; j+=2) {
140  auto b = innerRange[j]; auto e=innerRange[j+1];
141  bool ok[e-b];
142  switch (checkRZ->algo()) {
144  std::get<0>(kernels).set(checkRZ);
145  std::get<0>(kernels)(b,e,innerHitsMap, ok);
146  break;
148  std::get<1>(kernels).set(checkRZ);
149  std::get<1>(kernels)(b,e,innerHitsMap, ok);
150  break;
152  std::get<2>(kernels).set(checkRZ);
153  std::get<2>(kernels)(b,e,innerHitsMap, ok);
154  break;
155  }
156  for (int i=0; i!=e-b; ++i) {
157  if (!ok[i]) continue;
158  if (theMaxElement!=0 && result.size() >= theMaxElement){
159  result.clear();
160  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
161  delete checkRZ;
162  return result;
163  }
164  result.add(b+i,io);
165  }
166  }
167  delete checkRZ;
168  }
169  LogDebug("HitPairGeneratorFromLayerPair")<<" total number of pairs provided back: "<<result.size();
170  return result;
171 }
#define LogDebug(id)
std::vector< HitWithPhi > theHits
int i
Definition: DBlmapReader.cc:9
std::size_t size() const
std::vector< float > drphi
T max() const
std::vector< float > z
SeedingHitSet::ConstRecHitPointer InnerRecHit
bool empty() const
virtual unsigned int size() const
T min() const
virtual void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::Event &ev, const edm::EventSetup &es)
std::vector< float > x
DoubleRange doubleRange(float phiMin, float phiMax) const
void reserve(std::size_t s)
int iEvent
Definition: GenABIO.cc:230
virtual HitRZCompatibility * checkRZ(const DetLayer *layer, const Hit &outerHit, const edm::EventSetup &iSetup, const DetLayer *outerlayer=0, float lr=0, float gz=0, float dr=0, float dz=0) const =0
const T & max(const T &a, const T &b)
constexpr double nSigmaRZ
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
std::vector< float > y
std::vector< float > v
constexpr double nSigmaPhi
std::size_t size() const
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
PixelRecoRange< float > Range
double b
Definition: hdecay.h:120
const DetLayer * detLayer() const
std::vector< float > dv
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
double a
Definition: hdecay.h:121
Square< F >::type sqr(const F &f)
Definition: Square.h:13
float rv(int i) const
std::vector< float > u
virtual HitDoublets doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es)
std::vector< float > du
void add(int il, int ol)
long double T
HitPairGeneratorFromLayerPair(unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int nSize=30000, unsigned int max=0)
Definition: fakeMenu.h:6
#define constexpr
SeedingHitSet::ConstRecHitPointer OuterRecHit