CMS 3D CMS Logo

CAHitTripletGenerator.cc
Go to the documentation of this file.
1 #include <unordered_map>
2 
13 
14 #include "CAGraph.h"
15 #include "CellularAutomaton.h"
16 
17 namespace {
18  template <typename T>
19  T sqr(T x) {
20  return x * x;
21  }
22 } // namespace
23 
24 using namespace std;
25 
27 
30  : extraHitRPhitolerance(cfg.getParameter<double>(
31  "extraHitRPhitolerance")), //extra window in ThirdHitPredictionFromCircle range (divide by R to get phi)
32  maxChi2(cfg.getParameter<edm::ParameterSet>("maxChi2")),
33  useBendingCorrection(cfg.getParameter<bool>("useBendingCorrection")),
34  caThetaCut(cfg.getParameter<double>("CAThetaCut")),
35  caPhiCut(cfg.getParameter<double>("CAPhiCut")),
36  caHardPtCut(cfg.getParameter<double>("CAHardPtCut")) {
37  edm::ParameterSet comparitorPSet = cfg.getParameter<edm::ParameterSet>("SeedComparitorPSet");
38  std::string comparitorName = comparitorPSet.getParameter<std::string>("ComponentName");
39  if (comparitorName != "none") {
40  theComparitor = SeedComparitorFactory::get()->create(comparitorName, comparitorPSet, iC);
41  }
42 }
43 
45  desc.add<double>("extraHitRPhitolerance", 0.06);
46  desc.add<bool>("useBendingCorrection", false);
47  desc.add<double>("CAThetaCut", 0.00125);
48  desc.add<double>("CAPhiCut", 0.1);
49  desc.add<double>("CAHardPtCut", 0);
50 
51  edm::ParameterSetDescription descMaxChi2;
52  descMaxChi2.add<double>("pt1", 0.8);
53  descMaxChi2.add<double>("pt2", 2);
54  descMaxChi2.add<double>("value1", 50);
55  descMaxChi2.add<double>("value2", 8);
56  descMaxChi2.add<bool>("enabled", true);
57  desc.add<edm::ParameterSetDescription>("maxChi2", descMaxChi2);
58 
59  edm::ParameterSetDescription descComparitor;
60  descComparitor.add<std::string>("ComponentName", "none");
61  descComparitor.setAllowAnything(); // until we have moved SeedComparitor too to EDProducers
62  desc.add<edm::ParameterSetDescription>("SeedComparitorPSet", descComparitor);
63 }
64 
66  if (theComparitor)
67  theComparitor->init(ev, es);
68 }
69 
70 namespace {
71  void createGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
72  for (unsigned int i = 0; i < layers.size(); i++) {
73  for (unsigned int j = 0; j < 3; ++j) {
74  auto vertexIndex = 0;
75  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
76  if (foundVertex == g.theLayers.end()) {
77  g.theLayers.emplace_back(layers[i][j].name(), layers[i][j].hits().size());
78  vertexIndex = g.theLayers.size() - 1;
79  } else {
80  vertexIndex = foundVertex - g.theLayers.begin();
81  }
82  if (j == 0) {
83  if (std::find(g.theRootLayers.begin(), g.theRootLayers.end(), vertexIndex) == g.theRootLayers.end()) {
84  g.theRootLayers.emplace_back(vertexIndex);
85  }
86  }
87  }
88  }
89  }
90 
91  void clearGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
92  g.theLayerPairs.clear();
93  for (unsigned int i = 0; i < g.theLayers.size(); i++) {
94  g.theLayers[i].theInnerLayers.clear();
95  g.theLayers[i].theInnerLayerPairs.clear();
96  g.theLayers[i].theOuterLayers.clear();
97  g.theLayers[i].theOuterLayerPairs.clear();
98  for (auto& v : g.theLayers[i].isOuterHitOfCell)
99  v.clear();
100  }
101  }
102 
103  void fillGraph(const SeedingLayerSetsHits& layers,
104  const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
105  CAGraph& g,
106  std::vector<const HitDoublets*>& hitDoublets) {
107  for (unsigned int i = 0; i < layers.size(); i++) {
108  for (unsigned int j = 0; j < 3; ++j) {
109  auto vertexIndex = 0;
110  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
111 
112  if (foundVertex == g.theLayers.end()) {
113  vertexIndex = g.theLayers.size() - 1;
114  } else {
115  vertexIndex = foundVertex - g.theLayers.begin();
116  }
117 
118  if (j > 0) {
119  auto innerVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j - 1].name());
120 
121  CALayerPair tmpInnerLayerPair(innerVertex - g.theLayers.begin(), vertexIndex);
122 
123  if (std::find(g.theLayerPairs.begin(), g.theLayerPairs.end(), tmpInnerLayerPair) == g.theLayerPairs.end()) {
124  auto found = std::find_if(regionLayerPairs.begin(),
125  regionLayerPairs.end(),
127  return pair.innerLayerIndex() == layers[i][j - 1].index() &&
128  pair.outerLayerIndex() == layers[i][j].index();
129  });
130  if (found != regionLayerPairs.end()) {
131  hitDoublets.emplace_back(&(found->doublets()));
132  g.theLayerPairs.push_back(tmpInnerLayerPair);
133  g.theLayers[vertexIndex].theInnerLayers.push_back(innerVertex - g.theLayers.begin());
134  innerVertex->theOuterLayers.push_back(vertexIndex);
135  g.theLayers[vertexIndex].theInnerLayerPairs.push_back(g.theLayerPairs.size() - 1);
136  innerVertex->theOuterLayerPairs.push_back(g.theLayerPairs.size() - 1);
137  }
138  }
139  }
140  }
141  }
142  }
143 } // namespace
144 
146  std::vector<OrderedHitSeeds>& result,
147  const edm::EventSetup& es,
148  const SeedingLayerSetsHits& layers) {
149  CAGraph g;
150 
151  std::vector<const HitDoublets*> hitDoublets;
152 
153  std::vector<CACell::CAntuplet> foundTriplets;
154 
155  int index = 0;
156  for (const auto& regionLayerPairs : regionDoublets) {
157  const TrackingRegion& region = regionLayerPairs.region();
158  hitDoublets.clear();
159  foundTriplets.clear();
160 
161  if (index == 0) {
162  createGraphStructure(layers, g);
163  } else {
164  clearGraphStructure(layers, g);
165  }
166  fillGraph(layers, regionLayerPairs, g, hitDoublets);
167  CellularAutomaton ca(g);
168  ca.findTriplets(hitDoublets, foundTriplets, region, caThetaCut, caPhiCut, caHardPtCut);
169 
170  auto& allCells = ca.getAllCells();
171 
172  const QuantityDependsPtEval maxChi2Eval = maxChi2.evaluator(es);
173 
174  // re-used thoughout, need to be vectors because of RZLine interface
175  std::array<float, 3> bc_r;
176  std::array<float, 3> bc_z;
177  std::array<float, 3> bc_errZ2;
178  std::array<GlobalPoint, 3> gps;
179  std::array<GlobalError, 3> ges;
180  std::array<bool, 3> barrels;
181 
182  unsigned int numberOfFoundTriplets = foundTriplets.size();
183  for (unsigned int tripletId = 0; tripletId < numberOfFoundTriplets; ++tripletId) {
184  OrderedHitTriplet tmpTriplet(allCells[foundTriplets[tripletId][0]].getInnerHit(),
185  allCells[foundTriplets[tripletId][0]].getOuterHit(),
186  allCells[foundTriplets[tripletId][1]].getOuterHit());
187 
188  auto isBarrel = [](const unsigned id) -> bool { return id == PixelSubdetector::PixelBarrel; };
189  for (unsigned int i = 0; i < 2; ++i) {
190  auto const& ahit = allCells[foundTriplets[tripletId][i]].getInnerHit();
191  gps[i] = ahit->globalPosition();
192  ges[i] = ahit->globalPositionError();
193  barrels[i] = isBarrel(ahit->geographicalId().subdetId());
194  }
195 
196  auto const& ahit = allCells[foundTriplets[tripletId][1]].getOuterHit();
197  gps[2] = ahit->globalPosition();
198  ges[2] = ahit->globalPositionError();
199  barrels[2] = isBarrel(ahit->geographicalId().subdetId());
200 
201  PixelRecoLineRZ line(gps[0], gps[2]);
202  ThirdHitPredictionFromCircle predictionRPhi(gps[0], gps[2], extraHitRPhitolerance);
203  const float curvature = predictionRPhi.curvature(ThirdHitPredictionFromCircle::Vector2D(gps[1].x(), gps[1].y()));
204  const float abscurv = std::abs(curvature);
205  const float thisMaxChi2 = maxChi2Eval.value(abscurv);
206  float chi2 = std::numeric_limits<float>::quiet_NaN();
207  // TODO: Do we have any use case to not use bending correction?
208 
209  if (useBendingCorrection) {
210  // Following PixelFitterByConformalMappingAndLine
211  const float simpleCot = (gps.back().z() - gps.front().z()) / (gps.back().perp() - gps.front().perp());
212  const float pt = 1.f / PixelRecoUtilities::inversePt(abscurv, es);
213  for (int i = 0; i < 3; ++i) {
214  const GlobalPoint& point = gps[i];
215  const GlobalError& error = ges[i];
216  bc_r[i] = sqrt(sqr(point.x() - region.origin().x()) + sqr(point.y() - region.origin().y()));
217  bc_r[i] += pixelrecoutilities::LongitudinalBendingCorrection(pt, es)(bc_r[i]);
218  bc_z[i] = point.z() - region.origin().z();
219  bc_errZ2[i] = (barrels[i]) ? error.czz() : error.rerr(point) * sqr(simpleCot);
220  }
221  RZLine rzLine(bc_r, bc_z, bc_errZ2, RZLine::ErrZ2_tag());
222  chi2 = rzLine.chi2();
223  } else {
224  RZLine rzLine(gps, ges, barrels);
225  chi2 = rzLine.chi2();
226  }
227 
228  if (edm::isNotFinite(chi2) || chi2 > thisMaxChi2) {
229  continue;
230  }
231 
232  if (theComparitor) {
233  if (!theComparitor->compatible(tmpTriplet)) {
234  continue;
235  }
236  }
237  result[index].emplace_back(tmpTriplet);
238  }
239  index++;
240  }
241 }
size
Write out results.
T getParameter(std::string const &) const
const QuantityDependsPt maxChi2
const_iterator begin() const
GlobalPoint const & origin() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
const_iterator end() const
T y() const
Definition: PV3DBase.h:60
std::vector< CACell > & getAllCells()
void hitNtuplets(const IntermediateHitDoublets &regionDoublets, std::vector< OrderedHitSeeds > &result, const edm::EventSetup &es, const SeedingLayerSetsHits &layers)
bool ev
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
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
CAHitTripletGenerator(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
Range curvature(double transverseIP) const
T inversePt(T curvature, const edm::EventSetup &iSetup)
QuantityDependsPtEval evaluator(const edm::EventSetup &es) const
T curvature(T InversePt, const edm::EventSetup &iSetup)
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< CALayer > theLayers
Definition: CAGraph.h:45
T z() const
Definition: PV3DBase.h:61
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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:46
Definition: RZLine.h:12
T rerr(const GlobalPoint &aPoint) const
HLT enums.
Square< F >::type sqr(const F &f)
Definition: Square.h:14
std::vector< int > theRootLayers
Definition: CAGraph.h:47
static void fillDescriptions(edm::ParameterSetDescription &desc)
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:59
std::unique_ptr< SeedComparitor > theComparitor
float chi2() const
Definition: RZLine.h:94
unsigned short size() const
Get the number of SeedingLayerSets.
static unsigned int minLayers
#define constexpr
*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