CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CAHitTripletGenerator.cc
Go to the documentation of this file.
1 #include <unordered_map>
2 
13 
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 
26 constexpr unsigned int CAHitTripletGenerator::minLayers;
27 
29  : theFieldToken(iC.esConsumes()),
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  cfg.getParameter<std::vector<edm::ParameterSet>>("CAThetaCut_byTriplets")),
36  caPhiCut(cfg.getParameter<double>("CAPhiCut"),
37  cfg.getParameter<std::vector<edm::ParameterSet>>("CAPhiCut_byTriplets")),
38  caHardPtCut(cfg.getParameter<double>("CAHardPtCut")) {
39  edm::ParameterSet comparitorPSet = cfg.getParameter<edm::ParameterSet>("SeedComparitorPSet");
40  std::string comparitorName = comparitorPSet.getParameter<std::string>("ComponentName");
41  if (comparitorName != "none") {
42  theComparitor = SeedComparitorFactory::get()->create(comparitorName, comparitorPSet, iC);
43  }
44 }
45 
47  desc.add<double>("extraHitRPhitolerance", 0.06);
48  desc.add<bool>("useBendingCorrection", false);
49  desc.add<double>("CAThetaCut", 0.00125);
50  desc.add<double>("CAPhiCut", 0.1);
51 
52  edm::ParameterSetDescription validatorCACut;
53  validatorCACut.add<string>("seedingLayers", "BPix1+BPix2+BPix3");
54  validatorCACut.add<double>("cut", 0.00125);
55  std::vector<edm::ParameterSet> defaultCACutVector;
56  edm::ParameterSet defaultCACut;
57  defaultCACut.addParameter<string>("seedingLayers", "");
58  defaultCACut.addParameter<double>("cut", -1.);
59  defaultCACutVector.push_back(defaultCACut);
60  desc.addVPSet("CAThetaCut_byTriplets", validatorCACut, defaultCACutVector);
61  desc.addVPSet("CAPhiCut_byTriplets", validatorCACut, defaultCACutVector);
62 
63  desc.add<double>("CAHardPtCut", 0);
64 
65  edm::ParameterSetDescription descMaxChi2;
66  descMaxChi2.add<double>("pt1", 0.8);
67  descMaxChi2.add<double>("pt2", 2);
68  descMaxChi2.add<double>("value1", 50);
69  descMaxChi2.add<double>("value2", 8);
70  descMaxChi2.add<bool>("enabled", true);
71  desc.add<edm::ParameterSetDescription>("maxChi2", descMaxChi2);
72 
73  edm::ParameterSetDescription descComparitor;
74  descComparitor.add<std::string>("ComponentName", "none");
75  descComparitor.setAllowAnything(); // until we have moved SeedComparitor too to EDProducers
76  desc.add<edm::ParameterSetDescription>("SeedComparitorPSet", descComparitor);
77 }
78 
80  if (theComparitor)
81  theComparitor->init(ev, es);
83 }
84 
85 namespace {
86  void createGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
87  for (unsigned int i = 0; i < layers.size(); i++) {
88  for (unsigned int j = 0; j < 3; ++j) {
89  auto vertexIndex = 0;
90  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
91  if (foundVertex == g.theLayers.end()) {
92  g.theLayers.emplace_back(layers[i][j].name(), layers[i][j].detLayer()->seqNum(), layers[i][j].hits().size());
93  vertexIndex = g.theLayers.size() - 1;
94  } else {
95  vertexIndex = foundVertex - g.theLayers.begin();
96  }
97  if (j == 0) {
98  if (std::find(g.theRootLayers.begin(), g.theRootLayers.end(), vertexIndex) == g.theRootLayers.end()) {
99  g.theRootLayers.emplace_back(vertexIndex);
100  }
101  }
102  }
103  }
104  }
105 
106  void clearGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
107  g.theLayerPairs.clear();
108  for (unsigned int i = 0; i < g.theLayers.size(); i++) {
109  g.theLayers[i].theInnerLayers.clear();
110  g.theLayers[i].theInnerLayerPairs.clear();
111  g.theLayers[i].theOuterLayers.clear();
112  g.theLayers[i].theOuterLayerPairs.clear();
113  for (auto& v : g.theLayers[i].isOuterHitOfCell)
114  v.clear();
115  }
116  }
117 
118  void fillGraph(const SeedingLayerSetsHits& layers,
119  const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
120  CAGraph& g,
121  std::vector<const HitDoublets*>& hitDoublets) {
122  for (unsigned int i = 0; i < layers.size(); i++) {
123  for (unsigned int j = 0; j < 3; ++j) {
124  auto vertexIndex = 0;
125  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
126 
127  if (foundVertex == g.theLayers.end()) {
128  vertexIndex = g.theLayers.size() - 1;
129  } else {
130  vertexIndex = foundVertex - g.theLayers.begin();
131  }
132 
133  if (j > 0) {
134  auto innerVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j - 1].name());
135 
136  CALayerPair tmpInnerLayerPair(innerVertex - g.theLayers.begin(), vertexIndex);
137 
138  if (std::find(g.theLayerPairs.begin(), g.theLayerPairs.end(), tmpInnerLayerPair) == g.theLayerPairs.end()) {
139  auto found = std::find_if(regionLayerPairs.begin(),
140  regionLayerPairs.end(),
142  return pair.innerLayerIndex() == layers[i][j - 1].index() &&
143  pair.outerLayerIndex() == layers[i][j].index();
144  });
145  if (found != regionLayerPairs.end()) {
146  hitDoublets.emplace_back(&(found->doublets()));
147  g.theLayerPairs.push_back(tmpInnerLayerPair);
148  g.theLayers[vertexIndex].theInnerLayers.push_back(innerVertex - g.theLayers.begin());
149  innerVertex->theOuterLayers.push_back(vertexIndex);
150  g.theLayers[vertexIndex].theInnerLayerPairs.push_back(g.theLayerPairs.size() - 1);
151  innerVertex->theOuterLayerPairs.push_back(g.theLayerPairs.size() - 1);
152  }
153  }
154  }
155  }
156  }
157  }
158 } // namespace
159 
161  std::vector<OrderedHitSeeds>& result,
162  const SeedingLayerSetsHits& layers) {
163  CAGraph g;
164 
165  std::vector<const HitDoublets*> hitDoublets;
166 
167  std::vector<CACell::CAntuplet> foundTriplets;
168 
169  int index = 0;
170  for (const auto& regionLayerPairs : regionDoublets) {
171  const TrackingRegion& region = regionLayerPairs.region();
172  hitDoublets.clear();
173  foundTriplets.clear();
174 
175  if (index == 0) {
176  createGraphStructure(layers, g);
179  } else {
180  clearGraphStructure(layers, g);
181  }
182  fillGraph(layers, regionLayerPairs, g, hitDoublets);
183  CellularAutomaton ca(g);
184  ca.findTriplets(hitDoublets, foundTriplets, region, caThetaCut, caPhiCut, caHardPtCut);
185 
186  auto& allCells = ca.getAllCells();
187 
188  const QuantityDependsPtEval maxChi2Eval = maxChi2.evaluator(*theField);
189 
190  // re-used thoughout, need to be vectors because of RZLine interface
191  std::array<float, 3> bc_r;
192  std::array<float, 3> bc_z;
193  std::array<float, 3> bc_errZ2;
194  std::array<GlobalPoint, 3> gps;
195  std::array<GlobalError, 3> ges;
196  std::array<bool, 3> barrels;
197 
198  unsigned int numberOfFoundTriplets = foundTriplets.size();
199  for (unsigned int tripletId = 0; tripletId < numberOfFoundTriplets; ++tripletId) {
200  OrderedHitTriplet tmpTriplet(allCells[foundTriplets[tripletId][0]].getInnerHit(),
201  allCells[foundTriplets[tripletId][0]].getOuterHit(),
202  allCells[foundTriplets[tripletId][1]].getOuterHit());
203 
204  auto isBarrel = [](const unsigned id) -> bool { return id == PixelSubdetector::PixelBarrel; };
205  for (unsigned int i = 0; i < 2; ++i) {
206  auto const& ahit = allCells[foundTriplets[tripletId][i]].getInnerHit();
207  gps[i] = ahit->globalPosition();
208  ges[i] = ahit->globalPositionError();
209  barrels[i] = isBarrel(ahit->geographicalId().subdetId());
210  }
211 
212  auto const& ahit = allCells[foundTriplets[tripletId][1]].getOuterHit();
213  gps[2] = ahit->globalPosition();
214  ges[2] = ahit->globalPositionError();
215  barrels[2] = isBarrel(ahit->geographicalId().subdetId());
216 
217  PixelRecoLineRZ line(gps[0], gps[2]);
218  ThirdHitPredictionFromCircle predictionRPhi(gps[0], gps[2], extraHitRPhitolerance);
219  const float curvature = predictionRPhi.curvature(ThirdHitPredictionFromCircle::Vector2D(gps[1].x(), gps[1].y()));
220  const float abscurv = std::abs(curvature);
221  const float thisMaxChi2 = maxChi2Eval.value(abscurv);
222  float chi2 = std::numeric_limits<float>::quiet_NaN();
223  // TODO: Do we have any use case to not use bending correction?
224 
225  if (useBendingCorrection) {
226  // Following PixelFitterByConformalMappingAndLine
227  const float simpleCot = (gps.back().z() - gps.front().z()) / (gps.back().perp() - gps.front().perp());
228  const float pt = 1.f / PixelRecoUtilities::inversePt(abscurv, *theField);
229  for (int i = 0; i < 3; ++i) {
230  const GlobalPoint& point = gps[i];
231  const GlobalError& error = ges[i];
232  bc_r[i] = sqrt(sqr(point.x() - region.origin().x()) + sqr(point.y() - region.origin().y()));
234  bc_z[i] = point.z() - region.origin().z();
235  bc_errZ2[i] = (barrels[i]) ? error.czz() : error.rerr(point) * sqr(simpleCot);
236  }
237  RZLine rzLine(bc_r, bc_z, bc_errZ2, RZLine::ErrZ2_tag());
238  chi2 = rzLine.chi2();
239  } else {
240  RZLine rzLine(gps, ges, barrels);
241  chi2 = rzLine.chi2();
242  }
243 
244  if (edm::isNotFinite(chi2) || chi2 > thisMaxChi2) {
245  continue;
246  }
247 
248  if (theComparitor) {
249  if (!theComparitor->compatible(tmpTriplet)) {
250  continue;
251  }
252  }
253  result[index].emplace_back(tmpTriplet);
254  }
255  index++;
256  }
257 }
const QuantityDependsPt maxChi2
tuple cfg
Definition: looper.py:296
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void setCutValuesByLayerIds(CAGraph &caLayers)
Definition: CACut.h:43
const_iterator begin() const
GlobalPoint const & origin() const
uint16_t *__restrict__ id
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
const_iterator end() const
T y() const
Definition: PV3DBase.h:60
std::vector< CACell > & getAllCells()
int sqr(const T &t)
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)
T curvature(T InversePt, const MagneticField &field)
tuple result
Definition: mps_fire.py:311
Range curvature(double transverseIP) const
const MagneticField * theField
bool getData(T &iHolder) const
Definition: EventSetup.h:122
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< CALayer > theLayers
Definition: CAGraph.h:59
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
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)
tuple extraHitRPhitolerance
T inversePt(T curvature, const MagneticField &field)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:60
Definition: RZLine.h:12
const TrackingRegion & region() const
tuple useBendingCorrection
T rerr(const GlobalPoint &aPoint) const
static constexpr unsigned int minLayers
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< int > theRootLayers
Definition: CAGraph.h:61
static void fillDescriptions(edm::ParameterSetDescription &desc)
float x
QuantityDependsPtEval evaluator(const MagneticField &field) const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > theFieldToken
#define get
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.
void findTriplets(const std::vector< const HitDoublets * > &hitDoublets, std::vector< CACell::CAntuplet > &foundTriplets, const TrackingRegion &region, const CACut &thetaCut, const CACut &phiCut, const float hardPtCut)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tuple size
Write out results.
*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 hitNtuplets(const IntermediateHitDoublets &regionDoublets, std::vector< OrderedHitSeeds > &result, const SeedingLayerSetsHits &layers)