LDMX Software
tracking::reco::DigitizationProcessor Class Reference

Digitization processor for the silicon strip tracker. More...

#include <DigitizationProcessor.h>

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::Measurement > digitizeHits (const std::vector< ldmx::SimTrackerHit > &sim_hits, std::vector< ldmx::SimSiStripHit > *raw_hits=nullptr)
 Digitize a collection of SimTrackerHits into Measurements.
 
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 Member Functions

void buildLorentzCache ()
 

Private Attributes

std::string hit_collection_
 Input hit collection to digitize.
 
std::string out_collection_
 Output measurement collection name.
 
double min_e_dep_
 Minimum energy deposition cut [MeV].
 
int track_id_
 Select a particular track ID (-1 = accept all).
 
bool merge_hits_ {false}
 Merge sim hits on the same sensor before digitizing.
 
bool do_smearing_ {true}
 Flag to enable/disable smearing in Mode 0.
 
double sigma_u_ {0}
 u-direction smearing sigma [mm].
 
double sigma_v_ {0}
 v-direction smearing sigma [mm].
 
bool use_charge_digitization_ {false}
 If true, use the full SiStripDigitizer instead of simple smearing.
 
tracking::digitization::SiStripDigitizer::SensorParams sensor_params_
 Parameters forwarded to SiStripDigitizer.
 
std::unique_ptr< tracking::digitization::SiStripDigitizer > strip_digitizer_
 The charge digitizer (constructed in onProcessStart).
 
