Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-07 08:10:32

0001 #include <fun4all/Fun4AllServer.h>
0002 
0003 #include <calotrigger/TriggerRunInfoReco.h>
0004 #include <globalvertex/GlobalVertexReco.h>
0005 
0006 #include <kfparticleqa/QAKFParticle.h>
0007 #include <kfparticleqa/QAKFParticleTrackPtAsymmetry.h>
0008 
0009 #pragma GCC diagnostic push
0010 
0011 #pragma GCC diagnostic ignored "-Wundefined-internal"
0012 
0013 #include <kfparticle_sphenix/KFParticle_sPHENIX.h>
0014 
0015 #pragma GCC diagnostic pop
0016 
0017 R__LOAD_LIBRARY(libkfparticle_sphenix.so)
0018 R__LOAD_LIBRARY(libcalotrigger.so)
0019 R__LOAD_LIBRARY(libkfparticleqa.so)
0020 
0021 namespace HeavyFlavorReco
0022 {
0023   int VERBOSITY_HF = 0;
0024 
0025   bool run_pipi_reco = true;
0026   bool run_ppi_reco = true; // set to true if needed
0027   bool run_KK_reco = true; // set to true if needed
0028   bool run_Kpi_reco = false; // set to true if needed
0029 
0030   std::string output_dir = "/sphenix/tg/tg01/hf/mjpeters/LightFlavorProduction/data/"; //Top dir of where the output nTuples will be written
0031   std::string kfp_header = "outputKFParticle_";
0032   std::string processing_folder = "inReconstruction/";
0033   std::string trailer = ".root";
0034 
0035   // https://wiki.bnl.gov/sPHENIX/index.php/KFParticle
0036   std::string pipi_decay_descriptor = "K_S0 -> pi^+ pi^-"; //See twiki on how to set this
0037   std::string pipi_reconstruction_name = "pipi_reco"; //Used for naming output folder, file and node
0038   std::string pipi_output_reco_file;
0039   std::string pipi_output_dir;
0040 
0041   std::string ppi_decay_descriptor = "[Lambda0 -> proton^+ pi^-]cc"; //See twiki on how to set this
0042   std::string ppi_reconstruction_name = "ppi_reco"; //Used for naming output folder, file and node
0043   std::string ppi_output_reco_file;
0044   std::string ppi_output_dir;
0045 
0046   std::string KK_decay_descriptor = "phi -> K^+ K^-"; //See twiki on how to set this
0047   std::string KK_reconstruction_name = "KK_reco"; //Used for naming output folder, file and node
0048   std::string KK_output_reco_file;
0049   std::string KK_output_dir;
0050 
0051   std::string Kpi_decay_descriptor = "[D0 -> K^- pi^+]cc"; //See twiki on how to set this
0052   std::string Kpi_reconstruction_name = "Kpi_reco"; //Used for naming output folder, file and node
0053   std::string Kpi_output_reco_file;
0054   std::string Kpi_output_dir;
0055 
0056   bool save_kfpntuple = true;
0057   bool use_pid = true;
0058   bool use_local_PID_file = true;
0059   std::string local_PID_filename = "/sphenix/user/mjpeters/analysis/LightFlavorRatios/macros/data/dedx_82420.root";
0060   bool save_tracks_to_DST = true;
0061   bool dont_use_global_vertex = true;
0062   bool require_track_and_vertex_match = true;
0063   bool save_all_vtx_info = true;
0064   bool constrain_phi_mass = true;
0065   bool use_2D_matching = false;
0066   bool get_trigger_info = false;
0067   bool get_detector_info = true;
0068   bool get_dEdx_info = true;
0069   float pid_frac = 0.4;
0070   bool constrain_lambda_mass = true;
0071 };  // namespace HeavyFlavorReco'
0072 
0073 using namespace HeavyFlavorReco;
0074 
0075 void init_kfp_dependencies()
0076 {
0077   //dE/dx needs TRKR_CLUSTER and CYLINDERCELLGEOM_SVTX which need to be in the DST or loaded from a geo file
0078   Fun4AllServer *se = Fun4AllServer::instance();
0079 
0080   GlobalVertexReco* gblvertex = new GlobalVertexReco();
0081   gblvertex->Verbosity(VERBOSITY_HF);
0082   se->registerSubsystem(gblvertex);
0083 
0084 
0085   if (get_trigger_info)
0086   {
0087     TriggerRunInfoReco *triggerruninforeco = new TriggerRunInfoReco();
0088     se->registerSubsystem(triggerruninforeco);
0089   }
0090 }
0091 
0092 void create_hf_directories(std::string reconstruction_name, std::string &final_output_dir, std::string &output_reco_file)
0093 {
0094   std::string output_file_name = kfp_header + reconstruction_name + trailer;
0095   final_output_dir = output_dir + reconstruction_name + "/";
0096   std::string output_reco_dir = final_output_dir + processing_folder;
0097   output_reco_file = output_reco_dir + output_file_name;
0098 
0099   std::string makeDirectory = "mkdir -p " + output_reco_dir;
0100   system(makeDirectory.c_str());
0101 }
0102 
0103 void reconstruct_pipi_mass()
0104 {
0105   Fun4AllServer *se = Fun4AllServer::instance();
0106 
0107   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(pipi_reconstruction_name);
0108   kfparticle->Verbosity(10);
0109 
0110   kfparticle->setDecayDescriptor(pipi_decay_descriptor);
0111 
0112   //kfparticle->extraolateTracksToSV(false); //To ensure the pT map is accurate
0113 
0114   kfparticle->saveOutput(save_kfpntuple);
0115 
0116   //kfparticle->useFakePrimaryVertex();
0117   //kfparticle->requireTrackVertexBunchCrossingMatch(false);
0118 
0119   kfparticle->usePID(use_pid);
0120   kfparticle->useLocalPIDFile(use_local_PID_file);
0121   kfparticle->setLocalPIDFilename(local_PID_filename);
0122   kfparticle->setPIDacceptFraction(pid_frac);
0123   kfparticle->get_dEdx_info();
0124   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0125   //kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0126   kfparticle->getAllPVInfo(save_all_vtx_info);
0127   kfparticle->allowZeroMassTracks();
0128   kfparticle->use2Dmatching(use_2D_matching);
0129   kfparticle->getTriggerInfo(get_trigger_info);
0130   kfparticle->getDetectorInfo(get_detector_info);
0131   kfparticle->saveDST(save_tracks_to_DST);
0132   kfparticle->setContainerName(pipi_reconstruction_name);
0133   kfparticle->saveParticleContainer(true);
0134   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0135 
0136   //PV to SV cuts
0137   kfparticle->constrainToPrimaryVertex();
0138   //kfparticle->setMotherIPchi2(100);
0139   kfparticle->setMotherIPchi2(FLT_MAX);
0140   kfparticle->setFlightDistancechi2(-1.);
0141   kfparticle->setMinDIRA(0.99);
0142   kfparticle->setMinDIRA_XY(-1.1);
0143   kfparticle->setDecayLengthRange(0.05, FLT_MAX);
0144   kfparticle->setDecayLengthRange_XY(-10., FLT_MAX);
0145   kfparticle->setDecayTimeRange_XY(-10000, FLT_MAX);
0146   kfparticle->setDecayTimeRange(-10000, FLT_MAX);
0147   kfparticle->setMinDecayTimeSignificance(-1e5);
0148   kfparticle->setMinDecayLengthSignificance(-1e5);
0149   kfparticle->setMinDecayLengthSignificance_XY(-1e5);
0150 
0151   //Track parameters
0152   kfparticle->setMinimumTrackPT(0.0);
0153   kfparticle->setMinimumTrackIPchi2(-1.);
0154   kfparticle->setMinimumTrackIPchi2_XY(-1.);
0155   kfparticle->setMinimumTrackIP(-1.);
0156   kfparticle->setMinimumTrackIP_XY(0.05);
0157   kfparticle->setMaximumTrackchi2nDOF(300.);
0158   kfparticle->setMinMVTXhits(1);
0159   kfparticle->setMinINTThits(1);
0160   kfparticle->setMinTPChits(20);
0161 
0162   //Vertex parameters
0163   kfparticle->setMaximumVertexchi2nDOF(20);
0164   kfparticle->setMaximumDaughterDCA(0.5);
0165   kfparticle->setMaximumDaughterDCA_XY(1);
0166 
0167   //Parent parameters
0168   kfparticle->setMotherPT(0);
0169   kfparticle->setMinimumMass(0.40);
0170   kfparticle->setMaximumMass(0.60);
0171   kfparticle->setMaximumMotherVertexVolume(0.1);
0172   kfparticle->setOutputName(pipi_output_reco_file);
0173 
0174   se->registerSubsystem(kfparticle);
0175 
0176   QAKFParticle *kfpqa = new QAKFParticle("QAKFParticle_K_S0","K_S0",0.4,0.6);
0177   kfpqa->setKFParticleNodeName(pipi_reconstruction_name);
0178   kfpqa->enableTrackPtAsymmetry(true); 
0179   kfpqa->Verbosity(VERBOSITY_HF);
0180   se->registerSubsystem(kfpqa);
0181 
0182 }
0183 
0184 void reconstruct_KK_mass()
0185 {
0186   Fun4AllServer *se = Fun4AllServer::instance();
0187 
0188   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(KK_reconstruction_name);
0189 
0190   kfparticle->setDecayDescriptor(KK_decay_descriptor);
0191   kfparticle->saveOutput(save_kfpntuple);
0192 
0193   kfparticle->usePID(use_pid);
0194   kfparticle->setPIDacceptFraction(pid_frac);
0195   kfparticle->useLocalPIDFile(use_local_PID_file);
0196   kfparticle->setLocalPIDFilename(local_PID_filename);
0197   kfparticle->get_dEdx_info();
0198   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0199   kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0200   kfparticle->getAllPVInfo(save_all_vtx_info);
0201   kfparticle->allowZeroMassTracks();
0202   kfparticle->use2Dmatching(use_2D_matching);
0203   kfparticle->getTriggerInfo(get_trigger_info);
0204   kfparticle->getDetectorInfo(get_detector_info);
0205   kfparticle->saveDST(save_tracks_to_DST);
0206   kfparticle->setContainerName(KK_reconstruction_name);
0207   kfparticle->saveParticleContainer(true);
0208   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0209 
0210   //PV to SV cuts
0211   kfparticle->constrainToPrimaryVertex();
0212   kfparticle->setMotherIPchi2(100);
0213   kfparticle->setFlightDistancechi2(-1.);
0214 
0215   //Track parameters
0216   kfparticle->setMinimumTrackPT(0.1);
0217   kfparticle->setMaximumTrackPT(0.7);
0218   kfparticle->setMaximumTrackchi2nDOF(100.);
0219   kfparticle->setMinTPChits(25);
0220   kfparticle->setMinMVTXhits(1);
0221   kfparticle->setMinINTThits(0);
0222 
0223   //Vertex parameters
0224   kfparticle->setMaximumVertexchi2nDOF(20);
0225   kfparticle->setMaximumDaughterDCA(0.05);
0226   kfparticle->setMaximumDaughterDCA_XY(100);
0227 
0228   //Parent parameters
0229   kfparticle->setMotherPT(0);
0230   kfparticle->setMinimumMass(0.98);
0231   kfparticle->setMaximumMass(1.1);
0232   kfparticle->setMaximumMotherVertexVolume(0.1);
0233 
0234   se->registerSubsystem(kfparticle);
0235 
0236   QAKFParticle *kfpqa = new QAKFParticle("QAKFParticle_phi","phi",0.98,1.1);
0237   kfpqa->setKFParticleNodeName(KK_reconstruction_name);
0238   se->registerSubsystem(kfpqa);
0239 }
0240 
0241 void reconstruct_ppi_mass()
0242 {
0243   Fun4AllServer *se = Fun4AllServer::instance();
0244 
0245   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(ppi_reconstruction_name);
0246 
0247   kfparticle->setDecayDescriptor(ppi_decay_descriptor);
0248   kfparticle->saveOutput(save_kfpntuple);
0249 
0250   kfparticle->usePID(use_pid);
0251   kfparticle->useLocalPIDFile(use_local_PID_file);
0252   kfparticle->setLocalPIDFilename(local_PID_filename);
0253   kfparticle->setPIDacceptFraction(pid_frac);
0254   kfparticle->get_dEdx_info();
0255   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0256   kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0257   kfparticle->getAllPVInfo(save_all_vtx_info);
0258   kfparticle->allowZeroMassTracks();
0259   kfparticle->use2Dmatching(use_2D_matching);
0260   kfparticle->getTriggerInfo(get_trigger_info);
0261   kfparticle->getDetectorInfo(get_detector_info);
0262   kfparticle->saveDST(save_tracks_to_DST);
0263   kfparticle->setContainerName(ppi_reconstruction_name);
0264   kfparticle->saveParticleContainer(true);
0265   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0266 
0267   //PV to SV cuts
0268   kfparticle->constrainToPrimaryVertex();
0269   //kfparticle->setMotherIPchi2(100);
0270   kfparticle->setMotherIPchi2(FLT_MAX);
0271   kfparticle->setFlightDistancechi2(-1.);
0272   kfparticle->setMinDIRA(0.99);
0273   kfparticle->setMinDIRA_XY(-1.1);
0274   kfparticle->setDecayLengthRange(0.05, FLT_MAX);
0275   kfparticle->setDecayLengthRange_XY(-10., FLT_MAX);
0276   kfparticle->setDecayTimeRange_XY(-10000, FLT_MAX);
0277   kfparticle->setDecayTimeRange(-10000, FLT_MAX);
0278   kfparticle->setMinDecayTimeSignificance(-1e5);
0279   kfparticle->setMinDecayLengthSignificance(-1e5);
0280   kfparticle->setMinDecayLengthSignificance_XY(-1e5);
0281 
0282   //Track parameters
0283   kfparticle->setMinimumTrackPT(0.0);
0284   kfparticle->setMinimumTrackIPchi2(-1.);
0285   kfparticle->setMinimumTrackIPchi2_XY(-1.);
0286   kfparticle->setMinimumTrackIP(-1.);
0287   kfparticle->setMinimumTrackIP_XY(0.05);
0288   kfparticle->setMaximumTrackchi2nDOF(300.);
0289   kfparticle->setMinMVTXhits(1);
0290   kfparticle->setMinINTThits(1);
0291   kfparticle->setMinTPChits(20);
0292 
0293   //Vertex parameters
0294   kfparticle->setMaximumVertexchi2nDOF(20);
0295   kfparticle->setMaximumDaughterDCA(0.5);
0296   kfparticle->setMaximumDaughterDCA_XY(100);
0297 
0298   //Parent parameters
0299   kfparticle->setMotherPT(0);
0300   kfparticle->setMinimumMass(1.08);
0301   kfparticle->setMaximumMass(1.15);
0302   kfparticle->setMaximumMotherVertexVolume(0.1);
0303   kfparticle->setOutputName(ppi_output_reco_file);
0304 
0305   se->registerSubsystem(kfparticle);
0306 
0307   QAKFParticle *kfpqa = new QAKFParticle("QAKFParticle_Lambda0","Lambda0",1.08,1.15);
0308   kfpqa->setKFParticleNodeName(ppi_reconstruction_name);
0309   se->registerSubsystem(kfpqa);
0310 }
0311 
0312 void reconstruct_Kpi_mass()
0313 {
0314   Fun4AllServer *se = Fun4AllServer::instance();
0315 
0316   KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(Kpi_reconstruction_name);
0317   kfparticle->Verbosity(0);
0318 
0319   kfparticle->setDecayDescriptor(Kpi_decay_descriptor);
0320   kfparticle->saveOutput(save_kfpntuple);
0321 
0322   kfparticle->usePID(use_pid);
0323   kfparticle->useLocalPIDFile(use_local_PID_file);
0324   kfparticle->setLocalPIDFilename(local_PID_filename);
0325   kfparticle->setPIDacceptFraction(pid_frac);
0326   kfparticle->get_dEdx_info();
0327   kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0328   kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0329   kfparticle->getAllPVInfo(save_all_vtx_info);
0330   kfparticle->allowZeroMassTracks();
0331   kfparticle->use2Dmatching(use_2D_matching);
0332   kfparticle->getTriggerInfo(get_trigger_info);
0333   kfparticle->getDetectorInfo(get_detector_info);
0334   kfparticle->saveDST(save_tracks_to_DST);
0335   kfparticle->setContainerName(Kpi_reconstruction_name);
0336   kfparticle->saveParticleContainer(true);
0337   kfparticle->magFieldFile("FIELDMAP_TRACKING");
0338 
0339   //PV to SV cuts
0340   kfparticle->constrainToPrimaryVertex();
0341   //kfparticle->setMotherIPchi2(100);
0342   kfparticle->setMotherIPchi2(FLT_MAX);
0343   kfparticle->setFlightDistancechi2(-1.);
0344   kfparticle->setMinDIRA(0.95);
0345   kfparticle->setMinDIRA_XY(-1.1);
0346   kfparticle->setDecayLengthRange(0., FLT_MAX);
0347   kfparticle->setDecayLengthRange_XY(-10., FLT_MAX);
0348   kfparticle->setDecayTimeRange_XY(-10000, FLT_MAX);
0349   kfparticle->setDecayTimeRange(-10000, FLT_MAX);
0350   kfparticle->setMinDecayTimeSignificance(-1e5);
0351   kfparticle->setMinDecayLengthSignificance(-1e5);
0352   kfparticle->setMinDecayLengthSignificance_XY(-1e5);
0353 
0354   //Track parameters
0355   kfparticle->setMinimumTrackPT(0.0);
0356   kfparticle->setMinimumTrackIPchi2(-1.);
0357   kfparticle->setMinimumTrackIPchi2_XY(-1.);
0358   kfparticle->setMinimumTrackIP(-1.);
0359   kfparticle->setMinimumTrackIP_XY(0.005);
0360   kfparticle->setMaximumTrackchi2nDOF(300.);
0361   kfparticle->setMinMVTXhits(1);
0362   kfparticle->setMinINTThits(1);
0363   kfparticle->setMinTPChits(20);
0364 
0365   //Vertex parameters
0366   kfparticle->setMaximumVertexchi2nDOF(20);
0367   kfparticle->setMaximumDaughterDCA(0.5);
0368   kfparticle->setMaximumDaughterDCA_XY(100);
0369 
0370   //Parent parameters
0371   kfparticle->setMotherPT(0);
0372   kfparticle->setMinimumMass(1.75);
0373   kfparticle->setMaximumMass(1.95);
0374   kfparticle->setMaximumMotherVertexVolume(0.1);
0375   kfparticle->setOutputName(Kpi_output_reco_file);
0376 
0377   se->registerSubsystem(kfparticle);
0378 
0379   QAKFParticle *kfpqa = new QAKFParticle("QAKFParticle_D0","D0",1.75,1.95);
0380   kfpqa->setKFParticleNodeName(Kpi_reconstruction_name);
0381   se->registerSubsystem(kfpqa);
0382 }
0383 
0384 void end_kfparticle(std::string full_file_name, std::string final_path)
0385 {
0386   ifstream file(full_file_name.c_str());
0387   if (file.good())
0388   {
0389     string moveOutput = "mv " + full_file_name + " " + final_path;
0390     system(moveOutput.c_str());
0391   }
0392 }