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> 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 
76  const TrackingRegion & region, OrderedHitPairs & result,
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, const Layer& innerLayer, const Layer& outerLayer,
91  LayerCacheType& layerCache) {
92 
93  const RecHitsSortedInPhi & innerHitsMap = layerCache(innerLayer, region, iSetup);
94  if (innerHitsMap.empty()) return HitDoublets(innerHitsMap,innerHitsMap);
95 
96  const RecHitsSortedInPhi& outerHitsMap = layerCache(outerLayer, region, iSetup);
97  if (outerHitsMap.empty()) return HitDoublets(innerHitsMap,outerHitsMap);
98  HitDoublets result(innerHitsMap,outerHitsMap); result.reserve(std::max(innerHitsMap.size(),outerHitsMap.size()));
99  doublets(region,
100  *innerLayer.detLayer(),*outerLayer.detLayer(),
101  innerHitsMap,outerHitsMap,iSetup,theMaxElement,result);
102 
103  return result;
104 
105 }
106 
108  const DetLayer & innerHitDetLayer,
109  const DetLayer & outerHitDetLayer,
110  const RecHitsSortedInPhi & innerHitsMap,
111  const RecHitsSortedInPhi & outerHitsMap,
112  const edm::EventSetup& iSetup,
113  const unsigned int theMaxElement,
114  HitDoublets & result){
115 
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])) continue;
126  Hit const & ohit = outerHitsMap.theHits[io].hit();
127  PixelRecoRange<float> phiRange = deltaPhi(outerHitsMap.x[io],
128  outerHitsMap.y[io],
129  outerHitsMap.z[io],
130  nSigmaPhi*outerHitsMap.drphi[io]
131  );
132 
133  if (phiRange.empty()) continue;
134 
135  const HitRZCompatibility *checkRZ = region.checkRZ(&innerHitDetLayer, ohit, iSetup, &outerHitDetLayer,
136  outerHitsMap.rv(io),outerHitsMap.z[io],
137  outerHitsMap.isBarrel ? outerHitsMap.du[io] : outerHitsMap.dv[io],
138  outerHitsMap.isBarrel ? outerHitsMap.dv[io] : outerHitsMap.du[io]
139  );
140  if(!checkRZ) continue;
141 
142  Kernels<HitZCheck,HitRCheck,HitEtaCheck> kernels;
143 
144  auto innerRange = innerHitsMap.doubleRange(phiRange.min(), phiRange.max());
145  LogDebug("HitPairGeneratorFromLayerPair")<<
146  "preparing for combination of: "<< innerRange[1]-innerRange[0]+innerRange[3]-innerRange[2]
147  <<" inner and: "<< outerHitsMap.theHits.size()<<" outter";
148  for(int j=0; j<3; j+=2) {
149  auto b = innerRange[j]; auto e=innerRange[j+1];
150  bool ok[e-b];
151  switch (checkRZ->algo()) {
153  std::get<0>(kernels).set(checkRZ);
154  std::get<0>(kernels)(b,e,innerHitsMap, ok);
155  break;
157  std::get<1>(kernels).set(checkRZ);
158  std::get<1>(kernels)(b,e,innerHitsMap, ok);
159  break;
161  std::get<2>(kernels).set(checkRZ);
162  std::get<2>(kernels)(b,e,innerHitsMap, ok);
163  break;
164  }
165  for (int i=0; i!=e-b; ++i) {
166  if (!ok[i]) continue;
167  if (theMaxElement!=0 && result.size() >= theMaxElement){
168  result.clear();
169  edm::LogError("TooManyPairs")<<"number of pairs exceed maximum, no pairs produced";
170  delete checkRZ;
171  return;
172  }
173  result.add(b+i,io);
174  }
175  }
176  delete checkRZ;
177  }
178  LogDebug("HitPairGeneratorFromLayerPair")<<" total number of pairs provided back: "<<result.size();
179  result.shrink_to_fit();
180 
181 }
182 
183 
#define LogDebug(id)
std::vector< HitWithPhi > theHits
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
def Base(process)
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
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
PixelRecoRange< float > Range
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