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>
4 
10 
22 
25 
33 
34 template <class T> T sqr( T t) {return t*t;}
35 
36 
37 using namespace PixelRecoUtilities;
38 using namespace std;
39 using namespace ctfseeding;
40 
41 void RectangularEtaPhiTrackingRegion::
42  initEtaRange( const GlobalVector & dir, const Margin& margin)
43 {
44  float eta = dir.eta();
45  theEtaRange = Range(eta-margin.left(), eta+margin.right());
46 }
47 
48 HitRZCompatibility* RectangularEtaPhiTrackingRegion::
49 checkRZOld(const DetLayer* layer, const TrackingRecHit *outerHit,const edm::EventSetup& iSetup) const
50 {
52  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
53 
54  bool isBarrel = (layer->location() == GeomDetEnumerators::barrel);
55  GlobalPoint ohit = tracker->idToDet(outerHit->geographicalId())->surface().toGlobal(outerHit->localPosition());
56  float outerred_r = sqrt( sqr(ohit.x()-origin().x())+sqr(ohit.y()-origin().y()) );
57  //PixelRecoPointRZ outer(ohit.perp(), ohit.z());
58  PixelRecoPointRZ outer(outerred_r, ohit.z());
59 
60  float zMinOrigin = origin().z() - originZBound();
61  float zMaxOrigin = origin().z() + originZBound();
62 
63  if (!thePrecise) {
64  double vcotMin = (outer.z() > zMaxOrigin) ?
65  (outer.z()-zMaxOrigin)/(outer.r()+originRBound())
66  : (outer.z()-zMaxOrigin)/(outer.r()-originRBound());
67  double vcotMax = (outer.z() > zMinOrigin) ?
68  (outer.z()-zMinOrigin)/(outer.r()-originRBound())
69  : (outer.z()-zMinOrigin)/(outer.r()+originRBound());
70  float cotRight = max(vcotMin,(double) sinh(theEtaRange.min()));
71  float cotLeft = min(vcotMax, (double) sinh(theEtaRange.max()));
72  return new HitEtaCheck( isBarrel, outer, cotLeft, cotRight);
73  }
74  float hitZErr = 0.;
75  float hitRErr = 0.;
76 
77  PixelRecoPointRZ outerL, outerR;
78  if (layer->location() == GeomDetEnumerators::barrel) {
79  outerL = PixelRecoPointRZ(outer.r(), outer.z()-hitZErr);
80  outerR = PixelRecoPointRZ(outer.r(), outer.z()+hitZErr);
81  } else if (outer.z() > 0) {
82  outerL = PixelRecoPointRZ(outer.r()+hitRErr, outer.z());
83  outerR = PixelRecoPointRZ(outer.r()-hitRErr, outer.z());
84  } else {
85  outerL = PixelRecoPointRZ(outer.r()-hitRErr, outer.z());
86  outerR = PixelRecoPointRZ(outer.r()+hitRErr, outer.z());
87  }
88  //CHECK
89  MultipleScatteringParametrisation oSigma(layer,iSetup);
90  float cotThetaOuter = sinh(theEtaRange.mean());
91  float sinThetaOuter = 1/sqrt(1+sqr(cotThetaOuter));
92  float outerZscatt = 3*oSigma(ptMin(),cotThetaOuter) / sinThetaOuter;
93 
94  PixelRecoLineRZ boundL(outerL, sinh(theEtaRange.max()));
95  PixelRecoLineRZ boundR(outerR, sinh(theEtaRange.min()));
96  float zMinLine = boundL.zAtR(0.)-outerZscatt;
97  float zMaxLine = boundR.zAtR(0.)+outerZscatt;
98  PixelRecoPointRZ vtxL(0.,max(zMinLine, zMinOrigin));
99  PixelRecoPointRZ vtxR(0.,min(zMaxLine, zMaxOrigin));
100  PixelRecoPointRZ vtxMean(0.,(vtxL.z()+vtxR.z())/2.);
101  //CHECK
102  MultipleScatteringParametrisation iSigma(layer,iSetup);
103  float innerScatt = 3 * iSigma(ptMin(),vtxMean, outer);
104 
105  SimpleLineRZ leftLine( vtxL, outerL);
106  SimpleLineRZ rightLine( vtxR, outerR);
107 
108  HitRZConstraint rzConstraint(leftLine, rightLine);
109  float cotTheta = fabs(leftLine.cotLine()+rightLine.cotLine())/2;
110 
111 // float bendR = longitudinalBendingCorrection(outer.r(),ptMin());
112 
113  if (isBarrel) {
114  float sinTheta = 1/sqrt(1+sqr(cotTheta));
115  float corrZ = innerScatt/sinTheta + hitZErr;
116  return new HitZCheck(rzConstraint, HitZCheck::Margin(corrZ,corrZ));
117  } else {
118  float cosTheta = 1/sqrt(1+sqr(1/cotTheta));
119  float corrR = innerScatt/cosTheta + hitRErr;
120  return new HitRCheck( rzConstraint, HitRCheck::Margin(corrR,corrR));
121  }
122 }
123 
125  RectangularEtaPhiTrackingRegion::estimator(const BarrelDetLayer* layer,const edm::EventSetup& iSetup) const
126 {
127 
128  // det dimensions
129  float halfLength = layer->surface().bounds().length()/2;
130  float halfThickness = layer->surface().bounds().thickness()/2;
131  float z0 = layer->position().z();
132  float radius = layer->specificSurface().radius();
133 
134  // det ranges
135  Range detRWindow (radius-halfThickness, radius+halfThickness);
136  Range detZWindow(z0-halfLength,z0+halfLength);
137 
138  // z prediction, skip if not intersection
139  HitZCheck zPrediction(rzConstraint());
140  Range hitZWindow = zPrediction.range(detRWindow.min()).
141  intersection(detZWindow);
142  if (hitZWindow.empty()) return 0;
143 
144  // phi prediction
145  OuterHitPhiPrediction phiPrediction = phiWindow(iSetup);
146 
147  //
148  // optional corrections for tolerance (mult.scatt, error, bending)
149  //
151  if (thePrecise) {
152  float cotTheta = (hitZWindow.mean()-origin().z()) / radius;
153  float sinTheta = 1/sqrt(1+sqr(cotTheta));
154  MultipleScatteringParametrisation msSigma(layer,iSetup);
155  float scatt = 3 * msSigma(ptMin(), cotTheta);
156  float bendR = longitudinalBendingCorrection(radius,ptMin(),iSetup);
157 
158  float hitErrRPhi = 0.;
159  float hitErrZ = 0.;
160  float corrPhi = (scatt+ hitErrRPhi)/radius;
161  float corrZ = scatt/sinTheta + bendR*fabs(cotTheta) + hitErrZ;
162 
163  phiPrediction.setTolerance(OuterHitPhiPrediction::Margin(corrPhi,corrPhi));
164  zPrediction.setTolerance(HitZCheck::Margin(corrZ,corrZ));
165 
166  //
167  // hit ranges in det
168  //
169  OuterHitPhiPrediction::Range phi1 = phiPrediction(detRWindow.min());
170  OuterHitPhiPrediction::Range phi2 = phiPrediction(detRWindow.max());
171  phiRange = Range( min(phi1.min(),phi2.min()), max(phi1.max(),phi2.max()));
172  Range w1 = zPrediction.range(detRWindow.min());
173  Range w2 = zPrediction.range(detRWindow.max());
174  hitZWindow = Range(
175  min(w1.min(),w2.min()), max(w1.max(),w2.max())).intersection(detZWindow);
176  }
177  else {
178  phiRange = phiPrediction(detRWindow.mean());
179  }
180 
181  return new OuterEstimator(
182  OuterDetCompatibility( layer, phiRange, detRWindow, hitZWindow),
183  OuterHitCompatibility( phiPrediction, zPrediction ),
184  iSetup);
185 }
186 
188 RectangularEtaPhiTrackingRegion::estimator(const ForwardDetLayer* layer,const edm::EventSetup& iSetup) const
189 {
190 
191  // det dimensions, ranges
192  float halfThickness = layer->surface().bounds().thickness()/2;
193  float zLayer = layer->position().z() ;
194  Range detZWindow( zLayer-halfThickness, zLayer+halfThickness);
195  Range detRWindow( layer->specificSurface().innerRadius(),
196  layer->specificSurface().outerRadius());
197 
198  // r prediction, skip if not intersection
199  HitRCheck rPrediction(rzConstraint());
200  Range hitRWindow = rPrediction.range(zLayer).intersection(detRWindow);
201  if (hitRWindow.empty()) return 0;
202 
203  // phi prediction
204  OuterHitPhiPrediction phiPrediction = phiWindow(iSetup);
205  OuterHitPhiPrediction::Range phiRange = phiPrediction(detRWindow.max());
206 
207  //
208  // optional corrections for tolerance (mult.scatt, error, bending)
209  //
210  if (thePrecise) {
211  float cotTheta = (detZWindow.mean()-origin().z())/hitRWindow.mean();
212  float cosTheta = cotTheta/sqrt(1+sqr(cotTheta));
213  MultipleScatteringParametrisation msSigma(layer,iSetup);
214  float scatt = 3 * msSigma(ptMin(),cotTheta);
215  float bendR = longitudinalBendingCorrection(hitRWindow.max(),ptMin(),iSetup);
216  float hitErrRPhi = 0.;
217  float hitErrR = 0.;
218  float corrPhi = (scatt+hitErrRPhi)/detRWindow.min();
219  float corrR = scatt/fabs(cosTheta) + bendR + hitErrR;
220 
221  phiPrediction.setTolerance(OuterHitPhiPrediction::Margin(corrPhi,corrPhi));
222  rPrediction.setTolerance(HitRCheck::Margin(corrR,corrR));
223 
224  //
225  // hit ranges in det
226  //
227  Range w1,w2;
228  if (zLayer > 0) {
229  w1 = rPrediction.range(detZWindow.min());
230  w2 = rPrediction.range(detZWindow.max());
231  } else {
232  w1 = rPrediction.range(detZWindow.max());
233  w2 = rPrediction.range(detZWindow.min());
234  }
235  hitRWindow = Range(w1.min(),w2.max()).intersection(detRWindow);
236  }
237 
238  return new OuterEstimator(
239  OuterDetCompatibility( layer, phiRange, hitRWindow, detZWindow),
240  OuterHitCompatibility( phiPrediction, rPrediction),iSetup );
241 }
242 
243 
244 
246  RectangularEtaPhiTrackingRegion::phiWindow(const edm::EventSetup& iSetup) const
247 {
248  float phi0 = direction().phi();
249  return OuterHitPhiPrediction(
250  OuterHitPhiPrediction::Range( phi0-thePhiMargin.left(),
251  phi0+thePhiMargin.left()),
252  OuterHitPhiPrediction::Range( curvature(invPtRange().min(),iSetup),
253  curvature(invPtRange().max(),iSetup)),
254  originRBound());
255 }
256 
257 
259  RectangularEtaPhiTrackingRegion::rzConstraint() const
260 {
261  HitRZConstraint::Point pLeft,pRight;
262  float zMin = origin().z() - originZBound();
263  float zMax = origin().z() + originZBound();
264  float rMin = -originRBound();
265  float rMax = originRBound();
266  if(theEtaRange.max() > 0) {
267  pRight = HitRZConstraint::Point(rMin,zMax);
268  } else {
269  pRight = HitRZConstraint::Point(rMax,zMax);
270  }
271  if (theEtaRange.min() > 0.) {
272  pLeft = HitRZConstraint::Point(rMax, zMin);
273  } else {
274  pLeft = HitRZConstraint::Point(rMin, zMin);
275  }
276  return HitRZConstraint(pLeft, sinh(theEtaRange.min()),
277  pRight, sinh(theEtaRange.max()) );
278 }
279 
280 TrackingRegion::Hits RectangularEtaPhiTrackingRegion::hits(
281  const edm::Event& ev,
282  const edm::EventSetup& es,
283  const SeedingLayer* layer) const
284 {
285 
286 
287  //ESTIMATOR
289 
290  const DetLayer * detLayer = layer->detLayer();
291  OuterEstimator * est = 0;
292 
293  bool measurementMethod = false;
294  if ( theMeasurementTrackerUsage > 0.5) measurementMethod = true;
295  if ( theMeasurementTrackerUsage > -0.5 &&
296  !(detLayer->subDetector() == GeomDetEnumerators::PixelBarrel ||
297  detLayer->subDetector() == GeomDetEnumerators::PixelEndcap) ) measurementMethod = true;
298 
299  if(measurementMethod) {
301  es.get<IdealMagneticFieldRecord>().get(field);
302  const MagneticField * magField = field.product();
303 
304  const GlobalPoint vtx = origin();
305  GlobalVector dir = direction();
306 
307  if (detLayer->subDetector() == GeomDetEnumerators::PixelBarrel || (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::barrel)){
308  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
309  est = estimator(&bl,es);
310  } else if (detLayer->subDetector() == GeomDetEnumerators::PixelEndcap || (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::endcap)) {
311  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
312  est = estimator(&fl,es);
313  }
314 
315  EtaPhiMeasurementEstimator etaPhiEstimator ((theEtaRange.second-theEtaRange.first)/2.,
316  (thePhiMargin.left()+thePhiMargin.right())/2.);
317  MeasurementEstimator & findDetAndHits = etaPhiEstimator;
318  if (est){
319  LogDebug("RectangularEtaPhiTrackingRegion")<<"use pixel specific estimator.";
320  findDetAndHits =*est;
321  }
322  else{
323  LogDebug("RectangularEtaPhiTrackingRegion")<<"use generic etat phi estimator.";
324  }
325 
326  // TSOS
327  float phi = dir.phi();
328  Surface::RotationType rot( sin(phi), -cos(phi), 0,
329  0, 0, -1,
330  cos(phi), sin(phi), 0);
331 
332  Plane::PlanePointer surface = Plane::build(GlobalPoint(0.,0.,0.), rot);
333  //TrajectoryStateOnSurface tsos(lpar, *surface, magField);
334 
335  FreeTrajectoryState fts( GlobalTrajectoryParameters(vtx, dir, 1, magField) );
336  TrajectoryStateOnSurface tsos(fts, *surface);
337 
338  // propagator
339  StraightLinePropagator prop( magField, alongMomentum);
340 
341  edm::ESHandle<MeasurementTracker> measurementTrackerESH;
342  es.get<CkfComponentsRecord>().get(theMeasurementTrackerName, measurementTrackerESH);
343  const MeasurementTracker * measurementTracker = measurementTrackerESH.product();
344  measurementTracker->update(ev);
345 
346  LayerMeasurements lm(measurementTracker);
347 
348  vector<TrajectoryMeasurement> meas = lm.measurements(*detLayer, tsos, prop, findDetAndHits);
349  typedef vector<TrajectoryMeasurement>::const_iterator IM;
350  for (IM im = meas.begin(); im != meas.end(); im++) {
351  TrajectoryMeasurement::ConstRecHitPointer ptrHit = im->recHit();
352  if (ptrHit->isValid()) result.push_back( ptrHit );
353  }
354 
355  LogDebug("RectangularEtaPhiTrackingRegion")<<" found "<< meas.size()<<" minus one measurements on layer: "<<detLayer->subDetector();
356 
357  } else {
358  //
359  // temporary solution
360  //
361  if (detLayer->location() == GeomDetEnumerators::barrel) {
362  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
363  est = estimator(&bl,es);
364  } else {
365  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
366  est = estimator(&fl,es);
367  }
368  if (!est) return result;
369 
370  TrackingRegion::Hits layerHits = layer->hits(ev,es);
371  for (TrackingRegion::Hits::const_iterator ih= layerHits.begin(); ih != layerHits.end(); ih++) {
372  if ( est->hitCompatibility()(ih->get()) ) {
373  result.push_back( *ih );
374  }
375  }
376  }
377 
378  delete est;
379  return result;
380 }
381 
383  std::ostringstream str;
384  str << TrackingRegionBase::print()
385  <<" eta: "<<theEtaRange<<" phi:"<<thePhiMargin
386  << "precise: "<<thePrecise;
387  return str.str();
388 }
389 
#define LogDebug(id)
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
const DetLayer * detLayer() const
Definition: SeedingLayer.cc:80
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
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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
#define min(a, b)
Definition: mlp_lapack.h:161
T min() const
T eta() const
virtual float thickness() const =0
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
static GlobalPoint vtxMean(const GlobalPoint &p1, const GlobalError &e1, const GlobalPoint &p2, const GlobalError &e2)
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
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