LDMX Software
tracking::reco::DigitizationProcessor Class Reference

Public Member Functions

 DigitizationProcessor (const std::string &name, framework::Process &process)
 
void onProcessStart () override
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
void configure (framework::config::Parameters &parameters) override
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
void onNewRun (const ldmx::RunHeader &header) override
 Before the run starts (but after the conditions are configured) set up the random seeds for this run.
 
void produce (framework::Event &event) override
 Process the event and put new data products into it.
 
std::vector< ldmx::MeasurementdigitizeHits (const std::vector< ldmx::SimTrackerHit > &sim_hits)
 Does basic digitization of SimTrackerHits.
 
bool mergeSimHits (const std::vector< ldmx::SimTrackerHit > &sim_hits, std::vector< ldmx::SimTrackerHit > &merged_hits)
 
bool mergeHits (const std::vector< ldmx::SimTrackerHit > &sihits, std::vector< ldmx::SimTrackerHit > &mergedHits)
 
- Public Member Functions inherited from tracking::reco::TrackingGeometryUser
 TrackingGeometryUser (const std::string &name, framework::Process &p)
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Attributes

std::string hit_collection_
 The path to the GDML description of the detector Input hit collection to smear.
 
std::string out_collection_
 Output hit collection name.
 
double min_e_dep_
 Minimum energy deposition cut.
 
int track_id_
 Select a particular track ID.
 
bool merge_hits_ {false}
 Merge the sim hits before digitizing.
 
bool do_smearing_ {true}
 Flag to enable/disable smearing.
 
double sigma_u_ {0}
 u-direction sigma
 
double sigma_v_ {0}
 v-direction sigma
 
std::string tracker_hit_passname_
 Pass Name.
 
std::default_random_engine generator_
 
std::shared_ptr< std::normal_distribution< float > > normal_
 

Additional Inherited Members

- Protected Member Functions inherited from tracking::reco::TrackingGeometryUser
const Acts::GeometryContext & geometryContext ()
 
const Acts::MagneticFieldContext & magneticFieldContext ()
 
const Acts::CalibrationContext & calibrationContext ()
 
const geo::TrackersTrackingGeometrygeometry ()
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 28 of file DigitizationProcessor.h.

Constructor & Destructor Documentation

◆ DigitizationProcessor()

tracking::reco::DigitizationProcessor::DigitizationProcessor ( const std::string & name,
framework::Process & process )

Definition at line 11 of file DigitizationProcessor.cxx.

13 : TrackingGeometryUser(name, process) {}
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void tracking::reco::DigitizationProcessor::configure ( framework::config::Parameters & parameters)
overridevirtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has className equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 19 of file DigitizationProcessor.cxx.

20 {
22 parameters.get<std::string>("hit_collection", "TaggerSimHits");
23
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);
33}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
std::string out_collection_
Output hit collection name.
std::string hit_collection_
The path to the GDML description of the detector Input hit collection to smear.
bool do_smearing_
Flag to enable/disable smearing.
double min_e_dep_
Minimum energy deposition cut.
int track_id_
Select a particular track ID.
bool merge_hits_
Merge the sim hits before digitizing.

References framework::config::Parameters::get().

◆ digitizeHits()

std::vector< ldmx::Measurement > tracking::reco::DigitizationProcessor::digitizeHits ( const std::vector< ldmx::SimTrackerHit > & sim_hits)

Does basic digitization of SimTrackerHits.

For now, this simply uses the global coordinates (SimTrackerHit position) and hit surface to extract the local coordinates. If specified, the local coordinates are smeared and the global coordinates are updated.

Parameters
sim_hitsThe collection of SimTrackerHits to digitize.

Definition at line 172 of file DigitizationProcessor.cxx.

