Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:17:13

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_KFPARTICLESPHENIX_H
0023 #define KFPARTICLESPHENIX_KFPARTICLESPHENIX_H
0024 
0025 #include "KFParticle_eventReconstruction.h"
0026 
0027 // There is something broken in this package. clang format puts
0028 // #include "KFParticle_DST.h" first if there is no space but then
0029 // loading KFParticle makes root barf. I have no time to track this down
0030 // right now, it must be something in KFParticle_eventReconstruction.h and
0031 // the include files it uses (some include guard misfiring?)
0032 
0033 #include "KFParticle_DST.h"
0034 #include "KFParticle_nTuple.h"
0035 
0036 // sPHENIX stuff
0037 #include <fun4all/SubsysReco.h>
0038 
0039 // KFParticle stuff
0040 #include <KFParticle.h>
0041 
0042 #include <algorithm>  // for max
0043 #include <memory>     // for allocator_traits<>::valu...
0044 #include <string>
0045 #include <utility>  // for pair
0046 #include <vector>   // for vector
0047 
0048 class PHCompositeNode;
0049 class TFile;
0050 
0051 class KFParticle_sPHENIX : public SubsysReco, public KFParticle_nTuple, public KFParticle_DST, protected KFParticle_eventReconstruction
0052 {
0053  public:
0054   KFParticle_sPHENIX();
0055 
0056   explicit KFParticle_sPHENIX(const std::string &name);
0057 
0058   ~KFParticle_sPHENIX() override = default;
0059 
0060   int Init(PHCompositeNode *topNode) override;
0061 
0062   int InitRun(PHCompositeNode *topNode) override;
0063 
0064   int process_event(PHCompositeNode *topNode) override;
0065 
0066   int End(PHCompositeNode *topNode) override;
0067 
0068   /**
0069    * If verbosity is > 0, this will print out all candidate information:
0070    * masses, momenta and positions for mothers, intermediates and final state tracks,
0071    * PV position, number of vertices and number of tracks in the event (multiplicity)
0072    */
0073   void printParticles(const KFParticle &motherParticle,
0074                       const KFParticle &chosenVertex,
0075                       const std::vector<KFParticle> &daughterParticles,
0076                       const std::vector<KFParticle> &intermediateParticles,
0077                       const int numPVs, const int numTracks);
0078 
0079   int parseDecayDescriptor();
0080 
0081   /// Parameters for the user to vary
0082 
0083   void setDecayDescriptor(const std::string &decayDescriptor) { m_decayDescriptor = decayDescriptor; }
0084 
0085   static const int max_particles = 99;
0086 
0087   void setMotherName(const std::string &mother_name)
0088   {
0089     m_mother_name = mother_name;
0090     m_mother_name_Tools = mother_name;
0091   }
0092 
0093   void hasIntermediateStates(bool has_intermediates = true)
0094   {
0095     m_has_intermediates = has_intermediates;
0096     m_has_intermediates_nTuple = has_intermediates;
0097     m_has_intermediates_sPHENIX = has_intermediates;
0098     m_has_intermediates_DST = has_intermediates;
0099   }
0100 
0101   void setNumberOfTracks(int num_tracks)
0102   {
0103     m_num_tracks = num_tracks;
0104     m_num_tracks_nTuple = num_tracks;
0105   }
0106 
0107   void setNumberTracksFromIntermeditateState(const std::vector<int> &num_tracks)
0108   {
0109     for (unsigned int i = 0; i < num_tracks.size(); ++i)
0110     {
0111       m_num_tracks_from_intermediate.push_back(num_tracks[i]);
0112       m_num_tracks_from_intermediate_nTuple.push_back(num_tracks[i]);
0113     }
0114   }
0115 
0116   void setNumberOfIntermediateStates(int n_intermediates)
0117   {
0118     m_num_intermediate_states = n_intermediates;
0119     m_num_intermediate_states_nTuple = n_intermediates;
0120   }
0121 
0122   void getChargeConjugate(bool get_charge_conjugate = true)
0123   {
0124     m_get_charge_conjugate_nTuple = get_charge_conjugate;
0125     m_get_charge_conjugate = get_charge_conjugate;
0126   }
0127 
0128   void setDaughters(std::vector<std::pair<std::string, int>> &daughter_list)
0129   {
0130     for (unsigned int i = 0; i < daughter_list.size(); ++i)
0131     {
0132       m_daughter_name.push_back(daughter_list[i].first);
0133       m_daughter_charge.push_back(daughter_list[i].second);
0134     }
0135   }
0136 
0137   void setIntermediateStates(const std::vector<std::pair<std::string, int>> &intermediate_list)
0138   {
0139     for (unsigned int i = 0; i < intermediate_list.size(); ++i)
0140     {
0141       m_intermediate_name_ntuple.push_back(intermediate_list[i].first);
0142       m_intermediate_name.push_back(intermediate_list[i].first);
0143       m_intermediate_charge.push_back(intermediate_list[i].second);
0144     }
0145   }
0146 
0147   void setMinimumMass(float min_mass) { m_min_mass = min_mass; }
0148 
0149   void setMaximumMass(float max_mass) { m_max_mass = max_mass; }
0150 
0151   void setDecayTimeRange_XY(float min_decayTime, float max_decayTime)
0152   {
0153     m_min_decayTime_xy = min_decayTime;
0154     m_max_decayTime_xy = max_decayTime;
0155   }
0156 
0157   void setDecayLengthRange_XY(float min_decayLength, float max_decayLength)
0158   {
0159     m_min_decayLength_xy = min_decayLength;
0160     m_max_decayLength_xy = max_decayLength;
0161   }
0162 
0163   void setDecayTimeRange(float min_decayTime, float max_decayTime)
0164   {
0165     m_min_decayTime = min_decayTime;
0166     m_max_decayTime = max_decayTime;
0167   }
0168 
0169   void setDecayLengthRange(float min_decayLength, float max_decayLength)
0170   {
0171     m_min_decayLength = min_decayLength;
0172     m_max_decayLength = max_decayLength;
0173   }
0174 
0175   void setMinDecayTimeSignificance(float min = 0) { m_mother_min_decay_time_significance = min; }
0176 
0177   void setMinDecayLengthSignificance(float min = 0) { m_mother_min_decay_length_significance = min; }
0178 
0179   void setMinDecayLengthSignificance_XY(float min = 0) { m_mother_min_decay_length_xy_significance = min; }
0180 
0181   void setMinimumTrackPT(float pt) { m_track_pt = pt; }
0182 
0183   void setMaximumTrackPTchi2(float ptchi2) { m_track_ptchi2 = ptchi2; }
0184 
0185   void setMinimumTrackIP_XY(float ip) { m_track_ip_xy = ip; }
0186 
0187   void setMinimumTrackIPchi2_XY(float ipchi2) { m_track_ipchi2_xy = ipchi2; }
0188 
0189   void setMinimumTrackIP(float ip) { m_track_ip = ip; }
0190 
0191   void setMinimumTrackIPchi2(float ipchi2) { m_track_ipchi2 = ipchi2; }
0192 
0193   void setMaximumTrackchi2nDOF(float trackchi2ndof) { m_track_chi2ndof = trackchi2ndof; }
0194 
0195   void setMinMVTXhits(int nHits) { m_nMVTXStates = nHits; } //Actually state counting but use this for backwards compatibility!
0196 
0197   void setMinINTThits(int nHits) { m_nINTTStates = nHits; } //Actually state counting but use this for backwards compatibility!
0198 
0199   void setMinTPChits(int nHits) { m_nTPCStates = nHits; } //Actually state counting but use this for backwards compatibility!
0200 
0201   void setMinTPOThits(int nHits) { m_nTPCStates = nHits; } //Actually state counting but use this for backwards compatibility!
0202 
0203   void setMaximumDaughterDCA_XY(float dca) { m_comb_DCA_xy = dca; }
0204 
0205   void setMaximumDaughterDCA(float dca) { m_comb_DCA = dca; }
0206  
0207   void setMinimumRadialSV(float min_rad_sv) { m_min_radial_SV = min_rad_sv; }
0208 
0209   void setMaximumVertexchi2nDOF(float vertexchi2nDOF) { m_vertex_chi2ndof = vertexchi2nDOF; }
0210 
0211   void setFlightDistancechi2(float fdchi2) { m_fdchi2 = fdchi2; }
0212 
0213   void setMinDIRA(float dira_min) { m_dira_min = dira_min; }
0214 
0215   void setMaxDIRA(float dira_max) { m_dira_max = dira_max; }
0216 
0217   void setMinDIRA_XY(float dira_min) { m_dira_xy_min = dira_min; }
0218 
0219   void setMaxDIRA_XY(float dira_max) { m_dira_xy_max = dira_max; }
0220 
0221   void setMotherPT(float mother_pt) { m_mother_pt = mother_pt; }
0222 
0223   void setMotherIP(float mother_ip) { m_mother_ip = mother_ip; }
0224 
0225   void setMotherIP_XY(float mother_ip) { m_mother_ip_xy = mother_ip; }
0226 
0227   void setMotherIPchi2(float mother_ipchi2) { m_mother_ipchi2 = mother_ipchi2; }
0228 
0229   void setMotherIPchi2_XY(float mother_ipchi2) { m_mother_ipchi2_xy = mother_ipchi2; }
0230 
0231   void setMaximumMotherVertexVolume(float vertexvol) { m_mother_vertex_volume = vertexvol; }
0232 
0233   void constrainToPrimaryVertex(bool constrain_to_vertex = true)
0234   {
0235     m_constrain_to_vertex = constrain_to_vertex;
0236     m_constrain_to_vertex_nTuple = constrain_to_vertex;
0237     m_constrain_to_vertex_sPHENIX = constrain_to_vertex;
0238   }
0239 
0240   void useMbdVertex(bool use = true)
0241   {
0242     m_use_mbd_vertex = use;
0243     m_use_mbd_vertex_truth = use;
0244   }
0245 
0246   void dontUseGlobalVertex(bool dont = true) { m_dont_use_global_vertex = m_dont_use_global_vertex_truth  = dont; }
0247 
0248   void useFakePrimaryVertex(bool use_fake = true)
0249   {
0250     m_use_fake_pv = use_fake;
0251     m_use_fake_pv_nTuple = use_fake;
0252   }
0253 
0254   void allowZeroMassTracks(bool allow = true) { m_allowZeroMassTracks = allow; }
0255 
0256   void extraolateTracksToSV(bool extrapolate = true)
0257   {
0258     m_extrapolateTracksToSV = extrapolate;
0259     m_extrapolateTracksToSV_nTuple = extrapolate;
0260   }
0261 
0262   void constrainIntermediateMasses(bool constrain_int_mass = true) { m_constrain_int_mass = constrain_int_mass; }
0263 
0264   void setIntermediateMassRange(const std::vector<std::pair<float, float>> &intermediate_mass_range)
0265   {
0266     for (unsigned int i = 0; i < intermediate_mass_range.size(); ++i) m_intermediate_mass_range.push_back(intermediate_mass_range[i]);
0267   }
0268 
0269   void setIntermediateMinPT(const std::vector<float> &intermediate_min_pt)
0270   {
0271     m_intermediate_min_pt = intermediate_min_pt;
0272   }
0273 
0274   void setIntermediateMinIP_XY(const std::vector<float> &intermediate_min_IP)
0275   {
0276     for (unsigned int i = 0; i < intermediate_min_IP.size(); ++i) m_intermediate_min_ip_xy.push_back(intermediate_min_IP[i]);
0277   }
0278 
0279   void setIntermediateIPRange_XY(const std::vector<std::pair<float, float> /*unused*/> &intermediate_IP_range)
0280   {
0281     for (unsigned int i = 0; i < intermediate_IP_range.size(); ++i)
0282     {
0283       m_intermediate_min_ip_xy.push_back(intermediate_IP_range[i].first);
0284       m_intermediate_max_ip_xy.push_back(intermediate_IP_range[i].second);
0285     }
0286   }
0287 
0288   void setIntermediateMinIP(const std::vector<float> &intermediate_min_IP)
0289   {
0290     for (unsigned int i = 0; i < intermediate_min_IP.size(); ++i) m_intermediate_min_ip.push_back(intermediate_min_IP[i]);
0291   }
0292 
0293   void setIntermediateIPRange(const std::vector<std::pair<float, float> /*unused*/> &intermediate_IP_range)
0294   {
0295     for (unsigned int i = 0; i < intermediate_IP_range.size(); ++i)
0296     {
0297       m_intermediate_min_ip.push_back(intermediate_IP_range[i].first);
0298       m_intermediate_max_ip.push_back(intermediate_IP_range[i].second);
0299     }
0300   }
0301 
0302   void setIntermediateMinIPchi2_XY(const std::vector<float> &intermediate_min_IPchi2)
0303   {
0304     for (unsigned int i = 0; i < intermediate_min_IPchi2.size(); ++i) m_intermediate_min_ipchi2_xy.push_back(intermediate_min_IPchi2[i]);
0305   }
0306 
0307   void setIntermediateIPchi2Range_XY(const std::vector<std::pair<float, float> /*unused*/> &intermediate_IPchi2_range)
0308   {
0309     for (unsigned int i = 0; i < intermediate_IPchi2_range.size(); ++i)
0310     {
0311       m_intermediate_min_ipchi2_xy.push_back(intermediate_IPchi2_range[i].first);
0312       m_intermediate_max_ipchi2_xy.push_back(intermediate_IPchi2_range[i].second);
0313     }
0314   }
0315 
0316   void setIntermediateMinIPchi2(const std::vector<float> &intermediate_min_IPchi2)
0317   {
0318     for (unsigned int i = 0; i < intermediate_min_IPchi2.size(); ++i) m_intermediate_min_ipchi2.push_back(intermediate_min_IPchi2[i]);
0319   }
0320 
0321   void setIntermediateIPchi2Range(const std::vector<std::pair<float, float> /*unused*/> &intermediate_IPchi2_range)
0322   {
0323     for (unsigned int i = 0; i < intermediate_IPchi2_range.size(); ++i)
0324     {
0325       m_intermediate_min_ipchi2.push_back(intermediate_IPchi2_range[i].first);
0326       m_intermediate_max_ipchi2.push_back(intermediate_IPchi2_range[i].second);
0327     }
0328   }
0329 
0330   void setIntermediateMinDIRA(const std::vector<float> &intermediate_min_DIRA)
0331   {
0332     for (unsigned int i = 0; i < intermediate_min_DIRA.size(); ++i) m_intermediate_min_dira.push_back(intermediate_min_DIRA[i]);
0333   }
0334 
0335   void setIntermediateMinFDchi2(const std::vector<float> &intermediate_min_FDchi2)
0336   {
0337     for (unsigned int i = 0; i < intermediate_min_FDchi2.size(); ++i) m_intermediate_min_fdchi2.push_back(intermediate_min_FDchi2[i]);
0338   }
0339 
0340   void setIntermediateMaxVertexVolume(const std::vector<float> &intermediate_max_vertexvol)
0341   {
0342     for (unsigned int i = 0; i < intermediate_max_vertexvol.size(); ++i) m_intermediate_vertex_volume.push_back(intermediate_max_vertexvol[i]);
0343   }
0344 
0345   void use2Dmatching(bool use_2D_matching_tools = true) { m_use_2D_matching_tools = use_2D_matching_tools; }
0346 
0347   void useMVA(bool require_mva = true) { m_require_mva = require_mva; }
0348 
0349   void setNumMVAPars(unsigned int nPars) { m_nPars = nPars; }
0350 
0351   void setMVAVarList(const std::vector<std::string> &mva_variable_list)
0352   {
0353     for (unsigned int i = 0; i < mva_variable_list.size(); ++i) m_mva_variable_list.push_back(mva_variable_list[i]);
0354   }
0355 
0356   void setMVAType(const std::string &mva_type) { m_mva_type = mva_type; }
0357 
0358   void setMVAWeightsPath(const std::string &mva_weights_path) { m_mva_path = mva_weights_path; }
0359 
0360   void setMVACutValue(float cut_value) { m_mva_cut_value = cut_value; }
0361 
0362   void saveDST(bool save = true) { m_save_dst = save; }
0363 
0364   void saveTrackContainer(bool save = true) { m_write_track_container = save; }
0365 
0366   void saveParticleContainer(bool save = true) { m_write_particle_container = save; }
0367 
0368   void setContainerName(const std::string &name) { m_container_name = name; }
0369 
0370   void saveOutput(bool save = true) { m_save_output = save; }
0371 
0372   void setOutputName(const std::string &name) { m_outfile_name = name; }
0373 
0374   void doTruthMatching(bool truth = true) { m_truth_matching = truth; }
0375 
0376   void getTriggerInfo(bool get = true) { m_get_trigger_info = get; }
0377 
0378   void getDetectorInfo(bool detinfo = true) { m_detector_info = detinfo; }
0379 
0380   void getCaloInfo(bool caloinfo = true) { m_calo_info = caloinfo; }
0381 
0382   void getAllPVInfo(bool pvinfo = true) { m_get_all_PVs = pvinfo; }
0383 
0384   void bunchCrossingZeroOnly(bool bcZeroOnly = true) { m_bunch_crossing_zero_only = bcZeroOnly; }
0385 
0386   void requireBunchCrossingMatch(bool require = true) { m_require_bunch_crossing_match = require; }
0387 
0388   void requireTrackVertexBunchCrossingMatch(bool require = true) { m_require_track_and_vertex_match = require; }
0389 
0390   void usePID(bool use = true){ m_use_PID = use; }
0391  
0392   void setPIDacceptFraction(float frac = 0.2){ m_dEdx_band_width = frac; }
0393 
0394   /// Use alternate vertex and track fitters
0395   void setVertexMapNodeName(const std::string &vtx_map_node_name) { m_vtx_map_node_name = m_vtx_map_node_name_nTuple = vtx_map_node_name; }
0396 
0397   /// Use alternate vertex and track fitters
0398   void setTrackMapNodeName(const std::string &trk_map_node_name) { m_trk_map_node_name = m_trk_map_node_name_nTuple = m_origin_track_map_node_name = trk_map_node_name; }
0399 
0400   void magFieldFile(const std::string &fname) { m_magField = fname; }
0401 
0402   void getField();
0403 
0404   void incrementCandidateCounter(){ candidateCounter += 1; }
0405   void setCandidateCounter(int countNum) { candidateCounter = countNum; }
0406   int getCandidateCounter() { return candidateCounter; }
0407 
0408  private:
0409   bool m_has_intermediates_sPHENIX;
0410   bool m_constrain_to_vertex_sPHENIX;
0411   bool m_require_mva;
0412   bool m_save_dst;
0413   bool m_save_output;
0414   int candidateCounter = 0;
0415   std::string m_outfile_name;
0416   TFile *m_outfile;
0417   std::string m_decayDescriptor;
0418   std::string m_magField = "FIELDMAP_TRACKING";
0419 };
0420 
0421 #endif  // KFPARTICLESPHENIX_KFPARTICLESPHENIX_H