1#include "Tracking/Reco/DigitizationProcessor.h"
9namespace tracking::reco {
11DigitizationProcessor::DigitizationProcessor(
const std::string& name,
13 : TrackingGeometryUser(name, process) {}
15void DigitizationProcessor::onProcessStart() {
16 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
19void DigitizationProcessor::configure(
22 parameters.
get<std::string>(
"hit_collection",
"TaggerSimHits");
24 tracker_hit_passname_ = parameters.
get<std::string>(
"tracker_hit_passname");
26 parameters.
get<std::string>(
"out_collection",
"OutputMeasuements");
27 min_e_dep_ = parameters.
get<
double>(
"min_e_dep", 0.05);
28 track_id_ = parameters.
get<
int>(
"track_id", -1);
29 do_smearing_ = parameters.
get<
bool>(
"do_smearing",
true);
30 sigma_u_ = parameters.
get<
double>(
"sigma_u", 0.01);
31 sigma_v_ = parameters.
get<
double>(
"sigma_v", 0.);
32 merge_hits_ = parameters.
get<
bool>(
"merge_hits",
false);
36 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
38 generator_.seed(rseed.getSeed(
"Tracking::DigitizationProcessor"));
42 ldmx_log(trace) <<
" Getting the tracking geometry:" << geometry().getTG();
47 const std::vector<ldmx::SimTrackerHit> sim_hits =
49 tracker_hit_passname_);
51 std::vector<ldmx::SimTrackerHit> merged_hits;
53 std::vector<ldmx::Measurement> measurements;
55 mergeSimHits(sim_hits, merged_hits);
56 measurements = digitizeHits(merged_hits);
58 measurements = digitizeHits(sim_hits);
61 event.add(out_collection_, measurements);
70bool DigitizationProcessor::mergeHits(
71 const std::vector<ldmx::SimTrackerHit>& sihits,
72 std::vector<ldmx::SimTrackerHit>& mergedHits) {
73 if (sihits.size() < 1)
return false;
75 if (sihits.size() == 1) {
76 mergedHits.push_back(sihits[0]);
85 merged_hit.
setID(sihits[0].getID());
88 double x{0}, y{0}, z{0}, px{0}, py{0}, pz{0};
89 double t{0}, e{0}, edep{0}, path{0};
92 pdg_id = sihits[0].getPdgID();
94 for (
auto hit : sihits) {
95 double edep_hit = hit.getEdep();
98 t += edep_hit * hit.getTime();
99 x += edep_hit * hit.getPosition()[0];
100 y += edep_hit * hit.getPosition()[1];
101 z += edep_hit * hit.getPosition()[2];
102 px += edep_hit * hit.getMomentum()[0];
103 py += edep_hit * hit.getMomentum()[1];
104 pz += edep_hit * hit.getMomentum()[2];
105 path += edep_hit * hit.getPathLength();
107 if (hit.getPdgID() != pdg_id) {
109 <<
"ERROR:: Found hits with compatible sensorID and track_id "
110 "but different PDGID";
111 ldmx_log(error) <<
"TRACKID ==" << hit.getTrackID() <<
" vs "
112 << sihits[0].getTrackID();
113 ldmx_log(error) <<
"PDGID== " << hit.getPdgID() <<
" vs " << pdg_id;
119 merged_hit.
setPosition(x / edep, y / edep, z / edep);
120 merged_hit.
setMomentum(px / edep, py / edep, pz / edep);
126 mergedHits.push_back(merged_hit);
131bool DigitizationProcessor::mergeSimHits(
132 const std::vector<ldmx::SimTrackerHit>& sim_hits,
133 std::vector<ldmx::SimTrackerHit>& merged_hits) {
136 std::map<int, std::map<int, std::vector<ldmx::SimTrackerHit>>> hitmap;
138 for (
const auto& hit : sim_hits) {
139 unsigned int index = tracking::sim::utils::getSensorID(hit);
140 unsigned int trackid = hit.getTrackID();
141 hitmap[index][trackid].push_back(hit);
143 ldmx_log(trace) <<
"hitmap being filled, size::[" << index <<
"]["
144 << trackid <<
"] size " << hitmap[index][trackid].size();
147 typedef std::map<int,
148 std::map<int, std::vector<ldmx::SimTrackerHit>>>::iterator
150 typedef std::map<int, std::vector<ldmx::SimTrackerHit>>::iterator hitmap_it2;
152 for (hitmap_it1 it = hitmap.begin(); it != hitmap.end(); it++) {
153 for (hitmap_it2 it2 = it->second.begin(); it2 != it->second.end(); it2++) {
154 mergeHits(it2->second, merged_hits);
158 ldmx_log(debug) <<
"Sim_hits Size = " << sim_hits.size()
159 <<
" Merged_hits Size = " << merged_hits.size();
161 for (
const auto& hit : sim_hits) {
162 ldmx_log(trace) << hit;
165 for (
const auto& mhit : merged_hits) {
166 ldmx_log(trace) << mhit;
172std::vector<ldmx::Measurement> DigitizationProcessor::digitizeHits(
173 const std::vector<ldmx::SimTrackerHit>& sim_hits) {
174 ldmx_log(debug) <<
"Found: " << sim_hits.size() <<
" sim hits in the '"
175 << hit_collection_ <<
"' with passname '"
176 << tracker_hit_passname_ <<
"'";
178 std::vector<ldmx::Measurement> measurements;
186 for (
auto& sim_hit : sim_hits) {
188 if (sim_hit.getEdep() > min_e_dep_) {
189 if (track_id_ > 0 && sim_hit.getTrackID() != track_id_)
continue;
194 auto layer_id = tracking::sim::utils::getSensorID(sim_hit);
198 auto hit_surface{geometry().getSurface(layer_id)};
204 <<
"Local to global\n"
205 << hit_surface->transform(geometryContext()).rotation() <<
"\n"
206 << hit_surface->transform(geometryContext()).translation();
208 Acts::Vector3 dummy_momentum;
209 Acts::Vector2 local_pos;
211 double surface_thickness = 0.320 * Acts::UnitConstants::mm;
217 local_pos = hit_surface
218 ->globalToLocal(geometryContext(), global_pos,
219 dummy_momentum, surface_thickness)
221 }
catch (
const std::exception& e) {
222 ldmx_log(warn) <<
"hit not on surface... Skipping.";
228 float smear_factor{(*normal_)(generator_)};
230 local_pos[0] += smear_factor * sigma_u_;
231 smear_factor = (*normal_)(generator_);
232 local_pos[1] += smear_factor * sigma_v_;
236 sigma_v_ * sigma_v_);
239 auto transf_global_pos{hit_surface->localToGlobal(
240 geometryContext(), local_pos, dummy_momentum)};
242 transf_global_pos(1),
243 transf_global_pos(2));
247 measurements.push_back(measurement);
#define DECLARE_PRODUCER(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.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
std::array< float, 3 > getGlobalPosition() const
void setLocalPosition(const float &meas_u, const float &meas_v)
Set the local position i.e.
void setLayerID(const int &layer_id)
Set the layer ID of the sensor where this measurement took place.
void setGlobalPosition(const float &meas_x, const float &meas_y, const float &meas_z)
Set the global 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 setPosition(const float x_, const float y_, const float z_)
Set the position of the hit [mm].
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 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.