CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelTripletHLTGenerator.cc
Go to the documentation of this file.
2 
7 
13 #include <iostream>
14 
16 
19 
20 using namespace std;
21 using namespace ctfseeding;
22 
24  : thePairGenerator(0),
25  theLayerCache(0),
26  useFixedPreFiltering(cfg.getParameter<bool>("useFixedPreFiltering")),
27  extraHitRZtolerance(cfg.getParameter<double>("extraHitRZtolerance")),
28  extraHitRPhitolerance(cfg.getParameter<double>("extraHitRPhitolerance")),
29  useMScat(cfg.getParameter<bool>("useMultScattering")),
30  useBend(cfg.getParameter<bool>("useBending"))
31 {
32  theMaxElement=cfg.getParameter<unsigned int>("maxElement");
33  dphi = (useFixedPreFiltering) ? cfg.getParameter<double>("phiPreFiltering") : 0;
34 }
35 
36 
38  const std::vector<SeedingLayer> & layers,
39  LayerCacheType* layerCache)
40 {
41  thePairGenerator = pairs.clone();
42  theLayers = layers;
43  theLayerCache = layerCache;
44 }
45 
47  const TrackingRegion& region,
49  const edm::Event & ev,
50  const edm::EventSetup& es)
51 {
52  OrderedHitPairs pairs; pairs.reserve(30000);
53  OrderedHitPairs::const_iterator ip;
54 
55  thePairGenerator->hitPairs(region,pairs,ev,es);
56 
57  if (pairs.empty()) return;
58 
59  int size = theLayers.size();
60 
61  typedef std::vector<ThirdHitRZPrediction<PixelRecoLineRZ> > Preds;
62  Preds preds(size);
63 
64  std::vector<const RecHitsSortedInPhi *> thirdHitMap(size);
66  vector<Hit> thirdHits;
67 
68  // fill the prediciton vetor
69  for (int il=0; il!=size; ++il) {
70  thirdHitMap[il] = &(*theLayerCache)(&theLayers[il], region, ev, es);
71  ThirdHitRZPrediction<PixelRecoLineRZ> & pred = preds[il];
72  pred.initLayer(theLayers[il].detLayer());
73  pred.initTolerance(extraHitRZtolerance);
74  }
75 
76 
77  double imppar = region.originRBound();
78  double curv = PixelRecoUtilities::curvature(1/region.ptMin(), es);
79 
80  for (ip = pairs.begin(); ip != pairs.end(); ip++) {
81 
82  GlobalPoint gp1tmp = (*ip).inner()->globalPosition();
83  GlobalPoint gp2tmp = (*ip).outer()->globalPosition();
84  GlobalPoint gp1(gp1tmp.x()-region.origin().x(), gp1tmp.y()-region.origin().y(), gp1tmp.z());
85  GlobalPoint gp2(gp2tmp.x()-region.origin().x(), gp2tmp.y()-region.origin().y(), gp2tmp.z());
86 
87  PixelRecoPointRZ point1(gp1.perp(), gp1.z());
88  PixelRecoPointRZ point2(gp2.perp(), gp2.z());
89  PixelRecoLineRZ line(point1, point2);
90  ThirdHitPredictionFromInvParabola predictionRPhi(gp1,gp2,imppar,curv,extraHitRPhitolerance);
91  ThirdHitPredictionFromInvParabola predictionRPhitmp(gp1tmp,gp2tmp,imppar+region.origin().perp(),curv,extraHitRPhitolerance);
92 
93 
94  for (int il=0; il!=size; ++il) {
95  const DetLayer * layer = theLayers[il].detLayer();
96 // bool pixelLayer = ( layer->subDetector() == GeomDetEnumerators::PixelBarrel
97 // || layer->subDetector() == GeomDetEnumerators::PixelEndcap);
98  bool barrelLayer = (layer->location() == GeomDetEnumerators::barrel);
99 
100  ThirdHitCorrection correction(es, region.ptMin(), layer, line, point2, useMScat, useBend);
101 
102  ThirdHitRZPrediction<PixelRecoLineRZ> & predictionRZ = preds[il];
103 
104  predictionRZ.initPropagator(&line);
105  Range rzRange = predictionRZ();
106 
107  correction.correctRZRange(rzRange);
108  Range phiRange;
109  if (useFixedPreFiltering) {
110  float phi0 = (*ip).outer()->globalPosition().phi();
111  phiRange = Range(phi0-dphi,phi0+dphi);
112  }
113  else {
114  Range radius;
115  if (barrelLayer) {
116  radius = predictionRZ.detRange();
117  } else {
118  radius = Range(
119  max(rzRange.min(), predictionRZ.detSize().min()),
120  min(rzRange.max(), predictionRZ.detSize().max()) );
121  }
122  if (radius.empty()) continue;
123  Range rPhi1m = predictionRPhitmp(radius.max(), -1);
124  Range rPhi1p = predictionRPhitmp(radius.max(), 1);
125  Range rPhi2m = predictionRPhitmp(radius.min(), -1);
126  Range rPhi2p = predictionRPhitmp(radius.min(), 1);
127  Range rPhi1 = rPhi1m.sum(rPhi1p);
128  Range rPhi2 = rPhi2m.sum(rPhi2p);
129  correction.correctRPhiRange(rPhi1);
130  correction.correctRPhiRange(rPhi2);
131  rPhi1.first /= radius.max();
132  rPhi1.second /= radius.max();
133  rPhi2.first /= radius.min();
134  rPhi2.second /= radius.min();
135  phiRange = mergePhiRanges(rPhi1,rPhi2);
136  }
137 
138 // LayerHitMapLoop thirdHits =
139 // pixelLayer ? thirdHitMap[il]->loop(phiRange, rzRange) :
140 // thirdHitMap[il]->loop();
141 
142  thirdHits.clear();
143  thirdHitMap[il]->hits(phiRange.min(),phiRange.max(), thirdHits);
144 
145  static float nSigmaRZ = std::sqrt(12.f);
146  static float nSigmaPhi = 3.f;
147 
148  typedef vector<Hit>::const_iterator IH;
149  for (IH th=thirdHits.begin(), eh=thirdHits.end(); th !=eh; ++th) {
150 
151  if (theMaxElement!=0 && result.size() >= theMaxElement){
152  result.clear();
153  edm::LogError("TooManyTriplets")<<" number of triples exceed maximum. no triplets produced.";
154  return;
155  }
156  const Hit& hit = (*th);
157  GlobalPoint point(hit->globalPosition().x()-region.origin().x(),
158  hit->globalPosition().y()-region.origin().y(),
159  hit->globalPosition().z() );
160  float p3_r = point.perp();
161  float p3_z = point.z();
162  float p3_phi = point.phi();
163 
164  if (barrelLayer) {
165  Range allowedZ = predictionRZ(p3_r);
166  correction.correctRZRange(allowedZ);
167 
168  float zErr = nSigmaRZ * std::sqrt(float(hit->globalPositionError().czz()));
169  Range hitRange(p3_z-zErr, p3_z+zErr);
170  Range crossingRange = allowedZ.intersection(hitRange);
171  if (crossingRange.empty()) continue;
172  } else {
173  Range allowedR = predictionRZ(p3_z);
174  correction.correctRZRange(allowedR);
175  float rErr = nSigmaRZ * std::sqrt(float(hit->globalPositionError().rerr( hit->globalPosition())));
176  Range hitRange(p3_r-rErr, p3_r+rErr);
177  Range crossingRange = allowedR.intersection(hitRange);
178  if (crossingRange.empty()) continue;
179  }
180 
181  float phiErr = nSigmaPhi*std::sqrt(float(hit->globalPositionError().phierr(hit->globalPosition())));
182  for (int icharge=-1; icharge <=1; icharge+=2) {
183  Range rangeRPhi = predictionRPhi(p3_r, icharge);
184  correction.correctRPhiRange(rangeRPhi);
185  if (checkPhiInRange(p3_phi, rangeRPhi.first/p3_r-phiErr, rangeRPhi.second/p3_r+phiErr)) {
186  result.push_back( OrderedHitTriplet( (*ip).inner(), (*ip).outer(), hit));
187  break;
188  }
189  }
190  }
191  }
192  }
193 
194 }
195 
196 bool PixelTripletHLTGenerator::checkPhiInRange(float phi, float phi1, float phi2) const
197 {
198  while (phi > phi2) phi -= Geom::ftwoPi();
199  while (phi < phi1) phi += Geom::ftwoPi();
200  return ( (phi1 <= phi) && (phi <= phi2) );
201 }
202 
204  const std::pair<float,float>& r1, const std::pair<float,float>& r2) const
205 {
206  float r2_min=r2.first;
207  float r2_max=r2.second;
208  while (r1.first-r2_min > Geom::fpi()) { r2_min += Geom::ftwoPi(); r2_max += Geom::ftwoPi();}
209  while (r1.first-r2_min < -Geom::fpi()) { r2_min -= Geom::ftwoPi(); r2_max -= Geom::ftwoPi(); }
210 
211  return std::make_pair(min(r1.first,r2_min),max(r1.second,r2_max));
212 }
T getParameter(std::string const &) const
std::vector< ctfseeding::SeedingLayer > theLayers
virtual HitPairGenerator * clone() const =0
void initPropagator(const Propagator *propagator)
T perp() const
Definition: PV3DBase.h:66
virtual float ptMin() const =0
minimal pt of interest
virtual GlobalPoint origin() const =0
T max() const
void initLayer(const DetLayer *layer)
virtual Location location() const =0
Which part of the detector (barrel, endcap)
static const double nSigmaPhi
PixelRecoRange< T > sum(const PixelRecoRange< T > &r) const
T y() const
Definition: PV3DBase.h:57
#define min(a, b)
Definition: mlp_lapack.h:161
float fpi()
Definition: Pi.h:35
virtual void init(const HitPairGenerator &pairs, const std::vector< ctfseeding::SeedingLayer > &layers, LayerCacheType *layerCache)
std::pair< float, float > mergePhiRanges(const std::pair< float, float > &r1, const std::pair< float, float > &r2) 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
double f[11][100]
static const double nSigmaRZ
PixelRecoRange< float > Range
PixelTripletHLTGenerator(const edm::ParameterSet &cfg)
virtual float originRBound() const =0
bounds the particle vertex in the transverse plane
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
bool checkPhiInRange(float phi, float phi1, float phi2) const
TransientTrackingRecHit::ConstRecHitPointer Hit
virtual unsigned int size() const
T x() const
Definition: PV3DBase.h:56
virtual void hitTriplets(const TrackingRegion &region, OrderedHitTriplets &trs, const edm::Event &ev, const edm::EventSetup &es)
tuple size
Write out results.
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
float ftwoPi()
Definition: Pi.h:36
Definition: DDAxes.h:10