CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RectangularEtaPhiTrackingRegion.cc
Go to the documentation of this file.
1 #include <cmath>
3 
4 #include "OuterEstimator.h"
5 
11 
22 
24 
33 
34 #include <iostream>
35 #include <algorithm>
36 #include <cctype>
37 
38 namespace {
39  template <class T>
40  T sqr(T t) {
41  return t * t;
42  }
43 } // namespace
44 
45 using namespace PixelRecoUtilities;
46 using namespace std;
47 
48 void RectangularEtaPhiTrackingRegion::checkTracks(reco::TrackCollection const& tracks, std::vector<bool>& mask) const {
49  const math::XYZPoint regOrigin(origin().x(), origin().y(), origin().z());
50  auto phi0 = phiDirection() + 0.5 * (phiMargin().right() - phiMargin().left());
51  auto dphi = 0.5 * (phiMargin().right() + phiMargin().left());
52 
53  assert(mask.size() == tracks.size());
54  int i = -1;
55  for (auto const& track : tracks) {
56  i++;
57  if (mask[i])
58  continue;
59 
60  if (track.pt() < ptMin()) {
61  continue;
62  }
63  if (!etaRange().inside(track.eta())) {
64  continue;
65  }
66  if (std::abs(proxim(track.phi(), phi0) - phi0) > dphi) {
67  continue;
68  }
69  if (std::abs(track.dxy(regOrigin)) > originRBound()) {
70  continue;
71  }
72  if (std::abs(track.dz(regOrigin)) > originZBound()) {
73  continue;
74  }
75  mask[i] = true;
76  }
77 }
78 
80  const std::string& name) {
82  std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
83  if (tmp == "never")
84  return UseMeasurementTracker::kNever;
85  if (tmp == "forsistrips")
86  return UseMeasurementTracker::kForSiStrips;
87  if (tmp == "always")
88  return UseMeasurementTracker::kAlways;
89  throw cms::Exception("Configuration") << "Got invalid string '" << name
90  << "', valid values are 'Never', 'ForSiStrips', 'Always' (case insensitive)";
91 }
92 
94  float eta = dir.eta();
95  theEtaRange = Range(eta - margin.left(), eta + margin.right());
96  theLambdaRange = Range(std::sinh(theEtaRange.min()), std::sinh(theEtaRange.max()));
97  theMeanLambda = std::sinh(theEtaRange.mean());
98 }
99 
100 std::unique_ptr<HitRZCompatibility> RectangularEtaPhiTrackingRegion::checkRZOld(const DetLayer* layer,
101  const Hit& outerHit,
102  const DetLayer* outerlayer) const {
103  bool isBarrel = (layer->location() == GeomDetEnumerators::barrel);
104  GlobalPoint ohit = outerHit->globalPosition();
105  float outerred_r = std::sqrt(sqr(ohit.x() - origin().x()) + sqr(ohit.y() - origin().y()));
106  PixelRecoPointRZ outer(outerred_r, ohit.z());
107 
108  float zMinOrigin = origin().z() - originZBound();
109  float zMaxOrigin = origin().z() + originZBound();
110 
111  if (!thePrecise) {
112  float vcotMin = (outer.z() > zMaxOrigin) ? (outer.z() - zMaxOrigin) / (outer.r() + originRBound())
113  : (outer.z() - zMaxOrigin) / (outer.r() - originRBound());
114  float vcotMax = (outer.z() > zMinOrigin) ? (outer.z() - zMinOrigin) / (outer.r() - originRBound())
115  : (outer.z() - zMinOrigin) / (outer.r() + originRBound());
116  float cotRight = std::max(vcotMin, theLambdaRange.min());
117  float cotLeft = std::min(vcotMax, theLambdaRange.max());
118  return std::make_unique<HitEtaCheck>(isBarrel, outer, cotLeft, cotRight);
119  }
120 
121  float outerZscatt = 0;
122  float innerScatt = 0;
123  //CHECK
124  if (theUseMS) {
125  MultipleScatteringParametrisation oSigma = theMSMaker->parametrisation(layer);
126  float cotThetaOuter = theMeanLambda;
127  float sinThetaOuterInv = std::sqrt(1.f + sqr(cotThetaOuter));
128  outerZscatt = 3.f * oSigma(ptMin(), cotThetaOuter) * sinThetaOuterInv;
129  }
130 
131  PixelRecoLineRZ boundL(outer, theLambdaRange.max());
132  PixelRecoLineRZ boundR(outer, theLambdaRange.min());
133  float zMinLine = boundL.zAtR(0.) - outerZscatt;
134  float zMaxLine = boundR.zAtR(0.) + outerZscatt;
135  PixelRecoPointRZ vtxL(0., max(zMinLine, zMinOrigin));
136  PixelRecoPointRZ vtxR(0., min(zMaxLine, zMaxOrigin));
137  PixelRecoPointRZ vtxMean(0., (vtxL.z() + vtxR.z()) * 0.5f);
138  //CHECK
139 
140  if (theUseMS) {
141  MultipleScatteringParametrisation iSigma = theMSMaker->parametrisation(layer);
142 
143  innerScatt =
144  3.f * (outerlayer ? iSigma(ptMin(), vtxMean, outer, outerlayer->seqNum()) : iSigma(ptMin(), vtxMean, outer));
145 
146  // innerScatt = 3.f *iSigma( ptMin(), vtxMean, outer);
147  }
148 
149  SimpleLineRZ leftLine(vtxL, outer);
150  SimpleLineRZ rightLine(vtxR, outer);
151 
152  HitRZConstraint rzConstraint(leftLine, rightLine);
153  auto cotTheta = std::abs(leftLine.cotLine() + rightLine.cotLine()) * 0.5f;
154 
155  // std::cout << "RectangularEtaPhiTrackingRegion " << outer.r()<<','<< outer.z() << " " << innerScatt << " " << cotTheta << " " << hitZErr << std::endl;
156 
157  if (isBarrel) {
158  auto sinThetaInv = std::sqrt(1.f + sqr(cotTheta));
159  auto corr = innerScatt * sinThetaInv;
160  return std::make_unique<HitZCheck>(rzConstraint, HitZCheck::Margin(corr, corr));
161  } else {
162  auto cosThetaInv = std::sqrt(1.f + sqr(1.f / cotTheta));
163  auto corr = innerScatt * cosThetaInv;
164  return std::make_unique<HitRCheck>(rzConstraint, HitRCheck::Margin(corr, corr));
165  }
166 }
167 
168 std::unique_ptr<MeasurementEstimator> RectangularEtaPhiTrackingRegion::estimator(const BarrelDetLayer* layer) const {
169  using Algo = HitZCheck;
170 
171  // det dimensions
172  float halfLength = 0.5f * layer->surface().bounds().length();
173  float halfThickness = 0.5f * layer->surface().bounds().thickness();
174  float z0 = layer->position().z();
175  float radius = layer->specificSurface().radius();
176 
177  // det ranges
178  Range detRWindow(radius - halfThickness, radius + halfThickness);
179  Range detZWindow(z0 - halfLength, z0 + halfLength);
180 
181  // z prediction, skip if not intersection
182  HitZCheck zPrediction(rzConstraint());
183  Range hitZWindow = zPrediction.range(detRWindow.min()).intersection(detZWindow);
184  if (hitZWindow.empty())
185  return nullptr;
186 
187  // phi prediction
188  OuterHitPhiPrediction phiPrediction = phiWindow(*theField);
189 
190  //
191  // optional corrections for tolerance (mult.scatt, error, bending)
192  //
194  if (thePrecise) {
195  auto invR = 1.f / radius;
196  auto cotTheta = (hitZWindow.mean() - origin().z()) * invR;
197  auto sinThetaInv = std::sqrt(1.f + sqr(cotTheta));
198  MultipleScatteringParametrisation msSigma = theMSMaker->parametrisation(layer);
199  auto scatt = 3.f * msSigma(ptMin(), cotTheta);
200  auto bendR = longitudinalBendingCorrection(radius, ptMin(), *theField);
201 
202  float hitErrRPhi = 0.;
203  float hitErrZ = 0.;
204  float corrPhi = (scatt + hitErrRPhi) * invR;
205  float corrZ = scatt * sinThetaInv + bendR * std::abs(cotTheta) + hitErrZ;
206 
207  phiPrediction.setTolerance(corrPhi);
208  zPrediction.setTolerance(HitZCheck::Margin(corrZ, corrZ));
209 
210  //
211  // hit ranges in det
212  //
213  OuterHitPhiPrediction::Range phi1 = phiPrediction(detRWindow.min());
214  OuterHitPhiPrediction::Range phi2 = phiPrediction(detRWindow.max());
215  phiRange = Range(std::min(phi1.min(), phi2.min()), std::max(phi1.max(), phi2.max()));
216  Range w1 = zPrediction.range(detRWindow.min());
217  Range w2 = zPrediction.range(detRWindow.max());
218  hitZWindow = Range(std::min(w1.min(), w2.min()), std::max(w1.max(), w2.max())).intersection(detZWindow);
219  } else {
220  phiRange = phiPrediction(detRWindow.mean());
221  }
222 
223  return std::make_unique<OuterEstimator<Algo>>(OuterDetCompatibility(layer, phiRange, detRWindow, hitZWindow),
224  OuterHitCompatibility<Algo>(phiPrediction, zPrediction));
225 }
226 
227 std::unique_ptr<MeasurementEstimator> RectangularEtaPhiTrackingRegion::estimator(const ForwardDetLayer* layer) const {
228  using Algo = HitRCheck;
229  // det dimensions, ranges
230  float halfThickness = 0.5f * layer->surface().bounds().thickness();
231  float zLayer = layer->position().z();
232  Range detZWindow(zLayer - halfThickness, zLayer + halfThickness);
233  Range detRWindow(layer->specificSurface().innerRadius(), layer->specificSurface().outerRadius());
234 
235  // r prediction, skip if not intersection
236  HitRCheck rPrediction(rzConstraint());
237  Range hitRWindow = rPrediction.range(zLayer).intersection(detRWindow);
238  if (hitRWindow.empty())
239  return nullptr;
240 
241  // phi prediction
242  OuterHitPhiPrediction phiPrediction = phiWindow(*theField);
243  OuterHitPhiPrediction::Range phiRange = phiPrediction(detRWindow.max());
244 
245  //
246  // optional corrections for tolerance (mult.scatt, error, bending)
247  //
248  if (thePrecise) {
249  float cotTheta = (detZWindow.mean() - origin().z()) / hitRWindow.mean();
250  float cosThetaInv = std::sqrt(1 + sqr(cotTheta)) / cotTheta;
251  MultipleScatteringParametrisation msSigma = theMSMaker->parametrisation(layer);
252  float scatt = 3.f * msSigma(ptMin(), cotTheta);
253  float bendR = longitudinalBendingCorrection(hitRWindow.max(), ptMin(), *theField);
254  float hitErrRPhi = 0.;
255  float hitErrR = 0.;
256  float corrPhi = (scatt + hitErrRPhi) / detRWindow.min();
257  float corrR = scatt * std::abs(cosThetaInv) + bendR + hitErrR;
258 
259  phiPrediction.setTolerance(corrPhi);
260  rPrediction.setTolerance(HitRCheck::Margin(corrR, corrR));
261 
262  //
263  // hit ranges in det
264  //
265  Range w1, w2;
266  if (zLayer > 0) {
267  w1 = rPrediction.range(detZWindow.min());
268  w2 = rPrediction.range(detZWindow.max());
269  } else {
270  w1 = rPrediction.range(detZWindow.max());
271  w2 = rPrediction.range(detZWindow.min());
272  }
273  hitRWindow = Range(w1.min(), w2.max()).intersection(detRWindow);
274  }
275 
276  return std::make_unique<OuterEstimator<Algo>>(OuterDetCompatibility(layer, phiRange, hitRWindow, detZWindow),
277  OuterHitCompatibility<Algo>(phiPrediction, rPrediction));
278 }
279 
281  auto phi0 = phiDirection();
282  return OuterHitPhiPrediction(
283  OuterHitPhiPrediction::Range(phi0 - thePhiMargin.left(), phi0 + thePhiMargin.right()),
284  OuterHitPhiPrediction::Range(curvature(invPtRange().min(), field), curvature(invPtRange().max(), field)),
285  originRBound());
286 }
287 
289  HitRZConstraint::Point pLeft, pRight;
290  float zMin = origin().z() - originZBound();
291  float zMax = origin().z() + originZBound();
292  float rMin = -originRBound();
293  float rMax = originRBound();
294  if (theEtaRange.max() > 0) {
295  pRight = HitRZConstraint::Point(rMin, zMax);
296  } else {
297  pRight = HitRZConstraint::Point(rMax, zMax);
298  }
299  if (theEtaRange.min() > 0.) {
300  pLeft = HitRZConstraint::Point(rMax, zMin);
301  } else {
302  pLeft = HitRZConstraint::Point(rMin, zMin);
303  }
304  return HitRZConstraint(pLeft, theLambdaRange.min(), pRight, theLambdaRange.max());
305 }
306 
309 
310  //ESTIMATOR
311 
312  const DetLayer* detLayer = layer.detLayer();
313 
314  bool measurementMethod = false;
315  if (theMeasurementTrackerUsage == UseMeasurementTracker::kAlways)
316  measurementMethod = true;
317  else if (theMeasurementTrackerUsage == UseMeasurementTracker::kForSiStrips &&
319  measurementMethod = true;
320 
321  if (measurementMethod) {
322  const GlobalPoint vtx = origin();
323  GlobalVector dir = direction();
324 
325  std::unique_ptr<MeasurementEstimator> est;
328  (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::barrel)) {
329  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
330  est = estimator(&bl);
331  } else if ((GeomDetEnumerators::isTrackerPixel(detLayer->subDetector()) &&
333  (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::endcap)) {
334  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
335  est = estimator(&fl);
336  }
337 
338  EtaPhiMeasurementEstimator etaPhiEstimator((theEtaRange.second - theEtaRange.first) * 0.5f,
339  (thePhiMargin.left() + thePhiMargin.right()) * 0.5f);
340  MeasurementEstimator* findDetAndHits = &etaPhiEstimator;
341  if (est) {
342  LogDebug("RectangularEtaPhiTrackingRegion") << "use pixel specific estimator.";
343  findDetAndHits = est.get();
344  } else {
345  LogDebug("RectangularEtaPhiTrackingRegion") << "use generic etat phi estimator.";
346  }
347 
348  // TSOS
349  float phi = phiDirection();
350  // std::cout << "dir " << direction().x()/direction().perp() <<','<< direction().y()/direction().perp() << " " << sin(phi) <<','<<cos(phi)<< std::endl;
351  Surface::RotationType rot(sin(phi), -cos(phi), 0, 0, 0, -1, cos(phi), sin(phi), 0);
352 
353  Plane::PlanePointer surface = Plane::build(GlobalPoint(0., 0., 0.), rot);
354  //TrajectoryStateOnSurface tsos(lpar, *surface, theField);
355 
356  FreeTrajectoryState fts(GlobalTrajectoryParameters(vtx, dir, 1, theField));
357  TrajectoryStateOnSurface tsos(fts, *surface);
358 
359  // propagator
360  StraightLinePropagator prop(theField, alongMomentum);
361 
362  LayerMeasurements lm(theMeasurementTracker->measurementTracker(), *theMeasurementTracker);
363 
364  auto hits = lm.recHits(*detLayer, tsos, prop, *findDetAndHits);
365 
366  result.reserve(hits.size());
367  for (auto h : hits) {
368  cache.emplace_back(h);
369  result.emplace_back(h);
370  }
371 
372  LogDebug("RectangularEtaPhiTrackingRegion")
373  << " found " << hits.size() << " minus one measurements on layer: " << detLayer->subDetector();
374  // std::cout << "RectangularEtaPhiTrackingRegion" <<" found "<< meas.size()<<" minus one measurements on layer: "<<detLayer->subDetector() << std::endl;
375 
376  } else {
377  //
378  // temporary solution (actually heavily used for Pixels....)
379  //
380  if (detLayer->location() == GeomDetEnumerators::barrel) {
381  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
382  auto est = estimator(&bl);
383  if (!est)
384  return result;
385  using Algo = HitZCheck;
386  auto const& hitComp = (reinterpret_cast<OuterEstimator<Algo> const&>(*est)).hitCompatibility();
387  auto layerHits = layer.hits();
388  result.reserve(layerHits.size());
389  for (auto&& ih : layerHits) {
390  if (hitComp(*ih))
391  result.emplace_back(ih);
392  }
393 
394  } else {
395  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
396  auto est = estimator(&fl);
397  if (!est)
398  return result;
399  using Algo = HitRCheck;
400  auto const& hitComp = (reinterpret_cast<OuterEstimator<Algo> const&>(*est)).hitCompatibility();
401  auto layerHits = layer.hits();
402  result.reserve(layerHits.size());
403  for (auto&& ih : layerHits) {
404  if (hitComp(*ih))
405  result.emplace_back(ih);
406  }
407  }
408  }
409 
410  // std::cout << "RectangularEtaPhiTrackingRegion hits " << result.size() << std::endl;
411 
412  return result;
413 }
414 
416  std::ostringstream str;
417  str << TrackingRegionBase::print() << " eta: " << theEtaRange << " phi:" << thePhiMargin << "precise: " << thePrecise;
418  return str.str();
419 }
void setTolerance(float tolerance)
float cotLine() const
virtual float length() const =0
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
T max() const
const BoundSurface & surface() const final
GeometricSearchDet interface.
TkTrackingRegionsMargin< float > Margin
Definition: HitRCheck.h:14
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
TkTrackingRegionsMargin< float > Margin
Definition: HitZCheck.h:14
virtual Location location() const =0
Which part of the detector (barrel, endcap)
PixelRecoRange< float > Range
std::unique_ptr< HitRZCompatibility > checkRZOld(const DetLayer *layer, const Hit &outerHit, const DetLayer *outerlayer) const
bool isBarrel(GeomDetEnumerators::SubDetector m)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
constexpr float ptMin
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< BaseTrackerRecHit * > recHits(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
T y() const
Definition: PV3DBase.h:60
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const Bounds & bounds() const
Definition: Surface.h:87
auto const & tracks
cannot be loose
bool empty() const
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
T min() const
int sqr(const T &t)
OuterHitPhiPrediction phiWindow(const MagneticField &field) const
assert(be >=bs)
TrackingRegion::Hits hits(const SeedingLayerSetsHits::SeedingLayer &layer) const override
get hits from layer compatible with region constraints
T curvature(T InversePt, const MagneticField &field)
Range range(const float &radius) const override
Definition: HitZCheck.h:33
constexpr T proxim(T b, T a)
Definition: normalizedPhi.h:14
constexpr std::array< uint8_t, layerIndexSize > layer
tuple result
Definition: mps_fire.py:311
virtual float thickness() const =0
float zAtR(float r) const
int seqNum() const
Definition: DetLayer.h:35
void initEtaRange(const GlobalVector &dir, const Margin &margin)
T sqrt(T t)
Definition: SSEVec.h:19
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:61
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Double_t margin
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< MeasurementEstimator > estimator(const BarrelDetLayer *layer) const
static GlobalPoint vtxMean(const GlobalPoint &p1, const GlobalError &e1, const GlobalPoint &p2, const GlobalError &e2)
bool isEndcap(GeomDetEnumerators::SubDetector m)
bool isTrackerStrip(GeomDetEnumerators::SubDetector m)
SimpleLineRZ::Point Point
void checkTracks(reco::TrackCollection const &tracks, std::vector< bool > &mask) const override
SeedingLayerSetsHits::Hits Hits
float z() const
T mean() const
virtual const Surface::PositionType & position() const
Returns position of the surface.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
const DetLayer * detLayer() const
virtual std::string print() const
T eta() const
Definition: PV3DBase.h:73
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
virtual const BoundDisk & specificSurface() const final
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
double longitudinalBendingCorrection(double radius, double pt, const MagneticField &field)
long double T
T x() const
Definition: PV3DBase.h:59
Definition: fakeMenu.h:6
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
def cache
Definition: utilities.py:3
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)
void setTolerance(const Margin &tolerance)
Definition: HitZCheck.h:26