Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimG4CMS_HFShowerLibrary_h
0002 #define SimG4CMS_HFShowerLibrary_h 1
0003 ///////////////////////////////////////////////////////////////////////////////
0004 // File: HFShowerLibrary.h
0005 // Description: Gets information from a shower library
0006 ///////////////////////////////////////////////////////////////////////////////
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h"
0011 #include "CondFormats/GeometryObjects/interface/HcalSimulationParameters.h"
0012 #include "SimG4CMS/Calo/interface/HFFibre.h"
0013 #include "SimDataFormats/CaloHit/interface/HFShowerPhoton.h"
0014 
0015 #include "G4ThreeVector.hh"
0016 
0017 //ROOT
0018 #include "TROOT.h"
0019 #include "TFile.h"
0020 #include "TTree.h"
0021 
0022 #include <string>
0023 #include <memory>
0024 
0025 class G4Step;
0026 class G4ParticleTable;
0027 
0028 class HFShowerLibrary {
0029 public:
0030   //Constructor and Destructor
0031   HFShowerLibrary(const std::string &name,
0032                   const HcalDDDSimConstants *hcons,
0033                   const HcalSimulationParameters *hps,
0034                   edm::ParameterSet const &p);
0035   ~HFShowerLibrary();
0036 
0037 public:
0038   struct Hit {
0039     Hit() {}
0040     G4ThreeVector position;
0041     int depth;
0042     double time;
0043   };
0044 
0045   std::vector<Hit> getHits(const G4Step *aStep, bool &ok, double weight, bool onlyLong = false);
0046   std::vector<Hit> fillHits(const G4ThreeVector &p,
0047                             const G4ThreeVector &v,
0048                             int parCode,
0049                             double parEnergy,
0050                             bool &ok,
0051                             double weight,
0052                             double time,
0053                             bool onlyLong = false);
0054 
0055   struct Params {
0056     double probMax_;
0057     double backProb_;
0058     double dphi_;
0059     bool equalizeTimeShift_;
0060     bool verbose_;
0061     bool applyFidCut_;
0062   };
0063   struct FileParams {
0064     std::string fileName_;
0065     std::string emBranchName_;
0066     std::string hadBranchName_;
0067     std::string branchEvInfo_;
0068     int fileVersion_;
0069     bool cacheBranches_ = false;
0070   };
0071   HFShowerLibrary(Params const &, FileParams const &, HFFibre::Params);
0072 
0073 private:
0074   HFShowerLibrary(const HcalDDDSimConstants *hcons,
0075                   const HcalSimulationParameters *hps,
0076                   edm::ParameterSet const &hfShower,
0077                   edm::ParameterSet const &hfShowerLibrary);
0078   bool rInside(double r) const;
0079   HFShowerPhotonCollection getRecord(int, int) const;
0080 
0081   struct VersionInfo {
0082     float libVers_;
0083     float listVersion_;
0084   };
0085   VersionInfo loadEventInfo(TBranch *, int fileVersion);
0086   HFShowerPhotonCollection interpolate(int, double);
0087   HFShowerPhotonCollection extrapolate(int, double);
0088   void storePhoton(HFShowerPhoton const &iPhoton, HFShowerPhotonCollection &iPhotons) const;
0089 
0090   enum class FileFormat { kOld, kNew, kNewV3 };
0091 
0092   struct BranchCache;
0093   struct BranchReader {
0094     BranchReader() : branch_(nullptr), offset_(0), format_(FileFormat::kOld) {}
0095     BranchReader(TBranch *iBranch, FileFormat iFormat, size_t iReadOffset, size_t maxRecordsToCache)
0096         : branch_(iBranch), offset_(iReadOffset), format_(iFormat) {
0097       if (0 < maxRecordsToCache) {
0098         doCaching(maxRecordsToCache);
0099         branch_ = nullptr;
0100       }
0101     }
0102 
0103     HFShowerPhotonCollection getRecord(int) const;
0104 
0105     std::size_t numberOfRecords() const;
0106 
0107   private:
0108     static HFShowerPhotonCollection getRecordOldForm(TBranch *, int iEntry);
0109     static HFShowerPhotonCollection getRecordNewForm(TBranch *, int iEntry);
0110     static HFShowerPhotonCollection getRecordNewFormV3(TBranch *, int iEntry);
0111     void doCaching(size_t maxRecords);
0112 
0113     static std::shared_ptr<BranchCache const> makeCache(BranchReader &,
0114                                                         size_t maxRecordsToCache,
0115                                                         std::string const &iFileName,
0116                                                         std::string const &iBranchName);
0117 
0118     TBranch *branch_;
0119     std::shared_ptr<BranchCache const> cache_;
0120     size_t offset_;
0121     FileFormat format_;
0122   };
0123 
0124   struct BranchCache {
0125     explicit BranchCache(BranchReader &, size_t maxRecordsToCache);
0126     [[nodiscard]] HFShowerPhotonCollection getRecord(int) const;
0127 
0128   private:
0129     HFShowerPhotonCollection photons_;
0130     std::vector<std::size_t> offsets_;
0131   };
0132 
0133   HFFibre fibre_;
0134   std::unique_ptr<TFile> hf_;
0135 
0136   BranchReader emBranch_;
0137   BranchReader hadBranch_;
0138 
0139   bool verbose_, applyFidCut_;
0140   int nMomBin_, totEvents_, evtPerBin_;
0141   std::vector<double> pmom_;
0142 
0143   bool equalizeTimeShift_;
0144   double probMax_, backProb_;
0145   double dphi_, rMin_, rMax_;
0146   std::vector<double> gpar_;
0147 };
0148 #endif