Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:10:22

0001 #include <fun4all/Fun4AllServer.h>
0002 
0003 #include <calotrigger/TriggerRunInfoReco.h>
0004 #include <globalvertex/GlobalVertexReco.h>
0005 
0006 #pragma GCC diagnostic push
0007 
0008 #pragma GCC diagnostic ignored "-Wundefined-internal"
0009 
0010 #include <kfparticle_sphenix/KFParticle_sPHENIX.h>
0011 
0012 #pragma GCC diagnostic pop
0013 
0014 R__LOAD_LIBRARY(libkfparticle_sphenix.so)
0015 R__LOAD_LIBRARY(libcalotrigger.so)
0016 R__LOAD_LIBRARY(libkfparticleqa.so)
0017 
0018 namespace HeavyFlavorReco
0019 {
0020   int VERBOSITY_HF = 0;
0021 
0022   bool run_pipi_reco = false;
0023   bool run_ppi_reco = false; // set to true if needed
0024   bool run_KK_reco = false; // set to true if needed
0025   bool run_Kpi_reco = false; // set to true if needed
0026   bool run_ee_reco = false; // set to true if needed
0027 
0028   std::string output_dir = "./"; //Top dir of where the output nTuples will be written
0029   std::string kfp_header = "outputKFParticle_";
0030   std::string processing_folder = "inReconstruction/";
0031   std::string trailer = ".root";
0032 
0033   // https://wiki.bnl.gov/sPHENIX/index.php/KFParticle
0034   std::string pipi_decay_descriptor = "K_S0 -> pi^+ pi^-"; //See twiki on how to set this
0035   std::string pipi_reconstruction_name = "pipi_reco"; //Used for naming output folder, file and node
0036   std::string pipi_output_reco_file;
0037   std::string pipi_output_dir;
0038 
0039   std::string ppi_decay_descriptor = "[Lambda0 -> proton^+ pi^-]cc"; //See twiki on how to set this
0040   std::string ppi_reconstruction_name = "ppi_reco"; //Used for naming output folder, file and node
0041   std::string ppi_output_reco_file;
0042   std::string ppi_output_dir;
0043 
0044   bool truthMatch = true;
0045   bool save_kfpntuple = false;
0046   bool use_pid = true;
0047   bool save_tracks_to_DST = true;
0048   bool dont_use_global_vertex = true;
0049   bool require_track_and_vertex_match = true;
0050   bool save_all_vtx_info = true;
0051   bool constrain_phi_mass = true;
0052   bool use_2D_matching = false;
0053   bool get_trigger_info = false;
0054   bool get_detector_info = true;
0055   bool get_dEdx_info = true;
0056   bool get_calo_info = false;
0057   float pid_frac = 0.4;
0058   float cemc_proj_radius = 102.9; //Virgile recommendation according to DetailedCalorimeterGeometry
0059   bool constrain_lambda_mass = true;
0060   bool extraolate_tracks_to_secondary_vertex = false; // Set to false to ensure the pT map is accurate for asymmetry study
0061 
0062   //Used
0063   float lf_cuts_setMinDIRA{-1.1};
0064   float lf_cuts_setDecayLengthRange_min{-1.};
0065   float lf_cuts_setMinimumTrackIP_XY{-1.};
0066   float lf_cuts_setMinMVTXhits{0};
0067   float lf_cuts_setMinINTThits{0};
0068   float lf_cuts_setMinTPChits{0};
0069   float lf_cuts_setMaximumVertexchi2nDOF{2000};
0070   float lf_cuts_setMaximumDaughterDCA{10};
0071 
0072   //Unused
0073   float lf_cuts_setMotherIPchi2{FLT_MAX};
0074   float lf_cuts_setFlightDistancechi2{-1.};
0075   float lf_cuts_setMinDIRA_XY{-1.1};
0076   float lf_cuts_setDecayLengthRange_max{FLT_MAX};
0077   float lf_cuts_setDecayLengthRange_XY_min{-10.};
0078   float lf_cuts_setDecayLengthRange_XY_max{FLT_MAX};
0079   float lf_cuts_setDecayTimeRange_XY_min{-10000};
0080   float lf_cuts_setDecayTimeRange_XY_max{FLT_MAX};
0081   float lf_cuts_setDecayTimeRange_min{-10000};
0082   float lf_cuts_setDecayTimeRange_max{FLT_MAX};
0083   float lf_cuts_setMinDecayTimeSignificance{-1e5};
0084   float lf_cuts_setMinDecayLengthSignificance{-1e5};
0085   float lf_cuts_setMinDecayLengthSignificance_XY{-1e5};
0086   float lf_cuts_setMinimumTrackPT{0.0};
0087   float lf_cuts_setMinimumTrackIPchi2{-1.};
0088   float lf_cuts_setMinimumTrackIPchi2_XY{-1.};
0089   float lf_cuts_setMinimumTrackIP{-1.};
0090   float lf_cuts_setMaximumTrackchi2nDOF{3000.};
0091   float lf_cuts_setMaximumDaughterDCA_XY{10};
0092   float lf_cuts_setMotherPT{0};
0093   float lf_cuts_setMaximumMotherVertexVolume{100};
0094 /*
0095   //Used
0096   float lf_cuts_setMinDIRA{0.99};
0097   float lf_cuts_setDecayLengthRange_min{0.05};
0098   float lf_cuts_setMinimumTrackIP_XY{0.05};
0099   float lf_cuts_setMinMVTXhits{1};
0100   float lf_cuts_setMinINTThits{1};
0101   float lf_cuts_setMinTPChits{20};
0102   float lf_cuts_setMaximumVertexchi2nDOF{20};
0103   float lf_cuts_setMaximumDaughterDCA{0.5};
0104 
0105   //Unused
0106   float lf_cuts_setMotherIPchi2{FLT_MAX};
0107   float lf_cuts_setFlightDistancechi2{-1.};
0108   float lf_cuts_setMinDIRA_XY{-1.1};
0109   float lf_cuts_setDecayLengthRange_max{FLT_MAX};
0110   float lf_cuts_setDecayLengthRange_XY_min{-10.};
0111   float lf_cuts_setDecayLengthRange_XY_max{FLT_MAX};
0112   float lf_cuts_setDecayTimeRange_XY_min{-10000};
0113   float lf_cuts_setDecayTimeRange_XY_max{FLT_MAX};
0114   float lf_cuts_setDecayTimeRange_min{-10000};
0115   float lf_cuts_setDecayTimeRange_max{FLT_MAX};
0116   float lf_cuts_setMinDecayTimeSignificance{-1e5};
0117   float lf_cuts_setMinDecayLengthSignificance{-1e5};
0118   float lf_cuts_setMinDecayLengthSignificance_XY{-1e5};
0119   float lf_cuts_setMinimumTrackPT{0.0};
0120   float lf_cuts_setMinimumTrackIPchi2{-1.};
0121   float lf_cuts_setMinimumTrackIPchi2_XY{-1.};
0122   float lf_cuts_setMinimumTrackIP{-1.};
0123   float lf_cuts_setMaximumTrackchi2nDOF{300.};
0124   float lf_cuts_setMaximumDaughterDCA_XY{1};
0125   float lf_cuts_setMotherPT{0};
0126   float lf_cuts_setMaximumMotherVertexVolume{0.1};
0127 */
0128 };  // namespace HeavyFlavorReco'
0129 
0130 using namespace HeavyFlavorReco;
0131 
0132 void init_kfp_dependencies()
0133 {
0134   //dE/dx needs TRKR_CLUSTER and CYLINDERCELLGEOM_SVTX which need to be in the DST or loaded from a geo file
0135   Fun4AllServer *se = Fun4AllServer::instance();
0136 
0137   GlobalVertexReco* gblvertex = new GlobalVertexReco();
0138   gblvertex->Verbosity(VERBOSITY_HF);
0139   se->registerSubsystem(gblvertex);
0140 
0141   if (get_trigger_info)
0142   {
0143     TriggerRunInfoReco *triggerruninforeco = new TriggerRunInfoReco();
0144     se->registerSubsystem(triggerruninforeco);
0145   }
0146 }
0147 
0148 void create_hf_directories(std::string reconstruction_name, std::string &final_output_dir, std::string &output_reco_file)
0149 {
0150   std::string output_file_name = kfp_header + reconstruction_name + trailer;
0151   final_output_dir = output_dir + reconstruction_name + "/";
0152   std::string output_reco_dir = final_output_dir + processing_folder;
0153   output_reco_file = output_reco_dir + output_file_name;
0154 
0155   std::string makeDirectory = "mkdir -p " + output_reco_dir;
0156   system(makeDirectory.c_str());
0157 }
0158 
0159 void reconstruct_pipi_mass()
0160 {
0161   Fun4AllServer *se = Fun4AllServer::instance();
0162 
0163   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(pipi_reconstruction_name);
0164   kfparticle->Verbosity(10);
0165 
0166   kfparticle->setDecayDescriptor(pipi_decay_descriptor);
0167 
0168   kfparticle->setTrackMapNodeName("HFSelected_SvtxTrackMap");
0169   kfparticle->extraolateTracksToSV(extraolate_tracks_to_secondary_vertex);
0170   kfparticle->saveOutput(save_kfpntuple);
0171 
0172   kfparticle->doTruthMatching(truthMatch);
0173   kfparticle->usePID(use_pid);
0174   kfparticle->setPIDacceptFraction(pid_frac);
0175   kfparticle->get_dEdx_info();
0176   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0177   kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0178   kfparticle->getAllPVInfo(save_all_vtx_info);
0179   kfparticle->allowZeroMassTracks();
0180   kfparticle->use2Dmatching(use_2D_matching);
0181   kfparticle->getTriggerInfo(get_trigger_info);
0182   kfparticle->getDetectorInfo(get_detector_info);
0183   kfparticle->get_dEdx_info(get_dEdx_info);
0184   kfparticle->saveDST(save_tracks_to_DST);
0185   kfparticle->setContainerName(pipi_reconstruction_name);
0186   kfparticle->saveParticleContainer(true);
0187   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0188 
0189   //PV to SV cuts
0190   kfparticle->constrainToPrimaryVertex();
0191   kfparticle->setMotherIPchi2(lf_cuts_setMotherIPchi2);
0192   kfparticle->setFlightDistancechi2(lf_cuts_setFlightDistancechi2);
0193   kfparticle->setMinDIRA(lf_cuts_setMinDIRA);
0194   kfparticle->setMinDIRA_XY(lf_cuts_setMinDIRA_XY);
0195   kfparticle->setDecayLengthRange(lf_cuts_setDecayLengthRange_min, lf_cuts_setDecayLengthRange_max);
0196   kfparticle->setDecayLengthRange_XY(lf_cuts_setDecayLengthRange_XY_min, lf_cuts_setDecayLengthRange_XY_max);
0197   kfparticle->setDecayTimeRange_XY(lf_cuts_setDecayTimeRange_XY_min, lf_cuts_setDecayTimeRange_XY_max);
0198   kfparticle->setDecayTimeRange(lf_cuts_setDecayTimeRange_min, lf_cuts_setDecayTimeRange_max);
0199   kfparticle->setMinDecayTimeSignificance(lf_cuts_setMinDecayTimeSignificance);
0200   kfparticle->setMinDecayLengthSignificance(lf_cuts_setMinDecayLengthSignificance);
0201   kfparticle->setMinDecayLengthSignificance_XY(lf_cuts_setMinDecayLengthSignificance_XY);
0202 
0203   //Track parameters
0204   kfparticle->setMinimumTrackPT(lf_cuts_setMinimumTrackPT);
0205   kfparticle->setMinimumTrackIPchi2(lf_cuts_setMinimumTrackIPchi2);
0206   kfparticle->setMinimumTrackIPchi2_XY(lf_cuts_setMinimumTrackIPchi2_XY);
0207   kfparticle->setMinimumTrackIP(lf_cuts_setMinimumTrackIP);
0208   kfparticle->setMinimumTrackIP_XY(lf_cuts_setMinimumTrackIP_XY);
0209   kfparticle->setMaximumTrackchi2nDOF(lf_cuts_setMaximumTrackchi2nDOF);
0210   kfparticle->setMinMVTXhits(lf_cuts_setMinMVTXhits);
0211   kfparticle->setMinINTThits(lf_cuts_setMinINTThits);
0212   kfparticle->setMinTPChits(lf_cuts_setMinTPChits);
0213 
0214   //Vertex parameters
0215   kfparticle->setMaximumVertexchi2nDOF(lf_cuts_setMaximumVertexchi2nDOF);
0216   kfparticle->setMaximumDaughterDCA(lf_cuts_setMaximumDaughterDCA);
0217   kfparticle->setMaximumDaughterDCA_XY(lf_cuts_setMaximumDaughterDCA_XY);
0218 
0219   //Parent parameters
0220   kfparticle->setMotherPT(lf_cuts_setMotherPT);
0221   kfparticle->setMinimumMass(0.40);
0222   kfparticle->setMaximumMass(0.60);
0223   kfparticle->setMaximumMotherVertexVolume(lf_cuts_setMaximumMotherVertexVolume);
0224   kfparticle->setOutputName(pipi_output_reco_file);
0225 
0226   se->registerSubsystem(kfparticle);
0227 }
0228 
0229 void reconstruct_ppi_mass()
0230 {
0231   Fun4AllServer *se = Fun4AllServer::instance();
0232 
0233   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(ppi_reconstruction_name);
0234 
0235   kfparticle->setDecayDescriptor(ppi_decay_descriptor);
0236 
0237   kfparticle->setTrackMapNodeName("HFSelected_SvtxTrackMap");
0238   kfparticle->extraolateTracksToSV(extraolate_tracks_to_secondary_vertex);
0239   kfparticle->saveOutput(save_kfpntuple);
0240 
0241   kfparticle->doTruthMatching(truthMatch);
0242   kfparticle->usePID(use_pid);
0243   kfparticle->setPIDacceptFraction(pid_frac);
0244   kfparticle->get_dEdx_info();
0245   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0246   kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0247   kfparticle->getAllPVInfo(save_all_vtx_info);
0248   kfparticle->allowZeroMassTracks();
0249   kfparticle->use2Dmatching(use_2D_matching);
0250   kfparticle->getTriggerInfo(get_trigger_info);
0251   kfparticle->getDetectorInfo(get_detector_info);
0252   kfparticle->get_dEdx_info(get_dEdx_info);
0253   kfparticle->saveDST(save_tracks_to_DST);
0254   kfparticle->setContainerName(ppi_reconstruction_name);
0255   kfparticle->saveParticleContainer(true);
0256   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0257 
0258   //PV to SV cuts
0259   kfparticle->constrainToPrimaryVertex();
0260   kfparticle->setMotherIPchi2(lf_cuts_setMotherIPchi2);
0261   kfparticle->setFlightDistancechi2(lf_cuts_setFlightDistancechi2);
0262   kfparticle->setMinDIRA(lf_cuts_setMinDIRA);
0263   kfparticle->setMinDIRA_XY(lf_cuts_setMinDIRA_XY);
0264   kfparticle->setDecayLengthRange(lf_cuts_setDecayLengthRange_min, lf_cuts_setDecayLengthRange_max);
0265   kfparticle->setDecayLengthRange_XY(lf_cuts_setDecayLengthRange_XY_min, lf_cuts_setDecayLengthRange_XY_max);
0266   kfparticle->setDecayTimeRange_XY(lf_cuts_setDecayTimeRange_XY_min, lf_cuts_setDecayTimeRange_XY_max);
0267   kfparticle->setDecayTimeRange(lf_cuts_setDecayTimeRange_min, lf_cuts_setDecayTimeRange_max);
0268   kfparticle->setMinDecayTimeSignificance(lf_cuts_setMinDecayTimeSignificance);
0269   kfparticle->setMinDecayLengthSignificance(lf_cuts_setMinDecayLengthSignificance);
0270   kfparticle->setMinDecayLengthSignificance_XY(lf_cuts_setMinDecayLengthSignificance_XY);
0271 
0272   //Track parameters
0273   kfparticle->setMinimumTrackPT(lf_cuts_setMinimumTrackPT);
0274   kfparticle->setMinimumTrackIPchi2(lf_cuts_setMinimumTrackIPchi2);
0275   kfparticle->setMinimumTrackIPchi2_XY(lf_cuts_setMinimumTrackIPchi2_XY);
0276   kfparticle->setMinimumTrackIP(lf_cuts_setMinimumTrackIP);
0277   kfparticle->setMinimumTrackIP_XY(lf_cuts_setMinimumTrackIP_XY);
0278   kfparticle->setMaximumTrackchi2nDOF(lf_cuts_setMaximumTrackchi2nDOF);
0279   kfparticle->setMinMVTXhits(lf_cuts_setMinMVTXhits);
0280   kfparticle->setMinINTThits(lf_cuts_setMinINTThits);
0281   kfparticle->setMinTPChits(lf_cuts_setMinTPChits);
0282 
0283   //Vertex parameters
0284   kfparticle->setMaximumVertexchi2nDOF(lf_cuts_setMaximumVertexchi2nDOF);
0285   kfparticle->setMaximumDaughterDCA(lf_cuts_setMaximumDaughterDCA);
0286   kfparticle->setMaximumDaughterDCA_XY(lf_cuts_setMaximumDaughterDCA_XY);
0287 
0288   //Parent parameters
0289   kfparticle->setMotherPT(lf_cuts_setMotherPT);
0290   kfparticle->setMinimumMass(1.08);
0291   kfparticle->setMaximumMass(1.15);
0292   kfparticle->setMaximumMotherVertexVolume(lf_cuts_setMaximumMotherVertexVolume);
0293   kfparticle->setOutputName(ppi_output_reco_file);
0294 
0295   kfparticle->setOutputName(ppi_output_reco_file);
0296 
0297   se->registerSubsystem(kfparticle);
0298 }
0299 
0300 void end_kfparticle(std::string full_file_name, std::string final_path)
0301 {
0302   ifstream file(full_file_name.c_str());
0303   if (file.good())
0304   {
0305     string moveOutput = "mv " + full_file_name + " " + final_path;
0306     system(moveOutput.c_str());
0307   }
0308 }
0309