std::string out_raw_collection_ {""}
 Output raw hit collection name (empty = don't save raw hits).
 
std::unique_ptr< tracking::digitization::PulseShape > pulse_shape_
 The constructed pulse shape (created in onProcessStart).
 
bool use_lorentz_ {true}
 If false, skip Lorentz angle calculation and drift carriers straight (equivalent to zero magnetic field perpendicular to the sensor normal).
 
std::string field_map_ {""}
 Path to the magnetic field map file.
 
std::unordered_map< unsigned int, std::pair< double, double > > lorentz_tan_cache_
 Per-layer cached Lorentz tangents: layer_id → {tan_electron, tan_hole}.
 
std::string tracker_hit_passname_
 Input collection pass name.
 
std::string dump_geo_csv_ {""}
 If non-empty, write a CSV of all ACTS surface transforms to this path.
 
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::TrackersTrackingGeometry & geometry ()
 
void loadBField (const std::string &path, const BFieldDistortion &distortion={})
 Load the interpolated B-field map from path and cache it.
 
void loadBField (const BFieldDistortion &distortion={})
 Load B-field from the path recorded in the detector GDML.
 
std::shared_ptr< Acts::MagneticFieldProvider > bField () const
 Return the loaded B-field provider.
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Static Protected Member Functions inherited from tracking::reco::TrackingGeometryUser
static BFieldDistortion bFieldDistortion (const framework::config::Parameters &parameters)
 Build a BFieldDistortion from processor configuration.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManager & ntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Digitization processor for the silicon strip tracker.

Two modes are available, selected by the use_charge_digitization parameter:

Mode 0 (default, use_charge_digitization = false): Simple Gaussian smearing of the local coordinates. Fast and sufficient for most studies. Resolution set by sigma_u / sigma_v.

Mode 1 (use_charge_digitization = true): Realistic charge digitization. The track segment through the sensor is divided into sub-segments; each creates electron-hole pairs (N = Edep / E_pair). Thermal diffusion during drift spreads the charge as a Gaussian across strips. Electronic noise is added and a threshold is applied; the surviving strip cluster is clustered by a charge-weighted centroid to produce the local U measurement.

Definition at line 42 of file DigitizationProcessor.h.

Constructor & Destructor Documentation

◆ DigitizationProcessor()

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

Definition at line 18 of file DigitizationProcessor.cxx.

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

Member Function Documentation

◆ buildLorentzCache()

void tracking::reco::DigitizationProcessor::buildLorentzCache ( )
private

Definition at line 144 of file DigitizationProcessor.cxx.

144 {
145 if (!use_charge_digitization_) return;
146
147 if (field_map_.empty())
148 loadBField();
149 else
151
152 // Low-field (Hall) mobility from the Canali model [cm²/(V·s)] → [m²/(V·s)]
153 const double t = sensor_params_.temperature;
154 auto carrier_e = tracking::digitization::getCarrier(-1);
155 auto carrier_h = tracking::digitization::getCarrier(1);
156 const double mu_e = carrier_e.mu0(t) * 1.0e-4; // m²/(V·s)
157 const double mu_h = carrier_h.mu0(t) * 1.0e-4;
158
159 auto bfield_cache = bField()->makeCache(magneticFieldContext());
160
161 for (const auto& [layer_id, surface] : geometry().layer_surface_map_) {
162 const Acts::Vector3 center_mm = surface->center(geometryContext());
163 const auto b_result = bField()->getField(center_mm, bfield_cache);
164 if (!b_result.ok()) continue;
165
166 // B in Tesla (ACTS field providers return values in Acts internal units)
167 const Acts::Vector3 b_t = b_result.value() / Acts::UnitConstants::T;
168
169 // Sensor W-normal = 3rd column of the rotation matrix
170 const Acts::Vector3 w_hat =
171 surface->localToGlobalTransform(geometryContext()).rotation().col(2);
172
173 const double bw = b_t.dot(w_hat); // [T]
174
175 // tan(θ_L) = charge_sign · μ · Bw
176 // electrons: charge = −1, holes: charge = +1
177 const double tan_e = -mu_e * bw;
178 const double tan_h = +mu_h * bw;
179
180 lorentz_tan_cache_[layer_id] = {tan_e, tan_h};
181
182 ldmx_log(debug) << "Lorentz cache: layer=" << layer_id << " Bw=" << bw
183 << " T" << " tan_e=" << tan_e << " tan_h=" << tan_h;
184 }
185
186 ldmx_log(info) << "Lorentz tangents computed for "
187 << lorentz_tan_cache_.size() << " layers from field map "
188 << (field_map_.empty() ? geometry().fieldMapFile()
189 : field_map_);
190}
tracking::digitization::SiStripDigitizer::SensorParams sensor_params_
Parameters forwarded to SiStripDigitizer.
std::unordered_map< unsigned int, std::pair< double, double > > lorentz_tan_cache_
Per-layer cached Lorentz tangents: layer_id → {tan_electron, tan_hole}.
bool use_charge_digitization_
If true, use the full SiStripDigitizer instead of simple smearing.
std::string field_map_
Path to the magnetic field map file.
void loadBField(const std::string &path, const BFieldDistortion &distortion={})
Load the interpolated B-field map from path and cache it.
std::shared_ptr< Acts::MagneticFieldProvider > bField() const
Return the loaded B-field provider.

◆ 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 class_name equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 92 of file DigitizationProcessor.cxx.

93 {
95 parameters.get<std::string>("hit_collection", "TaggerSimHits");
96
97 tracker_hit_passname_ = parameters.get<std::string>("tracker_hit_passname");
99 parameters.get<std::string>("out_collection", "OutputMeasuements");
100 min_e_dep_ = parameters.get<double>("min_e_dep", 0.05);
101 track_id_ = parameters.get<int>("track_id", -1);
102 do_smearing_ = parameters.get<bool>("do_smearing", true);
103 sigma_u_ = parameters.get<double>("sigma_u", 0.01);
104 sigma_v_ = parameters.get<double>("sigma_v", 0.);
105 merge_hits_ = parameters.get<bool>("merge_hits", false);
106
107 // Mode 1: charge digitization parameters
109 parameters.get<bool>("use_charge_digitization", false);
110
112 sensor_params_.bias_voltage = parameters.get<double>("bias_voltage", 200.0);
114 parameters.get<double>("depletion_voltage", 70.0);
115 sensor_params_.temperature = parameters.get<double>("temperature", 300.0);
117 parameters.get<double>("noise_electrons", 1000.0);
119 parameters.get<double>("threshold_electrons", 3000.0);
120 // Fixed sensor properties — not user-configurable.
121 // LDMX (and HPS) use n-type bulk with hole-side readout.
125 use_lorentz_ = parameters.get<bool>("use_lorentz", true);
127 parameters.get<double>("electron_lorentz_tangent", 0.0);
129 parameters.get<double>("hole_lorentz_tangent", 0.0);
130 sensor_params_.trapping = parameters.get<double>("trapping", 0.0);
132 parameters.get<double>("deposition_granularity", 0.10);
133 sensor_params_.n_segments_min = parameters.get<int>("n_segments_min", 5);
134 // n_readout_strips is fixed by the sensor geometry constant
135 // N_READOUT_STRIPS.
136
137 out_raw_collection_ = parameters.get<std::string>("out_raw_collection", "");
138 field_map_ = parameters.get<std::string>("field_map", "");
139 }
140
141 dump_geo_csv_ = parameters.get<std::string>("dump_geo_csv", "");
142}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
std::string out_collection_
Output measurement collection name.
std::string hit_collection_
Input hit collection to digitize.
bool do_smearing_
Flag to enable/disable smearing in Mode 0.
std::string dump_geo_csv_
If non-empty, write a CSV of all ACTS surface transforms to this path.
bool use_lorentz_
If false, skip Lorentz angle calculation and drift carriers straight (equivalent to zero magnetic fie...
std::string tracker_hit_passname_
Input collection pass name.
double min_e_dep_
Minimum energy deposition cut [MeV].
int track_id_
Select a particular track ID (-1 = accept all).
double sigma_u_
u-direction smearing sigma [mm].
bool merge_hits_
Merge sim hits on the same sensor before digitizing.
double sigma_v_
v-direction smearing sigma [mm].
std::string out_raw_collection_
Output raw hit collection name (empty = don't save raw hits).
double electron_lorentz_tangent
tan(θ_Lorentz) for electrons. Sign encodes U-shift direction.
double threshold_electrons
Readout threshold [electrons]. Strips below this are suppressed.
double noise_electrons
Electronic noise sigma [electrons ENC].
double bias_voltage
Applied reverse-bias voltage [V].
double deposition_granularity
Adaptive segmentation granularity: max U-step as fraction of sense_pitch.
double trapping
Charge-trapping fraction lost per 100 µm of drift.
bool hole_side_readout
Simulate and read out the hole-collection side (p-strips / backplane).
int n_segments_min
Minimum number of track sub-segments (used when the track is close to normal incidence so the adaptiv...
bool electron_side_readout
Simulate and read out the electron-collection side (n-strips).
bool is_n_type
true = n-type bulk; false = p-type bulk. LDMX (and HPS) use n-type bulk.

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

◆ digitizeHits()

std::vector< ldmx::Measurement > tracking::reco::DigitizationProcessor::digitizeHits ( const std::vector< ldmx::SimTrackerHit > & sim_hits,
std::vector< ldmx::SimSiStripHit > * raw_hits = nullptr )

Digitize a collection of SimTrackerHits into Measurements.

Operates in either smearing mode or full charge-digitization mode depending on the use_charge_digitization configuration flag.

Parameters
sim_hitsThe collection of SimTrackerHits to digitize.
raw_hitsIf non-null and charge digitization is active, filled with one SimSiStripHit per above-threshold readout strip.

Definition at line 330 of file DigitizationProcessor.cxx.

332 {
333 ldmx_log(debug) << "Found: " << sim_hits.size() << " sim hits in '"
334 << hit_collection_ << "' with passname '"
335 << tracker_hit_passname_ << "'";
336
337 std::vector<ldmx::Measurement> measurements;
338
339 struct StripContrib {
340 double charge_electrons_;
341 double hit_time_ns_;
342 int track_id_;
343 int pdg_id_;
344 int sim_hit_id_;
345 float edep_;
346 };
347 // layer_id -> strip_idx -> per-hit contributions (populated in Phase 1,
348 // consumed in Phase 2 after the loop to apply noise once per strip)
349 std::map<int, std::map<int, std::vector<StripContrib>>> layer_strip_contribs;
350
351 for (auto& sim_hit : sim_hits) {
352 // Energy deposition cut
353 if (sim_hit.getEdep() <= min_e_dep_) continue;
354 if (track_id_ > 0 && sim_hit.getTrackID() != track_id_) continue;
355
356 ldmx::Measurement measurement(sim_hit);
357
358 // Sensor identification
359 auto layer_id = tracking::sim::utils::getSensorID(sim_hit);
360 measurement.setLayerID(layer_id);
361
362 auto hit_surface{geometry().getSurface(layer_id)};
363 if (!hit_surface) continue;
364
365 ldmx_log(trace)
366 << "Local to global\n"
367 << hit_surface->localToGlobalTransform(geometryContext()).rotation()
368 << "\n"
369 << hit_surface->localToGlobalTransform(geometryContext()).translation();
370
371 // -----------------------------------------------------------------------
372 // Project global hit position onto the surface (2D local coords)
373 // -----------------------------------------------------------------------
374 Acts::Vector3 dummy_momentum;
375 Acts::Vector2 local_pos_2d;
376
377 // TODO: clarify / derive the 0.320 mm surface tolerance from the geometry
378 constexpr double surface_thickness = 0.320 * Acts::UnitConstants::mm;
379
380 Acts::Vector3 global_pos(measurement.getGlobalPosition()[0],
381 measurement.getGlobalPosition()[1],
382 measurement.getGlobalPosition()[2]);
383
384 try {
385 local_pos_2d = hit_surface
386 ->globalToLocal(geometryContext(), global_pos,
387 dummy_momentum, surface_thickness)
388 .value();
389 } catch (const std::exception& e) {
390 ldmx_log(warn) << "hit not on surface... Skipping.";
391 continue;
392 }
393
394 // Store the projected truth U before any smearing or charge digitization.
395 measurement.setTruthU(static_cast<float>(local_pos_2d[0]));
396
397 // -----------------------------------------------------------------------
398 // Mode 1: realistic charge digitization
399 // -----------------------------------------------------------------------
401 // Read sensor thickness from the geometry.
402 const auto* placement = hit_surface->surfacePlacement();
403 if (!placement) {
404 ldmx_log(warn) << "No detector element for layer_id=" << layer_id
405 << " — skipping hit";
406 continue;
407 }
408 const double thickness =
409 static_cast<const tracking::geo::DetectorElement*>(placement)
410 ->thickness();
411 strip_digitizer_->setThickness(thickness);
412
413 // Build the full 3D local position and direction for charge simulation.
414 const Acts::Transform3 surf_transform =
415 hit_surface->localToGlobalTransform(geometryContext());
416
417 // 3D local position: apply the inverse surface transform to the global
418 // hit position so that we know the depth (W) coordinate.
419 const Acts::Vector3 local_pos_3d = surf_transform.inverse() * global_pos;
420
421 // 3D local direction: rotate the global unit momentum into local frame.
422 // Apply the same LDMX→ACTS frame permutation as Measurement.cxx:
423 // ACTS-X = LDMX-z [2], ACTS-Y = LDMX-x [0], ACTS-Z = LDMX-y [1].
424 Acts::Vector3 global_mom(sim_hit.getMomentum()[2],
425 sim_hit.getMomentum()[0],
426 sim_hit.getMomentum()[1]);
427 const double mom_mag = global_mom.norm();
428
429 Acts::Vector3 local_dir_3d;
430 if (mom_mag > 0.0) {
431 local_dir_3d =
432 surf_transform.rotation().transpose() * (global_mom / mom_mag);
433 } else {
434 // Degenerate case: treat as normal incidence
435 local_dir_3d = Acts::Vector3(0.0, 0.0, 1.0);
436 }
437
438 // Path length through the sensor; fall back to thickness / |cos θ|
439 // if the stored value is not set.
440 double path_length = sim_hit.getPathLength();
441 if (path_length <= 0.0) {
442 const double cos_theta = std::abs(local_dir_3d[2]);
443 path_length = (cos_theta > 1e-3) ? thickness / cos_theta : thickness;
444 }
445
446 // Apply per-layer Lorentz tangents from the B-field cache (if available).
447 if (use_lorentz_) {
448 auto lorentz_it = lorentz_tan_cache_.find(layer_id);
449 if (lorentz_it != lorentz_tan_cache_.end()) {
450 strip_digitizer_->mutableParams().electron_lorentz_tangent =
451 lorentz_it->second.first;
452 strip_digitizer_->mutableParams().hole_lorentz_tangent =
453 lorentz_it->second.second;
454 }
455 }
456
457 // Compute charge deposited on each strip
458 auto strip_charges = strip_digitizer_->computeStripCharges(
459 sim_hit.getEdep(), local_pos_3d, local_dir_3d, path_length);
460
461 ldmx_log(trace) << "Charge digi: " << strip_charges.size()
462 << " strips from computeStripCharges (pre-noise)";
463
464 // Phase 1: accumulate this hit's strip charges into the per-layer map.
465 // Noise is applied once per strip in Phase 2 (after the sim-hit loop)
466 // so that overlapping contributions from different SimParticles are
467 // summed before threshold is applied.
468 if (raw_hits && pulse_shape_) {
469 const double hit_time_ns = sim_hit.getTime();
470 for (const auto& [strip_idx, charge] : strip_charges) {
471 layer_strip_contribs[layer_id][strip_idx].push_back(StripContrib{
472 charge, hit_time_ns, sim_hit.getTrackID(), sim_hit.getPdgID(),
473 sim_hit.getID(), sim_hit.getEdep()});
474 }
475 }
476
477 // Measurements are produced downstream by StripFitProcessor +
478 // StripClusterProcessor for the reconstructed position, but we still
479 // emit a truth-position Measurement here so that DigiDQM can build a
480 // per-layer truth-U lookup for the sim_cluster_du residual.
481 // Global position, time, edep, ID, and track ID are already populated
482 // by the Measurement(sim_hit) constructor above; set local coords and
483 // zero the covariance (this is a truth hit, not a smeared measurement).
484 measurement.setLocalPosition(local_pos_2d(0), local_pos_2d(1));
485 measurement.setLocalCovariance(0., 0.);
486 measurements.push_back(measurement);
487
488 // -----------------------------------------------------------------------
489 // Mode 0: simple Gaussian smearing
490 // -----------------------------------------------------------------------
491 } else {
492 if (do_smearing_) {
493 float smear_factor{(*normal_)(generator_)};
494 local_pos_2d[0] += smear_factor * sigma_u_;
495 smear_factor = (*normal_)(generator_);
496 local_pos_2d[1] += smear_factor * sigma_v_;
497
498 measurement.setLocalCovariance(
499 static_cast<float>(sigma_u_ * sigma_u_),
500 static_cast<float>(tracking::digitization::SIGMA_V_MM *
501 tracking::digitization::SIGMA_V_MM));
502
503 auto transf_global_pos{hit_surface->localToGlobal(
504 geometryContext(), local_pos_2d, dummy_momentum)};
505 measurement.setGlobalPosition(measurement.getGlobalPosition()[0],
506 transf_global_pos(1),
507 transf_global_pos(2));
508 }
509
510 measurement.setLocalPosition(local_pos_2d(0), local_pos_2d(1));
511 measurements.push_back(measurement);
512 }
513 } // loop over sim hits
514
515 // Phase 2: apply noise once per strip across all sim-hit contributions,
516 // then build SimSiStripHits with correctly superimposed pulse shapes.
517 if (raw_hits && pulse_shape_) {
518 const int adc_max = (1 << tracking::digitization::ADC_BITS) - 1;
519
520 for (auto& [lyr_id, strip_contribs_map] : layer_strip_contribs) {
521 // Sum all contributions to get the total pre-noise charge per strip.
522 std::map<int, double> total_charges;
523 for (const auto& [strip_idx, contribs] : strip_contribs_map) {
524 double total = 0.0;
525 for (const auto& c : contribs) total += c.charge_electrons_;
526 total_charges[strip_idx] = total;
527 }
528
529 // Add noise to every strip (and its ±1 neighbours) then apply threshold.
530 strip_digitizer_->applyNoiseAndThreshold(total_charges);
531 if (total_charges.empty()) continue;
532
533 for (const auto& [strip_idx, final_charge] : total_charges) {
534 const auto contrib_it = strip_contribs_map.find(strip_idx);
535 const bool has_signal = (contrib_it != strip_contribs_map.end());
536
537 int track_id_out = -1;
538 int pdg_id_out = 0;
539 int sim_hit_id_out = -1;
540 float edep_out = 0.f;
541 double ref_time_ns = 0.0;
542 std::vector<short> samples(tracking::digitization::N_SAMPLES);
543
544 if (has_signal) {
545 const auto& contribs = contrib_it->second;
546
547 // Dominant contributor = strip's largest single charge deposit.
548 const StripContrib* dom = &contribs.front();
549 for (const auto& c : contribs)
550 if (c.charge_electrons_ > dom->charge_electrons_) dom = &c;
551
552 ref_time_ns = dom->hit_time_ns_;
553 track_id_out = dom->track_id_;
554 pdg_id_out = dom->pdg_id_;
555 sim_hit_id_out = dom->sim_hit_id_;
556 for (const auto& c : contribs) edep_out += c.edep_;
557
558 // ADC = pedestal + superposition of each contributor's shaped pulse.
559 for (int isamp = 0; isamp < tracking::digitization::N_SAMPLES;
560 ++isamp) {
561 const double t_samp =
562 tracking::digitization::T0_OFFSET_NS +
563 isamp * tracking::digitization::SAMPLING_INTERVAL_NS;
564 double val =
565 static_cast<double>(tracking::digitization::ADC_PEDESTAL);
566 for (const auto& c : contribs)
567 val += (c.charge_electrons_ /
568 tracking::digitization::ADC_ELECTRONS_PER_COUNT) *
569 pulse_shape_->eval(t_samp - c.hit_time_ns_);
570 samples[isamp] = static_cast<short>(
571 std::clamp(static_cast<int>(std::round(val)), 0, adc_max));
572 }
573 } else {
574 // Noise-only strip: added as a ±1 neighbour by
575 // applyNoiseAndThreshold. Borrow the nearest signal strip's dominant
576 // hit time for pulse shaping.
577 for (int delta : {-1, +1}) {
578 const auto nb = strip_contribs_map.find(strip_idx + delta);
579 if (nb != strip_contribs_map.end() && !nb->second.empty()) {
580 const StripContrib* dom = &nb->second.front();
581 for (const auto& c : nb->second)
582 if (c.charge_electrons_ > dom->charge_electrons_) dom = &c;
583 ref_time_ns = dom->hit_time_ns_;
584 break;
585 }
586 }
587 const double peak_adc =
588 final_charge / tracking::digitization::ADC_ELECTRONS_PER_COUNT;
589 for (int isamp = 0; isamp < tracking::digitization::N_SAMPLES;
590 ++isamp) {
591 const double t_samp =
592 tracking::digitization::T0_OFFSET_NS +
593 isamp * tracking::digitization::SAMPLING_INTERVAL_NS;
594 const double val =
595 static_cast<double>(tracking::digitization::ADC_PEDESTAL) +
596 peak_adc * pulse_shape_->eval(t_samp - ref_time_ns);
597 samples[isamp] = static_cast<short>(
598 std::clamp(static_cast<int>(std::round(val)), 0, adc_max));
599 }
600 }
601
602 raw_hits->emplace_back(lyr_id, strip_idx, std::move(samples),
603 static_cast<long>(ref_time_ns), track_id_out,
604 pdg_id_out, sim_hit_id_out, edep_out);
605 }
606 }
607 } // Phase 2
608
609 return measurements;
610} // digitizeHits
std::unique_ptr< tracking::digitization::PulseShape > pulse_shape_
The constructed pulse shape (created in onProcessStart).
std::unique_ptr< tracking::digitization::SiStripDigitizer > strip_digitizer_
The charge digitizer (constructed in onProcessStart).

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

◆ mergeHits()

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

Definition at line 231 of file DigitizationProcessor.cxx.

233 {
234 if (sihits.size() < 1) return false;
235
236 if (sihits.size() == 1) {
237 mergedHits.push_back(sihits[0]);
238 return true;
239 }
240
241 ldmx::SimTrackerHit merged_hit;
242 merged_hit.setLayerID(sihits[0].getLayerID());
243 merged_hit.setModuleID(sihits[0].getModuleID());
244 merged_hit.setID(sihits[0].getID());
245 merged_hit.setTrackID(sihits[0].getTrackID());
246
247 double x{0}, y{0}, z{0}, px{0}, py{0}, pz{0};
248 double t{0}, e{0}, edep{0}, path{0};
249 int pdg_id = sihits[0].getPdgID();
250
251 for (auto hit : sihits) {
252 double edep_hit = hit.getEdep();
253 edep += edep_hit;
254 e += hit.getEnergy();
255 t += edep_hit * hit.getTime();
256 x += edep_hit * hit.getPosition()[0];
257 y += edep_hit * hit.getPosition()[1];
258 z += edep_hit * hit.getPosition()[2];
259 px += edep_hit * hit.getMomentum()[0];
260 py += edep_hit * hit.getMomentum()[1];
261 pz += edep_hit * hit.getMomentum()[2];
262 path += edep_hit * hit.getPathLength();
263
264 if (hit.getPdgID() != pdg_id) {
265 ldmx_log(error)
266 << "ERROR:: Found hits with compatible sensorID and track_id "
267 "but different PDGID";
268 ldmx_log(error) << "TRACKID ==" << hit.getTrackID() << " vs "
269 << sihits[0].getTrackID();
270 ldmx_log(error) << "PDGID== " << hit.getPdgID() << " vs " << pdg_id;
271 return false;
272 }
273 }
274
275 merged_hit.setTime(t / edep);
276 merged_hit.setPosition(x / edep, y / edep, z / edep);
277 merged_hit.setMomentum(px / edep, py / edep, pz / edep);
278 merged_hit.setPathLength(path / edep);
279 merged_hit.setEnergy(e);
280 merged_hit.setEdep(edep);
281 merged_hit.setPdgID(pdg_id);
282
283 mergedHits.push_back(merged_hit);
284 return true;
285}
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 287 of file DigitizationProcessor.cxx.

289 {
290 // Key: [sensor_id][track_id] → list of hits to merge
291 std::map<int, std::map<int, std::vector<ldmx::SimTrackerHit>>> hitmap;
292
293 for (const auto& hit : sim_hits) {
294 unsigned int index = tracking::sim::utils::getSensorID(hit);
295 unsigned int trackid = hit.getTrackID();
296 hitmap[index][trackid].push_back(hit);
297
298 ldmx_log(trace) << "hitmap being filled, size::[" << index << "]["
299 << trackid << "] size " << hitmap[index][trackid].size();
300 }
301
302 typedef std::map<int,
303 std::map<int, std::vector<ldmx::SimTrackerHit>>>::iterator
304 hitmap_it1;
305 typedef std::map<int, std::vector<ldmx::SimTrackerHit>>::iterator hitmap_it2;
306
307 for (hitmap_it1 it = hitmap.begin(); it != hitmap.end(); it++) {
308 for (hitmap_it2 it2 = it->second.begin(); it2 != it->second.end(); it2++) {
309 mergeHits(it2->second, merged_hits);
310 }
311 }
312
313 ldmx_log(debug) << "Sim_hits Size = " << sim_hits.size()
314 << " Merged_hits Size = " << merged_hits.size();
315
316 for (const auto& hit : sim_hits) {
317 ldmx_log(trace) << hit;
318 }
319 for (const auto& mhit : merged_hits) {
320 ldmx_log(trace) << mhit;
321 }
322
323 return true;
324}

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

192 {
195 const uint64_t seed = rseed.getSeed("Tracking::DigitizationProcessor");
196 generator_.seed(seed);
197 if (strip_digitizer_) strip_digitizer_->seed(seed);
198}
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 22 of file DigitizationProcessor.cxx.

22 {
23 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
24
27 std::make_unique<tracking::digitization::SiStripDigitizer>(
29 ldmx_log(info) << "Charge digitization enabled."
30 << " thickness=from geometry"
31 << " sense_pitch=" << tracking::digitization::SENSE_PITCH_MM
32 << " mm" << " readout_pitch="
33 << tracking::digitization::READOUT_PITCH_MM << " mm"
34 << " Vbias=" << sensor_params_.bias_voltage << " V"
35 << " Vdep=" << sensor_params_.depletion_voltage << " V"
36 << " bulk=" << (sensor_params_.is_n_type ? "n" : "p")
37 << "-type" << " e_lorentz_tan="
39 << " h_lorentz_tan=" << sensor_params_.hole_lorentz_tangent
40 << " trapping=" << sensor_params_.trapping
41 << " noise=" << sensor_params_.noise_electrons << " e-"
42 << " threshold=" << sensor_params_.threshold_electrons
43 << " e-"
44 << " n_segments_min=" << sensor_params_.n_segments_min
45 << " granularity=" << sensor_params_.deposition_granularity;
46
48 std::string(tracking::digitization::PULSE_SHAPE_NAME),
49 tracking::digitization::PEAKING_TIME_NS,
50 tracking::digitization::SECOND_TIME_CONST_NS);
51 ldmx_log(info) << "Pulse shaping: shape="
52 << tracking::digitization::PULSE_SHAPE_NAME
53 << " tp=" << tracking::digitization::PEAKING_TIME_NS
54 << " ns"
55 << " n_samples=" << tracking::digitization::N_SAMPLES
56 << " sampling_interval="
57 << tracking::digitization::SAMPLING_INTERVAL_NS << " ns"
58 << " t0_offset=" << tracking::digitization::T0_OFFSET_NS
59 << " ns";
60
61 if (field_map_.empty()) {
62 ldmx_log(debug) << "field_map not set; will auto-load from GDML";
63 }
64 if (use_lorentz_)
65 buildLorentzCache();
66 else
67 ldmx_log(info)
68 << "Lorentz angle correction disabled (use_lorentz=false).";
69 }
70
71 // Dump all ACTS surfaces to CSV for geometry verification.
72 if (!dump_geo_csv_.empty()) {
73 std::ofstream csv(dump_geo_csv_);
74 csv << "layer_id,cx,cy,cz,Ux,Uy,Uz,Vx,Vy,Vz,Wx,Wy,Wz\n";
75 for (const auto& [layer_id, surface] : geometry().layer_surface_map_) {
76 const auto& xf = surface->localToGlobalTransform(geometryContext());
77 const auto ctr = xf.translation(); // centre [mm in Acts units]
78 const auto r = xf.rotation();
79 const auto u = r.col(0);
80 const auto v = r.col(1);
81 const auto w = r.col(2);
82 csv << layer_id << "," << ctr.x() << "," << ctr.y() << "," << ctr.z()
83 << "," << u.x() << "," << u.y() << "," << u.z() << "," << v.x() << ","
84 << v.y() << "," << v.z() << "," << w.x() << "," << w.y() << ","
85 << w.z() << "\n";
86 }
87 ldmx_log(info) << "Surface geometry written to " << dump_geo_csv_ << " ("
88 << geometry().layer_surface_map_.size() << " surfaces)";
89 }
90}
static std::unique_ptr< PulseShape > make(const std::string &name, double tp, double tp2=0.0)
Factory: construct a pulse shape by name.

References tracking::digitization::PulseShape::make().

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

200 {
201 ldmx_log(trace) << " Getting the tracking geometry:" << geometry().getTG();
202
203 const auto& sim_hits = event.getCollection<ldmx::SimTrackerHit>(
205
206 std::vector<ldmx::SimTrackerHit> merged_hits;
207 std::vector<ldmx::Measurement> measurements;
208 std::vector<ldmx::SimSiStripHit> raw_hits;
209
210 const bool save_raw =
212 auto* raw_ptr = save_raw ? &raw_hits : nullptr;
213
214 if (merge_hits_) {
215 mergeSimHits(sim_hits, merged_hits);
216 measurements = digitizeHits(merged_hits, raw_ptr);
217 } else {
218 measurements = digitizeHits(sim_hits, raw_ptr);
219 }
220
221 event.add(out_collection_, measurements);
222 if (save_raw) {
223 event.add(out_raw_collection_, raw_hits);
224 }
225}
std::vector< ldmx::Measurement > digitizeHits(const std::vector< ldmx::SimTrackerHit > &sim_hits, std::vector< ldmx::SimSiStripHit > *raw_hits=nullptr)
Digitize a collection of SimTrackerHits into Measurements.

Member Data Documentation

◆ do_smearing_

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

Flag to enable/disable smearing in Mode 0.

Definition at line 98 of file DigitizationProcessor.h.

98{true};

◆ dump_geo_csv_

std::string tracking::reco::DigitizationProcessor::dump_geo_csv_ {""}
private

If non-empty, write a CSV of all ACTS surface transforms to this path.

Definition at line 142 of file DigitizationProcessor.h.

142{""};

◆ field_map_

std::string tracking::reco::DigitizationProcessor::field_map_ {""}
private

Path to the magnetic field map file.

Empty = use fixed configured tangents.

Definition at line 128 of file DigitizationProcessor.h.

128{""};

◆ generator_

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

Definition at line 144 of file DigitizationProcessor.h.

◆ hit_collection_

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

Input hit collection to digitize.

Definition at line 83 of file DigitizationProcessor.h.

◆ lorentz_tan_cache_

std::unordered_map<unsigned int, std::pair<double, double> > tracking::reco::DigitizationProcessor::lorentz_tan_cache_
private

Per-layer cached Lorentz tangents: layer_id → {tan_electron, tan_hole}.

Definition at line 131 of file DigitizationProcessor.h.

◆ merge_hits_

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

Merge sim hits on the same sensor before digitizing.

Definition at line 92 of file DigitizationProcessor.h.

92{false};

◆ min_e_dep_

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

Minimum energy deposition cut [MeV].

Definition at line 88 of file DigitizationProcessor.h.

◆ normal_

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

Definition at line 145 of file DigitizationProcessor.h.

◆ out_collection_

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

Output measurement collection name.

Definition at line 85 of file DigitizationProcessor.h.

◆ out_raw_collection_

std::string tracking::reco::DigitizationProcessor::out_raw_collection_ {""}
private

Output raw hit collection name (empty = don't save raw hits).

Definition at line 116 of file DigitizationProcessor.h.

116{""};

◆ pulse_shape_

std::unique_ptr<tracking::digitization::PulseShape> tracking::reco::DigitizationProcessor::pulse_shape_
private

The constructed pulse shape (created in onProcessStart).

Definition at line 118 of file DigitizationProcessor.h.

◆ sensor_params_

tracking::digitization::SiStripDigitizer::SensorParams tracking::reco::DigitizationProcessor::sensor_params_
private

Parameters forwarded to SiStripDigitizer.

Definition at line 110 of file DigitizationProcessor.h.

◆ sigma_u_

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

u-direction smearing sigma [mm].

Definition at line 100 of file DigitizationProcessor.h.

100{0};

◆ sigma_v_

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

v-direction smearing sigma [mm].

Definition at line 102 of file DigitizationProcessor.h.

102{0};

◆ strip_digitizer_

std::unique_ptr<tracking::digitization::SiStripDigitizer> tracking::reco::DigitizationProcessor::strip_digitizer_
private

The charge digitizer (constructed in onProcessStart).

Definition at line 112 of file DigitizationProcessor.h.

◆ track_id_

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

Select a particular track ID (-1 = accept all).

Definition at line 90 of file DigitizationProcessor.h.

◆ tracker_hit_passname_

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

Input collection pass name.

Definition at line 139 of file DigitizationProcessor.h.

◆ use_charge_digitization_

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

If true, use the full SiStripDigitizer instead of simple smearing.

Definition at line 108 of file DigitizationProcessor.h.

108{false};

◆ use_lorentz_

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

If false, skip Lorentz angle calculation and drift carriers straight (equivalent to zero magnetic field perpendicular to the sensor normal).

Definition at line 125 of file DigitizationProcessor.h.

125{true};

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