173 {
174 ldmx_log(debug) << "Found: " << sim_hits.size() << " sim hits in the '"
175 << hit_collection_ << "' with passname '"
176 << tracker_hit_passname_ << "'";
177
178 std::vector<ldmx::Measurement> measurements;
179
180 // Loop over all SimTrackerHits and
181 // * Use the position of the SimTrackerHit (global position) and the surface
182 // the hit was created on to extract the local coordinates.
183 // * If specified, smear the local coordinates and update the global
184 // coordinates.
185 // * Create a Measurement object.
186 for (auto& sim_hit : sim_hits) {
187 // Remove low energy deposit hits
188 if (sim_hit.getEdep() > min_e_dep_) {
189 if (track_id_ > 0 && sim_hit.getTrackID() != track_id_) continue;
190
191 ldmx::Measurement measurement(sim_hit);
192
193 // Get the layer_ ID.
194 auto layer_id = tracking::sim::utils::getSensorID(sim_hit);
195 measurement.setLayerID(layer_id);
196
197 // Get the surface
198 auto hit_surface{geometry().getSurface(layer_id)};
199
200 if (hit_surface) {
201 // Transform from global to local coordinates.
202 // hit_surface->toStream(geometry_context(), std::cout);
203 ldmx_log(trace)
204 << "Local to global\n"
205 << hit_surface->transform(geometryContext()).rotation() << "\n"
206 << hit_surface->transform(geometryContext()).translation();
207
208 Acts::Vector3 dummy_momentum;
209 Acts::Vector2 local_pos;
210 // TODO: where is 0.320 mm coming from?
211 double surface_thickness = 0.320 * Acts::UnitConstants::mm;
212 Acts::Vector3 global_pos(measurement.getGlobalPosition()[0],
213 measurement.getGlobalPosition()[1],
214 measurement.getGlobalPosition()[2]);
215
216 try {
217 local_pos = hit_surface
218 ->globalToLocal(geometryContext(), global_pos,
219 dummy_momentum, surface_thickness)
220 .value();
221 } catch (const std::exception& e) {
222 ldmx_log(warn) << "hit not on surface... Skipping.";
223 continue;
224 }
225
226 // Smear the local position
227 if (do_smearing_) {
228 float smear_factor{(*normal_)(generator_)};
229
230 local_pos[0] += smear_factor * sigma_u_;
231 smear_factor = (*normal_)(generator_);
232 local_pos[1] += smear_factor * sigma_v_;
233
234 // update covariance
235 measurement.setLocalCovariance(sigma_u_ * sigma_u_,
237
238 // transform to global
239 auto transf_global_pos{hit_surface->localToGlobal(
240 geometryContext(), local_pos, dummy_momentum)};
241 measurement.setGlobalPosition(measurement.getGlobalPosition()[0],
242 transf_global_pos(1),
243 transf_global_pos(2));
244
245 } // do smearing
246 measurement.setLocalPosition(local_pos(0), local_pos(1));
247 measurements.push_back(measurement);
248 } // hit_surface exists
249
250 } // energy cut
251 } // loop on sim-hits
252
253 return measurements;
254
255} // digitizeHits

References ldmx::Measurement::getGlobalPosition(), ldmx::Measurement::setGlobalPosition(), ldmx::Measurement::setLayerID(), ldmx::Measurement::setLocalCovariance(), and ldmx::Measurement::setLocalPosition().

◆ mergeHits()

bool tracking::reco::DigitizationProcessor::mergeHits ( const std::vector< ldmx::SimTrackerHit > & sihits,
std::vector< ldmx::SimTrackerHit > & mergedHits )

Definition at line 70 of file DigitizationProcessor.cxx.

72 {
73 if (sihits.size() < 1) return false;
74
75 if (sihits.size() == 1) {
76 mergedHits.push_back(sihits[0]);
77 return true;
78 }
79
80 ldmx::SimTrackerHit merged_hit;
81 // Since all the hits will be on the same sensor, just use the ID of the
82 // first
83 merged_hit.setLayerID(sihits[0].getLayerID());
84 merged_hit.setModuleID(sihits[0].getModuleID());
85 merged_hit.setID(sihits[0].getID());
86 merged_hit.setTrackID(sihits[0].getTrackID());
87
88 double x{0}, y{0}, z{0}, px{0}, py{0}, pz{0};
89 double t{0}, e{0}, edep{0}, path{0};
90 int pdg_id{0};
91
92 pdg_id = sihits[0].getPdgID();
93
94 for (auto hit : sihits) {
95 double edep_hit = hit.getEdep();
96 edep += edep_hit;
97 e += hit.getEnergy();
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();
106
107 if (hit.getPdgID() != pdg_id) {
108 ldmx_log(error)
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;
114 return false;
115 }
116 }
117
118 merged_hit.setTime(t / edep);
119 merged_hit.setPosition(x / edep, y / edep, z / edep);
120 merged_hit.setMomentum(px / edep, py / edep, pz / edep);
121 merged_hit.setPathLength(path / edep);
122 merged_hit.setEnergy(e);
123 merged_hit.setEdep(edep);
124 merged_hit.setPdgID(pdg_id);
125
126 mergedHits.push_back(merged_hit);
127
128 return true;
129}
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].

◆ mergeSimHits()

bool tracking::reco::DigitizationProcessor::mergeSimHits ( const std::vector< ldmx::SimTrackerHit > & sim_hits,
std::vector< ldmx::SimTrackerHit > & merged_hits )

Definition at line 131 of file DigitizationProcessor.cxx.

