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 max)
37  : theLayerCache(*layerCache), theOuterLayer(outer), theInnerLayer(inner), theMaxElement(max)
38 {
39 }
40 
42 
43 // devirtualizer
44 #include<tuple>
45 namespace {
46 
47  template<typename Algo>
48  struct Kernel {
49  using Base = HitRZCompatibility;
50  void set(Base const * a) {
51  assert( a->algo()==Algo::me);
52  checkRZ=reinterpret_cast<Algo const *>(a);
53  }
54 
55  void operator()(int b, int e, const RecHitsSortedInPhi & innerHitsMap, bool * ok) const {
56  constexpr float nSigmaRZ = 3.46410161514f; // std::sqrt(12.f);
57  for (int i=b; i!=e; ++i) {
58  Range allowed = checkRZ->range(innerHitsMap.u[i]);
59  float vErr = nSigmaRZ * innerHitsMap.dv[i];
60  Range hitRZ(innerHitsMap.v[i]-vErr, innerHitsMap.v[i]+vErr);
61  Range crossRange = allowed.intersection(hitRZ);
62  ok[i-b] = ! crossRange.empty() ;
63  }
64  }
65  Algo const * checkRZ;
66 
67  };
68 
69 
70  template<typename ... Args> using Kernels = std::tuple<Kernel<Args>...>;
71 
72 }
73 
74 
77  const edm::Event& iEvent, const edm::EventSetup& iSetup, Layers layers) {
78 
79  auto const & ds = doublets(region, iEvent, iSetup, layers);
80  for (std::size_t i=0; i!=ds.size(); ++i) {
81  result.push_back( OrderedHitPair( ds.hit(i,HitDoublets::inner),ds.hit(i,HitDoublets::outer) ));
82  }
83  if (theMaxElement!=0 && result.size() >= theMaxElement){
84  result.clear();
85  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
86  }
87 }
88 
89 
91  const edm::Event & iEvent, const edm::EventSetup& iSetup, Layers layers) {
92 
93  typedef OrderedHitPair::InnerRecHit InnerHit;
94  typedef OrderedHitPair::OuterRecHit OuterHit;
96 
97  Layer innerLayerObj = innerLayer(layers);
98  Layer outerLayerObj = outerLayer(layers);
99 
100  const RecHitsSortedInPhi & innerHitsMap = theLayerCache(innerLayerObj, region, iEvent, iSetup);
101  if (innerHitsMap.empty()) return HitDoublets(innerHitsMap,innerHitsMap);
102 
103  const RecHitsSortedInPhi& outerHitsMap = theLayerCache(outerLayerObj, region, iEvent, iSetup);
104  if (outerHitsMap.empty()) return HitDoublets(innerHitsMap,outerHitsMap);
105 
106  HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
107 
108  InnerDeltaPhi deltaPhi(*outerLayerObj.detLayer(), *innerLayerObj.detLayer(), region, iSetup);
109 
110  // std::cout << "layers " << theInnerLayer.detLayer()->seqNum() << " " << outerLayer.detLayer()->seqNum() << std::endl;
111 
112  // constexpr float nSigmaRZ = std::sqrt(12.f);
113  constexpr float nSigmaPhi = 3.f;
114  for (int io = 0; io!=int(outerHitsMap.theHits.size()); ++io) {
115  Hit const & ohit = outerHitsMap.theHits[io].hit();
116  PixelRecoRange<float> phiRange = deltaPhi(outerHitsMap.x[io],
117  outerHitsMap.y[io],
118  outerHitsMap.z[io],
119  nSigmaPhi*outerHitsMap.drphi[io]
120  );
121 
122  if (phiRange.empty()) continue;
123 
124  const HitRZCompatibility *checkRZ = region.checkRZ(innerLayerObj.detLayer(), ohit, iSetup, outerLayerObj.detLayer(),
125  outerHitsMap.rv(io),outerHitsMap.z[io],
126  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
127  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]
128  );
129  if(!checkRZ) continue;
130 
131  Kernels<HitZCheck,HitRCheck,HitEtaCheck> kernels;
132 
133  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
134  LogDebug("HitPairGeneratorFromLayerPair")<<
135  "preparing for combination of: "<< innerRange[1]-innerRange[0]+innerRange[3]-innerRange[2]
136  <<" inner and: "<< outerHitsMap.theHits.size()<<" outter";
137  for(int j=0; j<3; j+=2) {
138  auto b = innerRange[j]; auto e=innerRange[j+1];
139  bool ok[e-b];
140  switch (checkRZ->algo()) {
142  std::get<0>(kernels).set(checkRZ);
143  std::get<0>(kernels)(b,e,innerHitsMap, ok);
144  break;
146  std::get<1>(kernels).set(checkRZ);
147  std::get<1>(kernels)(b,e,innerHitsMap, ok);
148  break;
150  std::get<2>(kernels).set(checkRZ);
151  std::get<2>(kernels)(b,e,innerHitsMap, ok);
152  break;
153  }
154  for (int i=0; i!=e-b; ++i) {
155  if (!ok[i]) continue;
156  if (theMaxElement!=0 && result.size() >= theMaxElement){
157  result.clear();
158  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
159  delete checkRZ;
160  return result;
161  }
162  result.add(b+i,io);
163  }
164  }
165  delete checkRZ;
166  }
167  LogDebug("HitPairGeneratorFromLayerPair")<<" total number of pairs provided back: "<<result.size();
168  result.shrink_to_fit();
169  return result;
170 }
#define LogDebug(id)
std::vector< HitWithPhi > theHits
int i
Definition: DBlmapReader.cc:9
std::size_t size() const
std::vector< float > drphi
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
T max() const
void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
std::vector< float > z
assert(m_qm.get())
SeedingHitSet::ConstRecHitPointer InnerRecHit
bool empty() const
virtual unsigned int size() const
T min() const
#define constexpr
std::vector< float > x
Layer innerLayer(const Layers &layers) const
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
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
std::vector< float > y
std::vector< float > v
HitDoublets doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
std::size_t size() const
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
PixelRecoRange< float > Range
HitPairGeneratorFromLayerPair(unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int max=0)
Layer outerLayer(const Layers &layers) const
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
std::vector< float > du
void add(int il, int ol)
long double T
Definition: fakeMenu.h:6
SeedingHitSet::ConstRecHitPointer OuterRecHit