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 
34 
36  edm::ConsumesCollector iC, unsigned int inner, unsigned int outer, LayerCacheType* layerCache, unsigned int max)
37  : theLayerCache(layerCache),
38  theFieldToken(iC.esConsumes()),
39  theMSMakerToken(iC.esConsumes()),
40  theOuterLayer(outer),
41  theInnerLayer(inner),
42  theMaxElement(max) {}
43 
45 
46 // devirtualizer
47 #include <tuple>
48 namespace {
49 
50  template <typename Algo>
51  struct Kernel {
52  using Base = HitRZCompatibility;
53  void set(Base const* a) {
54  assert(a->algo() == Algo::me);
55  checkRZ = reinterpret_cast<Algo const*>(a);
56  }
57 
58  void operator()(int b, int e, const RecHitsSortedInPhi& innerHitsMap, bool* ok) const {
59  constexpr float nSigmaRZ = 3.46410161514f; // std::sqrt(12.f);
60  for (int i = b; i != e; ++i) {
61  Range allowed = checkRZ->range(innerHitsMap.u[i]);
62  float vErr = nSigmaRZ * innerHitsMap.dv[i];
63  Range hitRZ(innerHitsMap.v[i] - vErr, innerHitsMap.v[i] + vErr);
64  Range crossRange = allowed.intersection(hitRZ);
65  ok[i - b] = !crossRange.empty();
66  }
67  }
68  Algo const* checkRZ;
69  };
70 
71  template <typename... Args>
72  using Kernels = std::tuple<Kernel<Args>...>;
73 
74 } // namespace
75 
78  const edm::Event& iEvent,
79  const edm::EventSetup& iSetup,
80  Layers layers) {
81  auto const& ds = doublets(region, iEvent, iSetup, layers);
82  if (not ds) {
83  return false;
84  }
85  for (std::size_t i = 0; i != ds->size(); ++i) {
86  result.push_back(OrderedHitPair(ds->hit(i, HitDoublets::inner), ds->hit(i, HitDoublets::outer)));
87  }
88  if (theMaxElement != 0 && result.size() >= theMaxElement) {
89  result.clear();
90  edm::LogError("TooManyPairs") << "number of pairs exceed maximum, no pairs produced";
91  return false;
92  }
93  return true;
94 }
95 
97  const edm::Event& iEvent,
98  const edm::EventSetup& iSetup,
99  const Layer& innerLayer,
100  const Layer& outerLayer,
101  LayerCacheType& layerCache) {
102  const RecHitsSortedInPhi& innerHitsMap = layerCache(innerLayer, region);
103  if (innerHitsMap.empty())
104  return HitDoublets(innerHitsMap, innerHitsMap);
105 
106  const RecHitsSortedInPhi& outerHitsMap = layerCache(outerLayer, region);
107  if (outerHitsMap.empty())
108  return HitDoublets(innerHitsMap, outerHitsMap);
109  const auto& field = iSetup.getData(theFieldToken);
110  const auto& msmaker = iSetup.getData(theMSMakerToken);
111  HitDoublets result(innerHitsMap, outerHitsMap);
112  result.reserve(std::max(innerHitsMap.size(), outerHitsMap.size()));
113  bool succeeded = doublets(region,
114  *innerLayer.detLayer(),
115  *outerLayer.detLayer(),
116  innerHitsMap,
117  outerHitsMap,
118  field,
119  msmaker,
121  result);
122  if (succeeded) {
123  return result;
124  } else {
125  return std::nullopt;
126  }
127 }
128 
130  const DetLayer& innerHitDetLayer,
131  const DetLayer& outerHitDetLayer,
132  const RecHitsSortedInPhi& innerHitsMap,
133  const RecHitsSortedInPhi& outerHitsMap,
134  const MagneticField& field,
136  const unsigned int theMaxElement,
137  HitDoublets& result) {
138  // HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
140  InnerDeltaPhi deltaPhi(outerHitDetLayer, innerHitDetLayer, region, field, msmaker);
141 
142  // std::cout << "layers " << theInnerLayer.detLayer()->seqNum() << " " << outerLayer.detLayer()->seqNum() << std::endl;
143 
144  // constexpr float nSigmaRZ = std::sqrt(12.f);
145  constexpr float nSigmaPhi = 3.f;
146  for (int io = 0; io != int(outerHitsMap.theHits.size()); ++io) {
147  if (!deltaPhi.prefilter(outerHitsMap.x[io], outerHitsMap.y[io]))
148  continue;
149  Hit const& ohit = outerHitsMap.theHits[io].hit();
150  PixelRecoRange<float> phiRange =
151  deltaPhi(outerHitsMap.x[io], outerHitsMap.y[io], outerHitsMap.z[io], nSigmaPhi * outerHitsMap.drphi[io]);
152 
153  if (phiRange.empty())
154  continue;
155 
156  std::unique_ptr<const HitRZCompatibility> checkRZ =
157  region.checkRZ(&innerHitDetLayer,
158  ohit,
159  &outerHitDetLayer,
160  outerHitsMap.rv(io),
161  outerHitsMap.z[io],
162  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
163  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]);
164  if (!checkRZ)
165  continue;
166 
167  Kernels<HitZCheck, HitRCheck, HitEtaCheck> kernels;
168 
169  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
170  LogDebug("HitPairGeneratorFromLayerPair")
171  << "preparing for combination of: " << innerRange[1] - innerRange[0] + innerRange[3] - innerRange[2]
172  << " inner and: " << outerHitsMap.theHits.size() << " outter";
173  for (int j = 0; j < 3; j += 2) {
174  auto b = innerRange[j];
175  auto e = innerRange[j + 1];
176  if (e == b)
177  continue;
178  bool ok[e - b];
179  switch (checkRZ->algo()) {
181  std::get<0>(kernels).set(checkRZ.get());
182  std::get<0>(kernels)(b, e, innerHitsMap, ok);
183  break;
185  std::get<1>(kernels).set(checkRZ.get());
186  std::get<1>(kernels)(b, e, innerHitsMap, ok);
187  break;
189  std::get<2>(kernels).set(checkRZ.get());
190  std::get<2>(kernels)(b, e, innerHitsMap, ok);
191  break;
192  }
193  for (int i = 0; i != e - b; ++i) {
194  if (!ok[i])
195  continue;
196  if (theMaxElement != 0 && result.size() >= theMaxElement) {
197  result.clear();
198  edm::LogError("TooManyPairs") << "number of pairs exceed maximum, no pairs produced";
199  return false;
200  }
201  result.add(b + i, io);
202  }
203  }
204  }
205  LogDebug("HitPairGeneratorFromLayerPair") << " total number of pairs provided back: " << result.size();
206  result.shrink_to_fit();
207  return true;
208 }
std::vector< HitWithPhi > theHits
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< float > drphi
float rv(int i) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
HitPairGeneratorFromLayerPair(edm::ConsumesCollector iC, unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int max=0)
std::vector< float > z
def Base(process)
Log< level::Error, false > LogError
Layer outerLayer(const Layers &layers) const
assert(be >=bs)
std::vector< float > x
int iEvent
Definition: GenABIO.cc:224
DoubleRange doubleRange(float phiMin, float phiMax) const
bool empty() const
constexpr double nSigmaRZ
std::vector< float > y
std::vector< float > v
constexpr float nSigmaPhi
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > theFieldToken
const edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > theMSMakerToken
bool hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
double b
Definition: hdecay.h:120
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
PixelRecoRange< float > Range
std::size_t size() const
std::vector< float > dv
double a
Definition: hdecay.h:121
Square< F >::type sqr(const F &f)
Definition: Square.h:14
Layer innerLayer(const Layers &layers) const
std::vector< float > u
std::optional< HitDoublets > doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
std::vector< float > du
long double T
Definition: fakeMenu.h:6
#define LogDebug(id)