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 
26 constexpr unsigned int CAHitTripletGenerator::minLayers;
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()));
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 }
ihd::RegionLayerSets::region
const TrackingRegion & region() const
Definition: IntermediateHitDoublets.h:61
HLT_2018_cff.extraHitRPhitolerance
extraHitRPhitolerance
Definition: HLT_2018_cff.py:8543
egmGedGsfElectronPFIsolation_cff.vertexIndex
vertexIndex
Definition: egmGedGsfElectronPFIsolation_cff.py:54
DDAxes::y
CAHitTripletGenerator::initEvent
void initEvent(const edm::Event &ev, const edm::EventSetup &es)
Definition: CAHitTripletGenerator.cc:65
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
CAHitTripletGenerator::minLayers
static constexpr unsigned int minLayers
Definition: CAHitTripletGenerator.h:33
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
IntermediateHitDoublets::LayerPairHitDoublets
Definition: IntermediateHitDoublets.h:145
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
CAHitTripletGenerator::maxChi2
const QuantityDependsPt maxChi2
Definition: CAHitTripletGenerator.h:124
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SeedingLayerSetsHits
Definition: SeedingLayerSetsHits.h:18
ThirdHitPredictionFromCircle.h
sqr
int sqr(const T &t)
Definition: pfalgo_common_ref.h:9
PixelRecoUtilities::inversePt
T inversePt(T curvature, const edm::EventSetup &iSetup)
Definition: PixelRecoUtilities.h:48
beam_dqm_sourceclient-live_cfg.maxChi2
maxChi2
Definition: beam_dqm_sourceclient-live_cfg.py:139
HitTripletGenerator.h
CAHitTripletGenerator::QuantityDependsPt::evaluator
QuantityDependsPtEval evaluator(const edm::EventSetup &es) const
Definition: CAHitTripletGenerator.h:104
CAHitTripletGenerator::QuantityDependsPtEval
Definition: CAHitTripletGenerator.h:57
DDAxes::x
findQualityFiles.v
v
Definition: findQualityFiles.py:179
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
CAHitTripletGenerator::caHardPtCut
const float caHardPtCut
Definition: CAHitTripletGenerator.h:129
PixelRecoUtilities::curvature
T curvature(T InversePt, const edm::EventSetup &iSetup)
Definition: PixelRecoUtilities.h:42
CAHitTripletGenerator::CAHitTripletGenerator
CAHitTripletGenerator(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
Definition: CAHitTripletGenerator.h:37
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ihd::RegionLayerSets
Definition: IntermediateHitDoublets.h:48
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
relativeConstraints.error
error
Definition: relativeConstraints.py:53
RZLine::chi2
float chi2() const
Definition: RZLine.h:94
ThirdHitPredictionFromCircle::curvature
Range curvature(double transverseIP) const
Definition: ThirdHitPredictionFromCircle.cc:102
CellularAutomaton::getAllCells
std::vector< CACell > & getAllCells()
Definition: CellularAutomaton.h:16
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
vertices_cff.x
x
Definition: vertices_cff.py:29
CAHitTripletGenerator::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &desc)
Definition: CAHitTripletGenerator.cc:44
CAHitTripletGenerator::extraHitRPhitolerance
const float extraHitRPhitolerance
Definition: CAHitTripletGenerator.h:122
Point3DBase< float, GlobalTag >
CAHitTripletGenerator::theComparitor
std::unique_ptr< SeedComparitor > theComparitor
Definition: CAHitTripletGenerator.h:55
ParameterSetDescription.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Basic2DVector< Scalar >
PixelPluginsPhase0_cfi.isBarrel
isBarrel
Definition: PixelPluginsPhase0_cfi.py:17
ihd::RegionLayerSets::end
const_iterator end() const
Definition: IntermediateHitDoublets.h:66
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ParameterSet
Definition: Functions.h:16
CAHitTripletGenerator::hitNtuplets
void hitNtuplets(const IntermediateHitDoublets &regionDoublets, std::vector< OrderedHitSeeds > &result, const edm::EventSetup &es, const SeedingLayerSetsHits &layers)
Definition: CAHitTripletGenerator.cc:145
PixelRecoLineRZ
Definition: PixelRecoLineRZ.h:12
CAHitTripletGenerator::caThetaCut
const float caThetaCut
Definition: CAHitTripletGenerator.h:127
BarrelDetLayer.h
IntermediateHitDoublets
Definition: IntermediateHitDoublets.h:131
GlobalErrorBase< double, ErrorMatrixTag >
CellularAutomaton
Definition: CellularAutomaton.h:12
CAGraph
Definition: CAGraph.h:44
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
CALayerPair
Definition: CAGraph.h:28
DynArray.h
looper.cfg
cfg
Definition: looper.py:297
CAHitTripletGenerator::QuantityDependsPtEval::value
float value(float curvature) const
Definition: CAHitTripletGenerator.h:62
CAGraph.h
HLT_2018_cff.useBendingCorrection
useBendingCorrection
Definition: HLT_2018_cff.py:8555
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
RZLine
Definition: RZLine.h:12
CAHitTripletGenerator.h
std
Definition: JetResolutionObject.h:76
CellularAutomaton::findTriplets
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)
Definition: CellularAutomaton.cc:134
isFinite.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
T
long double T
Definition: Basic3DVectorLD.h:48
ihd::RegionLayerSets::begin
const_iterator begin() const
Definition: IntermediateHitDoublets.h:64
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
OrderedHitTriplet
Definition: OrderedHitTriplet.h:11
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
RZLine::ErrZ2_tag
Definition: RZLine.h:14
pixelrecoutilities::LongitudinalBendingCorrection
Definition: LongitudinalBendingCorrection.h:6
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TrackingRegion
Definition: TrackingRegion.h:40
mps_fire.result
result
Definition: mps_fire.py:303
CAHitTripletGenerator::useBendingCorrection
const bool useBendingCorrection
Definition: CAHitTripletGenerator.h:125
ConsumesCollector.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ThirdHitPredictionFromCircle
Definition: ThirdHitPredictionFromCircle.h:10
CAHitTripletGenerator::caPhiCut
const float caPhiCut
Definition: CAHitTripletGenerator.h:128
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
point
*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
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
CellularAutomaton.h
g
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
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443