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  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);
82 }
83 
84 namespace {
85  void createGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
86  for (unsigned int i = 0; i < layers.size(); i++) {
87  for (unsigned int j = 0; j < 3; ++j) {
88  auto vertexIndex = 0;
89  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
90  if (foundVertex == g.theLayers.end()) {
91  g.theLayers.emplace_back(layers[i][j].name(), layers[i][j].detLayer()->seqNum(), layers[i][j].hits().size());
92  vertexIndex = g.theLayers.size() - 1;
93  } else {
94  vertexIndex = foundVertex - g.theLayers.begin();
95  }
96  if (j == 0) {
97  if (std::find(g.theRootLayers.begin(), g.theRootLayers.end(), vertexIndex) == g.theRootLayers.end()) {
98  g.theRootLayers.emplace_back(vertexIndex);
99  }
100  }
101  }
102  }
103  }
104 
105  void clearGraphStructure(const SeedingLayerSetsHits& layers, CAGraph& g) {
106  g.theLayerPairs.clear();
107  for (unsigned int i = 0; i < g.theLayers.size(); i++) {
108  g.theLayers[i].theInnerLayers.clear();
109  g.theLayers[i].theInnerLayerPairs.clear();
110  g.theLayers[i].theOuterLayers.clear();
111  g.theLayers[i].theOuterLayerPairs.clear();
112  for (auto& v : g.theLayers[i].isOuterHitOfCell)
113  v.clear();
114  }
115  }
116 
117  void fillGraph(const SeedingLayerSetsHits& layers,
118  const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
119  CAGraph& g,
120  std::vector<const HitDoublets*>& hitDoublets) {
121  for (unsigned int i = 0; i < layers.size(); i++) {
122  for (unsigned int j = 0; j < 3; ++j) {
123  auto vertexIndex = 0;
124  auto foundVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j].name());
125 
126  if (foundVertex == g.theLayers.end()) {
127  vertexIndex = g.theLayers.size() - 1;
128  } else {
129  vertexIndex = foundVertex - g.theLayers.begin();
130  }
131 
132  if (j > 0) {
133  auto innerVertex = std::find(g.theLayers.begin(), g.theLayers.end(), layers[i][j - 1].name());
134 
135  CALayerPair tmpInnerLayerPair(innerVertex - g.theLayers.begin(), vertexIndex);
136 
137  if (std::find(g.theLayerPairs.begin(), g.theLayerPairs.end(), tmpInnerLayerPair) == g.theLayerPairs.end()) {
138  auto found = std::find_if(regionLayerPairs.begin(),
139  regionLayerPairs.end(),
141  return pair.innerLayerIndex() == layers[i][j - 1].index() &&
142  pair.outerLayerIndex() == layers[i][j].index();
143  });
144  if (found != regionLayerPairs.end()) {
145  hitDoublets.emplace_back(&(found->doublets()));
146  g.theLayerPairs.push_back(tmpInnerLayerPair);
147  g.theLayers[vertexIndex].theInnerLayers.push_back(innerVertex - g.theLayers.begin());
148  innerVertex->theOuterLayers.push_back(vertexIndex);
149  g.theLayers[vertexIndex].theInnerLayerPairs.push_back(g.theLayerPairs.size() - 1);
150  innerVertex->theOuterLayerPairs.push_back(g.theLayerPairs.size() - 1);
151  }
152  }
153  }
154  }
155  }
156  }
157 } // namespace
158 
160  std::vector<OrderedHitSeeds>& result,
161  const edm::EventSetup& es,
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(es);
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, es);
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 }
ihd::RegionLayerSets::region
const TrackingRegion & region() const
Definition: IntermediateHitDoublets.h:61
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:79
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
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:34
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
HLT_FULL_cff.extraHitRPhitolerance
extraHitRPhitolerance
Definition: HLT_FULL_cff.py:9864
CAHitTripletGenerator::maxChi2
const QuantityDependsPt maxChi2
Definition: CAHitTripletGenerator.h:125
CACut::setCutValuesByLayerIds
void setCutValuesByLayerIds(CAGraph &caLayers)
Definition: CACut.h:43
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:144
HitTripletGenerator.h
CAHitTripletGenerator::QuantityDependsPt::evaluator
QuantityDependsPtEval evaluator(const edm::EventSetup &es) const
Definition: CAHitTripletGenerator.h:105
CAHitTripletGenerator::QuantityDependsPtEval
Definition: CAHitTripletGenerator.h:58
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:130
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:38
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
CAHitTripletGenerator::caPhiCut
CACut caPhiCut
Definition: CAHitTripletGenerator.h:129
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
CAHitTripletGenerator::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &desc)
Definition: CAHitTripletGenerator.cc:46
CAHitTripletGenerator::extraHitRPhitolerance
const float extraHitRPhitolerance
Definition: CAHitTripletGenerator.h:123
Point3DBase< float, GlobalTag >
CAHitTripletGenerator::theComparitor
std::unique_ptr< SeedComparitor > theComparitor
Definition: CAHitTripletGenerator.h:56
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:47
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:159
HLT_FULL_cff.useBendingCorrection
useBendingCorrection
Definition: HLT_FULL_cff.py:9886
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88272
PixelRecoLineRZ
Definition: PixelRecoLineRZ.h:12
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
BarrelDetLayer.h
IntermediateHitDoublets
Definition: IntermediateHitDoublets.h:131
GlobalErrorBase< double, ErrorMatrixTag >
CellularAutomaton
Definition: CellularAutomaton.h:12
CAGraph
Definition: CAGraph.h:50
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
CALayerPair
Definition: CAGraph.h:34
DynArray.h
looper.cfg
cfg
Definition: looper.py:297
CAHitTripletGenerator::QuantityDependsPtEval::value
float value(float curvature) const
Definition: CAHitTripletGenerator.h:63
CAGraph.h
RZLine
Definition: RZLine.h:12
CAHitTripletGenerator.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
isFinite.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
T
long double T
Definition: Basic3DVectorLD.h:48
CellularAutomaton::findTriplets
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)
Definition: CellularAutomaton.cc:139
ihd::RegionLayerSets::begin
const_iterator begin() const
Definition: IntermediateHitDoublets.h:64
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
genVertex_cff.x
x
Definition: genVertex_cff.py:12
OrderedHitTriplet
Definition: OrderedHitTriplet.h:11
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
RZLine::ErrZ2_tag
Definition: RZLine.h:14
pixelrecoutilities::LongitudinalBendingCorrection
Definition: LongitudinalBendingCorrection.h:6
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TrackingRegion
Definition: TrackingRegion.h:41
mps_fire.result
result
Definition: mps_fire.py:311
CAHitTripletGenerator::useBendingCorrection
const bool useBendingCorrection
Definition: CAHitTripletGenerator.h:126
ConsumesCollector.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ThirdHitPredictionFromCircle
Definition: ThirdHitPredictionFromCircle.h:10
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
CAHitTripletGenerator::caThetaCut
CACut caThetaCut
Definition: CAHitTripletGenerator.h:128
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
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