CMS 3D CMS Logo

PixelTripletNoTipGenerator.cc
Go to the documentation of this file.
5 
10 #include "ThirdHitZPrediction.h"
11 
14 
19 
21 template <class T>
22 T sqr(T t) {
23  return t * t;
24 }
25 
26 using namespace std;
27 
30  fieldToken_(iC.esConsumes()),
31  msmakerToken_(iC.esConsumes()),
32  extraHitRZtolerance(cfg.getParameter<double>("extraHitRZtolerance")),
33  extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")),
34  extraHitPhiToleranceForPreFiltering(cfg.getParameter<double>("extraHitPhiToleranceForPreFiltering")),
35  theNSigma(cfg.getParameter<double>("nSigma")),
36  theChi2Cut(cfg.getParameter<double>("chi2Cut")) {}
37 
39 
42  const edm::Event& ev,
43  const edm::EventSetup& es,
44  const SeedingLayerSetsHits::SeedingLayerSet& pairLayers,
45  const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers) {
46  //
47  //edm::Handle<reco::BeamSpot> bsHandle;
48  //ev.getByLabel( theBeamSpotTag, bsHandle);
49  //if(!bsHandle.isValid()) return;
50  //const reco::BeamSpot & bs = *bsHandle;
51  //double errorXY = sqrt( sqr(bs.BeamWidthX()) + sqr(bs.BeamWidthY()) );
52  //
53 
54  const GlobalPoint& bsPoint = region.origin();
55  double errorXY = region.originRBound();
56  GlobalVector shift = bsPoint - GlobalPoint(0., 0., 0.);
57 
58  OrderedHitPairs pairs;
59  pairs.reserve(30000);
60  OrderedHitPairs::const_iterator ip;
61  thePairGenerator->hitPairs(region, pairs, ev, es, pairLayers);
62 
63  if (pairs.empty())
64  return;
65 
66  const DetLayer* firstLayer = thePairGenerator->innerLayer(pairLayers).detLayer();
67  const DetLayer* secondLayer = thePairGenerator->outerLayer(pairLayers).detLayer();
68  if (!firstLayer || !secondLayer)
69  return;
70 
71  int size = thirdLayers.size();
72 
73  const RecHitsSortedInPhi** thirdHitMap = new const RecHitsSortedInPhi*[size];
74  for (int il = 0; il <= size - 1; il++) {
75  thirdHitMap[il] = &(*theLayerCache)(thirdLayers[il], region);
76  }
77 
78  const auto& field = es.getData(fieldToken_);
79  const auto& msmaker = es.getData(msmakerToken_);
80 
81  MultipleScatteringParametrisation sigma1RPhi = msmaker.parametrisation(firstLayer);
82  MultipleScatteringParametrisation sigma2RPhi = msmaker.parametrisation(secondLayer);
83 
85  for (ip = pairs.begin(); ip != pairs.end(); ip++) {
86  GlobalPoint p1((*ip).inner()->globalPosition() - shift);
87  GlobalPoint p2((*ip).outer()->globalPosition() - shift);
88 
89  ThirdHitPredictionFromInvLine predictionRPhiTMP(p1, p2);
90  double pt_p1p2 = 1. / PixelRecoUtilities::inversePt(predictionRPhiTMP.curvature(), field);
91 
92  PixelRecoPointRZ point1(p1.perp(), p1.z());
93  PixelRecoPointRZ point2(p2.perp(), p2.z());
94 
95  PixelRecoLineRZ line(point1, point2);
96  double msRPhi1 = sigma1RPhi(pt_p1p2, line.cotLine(), 0.f);
97  double msRPhi2 = sigma2RPhi(pt_p1p2, line.cotLine(), point1);
98  double sinTheta = 1 / sqrt(1 + sqr(line.cotLine()));
99  double cosTheta = fabs(line.cotLine()) / sqrt(1 + sqr(line.cotLine()));
100 
101  double p1_errorRPhi = sqrt(sqr((*ip).inner()->errorGlobalRPhi()) + sqr(msRPhi1) + sqr(errorXY));
102  double p2_errorRPhi = sqrt(sqr((*ip).outer()->errorGlobalRPhi()) + sqr(msRPhi2) + sqr(errorXY));
103 
104  ThirdHitPredictionFromInvLine predictionRPhi(p1, p2, p1_errorRPhi, p2_errorRPhi);
105 
106  for (int il = 0; il <= size - 1; il++) {
107  const DetLayer* layer = thirdLayers[il].detLayer();
108  bool barrelLayer = (layer->location() == GeomDetEnumerators::barrel);
109  MultipleScatteringParametrisation sigma3RPhi = msmaker.parametrisation(layer);
110  double msRPhi3 = sigma3RPhi(pt_p1p2, line.cotLine(), point2);
111 
112  Range rRange;
113  if (barrelLayer) {
114  const BarrelDetLayer& bl = dynamic_cast<const BarrelDetLayer&>(*layer);
115  float halfThickness = bl.surface().bounds().thickness() / 2;
116  float radius = bl.specificSurface().radius();
117  rRange = Range(radius - halfThickness, radius + halfThickness);
118  } else {
119  const ForwardDetLayer& fl = dynamic_cast<const ForwardDetLayer&>(*layer);
120  float halfThickness = fl.surface().bounds().thickness() / 2;
121  float zLayer = fl.position().z();
122  float zMin = zLayer - halfThickness;
123  float zMax = zLayer + halfThickness;
124  GlobalVector dr = p2 - p1;
125  GlobalPoint p3_a = p2 + dr * (zMin - p2.z()) / dr.z();
126  GlobalPoint p3_b = p2 + dr * (zMax - p2.z()) / dr.z();
127  if (zLayer * p3_a.z() < 0)
128  continue;
129  rRange = Range(p3_a.perp(), p3_b.perp());
130  rRange.sort();
131  }
132  double displacment = shift.perp();
133  GlobalPoint crossing1 = predictionRPhi.crossing(rRange.min() - displacment) + shift;
134  GlobalPoint crossing2 = predictionRPhi.crossing(rRange.max() + displacment) + shift;
135  float c1_phi = crossing1.phi();
136  float c2_phi = crossing2.phi();
137  if (c2_phi < c1_phi)
138  swap(c1_phi, c2_phi);
139  if (c2_phi - c1_phi > M_PI) {
140  c2_phi -= 2 * M_PI;
141  swap(c1_phi, c2_phi);
142  }
143  double extraAngle = (displacment + theNSigma * msRPhi3) / rRange.min() + extraHitPhiToleranceForPreFiltering;
144  c1_phi -= extraAngle;
145  c2_phi += extraAngle;
146  vector<Hit> thirdHits = thirdHitMap[il]->hits(c1_phi, c2_phi);
147 
148  typedef vector<Hit>::const_iterator IH;
149  for (IH th = thirdHits.begin(), eh = thirdHits.end(); th < eh; ++th) {
150  GlobalPoint p3((*th)->globalPosition() - shift);
151  double p3_errorRPhi = sqrt(sqr((*th)->errorGlobalRPhi()) + sqr(msRPhi3) + sqr(errorXY));
152 
153  predictionRPhi.add(p3, p3_errorRPhi);
154 
155  double curvature = predictionRPhi.curvature();
156 
157  ThirdHitZPrediction zPrediction((*ip).inner()->globalPosition(),
158  sqrt(sqr((*ip).inner()->errorGlobalR()) + sqr(msRPhi1 / cosTheta)),
159  sqrt(sqr((*ip).inner()->errorGlobalZ()) + sqr(msRPhi1 / sinTheta)),
160  (*ip).outer()->globalPosition(),
161  sqrt(sqr((*ip).outer()->errorGlobalR()) + sqr(msRPhi2 / cosTheta)),
162  sqrt(sqr((*ip).outer()->errorGlobalZ()) + sqr(msRPhi2 / sinTheta)),
163  curvature,
164  theNSigma);
166  zPrediction((*th)->globalPosition(), sqrt(sqr((*th)->errorGlobalR())) + sqr(msRPhi3 / cosTheta));
167 
168  double z3Hit = (*th)->globalPosition().z();
169  double z3HitError =
170  theNSigma * (sqrt(sqr((*th)->errorGlobalZ()) + sqr(msRPhi3 / sinTheta))) + extraHitRZtolerance;
171  Range hitZRange(z3Hit - z3HitError, z3Hit + z3HitError);
172  bool inside = hitZRange.hasIntersection(zRange);
173 
174  double curvatureMS = PixelRecoUtilities::curvature(1. / region.ptMin(), field);
175  bool ptCut = (predictionRPhi.curvature() - theNSigma * predictionRPhi.errorCurvature() < curvatureMS);
176  bool chi2Cut = (predictionRPhi.chi2() < theChi2Cut);
177  if (inside && ptCut && chi2Cut) {
178  if (theMaxElement != 0 && result.size() >= theMaxElement) {
179  result.clear();
180  edm::LogError("TooManyTriplets") << " number of triples exceed maximum. no triplets produced.";
181  delete[] thirdHitMap;
182  return;
183  }
184  result.push_back(OrderedHitTriplet((*ip).inner(), (*ip).outer(), *th));
185  }
186  predictionRPhi.remove(p3, p3_errorRPhi);
187  }
188  }
189  }
190  delete[] thirdHitMap;
191 }
194  const edm::EventSetup& es,
195  const HitDoublets& doublets,
196  const RecHitsSortedInPhi** thirdHitMap,
197  const std::vector<const DetLayer*>& thirdLayerDetLayer,
198  const int nThirdLayers) {
199  throw cms::Exception("Error") << "PixelTripletNoTipGenerator::hitTriplets is not implemented \n";
200 }
size
Write out results.
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual const Surface::PositionType & position() const
Returns position of the surface.
T perp() const
Definition: PV3DBase.h:69
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const BoundSurface & surface() const final
GeometricSearchDet interface.
PixelRecoRange< T > & sort()
const BoundSurface & surface() const final
The surface of the GeometricSearchDet.
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void hitTriplets(const TrackingRegion &region, OrderedHitTriplets &trs, const edm::Event &ev, const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayerSet &pairLayers, const std::vector< SeedingLayerSetsHits::SeedingLayer > &thirdLayers) override
Log< level::Error, false > LogError
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > msmakerToken_
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
T curvature(T InversePt, const MagneticField &field)
virtual float thickness() const =0
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > fieldToken_
T sqrt(T t)
Definition: SSEVec.h:19
T inversePt(T curvature, const MagneticField &field)
std::vector< Hit > hits(float phiMin, float phiMax) const
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
#define M_PI
PixelRecoRange< float > Range
std::unique_ptr< HitPairGeneratorFromLayerPair > thePairGenerator
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
static unsigned int const shift
long double T
PixelTripletNoTipGenerator(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
const Bounds & bounds() const
Definition: Surface.h:87