Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef FILLCLUSMATCHTREE__H
0002 #define FILLCLUSMATCHTREE__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 "TrackClusEvaluator.h"
0047 #include "TrkrClusLoc.h"
0048 
0049 #include <fun4all/SubsysReco.h>
0050 
0051 #include <string>
0052 #include <vector>
0053 
0054 class EmbRecoMatchContainer;
0055 class PHCompositeNode;
0056 class PHG4ParticleSvtxMap;
0057 class SvtxPHG4ParticleMap;
0058 class EmbRecoMatchContainer;
0059 class PHCompositeNode;
0060 class PHG4TpcCylinderGeom;
0061 class PHG4TpcCylinderGeomContainer;
0062 class PHG4TruthInfoContainer;
0063 class SvtxTrack;
0064 class SvtxTrackMap;
0065 class TrackSeedContainer;
0066 class TrkrCluster;
0067 class TrkrTruthTrack;
0068 class TrkrTruthTrackContainer;
0069 class TTree;
0070 class TH2D;
0071 class ClusHitsVerbose;
0072 class TrkrClusterIsMatcher;
0073 
0074 class FillClusMatchTree : public SubsysReco
0075 {
0076  public:
0077   FillClusMatchTree(
0078       TrkrClusterIsMatcher *_ismatcher, const std::string &tfile_name = "trackclusmatch.root", bool _fill_clusters = true, bool _fill_clusverbose = true, bool _fill_svtxnomatch = false);
0079 
0080   virtual ~FillClusMatchTree() = default;
0081 
0082   int Init(PHCompositeNode *) override;
0083   int InitRun(PHCompositeNode *topNode) override;
0084   int process_event(PHCompositeNode * /*topNode*/) override;
0085   int End(PHCompositeNode *topNode) override;
0086 
0087   void clear_clusvecs(const std::string &tag = "");
0088 
0089   void print_mvtx_diagnostics();
0090 
0091   TrkrClusterIsMatcher *m_ismatcher;
0092 
0093  private:
0094   int createNodes(PHCompositeNode *topNode);
0095   TrackClusEvaluator m_TCEval;
0096 
0097   // contianer used to fill the other track matches
0098   EmbRecoMatchContainer *m_EmbRecoMatchContainer{nullptr};
0099   PHG4TruthInfoContainer *m_PHG4TruthInfoContainer{nullptr};
0100   SvtxTrackMap *m_SvtxTrackMap{nullptr};
0101   TrkrTruthTrackContainer *m_TrkrTruthTrackContainer{nullptr};
0102   ClusHitsVerbose *m_PHG4ClusHitVerb{nullptr};
0103   ClusHitsVerbose *m_SvtxClusHitVerb{nullptr};
0104   /* TrkrClusterContainer         *m_TruthClusterContainer        {nullptr}; */
0105   /* TrkrClusterContainer         *m_RecoClusterContainer         {nullptr}; */
0106   /* PHG4TpcCylinderGeomContainer *m_PHG4TpcCylinderGeomContainer {nullptr}; */
0107 
0108   TTree *m_ttree;
0109   std::string m_outfile_name;
0110 
0111  public:
0112   bool m_fill_clusters;
0113   bool m_fill_clusverbose;  // unmatched Svtx tracks
0114   bool m_fill_SvUnmatched;  // unmatched Svtx tracks
0115  private:
0116   // Tree Branch members:
0117   int nevent{-1};
0118   int nphg4{0};
0119   int nsvtx{0};
0120   int ntrackmatches{0};
0121   int nphg4_part{0};
0122   float centrality{0.};
0123 
0124   // Tracks and clustes
0125   //
0126   // lables:
0127   //  tracks:
0128   //    g4 : phg4track matched
0129   //    sv : svtx_track matched
0130   //    gU : phg4track not-matched
0131   //    sU : svtx_track not-matched
0132   //  clusters:
0133   //    M : matched
0134   //    U : unmatched
0135   TH2D *h2_G4_nPixelsPhi;
0136   TH2D *h2_G4_nPixelsZ;
0137   TH2D *h2_Sv_nPixelsPhi;
0138   TH2D *h2_Sv_nPixelsZ;
0139 
0140   // Track tree
0141   int b_trackid{};
0142   bool b_is_g4track{};
0143   bool b_is_Svtrack{};
0144   bool b_is_matched{};
0145 
0146   float b_trkpt{};
0147   float b_trkphi{};
0148   float b_trketa{};
0149 
0150   int b_nclus{};
0151   int b_nclustpc{};
0152   int b_nclusmvtx{};
0153   int b_nclusintt{};
0154 
0155   float b_matchrat{};
0156   float b_matchrat_intt{};
0157   float b_matchrat_mvtx{};
0158   float b_matchrat_tpc{};
0159 
0160   std::vector<bool> b_clusmatch{};
0161   std::vector<float> b_clus_x{};
0162   std::vector<float> b_clus_y{};
0163   std::vector<float> b_clus_z{};
0164   std::vector<float> b_clus_r{};
0165   std::vector<int> b_clus_layer{};
0166   /* std::vector<int>   b_clus_nphibins   {}; */
0167   /* std::vector<int>   b_clus_ntbins     {}; */
0168 
0169   std::vector<float> b_clus_lphi{};      // l for local surface
0170   std::vector<float> b_clus_lphisize{};  // phi scaled by dphi
0171   std::vector<float> b_clus_lz{};
0172   std::vector<float> b_clus_lzsize{};
0173 
0174   // Maps of hits within clusters
0175   /* using BinData = std::pair<int,float>;  // index + energy for a given bin (MVTX, INTT, or TPC) */
0176   using VecVecInt = std::vector<std::vector<int>>;
0177   /* using VecVecFloat = std::vector<std::vector<float>>; */
0178   VecVecInt b_phibins;
0179   VecVecInt b_phibins_cut;
0180   VecVecInt b_zbins;
0181   VecVecInt b_zbins_cut;
0182 
0183   VecVecInt b_phibinsE;
0184   VecVecInt b_phibinsE_cut;
0185   VecVecInt b_zbinsE;
0186   VecVecInt b_zbinsE_cut;
0187 
0188   void fill_cluster_branches(TrkrClusLoc &, bool isPHG4 = true);
0189   /* void pushback_verb_bins(TrkrDefs::cluskey, bool isPHG4=true); */
0190 };
0191 
0192 #endif  // FILLTRUTHRECOMATCHTREE_H