Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:08

0001 #ifndef FILLTRUTHRECOMATCHTREE_H
0002 #define FILLTRUTHRECOMATCHTREE_H
0003 
0004 /**
0005  * @file trackbase/TrkrMatchDefs.h
0006  * @author D. Stewart
0007  * @date February 2023
0008  * @brief Write a TFile with a TTree with the matched tracks and (optionall) clusters
0009  *   This module takes the matching done in TruthRecoTrackMatching in the
0010  *   EmbRecoMatchContainer objects, and writes out the tracks kinematics to TTree
0011  *   in a TFile.
0012  *    The following data is always written out:
0013  *      For each track type:
0014  *          G4M : PHG4 matched
0015  *          G4U : PHG4 unmatched
0016  *          SvM : Svtx (reco) matched
0017  *          SvU : SVtx (reco) unmatched
0018  *      The following is stored:
0019  *          trackid, nclus, nclus{mvtx,intt,tpc}, pt, phi, eta
0020  *      For matched tracks (G4M and SvM):
0021  *           nclus_matchrat, nclus{mvtx,intt,tpc}_matchrat
0022  *      For matched tracks, the numbers of matched clusters (these are shared by G4M and SvM):
0023  *           nclusM, nclusM_{mvtx,intt,tpc}
0024  *
0025  *    If the option is passed to save clusteres (default is on), then the cluster
0026  *    locations are saved too, as unmatched clusters (in all types of tracks),
0027  *    and the mutually matched clusters (shared by the G4M and SvM tracks):
0028  *      {G4U,G4M,SvU,SvM}_clusU_{i0,i1,x,y,z,r}
0029  *    For matche clusters, these are simply:
0030  *      clusM_{i0,i1,x,y,z,r,layer}
0031  *    The vectors of x,y,z,r are stoped in each branch with each tracks' data sequentially
0032  *    following the last. The branch i0 and i1 index where the one starts and the other stops.
0033  *    for each track.
0034  *
0035  *    Data for matched tracks positionally align with each other (i.e. 1st entry in each
0036  *    correlate, then the 2nd, etc...)
0037  *
0038  *    A track is only an unmatched track is it has no matches (the options in
0039  *    TruthRecoTrackMatching can allow multiply matches for the same track...)
0040  *
0041  *    options:
0042  *      save cluster locations = true
0043  *      save un-matched Svtx tracks = false
0044  */
0045 
0046 #include "g4evaltools.h"
0047 
0048 #include <fun4all/SubsysReco.h>
0049 #include <string>
0050 #include <vector>
0051 
0052 class EmbRecoMatchContainer;
0053 class PHCompositeNode;
0054 class PHG4ParticleSvtxMap;
0055 class SvtxPHG4ParticleMap;
0056 class EmbRecoMatchContainer;
0057 class PHCompositeNode;
0058 class PHG4TpcCylinderGeom;
0059 class PHG4TpcCylinderGeomContainer;
0060 class PHG4TruthInfoContainer;
0061 class SvtxTrack;
0062 class SvtxTrackMap;
0063 class TrackSeedContainer;
0064 class TrkrCluster;
0065 /* class TrkrClusterContainer; */
0066 class TrkrTruthTrack;
0067 class TrkrTruthTrackContainer;
0068 class TTree;
0069 class TH2D;
0070 
0071 class FillTruthRecoMatchTree : public SubsysReco
0072 {
0073  public:
0074   FillTruthRecoMatchTree(
0075       bool _fill_clusters = true, bool _fill_svtxnomatch = false, float _cluster_nzwidths = 0.5, float _cluster_nphiwidths = 0.5, const std::string &tfile_name = "trackclusmatch.root");
0076 
0077   virtual ~FillTruthRecoMatchTree();
0078 
0079   int Init(PHCompositeNode *) override;
0080   int InitRun(PHCompositeNode *topNode) override;
0081   int process_event(PHCompositeNode * /*topNode*/) override;
0082   int End(PHCompositeNode *topNode) override;
0083 
0084   void clear_clusvecs(const std::string &tag = "");
0085 
0086   void print_mvtx_diagnostics();
0087 
0088  private:
0089   int createNodes(PHCompositeNode *topNode);
0090 
0091   G4Eval::TrkrClusterComparer m_cluster_comp{1., 1.};
0092   G4Eval::ClusCntr m_cluscntr;
0093 
0094   // contianer used to fill the other track matches
0095   EmbRecoMatchContainer *m_EmbRecoMatchContainer{nullptr};
0096   PHG4TruthInfoContainer *m_PHG4TruthInfoContainer{nullptr};
0097   SvtxTrackMap *m_SvtxTrackMap{nullptr};
0098   /* TrkrClusterContainer         *m_TruthClusterContainer        {nullptr}; */
0099   /* TrkrClusterContainer         *m_RecoClusterContainer         {nullptr}; */
0100   TrkrTruthTrackContainer *m_TrkrTruthTrackContainer{nullptr};
0101   /* PHG4TpcCylinderGeomContainer *m_PHG4TpcCylinderGeomContainer {nullptr}; */
0102 
0103   TTree *m_ttree;
0104   bool m_fill_clusters;
0105   bool m_fill_SvU;  // unmatched Svtx tracks
0106   std::string m_outfile_name;
0107 
0108   // Tree Branch members:
0109   int nevent{-1};
0110   int nphg4{0};
0111   int nsvtx{0};
0112   int ntrackmatches{0};
0113   int nphg4_part{0};
0114   float centrality{0.};
0115 
0116   // Tracks and clustes
0117   //
0118   // lables:
0119   //  tracks:
0120   //    g4 : phg4track matched
0121   //    sv : svtx_track matched
0122   //    gU : phg4track not-matched
0123   //    sU : svtx_track not-matched
0124   //  clusters:
0125   //    M : matched
0126   //    U : unmatched
0127   TH2D *h2_G4_nPixelsPhi;
0128   TH2D *h2_G4_nPixelsZ;
0129   TH2D *h2_Sv_nPixelsPhi;
0130   TH2D *h2_Sv_nPixelsZ;
0131 
0132   // Track tree
0133   int b_trackid{};
0134   bool b_is_g4track{};
0135   bool b_is_Svtrack{};
0136   bool b_is_matched{};
0137 
0138   float b_trkpt{};
0139   float b_trkphi{};
0140   float b_trketa{};
0141 
0142   int b_nclus{};
0143   int b_nclustpc{};
0144   int b_nclusmvtx{};
0145   int b_nclusintt{};
0146 
0147   float b_matchrat{};
0148   float b_matchrat_intt{};
0149   float b_matchrat_mvtx{};
0150   float b_matchrat_tpc{};
0151 
0152   std::vector<bool> b_clusmatch{};
0153   std::vector<float> b_clus_x{};
0154   std::vector<float> b_clus_y{};
0155   std::vector<float> b_clus_z{};
0156   std::vector<float> b_clus_r{};
0157   std::vector<int> b_clus_layer{};
0158   std::vector<int> b_clus_nphibins{};
0159   std::vector<int> b_clus_ntbins{};
0160 
0161   /* std::vector<int>   b_G4M_trackid            {}; // g4-track-matched */
0162   /* std::vector<int>   b_G4M_nclus              {}; */
0163   /* std::vector<int>   b_G4M_nclusmvtx          {}; */
0164   /* std::vector<int>   b_G4M_nclusintt          {}; */
0165   /* std::vector<int>   b_G4M_nclustpc           {}; */
0166   /* std::vector<float> b_G4M_nclus_matchrat     {}; */
0167   /* std::vector<float> b_G4M_nclusmvtx_matchrat {}; */
0168   /* std::vector<float> b_G4M_nclusintt_matchrat {}; */
0169   /* std::vector<float> b_G4M_nclustpc_matchrat  {}; */
0170   /* std::vector<float> b_G4M_pt                 {}; */
0171   /* std::vector<float> b_G4M_phi                {}; */
0172   /* std::vector<float> b_G4M_eta                {}; */
0173   /* std::vector<int>   b_SvM_trackid            {}; // Svtx-track-matched */
0174   /* std::vector<int>   b_SvM_nclus              {}; */
0175   /* std::vector<int>   b_SvM_nclusmvtx          {}; */
0176   /* std::vector<int>   b_SvM_nclusintt          {}; */
0177   /* std::vector<int>   b_SvM_nclustpc           {}; */
0178   /* std::vector<float> b_SvM_nclus_matchrat     {}; */
0179   /* std::vector<float> b_SvM_nclusmvtx_matchrat {}; */
0180   /* std::vector<float> b_SvM_nclusintt_matchrat {}; */
0181   /* std::vector<float> b_SvM_nclustpc_matchrat  {}; */
0182   /* std::vector<float> b_SvM_pt                 {}; */
0183   /* std::vector<float> b_SvM_phi                {}; */
0184   /* std::vector<float> b_SvM_eta                {}; */
0185   /* std::vector<int>   b_clusM_i0               {}; // if storing clusters -- matched clusters */
0186   /* std::vector<int>   b_clusM_i1               {}; */
0187   /* std::vector<float> b_clusM_layer            {}; */
0188   /* std::vector<float> b_clusM_x                {}; */
0189   /* std::vector<float> b_clusM_y                {}; */
0190   /* std::vector<float> b_clusM_z                {}; */
0191   /* std::vector<float> b_clusM_r                {}; */
0192   /* std::vector<int>   b_G4M_clusU_i0           {}; // matched phg4 unmatched clusters */
0193   /* std::vector<int>   b_G4M_clusU_i1           {}; */
0194   /* std::vector<float> b_G4M_clusU_layer        {}; */
0195   /* std::vector<float> b_G4M_clusU_x            {}; */
0196   /* std::vector<float> b_G4M_clusU_y            {}; */
0197   /* std::vector<float> b_G4M_clusU_z            {}; */
0198   /* std::vector<float> b_G4M_clusU_r            {}; */
0199   /* std::vector<int>   b_SvM_clusU_i0           {}; //  matched phg4 unmatched clusters */
0200   /* std::vector<int>   b_SvM_clusU_i1           {}; */
0201   /* std::vector<float> b_SvM_clusU_layer        {}; */
0202   /* std::vector<float> b_SvM_clusU_x            {}; */
0203   /* std::vector<float> b_SvM_clusU_y            {}; */
0204   /* std::vector<float> b_SvM_clusU_z            {}; */
0205   /* std::vector<float> b_SvM_clusU_r            {}; */
0206   /* std::vector<int>   b_G4U_trackid            {}; // unmatched tracks */
0207   /* std::vector<int>   b_G4U_nclus              {}; */
0208   /* std::vector<int>   b_G4U_nclusmvtx          {}; */
0209   /* std::vector<int>   b_G4U_nclusintt          {}; */
0210   /* std::vector<int>   b_G4U_nclustpc           {}; */
0211   /* std::vector<float> b_G4U_pt                 {}; */
0212   /* std::vector<float> b_G4U_phi                {}; */
0213   /* std::vector<float> b_G4U_eta                {}; */
0214   /* std::vector<int>   b_SvU_trackid            {}; // Svtx-track-matched */
0215   /* std::vector<int>   b_SvU_nclus              {}; */
0216   /* std::vector<int>   b_SvU_nclusmvtx          {}; */
0217   /* std::vector<int>   b_SvU_nclusintt          {}; */
0218   /* std::vector<int>   b_SvU_nclustpc           {}; */
0219   /* std::vector<float> b_SvU_pt                 {}; */
0220   /* std::vector<float> b_SvU_phi                {}; */
0221   /* std::vector<float> b_SvU_eta                {}; */
0222   /* std::vector<int>   b_G4U_clusU_i0           {}; // unmatched phg4 unmatched clusters */
0223   /* std::vector<int>   b_G4U_clusU_i1           {}; */
0224   /* std::vector<float> b_G4U_clusU_layer        {}; */
0225   /* std::vector<float> b_G4U_clusU_x            {}; */
0226   /* std::vector<float> b_G4U_clusU_y            {}; */
0227   /* std::vector<float> b_G4U_clusU_z            {}; */
0228   /* std::vector<float> b_G4U_clusU_r            {}; */
0229   /* std::vector<int>   b_SvU_clusU_i0           {}; // unmatched phg4 unmatched clusters */
0230   /* std::vector<int>   b_SvU_clusU_i1           {}; */
0231   /* std::vector<float> b_SvU_clusU_layer        {}; */
0232   /* std::vector<float> b_SvU_clusU_x            {}; */
0233   /* std::vector<float> b_SvU_clusU_y            {}; */
0234   /* std::vector<float> b_SvU_clusU_z            {}; */
0235   /* std::vector<float> b_SvU_clusU_r            {}; */
0236 };
0237 
0238 #endif  // FILLTRUTHRECOMATCHTREE_H