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