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 
90  const edm::Event & iEvent, const edm::EventSetup& iSetup, Layers layers) {
91 
92  typedef OrderedHitPair::InnerRecHit InnerHit;
93  typedef OrderedHitPair::OuterRecHit OuterHit;
95 
96  Layer innerLayerObj = innerLayer(layers);
97  Layer outerLayerObj = outerLayer(layers);
98 
99  const RecHitsSortedInPhi & innerHitsMap = theLayerCache(innerLayerObj, region, iEvent, iSetup);
100  if (innerHitsMap.empty()) return HitDoublets(innerHitsMap,innerHitsMap);
101 
102  const RecHitsSortedInPhi& outerHitsMap = theLayerCache(outerLayerObj, region, iEvent, iSetup);
103  if (outerHitsMap.empty()) return HitDoublets(innerHitsMap,outerHitsMap);
104  HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
105  doublets(region,
106  *innerLayerObj.detLayer(),*outerLayerObj.detLayer(),
107  innerHitsMap,outerHitsMap,iSetup,theMaxElement,result);
108  return result;
109 
110 }
111 
113  const DetLayer & innerHitDetLayer,
114  const DetLayer & outerHitDetLayer,
115  const RecHitsSortedInPhi & innerHitsMap,
116  const RecHitsSortedInPhi & outerHitsMap,
117  const edm::EventSetup& iSetup,
118  const unsigned int theMaxElement,
119  HitDoublets & result){
120 
121  // HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
123  InnerDeltaPhi deltaPhi(outerHitDetLayer, innerHitDetLayer, region, iSetup);
124 
125  // std::cout << "layers " << theInnerLayer.detLayer()->seqNum() << " " << outerLayer.detLayer()->seqNum() << std::endl;
126 
127  // constexpr float nSigmaRZ = std::sqrt(12.f);
128  constexpr float nSigmaPhi = 3.f;
129  for (int io = 0; io!=int(outerHitsMap.theHits.size()); ++io) {
130  if (!deltaPhi.prefilter(outerHitsMap.x[io],outerHitsMap.y[io])) continue;
131  Hit const & ohit = outerHitsMap.theHits[io].hit();
132  PixelRecoRange<float> phiRange = deltaPhi(outerHitsMap.x[io],
133  outerHitsMap.y[io],
134  outerHitsMap.z[io],
135  nSigmaPhi*outerHitsMap.drphi[io]
136  );
137 
138  if (phiRange.empty()) continue;
139 
140  const HitRZCompatibility *checkRZ = region.checkRZ(&innerHitDetLayer, ohit, iSetup, &outerHitDetLayer,
141  outerHitsMap.rv(io),outerHitsMap.z[io],
142  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
143  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]
144  );
145  if(!checkRZ) continue;
146 
147  Kernels<HitZCheck,HitRCheck,HitEtaCheck> kernels;
148 
149  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
150  LogDebug("HitPairGeneratorFromLayerPair")<<
151  "preparing for combination of: "<< innerRange[1]-innerRange[0]+innerRange[3]-innerRange[2]
152  <<" inner and: "<< outerHitsMap.theHits.size()<<" outter";
153  for(int j=0; j<3; j+=2) {
154  auto b = innerRange[j]; auto e=innerRange[j+1];
155  bool ok[e-b];
156  switch (checkRZ->algo()) {
158  std::get<0>(kernels).set(checkRZ);
159  std::get<0>(kernels)(b,e,innerHitsMap, ok);
160  break;
162  std::get<1>(kernels).set(checkRZ);
163  std::get<1>(kernels)(b,e,innerHitsMap, ok);
164  break;
166  std::get<2>(kernels).set(checkRZ);
167  std::get<2>(kernels)(b,e,innerHitsMap, ok);
168  break;
169  }
170  for (int i=0; i!=e-b; ++i) {
171  if (!ok[i]) continue;
172  if (theMaxElement!=0 && result.size() >= theMaxElement){
173  result.clear();
174  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
175  delete checkRZ;
176  return;
177  }
178  result.add(b+i,io);
179  }
180  }
181  delete checkRZ;
182  }
183  LogDebug("HitPairGeneratorFromLayerPair")<<" total number of pairs provided back: "<<result.size();
184  result.shrink_to_fit();
185 
186 }
187 
188 
#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)
PixelRecoRange< float > Range
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)
tuple result
Definition: mps_fire.py:83
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
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
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
bool prefilter(float xHit, float yHit) const
Definition: InnerDeltaPhi.h:32
std::vector< float > du
void add(int il, int ol)
long double T
Definition: fakeMenu.h:6
SeedingHitSet::ConstRecHitPointer OuterRecHit