CMS 3D CMS Logo

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