test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CAHitQuadrupletGenerator.cc
Go to the documentation of this file.
2 
4 
6 #include "LayerQuadruplets.h"
11 
12 
14 
15 
16 
17 #include "CellularAutomaton.h"
18 
20 
22 
23 #include <functional>
24 
25 namespace
26 {
27 
28  template <typename T>
29  T sqr(T x)
30  {
31  return x*x;
32  }
33 }
34 
35 
36 
37 using namespace std;
38 using namespace ctfseeding;
39 
41 
43 extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")), //extra window in ThirdHitPredictionFromCircle range (divide by R to get phi)
44 maxChi2(cfg.getParameter<edm::ParameterSet>("maxChi2")),
45 fitFastCircle(cfg.getParameter<bool>("fitFastCircle")),
46 fitFastCircleChi2Cut(cfg.getParameter<bool>("fitFastCircleChi2Cut")),
47 useBendingCorrection(cfg.getParameter<bool>("useBendingCorrection")),
48 caThetaCut(cfg.getParameter<double>("CAThetaCut")),
49 caPhiCut(cfg.getParameter<double>("CAPhiCut")),
50 caHardPtCut(cfg.getParameter<double>("CAHardPtCut"))
51 {
52  if(needSeedingLayerSetsHits)
54 
55  if (cfg.exists("SeedComparitorPSet"))
56  {
57  edm::ParameterSet comparitorPSet =
58  cfg.getParameter<edm::ParameterSet>("SeedComparitorPSet");
59  std::string comparitorName = comparitorPSet.getParameter<std::string>("ComponentName");
60  if (comparitorName != "none")
61  {
62  theComparitor.reset(SeedComparitorFactory::get()->create(comparitorName, comparitorPSet, iC));
63  }
64  }
65 }
66 
68 {
69 }
70 
72  desc.add<double>("extraHitRPhitolerance", 0.1);
73  desc.add<bool>("fitFastCircle", false);
74  desc.add<bool>("fitFastCircleChi2Cut", false);
75  desc.add<bool>("useBendingCorrection", false);
76  desc.add<double>("CAThetaCut", 0.00125);
77  desc.add<double>("CAPhiCut", 10);
78  desc.add<double>("CAHardPtCut", 0);
79 
80  edm::ParameterSetDescription descMaxChi2;
81  descMaxChi2.add<double>("pt1", 0.2);
82  descMaxChi2.add<double>("pt2", 1.5);
83  descMaxChi2.add<double>("value1", 500);
84  descMaxChi2.add<double>("value2", 50);
85  descMaxChi2.add<bool>("enabled", true);
86  desc.add<edm::ParameterSetDescription>("maxChi2", descMaxChi2);
87 
88  edm::ParameterSetDescription descComparitor;
89  descComparitor.add<std::string>("ComponentName", "none");
90  descComparitor.setAllowAnything(); // until we have moved SeedComparitor too to EDProducers
91  desc.add<edm::ParameterSetDescription>("SeedComparitorPSet", descComparitor);
92 }
93 
95  if (theComparitor) theComparitor->init(ev, es);
96 }
97 
98 namespace {
99  template <typename T_HitDoublets, typename T_GeneratorOrPairsFunction>
100  void fillGraph(const SeedingLayerSetsHits& layers, CAGraph& g, T_HitDoublets& hitDoublets,
101  T_GeneratorOrPairsFunction generatorOrPairsFunction) {
102  for (unsigned int i = 0; i < layers.size(); i++)
103  {
104  for (unsigned int j = 0; j < 4; ++j)
105  {
106  auto vertexIndex = 0;
107  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(),
108  layers[i][j].name());
109  if (foundVertex == g.theLayers.end())
110  {
111  g.theLayers.emplace_back(layers[i][j].name(), layers[i][j].hits().size());
112  vertexIndex = g.theLayers.size() - 1;
113  }
114  else
115  {
116  vertexIndex = foundVertex - g.theLayers.begin();
117  }
118  if (j == 0)
119  {
120 
121  if (std::find(g.theRootLayers.begin(), g.theRootLayers.end(),
122  vertexIndex) == g.theRootLayers.end())
123  {
124  g.theRootLayers.emplace_back(vertexIndex);
125 
126  }
127 
128  }
129  else
130  {
131 
132  auto innerVertex = std::find(g.theLayers.begin(),
133  g.theLayers.end(), layers[i][j - 1].name());
134 
135  CALayerPair tmpInnerLayerPair(innerVertex - g.theLayers.begin(),
136  vertexIndex);
137 
138  if (std::find(g.theLayerPairs.begin(), g.theLayerPairs.end(),
139  tmpInnerLayerPair) == g.theLayerPairs.end())
140  {
141  const bool nonEmpty = generatorOrPairsFunction(layers[i][j-1], layers[i][j], hitDoublets);
142  if(nonEmpty) {
143  g.theLayerPairs.push_back(tmpInnerLayerPair);
144  g.theLayers[vertexIndex].theInnerLayers.push_back(
145  innerVertex - g.theLayers.begin());
146  innerVertex->theOuterLayers.push_back(vertexIndex);
147  g.theLayers[vertexIndex].theInnerLayerPairs.push_back(
148  g.theLayerPairs.size() - 1);
149  innerVertex->theOuterLayerPairs.push_back(
150  g.theLayerPairs.size() - 1);
151  }
152  }
153 
154  }
155 
156  }
157  }
158  }
159 }
160 
161 
164  const edm::EventSetup& es)
165 {
167  ev.getByToken(theSeedingLayerToken, hlayers);
168  const SeedingLayerSetsHits& layers = *hlayers;
169  if (layers.numberOfLayersInSet() != 4)
170  throw cms::Exception("Configuration")
171  << "CAHitQuadrupletsGenerator expects SeedingLayerSetsHits::numberOfLayersInSet() to be 4, got "
172  << layers.numberOfLayersInSet();
173 
174  CAGraph g;
175 
176 
177  std::vector<HitDoublets> hitDoublets;
178 
179 
180  HitPairGeneratorFromLayerPair thePairGenerator(0, 1, &theLayerCache);
181  fillGraph(layers, g, hitDoublets,
184  std::vector<HitDoublets>& hitDoublets) {
185  hitDoublets.emplace_back(thePairGenerator.doublets(region, ev, es, inner, outer));
186  return true;
187  });
188 
189  if (theComparitor)
190  theComparitor->init(ev, es);
191 
192  std::vector<const HitDoublets *> hitDoubletsPtr;
193  hitDoubletsPtr.reserve(hitDoublets.size());
194  for(const auto& e: hitDoublets)
195  hitDoubletsPtr.emplace_back(&e);
196 
197  hitQuadruplets(region, result, hitDoubletsPtr, g, es);
199 }
200 
203  const edm::EventSetup& es,
204  const SeedingLayerSetsHits& layers) {
205  CAGraph g;
206 
207  std::vector<const HitDoublets *> hitDoublets;
208 
209  auto layerPairEqual = [](const IntermediateHitDoublets::LayerPairHitDoublets& pair,
212  return pair.innerLayerIndex() == inner && pair.outerLayerIndex() == outer;
213  };
214  fillGraph(layers, g, hitDoublets,
215  [&](const SeedingLayerSetsHits::SeedingLayer& inner,
217  std::vector<const HitDoublets *>& hitDoublets) {
218  using namespace std::placeholders;
219  auto found = std::find_if(regionLayerPairs.begin(), regionLayerPairs.end(),
220  std::bind(layerPairEqual, _1, inner.index(), outer.index()));
221  if(found != regionLayerPairs.end()) {
222  hitDoublets.emplace_back(&(found->doublets()));
223  return true;
224  }
225  return false;
226  });
227 
228  hitQuadruplets(regionLayerPairs.region(), result, hitDoublets, g, es);
229 }
230 
233  std::vector<const HitDoublets *>& hitDoublets, const CAGraph& g,
234  const edm::EventSetup& es) {
235  const int numberOfHitsInNtuplet = 4;
236  std::vector<CACell::CAntuplet> foundQuadruplets;
237 
238  CellularAutomaton ca(g);
239 
240  ca.createAndConnectCells(hitDoublets, region, caThetaCut,
242 
243  ca.evolve(numberOfHitsInNtuplet);
244 
245  ca.findNtuplets(foundQuadruplets, numberOfHitsInNtuplet);
246 
247 
248  const QuantityDependsPtEval maxChi2Eval = maxChi2.evaluator(es);
249 
250  // re-used thoughout, need to be vectors because of RZLine interface
251  std::array<float, 4> bc_r;
252  std::array<float, 4> bc_z;
253  std::array<float, 4> bc_errZ2;
254  std::array<GlobalPoint, 4> gps;
255  std::array<GlobalError, 4> ges;
256  std::array<bool, 4> barrels;
257 
258  unsigned int numberOfFoundQuadruplets = foundQuadruplets.size();
259 
260  // Loop over quadruplets
261  for (unsigned int quadId = 0; quadId < numberOfFoundQuadruplets; ++quadId)
262  {
263 
264  auto isBarrel = [](const unsigned id) -> bool
265  {
266  return id == PixelSubdetector::PixelBarrel;
267  };
268  for(unsigned int i = 0; i< 3; ++i)
269  {
270  auto const& ahit = foundQuadruplets[quadId][i]->getInnerHit();
271  gps[i] = ahit->globalPosition();
272  ges[i] = ahit->globalPositionError();
273  barrels[i] = isBarrel(ahit->geographicalId().subdetId());
274  }
275 
276  auto const& ahit = foundQuadruplets[quadId][2]->getOuterHit();
277  gps[3] = ahit->globalPosition();
278  ges[3] = ahit->globalPositionError();
279  barrels[3] = isBarrel(ahit->geographicalId().subdetId());
280 
281  // TODO:
282  // - 'line' is not used for anything
283  // - if we decide to always do the circle fit for 4 hits, we don't
284  // need ThirdHitPredictionFromCircle for the curvature; then we
285  // could remove extraHitRPhitolerance configuration parameter
286  PixelRecoLineRZ line(gps[0], gps[2]);
287  ThirdHitPredictionFromCircle predictionRPhi(gps[0], gps[2], extraHitRPhitolerance);
288  const float curvature = predictionRPhi.curvature(ThirdHitPredictionFromCircle::Vector2D(gps[1].x(), gps[1].y()));
289  const float abscurv = std::abs(curvature);
290  const float thisMaxChi2 = maxChi2Eval.value(abscurv);
291 
292  if (theComparitor)
293  {
294  SeedingHitSet tmpTriplet(foundQuadruplets[quadId][0]->getInnerHit(), foundQuadruplets[quadId][2]->getInnerHit(), foundQuadruplets[quadId][2]->getOuterHit());
295 
296 
297  if (!theComparitor->compatible(tmpTriplet) )
298  {
299  continue;
300  }
301  }
302 
303  float chi2 = std::numeric_limits<float>::quiet_NaN();
304  // TODO: Do we have any use case to not use bending correction?
306  {
307  // Following PixelFitterByConformalMappingAndLine
308  const float simpleCot = ( gps.back().z() - gps.front().z() ) / (gps.back().perp() - gps.front().perp() );
309  const float pt = 1.f / PixelRecoUtilities::inversePt(abscurv, es);
310  for (int i=0; i < 4; ++i)
311  {
312  const GlobalPoint & point = gps[i];
313  const GlobalError & error = ges[i];
314  bc_r[i] = sqrt( sqr(point.x() - region.origin().x()) + sqr(point.y() - region.origin().y()) );
315  bc_r[i] += pixelrecoutilities::LongitudinalBendingCorrection(pt, es)(bc_r[i]);
316  bc_z[i] = point.z() - region.origin().z();
317  bc_errZ2[i] = (barrels[i]) ? error.czz() : error.rerr(point)*sqr(simpleCot);
318  }
319  RZLine rzLine(bc_r, bc_z, bc_errZ2, RZLine::ErrZ2_tag());
320  chi2 = rzLine.chi2();
321  } else
322  {
323  RZLine rzLine(gps, ges, barrels);
324  chi2 = rzLine.chi2();
325  }
326  if (edm::isNotFinite(chi2) || chi2 > thisMaxChi2)
327  {
328  continue;
329 
330  }
331  // TODO: Do we have any use case to not use circle fit? Maybe
332  // HLT where low-pT inefficiency is not a problem?
333  if (fitFastCircle)
334  {
335  FastCircleFit c(gps, ges);
336  chi2 += c.chi2();
337  if (edm::isNotFinite(chi2))
338  continue;
339  if (fitFastCircleChi2Cut && chi2 > thisMaxChi2)
340  continue;
341  }
342 
343  result.emplace_back(foundQuadruplets[quadId][0]->getInnerHit(), foundQuadruplets[quadId][1]->getInnerHit(), foundQuadruplets[quadId][2]->getInnerHit(), foundQuadruplets[quadId][2]->getOuterHit());
344  }
345 }
346 
347 
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.
void findNtuplets(std::vector< CACell::CAntuplet > &, const unsigned int)
tuple cfg
Definition: looper.py:293
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
void hitNtuplets(const IntermediateHitDoublets::RegionLayerSets &regionLayerPairs, OrderedHitSeeds &result, const edm::EventSetup &es, const SeedingLayerSetsHits &layers)
const_iterator begin() const
void createAndConnectCells(const std::vector< const HitDoublets * > &, const TrackingRegion &, const float, const float, const float)
GlobalPoint const & origin() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
bool isBarrel(GeomDetEnumerators::SubDetector m)
CAHitQuadrupletGenerator(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC, bool needSeedingLayerSetsHits=true)
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
std::unique_ptr< SeedComparitor > theComparitor
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
virtual void hitQuadruplets(const TrackingRegion &reg, OrderedHitSeeds &quadruplets, const edm::Event &ev, const edm::EventSetup &es)
from base class
T inversePt(T curvature, const edm::EventSetup &iSetup)
T x() const
Cartesian x coordinate.
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
void initEvent(const edm::Event &ev, const edm::EventSetup &es)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
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
const QuantityDependsPt maxChi2
float chi2() const
Definition: FastCircleFit.h:66
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)
QuantityDependsPtEval evaluator(const edm::EventSetup &es) const
long double T
T x() const
Definition: PV3DBase.h:62
float chi2() const
Definition: RZLine.h:97
unsigned short size() const
Get the number of SeedingLayerSets.
tuple size
Write out results.
edm::EDGetTokenT< SeedingLayerSetsHits > theSeedingLayerToken
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
void evolve(const unsigned int)