CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelTripletLargeTipGenerator.cc
Go to the documentation of this file.
2 
7 
12 
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <vector>
18 #include <cmath>
19 #include <map>
20 
21 using namespace std;
22 using namespace ctfseeding;
23 
25 
27 
28 namespace {
29  struct LayerRZPredictions {
31  ThirdHitRZPrediction<HelixRZ> helix1, helix2;
32  MatchedHitRZCorrectionFromBending rzPositionFixup;
33  };
34 }
35 
36 static const double nSigmaRZ = 3.4641016151377544; // sqrt(12.)
37 static const double nSigmaPhi = 3.;
38 
40  : thePairGenerator(0),
41  theLayerCache(0),
42  useFixedPreFiltering(cfg.getParameter<bool>("useFixedPreFiltering")),
43  extraHitRZtolerance(cfg.getParameter<double>("extraHitRZtolerance")),
44  extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")),
45  useMScat(cfg.getParameter<bool>("useMultScattering")),
46  useBend(cfg.getParameter<bool>("useBending"))
47 {
48  theMaxElement=cfg.getParameter<unsigned int>("maxElement");
50  dphi = cfg.getParameter<double>("phiPreFiltering");
51 }
52 
54  const std::vector<SeedingLayer> &layers, LayerCacheType *layerCache)
55 {
56  thePairGenerator = pairs.clone();
57  theLayers = layers;
58  theLayerCache = layerCache;
59 }
60 
61 static bool intersect(Range &range, const Range &second)
62 {
63  if (range.first >= second.max() || range.second <= second.min())
64  return false;
65  if (range.first < second.min())
66  range.first = second.min();
67  if (range.second > second.max())
68  range.second = second.max();
69  return range.first < range.second;
70 }
71 
73  const TrackingRegion& region,
75  const edm::Event & ev,
76  const edm::EventSetup& es)
77 {
79  es.get<TrackerDigiGeometryRecord>().get(tracker);
80 
81  OrderedHitPairs pairs;
82  pairs.reserve(30000);
83  thePairGenerator->hitPairs(region,pairs,ev,es);
84  if (pairs.empty())
85  return;
86 
87  int size = theLayers.size();
88 
89  map<const DetLayer*, LayerRZPredictions> mapPred;
90  const RecHitsSortedInPhi **thirdHitMap = new const RecHitsSortedInPhi*[size];
91  for(int il = 0; il < size; il++) {
92  thirdHitMap[il] = &(*theLayerCache)(&theLayers[il], region, ev, es);
93  const DetLayer *layer = theLayers[il].detLayer();
94  LayerRZPredictions &predRZ = mapPred[layer];
95  predRZ.line.initLayer(layer);
96  predRZ.helix1.initLayer(layer);
97  predRZ.helix2.initLayer(layer);
98  predRZ.line.initTolerance(extraHitRZtolerance);
99  predRZ.helix1.initTolerance(extraHitRZtolerance);
100  predRZ.helix2.initTolerance(extraHitRZtolerance);
101  predRZ.rzPositionFixup = MatchedHitRZCorrectionFromBending(layer);
102  }
103 
104  double curv = PixelRecoUtilities::curvature(1. / region.ptMin(), es);
105 
106  for(OrderedHitPairs::const_iterator ip = pairs.begin();
107  ip != pairs.end(); ++ip) {
108 
109  GlobalPoint gp1 = ip->inner()->globalPosition();
110  GlobalPoint gp2 = ip->outer()->globalPosition();
111 
112  PixelRecoLineRZ line(gp1, gp2);
113  PixelRecoPointRZ point2(gp2.perp(), gp2.z());
114  ThirdHitPredictionFromCircle predictionRPhi(gp1, gp2, extraHitRPhitolerance);
115 
116  Range generalCurvature = predictionRPhi.curvature(region.originRBound());
117  if (!intersect(generalCurvature, Range(-curv, curv)))
118  continue;
119 
120  for(int il = 0; il < size; il++) {
121  const DetLayer *layer = theLayers[il].detLayer();
122 // bool pixelLayer = layer->subDetector() == GeomDetEnumerators::PixelBarrel ||
123 // layer->subDetector() == GeomDetEnumerators::PixelEndcap;
124  bool barrelLayer = layer->location() == GeomDetEnumerators::barrel;
125 
126  Range curvature = generalCurvature;
127  ThirdHitCorrection correction(es, region.ptMin(), layer, line, point2, useMScat);
128 
129  LayerRZPredictions &predRZ = mapPred.find(layer)->second;
130  predRZ.line.initPropagator(&line);
131 
132  HelixRZ helix;
133  Range rzRange;
134  if (useBend) {
135  // For the barrel region:
136  // swiping the helix passing through the two points across from
137  // negative to positive bending, can give us a sort of U-shaped
138  // projection onto the phi-z (barrel) or r-z plane (forward)
139  // so we checking minimum/maximum of all three possible extrema
140  //
141  // For the endcap region:
142  // Checking minimum/maximum radius of the helix projection
143  // onto an endcap plane, here we have to guard against
144  // looping tracks, when phi(delta z) gets out of control.
145  // HelixRZ::rAtZ should not follow looping tracks, but clamp
146  // to the minimum reachable r with the next-best lower |curvature|.
147  // So same procedure as for the barrel region can be applied.
148  //
149  // In order to avoid looking for potential looping tracks at all
150  // we also clamp the allowed curvature range for this layer,
151  // and potentially fail the layer entirely
152 
153  if (!barrelLayer) {
154  Range z3s = predRZ.line.detRange();
155  double z3 = z3s.first < 0 ? max(z3s.first, z3s.second)
156  : min(z3s.first, z3s.second);
157  double maxCurvature = HelixRZ::maxCurvature(&predictionRPhi,
158  gp1.z(), gp2.z(), z3);
159  if (!intersect(curvature, Range(-maxCurvature, maxCurvature)))
160  continue;
161  }
162 
163  helix = HelixRZ(&predictionRPhi, gp1.z(), gp2.z(), curvature.first);
164  HelixRZ helix2(&predictionRPhi, gp1.z(), gp2.z(), curvature.second);
165 
166  predRZ.helix1.initPropagator(&helix);
167  predRZ.helix2.initPropagator(&helix2);
168 
169  Range rzRanges[2] = { predRZ.helix1(), predRZ.helix2() };
170  rzRange.first = min(rzRanges[0].first, rzRanges[1].first);
171  rzRange.second = max(rzRanges[0].second, rzRanges[1].second);
172 
173  // if the allowed curvatures include a straight line,
174  // this can give us another extremum for allowed r/z
175  if (curvature.first * curvature.second < 0.0) {
176  Range rzLineRange = predRZ.line();
177  rzRange.first = min(rzRange.first, rzLineRange.first);
178  rzRange.second = max(rzRange.second, rzLineRange.second);
179  }
180  } else
181  rzRange = predRZ.line();
182 
183  if (rzRange.first >= rzRange.second)
184  continue;
185 
186  correction.correctRZRange(rzRange);
187 
188  Range phiRange;
189  if (useFixedPreFiltering) {
190  float phi0 = ip->outer()->globalPosition().phi();
191  phiRange = Range(phi0 - dphi, phi0 + dphi);
192  } else {
193  Range radius;
194 
195  if (barrelLayer) {
196  radius = predRZ.line.detRange();
197  if (!intersect(rzRange, predRZ.line.detSize()))
198  continue;
199  } else {
200  radius = rzRange;
201  if (!intersect(radius, predRZ.line.detSize()))
202  continue;
203  }
204 
205  Range rPhi1 = predictionRPhi(curvature, radius.first);
206  Range rPhi2 = predictionRPhi(curvature, radius.second);
207  correction.correctRPhiRange(rPhi1);
208  correction.correctRPhiRange(rPhi2);
209  rPhi1.first /= radius.first;
210  rPhi1.second /= radius.first;
211  rPhi2.first /= radius.second;
212  rPhi2.second /= radius.second;
213  phiRange = mergePhiRanges(rPhi1, rPhi2);
214  }
215 
217  vector<Hit> thirdHits = thirdHitMap[il]->hits(phiRange.min(), phiRange.max());
218 
219  MatchedHitRZCorrectionFromBending l2rzFixup(ip->outer()->det()->geographicalId());
220  MatchedHitRZCorrectionFromBending l3rzFixup = predRZ.rzPositionFixup;
221 
222  typedef vector<Hit>::const_iterator IH;
223  for (IH th=thirdHits.begin(), eh=thirdHits.end(); th < eh; ++th) {
224  GlobalPoint p3 = (*th)->globalPosition();
225  double p3_r = p3.perp();
226  double p3_z = p3.z();
227  double p3_phi = p3.phi();
228 
229  Range rangeRPhi = predictionRPhi(curvature, p3_r);
230  correction.correctRPhiRange(rangeRPhi);
231 
232  double phiErr = nSigmaPhi * sqrt((*th)->globalPositionError().phierr(p3));
233  if (!checkPhiInRange(p3_phi, rangeRPhi.first/p3_r - phiErr, rangeRPhi.second/p3_r + phiErr))
234  continue;
235 
237  Basic2DVector<double> thc(p3.x(), p3.y());
238 
239  double curv_ = predictionRPhi.curvature(thc);
240  double p2_r = point2.r(), p2_z = point2.z();
241 
242  l2rzFixup(predictionRPhi, curv_, *ip->outer(), p2_r, p2_z);
243  l3rzFixup(predictionRPhi, curv_, **th, p3_r, p3_z);
244 
245  Range rangeRZ;
246  if (useBend) {
247  HelixRZ updatedHelix(&predictionRPhi, gp1.z(), p2_z, curv_);
248  rangeRZ = predRZ.helix1(barrelLayer ? p3_r : p3_z, updatedHelix);
249  } else {
250  float tIP = predictionRPhi.transverseIP(thc);
251  PixelRecoPointRZ updatedPoint2(p2_r, p2_z);
252  PixelRecoLineRZ updatedLine(line.origin(), point2, tIP);
253  rangeRZ = predRZ.line(barrelLayer ? p3_r : p3_z, line);
254  }
255  correction.correctRZRange(rangeRZ);
256 
257  double err = nSigmaRZ * sqrt(barrelLayer
258  ? hit->globalPositionError().czz()
259  : hit->globalPositionError().rerr(p3));
260  rangeRZ.first -= err, rangeRZ.second += err;
261 
262  if (!rangeRZ.inside(barrelLayer ? p3_z : p3_r))
263  continue;
264  if (theMaxElement!=0 && result.size() >= theMaxElement){
265  result.clear();
266  edm::LogError("TooManyTriplets")<<" number of triples exceed maximum. no triplets produced.";
267  delete[] thirdHitMap;
268  return;
269  }
270  result.push_back(OrderedHitTriplet(ip->inner(), ip->outer(), *th));
271  }
272  }
273  }
274  delete[] thirdHitMap;
275 }
276 
277 bool PixelTripletLargeTipGenerator::checkPhiInRange(float phi, float phi1, float phi2) const
278 {
279  while (phi > phi2) phi -= 2. * M_PI;
280  while (phi < phi1) phi += 2. * M_PI;
281  return phi <= phi2;
282 }
283 
285  const std::pair<float, float> &r1, const std::pair<float, float> &r2) const
286 {
287  float r2Min = r2.first;
288  float r2Max = r2.second;
289  while (r1.first - r2Min > +M_PI) r2Min += 2. * M_PI, r2Max += 2. * M_PI;
290  while (r1.first - r2Min < -M_PI) r2Min -= 2. * M_PI, r2Max -= 2. * M_PI;
291  return std::make_pair(min(r1.first, r2Min), max(r1.second, r2Max));
292 }
T getParameter(std::string const &) const
virtual HitPairGenerator * clone() const =0
T perp() const
Definition: PV3DBase.h:66
virtual float ptMin() const =0
minimal pt of interest
virtual Location location() const =0
Which part of the detector (barrel, endcap)
ThirdHitPredictionFromCircle::HelixRZ HelixRZ
static const double nSigmaPhi
std::vector< Hit > hits(float phiMin, float phiMax) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
#define min(a, b)
Definition: mlp_lapack.h:161
T r() const
Radius, same as mag()
U second(std::pair< T, U > const &p)
bool checkPhiInRange(float phi, float phi1, float phi2) const
T curvature(T InversePt, const edm::EventSetup &iSetup)
const T & max(const T &a, const T &b)
virtual void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const edm::EventSetup &es)
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
tuple result
Definition: query.py:137
virtual void hitTriplets(const TrackingRegion &region, OrderedHitTriplets &trs, const edm::Event &ev, const edm::EventSetup &es)
bool first
Definition: L1TdeRCT.cc:79
static const double nSigmaRZ
std::pair< float, float > mergePhiRanges(const std::pair< float, float > &r1, const std::pair< float, float > &r2) const
PixelRecoRange< float > Range
#define M_PI
Definition: BFit3D.cc:3
static double maxCurvature(const ThirdHitPredictionFromCircle *circle, double z1, double z2, double z3)
const T & get() const
Definition: EventSetup.h:55
std::vector< ctfseeding::SeedingLayer > theLayers
virtual float originRBound() const =0
bounds the particle vertex in the transverse plane
static bool intersect(Range &range, const Range &second)
PixelTripletLargeTipGenerator(const edm::ParameterSet &cfg)
TransientTrackingRecHit::ConstRecHitPointer Hit
virtual void init(const HitPairGenerator &pairs, const std::vector< ctfseeding::SeedingLayer > &layers, LayerCacheType *layerCache)
virtual unsigned int size() const
T x() const
Definition: PV3DBase.h:56
tuple size
Write out results.
double p3[4]
Definition: TauolaWrapper.h:91
Definition: DDAxes.h:10