CMS 3D CMS Logo

TrackingRecHitStripGSPlugin.cc
Go to the documentation of this file.
4 
9 
11 
12 #include <string>
13 #include <iostream>
14 
15 /* This plugin performs simple Gaussian smearing (GS) of the sim hit position
16  * per module. If y resolution < 0 (default) the module length/sqrt(12) is taken as uncertainty.
17  */
18 
21 {
22  private:
23  double _resolutionX;
24  double _resolutionX2;
25 
26  double _resolutionY;
27  double _resolutionY2;
28 
29  constexpr static double INV12 = 1.0/12.0;
30 
31  public:
33  const std::string& name,
35  edm::ConsumesCollector& consumesCollector
36  ):
37  TrackingRecHitAlgorithm(name,config,consumesCollector),
38  _resolutionX(0.001),
39  _resolutionX2(_resolutionX*_resolutionX),
40  _resolutionY(-1),
41  _resolutionY2(_resolutionY*_resolutionY)
42 
43  {
44  if (config.exists("resolutionX"))
45  {
46  _resolutionX = config.getParameter<double>("resolutionX");
47  _resolutionX2=_resolutionX*_resolutionX;
48  }
49  if (config.exists("resolutionY"))
50  {
51  _resolutionY = config.getParameter<double>("resolutionY");
52  _resolutionY2=_resolutionY*_resolutionY;
53  }
54  }
55 
57  {
58  for (const std::pair<unsigned int,const PSimHit*>& simHitIdPair: product->getSimHitIdPairs())
59  {
60  const PSimHit* simHit = simHitIdPair.second;
61  const Local3DPoint& simHitPosition = simHit->localPosition();
62 
63  const GeomDet* geomDet = this->getTrackerGeometry().idToDetUnit(product->getDetId());
64  const Plane& plane = geomDet->surface();
65  const Bounds& bounds = plane.bounds();
66  const double boundY = bounds.length();
67 
68  Local3DPoint recHitPosition;
69 
70  unsigned int retry = 0;
71  do
72  {
73  recHitPosition = Local3DPoint(
74  simHitPosition.x()+this->getRandomEngine().gaussShoot(0.0,_resolutionX),
75  0.0, 0.0 //fix y & z coordinates to center of module
76  );
77 
78  // If we tried to generate thePosition, and it's out of the bounds
79  // for 10 times, then take and return the simHit's location.
80  ++retry;
81  if (retry>10)
82  {
83  recHitPosition = Local3DPoint(
84  simHitPosition.x(),
85  0.0, 0.0 //fix y & z coordinates to center of module
86  );
87  break;
88  }
89  }
90  while (not bounds.inside(recHitPosition));
91 
93  //xx (variance)
94  _resolutionX2,
95  //xy (covariance)
96  0.0,
97  //take here the provided y resolution or (lenght/sqrt(12))^2
98  _resolutionY<0.0 ? boundY*boundY*INV12 : _resolutionY2
99  );
100 
102  recHitPosition,
103  error,
104  *geomDet,
106  );
107  product->addRecHit(recHit,{simHitIdPair});
108  }
109  return product;
110  }
111 };
112 
116  "TrackingRecHitStripGSPlugin"
117 );
118 
T getParameter(std::string const &) const
virtual float length() const =0
TrackingRecHitStripGSPlugin(const std::string &name, const edm::ParameterSet &config, edm::ConsumesCollector &consumesCollector)
bool exists(std::string const &parameterName) const
checks if a parameter exists
const TrackerGeometry & getTrackerGeometry() const
const Bounds & bounds() const
Definition: Surface.h:120
Definition: config.py:1
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
Definition: Plane.h:17
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
Local3DPoint localPosition() const
Definition: PSimHit.h:52
const RandomEngineAndDistribution & getRandomEngine() const
std::shared_ptr< TrackingRecHitProduct > TrackingRecHitProductPtr
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
TrackingRecHitProductPtr process(TrackingRecHitProductPtr product) const override
double gaussShoot(double mean=0.0, double sigma=1.0) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: Bounds.h:22
T x() const
Definition: PV3DBase.h:62
#define constexpr