1#include "Tracking/Reco/DigitizationProcessor.h"
5#include "Tracking/Event/Measurement.h"
6#include "Tracking/Sim/TrackingUtils.h"
14namespace tracking::reco {
16DigitizationProcessor::DigitizationProcessor(
const std::string& name,
18 : TrackingGeometryUser(name, process) {}
20void DigitizationProcessor::onProcessStart() {
21 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
22 ldmx_log(info) <<
"Initialization done" << std::endl;
25void DigitizationProcessor::configure(
28 parameters.
getParameter<std::string>(
"hit_collection",
"TaggerSimHits");
29 out_collection_ = parameters.
getParameter<std::string>(
"out_collection",
31 min_e_dep_ = parameters.
getParameter<
double>(
"min_e_dep", 0.05);
32 track_id_ = parameters.
getParameter<
int>(
"track_id", -1);
33 do_smearing_ = parameters.
getParameter<
bool>(
"do_smearing",
true);
34 sigma_u_ = parameters.
getParameter<
double>(
"sigma_u", 0.01);
35 sigma_v_ = parameters.
getParameter<
double>(
"sigma_v", 0.);
36 merge_hits_ = parameters.
getParameter<
bool>(
"merge_hits",
false);
40 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
42 generator_.seed(rseed.getSeed(
"Tracking::DigitizationProcessor"));
46 ldmx_log(debug) <<
" Getting the tracking geometry:" << geometry().getTG();
51 const std::vector<ldmx::SimTrackerHit> sim_hits =
54 std::vector<ldmx::SimTrackerHit> merged_hits;
56 std::vector<ldmx::Measurement> measurements;
58 mergeSimHits(sim_hits, merged_hits);
59 measurements = digitizeHits(merged_hits);
63 measurements = digitizeHits(sim_hits);
66 event.add(out_collection_, measurements);
75bool DigitizationProcessor::mergeHits(
76 const std::vector<ldmx::SimTrackerHit>& sihits,
77 std::vector<ldmx::SimTrackerHit>& mergedHits) {
78 if (sihits.size() < 1)
return false;
80 if (sihits.size() == 1) {
81 mergedHits.push_back(sihits[0]);
89 mergedHit.
setID(sihits[0].getID());
92 double X{0}, Y{0}, Z{0}, PX{0}, PY{0}, PZ{0};
93 double T{0}, E{0}, EDEP{0}, path{0};
96 pdgID = sihits[0].getPdgID();
98 for (
auto hit : sihits) {
99 double edep_hit = hit.getEdep();
101 E += hit.getEnergy();
102 T += edep_hit * hit.getTime();
103 X += edep_hit * hit.getPosition()[0];
104 Y += edep_hit * hit.getPosition()[1];
105 Z += edep_hit * hit.getPosition()[2];
106 PX += edep_hit * hit.getMomentum()[0];
107 PY += edep_hit * hit.getMomentum()[1];
108 PZ += edep_hit * hit.getMomentum()[2];
109 path += edep_hit * hit.getPathLength();
111 if (hit.getPdgID() != pdgID) {
113 <<
"ERROR:: Found hits with compatible sensorID and track_id "
114 "but different PDGID";
115 ldmx_log(error) <<
"TRACKID ==" << hit.getTrackID() <<
" vs "
116 << sihits[0].getTrackID();
117 ldmx_log(error) <<
"PDGID== " << hit.getPdgID() <<
" vs " << pdgID;
123 mergedHit.
setPosition(X / EDEP, Y / EDEP, Z / EDEP);
124 mergedHit.
setMomentum(PX / EDEP, PY / EDEP, PZ / EDEP);
130 mergedHits.push_back(mergedHit);
136bool DigitizationProcessor::mergeSimHits(
137 const std::vector<ldmx::SimTrackerHit>& sim_hits,
138 std::vector<ldmx::SimTrackerHit>& merged_hits) {
141 std::map<int, std::map<int, std::vector<ldmx::SimTrackerHit>>> hitmap;
143 for (
auto hit : sim_hits) {
144 unsigned int index = tracking::sim::utils::getSensorID(hit);
145 unsigned int trackid = hit.getTrackID();
146 hitmap[index][trackid].push_back(hit);
148 ldmx_log(debug) <<
"hitmap being filled, size::[" << index <<
"]["
149 << trackid <<
"] size " << hitmap[index][trackid].size();
152 typedef std::map<int,
153 std::map<int, std::vector<ldmx::SimTrackerHit>>>::iterator
155 typedef std::map<int, std::vector<ldmx::SimTrackerHit>>::iterator hitmap_it2;
156 for (hitmap_it1 it = hitmap.begin(); it != hitmap.end(); it++) {
157 for (hitmap_it2 it2 = it->second.begin(); it2 != it->second.end(); it2++) {
158 mergeHits(it2->second, merged_hits);
162 ldmx_log(debug) <<
"Sim_hits Size=" << sim_hits.size()
163 <<
"Merged_hits Size=" << merged_hits.size();
171std::vector<ldmx::Measurement> DigitizationProcessor::digitizeHits(
172 const std::vector<ldmx::SimTrackerHit>& sim_hits) {
173 ldmx_log(debug) <<
"Found:" << sim_hits.size() <<
" sim hits in the "
176 std::vector<ldmx::Measurement> measurements;
184 for (
auto& sim_hit : sim_hits) {
186 if (sim_hit.getEdep() > min_e_dep_) {
187 if (track_id_ > 0 && sim_hit.getTrackID() != track_id_)
continue;
192 auto layer_id = tracking::sim::utils::getSensorID(sim_hit);
196 auto hit_surface{geometry().getSurface(layer_id)};
202 <<
"Local to global" << std::endl
203 << hit_surface->transform(geometry_context()).rotation()
205 << hit_surface->transform(geometry_context()).translation();
207 Acts::Vector3 dummy_momentum;
208 Acts::Vector2 local_pos;
209 double surface_thickness = 0.320 * Acts::UnitConstants::mm;
215 local_pos = hit_surface
216 ->globalToLocal(geometry_context(), global_pos,
217 dummy_momentum, surface_thickness)
219 }
catch (
const std::exception& e) {
220 ldmx_log(warn) <<
"hit not on surface... Skipping.";
226 float smear_factor{(*normal_)(generator_)};
228 local_pos[0] += smear_factor * sigma_u_;
229 smear_factor = (*normal_)(generator_);
230 local_pos[1] += smear_factor * sigma_v_;
234 sigma_v_ * sigma_v_);
237 auto transf_global_pos{hit_surface->localToGlobal(
238 geometry_context(), local_pos, dummy_momentum)};
240 transf_global_pos(1),
241 transf_global_pos(2));
245 measurements.push_back(measurement);
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Implements an event buffer system for storing event data.
Class which represents the process under execution.
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
std::array< float, 3 > getGlobalPosition() const
void setGlobalPosition(const float &x, const float &y, const float &z)
Set the global position i.e.
void setLayerID(const int &layerid)
Set the layer ID of the sensor where this measurement took place.
void setLocalPosition(const float &u, const float &v)
Set the local position i.e.
void setLocalCovariance(const float &cov_uu, const float &cov_vv)
Set cov(U,U) and cov(V, V).
Represents a simulated tracker hit in the simulation.
void setEdep(const float edep)
Set the energy deposited on the hit [MeV].
void setModuleID(const int moduleID)
Set the module ID associated with a hit.
void setTime(const float time)
Set the global time of the hit [ns].
void setID(const long id)
Set the detector ID of the hit.
void setPosition(const float x, const float y, const float z)
Set the position of the hit [mm].
void setLayerID(const int layerID)
Set the geometric layer ID of the hit.
void setPathLength(const float pathLength)
Set the path length of the hit [mm].
void setEnergy(const float energy)
Set the energy of the hit.
void setPdgID(const int simPdgID)
Set the Sim particle track ID of the hit.
void setTrackID(const int simTrackID)
Set the Sim particle track ID of the hit.
void setMomentum(const float px, const float py, const float pz)
Set the momentum of the particle at the position at which the hit took place [GeV].
All classes in the ldmx-sw project use this namespace.