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