Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:24

0001 #include "FastSimulation/TrackingRecHitProducer/interface/TrackingRecHitAlgorithm.h"
0002 #include "FastSimulation/TrackingRecHitProducer/interface/TrackingRecHitAlgorithmFactory.h"
0003 #include "FastSimulation/TrackingRecHitProducer/interface/TrackingRecHitProduct.h"
0004 
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0007 #include "DataFormats/TrackerRecHit2D/interface/FastSingleTrackerRecHit.h"
0008 #include "DataFormats/GeometrySurface/interface/Plane.h"
0009 
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 #include <string>
0013 #include <iostream>
0014 
0015 /* This plugin performs simple Gaussian smearing (GS) of the sim hit position
0016  * per module. If y resolution < 0 (default) the module length/sqrt(12) is taken as uncertainty.
0017  */
0018 
0019 class TrackingRecHitStripGSPlugin : public TrackingRecHitAlgorithm {
0020 private:
0021   double _resolutionX;
0022   double _resolutionX2;
0023 
0024   double _resolutionY;
0025   double _resolutionY2;
0026 
0027   constexpr static double INV12 = 1.0 / 12.0;
0028 
0029 public:
0030   TrackingRecHitStripGSPlugin(const std::string& name,
0031                               const edm::ParameterSet& config,
0032                               edm::ConsumesCollector& consumesCollector)
0033       : TrackingRecHitAlgorithm(name, config, consumesCollector),
0034         _resolutionX(0.001),
0035         _resolutionX2(_resolutionX * _resolutionX),
0036         _resolutionY(-1),
0037         _resolutionY2(_resolutionY * _resolutionY)
0038 
0039   {
0040     if (config.exists("resolutionX")) {
0041       _resolutionX = config.getParameter<double>("resolutionX");
0042       _resolutionX2 = _resolutionX * _resolutionX;
0043     }
0044     if (config.exists("resolutionY")) {
0045       _resolutionY = config.getParameter<double>("resolutionY");
0046       _resolutionY2 = _resolutionY * _resolutionY;
0047     }
0048   }
0049 
0050   TrackingRecHitProductPtr process(TrackingRecHitProductPtr product) const override {
0051     for (const std::pair<unsigned int, const PSimHit*>& simHitIdPair : product->getSimHitIdPairs()) {
0052       const PSimHit* simHit = simHitIdPair.second;
0053       const Local3DPoint& simHitPosition = simHit->localPosition();
0054 
0055       const GeomDet* geomDet = this->getTrackerGeometry().idToDetUnit(product->getDetId());
0056       const Plane& plane = geomDet->surface();
0057       const Bounds& bounds = plane.bounds();
0058       const double boundY = bounds.length();
0059 
0060       Local3DPoint recHitPosition;
0061 
0062       unsigned int retry = 0;
0063       do {
0064         recHitPosition = Local3DPoint(simHitPosition.x() + this->getRandomEngine().gaussShoot(0.0, _resolutionX),
0065                                       0.0,
0066                                       0.0  //fix y & z coordinates to center of module
0067         );
0068 
0069         // If we tried to generate thePosition, and it's out of the bounds
0070         // for 10 times, then take and return the simHit's location.
0071         ++retry;
0072         if (retry > 10) {
0073           recHitPosition = Local3DPoint(simHitPosition.x(), 0.0, 0.0  //fix y & z coordinates to center of module
0074           );
0075           break;
0076         }
0077       } while (not bounds.inside(recHitPosition));
0078 
0079       LocalError error(
0080           //xx (variance)
0081           _resolutionX2,
0082           //xy (covariance)
0083           0.0,
0084           //take here the provided y resolution or (lenght/sqrt(12))^2
0085           _resolutionY < 0.0 ? boundY * boundY * INV12 : _resolutionY2);
0086 
0087       FastSingleTrackerRecHit recHit(recHitPosition, error, *geomDet, fastTrackerRecHitType::siStrip1D);
0088       product->addRecHit(recHit, {simHitIdPair});
0089     }
0090     return product;
0091   }
0092 };
0093 
0094 DEFINE_EDM_PLUGIN(TrackingRecHitAlgorithmFactory, TrackingRecHitStripGSPlugin, "TrackingRecHitStripGSPlugin");