CMS 3D CMS Logo

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