Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:17:56

0001 #ifndef G4EVAL_EVENTEVALUATOR_H
0002 #define G4EVAL_EVENTEVALUATOR_H
0003 
0004 //===============================================
0005 /// \file EventEvaluator.h
0006 /// \brief Compares reconstructed tracks to truth particles
0007 /// \author Michael P. McCumber (revised sPHENIX version)
0008 //===============================================
0009 
0010 #include <fun4all/SubsysReco.h>
0011 
0012 #include <set>
0013 #include <string>
0014 
0015 class CaloEvalStack;
0016 class PHCompositeNode;
0017 class PHHepMCGenEventMap;
0018 class PHHepMCGenEvent;
0019 class TFile;
0020 class TNtuple;
0021 class TTree;  // Added by Barak
0022 
0023 /// \class EventEvaluator
0024 ///
0025 /// \brief Compares reconstructed showers to truth particles
0026 ///
0027 /// Plan: This module will trace the reconstructed clusters back to
0028 /// the greatest contributor Monte Carlo particle and then
0029 /// test one against the other.
0030 ///
0031 class EventEvaluator : public SubsysReco
0032 {
0033  public:
0034   enum class TrackSource_t : unsigned short
0035   {
0036     all = 0,
0037     inner = 1
0038   };
0039 
0040   EventEvaluator(const std::string& name = "EventEvaluator",
0041                  const std::string& filename = "g4eval_cemc.root");
0042   ~EventEvaluator() override{};
0043 
0044   int Init(PHCompositeNode* topNode) override;
0045   int process_event(PHCompositeNode* topNode) override;
0046   int End(PHCompositeNode* topNode) override;
0047 
0048   void set_strict(bool b) { _strict = b; }
0049 
0050   void set_do_store_event_level_info(bool b) { _do_store_event_info = b; }
0051   void set_do_HCALIN(bool b) { _do_HCALIN = b; }
0052   void set_do_HCALOUT(bool b) { _do_HCALOUT = b; }
0053   void set_do_CEMC(bool b) { _do_CEMC = b; }
0054   void set_do_HITS(bool b) { _do_HITS = b; }
0055   void set_do_TRACKS(bool b) { _do_TRACKS = b; }
0056   void set_do_CLUSTERS(bool b) { _do_CLUSTERS = b; }
0057   void set_do_VERTEX(bool b) { _do_VERTEX = b; }
0058   void set_do_PROJECTIONS(bool b) { _do_PROJECTIONS = b; }
0059   void set_do_MCPARTICLES(bool b) { _do_MCPARTICLES = b; }
0060   void set_do_HEPMC(bool b) { _do_HEPMC = b; }
0061   void set_do_GEOMETRY(bool b) { _do_GEOMETRY = b; }
0062 
0063   // limit the tracing of towers and clusters back to the truth particles
0064   // to only those reconstructed objects above a particular energy
0065   // threshold (evaluation for objects above threshold unaffected)
0066   void set_reco_tracing_energy_threshold(float thresh)
0067   {
0068     _reco_e_threshold = thresh;
0069   }
0070   void set_reco_tracing_energy_threshold_BECAL(float thresh)
0071   {
0072     _reco_e_threshold_BECAL = thresh;
0073   }
0074 
0075   //! max depth/generation of the MC_particle/PHG4Particle that would be saved.
0076   void set_depth_MCstack(int d)
0077   {
0078     _depth_MCstack = d;
0079   }
0080 
0081  private:
0082   bool _do_store_event_info = false;
0083   bool _do_HCALIN = false;
0084   bool _do_HCALOUT = false;
0085   bool _do_CEMC = false;
0086   bool _do_HITS = false;
0087   bool _do_TRACKS = false;
0088   bool _do_CLUSTERS = false;
0089   bool _do_VERTEX = false;
0090   bool _do_PROJECTIONS = false;
0091   bool _do_MCPARTICLES = false;
0092   bool _do_HEPMC = false;
0093   bool _do_GEOMETRY = false;
0094   unsigned int _ievent = 0;
0095 
0096   // Event level info
0097   float _cross_section = 0.;
0098   float _event_weight = 0.;
0099   int _n_generator_accepted = 0;
0100 
0101   // track hits
0102   int _nHitsLayers = 0;
0103   int* _hits_layerID = nullptr;
0104   int* _hits_trueID = nullptr;
0105   float* _hits_x = nullptr;
0106   float* _hits_y = nullptr;
0107   float* _hits_z = nullptr;
0108   float* _hits_t = nullptr;
0109 
0110   // towers
0111   int _nTowers_HCALIN = 0;
0112   float* _tower_HCALIN_E = nullptr;
0113   int* _tower_HCALIN_iEta = nullptr;
0114   int* _tower_HCALIN_iPhi = nullptr;
0115   int* _tower_HCALIN_trueID = nullptr;
0116 
0117   int _nTowers_HCALOUT = 0;
0118   float* _tower_HCALOUT_E = nullptr;
0119   int* _tower_HCALOUT_iEta = nullptr;
0120   int* _tower_HCALOUT_iPhi = nullptr;
0121   int* _tower_HCALOUT_trueID = nullptr;
0122 
0123   int _nTowers_CEMC = 0;
0124   float* _tower_CEMC_E = nullptr;
0125   int* _tower_CEMC_iEta = nullptr;
0126   int* _tower_CEMC_iPhi = nullptr;
0127   int* _tower_CEMC_trueID = nullptr;
0128 
0129   // clusters
0130   int _nclusters_HCALIN = 0;
0131   float* _cluster_HCALIN_E = nullptr;
0132   float* _cluster_HCALIN_Eta = nullptr;
0133   float* _cluster_HCALIN_Phi = nullptr;
0134   int* _cluster_HCALIN_NTower = nullptr;
0135   int* _cluster_HCALIN_trueID = nullptr;
0136 
0137   int _nclusters_HCALOUT = 0;
0138   float* _cluster_HCALOUT_E = nullptr;
0139   float* _cluster_HCALOUT_Eta = nullptr;
0140   float* _cluster_HCALOUT_Phi = nullptr;
0141   int* _cluster_HCALOUT_NTower = nullptr;
0142   int* _cluster_HCALOUT_trueID = nullptr;
0143 
0144   int _nclusters_CEMC = 0;
0145   float* _cluster_CEMC_E = nullptr;
0146   float* _cluster_CEMC_Eta = nullptr;
0147   float* _cluster_CEMC_Phi = nullptr;
0148   int* _cluster_CEMC_NTower = nullptr;
0149   int* _cluster_CEMC_trueID = nullptr;
0150 
0151   // vertex
0152   float _vertex_x = 0.;
0153   float _vertex_y = 0.;
0154   float _vertex_z = 0.;
0155   int _vertex_NCont = 0;
0156   float _vertex_true_x = 0.;
0157   float _vertex_true_y = 0.;
0158   float _vertex_true_z = 0.;
0159 
0160   // tracks
0161   int _nTracks = 0;
0162   float* _track_ID = nullptr;
0163   float* _track_px = nullptr;
0164   float* _track_py = nullptr;
0165   float* _track_pz = nullptr;
0166   float* _track_dca = nullptr;
0167   float* _track_dca_2d = nullptr;
0168   float* _track_trueID = nullptr;
0169   unsigned short* _track_source = nullptr;
0170 
0171   int _nProjections = 0;
0172   float* _track_ProjTrackID = nullptr;
0173   int* _track_ProjLayer = nullptr;
0174   float* _track_TLP_x = nullptr;
0175   float* _track_TLP_y = nullptr;
0176   float* _track_TLP_z = nullptr;
0177   float* _track_TLP_t = nullptr;
0178   float* _track_TLP_true_x = nullptr;
0179   float* _track_TLP_true_y = nullptr;
0180   float* _track_TLP_true_z = nullptr;
0181   float* _track_TLP_true_t = nullptr;
0182 
0183   // MC particles
0184   int _nMCPart = 0;
0185   int* _mcpart_ID = nullptr;
0186   int* _mcpart_ID_parent = nullptr;
0187   int* _mcpart_PDG = nullptr;
0188   float* _mcpart_E = nullptr;
0189   float* _mcpart_px = nullptr;
0190   float* _mcpart_py = nullptr;
0191   float* _mcpart_pz = nullptr;
0192   int* _mcpart_BCID = nullptr;
0193 
0194   // MC particles
0195   int _nHepmcp = 0;
0196   int _hepmcp_procid = 0;
0197   float _hepmcp_x1 = 0.;
0198   float _hepmcp_x2 = 0.;
0199   //  float* _hepmcp_ID_parent;
0200   int* _hepmcp_status = nullptr;
0201   int* _hepmcp_PDG = nullptr;
0202   float* _hepmcp_E = nullptr;
0203   float* _hepmcp_px = nullptr;
0204   float* _hepmcp_py = nullptr;
0205   float* _hepmcp_pz = nullptr;
0206   int* _hepmcp_m1 = nullptr;
0207   int* _hepmcp_m2 = nullptr;
0208   int* _hepmcp_BCID = nullptr;
0209 
0210   int _calo_ID = 0;
0211   int _calo_towers_N = 0;
0212   int* _calo_towers_iEta = nullptr;
0213   int* _calo_towers_iPhi = nullptr;
0214   float* _calo_towers_Eta = nullptr;
0215   float* _calo_towers_Phi = nullptr;
0216   float* _calo_towers_x = nullptr;
0217   float* _calo_towers_y = nullptr;
0218   float* _calo_towers_z = nullptr;
0219   int* _geometry_done = nullptr;
0220 
0221   float _reco_e_threshold = 0.;
0222   float _reco_e_threshold_BECAL = 0.;
0223   int _depth_MCstack = 0;
0224 
0225   CaloEvalStack* _caloevalstackHCALIN = nullptr;
0226   CaloEvalStack* _caloevalstackHCALOUT = nullptr;
0227   CaloEvalStack* _caloevalstackCEMC = nullptr;
0228 
0229   //----------------------------------
0230   // evaluator output ntuples
0231 
0232   bool _strict = false;
0233 
0234   TTree* _event_tree = nullptr;     // Added by Barak
0235   TTree* _geometry_tree = nullptr;  // Added by Barak
0236 
0237   // evaluator output file
0238   std::string _filename;
0239   TFile* _tfile = nullptr;
0240   TFile* _tfile_geometry = nullptr;
0241 
0242   // subroutines
0243   int GetProjectionIndex(const std::string& projname);    ///< return track projection index for given track projection layer
0244   std::string GetProjectionNameFromIndex(int projindex);  ///< return track projection layer name from projection index (see GetProjectionIndex)
0245   void fillOutputNtuples(PHCompositeNode* topNode);       ///< dump the evaluator information into ntuple for external analysis
0246   void resetGeometryArrays();                             ///< reset the tree variables before filling for a new event
0247   void resetBuffer();                                     ///< reset the tree variables before filling for a new event
0248 
0249   const int _maxNHits = 10000;
0250   const int _maxNTowersCentral = 2000;
0251   const int _maxNTowersCalo = 5000000;
0252   const int _maxNclustersCentral = 2000;
0253   const int _maxNTracks = 200;
0254   const int _maxNProjections = 2000;
0255   const int _maxNMCPart = 100000;
0256   const int _maxNHepmcp = 1000;
0257 
0258   enum calotype
0259   {
0260     kCEMC = 0,
0261     kHCALIN = 1,
0262     kHCALOUT = 2
0263   };
0264 };
0265 
0266 #endif  // G4EVAL_EVENTEVALUATOR_H