CMS 3D CMS Logo

PixelHitMatcher.cc
Go to the documentation of this file.
3 
11 
12 using namespace reco;
13 using namespace std;
14 
16  const TrajectoryStateOnSurface &absolute_ts,
17  const GlobalPoint &absolute_gp) const {
18  GlobalVector ts = absolute_ts.globalParameters().position() - vprim;
19  GlobalVector gp = absolute_gp - vprim;
20 
21  float rDiff = gp.perp() - ts.perp();
22  float rMin = theRMin;
23  float rMax = theRMax;
24  float myZ = gp.z();
25  if ((std::abs(myZ) > 70.f) & (std::abs(myZ) < 170.f)) {
26  rMin = theRMinI;
27  rMax = theRMaxI;
28  }
29 
30  if ((rDiff >= rMax) | (rDiff <= rMin))
31  return false;
32 
33  float phiDiff = normalizedPhi(gp.barePhi() - ts.barePhi());
34 
35  return (phiDiff < thePhiMax) & (phiDiff > thePhiMin);
36 }
37 
39  const TrajectoryStateOnSurface &absolute_ts,
40  const GlobalPoint &absolute_gp) const {
41  GlobalVector ts = absolute_ts.globalParameters().position() - vprim;
42  GlobalVector gp = absolute_gp - vprim;
43 
44  float myZ = gp.z();
45  float zDiff = myZ - ts.z();
46  float myZmax = theZMax;
47  float myZmin = theZMin;
48  if ((std::abs(myZ) < 30.f) & (gp.perp() > 8.f)) {
49  myZmax = 0.09f;
50  myZmin = -0.09f;
51  }
52 
53  if ((zDiff >= myZmax) | (zDiff <= myZmin))
54  return false;
55 
56  float phiDiff = normalizedPhi(gp.barePhi() - ts.barePhi());
57 
58  return (phiDiff < thePhiMax) & (phiDiff > thePhiMin);
59 }
60 
62  float phi1max,
63  float phi2minB,
64  float phi2maxB,
65  float phi2minF,
66  float phi2maxF,
67  float z2minB,
68  float z2maxB,
69  float r2minF,
70  float r2maxF,
71  float rMinI,
72  float rMaxI,
73  bool useRecoVertex)
74  : //zmin1 and zmax1 are dummy at this moment, set from beamspot later
75  meas1stBLayer{phi1min, phi1max, 0., 0.},
76  meas2ndBLayer{phi2minB, phi2maxB, z2minB, z2maxB},
77  meas1stFLayer{phi1min, phi1max, 0., 0., rMinI, rMaxI},
78  meas2ndFLayer{phi2minF, phi2maxF, r2minF, r2maxF, rMinI, rMaxI},
79  prop1stLayer(nullptr),
80  prop2ndLayer(nullptr),
81  useRecoVertex_(useRecoVertex) {}
82 
83 void PixelHitMatcher::set1stLayer(float dummyphi1min, float dummyphi1max) {
84  meas1stBLayer.thePhiMin = dummyphi1min;
85  meas1stBLayer.thePhiMax = dummyphi1max;
86  meas1stFLayer.thePhiMin = dummyphi1min;
87  meas1stFLayer.thePhiMax = dummyphi1max;
88 }
89 
90 void PixelHitMatcher::set1stLayerZRange(float zmin1, float zmax1) {
91  meas1stBLayer.theZMin = zmin1;
92  meas1stBLayer.theZMax = zmax1;
93  meas1stFLayer.theRMin = zmin1;
94  meas1stFLayer.theRMax = zmax1;
95 }
96 
97 void PixelHitMatcher::set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF) {
98  meas2ndBLayer.thePhiMin = dummyphi2minB;
99  meas2ndBLayer.thePhiMax = dummyphi2maxB;
100  meas2ndFLayer.thePhiMin = dummyphi2minF;
101  meas2ndFLayer.thePhiMax = dummyphi2maxF;
102 }
103 
104 void PixelHitMatcher::setES(const MagneticField *magField, const TrackerGeometry *trackerGeometry) {
105  theMagField = magField;
106  theTrackerGeometry = trackerGeometry;
107  float mass = .000511; // electron propagation
108  prop1stLayer = std::make_unique<PropagatorWithMaterial>(oppositeToMomentum, mass, theMagField);
109  prop2ndLayer = std::make_unique<PropagatorWithMaterial>(alongMomentum, mass, theMagField);
110 }
111 
112 std::vector<SeedWithInfo> PixelHitMatcher::operator()(const std::vector<const TrajectorySeedCollection *> &seedsV,
113  const GlobalPoint &xmeas,
114  const GlobalPoint &vprim,
115  float energy,
116  int charge) const {
117  auto xmeas_r = xmeas.perp();
118 
119  const float phicut = std::cos(2.5);
120 
121  auto fts = trackingTools::ftsFromVertexToPoint(*theMagField, xmeas, vprim, energy, charge);
123  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
124 
125  std::vector<SeedWithInfo> result;
126  unsigned int allSeedsSize = 0;
127  for (auto const sc : seedsV)
128  allSeedsSize += sc->size();
129 
131 
132  auto ndets = theTrackerGeometry->dets().size();
133 
134  int iTsos[ndets];
135  for (auto &i : iTsos)
136  i = -1;
137  std::vector<TrajectoryStateOnSurface> vTsos;
138  vTsos.reserve(allSeedsSize);
139 
140  for (const auto seeds : seedsV) {
141  for (const auto &seed : *seeds) {
142  std::vector<GlobalPoint> hitGpMap;
143  if (seed.nHits() > 9) {
144  edm::LogWarning("GsfElectronAlgo|UnexpectedSeed") << "We cannot deal with seeds having more than 9 hits.";
145  continue;
146  }
147 
148  const TrajectorySeed::range &hits = seed.recHits();
149  // cache the global points
150 
151  for (auto it = hits.first; it != hits.second; ++it) {
152  hitGpMap.emplace_back(it->globalPosition());
153  }
154 
155  //iterate on the hits
156  auto he = hits.second - 1;
157  for (auto it1 = hits.first; it1 < he; ++it1) {
158  if (!it1->isValid())
159  continue;
160  auto idx1 = std::distance(hits.first, it1);
161  const DetId id1 = it1->geographicalId();
162  const GeomDet *geomdet1 = it1->det();
163 
164  auto ix1 = geomdet1->gdetIndex();
165 
166  /* VI: this generates regression (other cut is just in phi). in my opinion it is safe and makes sense
167  auto away = geomdet1->position().basicVector().dot(xmeas.basicVector()) <0;
168  if (away) continue;
169  */
170 
171  const GlobalPoint &hit1Pos = hitGpMap[idx1];
172  auto dt = hit1Pos.x() * xmeas.x() + hit1Pos.y() * xmeas.y();
173  if (dt < 0)
174  continue;
175  if (dt < phicut * (xmeas_r * hit1Pos.perp()))
176  continue;
177 
178  if (iTsos[ix1] < 0) {
179  iTsos[ix1] = vTsos.size();
180  vTsos.push_back(prop1stLayer->propagate(tsos, geomdet1->surface()));
181  }
182  auto tsos1 = &vTsos[iTsos[ix1]];
183 
184  if (!tsos1->isValid())
185  continue;
186  bool est = id1.subdetId() % 2 ? meas1stBLayer(vprim, *tsos1, hit1Pos) : meas1stFLayer(vprim, *tsos1, hit1Pos);
187  if (!est)
188  continue;
189  EleRelPointPair pp1(hit1Pos, tsos1->globalParameters().position(), vprim);
190  const math::XYZPoint relHit1Pos(hit1Pos - vprim), relTSOSPos(tsos1->globalParameters().position() - vprim);
191  const int subDet1 = id1.subdetId();
192  const float dRz1 = (id1.subdetId() % 2 ? pp1.dZ() : pp1.dPerp());
193  const float dPhi1 = pp1.dPhi();
194  // setup our vertex
195  double zVertex;
196  if (!useRecoVertex_) {
197  // we don't know the z vertex position, get it from linear extrapolation
198  // compute the z vertex from the cluster point and the found pixel hit
199  const double pxHit1z = hit1Pos.z();
200  const double pxHit1x = hit1Pos.x();
201  const double pxHit1y = hit1Pos.y();
202  const double r1diff =
203  std::sqrt((pxHit1x - vprim.x()) * (pxHit1x - vprim.x()) + (pxHit1y - vprim.y()) * (pxHit1y - vprim.y()));
204  const double r2diff =
205  std::sqrt((xmeas.x() - pxHit1x) * (xmeas.x() - pxHit1x) + (xmeas.y() - pxHit1y) * (xmeas.y() - pxHit1y));
206  zVertex = pxHit1z - r1diff * (xmeas.z() - pxHit1z) / r2diff;
207  } else {
208  // here use rather the reco vertex z position
209  zVertex = vprim.z();
210  }
211  GlobalPoint vertex(vprim.x(), vprim.y(), zVertex);
213  // now find the matching hit
214  for (auto it2 = it1 + 1; it2 != hits.second; ++it2) {
215  if (!it2->isValid())
216  continue;
217  auto idx2 = std::distance(hits.first, it2);
218  const DetId id2 = it2->geographicalId();
219  const GeomDet *geomdet2 = it2->det();
220  const auto det_key = std::make_pair(geomdet2->gdetIndex(), hit1Pos);
221  const TrajectoryStateOnSurface *tsos2;
222  auto tsos2_itr = mapTsos2Fast.find(det_key);
223  if (tsos2_itr != mapTsos2Fast.end()) {
224  tsos2 = &(tsos2_itr->second);
225  } else {
226  auto empl_result = mapTsos2Fast.emplace(det_key, prop2ndLayer->propagate(fts2, geomdet2->surface()));
227  tsos2 = &(empl_result.first->second);
228  }
229  if (!tsos2->isValid())
230  continue;
231  const GlobalPoint &hit2Pos = hitGpMap[idx2];
232  bool est2 =
233  id2.subdetId() % 2 ? meas2ndBLayer(vertex, *tsos2, hit2Pos) : meas2ndFLayer(vertex, *tsos2, hit2Pos);
234  if (est2) {
235  EleRelPointPair pp2(hit2Pos, tsos2->globalParameters().position(), vertex);
236  const int subDet2 = id2.subdetId();
237  const float dRz2 = (subDet2 % 2 == 1) ? pp2.dZ() : pp2.dPerp();
238  const float dPhi2 = pp2.dPhi();
239  const unsigned char hitsMask = (1 << idx1) | (1 << idx2);
240  result.push_back({seed, hitsMask, subDet2, dRz2, dPhi2, subDet1, dRz1, dPhi1});
241  }
242  } // inner loop on hits
243  } // outer loop on hits
244  } // loop on seeds
245  } //loop on vector of seeds
246 
247  return result;
248 }
Vector3DBase
Definition: Vector3DBase.h:8
PixelHitMatcher::useRecoVertex_
const bool useRecoVertex_
Definition: PixelHitMatcher.h:101
TrajectoryStateOnSurface.h
photonAnalyzer_cfi.rMax
rMax
Definition: photonAnalyzer_cfi.py:91
mps_fire.i
i
Definition: mps_fire.py:355
FreeTrajectoryState.h
MessageLogger.h
TrackerGeometry.h
GeomDet
Definition: GeomDet.h:27
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
GlobalTrajectoryParameters::position
GlobalPoint position() const
Definition: GlobalTrajectoryParameters.h:60
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
TrajectorySeed::range
std::pair< const_iterator, const_iterator > range
Definition: TrajectorySeed.h:21
PixelHitMatcher::set1stLayerZRange
void set1stLayerZRange(float zmin1, float zmax1)
Definition: PixelHitMatcher.cc:90
PixelHitMatcher::theMagField
const MagneticField * theMagField
Definition: PixelHitMatcher.h:99
globals_cff.id1
id1
Definition: globals_cff.py:32
oppositeToMomentum
Definition: PropagationDirection.h:4
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ElectronUtilities.h
PixelHitMatcher::ForwardMeasurementEstimator::thePhiMax
float thePhiMax
Definition: PixelHitMatcher.h:86
PixelHitMatcher::meas1stFLayer
ForwardMeasurementEstimator meas1stFLayer
Definition: PixelHitMatcher.h:95
PixelHitMatcher::BarrelMeasurementEstimator::theZMin
float theZMin
Definition: PixelHitMatcher.h:78
PixelHitMatcher::PixelHitMatcher
PixelHitMatcher(float phi1min, float phi1max, float phi2minB, float phi2maxB, float phi2minF, float phi2maxF, float z2minB, float z2maxB, float r2minF, float r2maxF, float rMinI, float rMaxI, bool useRecoVertex)
Definition: PixelHitMatcher.cc:61
HLT_FULL_cff.zVertex
zVertex
Definition: HLT_FULL_cff.py:109725
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
dt
float dt
Definition: AMPTWrapper.h:136
HLT_2018_cff.useRecoVertex
useRecoVertex
Definition: HLT_2018_cff.py:13862
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
trackingTools::ftsFromVertexToPoint
FreeTrajectoryState ftsFromVertexToPoint(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
Definition: ftsFromVertexToPoint.cc:17
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
PixelHitMatcher::ForwardMeasurementEstimator::theRMin
float theRMin
Definition: PixelHitMatcher.h:87
utils.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
PixelHitMatcher::operator()
std::vector< SeedWithInfo > operator()(const std::vector< const TrajectorySeedCollection * > &seedsV, const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, int charge) const
Definition: PixelHitMatcher.cc:112
normalizedPhi
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
Point3DBase< float, GlobalTag >
PixelHitMatcher::prop1stLayer
std::unique_ptr< PropagatorWithMaterial > prop1stLayer
Definition: PixelHitMatcher.h:97
PixelHitMatcher::BarrelMeasurementEstimator::theZMax
float theZMax
Definition: PixelHitMatcher.h:79
edm::LogWarning
Definition: MessageLogger.h:141
PixelHitMatcher::set2ndLayer
void set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF)
Definition: PixelHitMatcher.cc:97
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
PixelHitMatcher::BarrelMeasurementEstimator::thePhiMax
float thePhiMax
Definition: PixelHitMatcher.h:77
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
PV3DBase::barePhi
T barePhi() const
Definition: PV3DBase.h:65
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
IntGlobalPointPairUnorderedMap
std::unordered_map< std::pair< int, GlobalPoint >, T, HashIntGlobalPointPair > IntGlobalPointPairUnorderedMap
Definition: utils.h:20
PixelHitMatcher::ForwardMeasurementEstimator::thePhiMin
float thePhiMin
Definition: PixelHitMatcher.h:85
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
EleRelPointPair
Definition: ElectronUtilities.h:43
ftsFromVertexToPoint.h
PixelHitMatcher::meas2ndFLayer
ForwardMeasurementEstimator meas2ndFLayer
Definition: PixelHitMatcher.h:96
PixelHitMatcher::ForwardMeasurementEstimator::theRMax
float theRMax
Definition: PixelHitMatcher.h:88
GeomDet::gdetIndex
int gdetIndex() const
Definition: GeomDet.h:87
std
Definition: JetResolutionObject.h:76
PixelHitMatcher::setES
void setES(const MagneticField *, const TrackerGeometry *trackerGeometry)
Definition: PixelHitMatcher.cc:104
hcalSimParameters_cfi.he
he
Definition: hcalSimParameters_cfi.py:75
PixelHitMatcher::BarrelMeasurementEstimator::operator()
bool operator()(const GlobalPoint &vprim, const TrajectoryStateOnSurface &ts, const GlobalPoint &gp) const
Definition: PixelHitMatcher.cc:38
PerpendicularBoundPlaneBuilder
Definition: PerpendicularBoundPlaneBuilder.h:11
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
PixelHitMatcher::ForwardMeasurementEstimator::operator()
bool operator()(const GlobalPoint &vprim, const TrajectoryStateOnSurface &ts, const GlobalPoint &gp) const
Definition: PixelHitMatcher.cc:15
PixelHitMatcher.h
PixelHitMatcher::prop2ndLayer
std::unique_ptr< PropagatorWithMaterial > prop2ndLayer
Definition: PixelHitMatcher.h:98
PixelHitMatcher::theTrackerGeometry
const TrackerGeometry * theTrackerGeometry
Definition: PixelHitMatcher.h:100
photonAnalyzer_cfi.rMin
rMin
Definition: photonAnalyzer_cfi.py:90
PerpendicularBoundPlaneBuilder.h
mps_fire.result
result
Definition: mps_fire.py:303
PixelHitMatcher::BarrelMeasurementEstimator::thePhiMin
float thePhiMin
Definition: PixelHitMatcher.h:76
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PixelHitMatcher::set1stLayer
void set1stLayer(float dummyphi1min, float dummyphi1max)
Definition: PixelHitMatcher.cc:83
TrajectoryStateOnSurface::globalParameters
const GlobalTrajectoryParameters & globalParameters() const
Definition: TrajectoryStateOnSurface.h:64
globals_cff.id2
id2
Definition: globals_cff.py:33
MagneticField
Definition: MagneticField.h:19
PixelHitMatcher::meas2ndBLayer
BarrelMeasurementEstimator meas2ndBLayer
Definition: PixelHitMatcher.h:94
PixelHitMatcher::meas1stBLayer
BarrelMeasurementEstimator meas1stBLayer
Definition: PixelHitMatcher.h:93
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
alongMomentum
Definition: PropagationDirection.h:4
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
TrackerGeometry
Definition: TrackerGeometry.h:14