LDMX Software
Public Member Functions | Private Attributes | List of all members
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 beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 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::default_random_engine generator_
 
std::shared_ptr< std::normal_distribution< float > > normal_
 

Additional Inherited Members

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from tracking::reco::TrackingGeometryUser
const Acts::GeometryContext & geometry_context ()
 
const Acts::MagneticFieldContext & magnetic_field_context ()
 
const Acts::CalibrationContext & calibration_context ()
 
const geo::TrackersTrackingGeometrygeometry ()
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 26 of file DigitizationProcessor.h.

Constructor & Destructor Documentation

◆ DigitizationProcessor()

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

Definition at line 16 of file DigitizationProcessor.cxx.

18 : TrackingGeometryUser(name, process) {}

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 25 of file DigitizationProcessor.cxx.

26 {
28 parameters.getParameter<std::string>("hit_collection", "TaggerSimHits");
29 out_collection_ = parameters.getParameter<std::string>("out_collection",
30 "OutputMeasuements");
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);
37}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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::getParameter().

◆ 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 171 of file DigitizationProcessor.cxx.

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

77 {
78 if (sihits.size() < 1) return false;
79
80 if (sihits.size() == 1) {
81 mergedHits.push_back(sihits[0]);
82 return true;
83 }
84
85 ldmx::SimTrackerHit mergedHit;
86 // Since all the hits will be on the same sensor, just use the ID of the first
87 mergedHit.setLayerID(sihits[0].getLayerID());
88 mergedHit.setModuleID(sihits[0].getModuleID());
89 mergedHit.setID(sihits[0].getID());
90 mergedHit.setTrackID(sihits[0].getTrackID());
91
92 double X{0}, Y{0}, Z{0}, PX{0}, PY{0}, PZ{0};
93 double T{0}, E{0}, EDEP{0}, path{0};
94 int pdgID{0};
95
96 pdgID = sihits[0].getPdgID();
97
98 for (auto hit : sihits) {
99 double edep_hit = hit.getEdep();
100 EDEP += edep_hit;
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();
110
111 if (hit.getPdgID() != pdgID) {
112 ldmx_log(error)
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;
118 return false;
119 }
120 }
121
122 mergedHit.setTime(T / EDEP);
123 mergedHit.setPosition(X / EDEP, Y / EDEP, Z / EDEP);
124 mergedHit.setMomentum(PX / EDEP, PY / EDEP, PZ / EDEP);
125 mergedHit.setPathLength(path / EDEP);
126 mergedHit.setEnergy(E);
127 mergedHit.setEdep(EDEP);
128 mergedHit.setPdgID(pdgID);
129
130 mergedHits.push_back(mergedHit);
131
132 return true;
133}
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].

◆ mergeSimHits()

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

Definition at line 136 of file DigitizationProcessor.cxx.

138 {
139 // The first key is the index of the sensitive element ID, second key is the
140 // track_id
141 std::map<int, std::map<int, std::vector<ldmx::SimTrackerHit>>> hitmap;
142
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);
147
148 ldmx_log(debug) << "hitmap being filled, size::[" << index << "]["
149 << trackid << "] size " << hitmap[index][trackid].size();
150 }
151
152 typedef std::map<int,
153 std::map<int, std::vector<ldmx::SimTrackerHit>>>::iterator
154 hitmap_it1;
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);
159 }
160 }
161
162 ldmx_log(debug) << "Sim_hits Size=" << sim_hits.size()
163 << "Merged_hits Size=" << merged_hits.size();
164
165 // for (auto hit : sim_hits) hit.Print();
166 // for (auto mhit : merged_hits) mhit.Print();
167
168 return true;
169}

◆ 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 39 of file DigitizationProcessor.cxx.

39 {
40 const auto& rseed = getCondition<framework::RandomNumberSeedService>(
42 generator_.seed(rseed.getSeed("Tracking::DigitizationProcessor"));
43}
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 20 of file DigitizationProcessor.cxx.

20 {
21 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
22 ldmx_log(info) << "Initialization done" << std::endl;
23}

◆ 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 45 of file DigitizationProcessor.cxx.

45 {
46 ldmx_log(debug) << " Getting the tracking geometry:" << geometry().getTG();
47
48 // Mode 0: Load simulated hits and produce smeared 1d measurements
49 // Mode 1: Load simulated hits and produce digitized 1d measurements
50
51 const std::vector<ldmx::SimTrackerHit> sim_hits =
52 event.getCollection<ldmx::SimTrackerHit>(hit_collection_);
53
54 std::vector<ldmx::SimTrackerHit> merged_hits;
55
56 std::vector<ldmx::Measurement> measurements;
57 if (merge_hits_) {
58 mergeSimHits(sim_hits, merged_hits);
59 measurements = digitizeHits(merged_hits);
60 }
61
62 else {
63 measurements = digitizeHits(sim_hits);
64 }
65
66 event.add(out_collection_, measurements);
67}
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 75 of file DigitizationProcessor.h.

75{true};

◆ generator_

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

Definition at line 83 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 65 of file DigitizationProcessor.h.

◆ merge_hits_

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

Merge the sim hits before digitizing.

Definition at line 73 of file DigitizationProcessor.h.

73{false};

◆ min_e_dep_

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

Minimum energy deposition cut.

Definition at line 69 of file DigitizationProcessor.h.

◆ normal_

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

Definition at line 84 of file DigitizationProcessor.h.

◆ out_collection_

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

Output hit collection name.

Definition at line 67 of file DigitizationProcessor.h.

◆ sigma_u_

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

u-direction sigma

Definition at line 77 of file DigitizationProcessor.h.

77{0};

◆ sigma_v_

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

v-direction sigma

Definition at line 79 of file DigitizationProcessor.h.

79{0};

◆ track_id_

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

Select a particular track ID.

Definition at line 71 of file DigitizationProcessor.h.


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