133 {
134 // The first key is the index_ of the sensitive element ID, second key is the
135 // track_id
136 std::map<int, std::map<int, std::vector<ldmx::SimTrackerHit>>> hitmap;
137
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);
142
143 ldmx_log(trace) << "hitmap being filled, size::[" << index << "]["
144 << trackid << "] size " << hitmap[index][trackid].size();
145 }
146
147 typedef std::map<int,
148 std::map<int, std::vector<ldmx::SimTrackerHit>>>::iterator
149 hitmap_it1;
150 typedef std::map<int, std::vector<ldmx::SimTrackerHit>>::iterator hitmap_it2;
151
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);
155 }
156 }
157
158 ldmx_log(debug) << "Sim_hits Size = " << sim_hits.size()
159 << " Merged_hits Size = " << merged_hits.size();
160
161 for (const auto& hit : sim_hits) {
162 ldmx_log(trace) << hit;
163 }
164
165 for (const auto& mhit : merged_hits) {
166 ldmx_log(trace) << mhit;
167 }
168
169 return true;
170}

◆ onNewRun()

void tracking::reco::DigitizationProcessor::onNewRun ( const ldmx::RunHeader & header)
overridevirtual

Before the run starts (but after the conditions are configured) set up the random seeds for this run.

Parameters
[in]headerRunHeader for this run, unused

Reimplemented from framework::EventProcessor.

Definition at line 35 of file DigitizationProcessor.cxx.

35 {
38 generator_.seed(rseed.getSeed("Tracking::DigitizationProcessor"));
39}
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.

References framework::RandomNumberSeedService::CONDITIONS_OBJECT_NAME.

◆ onProcessStart()

void tracking::reco::DigitizationProcessor::onProcessStart ( )
overridevirtual

Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.

Reimplemented from framework::EventProcessor.

Definition at line 15 of file DigitizationProcessor.cxx.

15 {
16 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
17}

◆ produce()

void tracking::reco::DigitizationProcessor::produce ( framework::Event & event)
overridevirtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 41 of file DigitizationProcessor.cxx.

41 {
42 ldmx_log(trace) << " Getting the tracking geometry:" << geometry().getTG();
43
44 // Mode 0: Load simulated hits and produce smeared 1d measurements
45 // Mode 1: Load simulated hits and produce digitized 1d measurements
46
47 const std::vector<ldmx::SimTrackerHit> sim_hits =
48 event.getCollection<ldmx::SimTrackerHit>(hit_collection_,
50
51 std::vector<ldmx::SimTrackerHit> merged_hits;
52
53 std::vector<ldmx::Measurement> measurements;
54 if (merge_hits_) {
55 mergeSimHits(sim_hits, merged_hits);
56 measurements = digitizeHits(merged_hits);
57 } else {
58 measurements = digitizeHits(sim_hits);
59 }
60
61 event.add(out_collection_, measurements);
62}
std::vector< ldmx::Measurement > digitizeHits(const std::vector< ldmx::SimTrackerHit > &sim_hits)
Does basic digitization of SimTrackerHits.

Member Data Documentation

◆ do_smearing_

bool tracking::reco::DigitizationProcessor::do_smearing_ {true}
private

Flag to enable/disable smearing.

Definition at line 78 of file DigitizationProcessor.h.

78{true};

◆ generator_

std::default_random_engine tracking::reco::DigitizationProcessor::generator_
private

Definition at line 88 of file DigitizationProcessor.h.

◆ hit_collection_

std::string tracking::reco::DigitizationProcessor::hit_collection_
private

The path to the GDML description of the detector Input hit collection to smear.

Definition at line 67 of file DigitizationProcessor.h.

◆ merge_hits_

bool tracking::reco::DigitizationProcessor::merge_hits_ {false}
private

Merge the sim hits before digitizing.

Definition at line 76 of file DigitizationProcessor.h.

76{false};

◆ min_e_dep_

double tracking::reco::DigitizationProcessor::min_e_dep_
private

Minimum energy deposition cut.

Definition at line 72 of file DigitizationProcessor.h.

◆ normal_

std::shared_ptr<std::normal_distribution<float> > tracking::reco::DigitizationProcessor::normal_
private

Definition at line 89 of file DigitizationProcessor.h.

◆ out_collection_

std::string tracking::reco::DigitizationProcessor::out_collection_
private

Output hit collection name.

Definition at line 69 of file DigitizationProcessor.h.

◆ sigma_u_

double tracking::reco::DigitizationProcessor::sigma_u_ {0}
private

u-direction sigma

Definition at line 80 of file DigitizationProcessor.h.

80{0};

◆ sigma_v_

double tracking::reco::DigitizationProcessor::sigma_v_ {0}
private

v-direction sigma

Definition at line 82 of file DigitizationProcessor.h.

82{0};

◆ track_id_

int tracking::reco::DigitizationProcessor::track_id_
private

Select a particular track ID.

Definition at line 74 of file DigitizationProcessor.h.

◆ tracker_hit_passname_

std::string tracking::reco::DigitizationProcessor::tracker_hit_passname_
private

Pass Name.

Definition at line 84 of file DigitizationProcessor.h.


The documentation for this class was generated from the following files: