Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FastSimulation_TrackingRecHitProducer_PixelTemplateSmearerBase_h
0002 #define FastSimulation_TrackingRecHitProducer_PixelTemplateSmearerBase_h
0003 
0004 //---------------------------------------------------------------------------
0005 //! \class SiTrackerGaussianSmearingRecHits
0006 //!
0007 //! \brief EDProducer to create RecHits from PSimHits with Gaussian smearing
0008 //!
0009 //---------------------------------------------------------------------------
0010 
0011 // FastSim stuff
0012 #include "FastSimulation/TrackingRecHitProducer/interface/TrackingRecHitAlgorithm.h"
0013 
0014 //Framework
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 
0017 // PSimHit
0018 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0019 
0020 // Geometry
0021 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
0022 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0023 // template object
0024 #include "CondFormats/SiPixelTransient/interface/SiPixelTemplate.h"
0025 
0026 // Vectors
0027 #include "DataFormats/GeometryVector/interface/Point3DBase.h"
0028 #include "DataFormats/GeometrySurface/interface/LocalError.h"
0029 
0030 // STL.  <memory> needed for uniq_ptr<>
0031 #include <vector>
0032 #include <string>
0033 #include <memory>
0034 
0035 class TFile;
0036 class RandomEngineAndDistribution;
0037 class SimpleHistogramGenerator;
0038 class PixelResolutionHistograms;
0039 
0040 class PixelTemplateSmearerBase : public TrackingRecHitAlgorithm {
0041 public:
0042   //--- Use this type to keep track of groups of hits that need to be merged:
0043   struct MergeGroup {
0044     std::vector<TrackingRecHitProduct::SimHitIdPair> group;
0045     bool smearIt;
0046   };
0047 
0048 protected:
0049   bool mergeHitsOn = false;  // if true then see if neighboring hits might merge
0050 
0051   //--- Template DB Object(s)
0052   const SiPixelTemplateDBObject* pixelTemplateDBObject_ = nullptr;            // needed for template<-->DetId map.
0053   std::vector<SiPixelTemplateStore> thePixelTemp_;                            // our own template storage
0054   const std::vector<SiPixelTemplateStore>* thePixelTempRef = &thePixelTemp_;  // points to the one we will use.
0055   int templateId = -1;
0056 
0057   //--- Flag to tell us whether we are in barrel or in forward.
0058   //    This is needed since the parameterization is slightly
0059   //    different for forward, since all forward detectors cover
0060   //    a smaller range of local incidence angles and thus
0061   //    the clusters are shorter and have less charge.
0062   bool isBarrel;
0063 
0064   //--- The histogram storage containers.
0065   std::shared_ptr<PixelResolutionHistograms> theEdgePixelResolutions;
0066   std::string theEdgePixelResolutionFileName;
0067 
0068   std::shared_ptr<PixelResolutionHistograms> theBigPixelResolutions;
0069   std::string theBigPixelResolutionFileName;
0070 
0071   std::shared_ptr<PixelResolutionHistograms> theRegularPixelResolutions;
0072   std::string theRegularPixelResolutionFileName;
0073 
0074   //--- Files with hit merging information:
0075   std::unique_ptr<TFile> theMergingProbabilityFile;
0076   std::string theMergingProbabilityFileName;
0077 
0078   std::unique_ptr<TFile> theMergedPixelResolutionXFile;
0079   std::string theMergedPixelResolutionXFileName;
0080 
0081   std::unique_ptr<TFile> theMergedPixelResolutionYFile;
0082   std::string theMergedPixelResolutionYFileName;
0083 
0084 public:
0085   explicit PixelTemplateSmearerBase(const std::string& name,
0086                                     const edm::ParameterSet& config,
0087                                     edm::ConsumesCollector& consumesCollector);
0088 
0089   ~PixelTemplateSmearerBase() override;
0090   TrackingRecHitProductPtr process(TrackingRecHitProductPtr product) const override;
0091   // void beginEvent(edm::Event& event, const edm::EventSetup& eventSetup) override;
0092   void beginRun(edm::Run const& run,
0093                 const edm::EventSetup& eventSetup,
0094                 const SiPixelTemplateDBObject* pixelTemplateDBObjectPtr,
0095                 const std::vector<SiPixelTemplateStore>& tempStoreRef) override;
0096   // void endEvent(edm::Event& event, const edm::EventSetup& eventSetup) override;
0097 
0098   //--- Process all unmerged hits. Calls smearHit() for each.
0099   TrackingRecHitProductPtr processUnmergedHits(std::vector<TrackingRecHitProduct::SimHitIdPair>& unmergedHits,
0100                                                TrackingRecHitProductPtr product,
0101                                                const PixelGeomDetUnit* detUnit,
0102                                                const double boundX,
0103                                                const double boundY,
0104                                                RandomEngineAndDistribution const* random) const;
0105   //--- Process all groups of merged hits.
0106   TrackingRecHitProductPtr processMergeGroups(std::vector<MergeGroup*>& mergeGroups,
0107                                               TrackingRecHitProductPtr product,
0108                                               const PixelGeomDetUnit* detUnit,
0109                                               const double boundX,
0110                                               const double boundY,
0111                                               RandomEngineAndDistribution const* random) const;
0112 
0113   //--- Process one umerged hit.
0114   FastSingleTrackerRecHit smearHit(const PSimHit& simHit,
0115                                    const PixelGeomDetUnit* detUnit,
0116                                    const double boundX,
0117                                    const double boundY,
0118                                    RandomEngineAndDistribution const*) const;
0119 
0120   //--- Process one merge group.
0121   FastSingleTrackerRecHit smearMergeGroup(MergeGroup* mg,
0122                                           const PixelGeomDetUnit* detUnit,
0123                                           const double boundX,
0124                                           const double boundY,
0125                                           const RandomEngineAndDistribution* random) const;
0126 
0127   //--- Method to decide if the two hits on the same DetUnit are merged, or not.
0128   bool hitsMerge(const PSimHit& simHit1, const PSimHit& simHit2) const;
0129 };
0130 #endif