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