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