CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HitPairGeneratorFromLayerPairForPhotonConversion.cc
Go to the documentation of this file.
3 
7 
13 
16 
17 using namespace GeomDetEnumerators;
18 using namespace std;
20 
21 // #define mydebug_Seed
22 
24 
25 namespace {
26  template<class T> inline T sqr( T t) {return t*t;}
27 }
28 
29 
36 
38  unsigned int inner,
39  unsigned int outer,
40  LayerCacheType* layerCache,
41  unsigned int nSize,
42  unsigned int max)
43  :
44  theLayerCache(*layerCache), theOuterLayer(outer), theInnerLayer(inner), theMaxElement(max) {
45 
46 }
47 
50  const edm::Event& event, const edm::EventSetup& es)
51 {
52  auto oldSize = result.size();
53  auto maxNum = result.size()+theMaxElement;
54 
55 #ifdef mydebug_Seed
56  ss.str("");
57 #endif
58 
59  typedef OrderedHitPair::InnerRecHit InnerHit;
60  typedef OrderedHitPair::OuterRecHit OuterHit;
62 
63  Layer innerLayerObj = innerLayer();
64  Layer outerLayerObj = outerLayer();
65 
66 #ifdef mydebug_Seed
67  ss << "In " << innerLayerObj.name() << " Out " << outerLayerObj.name() << std::endl;
68 #endif
69 
70  if(!checkBoundaries(*innerLayerObj.detLayer(),convRegion,40.,60.)) return; //FIXME, the maxSearchR(Z) are not optimized
71  if(!checkBoundaries(*outerLayerObj.detLayer(),convRegion,50.,60.)) return; //FIXME, the maxSearchR(Z) are not optimized
72 
73  /*get hit sorted in phi for each layer: NB: doesn't apply any region cut*/
74  const RecHitsSortedInPhi & innerHitsMap = theLayerCache(innerLayerObj, region, event, es);
75  if (innerHitsMap.empty()) return;
76 
77  const RecHitsSortedInPhi& outerHitsMap = theLayerCache(outerLayerObj, region, event, es);
78  if (outerHitsMap.empty()) return;
79  /*----------------*/
80 
81  /*This object will check the compatibility of the his in phi among the two layers. */
82  //InnerDeltaPhi deltaPhi(innerLayerObj.detLayer(), region, es);
83 
84  static const float nSigmaRZ = std::sqrt(12.f);
85  // static const float nSigmaPhi = 3.f;
86  vector<RecHitsSortedInPhi::Hit> innerHits, outerHits;
87  float outerPhimin, outerPhimax;
88  float innerPhimin, innerPhimax;
89 
90  /*Getting only the Hits in the outer layer that are compatible with the conversion region*/
91  if(!getPhiRange(outerPhimin,outerPhimax,*outerLayerObj.detLayer(),convRegion,es)) return;
92  outerHitsMap.hits( outerPhimin, outerPhimax, outerHits);
93 
94 #ifdef mydebug_Seed
95  ss << "\tophimin, ophimax " << outerPhimin << " " << outerPhimax << std::endl;
96 #endif
97 
98  /* loop on outer hits*/
99  for (vector<RecHitsSortedInPhi::Hit>::const_iterator oh = outerHits.begin(); oh!= outerHits.end(); ++oh) {
100  RecHitsSortedInPhi::Hit ohit = (*oh);
101 #ifdef mydebug_Seed
102  GlobalPoint oPos = ohit->globalPosition();
103 
104  ss << "\toPos " << oPos << " r " << oPos.perp() << " phi " << oPos.phi() << " cotTheta " << oPos.z()/oPos.perp() << std::endl;
105 #endif
106 
107  /*Check the compatibility of the ohit with the eta of the seeding track*/
108  if(checkRZCompatibilityWithSeedTrack(ohit,*outerLayerObj.detLayer(),convRegion)) 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  const HitRZCompatibility *checkRZ = region.checkRZ(innerLayerObj.detLayer(), ohit, es);
119  if(!checkRZ) {
120 #ifdef mydebug_Seed
121  ss << "*******\nNo valid checkRZ\n*******" << std::endl;
122 #endif
123  continue;
124  }
125 
126  /*Get only the inner hits compatible with the conversion region*/
127  innerHits.clear();
128  if(!getPhiRange(innerPhimin,innerPhimax,*innerLayerObj.detLayer(),convRegion,es)) continue;
129  innerHitsMap.hits(innerPhimin, innerPhimax, innerHits);
130 
131 #ifdef mydebug_Seed
132  ss << "\tiphimin, iphimax " << innerPhimin << " " << innerPhimax << std::endl;
133 #endif
134 
135  /*Loop on inner hits*/
136  for ( vector<RecHitsSortedInPhi::Hit>::const_iterator ih=innerHits.begin(), ieh = innerHits.end(); ih < ieh; ++ih) {
137  GlobalPoint innPos = (*ih)->globalPosition();
138 
139 
140 #ifdef mydebug_Seed
141  ss << "\tinnPos " << innPos << " r " << innPos.perp() << " phi " << innPos.phi() << " cotTheta " << innPos.z()/innPos.perp() << std::endl;
142 #endif
143 
144  /*Check the compatibility of the ohit with the eta of the seeding track*/
145  if(checkRZCompatibilityWithSeedTrack(*ih,*innerLayerObj.detLayer(),convRegion)) continue;
146 
147  float r_reduced = std::sqrt( sqr(innPos.x()-region.origin().x())+sqr(innPos.y()-region.origin().y()));
148  Range allowed;
149  Range hitRZ;
150  if (innerLayerObj.detLayer()->location() == barrel) {
151  allowed = checkRZ->range(r_reduced);
152  float zErr = nSigmaRZ * (*ih)->errorGlobalZ();
153  hitRZ = Range(innPos.z()-zErr, innPos.z()+zErr);
154  } else {
155  allowed = checkRZ->range(innPos.z());
156  float rErr = nSigmaRZ * (*ih)->errorGlobalR();
157  hitRZ = Range(r_reduced-rErr, r_reduced+rErr);
158  }
159  Range crossRange = allowed.intersection(hitRZ);
160 
161 #ifdef mydebug_Seed
162  ss
163  << "\n\t\t allowed Range " << allowed.min() << " \t, " << allowed.max()
164  << "\n\t\t hitRz Range " << hitRZ.min() << " \t, " << hitRZ.max()
165  << "\n\t\t Cross Range " << crossRange.min() << " \t, " << crossRange.max()
166  << "\n\t\t the seed track has origin " << convRegion.convPoint() << " \t cotTheta " << convRegion.cotTheta()
167  << std::endl;
168 #endif
169 
170  if (! crossRange.empty() ) {
171 #ifdef mydebug_Seed
172  ss
173  << "\n\t\t !!!!ACCEPTED!!! \n\n";
174 #endif
175  if (theMaxElement!=0 && result.size() >= maxNum ){
176  result.resize(oldSize);
177 #ifdef mydebug_Seed
178  edm::LogError("TooManySeeds")<<"number of pairs exceed maximum, no pairs produced";
179 #endif
180  delete checkRZ;
181 
182 #ifdef mydebug_Seed
183  std::cout << ss.str();
184 #endif
185  return;
186  }
187  result.push_back( OrderedHitPair( *ih, ohit) );
188  }
189  }
190  delete checkRZ;
191  }
192 
193 #ifdef mydebug_Seed
194  std::cout << ss.str();
195 #endif
196 }
197 
198 
200  if (layer.location() == GeomDetEnumerators::barrel){
201  const BarrelDetLayer& bl = static_cast<const BarrelDetLayer&>(layer);
202  float rLayer = bl.specificSurface().radius();
203 
204  // the maximal delta phi will be for the innermost hits
205  float theThickness = layer.surface().bounds().thickness();
206  return rLayer + 0.5f*theThickness;
207  }
208 
209  //Fixme
210  return 0;
211 }
212 
214  if (layer.location() == GeomDetEnumerators::endcap){
215  float layerZ = layer.position().z();
216  float theThickness = layer.surface().bounds().thickness();
217  float layerZmax = layerZ > 0 ? layerZ+0.5f*theThickness: layerZ-0.5f*theThickness;
218  return layerZmax;
219  }else{
220  //Fixme
221  return 0;
222  }
223 }
224 bool HitPairGeneratorFromLayerPairForPhotonConversion::checkBoundaries(const DetLayer& layer,const ConversionRegion& convRegion,float maxSearchR, float maxSearchZ){
225 
226  if(layer.location() == GeomDetEnumerators::barrel){
227 
228  float minZEndCap=130;
229  if(fabs(convRegion.convPoint().z()) > minZEndCap){
230 #ifdef mydebug_Seed
231  ss << "\tthe conversion seems to be in the endcap. Zconv " << convRegion.convPoint().z() << std::endl;
232  std::cout << ss.str();
233 #endif
234  return false;
235  }
236 
237  float R=getLayerRadius(layer);
238 
239  if(convRegion.convPoint().perp()>R){
240 #ifdef mydebug_Seed
241  ss << "\tthis layer is before the conversion : R layer " << R << " [ Rconv " << convRegion.convPoint().perp() << " Zconv " << convRegion.convPoint().z()<< std::endl;
242  std::cout << ss.str();
243 #endif
244  return false;
245  }
246 
247  if(R - convRegion.convPoint().perp() > maxSearchR ){
248 #ifdef mydebug_Seed
249  ss << "\tthis layer is far from the conversion more than cut " << maxSearchR << " cm. R layer " << R << " [ Rconv " << convRegion.convPoint().perp() << " Zconv " << convRegion.convPoint().z()<< std::endl;
250  std::cout << ss.str();
251 #endif
252  return false;
253  }
254 
255  }else if (layer.location() == GeomDetEnumerators::endcap){
256 
257  float Z=getLayerZ(layer);
258  if(
259  (convRegion.convPoint().z()>0 && convRegion.convPoint().z()>Z)
260  ||
261  (convRegion.convPoint().z()<0 && convRegion.convPoint().z()<Z)
262  ) {
263 #ifdef mydebug_Seed
264  ss << "\tthis layer is before the conversion : Z layer " << Z << " [ Rconv " << convRegion.convPoint().perp()<< " Zconv " << convRegion.convPoint().z() << std::endl;
265  std::cout << ss.str();
266 #endif
267  return false;
268  }
269 
270 
271  if(fabs(Z - convRegion.convPoint().z()) > maxSearchZ ){
272 #ifdef mydebug_Seed
273  ss << "\tthis layer is far from the conversion more than cut " << maxSearchZ << " cm. Z layer " << Z << " [ Rconv " << convRegion.convPoint().perp()<< " Zconv " << convRegion.convPoint().z() << std::endl;
274  std::cout << ss.str();
275 #endif
276  return false;
277  }
278 
279  }
280  return true;
281 }
282 
284  if(layer.location() == GeomDetEnumerators::barrel){
285  return getPhiRange(Phimin,Phimax,getLayerRadius(layer),convRegion,es);
286  }else if (layer.location() == GeomDetEnumerators::endcap){
287  float Z=getLayerZ(layer);
288  float R=Z/convRegion.cotTheta();
289  return getPhiRange(Phimin,Phimax,R,convRegion,es); //FIXME
290  }
291  return false;
292 }
293 
294 bool HitPairGeneratorFromLayerPairForPhotonConversion::getPhiRange(float& Phimin, float& Phimax, const float& layerR, const ConversionRegion &convRegion, const edm::EventSetup& es){
295  Phimin = reco::deltaPhi(convRegion.convPoint().phi(),0.);
296 
297  float dphi;
298  float ptmin=0.1;
299  float DeltaL=layerR-convRegion.convPoint().perp();
300 
301  if(DeltaL<0){
302  Phimin=0;
303  Phimax=0;
304  return false;
305  }
306 
307  float theRCurvatureMin = PixelRecoUtilities::bendingRadius(ptmin,es);
308 
309  if(theRCurvatureMin<DeltaL)
310  dphi = atan(DeltaL/layerR);
311  else
312  dphi = atan(theRCurvatureMin/layerR * ( 1 - sqrt(1-sqr(DeltaL/theRCurvatureMin)) ) );
313 
314  if(convRegion.charge()>0){
315  Phimax=Phimin;
316  Phimin=Phimax-dphi;
317  }else{
318  Phimax=Phimin+dphi;
319  }
320 
321  //std::cout << dphi << " " << Phimin << " " << Phimax << " " << layerR << " " << DeltaL << " " << convRegion.convPoint().phi() << " " << convRegion.convPoint().perp()<< std::endl;
322  return true;
323 }
324 
327  static const float nSigmaRZ = std::sqrt(12.f);
328  Range hitCotTheta;
329 
330  double sigmaCotTheta = convRegion.errTheta() * (1+convRegion.cotTheta()*convRegion.cotTheta()); //Error Propagation from sigma theta.
331  Range allowedCotTheta(convRegion.cotTheta()-nSigmaRZ*sigmaCotTheta,convRegion.cotTheta()+nSigmaRZ*sigmaCotTheta);
332 
333  double dz = hit->globalPosition().z()-convRegion.pvtxPoint().z();
334  double r_reduced = std::sqrt( sqr(hit->globalPosition().x()-convRegion.pvtxPoint().x())+sqr(hit->globalPosition().y()-convRegion.pvtxPoint().y()));
335 
336  if (layer.location() == GeomDetEnumerators::barrel){
337  float zErr = nSigmaRZ * hit->errorGlobalZ();
338  hitCotTheta = Range(getCot(dz-zErr,r_reduced),getCot(dz+zErr,r_reduced));
339  }else{
340  float rErr = nSigmaRZ * hit->errorGlobalR();
341  if(dz>0)
342  hitCotTheta = Range(getCot(dz,r_reduced+rErr),getCot(dz,r_reduced-rErr));
343  else
344  hitCotTheta = Range(getCot(dz,r_reduced-rErr), getCot(dz,r_reduced+rErr));
345  }
346 
347  Range crossRange = allowedCotTheta.intersection(hitCotTheta);
348 
349 #ifdef mydebug_Seed
350  ss
351  << "\n\t\t cotTheta allowed Range " << allowedCotTheta.min() << " \t, " << allowedCotTheta.max()
352  << "\n\t\t hitCotTheta Range " << hitCotTheta.min() << " \t, " << hitCotTheta.max()
353  << "\n\t\t Cross Range " << crossRange.min() << " \t, " << crossRange.max()
354  << "\n\t\t the seed track has origin " << convRegion.convPoint() << " \t cotTheta " << convRegion.cotTheta()
355  << std::endl;
356 #endif
357 
358  return crossRange.empty();
359 }
360 
361 
363 getCot(double dz, double dr){
364  if ( std::abs(dr) > 1.e-4f ) return dz/dr;
365  else
366  if(dz>0) return 99999.f;
367  else return -99999.f;
368 }
369 
const double Z[kNumberCalorimeter]
std::vector< Hit > hits(float phiMin, float phiMax) const
float cotTheta() const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
bool checkRZCompatibilityWithSeedTrack(const RecHitsSortedInPhi::Hit &hit, const DetLayer &layer, const ConversionRegion &convRegion)
T perp() const
Definition: PV3DBase.h:72
GlobalPoint const & origin() const
void hitPairs(const ConversionRegion &convRegion, const TrackingRegion &reg, OrderedHitPairs &prs, const edm::Event &ev, const edm::EventSetup &es)
virtual Location location() const =0
Which part of the detector (barrel, endcap)
virtual Range range(const float &rORz) const =0
GlobalPoint pvtxPoint() const
int charge() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
SeedingHitSet::ConstRecHitPointer InnerRecHit
GlobalPoint convPoint() const
const Bounds & bounds() const
Definition: Surface.h:128
virtual unsigned int size() const
virtual float thickness() const =0
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
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
bool getPhiRange(float &Phimin, float &Phimax, const DetLayer &layer, const ConversionRegion &convRegion, const edm::EventSetup &es)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
PixelRecoRange< float > Range
bool checkBoundaries(const DetLayer &layer, const ConversionRegion &convRegion, float maxSearchR, float maxSearchZ)
virtual const Surface::PositionType & position() const
Returns position of the surface.
virtual const BoundCylinder & specificSurface() const
Extension of the interface.
const DetLayer * detLayer() const
double errTheta() const
T bendingRadius(T pt, const edm::EventSetup &iSetup)
double ptmin
Definition: HydjetWrapper.h:85
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
HitPairGeneratorFromLayerPairForPhotonConversion(unsigned int inner, unsigned int outer, LayerCacheType *layerCache, unsigned int nSize=30000, unsigned int max=0)
tuple cout
Definition: gather_cfg.py:121
long double T
T x() const
Definition: PV3DBase.h:62
SeedingHitSet::ConstRecHitPointer OuterRecHit