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