CMS 3D CMS Logo

HitQuadrupletGeneratorFromLayerPairForPhotonConversion.cc
Go to the documentation of this file.
3 
7 
13 
16 
17 using namespace GeomDetEnumerators;
18 using namespace std;
20 
21 //#define mydebug_QSeed
22 
24 template <class T>
25 inline T sqr(T t) {
26  return t * t;
27 }
28 
35 
37  unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int max)
38  : theLayerCache(*layerCache), theOuterLayer(outer), theInnerLayer(inner), theMaxElement(max) {
39  ss = new std::stringstream;
40 }
41 
44  const Layers &layers,
45  const edm::Event &event,
46  const edm::EventSetup &es) {
47  ss->str("");
48 
49  typedef OrderedHitPair::InnerRecHit InnerHit;
50  typedef OrderedHitPair::OuterRecHit OuterHit;
52 
53  Layer innerLayerObj = layers[theInnerLayer];
54  Layer outerLayerObj = layers[theOuterLayer];
55 
56  size_t totCountP2 = 0, totCountP1 = 0, totCountM2 = 0, totCountM1 = 0, selCount = 0;
57 #ifdef mydebug_QSeed
58  (*ss) << "In " << innerLayerObj.name() << " Out " << theOuterLayer.name() << std::endl;
59 #endif
60 
61  /*get hit sorted in phi for each layer: NB: doesn't apply any region cut*/
62  const RecHitsSortedInPhi &innerHitsMap = theLayerCache(innerLayerObj, region, es);
63  if (innerHitsMap.empty())
64  return;
65 
66  const RecHitsSortedInPhi &outerHitsMap = theLayerCache(outerLayerObj, region, es);
67  if (outerHitsMap.empty())
68  return;
69  /*----------------*/
70 
71  /*This object will check the compatibility of the his in phi among the two layers. */
72  //InnerDeltaPhi deltaPhi(*innerLayerObj.detLayer(), region, es);
73 
74  vector<RecHitsSortedInPhi::Hit> innerHits;
75  // float outerPhimin, outerPhimax;
76  float innerPhimin, innerPhimax;
77  float maxDeltaPhi = 1.; //sguazz
78  //float maxDeltaPhi=1.;
79 
80  RecHitsSortedInPhi::Range outerHits = outerHitsMap.all();
81 
83  for (RecHitsSortedInPhi::HitIter oh = outerHits.first; oh != outerHits.second; ++oh) {
84  RecHitsSortedInPhi::Hit ohit = (*oh).hit();
85  GlobalPoint oPos = ohit->globalPosition();
86 
87  totCountP2++;
88  const HitRZCompatibility *checkRZ = region.checkRZ(outerLayerObj.detLayer(), ohit, es);
89  for (nextoh = oh + 1; nextoh != outerHits.second; ++nextoh) {
90  RecHitsSortedInPhi::Hit nohit = (*nextoh).hit();
91  GlobalPoint noPos = nohit->globalPosition();
92 
93 #ifdef mydebug_QSeed
94  (*ss) << "\toPos " << oPos << " r " << oPos.perp() << " phi " << oPos.phi() << " cotTheta "
95  << oPos.z() / oPos.perp() << std::endl;
96  (*ss) << "\tnoPos " << noPos << " r " << noPos.perp() << " phi " << noPos.phi() << " cotTheta "
97  << noPos.z() / noPos.perp() << std::endl;
98  (*ss) << "\tDeltaPhi " << reco::deltaPhi(noPos.barePhi(), oPos.barePhi()) << std::endl;
99 #endif
100 
101  if (fabs(reco::deltaPhi(noPos.barePhi(), oPos.barePhi())) > maxDeltaPhi)
102  break;
103 
104  totCountM2++;
105 
106  /*Check the compatibility of the ohit with the eta of the seeding track*/
107  if (failCheckRZCompatibility(nohit, *outerLayerObj.detLayer(), checkRZ, region))
108  continue;
109 
110  /*
111  //Do I need this? it uses a compatibility that probably I wouldn't
112  //Removing for the time being
113 
114  PixelRecoRange<float> phiRange = deltaPhi( oPos.perp(), oPos.phi(), oPos.z(), nSigmaPhi*(ohit->errorGlobalRPhi()));
115  if (phiRange.empty()) continue;
116  */
117 
118  /*Get only the inner hits compatible with the conversion region*/
119  innerPhimin = ohit->globalPosition().phi();
120  innerPhimax = nohit->globalPosition().phi();
121  // checkPhiRange(innerPhimin,innerPhimax);
122 
123  innerHits.clear();
124  innerHitsMap.hits(innerPhimin, innerPhimax, innerHits);
125 
126 #ifdef mydebug_QSeed
127  (*ss) << "\tiphimin, iphimax " << innerPhimin << " " << innerPhimax << std::endl;
128 #endif
129 
130  const HitRZCompatibility *checkRZb = region.checkRZ(innerLayerObj.detLayer(), ohit, es);
131  const HitRZCompatibility *checkRZc = region.checkRZ(innerLayerObj.detLayer(), nohit, es);
132 
133  /*Loop on inner hits*/
134  vector<RecHitsSortedInPhi::Hit>::const_iterator ieh = innerHits.end();
135  for (vector<RecHitsSortedInPhi::Hit>::const_iterator ih = innerHits.begin(); ih < ieh; ++ih) {
136  RecHitsSortedInPhi::Hit ihit = *ih;
137 
138 #ifdef mydebug_QSeed
139  GlobalPoint innPos = (*ih)->globalPosition();
140  (*ss) << "\toPos " << oPos << " r " << oPos.perp() << " phi " << oPos.phi() << " cotTheta "
141  << oPos.z() / oPos.perp() << std::endl;
142  (*ss) << "\tnoPos " << noPos << " r " << noPos.perp() << " phi " << noPos.phi() << " cotTheta "
143  << noPos.z() / noPos.perp() << std::endl;
144  (*ss) << "\tinnPos " << innPos << " r " << innPos.perp() << " phi " << innPos.phi() << " cotTheta "
145  << innPos.z() / innPos.perp() << std::endl;
146 #endif
147 
148  totCountP1++;
149 
150  /*Check the compatibility of the ihit with the two outer hits*/
151  if (failCheckRZCompatibility(ihit, *innerLayerObj.detLayer(), checkRZb, region) ||
152  failCheckRZCompatibility(ihit, *innerLayerObj.detLayer(), checkRZc, region))
153  continue;
154 
155  for (vector<RecHitsSortedInPhi::Hit>::const_iterator nextih = ih + 1; nextih != ieh; ++nextih) {
156  RecHitsSortedInPhi::Hit nihit = *nextih;
157 
158 #ifdef mydebug_QSeed
159  GlobalPoint ninnPos = (*nextih)->globalPosition();
160  (*ss) << "\toPos " << oPos << " r " << oPos.perp() << " phi " << oPos.phi() << " cotTheta "
161  << oPos.z() / oPos.perp() << std::endl;
162  (*ss) << "\tnoPos " << noPos << " r " << noPos.perp() << " phi " << noPos.phi() << " cotTheta "
163  << noPos.z() / noPos.perp() << std::endl;
164  (*ss) << "\tinnPos " << innPos << " r " << innPos.perp() << " phi " << innPos.phi() << " cotTheta "
165  << innPos.z() / innPos.perp() << std::endl;
166  (*ss) << "\tninnPos " << ninnPos << " r " << ninnPos.perp() << " phi " << ninnPos.phi() << " cotTheta "
167  << ninnPos.z() / ninnPos.perp() << std::endl;
168 #endif
169 
170  totCountM1++;
171 
172  /*Check the compatibility of the nihit with the two outer hits*/
173  if (failCheckRZCompatibility(nihit, *innerLayerObj.detLayer(), checkRZb, region) ||
174  failCheckRZCompatibility(nihit, *innerLayerObj.detLayer(), checkRZc, region))
175  continue;
176 
177  /*Sguazz modifica qui*/
178  if (failCheckSlopeTest(ohit, nohit, ihit, nihit, region))
179  continue;
180 
181  if (theMaxElement != 0 && result.size() >= theMaxElement) {
182  result.clear();
183  edm::LogError("TooManyQuads") << "number of Quad combinations exceed maximum, no quads produced";
184  delete checkRZ;
185  delete checkRZb;
186  delete checkRZc;
187 #ifdef mydebug_QSeed
188  (*ss) << "In " << innerLayerObj.name() << " Out " << outerLayerObj.name() << "\tP2 " << totCountP2
189  << "\tM2 " << totCountM2 << "\tP1 " << totCountP1 << "\tM1 " << totCountM1 << "\tsel " << selCount
190  << std::endl;
191  std::cout << (*ss).str();
192 #endif
193  return;
194  }
195  selCount++;
196  result.push_back(OrderedHitPair(ihit, ohit));
197  result.push_back(OrderedHitPair(nihit, nohit));
198  //#ifdef mydebug_QSeed
199  //(*ss) << "sizeOfresul " << result.size() << std::endl;
200  //#endif
201  }
202  }
203  delete checkRZb;
204  delete checkRZc;
205  }
206  delete checkRZ;
207  }
208 #ifdef mydebug_QSeed
209  (*ss) << "In " << innerLayerObj.name() << " Out " << outerLayerObj.name() << "\tP2 " << totCountP2 << "\tM2 "
210  << totCountM2 << "\tP1 " << totCountP1 << "\tM1 " << totCountM1 << "\tsel " << selCount << std::endl;
211  std::cout << (*ss).str();
212 #endif
213 }
214 
216  const DetLayer &layer,
217  const HitRZCompatibility *checkRZ,
218  const TrackingRegion &region) {
219  if (!checkRZ) {
220 #ifdef mydebug_QSeed
221  (*ss) << "*******\nNo valid checkRZ\n*******" << std::endl;
222 #endif
223  return true;
224  }
225 
226  static const float nSigmaRZ = std::sqrt(12.f);
227  float r_reduced = std::sqrt(sqr(hit->globalPosition().x() - region.origin().x()) +
228  sqr(hit->globalPosition().y() - region.origin().y()));
229  Range allowed;
230  Range hitRZ;
231  if (layer.location() == barrel) {
232  allowed = checkRZ->range(r_reduced);
233  float zErr = nSigmaRZ * hit->errorGlobalZ();
234  hitRZ = Range(hit->globalPosition().z() - zErr, hit->globalPosition().z() + zErr);
235  } else {
236  allowed = checkRZ->range(hit->globalPosition().z());
237  float rErr = nSigmaRZ * hit->errorGlobalR();
238  hitRZ = Range(r_reduced - rErr, r_reduced + rErr);
239  }
240  Range crossRange = allowed.intersection(hitRZ);
241 
242 #ifdef mydebug_QSeed
243  (*ss) << "\n\t\t allowed Range " << allowed.min() << " \t, " << allowed.max() << "\n\t\t hitRz Range "
244  << hitRZ.min() << " \t, " << hitRZ.max() << "\n\t\t Cross Range " << crossRange.min() << " \t, "
245  << crossRange.max() << std::endl;
246  if (!crossRange.empty())
247  (*ss) << "\n\t\t !!!!ACCEPTED!!! \n\n";
248 #endif
249 
250  return crossRange.empty();
251 }
252 
254  const RecHitsSortedInPhi::Hit &nohit,
255  const RecHitsSortedInPhi::Hit &ihit,
256  const RecHitsSortedInPhi::Hit &nihit,
257  const TrackingRegion &region) {
258  double r[5], z[5], ez[5];
259  // double pr[2], pz[2], e2pz[2], mr[2], mz[2], e2mz[2];
260 
261  //
262  //Hits
263  r[0] = ohit->globalPosition().perp();
264  z[0] = ohit->globalPosition().z();
265  ez[0] = getEffectiveErrorOnZ(ohit, region);
266  //
267  r[1] = nohit->globalPosition().perp();
268  z[1] = nohit->globalPosition().z();
269  ez[1] = getEffectiveErrorOnZ(nohit, region);
270  //
271  r[2] = nihit->globalPosition().perp();
272  z[2] = nihit->globalPosition().z();
273  ez[2] = getEffectiveErrorOnZ(nihit, region);
274  //
275  r[3] = ihit->globalPosition().perp();
276  z[3] = ihit->globalPosition().z();
277  ez[3] = getEffectiveErrorOnZ(ihit, region);
278  //
279  //R (r) ordering of the 4 hit arrays
280  bubbleSortVsR(4, r, z, ez);
281  //
282  //Vertex
283  r[4] = region.origin().perp();
284  z[4] = region.origin().z();
285  double vError = region.originZBound();
286  if (vError > 15.)
287  vError = 1.;
288  ez[4] = 3. * vError;
289 
290  //
291  //Sequence of checks
292  //
293  //Inner segment == vertex
294  double rInn = r[4];
295  double zInnMin = z[4] - ez[4];
296  double zInnMax = z[4] + ez[4];
297  //
298  // Int == 2, Out == 3
299  double rOut = r[3];
300  double zOutMin = z[3] - ez[3];
301  double zOutMax = z[3] + ez[3];
302  double rInt = r[2];
303  double zIntMin = z[2] - ez[2];
304  double zIntMax = z[2] + ez[2];
305  if (failCheckSegmentZCompatibility(rInn, zInnMin, zInnMax, rInt, zIntMin, zIntMax, rOut, zOutMin, zOutMax))
306  return true;
307  //
308  // Int == 1, Out == 2 (with updated limits)
309  rOut = rInt;
310  zOutMin = zIntMin;
311  zOutMax = zIntMax;
312  rInt = r[1];
313  zIntMin = z[1] - ez[1];
314  zIntMax = z[1] + ez[1];
315  if (failCheckSegmentZCompatibility(rInn, zInnMin, zInnMax, rInt, zIntMin, zIntMax, rOut, zOutMin, zOutMax))
316  return true;
317  //
318  // Int == 0, Out == 1 (with updated limits)
319  rOut = rInt;
320  zOutMin = zIntMin;
321  zOutMax = zIntMax;
322  rInt = r[0];
323  zIntMin = z[0] - ez[0];
324  zIntMax = z[0] + ez[0];
325  if (failCheckSegmentZCompatibility(rInn, zInnMin, zInnMax, rInt, zIntMin, zIntMax, rOut, zOutMin, zOutMax))
326  return true;
327 
328  //
329  // Test is ok!!!
330  return false;
331 }
332 
334  int size, double *ax, double *ay, double *e2y, double &p0, double &e2p0, double &p1) {
335  //#include "verySimpleFit.icc"
336  return 0;
337 }
338 
341  //
342  //Fit-wise the effective error on Z is approximately the sum in quadrature of the error on Z
343  //and the error on R correctly projected by using hit-vertex direction
344 
345  double sqrProjFactor =
346  sqr((hit->globalPosition().z() - region.origin().z()) / (hit->globalPosition().perp() - region.origin().perp()));
347  return (hit->globalPositionError().czz() + sqrProjFactor * hit->globalPositionError().rerr(hit->globalPosition()));
348 }
349 
351  const TrackingRegion &region) {
352  //
353  //Fit-wise the effective error on Z is approximately the sum in quadrature of the error on Z
354  //and the error on R correctly projected by using hit-vertex direction
355  double sqrProjFactor =
356  sqr((hit->globalPosition().z() - region.origin().z()) / (hit->globalPosition().perp() - region.origin().perp()));
357  double effErr =
358  sqrt(hit->globalPositionError().czz() + sqrProjFactor * hit->globalPositionError().rerr(hit->globalPosition()));
359  if (effErr > 2.) {
360  effErr *= 1.8; //Single Side error is strip length * sqrt( 12.) = 3.46
361  //empirically found that the error on ss hits value it is already twice as large (two sigmas)!
362  //Multiply by sqrt(12.)/2.=1.73 to have effErr equal to the strip lenght (1.8 to allow for some margin)
363  //effErr*=2.5; //Used in some tests
364  } else {
365  effErr *= 2.; //Tight //Double side... allowing for 2 sigma variation
366  //effErr*=5.; //Loose //Double side... allowing for 2 sigma variation
367  }
368  return effErr;
369 }
370 
371 void HitQuadrupletGeneratorFromLayerPairForPhotonConversion::bubbleSortVsR(int n, double *ar, double *az, double *aez) {
372  bool swapped = true;
373  int j = 0;
374  double tmpr, tmpz, tmpez;
375  while (swapped) {
376  swapped = false;
377  j++;
378  for (int i = 0; i < n - j; i++) {
379  if (ar[i] > ar[i + 1]) {
380  tmpr = ar[i];
381  ar[i] = ar[i + 1];
382  ar[i + 1] = tmpr;
383  tmpz = az[i];
384  az[i] = az[i + 1];
385  az[i + 1] = tmpz;
386  tmpez = aez[i];
387  aez[i] = aez[i + 1];
388  aez[i + 1] = tmpez;
389  swapped = true;
390  }
391  }
392  }
393 }
394 
396  double &zInnMin,
397  double &zInnMax,
398  double &rInt,
399  double &zIntMin,
400  double &zIntMax,
401  double &rOut,
402  double &zOutMin,
403  double &zOutMax) {
404  //
405  // Check the compatibility in z of an INTermediate segment between an INNer segment and an OUTer segment;
406  // when true is returned zIntMin and zIntMax are replaced with allowed range values
407 
408  //Left side
409  double zLeft = getZAtR(rInn, zInnMin, rInt, rOut, zOutMin);
410  if (zIntMax < zLeft)
411  return true;
412  //Right side
413  double zRight = getZAtR(rInn, zInnMax, rInt, rOut, zOutMax);
414  if (zIntMin > zRight)
415  return true;
416  if (zIntMin < zLeft && zIntMax < zRight) {
417  zIntMax = zLeft;
418  return false;
419  }
420  if (zIntMin > zLeft && zIntMax > zRight) {
421  zIntMax = zRight;
422  return false;
423  }
424 
425  //Segment is fully contained
426  return false;
427 }
428 
430  double &rInn, double &zInn, double &r, double &rOut, double &zOut) {
431  // z - zInn r - rInn r - rInn
432  // ----------- = ----------- ==> z = zInn + (zOut - zInn) * -----------
433  // zOut - zInn rOut - rInn rOut - rInn
434 
435  return zInn + (zOut - zInn) * (r - rInn) / (rOut - rInn);
436 }
size
Write out results.
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
std::vector< Hit > hits(float phiMin, float phiMax) const
T perp() const
Definition: PV3DBase.h:69
GlobalPoint const & origin() const
virtual Location location() const =0
Which part of the detector (barrel, endcap)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T y() const
Definition: PV3DBase.h:60
SeedingHitSet::ConstRecHitPointer InnerRecHit
Definition: OrderedHitPair.h:9
void hitPairs(const TrackingRegion &reg, OrderedHitPairs &prs, const Layers &layers, const edm::Event &ev, const edm::EventSetup &es)
T min() const
T barePhi() const
Definition: PV3DBase.h:65
virtual Range range(const float &rORz) const =0
std::vector< HitWithPhi >::const_iterator HitIter
T sqrt(T t)
Definition: SSEVec.h:19
std::pair< HitIter, HitIter > Range
T z() const
Definition: PV3DBase.h:61
bool failCheckSegmentZCompatibility(double &rInn, double &zInnMin, double &zInnMax, double &rInt, double &zIntMin, double &zIntMax, double &rOut, double &zOutMin, double &zOutMax)
unsigned int size() const override
virtual HitRZCompatibility * checkRZ(const DetLayer *layer, const Hit &outerHit, const edm::EventSetup &iSetup, const DetLayer *outerlayer=0, float lr=0, float gz=0, float dr=0, float dz=0) const =0
double f[11][100]
const std::string & name() const
HitQuadrupletGeneratorFromLayerPairForPhotonConversion(unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int max=0)
bool failCheckSlopeTest(const RecHitsSortedInPhi::Hit &ohit, const RecHitsSortedInPhi::Hit &nohit, const RecHitsSortedInPhi::Hit &ihit, const RecHitsSortedInPhi::Hit &nihit, const TrackingRegion &region)
float originZBound() const
bounds the particle vertex in the longitudinal plane
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
double getEffectiveErrorOnZ(const RecHitsSortedInPhi::Hit &hit, const TrackingRegion &region)
double verySimpleFit(int size, double *ax, double *ay, double *e2y, double &p0, double &e2p0, double &p1)
const DetLayer * detLayer() const
double p1[4]
Definition: TauolaWrapper.h:89
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
double getZAtR(double &rInn, double &zInn, double &r, double &rOut, double &zOut)
bool failCheckRZCompatibility(const RecHitsSortedInPhi::Hit &hit, const DetLayer &layer, const HitRZCompatibility *checkRZ, const TrackingRegion &region)
long double T
T x() const
Definition: PV3DBase.h:59
SeedingHitSet::ConstRecHitPointer OuterRecHit
Definition: OrderedHitPair.h:8
Definition: event.py:1
double getSqrEffectiveErrorOnZ(const RecHitsSortedInPhi::Hit &hit, const TrackingRegion &region)