CMS 3D CMS Logo

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>
23  inline T sqr(T t) {
24  return t * t;
25  }
26 } // namespace
27 
33 
35  unsigned int outer,
36  LayerCacheType* layerCache,
37  unsigned int max)
38  : theLayerCache(layerCache), theOuterLayer(outer), theInnerLayer(inner), theMaxElement(max) {}
39 
41 
42 // devirtualizer
43 #include <tuple>
44 namespace {
45 
46  template <typename Algo>
47  struct Kernel {
48  using Base = HitRZCompatibility;
49  void set(Base const* a) {
50  assert(a->algo() == Algo::me);
51  checkRZ = reinterpret_cast<Algo const*>(a);
52  }
53 
54  void operator()(int b, int e, const RecHitsSortedInPhi& innerHitsMap, bool* ok) const {
55  constexpr float nSigmaRZ = 3.46410161514f; // std::sqrt(12.f);
56  for (int i = b; i != e; ++i) {
57  Range allowed = checkRZ->range(innerHitsMap.u[i]);
58  float vErr = nSigmaRZ * innerHitsMap.dv[i];
59  Range hitRZ(innerHitsMap.v[i] - vErr, innerHitsMap.v[i] + vErr);
60  Range crossRange = allowed.intersection(hitRZ);
61  ok[i - b] = !crossRange.empty();
62  }
63  }
64  Algo const* checkRZ;
65  };
66 
67  template <typename... Args>
68  using Kernels = std::tuple<Kernel<Args>...>;
69 
70 } // namespace
71 
74  const edm::Event& iEvent,
75  const edm::EventSetup& iSetup,
76  Layers layers) {
77  auto const& ds = doublets(region, iEvent, iSetup, layers);
78  for (std::size_t i = 0; i != ds.size(); ++i) {
79  result.push_back(OrderedHitPair(ds.hit(i, HitDoublets::inner), ds.hit(i, HitDoublets::outer)));
80  }
81  if (theMaxElement != 0 && result.size() >= theMaxElement) {
82  result.clear();
83  edm::LogError("TooManyPairs") << "number of pairs exceed maximum, no pairs produced";
84  }
85 }
86 
88  const edm::Event& iEvent,
89  const edm::EventSetup& iSetup,
90  const Layer& innerLayer,
91  const Layer& outerLayer,
92  LayerCacheType& layerCache) {
93  const RecHitsSortedInPhi& innerHitsMap = layerCache(innerLayer, region, iSetup);
94  if (innerHitsMap.empty())
95  return HitDoublets(innerHitsMap, innerHitsMap);
96 
97  const RecHitsSortedInPhi& outerHitsMap = layerCache(outerLayer, region, iSetup);
98  if (outerHitsMap.empty())
99  return HitDoublets(innerHitsMap, outerHitsMap);
100  HitDoublets result(innerHitsMap, outerHitsMap);
101  result.reserve(std::max(innerHitsMap.size(), outerHitsMap.size()));
102  doublets(
103  region, *innerLayer.detLayer(), *outerLayer.detLayer(), innerHitsMap, outerHitsMap, iSetup, theMaxElement, result);
104 
105  return result;
106 }
107 
109  const DetLayer& innerHitDetLayer,
110  const DetLayer& outerHitDetLayer,
111  const RecHitsSortedInPhi& innerHitsMap,
112  const RecHitsSortedInPhi& outerHitsMap,
113  const edm::EventSetup& iSetup,
114  const unsigned int theMaxElement,
115  HitDoublets& result) {
116  // HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
118  InnerDeltaPhi deltaPhi(outerHitDetLayer, innerHitDetLayer, region, iSetup);
119 
120  // std::cout << "layers " << theInnerLayer.detLayer()->seqNum() << " " << outerLayer.detLayer()->seqNum() << std::endl;
121 
122  // constexpr float nSigmaRZ = std::sqrt(12.f);
123  constexpr float nSigmaPhi = 3.f;
124  for (int io = 0; io != int(outerHitsMap.theHits.size()); ++io) {
125  if (!deltaPhi.prefilter(outerHitsMap.x[io], outerHitsMap.y[io]))
126  continue;
127  Hit const& ohit = outerHitsMap.theHits[io].hit();
128  PixelRecoRange<float> phiRange =
129  deltaPhi(outerHitsMap.x[io], outerHitsMap.y[io], outerHitsMap.z[io], nSigmaPhi * outerHitsMap.drphi[io]);
130 
131  if (phiRange.empty())
132  continue;
133 
134  const HitRZCompatibility* checkRZ =
135  region.checkRZ(&innerHitDetLayer,
136  ohit,
137  iSetup,
138  &outerHitDetLayer,
139  outerHitsMap.rv(io),
140  outerHitsMap.z[io],
141  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
142  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]);
143  if (!checkRZ)
144  continue;
145 
146  Kernels<HitZCheck, HitRCheck, HitEtaCheck> kernels;
147 
148  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
149  LogDebug("HitPairGeneratorFromLayerPair")
150  << "preparing for combination of: " << innerRange[1] - innerRange[0] + innerRange[3] - innerRange[2]
151  << " inner and: " << outerHitsMap.theHits.size() << " outter";
152  for (int j = 0; j < 3; j += 2) {
153  auto b = innerRange[j];
154  auto e = innerRange[j + 1];
155  if (e == b)
156  continue;
157  bool ok[e - b];
158  switch (checkRZ->algo()) {
160  std::get<0>(kernels).set(checkRZ);
161  std::get<0>(kernels)(b, e, innerHitsMap, ok);
162  break;
164  std::get<1>(kernels).set(checkRZ);
165  std::get<1>(kernels)(b, e, innerHitsMap, ok);
166  break;
168  std::get<2>(kernels).set(checkRZ);
169  std::get<2>(kernels)(b, e, innerHitsMap, ok);
170  break;
171  }
172  for (int i = 0; i != e - b; ++i) {
173  if (!ok[i])
174  continue;
175  if (theMaxElement != 0 && result.size() >= theMaxElement) {
176  result.clear();
177  edm::LogError("TooManyPairs") << "number of pairs exceed maximum, no pairs produced";
178  delete checkRZ;
179  return;
180  }
181  result.add(b + i, io);
182  }
183  }
184  delete checkRZ;
185  }
186  LogDebug("HitPairGeneratorFromLayerPair") << " total number of pairs provided back: " << result.size();
187  result.shrink_to_fit();
188 }
#define LogDebug(id)
std::vector< HitWithPhi > theHits
std::size_t size() const
std::vector< float > drphi
T max() const
void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
std::vector< float > z
def Base(process)
bool empty() const
T min() const
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:224
unsigned int size() const override
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
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:118
PixelRecoRange< float > Range
const DetLayer * detLayer() const
std::vector< float > dv
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
double a
Definition: hdecay.h:119
Square< F >::type sqr(const F &f)
Definition: Square.h:14
float rv(int i) const
std::vector< float > u
bool prefilter(float xHit, float yHit) const
Definition: InnerDeltaPhi.h:30
std::vector< float > du
void add(int il, int ol)
long double T
Definition: fakeMenu.h:6
#define constexpr