File indexing completed on 2026-08-31 08:17:01
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;
0027 bool run_KK_reco = false;
0028 bool run_Kpi_reco = false;
0029
0030 std::string output_dir = "./";
0031 std::string kfp_header = "outputKFParticle_";
0032 std::string processing_folder = "inReconstruction/";
0033 std::string trailer = ".root";
0034
0035 std::string trackMapName = "SvtxTrackMap";
0036
0037
0038 std::string pipi_decay_descriptor = "K_S0 -> pi^+ pi^-";
0039 std::string pipi_reconstruction_name = "pipi_reco";
0040 std::string pipi_output_reco_file;
0041 std::string pipi_output_dir;
0042
0043 std::string ppi_decay_descriptor = "[Lambda0 -> proton^+ pi^-]cc";
0044 std::string ppi_reconstruction_name = "ppi_reco";
0045 std::string ppi_output_reco_file;
0046 std::string ppi_output_dir;
0047
0048 std::string KK_decay_descriptor = "phi -> K^+ K^-";
0049 std::string KK_reconstruction_name = "KK_reco";
0050 std::string KK_output_reco_file;
0051 std::string KK_output_dir;
0052
0053 std::string Kpi_decay_descriptor = "[D0 -> K^- pi^+]cc";
0054 std::string Kpi_reconstruction_name = "Kpi_reco";
0055 std::string Kpi_output_reco_file;
0056 std::string Kpi_output_dir;
0057
0058 bool save_kfpntuple = true;
0059 bool use_pid = false;
0060 bool save_tracks_to_DST = false;
0061 bool dont_use_global_vertex = true;
0062 bool use_fake_pv = false;
0063 bool require_track_and_vertex_match = false;
0064 bool save_all_vtx_info = true;
0065 bool constrain_phi_mass = true;
0066 bool use_2D_matching = false;
0067 bool get_trigger_info = false;
0068 bool get_detector_info = false;
0069 bool get_dEdx_info = true;
0070 float pid_frac = 0.6;
0071 bool constrain_lambda_mass = true;
0072
0073
0074 float lf_cuts_setMinDIRA{0.9};
0075 float lf_cuts_setDecayLengthRange_min{0.};
0076 float lf_cuts_setMinimumTrackIP_XY{-1.};
0077 float lf_cuts_setMinMVTXhits{0};
0078 float lf_cuts_setMinINTThits{0};
0079 float lf_cuts_setMinTPChits{20};
0080 float lf_cuts_setMaximumVertexchi2nDOF{FLT_MAX};
0081 float lf_cuts_setMaximumDaughterDCA{1.5};
0082
0083 float lf_cuts_setMaximumTrackPTchi2{1.};
0084
0085
0086 float lf_cuts_setMinimumRadialSV{2.5};
0087 float lf_cuts_setMaximumRadialSV{40.};
0088
0089 float lf_cuts_setMotherIPchi2{FLT_MAX};
0090 float lf_cuts_setFlightDistancechi2{-1.};
0091 float lf_cuts_setMinDIRA_XY{0.};
0092 float lf_cuts_setDecayLengthRange_max{FLT_MAX};
0093 float lf_cuts_setDecayLengthRange_XY_min{0.};
0094 float lf_cuts_setDecayLengthRange_XY_max{FLT_MAX};
0095 float lf_cuts_setDecayTimeRange_XY_min{0.};
0096 float lf_cuts_setDecayTimeRange_XY_max{FLT_MAX};
0097 float lf_cuts_setDecayTimeRange_min{0.};
0098 float lf_cuts_setDecayTimeRange_max{FLT_MAX};
0099 float lf_cuts_setMinDecayTimeSignificance{-1e5};
0100 float lf_cuts_setMinDecayLengthSignificance{-1e5};
0101 float lf_cuts_setMinDecayLengthSignificance_XY{-1e5};
0102 float lf_cuts_setMinimumTrackPT{0.0};
0103 float lf_cuts_setMinimumTrackIPchi2{-1.};
0104 float lf_cuts_setMinimumTrackIPchi2_XY{-1.};
0105 float lf_cuts_setMinimumTrackIP{-1.};
0106 float lf_cuts_setMaximumTrackchi2nDOF{1000.};
0107 float lf_cuts_setMaximumDaughterDCA_XY{1.5};
0108 float lf_cuts_setMotherPT{0};
0109 float lf_cuts_setMaximumMotherVertexVolume{10000.};
0110 };
0111
0112 using namespace HeavyFlavorReco;
0113
0114 void init_kfp_dependencies()
0115 {
0116
0117 Fun4AllServer *se = Fun4AllServer::instance();
0118
0119 GlobalVertexReco* gblvertex = new GlobalVertexReco();
0120 gblvertex->Verbosity(VERBOSITY_HF);
0121 se->registerSubsystem(gblvertex);
0122
0123
0124 if (get_trigger_info)
0125 {
0126 TriggerRunInfoReco *triggerruninforeco = new TriggerRunInfoReco();
0127 se->registerSubsystem(triggerruninforeco);
0128 }
0129 }
0130
0131 void create_hf_directories(std::string reconstruction_name, std::string &final_output_dir, std::string &output_reco_file)
0132 {
0133 std::string output_file_name = kfp_header + reconstruction_name + trailer;
0134 final_output_dir = output_dir + reconstruction_name + "/";
0135 std::string output_reco_dir = final_output_dir + processing_folder;
0136 output_reco_file = output_reco_dir + output_file_name;
0137
0138 std::string makeDirectory = "mkdir -p " + output_reco_dir;
0139 system(makeDirectory.c_str());
0140 }
0141
0142 void reconstruct_pipi_mass()
0143 {
0144 Fun4AllServer *se = Fun4AllServer::instance();
0145
0146 KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(pipi_reconstruction_name);
0147 kfparticle->Verbosity(VERBOSITY_HF);
0148
0149 kfparticle->setTrackMapNodeName(trackMapName);
0150
0151 kfparticle->setDecayDescriptor(pipi_decay_descriptor);
0152
0153 kfparticle->saveOutput(save_kfpntuple);
0154
0155 kfparticle->usePID(use_pid);
0156 kfparticle->setPIDacceptFraction(pid_frac);
0157 kfparticle->get_dEdx_info();
0158 kfparticle->useFakePrimaryVertex(use_fake_pv);
0159 kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0160 kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0161 kfparticle->getAllPVInfo(save_all_vtx_info);
0162 kfparticle->allowZeroMassTracks();
0163 kfparticle->use2Dmatching(use_2D_matching);
0164 kfparticle->getTriggerInfo(get_trigger_info);
0165 kfparticle->getDetectorInfo(get_detector_info);
0166 kfparticle->saveDST(save_tracks_to_DST);
0167 kfparticle->setContainerName(pipi_reconstruction_name);
0168 kfparticle->saveParticleContainer(true);
0169 kfparticle->magFieldFile("FIELDMAP_TRACKING");
0170
0171
0172 kfparticle->constrainToPrimaryVertex(true);
0173 kfparticle->setMotherPV_DCA_StdDev(lf_cuts_setMotherIPchi2);
0174 kfparticle->setFlightDistancechi2(lf_cuts_setFlightDistancechi2);
0175 kfparticle->setMinDIRA(lf_cuts_setMinDIRA);
0176 kfparticle->setMinDIRA_XY(lf_cuts_setMinDIRA_XY);
0177 kfparticle->setDecayLengthRange(lf_cuts_setDecayLengthRange_min, lf_cuts_setDecayLengthRange_max);
0178 kfparticle->setDecayLengthRange_XY(lf_cuts_setDecayLengthRange_XY_min, lf_cuts_setDecayLengthRange_XY_max);
0179 kfparticle->setDecayTimeRange_XY(lf_cuts_setDecayTimeRange_XY_min, lf_cuts_setDecayTimeRange_XY_max);
0180 kfparticle->setDecayTimeRange(lf_cuts_setDecayTimeRange_min, lf_cuts_setDecayTimeRange_max);
0181 kfparticle->setMinDecayTimeSignificance(lf_cuts_setMinDecayTimeSignificance);
0182 kfparticle->setMinDecayLengthSignificance(lf_cuts_setMinDecayLengthSignificance);
0183 kfparticle->setMinDecayLengthSignificance_XY(lf_cuts_setMinDecayLengthSignificance_XY);
0184
0185 kfparticle->setMinimumRadialSV(lf_cuts_setMinimumRadialSV);
0186 kfparticle->setMaximumRadialSV(lf_cuts_setMaximumRadialSV);
0187
0188
0189 kfparticle->setMinimumTrackPT(lf_cuts_setMinimumTrackPT);
0190 kfparticle->setMaximumTrackPTchi2(lf_cuts_setMaximumTrackPTchi2);
0191 kfparticle->setMinimumTrackPV_DCA_StdDev(lf_cuts_setMinimumTrackIPchi2);
0192 kfparticle->setMinimumTrackPV_DCA_StdDev_XY(lf_cuts_setMinimumTrackIPchi2_XY);
0193 kfparticle->setMinimumTrackPV_DCA(lf_cuts_setMinimumTrackIP);
0194 kfparticle->setMinimumTrackPV_DCA_XY(lf_cuts_setMinimumTrackIP_XY);
0195 kfparticle->setMaximumTrackchi2nDOF(lf_cuts_setMaximumTrackchi2nDOF);
0196 kfparticle->setMinMVTXhits(lf_cuts_setMinMVTXhits);
0197 kfparticle->setMinINTThits(lf_cuts_setMinINTThits);
0198 kfparticle->setMinTPChits(lf_cuts_setMinTPChits);
0199
0200
0201 kfparticle->setMaximumVertexchi2nDOF(lf_cuts_setMaximumVertexchi2nDOF);
0202 kfparticle->setMaximumDaughterDCA(lf_cuts_setMaximumDaughterDCA);
0203 kfparticle->setMaximumDaughterDCA_XY(lf_cuts_setMaximumDaughterDCA_XY);
0204
0205
0206 kfparticle->setMotherPT(lf_cuts_setMotherPT);
0207 kfparticle->setMinimumMass(0.40);
0208 kfparticle->setMaximumMass(0.60);
0209 kfparticle->setMaximumMotherVertexVolume(lf_cuts_setMaximumMotherVertexVolume);
0210 kfparticle->setOutputName(pipi_output_reco_file);
0211
0212 se->registerSubsystem(kfparticle);
0213
0214
0215
0216
0217
0218
0219
0220 }
0221
0222 void reconstruct_KK_mass()
0223 {
0224 Fun4AllServer *se = Fun4AllServer::instance();
0225
0226 KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(KK_reconstruction_name);
0227 kfparticle->Verbosity(VERBOSITY_HF);
0228
0229 kfparticle->setDecayDescriptor(KK_decay_descriptor);
0230 kfparticle->saveOutput(save_kfpntuple);
0231
0232 kfparticle->setTrackMapNodeName(trackMapName);
0233
0234 kfparticle->usePID(true);
0235 kfparticle->setPIDacceptFraction(pid_frac);
0236 kfparticle->get_dEdx_info();
0237 kfparticle->useFakePrimaryVertex(use_fake_pv);
0238 kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0239 kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0240 kfparticle->getAllPVInfo(save_all_vtx_info);
0241 kfparticle->allowZeroMassTracks();
0242 kfparticle->use2Dmatching(use_2D_matching);
0243 kfparticle->getTriggerInfo(get_trigger_info);
0244 kfparticle->getDetectorInfo(get_detector_info);
0245 kfparticle->saveDST(save_tracks_to_DST);
0246 kfparticle->setContainerName(KK_reconstruction_name);
0247 kfparticle->saveParticleContainer(true);
0248 kfparticle->magFieldFile("FIELDMAP_TRACKING");
0249
0250
0251 kfparticle->constrainToPrimaryVertex(true);
0252 kfparticle->setMotherPV_DCA_StdDev(FLT_MAX);
0253 kfparticle->setFlightDistancechi2(-1.);
0254
0255
0256 kfparticle->setMinimumTrackPT(0.1);
0257 kfparticle->setMaximumTrackPT(0.7);
0258 kfparticle->setMaximumTrackchi2nDOF(FLT_MAX);
0259 kfparticle->setMinTPChits(25);
0260 kfparticle->setMinMVTXhits(0);
0261 kfparticle->setMinINTThits(0);
0262
0263
0264 kfparticle->setMaximumVertexchi2nDOF(FLT_MAX);
0265 kfparticle->setMaximumDaughterDCA(FLT_MAX);
0266 kfparticle->setMaximumDaughterDCA_XY(FLT_MAX);
0267
0268
0269 kfparticle->setMotherPT(0);
0270 kfparticle->setMinimumMass(0.98);
0271 kfparticle->setMaximumMass(1.1);
0272 kfparticle->setMaximumMotherVertexVolume(FLT_MAX);
0273
0274 kfparticle->setOutputName(KK_output_reco_file);
0275
0276 se->registerSubsystem(kfparticle);
0277
0278
0279
0280
0281 }
0282
0283 void reconstruct_ppi_mass()
0284 {
0285 Fun4AllServer *se = Fun4AllServer::instance();
0286
0287 KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(ppi_reconstruction_name);
0288 kfparticle->Verbosity(VERBOSITY_HF);
0289
0290 kfparticle->setDecayDescriptor(ppi_decay_descriptor);
0291 kfparticle->saveOutput(save_kfpntuple);
0292
0293 kfparticle->setTrackMapNodeName(trackMapName);
0294
0295 kfparticle->usePID(use_pid);
0296 kfparticle->setPIDacceptFraction(pid_frac);
0297 kfparticle->get_dEdx_info();
0298 kfparticle->useFakePrimaryVertex(use_fake_pv);
0299 kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0300 kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0301 kfparticle->getAllPVInfo(save_all_vtx_info);
0302 kfparticle->allowZeroMassTracks();
0303 kfparticle->use2Dmatching(use_2D_matching);
0304 kfparticle->getTriggerInfo(get_trigger_info);
0305 kfparticle->getDetectorInfo(get_detector_info);
0306 kfparticle->saveDST(save_tracks_to_DST);
0307 kfparticle->setContainerName(ppi_reconstruction_name);
0308 kfparticle->saveParticleContainer(true);
0309 kfparticle->magFieldFile("FIELDMAP_TRACKING");
0310
0311
0312 kfparticle->constrainToPrimaryVertex(true);
0313 kfparticle->setMotherPV_DCA_StdDev(lf_cuts_setMotherIPchi2);
0314 kfparticle->setFlightDistancechi2(lf_cuts_setFlightDistancechi2);
0315 kfparticle->setMinDIRA(lf_cuts_setMinDIRA);
0316 kfparticle->setMinDIRA_XY(lf_cuts_setMinDIRA_XY);
0317 kfparticle->setDecayLengthRange(lf_cuts_setDecayLengthRange_min, lf_cuts_setDecayLengthRange_max);
0318 kfparticle->setDecayLengthRange_XY(lf_cuts_setDecayLengthRange_XY_min, lf_cuts_setDecayLengthRange_XY_max);
0319 kfparticle->setDecayTimeRange_XY(lf_cuts_setDecayTimeRange_XY_min, lf_cuts_setDecayTimeRange_XY_max);
0320 kfparticle->setDecayTimeRange(lf_cuts_setDecayTimeRange_min, lf_cuts_setDecayTimeRange_max);
0321 kfparticle->setMinDecayTimeSignificance(lf_cuts_setMinDecayTimeSignificance);
0322 kfparticle->setMinDecayLengthSignificance(lf_cuts_setMinDecayLengthSignificance);
0323 kfparticle->setMinDecayLengthSignificance_XY(lf_cuts_setMinDecayLengthSignificance_XY);
0324
0325 kfparticle->setMinimumRadialSV(lf_cuts_setMinimumRadialSV);
0326 kfparticle->setMaximumRadialSV(lf_cuts_setMaximumRadialSV);
0327
0328
0329 kfparticle->setMinimumTrackPT(lf_cuts_setMinimumTrackPT);
0330 kfparticle->setMaximumTrackPTchi2(lf_cuts_setMaximumTrackPTchi2);
0331 kfparticle->setMinimumTrackPV_DCA_StdDev(lf_cuts_setMinimumTrackIPchi2);
0332 kfparticle->setMinimumTrackPV_DCA_StdDev_XY(lf_cuts_setMinimumTrackIPchi2_XY);
0333 kfparticle->setMinimumTrackPV_DCA(lf_cuts_setMinimumTrackIP);
0334 kfparticle->setMinimumTrackPV_DCA_XY(lf_cuts_setMinimumTrackIP_XY);
0335 kfparticle->setMaximumTrackchi2nDOF(lf_cuts_setMaximumTrackchi2nDOF);
0336 kfparticle->setMinMVTXhits(lf_cuts_setMinMVTXhits);
0337 kfparticle->setMinINTThits(lf_cuts_setMinINTThits);
0338 kfparticle->setMinTPChits(lf_cuts_setMinTPChits);
0339
0340
0341 kfparticle->setMaximumVertexchi2nDOF(lf_cuts_setMaximumVertexchi2nDOF);
0342 kfparticle->setMaximumDaughterDCA(lf_cuts_setMaximumDaughterDCA);
0343 kfparticle->setMaximumDaughterDCA_XY(lf_cuts_setMaximumDaughterDCA_XY);
0344
0345
0346 kfparticle->setMotherPT(lf_cuts_setMotherPT);
0347 kfparticle->setMinimumMass(1.08);
0348 kfparticle->setMaximumMass(1.15);
0349 kfparticle->setMaximumMotherVertexVolume(lf_cuts_setMaximumMotherVertexVolume);
0350 kfparticle->setOutputName(ppi_output_reco_file);
0351
0352 se->registerSubsystem(kfparticle);
0353
0354
0355
0356
0357 }
0358
0359 void reconstruct_Kpi_mass()
0360 {
0361 Fun4AllServer *se = Fun4AllServer::instance();
0362
0363 KFParticle_sPHENIX *kfparticle = new KFParticle_sPHENIX(Kpi_reconstruction_name);
0364 kfparticle->Verbosity(VERBOSITY_HF);
0365
0366 kfparticle->setDecayDescriptor(Kpi_decay_descriptor);
0367 kfparticle->saveOutput(save_kfpntuple);
0368
0369 kfparticle->setTrackMapNodeName(trackMapName);
0370
0371 kfparticle->usePID(false);
0372 kfparticle->setPIDacceptFraction(pid_frac);
0373 kfparticle->get_dEdx_info();
0374 kfparticle->useFakePrimaryVertex(use_fake_pv);
0375 kfparticle->dontUseGlobalVertex(dont_use_global_vertex);
0376 kfparticle->requireTrackVertexBunchCrossingMatch(require_track_and_vertex_match);
0377 kfparticle->getAllPVInfo(save_all_vtx_info);
0378 kfparticle->allowZeroMassTracks();
0379 kfparticle->use2Dmatching(use_2D_matching);
0380 kfparticle->getTriggerInfo(get_trigger_info);
0381 kfparticle->getDetectorInfo(get_detector_info);
0382 kfparticle->saveDST(save_tracks_to_DST);
0383 kfparticle->setContainerName(Kpi_reconstruction_name);
0384 kfparticle->saveParticleContainer(true);
0385 kfparticle->magFieldFile("FIELDMAP_TRACKING");
0386
0387
0388 kfparticle->constrainToPrimaryVertex(true);
0389
0390 kfparticle->setMotherPV_DCA_StdDev(FLT_MAX);
0391 kfparticle->setFlightDistancechi2(-1.);
0392 kfparticle->setMinDIRA(-1.);
0393 kfparticle->setMinDIRA_XY(-1.1);
0394 kfparticle->setDecayLengthRange(-10., FLT_MAX);
0395 kfparticle->setDecayLengthRange_XY(-10., FLT_MAX);
0396 kfparticle->setDecayTimeRange_XY(-10000, FLT_MAX);
0397 kfparticle->setDecayTimeRange(-10000, FLT_MAX);
0398 kfparticle->setMinDecayTimeSignificance(-1e5);
0399 kfparticle->setMinDecayLengthSignificance(-1e5);
0400 kfparticle->setMinDecayLengthSignificance_XY(-1e5);
0401
0402 kfparticle->setMinimumRadialSV(0.5);
0403
0404
0405 kfparticle->setMinimumTrackPT(0.0);
0406 kfparticle->setMinimumTrackPV_DCA_StdDev(-1.);
0407 kfparticle->setMinimumTrackPV_DCA_StdDev_XY(-1.);
0408 kfparticle->setMinimumTrackPV_DCA(-1.);
0409 kfparticle->setMinimumTrackPV_DCA_XY(-1.);
0410 kfparticle->setMaximumTrackchi2nDOF(FLT_MAX);
0411 kfparticle->setMinMVTXhits(0);
0412 kfparticle->setMinINTThits(0);
0413 kfparticle->setMinTPChits(20);
0414
0415
0416 kfparticle->setMaximumVertexchi2nDOF(FLT_MAX);
0417 kfparticle->setMaximumDaughterDCA(0.5);
0418 kfparticle->setMaximumDaughterDCA_XY(0.5);
0419
0420
0421 kfparticle->setMotherPT(0);
0422 kfparticle->setMinimumMass(1.75);
0423 kfparticle->setMaximumMass(1.95);
0424 kfparticle->setMaximumMotherVertexVolume(FLT_MAX);
0425 kfparticle->setOutputName(Kpi_output_reco_file);
0426
0427 se->registerSubsystem(kfparticle);
0428
0429
0430
0431
0432 }
0433
0434 void end_kfparticle(std::string full_file_name, std::string final_path)
0435 {
0436 ifstream file(full_file_name.c_str());
0437 if (file.good())
0438 {
0439 string moveOutput = "mv " + full_file_name + " " + final_path;
0440 system(moveOutput.c_str());
0441 }
0442 }