CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RectangularEtaPhiTrackingRegion.cc
Go to the documentation of this file.
1 #include <cmath>
3 
4 #include "OuterEstimator.h"
5 
11 
23 
26 
35 
36 
37 #include<iostream>
38 
39 template <class T> T sqr( T t) {return t*t;}
40 
41 
42 using namespace PixelRecoUtilities;
43 using namespace std;
44 using namespace ctfseeding;
45 
46 void RectangularEtaPhiTrackingRegion:: initEtaRange( const GlobalVector & dir, const Margin& margin) {
47  float eta = dir.eta();
48  theEtaRange = Range(eta-margin.left(), eta+margin.right());
49  theLambdaRange=Range(std::sinh(theEtaRange.min()),std::sinh(theEtaRange.max()));
50  theMeanLambda = std::sinh(theEtaRange.mean());
51 }
52 
53 HitRZCompatibility* RectangularEtaPhiTrackingRegion::
54 checkRZOld(const DetLayer* layer, const TrackingRecHit *outerHit,const edm::EventSetup& iSetup) const
55 {
57  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
58 
59  bool isBarrel = (layer->location() == GeomDetEnumerators::barrel);
60  GlobalPoint ohit = tracker->idToDet(outerHit->geographicalId())->surface().toGlobal(outerHit->localPosition());
61  float outerred_r = sqrt( sqr(ohit.x()-origin().x())+sqr(ohit.y()-origin().y()) );
62  //PixelRecoPointRZ outer(ohit.perp(), ohit.z());
63  PixelRecoPointRZ outer(outerred_r, ohit.z());
64 
65  float zMinOrigin = origin().z() - originZBound();
66  float zMaxOrigin = origin().z() + originZBound();
67 
68  if (!thePrecise) {
69  float vcotMin = (outer.z() > zMaxOrigin) ?
70  (outer.z()-zMaxOrigin)/(outer.r()+originRBound())
71  : (outer.z()-zMaxOrigin)/(outer.r()-originRBound());
72  float vcotMax = (outer.z() > zMinOrigin) ?
73  (outer.z()-zMinOrigin)/(outer.r()-originRBound())
74  : (outer.z()-zMinOrigin)/(outer.r()+originRBound());
75  float cotRight = std::max(vcotMin,theLambdaRange.min());
76  float cotLeft = std::min(vcotMax, theLambdaRange.max());
77  return new HitEtaCheck( isBarrel, outer, cotLeft, cotRight);
78  }
79  float hitZErr = 0.;
80  float hitRErr = 0.;
81 
82  PixelRecoPointRZ outerL, outerR;
83  if (layer->location() == GeomDetEnumerators::barrel) {
84  outerL = PixelRecoPointRZ(outer.r(), outer.z()-hitZErr);
85  outerR = PixelRecoPointRZ(outer.r(), outer.z()+hitZErr);
86  } else if (outer.z() > 0) {
87  outerL = PixelRecoPointRZ(outer.r()+hitRErr, outer.z());
88  outerR = PixelRecoPointRZ(outer.r()-hitRErr, outer.z());
89  } else {
90  outerL = PixelRecoPointRZ(outer.r()-hitRErr, outer.z());
91  outerR = PixelRecoPointRZ(outer.r()+hitRErr, outer.z());
92  }
93  //CHECK
94  MultipleScatteringParametrisation oSigma(layer,iSetup);
95  float cotThetaOuter = theMeanLambda;
96  float sinThetaOuter = 1/std::sqrt(1+sqr(cotThetaOuter));
97  float outerZscatt = 3.f*oSigma(ptMin(),cotThetaOuter) / sinThetaOuter;
98 
99  PixelRecoLineRZ boundL(outerL, theLambdaRange.max());
100  PixelRecoLineRZ boundR(outerR, theLambdaRange.min());
101  float zMinLine = boundL.zAtR(0.)-outerZscatt;
102  float zMaxLine = boundR.zAtR(0.)+outerZscatt;
103  PixelRecoPointRZ vtxL(0.,max(zMinLine, zMinOrigin));
104  PixelRecoPointRZ vtxR(0.,min(zMaxLine, zMaxOrigin));
105  PixelRecoPointRZ vtxMean(0.,(vtxL.z()+vtxR.z())*0.5f);
106  //CHECK
107  MultipleScatteringParametrisation iSigma(layer,iSetup);
108  float innerScatt = 3.f * iSigma(ptMin(),vtxMean, outer);
109 
110  SimpleLineRZ leftLine( vtxL, outerL);
111  SimpleLineRZ rightLine( vtxR, outerR);
112 
113  HitRZConstraint rzConstraint(leftLine, rightLine);
114  float cotTheta = std::abs(leftLine.cotLine()+rightLine.cotLine())*0.5f;
115 
116 // float bendR = longitudinalBendingCorrection(outer.r(),ptMin());
117 
118  // std::cout << "RectangularEtaPhiTrackingRegion " << outer.r()<<','<< outer.z() << " " << innerScatt << " " << cotTheta << " " << hitZErr << std::endl;
119 
120  if (isBarrel) {
121  float sinTheta = 1/std::sqrt(1+sqr(cotTheta));
122  float corrZ = innerScatt/sinTheta + hitZErr;
123  return new HitZCheck(rzConstraint, HitZCheck::Margin(corrZ,corrZ));
124  } else {
125  float cosTheta = 1/std::sqrt(1+sqr(1/cotTheta));
126  float corrR = innerScatt/cosTheta + hitRErr;
127  return new HitRCheck( rzConstraint, HitRCheck::Margin(corrR,corrR));
128  }
129 }
130 
132  RectangularEtaPhiTrackingRegion::estimator(const BarrelDetLayer* layer,const edm::EventSetup& iSetup) const
133 {
134 
135  // det dimensions
136  float halfLength = 0.5f*layer->surface().bounds().length();
137  float halfThickness = 0.5f*layer->surface().bounds().thickness();
138  float z0 = layer->position().z();
139  float radius = layer->specificSurface().radius();
140 
141  // det ranges
142  Range detRWindow (radius-halfThickness, radius+halfThickness);
143  Range detZWindow(z0-halfLength,z0+halfLength);
144 
145  // z prediction, skip if not intersection
146  HitZCheck zPrediction(rzConstraint());
147  Range hitZWindow = zPrediction.range(detRWindow.min()).
148  intersection(detZWindow);
149  if (hitZWindow.empty()) return 0;
150 
151  // phi prediction
152  OuterHitPhiPrediction phiPrediction = phiWindow(iSetup);
153 
154  //
155  // optional corrections for tolerance (mult.scatt, error, bending)
156  //
158  if (thePrecise) {
159  float cotTheta = (hitZWindow.mean()-origin().z()) / radius;
160  float sinTheta = 1/std::sqrt(1+sqr(cotTheta));
161  MultipleScatteringParametrisation msSigma(layer,iSetup);
162  float scatt = 3.f * msSigma(ptMin(), cotTheta);
163  float bendR = longitudinalBendingCorrection(radius,ptMin(),iSetup);
164 
165  float hitErrRPhi = 0.;
166  float hitErrZ = 0.;
167  float corrPhi = (scatt+ hitErrRPhi)/radius;
168  float corrZ = scatt/sinTheta + bendR*std::abs(cotTheta) + hitErrZ;
169 
170  phiPrediction.setTolerance(OuterHitPhiPrediction::Margin(corrPhi,corrPhi));
171  zPrediction.setTolerance(HitZCheck::Margin(corrZ,corrZ));
172 
173  //
174  // hit ranges in det
175  //
176  OuterHitPhiPrediction::Range phi1 = phiPrediction(detRWindow.min());
177  OuterHitPhiPrediction::Range phi2 = phiPrediction(detRWindow.max());
178  phiRange = Range( std::min(phi1.min(),phi2.min()), std::max(phi1.max(),phi2.max()));
179  Range w1 = zPrediction.range(detRWindow.min());
180  Range w2 = zPrediction.range(detRWindow.max());
181  hitZWindow = Range(std::min(w1.min(),w2.min()), std::max(w1.max(),w2.max())).intersection(detZWindow);
182  }
183  else {
184  phiRange = phiPrediction(detRWindow.mean());
185  }
186 
187  return new OuterEstimator(
188  OuterDetCompatibility( layer, phiRange, detRWindow, hitZWindow),
189  OuterHitCompatibility( phiPrediction, zPrediction ),
190  iSetup);
191 }
192 
194 RectangularEtaPhiTrackingRegion::estimator(const ForwardDetLayer* layer,const edm::EventSetup& iSetup) const
195 {
196 
197  // det dimensions, ranges
198  float halfThickness = 0.5f*layer->surface().bounds().thickness();
199  float zLayer = layer->position().z() ;
200  Range detZWindow( zLayer-halfThickness, zLayer+halfThickness);
201  Range detRWindow( layer->specificSurface().innerRadius(),
202  layer->specificSurface().outerRadius());
203 
204  // r prediction, skip if not intersection
205  HitRCheck rPrediction(rzConstraint());
206  Range hitRWindow = rPrediction.range(zLayer).intersection(detRWindow);
207  if (hitRWindow.empty()) return 0;
208 
209  // phi prediction
210  OuterHitPhiPrediction phiPrediction = phiWindow(iSetup);
211  OuterHitPhiPrediction::Range phiRange = phiPrediction(detRWindow.max());
212 
213  //
214  // optional corrections for tolerance (mult.scatt, error, bending)
215  //
216  if (thePrecise) {
217  float cotTheta = (detZWindow.mean()-origin().z())/hitRWindow.mean();
218  float cosTheta = cotTheta/std::sqrt(1+sqr(cotTheta));
219  MultipleScatteringParametrisation msSigma(layer,iSetup);
220  float scatt = 3.f * msSigma(ptMin(),cotTheta);
221  float bendR = longitudinalBendingCorrection(hitRWindow.max(),ptMin(),iSetup);
222  float hitErrRPhi = 0.;
223  float hitErrR = 0.;
224  float corrPhi = (scatt+hitErrRPhi)/detRWindow.min();
225  float corrR = scatt/std::abs(cosTheta) + bendR + hitErrR;
226 
227  phiPrediction.setTolerance(OuterHitPhiPrediction::Margin(corrPhi,corrPhi));
228  rPrediction.setTolerance(HitRCheck::Margin(corrR,corrR));
229 
230  //
231  // hit ranges in det
232  //
233  Range w1,w2;
234  if (zLayer > 0) {
235  w1 = rPrediction.range(detZWindow.min());
236  w2 = rPrediction.range(detZWindow.max());
237  } else {
238  w1 = rPrediction.range(detZWindow.max());
239  w2 = rPrediction.range(detZWindow.min());
240  }
241  hitRWindow = Range(w1.min(),w2.max()).intersection(detRWindow);
242  }
243 
244  return new OuterEstimator(
245  OuterDetCompatibility( layer, phiRange, hitRWindow, detZWindow),
246  OuterHitCompatibility( phiPrediction, rPrediction),iSetup );
247 }
248 
249 
250 
252  RectangularEtaPhiTrackingRegion::phiWindow(const edm::EventSetup& iSetup) const
253 {
254  float phi0 = phiDirection();
255  return OuterHitPhiPrediction(
256  OuterHitPhiPrediction::Range( phi0-thePhiMargin.left(),
257  phi0+thePhiMargin.right()),
258  OuterHitPhiPrediction::Range( curvature(invPtRange().min(),iSetup),
259  curvature(invPtRange().max(),iSetup)),
260  originRBound());
261 }
262 
263 
265  RectangularEtaPhiTrackingRegion::rzConstraint() const {
266  HitRZConstraint::Point pLeft,pRight;
267  float zMin = origin().z() - originZBound();
268  float zMax = origin().z() + originZBound();
269  float rMin = -originRBound();
270  float rMax = originRBound();
271  if(theEtaRange.max() > 0) {
272  pRight = HitRZConstraint::Point(rMin,zMax);
273  } else {
274  pRight = HitRZConstraint::Point(rMax,zMax);
275  }
276  if (theEtaRange.min() > 0.) {
277  pLeft = HitRZConstraint::Point(rMax, zMin);
278  } else {
279  pLeft = HitRZConstraint::Point(rMin, zMin);
280  }
281  return HitRZConstraint(pLeft, theLambdaRange.min(),
282  pRight,theLambdaRange.max()
283  );
284 }
285 
286 TrackingRegion::Hits RectangularEtaPhiTrackingRegion::hits(
287  const edm::Event& ev,
288  const edm::EventSetup& es,
289  const SeedingLayer* layer) const
290 {
291  return hits_(ev, es, *layer, [&](const SeedingLayer& l) -> TrackingRegion::Hits { return l.hits(ev, es);});
292 }
293 
294 TrackingRegion::Hits RectangularEtaPhiTrackingRegion::hits(
295  const edm::Event& ev,
296  const edm::EventSetup& es,
297  const SeedingLayerSetsHits::SeedingLayer& layer) const {
298  return hits_(ev, es, layer, [](const SeedingLayerSetsHits::SeedingLayer& l) -> TrackingRegion::Hits { return l.hits(); });
299 }
300 
301 template <typename T, typename F>
302 TrackingRegion::Hits RectangularEtaPhiTrackingRegion::hits_(
303  const edm::Event& ev,
304  const edm::EventSetup& es,
305  const T& layer,
306  F hitGetter) const
307 {
308 
309 
310  //ESTIMATOR
312 
313  const DetLayer * detLayer = layer.detLayer();
314  OuterEstimator * est = 0;
315 
316  bool measurementMethod = false;
317  if ( theMeasurementTrackerUsage > 0.5) measurementMethod = true;
318  if ( theMeasurementTrackerUsage > -0.5 &&
319  !(detLayer->subDetector() == GeomDetEnumerators::PixelBarrel ||
320  detLayer->subDetector() == GeomDetEnumerators::PixelEndcap) ) measurementMethod = true;
321 
322  if(measurementMethod) {
324  es.get<IdealMagneticFieldRecord>().get(field);
325  const MagneticField * magField = field.product();
326 
327  const GlobalPoint vtx = origin();
328  GlobalVector dir = direction();
329 
330  if (detLayer->subDetector() == GeomDetEnumerators::PixelBarrel || (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::barrel)){
331  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
332  est = estimator(&bl,es);
333  } else if (detLayer->subDetector() == GeomDetEnumerators::PixelEndcap || (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::endcap)) {
334  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
335  est = estimator(&fl,es);
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;
344  }
345  else{
346  LogDebug("RectangularEtaPhiTrackingRegion")<<"use generic etat phi estimator.";
347  }
348 
349  // TSOS
350  float phi = phiDirection();
351  // std::cout << "dir " << direction().x()/direction().perp() <<','<< direction().y()/direction().perp() << " " << sin(phi) <<','<<cos(phi)<< std::endl;
352  Surface::RotationType rot( sin(phi), -cos(phi), 0,
353  0, 0, -1,
354  cos(phi), sin(phi), 0);
355 
356  Plane::PlanePointer surface = Plane::build(GlobalPoint(0.,0.,0.), rot);
357  //TrajectoryStateOnSurface tsos(lpar, *surface, magField);
358 
359  FreeTrajectoryState fts( GlobalTrajectoryParameters(vtx, dir, 1, magField) );
360  TrajectoryStateOnSurface tsos(fts, *surface);
361 
362  // propagator
363  StraightLinePropagator prop( magField, alongMomentum);
364 
366  ev.getByLabel(edm::InputTag(theMeasurementTrackerName), mte);
367  LayerMeasurements lm(mte->measurementTracker(), *mte);
368 
369  vector<TrajectoryMeasurement> meas = lm.measurements(*detLayer, tsos, prop, *findDetAndHits);
370  result.reserve(meas.size());
371  for (auto const & im : meas) {
372  auto ptrHit = im.recHit();
373  if (ptrHit->isValid()) result.push_back( std::move(ptrHit) );
374  }
375 
376  LogDebug("RectangularEtaPhiTrackingRegion")<<" found "<< meas.size()<<" minus one measurements on layer: "<<detLayer->subDetector();
377  // std::cout << "RectangularEtaPhiTrackingRegion" <<" found "<< meas.size()<<" minus one measurements on layer: "<<detLayer->subDetector() << std::endl;
378 
379  } else {
380  //
381  // temporary solution
382  //
383  if (detLayer->location() == GeomDetEnumerators::barrel) {
384  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
385  est = estimator(&bl,es);
386  } else {
387  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
388  est = estimator(&fl,es);
389  }
390  if (!est) return result;
391 
392  TrackingRegion::Hits layerHits = hitGetter(layer);
393  result.reserve(layerHits.size());
394  for (auto const & ih : layerHits) {
395  if ( est->hitCompatibility()(ih.get()) ) {
396  result.push_back( std::move(ih) );
397  }
398  }
399  }
400 
401  // std::cout << "RectangularEtaPhiTrackingRegion hits " << result.size() << std::endl;
402  delete est;
403  return result;
404 }
405 
407  std::ostringstream str;
408  str << TrackingRegionBase::print()
409  <<" eta: "<<theEtaRange<<" phi:"<<thePhiMargin
410  << "precise: "<<thePrecise;
411  return str.str();
412 }
413 
#define LogDebug(id)
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual float length() const =0
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
T max() const
virtual Location location() const =0
Which part of the detector (barrel, endcap)
const OuterHitCompatibility & hitCompatibility() const
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
virtual const BoundSurface & surface() const GCC11_FINAL
GeometricSearchDet interface.
const Bounds & bounds() const
Definition: Surface.h:128
T min() const
T eta() const
tuple field
Definition: statics.py:62
virtual float thickness() const =0
float zAtR(float r) const
T curvature(T InversePt, const edm::EventSetup &iSetup)
const T & max(const T &a, const T &b)
virtual const BoundSurface & surface() const GCC11_FINAL
The surface of the GeometricSearchDet.
T sqrt(T t)
Definition: SSEVec.h:48
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
SimpleLineRZ::Point Point
void hits(const edm::Event &ev, const edm::EventSetup &es, Hits &) const
PixelRecoRange< float > Range
float z() const
double longitudinalBendingCorrection(double radius, double pt, const edm::EventSetup &iSetup)
virtual const Surface::PositionType & position() const
Returns position of the surface.
std::vector< Hit > Hits
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual std::string print() const
virtual const BoundDisk & specificSurface() const GCC11_FINAL
T eta() const
Definition: PV3DBase.h:76
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
void setTolerance(const Margin &tolerance)
DetId geographicalId() const
dbl *** dir
Definition: mlp_gen.cc:35
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
virtual const BoundCylinder & specificSurface() const GCC11_FINAL
Extension of the interface.
Definition: DDAxes.h:10