CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CAHitTripletGenerator.cc
Go to the documentation of this file.
1 #include <unordered_map>
2 
4 
6 
12 
14 
15 #include "CellularAutomaton.h"
16 
18 
20 
21 namespace
22 {
23 
24 template<typename T>
25 T sqr(T x)
26 {
27  return x * x;
28 }
29 }
30 
31 using namespace std;
32 using namespace ctfseeding;
33 
35 
38  bool needSeedingLayerSetsHits) :
39  extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")), //extra window in ThirdHitPredictionFromCircle range (divide by R to get phi)
40  maxChi2(cfg.getParameter < edm::ParameterSet > ("maxChi2")),
41  useBendingCorrection(cfg.getParameter<bool>("useBendingCorrection")),
42  caThetaCut( cfg.getParameter<double>("CAThetaCut")),
43  caPhiCut(cfg.getParameter<double>("CAPhiCut")),
44  caHardPtCut(cfg.getParameter<double>("CAHardPtCut"))
45 {
46 
47  if(needSeedingLayerSetsHits)
49 
50  if (cfg.exists("SeedComparitorPSet"))
51  {
52  edm::ParameterSet comparitorPSet = cfg.getParameter < edm::ParameterSet
53  > ("SeedComparitorPSet");
54  std::string comparitorName = comparitorPSet.getParameter < std::string
55  > ("ComponentName");
56  if (comparitorName != "none")
57  {
58  theComparitor.reset(
59  SeedComparitorFactory::get()->create(comparitorName,
60  comparitorPSet, iC));
61  }
62  }
63 }
64 
66 {
67 }
68 
70  desc.add<double>("extraHitRPhitolerance", 0.06);
71  desc.add<bool>("useBendingCorrection", false);
72  desc.add<double>("CAThetaCut", 0.00125);
73  desc.add<double>("CAPhiCut", 0.1);
74  desc.add<double>("CAHardPtCut", 0);
75 
76  edm::ParameterSetDescription descMaxChi2;
77  descMaxChi2.add<double>("pt1", 0.8);
78  descMaxChi2.add<double>("pt2", 2);
79  descMaxChi2.add<double>("value1", 50);
80  descMaxChi2.add<double>("value2", 8);
81  descMaxChi2.add<bool>("enabled", true);
82  desc.add<edm::ParameterSetDescription>("maxChi2", descMaxChi2);
83 
84  edm::ParameterSetDescription descComparitor;
85  descComparitor.add<std::string>("ComponentName", "none");
86  descComparitor.setAllowAnything(); // until we have moved SeedComparitor too to EDProducers
87  desc.add<edm::ParameterSetDescription>("SeedComparitorPSet", descComparitor);
88 }
89 
91  if (theComparitor) theComparitor->init(ev, es);
92 }
93 
94 namespace {
95  template <typename T_HitDoublets, typename T_GeneratorOrPairsFunction>
96  void fillGraph(const SeedingLayerSetsHits& layers, CAGraph& g, T_HitDoublets& hitDoublets,
97  T_GeneratorOrPairsFunction generatorOrPairsFunction) {
98 
99  for (unsigned int i = 0; i < layers.size(); i++)
100  {
101  for (unsigned int j = 0; j < 3; ++j)
102  {
103  auto vertexIndex = 0;
104  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(),
105  layers[i][j].name());
106  if (foundVertex == g.theLayers.end())
107  {
108  g.theLayers.emplace_back(layers[i][j].name(),
109  layers[i][j].hits().size());
110  vertexIndex = g.theLayers.size() - 1;
111  }
112  else
113  {
114  vertexIndex = foundVertex - g.theLayers.begin();
115  }
116  if (j == 0)
117  {
118 
119  if (std::find(g.theRootLayers.begin(), g.theRootLayers.end(),
120  vertexIndex) == g.theRootLayers.end())
121  {
122  g.theRootLayers.emplace_back(vertexIndex);
123 
124  }
125 
126  }
127  else
128  {
129 
130  auto innerVertex = std::find(g.theLayers.begin(),
131  g.theLayers.end(), layers[i][j - 1].name());
132 
133  CALayerPair tmpInnerLayerPair(innerVertex - g.theLayers.begin(),
134  vertexIndex);
135 
136  if (std::find(g.theLayerPairs.begin(), g.theLayerPairs.end(),
137  tmpInnerLayerPair) == g.theLayerPairs.end())
138  {
139  const bool nonEmpty = generatorOrPairsFunction(layers[i][j - 1], layers[i][j], hitDoublets);
140  if(nonEmpty) {
141  g.theLayerPairs.push_back(tmpInnerLayerPair);
142  g.theLayers[vertexIndex].theInnerLayers.push_back(
143  innerVertex - g.theLayers.begin());
144  innerVertex->theOuterLayers.push_back(vertexIndex);
145  g.theLayers[vertexIndex].theInnerLayerPairs.push_back(
146  g.theLayerPairs.size() - 1);
147  innerVertex->theOuterLayerPairs.push_back(
148  g.theLayerPairs.size() - 1);
149  }
150  }
151 
152  }
153 
154  }
155  }
156  }
157 }
158 
161  const edm::EventSetup& es)
162 {
164  ev.getByToken(theSeedingLayerToken, hlayers);
165  const SeedingLayerSetsHits& layers = *hlayers;
166  if (layers.numberOfLayersInSet() != 3)
167  throw cms::Exception("Configuration")
168  << "CAHitTripletGenerator expects SeedingLayerSetsHits::numberOfLayersInSet() to be 3, got "
169  << layers.numberOfLayersInSet();
170 
171  CAGraph g;
172 
173  std::vector<HitDoublets> hitDoublets;
174 
175 
176 
177  HitPairGeneratorFromLayerPair thePairGenerator(0, 1, &theLayerCache);
178  fillGraph(layers, g, hitDoublets, [&](const SeedingLayerSetsHits::SeedingLayer& inner, const SeedingLayerSetsHits::SeedingLayer& outer, std::vector<HitDoublets>& hitDoublets) {
179  hitDoublets.emplace_back(thePairGenerator.doublets(region, ev, es, inner, outer));
180  return true;
181  });
182 
183 
184  if (theComparitor)
185  theComparitor->init(ev, es);
186 
187  std::vector<const HitDoublets *> hitDoubletsPtr;
188  hitDoubletsPtr.reserve(hitDoublets.size());
189  for(const auto& e: hitDoublets)
190  hitDoubletsPtr.emplace_back(&e);
191 
192  hitTriplets(region, result, hitDoubletsPtr, g, es);
194 }
195 
198  const edm::EventSetup& es,
199  const SeedingLayerSetsHits& layers) {
200  CAGraph g;
201 
202  std::vector<const HitDoublets *> hitDoublets;
203 
204  auto layerPairEqual = [](const IntermediateHitDoublets::LayerPairHitDoublets& pair,
207  return pair.innerLayerIndex() == inner && pair.outerLayerIndex() == outer;
208  };
209  fillGraph(layers, g, hitDoublets, [&](const SeedingLayerSetsHits::SeedingLayer& inner, const SeedingLayerSetsHits::SeedingLayer& outer, std::vector<const HitDoublets *>& hitDoublets) {
210  using namespace std::placeholders;
211  auto found = std::find_if(regionLayerPairs.begin(), regionLayerPairs.end(), std::bind(layerPairEqual, _1, inner.index(), outer.index()));
212  if(found != regionLayerPairs.end()) {
213  hitDoublets.emplace_back(&(found->doublets()));
214  return true;
215  }
216  return false;
217  });
218 
219  hitTriplets(regionLayerPairs.region(), result, hitDoublets, g, es);
220 }
221 
222 
225  std::vector<const HitDoublets *>& hitDoublets, const CAGraph& g,
226  const edm::EventSetup& es) {
227  std::vector<CACell::CAntuplet> foundTriplets;
228  CellularAutomaton ca(g);
229 
230  ca.findTriplets(hitDoublets, foundTriplets, region, caThetaCut, caPhiCut,
231  caHardPtCut);
232 
233  unsigned int numberOfFoundTriplets = foundTriplets.size();
234 
235  const QuantityDependsPtEval maxChi2Eval = maxChi2.evaluator(es);
236 
237  // re-used thoughout, need to be vectors because of RZLine interface
238  std::array<float, 3> bc_r;
239  std::array<float, 3> bc_z;
240  std::array<float, 3> bc_errZ2;
241  std::array < GlobalPoint, 3 > gps;
242  std::array < GlobalError, 3 > ges;
243  std::array<bool, 3> barrels;
244 
245  for (unsigned int tripletId = 0; tripletId < numberOfFoundTriplets;
246  ++tripletId)
247  {
248 
249  OrderedHitTriplet tmpTriplet(foundTriplets[tripletId][0]->getInnerHit(),
250  foundTriplets[tripletId][0]->getOuterHit(),
251  foundTriplets[tripletId][1]->getOuterHit());
252 
253  auto isBarrel = [](const unsigned id) -> bool
254  {
255  return id == PixelSubdetector::PixelBarrel;
256  };
257  for (unsigned int i = 0; i < 2; ++i)
258  {
259  auto const& ahit = foundTriplets[tripletId][i]->getInnerHit();
260  gps[i] = ahit->globalPosition();
261  ges[i] = ahit->globalPositionError();
262  barrels[i] = isBarrel(ahit->geographicalId().subdetId());
263  }
264 
265  auto const& ahit = foundTriplets[tripletId][1]->getOuterHit();
266  gps[2] = ahit->globalPosition();
267  ges[2] = ahit->globalPositionError();
268  barrels[2] = isBarrel(ahit->geographicalId().subdetId());
269 
270  PixelRecoLineRZ line(gps[0], gps[2]);
271  ThirdHitPredictionFromCircle predictionRPhi(gps[0], gps[2],
273  const float curvature = predictionRPhi.curvature(
274  ThirdHitPredictionFromCircle::Vector2D(gps[1].x(), gps[1].y()));
275  const float abscurv = std::abs(curvature);
276  const float thisMaxChi2 = maxChi2Eval.value(abscurv);
277  float chi2 = std::numeric_limits<float>::quiet_NaN();
278  // TODO: Do we have any use case to not use bending correction?
280  {
281  // Following PixelFitterByConformalMappingAndLine
282  const float simpleCot = (gps.back().z() - gps.front().z())
283  / (gps.back().perp() - gps.front().perp());
284  const float pt = 1.f / PixelRecoUtilities::inversePt(abscurv, es);
285  for (int i = 0; i < 3; ++i)
286  {
287  const GlobalPoint & point = gps[i];
288  const GlobalError & error = ges[i];
289  bc_r[i] = sqrt(
290  sqr(point.x() - region.origin().x())
291  + sqr(point.y() - region.origin().y()));
293  es)(bc_r[i]);
294  bc_z[i] = point.z() - region.origin().z();
295  bc_errZ2[i] =
296  (barrels[i]) ?
297  error.czz() :
298  error.rerr(point) * sqr(simpleCot);
299  }
300  RZLine rzLine(bc_r, bc_z, bc_errZ2, RZLine::ErrZ2_tag());
301  chi2 = rzLine.chi2();
302  }
303  else
304  {
305  RZLine rzLine(gps, ges, barrels);
306  chi2 = rzLine.chi2();
307  }
308 
309  if (edm::isNotFinite(chi2) || chi2 > thisMaxChi2)
310  {
311  continue;
312 
313  }
314 
315  if (theComparitor)
316  {
317  if (!theComparitor->compatible(tmpTriplet))
318  {
319 
320  continue;
321  }
322  }
323 
324  result.push_back(tmpTriplet);
325 
326  }
328 }
329 
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
const QuantityDependsPt maxChi2
tuple cfg
Definition: looper.py:293
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const_iterator begin() const
GlobalPoint const & origin() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
bool isBarrel(GeomDetEnumerators::SubDetector m)
const_iterator end() const
T y() const
Definition: PV3DBase.h:63
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool ev
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
CAHitTripletGenerator(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC, bool needSeedingLayerSetsHits=true)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
#define constexpr
tuple result
Definition: mps_fire.py:84
Range curvature(double transverseIP) const
edm::EDGetTokenT< SeedingLayerSetsHits > theSeedingLayerToken
T inversePt(T curvature, const edm::EventSetup &iSetup)
T x() const
Cartesian x coordinate.
QuantityDependsPtEval evaluator(const edm::EventSetup &es) const
bool isNotFinite(T x)
Definition: isFinite.h:10
T curvature(T InversePt, const edm::EventSetup &iSetup)
SeedingLayerSetsHits::LayerIndex innerLayerIndex() const
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< CALayer > theLayers
Definition: CAGraph.h:67
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
void initEvent(const edm::Event &ev, const edm::EventSetup &es)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:68
HitDoublets doublets(const TrackingRegion &reg, const edm::Event &ev, const edm::EventSetup &es, Layers layers)
Definition: RZLine.h:12
const TrackingRegion & region() const
virtual void hitTriplets(const TrackingRegion &reg, OrderedHitTriplets &triplets, const edm::Event &ev, const edm::EventSetup &es)
from base class
T rerr(const GlobalPoint &aPoint) const
SeedingLayerSetsHits::LayerIndex outerLayerIndex() const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
std::vector< int > theRootLayers
Definition: CAGraph.h:69
static void fillDescriptions(edm::ParameterSetDescription &desc)
void hitNtuplets(const IntermediateHitDoublets::RegionLayerSets &regionLayerPairs, OrderedHitTriplets &result, const edm::EventSetup &es, const SeedingLayerSetsHits &layers)
void findTriplets(const std::vector< const HitDoublets * > &hitDoublets, std::vector< CACell::CAntuplet > &foundTriplets, const TrackingRegion &region, const float thetaCut, const float phiCut, const float hardPtCut)
long double T
T x() const
Definition: PV3DBase.h:62
std::unique_ptr< SeedComparitor > theComparitor
float chi2() const
Definition: RZLine.h:97
unsigned short size() const
Get the number of SeedingLayerSets.
static unsigned int minLayers
tuple size
Write out results.
T get(const Candidate &c)
Definition: component.h:55
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5