CMS 3D CMS Logo

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