Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:38

0001 #ifndef HGCalSimProducers_HGCDigitizer_h
0002 #define HGCalSimProducers_HGCDigitizer_h
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0006 #include "FWCore/Framework/interface/ESWatcher.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 
0009 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0010 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0011 
0012 #include "SimCalorimetry/HGCalSimProducers/interface/HGCDigitizerBase.h"
0013 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0014 #include "DataFormats/HGCalDigi/interface/PHGCSimAccumulator.h"
0015 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0016 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0017 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0018 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0019 
0020 #include <vector>
0021 #include <map>
0022 #include <unordered_set>
0023 #include <memory>
0024 #include <tuple>
0025 
0026 class PCaloHit;
0027 class PileUpEventPrincipal;
0028 
0029 class HGCDigitizer {
0030 public:
0031   HGCDigitizer(const edm::ParameterSet& ps, edm::ConsumesCollector& iC);
0032   ~HGCDigitizer() = default;
0033 
0034   // index , det id, time
0035   typedef std::tuple<int, uint32_t, float> HGCCaloHitTuple_t;
0036   static bool orderByDetIdThenTime(const HGCCaloHitTuple_t& a, const HGCCaloHitTuple_t& b) {
0037     unsigned int detId_a(std::get<1>(a)), detId_b(std::get<1>(b));
0038 
0039     if (detId_a < detId_b)
0040       return true;
0041     if (detId_a > detId_b)
0042       return false;
0043 
0044     double time_a(std::get<2>(a)), time_b(std::get<2>(b));
0045     if (time_a < time_b)
0046       return true;
0047 
0048     return false;
0049   }
0050 
0051   /**
0052      @short handle SimHit accumulation
0053    */
0054   void accumulate(edm::Event const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre);
0055   void accumulate_forPreMix(edm::Event const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre);
0056 
0057   void accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre);
0058   void accumulate_forPreMix(PileUpEventPrincipal const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre);
0059 
0060   void accumulate(edm::Handle<edm::PCaloHitContainer> const& hits,
0061                   int bxCrossing,
0062                   const HGCalGeometry* geom,
0063                   CLHEP::HepRandomEngine* hre);
0064   void accumulate_forPreMix(edm::Handle<edm::PCaloHitContainer> const& hits,
0065                             int bxCrossing,
0066                             const HGCalGeometry* geom,
0067                             CLHEP::HepRandomEngine* hre);
0068 
0069   void accumulate_forPreMix(const PHGCSimAccumulator& simAccumulator, const bool minbiasFlag);
0070   /**
0071      @short actions at the start/end of event
0072    */
0073   void initializeEvent(edm::Event const& e, edm::EventSetup const& c);
0074   void finalizeEvent(edm::Event& e, edm::EventSetup const& c, CLHEP::HepRandomEngine* hre);
0075 
0076   std::string digiCollection() { return digiCollection_; }
0077 
0078 private:
0079   uint32_t getType() const;
0080 
0081   std::unique_ptr<hgc::HGCSimHitDataAccumulator> simHitAccumulator_;
0082   std::unique_ptr<hgc::HGCPUSimHitDataAccumulator> pusimHitAccumulator_;
0083 
0084   const std::string digiCollection_;
0085 
0086   //digitization type (it's up to the specializations to decide it's meaning)
0087   const int digitizationType_;
0088 
0089   // if true, we're running mixing in premixing stage1 and have to produce the output differently
0090   const bool premixStage1_;
0091 
0092   // Minimum charge threshold for premixing stage1
0093   const double premixStage1MinCharge_;
0094   // Maximum charge for packing in premixing stage1
0095   const double premixStage1MaxCharge_;
0096 
0097   //handle sim hits
0098   const int maxSimHitsAccTime_;
0099   const double bxTime_;
0100   double ev_per_eh_pair_;
0101   const std::string hitsProducer_;
0102   const std::string hitCollection_;
0103   const edm::EDGetTokenT<std::vector<PCaloHit>> hitToken_;
0104   void resetSimHitDataAccumulator();
0105   void resetPUSimHitDataAccumulator();
0106   //debug position
0107   void checkPosition(const HGCalDigiCollection* digis) const;
0108 
0109   //digitizer
0110   std::unique_ptr<HGCDigitizerBase> theDigitizer_;
0111 
0112   //geometries
0113   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0114   edm::ESWatcher<CaloGeometryRecord> geomWatcher_;
0115   std::unordered_set<DetId> validIds_;
0116   const HGCalGeometry* gHGCal_ = nullptr;
0117 
0118   //misc switches
0119   const uint32_t verbosity_;
0120 
0121   //delay to apply after evaluating time of arrival at the sensitive detector
0122   const float tofDelay_;
0123 
0124   //average occupancies
0125   std::array<double, 4> averageOccupancies_;
0126   uint32_t nEvents_;
0127 
0128   //maxBx limit beyond which the Digitizer should filter out all hits
0129   static const unsigned int maxBx_ = 14;
0130   static const unsigned int thisBx_ = 9;
0131   std::vector<float> cce_;
0132   std::unordered_map<uint32_t, std::vector<std::pair<float, float>>> hitRefs_bx0;
0133   std::unordered_map<uint32_t, std::vector<std::tuple<float, float, float>>> PhitRefs_bx0;
0134   std::unordered_map<uint32_t, bool> hitOrder_monitor;
0135 };
0136 
0137 #endif