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 SeedingLayerSetsHits::SeedingLayer& layer) const {
291 
292  //ESTIMATOR
293 
294  const DetLayer * detLayer = layer.detLayer();
295  OuterEstimator * est = 0;
296 
297  bool measurementMethod = false;
298  if(theMeasurementTrackerUsage == UseMeasurementTracker::kAlways) measurementMethod = true;
299  else if(theMeasurementTrackerUsage == UseMeasurementTracker::kForSiStrips &&
300  !(detLayer->subDetector() == GeomDetEnumerators::PixelBarrel ||
301  detLayer->subDetector() == GeomDetEnumerators::PixelEndcap) ) measurementMethod = true;
302 
303  if(measurementMethod) {
305  es.get<IdealMagneticFieldRecord>().get(field);
306  const MagneticField * magField = field.product();
307 
308  const GlobalPoint vtx = origin();
309  GlobalVector dir = direction();
310 
311  if (detLayer->subDetector() == GeomDetEnumerators::PixelBarrel || (!theUseEtaPhi && detLayer->location() == GeomDetEnumerators::barrel)){
312  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
313  est = estimator(&bl,es);
314  } else if (detLayer->subDetector() == GeomDetEnumerators::PixelEndcap || (!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;
325  }
326  else{
327  LogDebug("RectangularEtaPhiTrackingRegion")<<"use generic etat phi estimator.";
328  }
329 
330  // TSOS
331  float phi = phiDirection();
332  // std::cout << "dir " << direction().x()/direction().perp() <<','<< direction().y()/direction().perp() << " " << sin(phi) <<','<<cos(phi)<< std::endl;
333  Surface::RotationType rot( sin(phi), -cos(phi), 0,
334  0, 0, -1,
335  cos(phi), sin(phi), 0);
336 
337  Plane::PlanePointer surface = Plane::build(GlobalPoint(0.,0.,0.), rot);
338  //TrajectoryStateOnSurface tsos(lpar, *surface, magField);
339 
340  FreeTrajectoryState fts( GlobalTrajectoryParameters(vtx, dir, 1, magField) );
341  TrajectoryStateOnSurface tsos(fts, *surface);
342 
343  // propagator
344  StraightLinePropagator prop( magField, alongMomentum);
345 
346  LayerMeasurements lm(theMeasurementTracker->measurementTracker(), *theMeasurementTracker);
347 
349  lm.recHits(hits,*detLayer, tsos, prop, *findDetAndHits);
350  /*
351  { // old code
352  vector<TrajectoryMeasurement> meas = lm.measurements(*detLayer, tsos, prop, *findDetAndHits);
353  auto n=0UL;
354  for (auto const & im : meas)
355  if(im.recHit()->isValid()) ++n;
356  assert(n==hits.size());
357  // std::cout << "old/new " << n <<'/'<<hits.size() << std::endl;
358  }
359  */
360 
361  result.reserve(hits.size());
362  for (auto h : hits) {
363  cache.emplace_back(h);
364  result.emplace_back(h);
365  }
366 
367  LogDebug("RectangularEtaPhiTrackingRegion")<<" found "<< hits.size()<<" minus one measurements on layer: "<<detLayer->subDetector();
368  // std::cout << "RectangularEtaPhiTrackingRegion" <<" found "<< meas.size()<<" minus one measurements on layer: "<<detLayer->subDetector() << std::endl;
369 
370  } else {
371  //
372  // temporary solution
373  //
374  if (detLayer->location() == GeomDetEnumerators::barrel) {
375  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*detLayer);
376  est = estimator(&bl,es);
377  } else {
378  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*detLayer);
379  est = estimator(&fl,es);
380  }
381  if (!est) return result;
382 
383  auto layerHits = layer.hits();
384  result.reserve(layerHits.size());
385  for (auto && ih : layerHits) {
386  if ( est->hitCompatibility()(*ih) ) {
387  result.emplace_back( std::move(ih) );
388  }
389  }
390  }
391 
392  // std::cout << "RectangularEtaPhiTrackingRegion hits " << result.size() << std::endl;
393  delete est;
394 
395  return result;
396 }
397 
399  std::ostringstream str;
400  str << TrackingRegionBase::print()
401  <<" eta: "<<theEtaRange<<" phi:"<<thePhiMargin
402  << "precise: "<<thePrecise;
403  return str.str();
404 }
405 
#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
std::vector< BaseTrackerRecHit * > SimpleHitContainer
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
virtual float thickness() const =0
float zAtR(float r) const
bool recHits(SimpleHitContainer &result, const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) 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]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
SimpleLineRZ::Point Point
PixelRecoRange< float > Range
SeedingLayerSetsHits::Hits Hits
float z() const
double longitudinalBendingCorrection(double radius, double pt, const edm::EventSetup &iSetup)
virtual const Surface::PositionType & position() const
Returns position of the surface.
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
const DetLayer * detLayer() const
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