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