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