File indexing completed on 2026-11-13 09:47:02
0001
0002 #include "TrackingTest_processor.h"
0003
0004 #include <JANA/JApplication.h>
0005 #include <JANA/JApplicationFwd.h>
0006 #include <JANA/JEvent.h>
0007 #include <JANA/Services/JGlobalRootLock.h>
0008 #include <JANA/Services/JParameterManager.h>
0009 #include <Math/GenVector/Cartesian3D.h>
0010 #include <Math/GenVector/PxPyPzM4D.h>
0011 #include <edm4eic/MCRecoParticleAssociationCollection.h>
0012 #include <edm4eic/ReconstructedParticleCollection.h>
0013 #include <edm4hep/MCParticleCollection.h>
0014 #include <edm4hep/Vector3d.h>
0015 #include <edm4hep/Vector3f.h>
0016 #include <fmt/format.h>
0017 #include <podio/ObjectID.h>
0018 #include <spdlog/logger.h>
0019 #include <cstddef>
0020 #include <map>
0021 #include <string>
0022 #include <utility>
0023
0024 #include "services/log/Log_service.h"
0025 #include "services/rootfile/RootFile_service.h"
0026
0027 using namespace fmt;
0028
0029
0030
0031
0032 void TrackingTest_processor::Init() {
0033 std::string plugin_name = ("tracking_test");
0034
0035
0036 auto* app = GetApplication();
0037
0038
0039 auto root_file_service = app->GetService<RootFile_service>();
0040
0041
0042 auto globalRootLock = app->GetService<JGlobalRootLock>();
0043 globalRootLock->acquire_write_lock();
0044 auto* file = root_file_service->GetHistFile();
0045 globalRootLock->release_lock();
0046
0047
0048 m_dir_main = file->mkdir(plugin_name.c_str());
0049
0050
0051 m_log = app->GetService<Log_service>()->logger(plugin_name);
0052 for (auto pair : app->GetJParameterManager()->GetAllParameters()) {
0053 m_log->info("{:<20} | {}", pair.first, pair.second->GetDescription());
0054 }
0055 }
0056
0057
0058
0059
0060 void TrackingTest_processor::Process(const std::shared_ptr<const JEvent>& event) {
0061 m_log->debug("---- TrackingTest_processor {} ----", event->GetEventNumber());
0062
0063 ProcessTrackingMatching(event);
0064 }
0065
0066
0067
0068
0069 void TrackingTest_processor::Finish() { fmt::print("OccupancyAnalysis::Finish() called\n"); }
0070
0071 void TrackingTest_processor::ProcessTrackingResults(const std::shared_ptr<const JEvent>& event) {
0072 const auto* reco_particles =
0073 event->GetCollection<edm4eic::ReconstructedParticle>("outputParticles");
0074
0075 m_log->debug("Tracking reconstructed particles N={}: ", reco_particles->size());
0076 m_log->debug(" {:<5} {:>8} {:>8} {:>8} {:>8} {:>8}", "[i]", "[px]", "[py]", "[pz]", "[P]",
0077 "[P*3]");
0078
0079 for (std::size_t i = 0; i < reco_particles->size(); i++) {
0080 auto particle = (*reco_particles)[i];
0081
0082 double px = particle.getMomentum().x;
0083 double py = particle.getMomentum().y;
0084 double pz = particle.getMomentum().z;
0085
0086 ROOT::Math::Cartesian3D p(px, py, pz);
0087 m_log->debug(" {:<5} {:>8.2f} {:>8.2f} {:>8.2f} {:>8.2f} {:>8.2f}", i, px, py, pz, p.R(),
0088 p.R() * 3);
0089 }
0090
0091 const auto* mc_particles = event->GetCollection<edm4hep::MCParticle>("MCParticles");
0092
0093 m_log->debug("MC particles N={}: ", mc_particles->size());
0094 m_log->debug(" {:<5} {:<6} {:<7} {:>8} {:>8} {:>8} {:>8}", "[i]", "status", "[PDG]", "[px]",
0095 "[py]", "[pz]", "[P]");
0096 for (std::size_t i = 0; i < mc_particles->size(); i++) {
0097
0098 const auto& particle = (*mc_particles)[i];
0099
0100 if (particle.getGeneratorStatus() != 1) {
0101 continue;
0102 }
0103
0104 double px = particle.getMomentum().x;
0105 double py = particle.getMomentum().y;
0106 double pz = particle.getMomentum().z;
0107 ROOT::Math::PxPyPzM4D p4v(px, py, pz, particle.getMass());
0108 ROOT::Math::Cartesian3D p(px, py, pz);
0109 if (p.R() < 1) {
0110 continue;
0111 }
0112
0113 m_log->debug(" {:<5} {:<6} {:<7} {:>8.2f} {:>8.2f} {:>8.2f} {:>8.2f}", i,
0114 particle.getGeneratorStatus(), particle.getPDG(), px, py, pz, p.R());
0115 }
0116 }
0117
0118 void TrackingTest_processor::ProcessTrackingMatching(const std::shared_ptr<const JEvent>& event) {
0119 m_log->debug("Associations [simId] [recID] [simE] [recE] [simPDG] [recPDG]");
0120
0121 const auto* associations = event->GetCollection<edm4eic::MCRecoParticleAssociation>(
0122 "ReconstructedChargedParticleAssociations");
0123
0124 for (auto assoc : *associations) {
0125 auto sim = assoc.getSim();
0126 auto rec = assoc.getRec();
0127
0128 m_log->debug(" {:<6} {:<6} {:>8d} {:>8d}", assoc.getSim().getObjectID().index,
0129 assoc.getRec().getObjectID().index, sim.getPDG(), rec.getPDG());
0130 }
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 }
0150
0151 void TrackingTest_processor::ProcessGloablMatching(const std::shared_ptr<const JEvent>& event) {
0152
0153 m_log->debug("ReconstructedParticles (FINAL) [objID] [PDG] [charge] [energy]");
0154 const auto* final_reco_particles =
0155 event->GetCollection<edm4eic::ReconstructedParticle>("ReconstructedParticlesWithAssoc");
0156 for (const auto& part : *final_reco_particles) {
0157 m_log->debug(" {:<6} {:<6} {:>8.2f} {:>8.2f}", part.getObjectID().index, part.getPDG(),
0158 part.getCharge(), part.getEnergy());
0159 }
0160 }