Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:30:54

0001 // ----------------------------------------------------------------------------
0002 // 'RelationalDebugHCalTreeMaker.h'
0003 // Derek Anderson
0004 // 03.09.2024
0005 //
0006 // A JANA plugin to construct a tree of HCal clusters
0007 // and related cells and particles.
0008 // ----------------------------------------------------------------------------
0009 
0010 #ifndef RELATIONALHCALDEBUGTREEMAKERPROCESSOR_H
0011 #define RELATIONALHCALDEBUGTREEMAKERPROCESSOR_H
0012 
0013 // c++ utilities
0014 #include <cmath>
0015 #include <limits>
0016 #include <vector>
0017 #include <string>
0018 #include <cstdlib>
0019 // root libraries
0020 #include <TTree.h>
0021 #include <TFile.h>
0022 #include <TDirectory.h>
0023 // JANA libraries
0024 #include <JANA/JEventProcessor.h>
0025 #include <JANA/JEventProcessorSequentialRoot.h>
0026 // data model types
0027 #include <edm4eic/Cluster.h>
0028 #include <edm4eic/TrackerHit.h>
0029 #include <edm4eic/ProtoCluster.h>
0030 #include <edm4eic/RawTrackerHit.h>
0031 #include <edm4eic/CalorimeterHit.h>
0032 #include <edm4eic/ReconstructedParticle.h>
0033 #include <edm4eic/MCRecoClusterParticleAssociation.h>
0034 #include <edm4hep/MCParticle.h>
0035 #include <edm4hep/SimCalorimeterHit.h>
0036 // eicrecon services
0037 #include <spdlog/spdlog.h>
0038 #include <services/log/Log_service.h>
0039 #include <services/rootfile/RootFile_service.h>
0040 #include <services/geometry/dd4hep/DD4hep_service.h>
0041 // dd4hep utilities
0042 #include "DD4hep/Objects.h"
0043 #include "DD4hep/Detector.h"
0044 #include "DD4hep/DetElement.h"
0045 #include "DD4hep/IDDescriptor.h"
0046 #include "DDG4/Geant4Data.h"
0047 #include "DDRec/Surface.h"
0048 #include "DDRec/SurfaceManager.h"
0049 #include "DDRec/CellIDPositionConverter.h"
0050 
0051 
0052 
0053 class RelationalHCalDebugTreeMakerProcessor: public JEventProcessorSequentialRoot {
0054 
0055   // struct to hold user options
0056   struct Config {
0057     std::string sPlugin;
0058     std::string sMCPars;
0059     std::string sGenPars;
0060     std::string sSimHits;
0061     std::string sRecHits;
0062     std::string sClusters;
0063     std::string sAssocs;
0064     std::vector<std::string> sFields;
0065   } m_config = {
0066     "RelationalHCalDebugTreeMaker",
0067     "MCParticles",
0068     "GeneratedParticles",
0069     "HcalEndcapNHits",
0070     "HcalEndcapNRecHits",
0071     "HcalEndcapNClusters",
0072     "HcalEndcapNClusterAssociations",
0073     {"layer", "slice"}
0074   };  // end Config
0075 
0076   // struct to hold class-wise constants
0077   struct Const {
0078     size_t nFieldMax;
0079   } m_const = {6};
0080 
0081   public:
0082 
0083     // ctor
0084     RelationalHCalDebugTreeMakerProcessor() { SetTypeName(NAME_OF_THIS); }
0085 
0086     // public methods
0087     void InitWithGlobalRootLock() override;
0088     void ProcessSequential(const std::shared_ptr<const JEvent>& event) override;
0089     void FinishWithGlobalRootLock() override;
0090 
0091   private:
0092 
0093     // internal methods
0094     void   InitializeDecoder();
0095     void   InitializeTree();
0096     void   ResetVariables();
0097     void   FillClusterVariables(const edm4eic::Cluster* clust, const int64_t iClust, const int64_t nCells, const int64_t nAssoc, const int64_t nContrib);
0098     void   FillCellVariables(const edm4eic::CalorimeterHit cell, const int64_t iClust);
0099     void   FillAssocVariables(const edm4hep::MCParticle mc, const int64_t iClust);
0100     void   FillContribVariables(const edm4hep::MCParticle mc, const int64_t iClust, const int64_t cellID);
0101     void   GetCellIndices(const int64_t cellID, std::vector<short>& indices);
0102     double GetTime(const double tIn);
0103     double GetEta(const double theta);
0104 
0105     // data objects we need from JANA
0106     PrefetchT<edm4hep::MCParticle>                       m_mcPars   = {this, m_config.sMCPars.data()};
0107     PrefetchT<edm4eic::ReconstructedParticle>            m_genPars  = {this, m_config.sGenPars.data()};
0108     PrefetchT<edm4hep::SimCalorimeterHit>                m_simHits  = {this, m_config.sSimHits.data()};
0109     PrefetchT<edm4eic::CalorimeterHit>                   m_recHits  = {this, m_config.sRecHits.data()};
0110     PrefetchT<edm4eic::Cluster>                          m_clusters = {this, m_config.sClusters.data()};
0111     PrefetchT<edm4eic::MCRecoClusterParticleAssociation> m_assocs   = {this, m_config.sAssocs.data()};
0112 
0113     // framework members
0114     dd4hep::BitFieldCoder* m_decoder;
0115 
0116     // i/o members
0117     TTree*      m_outTree;
0118     TDirectory* m_pluginDir;
0119 
0120     // event members
0121     uint64_t m_evtIndex;
0122     uint64_t m_nClust;
0123 
0124     // cluster members
0125     std::vector<uint64_t> m_clustIndex;
0126     std::vector<uint64_t> m_clustNCells;
0127     std::vector<uint64_t> m_clustNAssoc;
0128     std::vector<uint64_t> m_clustNContrib;
0129     std::vector<float>    m_clustEne;
0130     std::vector<float>    m_clustEta;
0131     std::vector<float>    m_clustPhi;
0132     std::vector<float>    m_clustRX;
0133     std::vector<float>    m_clustRY;
0134     std::vector<float>    m_clustRZ;
0135     std::vector<float>    m_clustTime;
0136 
0137     // cells in cluster members
0138     std::vector<uint64_t> m_cellID;
0139     std::vector<uint64_t> m_cellClustIndex;
0140     std::vector<float>    m_cellEne;
0141     std::vector<float>    m_cellRX;
0142     std::vector<float>    m_cellRY;
0143     std::vector<float>    m_cellRZ;
0144     std::vector<float>    m_cellTime;
0145     std::vector<short>    m_cellIndexA;
0146     std::vector<short>    m_cellIndexB;
0147     std::vector<short>    m_cellIndexC;
0148     std::vector<short>    m_cellIndexE;
0149     std::vector<short>    m_cellIndexF;
0150     std::vector<short>    m_cellIndexG;
0151 
0152     // mc particle associated to cluster members
0153     std::vector<uint64_t> m_assocClustIndex;
0154     std::vector<int32_t>  m_assocGenStat;
0155     std::vector<int32_t>  m_assocSimStat;
0156     std::vector<int32_t>  m_assocPDG;
0157     std::vector<float>    m_assocEne;
0158     std::vector<float>    m_assocPhi;
0159     std::vector<float>    m_assocEta;
0160     std::vector<float>    m_assocMass;
0161     std::vector<float>    m_assocStartVX;
0162     std::vector<float>    m_assocStartVY;
0163     std::vector<float>    m_assocStartVZ;
0164     std::vector<float>    m_assocStopVX;
0165     std::vector<float>    m_assocStopVY;
0166     std::vector<float>    m_assocStopVZ;
0167     std::vector<float>    m_assocTime;
0168 
0169     // mc particle contributing to cluster members
0170     std::vector<uint64_t> m_contribClustIndex;
0171     std::vector<uint64_t> m_contribCellID;
0172     std::vector<int32_t>  m_contribGenStat;
0173     std::vector<int32_t>  m_contribSimStat;
0174     std::vector<int32_t>  m_contribPDG;
0175     std::vector<float>    m_contribEne;
0176     std::vector<float>    m_contribPhi;
0177     std::vector<float>    m_contribEta;
0178     std::vector<float>    m_contribMass;
0179     std::vector<float>    m_contribStartVX;
0180     std::vector<float>    m_contribStartVY;
0181     std::vector<float>    m_contribStartVZ;
0182     std::vector<float>    m_contribStopVX;
0183     std::vector<float>    m_contribStopVY;
0184     std::vector<float>    m_contribStopVZ;
0185     std::vector<float>    m_contribTime;
0186 
0187 };  // end RelationalHCalDebugTreeMaker
0188 
0189 #endif
0190 
0191 // end ------------------------------------------------------------------------