Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:20:17

0001 /*
0002  * This file is part of KFParticle package
0003  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
0004  *               2007-2019 Goethe University of Frankfurt
0005  *               2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
0006  *               2007-2019 Maksym Zyzak
0007  *
0008  * KFParticle is free software: you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License as published by
0010  * the Free Software Foundation, either version 3 of the License, or
0011  * (at your option) any later version.
0012  *
0013  * KFParticle is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  *
0018  * You should have received a copy of the GNU General Public License
0019  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0020  */
0021 
0022 #ifndef KFPARTICLESPHENIX_KFPARTICLETOOLS_H
0023 #define KFPARTICLESPHENIX_KFPARTICLETOOLS_H
0024 
0025 #include "KFParticle_MVA.h"
0026 
0027 #include <globalvertex/MbdVertex.h>
0028 #include <globalvertex/MbdVertexMap.h>
0029 
0030 #include <KFParticle.h>
0031 
0032 #include <TF1.h>
0033 
0034 #include <limits>
0035 #include <string>   // for string
0036 #include <tuple>    // for tuple
0037 #include <utility>  // for pair
0038 #include <vector>
0039 
0040 class PHCompositeNode;
0041 
0042 class SvtxVertexMap;
0043 class SvtxTrackMap;
0044 class SvtxVertex;
0045 class SvtxTrack;
0046 class GlobalVertexMap;
0047 class GlobalVertex;
0048 class TrkrClusterContainer;
0049 class PHG4TpcGeomContainer;
0050 
0051 class KFParticle_Tools : protected KFParticle_MVA
0052 {
0053  public:
0054   KFParticle_Tools();
0055 
0056   ~KFParticle_Tools() override = default;
0057 
0058   KFParticle makeVertex(PHCompositeNode *topNode);
0059 
0060   std::vector<KFParticle> makeAllPrimaryVertices(PHCompositeNode *topNode, const std::string &vertexMapName);
0061 
0062   KFParticle makeParticle(PHCompositeNode *topNode);
0063 
0064   std::vector<KFParticle> makeAllDaughterParticles(PHCompositeNode *topNode);
0065 
0066   void getTracksFromBC(PHCompositeNode *topNode, const int &bunch_crossing, const std::string &vertexMapName, int &nTracks, int &nPVs);
0067 
0068   int getTracksFromVertex(PHCompositeNode *topNode, const KFParticle &vertex, const std::string &vertexMapName);
0069 
0070   /*const*/ bool isGoodTrack(const KFParticle &particle, const std::vector<KFParticle> &primaryVertices);
0071 
0072   int calcMinIP(const KFParticle &track, const std::vector<KFParticle> &PVs, float &minimumIP, float &minimumIPchi2, bool do3D = true);
0073 
0074   std::vector<int> findAllGoodTracks(const std::vector<KFParticle> &daughterParticles, const std::vector<KFParticle> &primaryVertices);
0075 
0076   std::vector<std::vector<int>> findTwoProngs(std::vector<KFParticle> daughterParticles, std::vector<int> goodTrackIndex, int nTracks);
0077 
0078   std::vector<std::vector<int>> findNProngs(std::vector<KFParticle> daughterParticles,
0079                                             const std::vector<int> &goodTrackIndex,
0080                                             std::vector<std::vector<int>> goodTracksThatMeet,
0081                                             int nRequiredTracks, unsigned int nProngs);
0082 
0083   std::vector<std::vector<int>> appendTracksToIntermediates(KFParticle intermediateResonances[], const std::vector<KFParticle> &daughterParticles, const std::vector<int> &goodTrackIndex, int num_remaining_tracks);
0084 
0085   /// Calculates the cosine of the angle betweent the flight direction and momentum
0086   float eventDIRA(const KFParticle &particle, const KFParticle &vertex, bool do3D = true);
0087 
0088   float flightDistanceChi2(const KFParticle &particle, const KFParticle &vertex);
0089 
0090   std::tuple<KFParticle, bool> buildMother(KFParticle vDaughters[], int daughterOrder[], bool isIntermediate, int intermediateNumber, int nTracks, bool constrainMass, float required_vertexID, PHCompositeNode* topNode);
0091 
0092   void constrainToVertex(KFParticle &particle, bool &goodCandidate, KFParticle &vertex);
0093 
0094   std::tuple<KFParticle, bool> getCombination(KFParticle vDaughters[], int daughterOrder[], KFParticle vertex,
0095                                               bool constrain_to_vertex, bool isIntermediate, int intermediateNumber, int nTracks, bool constrainMass, float required_vertexID, PHCompositeNode* topNode);
0096 
0097   std::vector<std::vector<int>> findUniqueDaughterCombinations(int start, int end);
0098 
0099   double calculateEllipsoidRadius(int posOrNeg, double sigma_ii, double sigma_jj, double sigma_ij);
0100 
0101   float calculateEllipsoidVolume(const KFParticle &particle);
0102 
0103   float calculateJT(const KFParticle &mother, const KFParticle &daughter);
0104 
0105   bool isInRange(float min, float value, float max);
0106 
0107   bool findParticle(const std::string &particle);
0108 
0109   int getParticleID(const std::string &particle);
0110 
0111   float getParticleMass(const std::string &particle);
0112   float getParticleMass(const int PDGID);
0113 
0114   void identify(const KFParticle &particle);
0115 
0116   float get_dEdx(PHCompositeNode *topNode, const KFParticle &daughter);
0117 
0118   void init_dEdx_fits();
0119 
0120   double get_dEdx_fitValue(float momentum, int PID);
0121 
0122   bool checkTrackAndVertexMatch(KFParticle vDaughters[], int nTracks, KFParticle vertex);
0123 
0124   void set_dont_use_global_vertex(bool set_variable){ m_dont_use_global_vertex = set_variable; }
0125 
0126  protected:
0127   std::string m_mother_name_Tools;
0128   int m_num_intermediate_states {-1};
0129   std::vector<int> m_num_tracks_from_intermediate;
0130   std::vector<std::string> m_daughter_name;
0131   std::vector<int> m_daughter_charge;
0132   int m_num_tracks {-1};
0133 
0134   bool m_has_intermediates;
0135   std::vector<std::string> m_intermediate_name;
0136   std::vector<int> m_intermediate_charge;
0137   std::vector<std::pair<float, float>> m_intermediate_mass_range;
0138   std::vector<float> m_intermediate_min_pt;
0139   std::vector<float> m_intermediate_min_dira;
0140   std::vector<float> m_intermediate_min_fdchi2;
0141   std::vector<float> m_intermediate_min_ip_xy;
0142   std::vector<float> m_intermediate_max_ip_xy;
0143   std::vector<float> m_intermediate_min_ipchi2_xy;
0144   std::vector<float> m_intermediate_max_ipchi2_xy;
0145   std::vector<float> m_intermediate_min_ip;
0146   std::vector<float> m_intermediate_max_ip;
0147   std::vector<float> m_intermediate_min_ipchi2;
0148   std::vector<float> m_intermediate_max_ipchi2;
0149   std::vector<float> m_intermediate_vertex_volume;
0150 
0151   bool m_use_PID{false};
0152   float m_dEdx_band_width {0.2}; //Fraction of expected dE/dx
0153   
0154   TF1 *f_pion_plus{nullptr};
0155   TF1 *f_kaon_plus{nullptr};
0156   TF1 *f_proton_plus{nullptr};
0157   TF1 *f_pion_minus{nullptr};
0158   TF1 *f_kaon_minus{nullptr};
0159   TF1 *f_proton_minus{nullptr};
0160 
0161   std::map<int, TF1*> pidMap;
0162 
0163   float m_min_mass {-1};
0164 
0165   float m_max_mass {-1};
0166 
0167   float m_min_decayTime_xy {-1000};
0168 
0169   float m_max_decayTime_xy {std::numeric_limits<float>::max()};
0170 
0171   float m_min_decayLength_xy {-1000};
0172 
0173   float m_max_decayLength_xy {std::numeric_limits<float>::max()};
0174 
0175   float m_min_decayTime {-1000};
0176 
0177   float m_max_decayTime {std::numeric_limits<float>::max()};
0178 
0179   float m_min_decayLength {-1000};
0180 
0181   float m_max_decayLength {std::numeric_limits<float>::max()};
0182 
0183   float m_mother_min_decay_time_significance {-1};
0184 
0185   float m_mother_min_decay_length_significance {-1};
0186 
0187   float m_mother_min_decay_length_xy_significance {-1};
0188 
0189   float m_track_min_pt {-1};
0190 
0191   float m_track_max_pt {5e3};
0192 
0193   float m_track_ptchi2 {std::numeric_limits<float>::max()};
0194 
0195   float m_track_ip_xy {-100};
0196 
0197   float m_track_ipchi2_xy {-1000};
0198 
0199   float m_track_ip {-1};
0200 
0201   float m_track_ipchi2 {-1};
0202 
0203   float m_track_chi2ndof {std::numeric_limits<float>::max()};
0204 
0205   int m_nMVTXStates {2};
0206 
0207   int m_nINTTStates {1};
0208 
0209   int m_nTPCStates {20};
0210 
0211   int m_nTPOTStates {0};
0212 
0213   float m_comb_DCA_xy {std::numeric_limits<float>::max()};
0214 
0215   float m_comb_DCA {std::numeric_limits<float>::max()};
0216 
0217   float m_vertex_chi2ndof {std::numeric_limits<float>::max()};
0218 
0219   float m_fdchi2 {-1};
0220 
0221   float m_dira_xy_min {-1};
0222 
0223   float m_dira_xy_max {1};
0224 
0225   float m_dira_min {-1};
0226 
0227   float m_dira_max {1};
0228 
0229   float m_mother_pt {-1};
0230 
0231   float m_mother_ip {std::numeric_limits<float>::max()};
0232 
0233   float m_mother_ipchi2 {std::numeric_limits<float>::max()};
0234 
0235   float m_mother_ip_xy {std::numeric_limits<float>::max()};
0236 
0237   float m_mother_ipchi2_xy {std::numeric_limits<float>::max()};
0238 
0239   float m_mother_vertex_volume {std::numeric_limits<float>::max()};
0240 
0241   float m_mva_cut_value {-1};
0242 
0243   bool m_get_charge_conjugate {false};
0244 
0245   bool m_extrapolateTracksToSV {true};
0246 
0247   bool m_allowZeroMassTracks {false};
0248 
0249   bool m_use_2D_matching_tools {false};
0250 
0251   float m_min_radial_SV = -1.;
0252 
0253   bool m_bunch_crossing_zero_only {false};  
0254 
0255   bool m_require_bunch_crossing_match {true};
0256 
0257   bool m_use_mbd_vertex {false};
0258 
0259   bool m_dont_use_global_vertex {false};
0260 
0261   bool m_require_track_and_vertex_match {false};
0262 
0263   std::string m_vtx_map_node_name;
0264   std::string m_trk_map_node_name;
0265   GlobalVertexMap *m_dst_globalvertexmap {nullptr};
0266   GlobalVertex *m_dst_globalvertex {nullptr};
0267   MbdVertexMap *m_dst_mbdvertexmap {nullptr};
0268   MbdVertex *m_dst_mbdvertex {nullptr};
0269   SvtxTrackMap *m_dst_trackmap {nullptr};
0270   SvtxTrack *m_dst_track {nullptr};
0271   SvtxVertexMap *m_dst_vertexmap {nullptr};
0272   SvtxVertex *m_dst_vertex {nullptr};
0273   TrkrClusterContainer *m_cluster_map {nullptr};
0274   PHG4TpcGeomContainer *m_geom_container {nullptr};
0275 
0276   void removeDuplicates(std::vector<double> &v);
0277   void removeDuplicates(std::vector<int> &v);
0278   void removeDuplicates(std::vector<std::vector<int>> &v);
0279   void removeDuplicates(std::vector<std::vector<std::string>> &v);
0280 };
0281 
0282 #endif  // KFPARTICLESPHENIX_KFPARTICLETOOLS_H