LDMX Software
tracking::reco::TruthSeedProcessor Class Reference

Create a track seed using truth information extracted from the corresponding SimParticle or SimTrackerHit. More...

#include <TruthSeedProcessor.h>

Public Member Functions

 TruthSeedProcessor (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~TruthSeedProcessor ()=default
 Destructor.
 
void configure (framework::config::Parameters &parameters) override
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
void onProcessStart () override
 Callback for the EventProcessor to take any necessary action when the processing of events starts.
 
void onNewRun (const ldmx::RunHeader &rh) override
 onNewRun is the first function called for each processor after the conditions are fully configured and accessible.
 
void produce (framework::Event &event) override
 Main loop that creates the seed tracks for both the tagger and recoil tracker.
 
- 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 makeHitCountMap (const std::vector< ldmx::SimTrackerHit > &sim_hits, std::map< int, std::vector< int > > &hit_count_map)
 Create a mapping from the selected scoring plane hit objects to the number of hits they associated particle creates in the tracker.
 
void createTruthTrack (const ldmx::SimParticle &particle, ldmx::Track &trk, const std::shared_ptr< Acts::Surface > &target_surface)
 Use the vertex position of the SimParticle to extract (x_, y_, z_, px, py, pz, q) and create a track seed.
 
void createTruthTrack (const ldmx::SimParticle &particle, const ldmx::SimTrackerHit &hit, ldmx::Track &trk, const std::shared_ptr< Acts::Surface > &target_surface)
 Use the scoring plane hit at the target to extract (x_, y_, z_, px, py, pz) and create a track seed.
 
void createTruthTrack (const std::vector< double > &pos_vec, const std::vector< double > &p_vec, int charge, ldmx::Track &trk, const std::shared_ptr< Acts::Surface > &target_surface)
 Create a seed track from the given position, momentum and charge.
 
bool scoringPlaneHitFilter (const ldmx::SimTrackerHit &hit, const std::vector< ldmx::SimTrackerHit > &ecal_sp_hits)
 Filter that checks if a scoring plane passes specified momentum cuts as well as if the associated SimParticle hits the ECal.
 
ldmx::Track seedFromTruth (const ldmx::Track &tt, bool seed_smearing)
 Create a track seed from a truth track applying a smearing to the truth parameters as well as an inflation to the covariance matrix.
 
ldmx::Track recoilFullSeed (const ldmx::SimParticle &particle, const int trackID, const ldmx::SimTrackerHit &hit, const ldmx::SimTrackerHit &ecal_hit, const std::map< int, std::vector< int > > &hit_count_map, const std::shared_ptr< Acts::Surface > &origin_surface, const std::shared_ptr< Acts::Surface > &target_surface, const std::shared_ptr< Acts::Surface > &ecal_surface)
 
ldmx::Track taggerFullSeed (const ldmx::SimParticle &beam_electron, const int trackID, const ldmx::SimTrackerHit &hit, const std::map< int, std::vector< int > > &hit_count_map, const std::shared_ptr< Acts::Surface > &origin_surface, const std::shared_ptr< Acts::Surface > &target_surface)
 This method retrieves the beam electron and forms a full seed The seed parameters are the truth parameters from the beam electron stored at the beam origin Additionally, the foolowing track states are stored ts_smeared : the truth smeared perigee state at the beam origin ts_truth_target : the truth on-surface state at the target Linear extrapolations are done from the origin of the particle to the reference surfaces This track also contains the list of hits belonging to the beam electron on the sensitive surfaces on the tagger tracker, for acceptance studies.
 

Private Attributes

std::vector< int > pdg_ids_ {11}
 pdg_ids of the particles we want to select for the seeds
 
std::string scoring_hits_coll_name_ {"TargetScoringPlaneHits"}
 Which scoring plane hits to use for the truth seeds generation.
 
std::string ecal_sp_coll_name_ {"EcalScoringPlaneHits"}
 
std::string sp_pass_name_ {""}
 
std::string tagger_sim_hits_coll_name_ {"TaggerSimHits"}
 Sim hits to check if the truth seed is findable.
 
std::string recoil_sim_hits_coll_name_ {"RecoilSimHits"}
 Sim hits to check if the truth seed is findable.
 
std::string input_pass_name_ {""}
 Pass name for the sim hit collections.
 
std::string sim_particles_coll_name_
 
std::string sim_particles_passname_
 
int n_min_hits_tagger_ {7}
 Minimum number of hits left in the recoil tracker to consider the seed as findable.
 
int n_min_hits_recoil_ {7}
 Minimum number of hits left in the recoil tracker to consider the seed as findable.
 
float z_min_ {-999}
 Min cut on the z_ of the scoring hit.
 
int track_id_ {-999}
 Only select a particular trackID.
 
double pz_cut_ {-9999}
 Ask for a minimum pz for the seeds.
 
double p_cut_ {0.}
 Ask for a minimum p for the seeds.
 
double p_cut_max_ {100000.}
 Ask for a maximum p for the seeds.
 
double p_cut_ecal_ {-1.}
 
bool recoil_sp_ {true}
 
bool target_sp_ {true}
 
bool skip_tagger_ {false}
 
bool skip_recoil_ {false}
 
int max_track_id_ {5}
 
std::unique_ptr< const TruthPropagator > propagator_
 
std::shared_ptr< tracking::reco::TrackExtrapolatorTool< TruthPropagator > > trk_extrap_
 
std::string field_map_ {""}
 Path to the magnetic field map.
 
std::default_random_engine generator_
 
std::shared_ptr< std::normal_distribution< float > > normal_
 
bool seed_smearing_ {false}
 
std::vector< double > d0smear_
 
std::vector< double > z0smear_
 
double phismear_
 
double thetasmear_
 
double relpsmear_
 
std::vector< double > rel_smearfactors_
 
std::vector< double > inflate_factors_
 
std::vector< double > beam_origin_ {-880.1, -44., 0.}
 
int particle_hypothesis_
 
std::string beam_electrons_collection_
 
std::string tagger_truth_collection_
 
std::string recoil_truth_collection_
 
std::string tagger_seeds_collection_
 
std::string recoil_seeds_collection_
 

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

Create a track seed using truth information extracted from the corresponding SimParticle or SimTrackerHit.

When creating seeds in the Tagger tracker, the SimParticle associated with the incident electron (trackID == 1) is used to create the seed from the parameters (x_, y_, z_, px, py, pz, q) at the vertex. For the Recoil tracker, since the electron is produced upstream, the SimParticle can't be used to get any parameters at the target. In this case, the target scoring plane hits are used to extract the parameters above.

Definition at line 36 of file TruthSeedProcessor.h.

Constructor & Destructor Documentation

◆ TruthSeedProcessor()

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

Constructor.

Parameters
nameName for this instance of the class.
processThe Process class associated with EventProcessor, provided by the framework.

Definition at line 12 of file TruthSeedProcessor.cxx.

14 : 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::TruthSeedProcessor::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.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 58 of file TruthSeedProcessor.cxx.

58 {
60 parameters.get<std::string>("scoring_hits_coll_name");
61 ecal_sp_coll_name_ = parameters.get<std::string>("ecal_sp_coll_name");
62 sp_pass_name_ = parameters.get<std::string>("sp_pass_name");
64 parameters.get<std::string>("recoil_sim_hits_coll_name");
66 parameters.get<std::string>("tagger_sim_hits_coll_name");
67 input_pass_name_ = parameters.get<std::string>("input_pass_name");
68 sim_particles_coll_name_ =
69 parameters.get<std::string>("sim_particles_coll_name");
70 sim_particles_passname_ =
71 parameters.get<std::string>("sim_particles_passname");
72
73 n_min_hits_tagger_ = parameters.get<int>("n_min_hits_tagger", 11);
74 n_min_hits_recoil_ = parameters.get<int>("n_min_hits_recoil", 7);
75 pdg_ids_ = parameters.get<std::vector<int>>("pdg_ids", {11});
76 z_min_ = parameters.get<double>("z_min", -9999); // mm
77 track_id_ = parameters.get<int>("track_id", -9999);
78 pz_cut_ = parameters.get<double>("pz_cut", -9999); // MeV
79 p_cut_ = parameters.get<double>("p_cut", 0.);
80 p_cut_max_ = parameters.get<double>("p_cut_max", 100000.); // MeV
81 p_cut_ecal_ = parameters.get<double>("p_cut_ecal", -1.); // MeV
82 recoil_sp_ = parameters.get<double>("recoil_sp", true);
83 target_sp_ = parameters.get<double>("tagger_sp", true);
84 seed_smearing_ = parameters.get<bool>("seedSmearing", false);
85 max_track_id_ = parameters.get<int>("max_track_id", 5);
86
87 ldmx_log(info) << "Seed Smearing is set to " << seed_smearing_;
88
89 d0smear_ = parameters.get<std::vector<double>>("d0smear", {0.01, 0.01, 0.01});
90 z0smear_ = parameters.get<std::vector<double>>("z0smear", {0.1, 0.1, 0.1});
91 phismear_ = parameters.get<double>("phismear", 0.001);
92 thetasmear_ = parameters.get<double>("thetasmear", 0.001);
93 relpsmear_ = parameters.get<double>("relpsmear", 0.1);
94
95 // Relative smear factor terms, only used if seed_smearing_ is true.
96 rel_smearfactors_ = parameters.get<std::vector<double>>(
97 "rel_smearfactors", {0.1, 0.1, 0.1, 0.1, 0.1, 0.1});
98 inflate_factors_ = parameters.get<std::vector<double>>(
99 "inflate_factors", {10., 10., 10., 10., 10., 10.});
100
101 // In tracking frame: where do these numbers come from?
102 // These numbers come from approximating the path of the beam up
103 // until it is about to enter the first detector volume (TriggerPad1).
104 // In detector coordinates, (x_,y_,z_) = (-21.7, -883) is
105 // where the beam arrives (if no smearing is applied) and we simply
106 // reorder these values so that they are in tracking coordinates.
107 beam_origin_ = parameters.get<std::vector<double>>("beamOrigin",
108 {-883.0, -21.745876, 0.0});
109
110 // Skip the tagger or recoil trackers if wanted
111 skip_tagger_ = parameters.get<bool>("skip_tagger", false);
112 skip_recoil_ = parameters.get<bool>("skip_recoil", false);
113 particle_hypothesis_ = parameters.get<int>("particle_hypothesis");
114
115 beam_electrons_collection_ =
116 parameters.get<std::string>("beam_electrons_collection");
117 tagger_truth_collection_ =
118 parameters.get<std::string>("tagger_truth_collection");
119 recoil_truth_collection_ =
120 parameters.get<std::string>("recoil_truth_collection");
121 tagger_seeds_collection_ =
122 parameters.get<std::string>("tagger_seeds_collection");
123 recoil_seeds_collection_ =
124 parameters.get<std::string>("recoil_seeds_collection");
125 // Get the field map for the propagator
126 field_map_ = parameters.get<std::string>("field_map");
127}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
float z_min_
Min cut on the z_ of the scoring hit.
std::string input_pass_name_
Pass name for the sim hit collections.
std::string recoil_sim_hits_coll_name_
Sim hits to check if the truth seed is findable.
std::vector< int > pdg_ids_
pdg_ids of the particles we want to select for the seeds
int track_id_
Only select a particular trackID.
double pz_cut_
Ask for a minimum pz for the seeds.
double p_cut_
Ask for a minimum p for the seeds.
std::string field_map_
Path to the magnetic field map.
std::string scoring_hits_coll_name_
Which scoring plane hits to use for the truth seeds generation.
std::string tagger_sim_hits_coll_name_
Sim hits to check if the truth seed is findable.
double p_cut_max_
Ask for a maximum p for the seeds.
int n_min_hits_tagger_
Minimum number of hits left in the recoil tracker to consider the seed as findable.
int n_min_hits_recoil_
Minimum number of hits left in the recoil tracker to consider the seed as findable.

References field_map_, framework::config::Parameters::get(), input_pass_name_, n_min_hits_recoil_, n_min_hits_tagger_, p_cut_, p_cut_max_, pdg_ids_, pz_cut_, recoil_sim_hits_coll_name_, scoring_hits_coll_name_, tagger_sim_hits_coll_name_, track_id_, and z_min_.

◆ createTruthTrack() [1/3]

void tracking::reco::TruthSeedProcessor::createTruthTrack ( const ldmx::SimParticle & particle,
const ldmx::SimTrackerHit & hit,
ldmx::Track & trk,
const std::shared_ptr< Acts::Surface > & target_surface )
private

Use the scoring plane hit at the target to extract (x_, y_, z_, px, py, pz) and create a track seed.

In this case, the SimParticle is used to extract the charge of the particle.

Parameters
particleThe SimParticle to extract the charge from.
hitThe SimTrackerHit used to create the seed.

Definition at line 129 of file TruthSeedProcessor.cxx.

131 {
132 std::vector<double> pos{static_cast<double>(hit.getPosition()[0]),
133 static_cast<double>(hit.getPosition()[1]),
134 static_cast<double>(hit.getPosition()[2])};
135 createTruthTrack(pos, hit.getMomentum(), particle.getCharge(), trk,
136 target_surface);
137
138 trk.setTrackID(hit.getTrackID());
139 trk.setPdgID(hit.getPdgID());
140}
double getCharge() const
Get the charge of this particle.
int getPdgID() const
Get the Sim particle track ID of the hit.
std::vector< float > getPosition() const
Get the XYZ position of the hit [mm].
std::vector< double > getMomentum() const
Get the XYZ momentum of the particle at the position at which the hit took place [MeV].
int getTrackID() const
Get the Sim particle track ID of the hit.
void createTruthTrack(const ldmx::SimParticle &particle, ldmx::Track &trk, const std::shared_ptr< Acts::Surface > &target_surface)
Use the vertex position of the SimParticle to extract (x_, y_, z_, px, py, pz, q) and create a track ...

References createTruthTrack(), ldmx::SimParticle::getCharge(), ldmx::SimTrackerHit::getMomentum(), ldmx::SimTrackerHit::getPdgID(), ldmx::SimTrackerHit::getPosition(), and ldmx::SimTrackerHit::getTrackID().

◆ createTruthTrack() [2/3]

void tracking::reco::TruthSeedProcessor::createTruthTrack ( const ldmx::SimParticle & particle,
ldmx::Track & trk,
const std::shared_ptr< Acts::Surface > & target_surface )
private

Use the vertex position of the SimParticle to extract (x_, y_, z_, px, py, pz, q) and create a track seed.

Parameters
particleThe SimParticle to make a seed from.

Definition at line 142 of file TruthSeedProcessor.cxx.

144 {
145 createTruthTrack(particle.getVertex(), particle.getMomentum(),
146 particle.getCharge(), trk, target_surface);
147
148 trk.setPdgID(particle.getPdgID());
149}
std::vector< double > getVertex() const
Get a vector containing the vertex of this particle in mm.
int getPdgID() const
Get the PDG ID of this particle.
Definition SimParticle.h:87
std::vector< double > getMomentum() const
Get a vector containing the momentum of this particle [MeV].

References createTruthTrack(), ldmx::SimParticle::getCharge(), ldmx::SimParticle::getMomentum(), ldmx::SimParticle::getPdgID(), and ldmx::SimParticle::getVertex().

Referenced by createTruthTrack(), createTruthTrack(), and taggerFullSeed().

◆ createTruthTrack() [3/3]

void tracking::reco::TruthSeedProcessor::createTruthTrack ( const std::vector< double > & pos_vec,
const std::vector< double > & p_vec,
int charge,
ldmx::Track & trk,
const std::shared_ptr< Acts::Surface > & target_surface )
private

Create a seed track from the given position, momentum and charge.

Parameters
pos_The position at which the particle was created.
pThe momentum of the particle at the point of creation.
chargeThe charge of the particle.
target_surfacethe surface to where to express the truth track

Definition at line 151 of file TruthSeedProcessor.cxx.

154 {
155 // Get the position and momentum of the particle at the point of creation.
156 // This only works for the incident electron when creating a tagger tracker
157 // seed. For the recoil tracker, the scoring plane position will need to
158 // be used. For other particles created in the target or tracker planes,
159 // this version of the method can also be used.
160 // These are just Eigen vectors defined as
161 // Eigen::Matrix<double, kSize, 1>;
162 Acts::Vector3 pos{pos_vec[0], pos_vec[1], pos_vec[2]};
163 Acts::Vector3 mom{p_vec[0], p_vec[1], p_vec[2]};
164
165 // Rotate the position and momentum into the ACTS frame.
166 pos = tracking::sim::utils::ldmx2Acts(pos);
167 mom = tracking::sim::utils::ldmx2Acts(mom);
168
169 // Get the charge of the particle.
170 // TODO: Add function that uses the PDG ID to calculate this.
171 double q{charge * Acts::UnitConstants::e};
172
173 // The idea here is:
174 // 1 - Define a bound track state parameters at point P on track. Basically a
175 // curvilinear representation.
176 // 2 - Propagate to target surface to obtain the
177 // BoundTrackState there.
178
179 // Transform the position, momentum and charge to free parameters.
180 auto free_params{tracking::sim::utils::toFreeParameters(pos, mom, q)};
181
182 // Create a line surface at the perigee. The perigee position is extracted
183 // from a particle's vertex or the particle's position at a specific
184 // scoring plane.
185 auto gen_surface{Acts::Surface::makeShared<Acts::PerigeeSurface>(
186 Acts::Vector3(free_params[Acts::eFreePos0], free_params[Acts::eFreePos1],
187 free_params[Acts::eFreePos2]))};
188
189 // ldmx_log(trace)<<"PF:: gen_surface"<<free_params[Acts::eFreePos0]<<"
190 // " <<free_params[Acts::eFreePos1]<<" " <<free_params[Acts::eFreePos2];
191
192 // Transform the parameters to local positions on the perigee surface.
193 auto bound_params{Acts::transformFreeToBoundParameters(
194 free_params, *gen_surface, geometryContext())
195 .value()};
196 // Create a particle hypothesis
197 auto part{Acts::ParticleHypothesis(Acts::PdgParticle(particle_hypothesis_))};
198 Acts::BoundTrackParameters bound_trk_pars(gen_surface, bound_params,
199 std::nullopt, part);
200
201 auto prop_bound_state =
202 trk_extrap_->extrapolate(bound_trk_pars, target_surface);
203
204 if (!prop_bound_state) {
205 ldmx_log(warn) << "Propagation to target surface failed — "
206 << "track may have exited the B-field map.";
207 return;
208 }
209
210 // Create the seed track object.
211 Acts::Vector3 ref = target_surface->center(geometryContext());
212 Acts::Vector3 ref_ldmx = tracking::sim::utils::acts2Ldmx(ref);
213 trk.setPerigeeLocation(ref_ldmx(0), ref_ldmx(1), ref_ldmx(2));
214
215 auto prop_bound_vec = prop_bound_state->parameters();
216
217 trk.setPerigeeParameters(
218 tracking::sim::utils::convertActsToLdmxPars(prop_bound_vec));
219}

◆ makeHitCountMap()

void tracking::reco::TruthSeedProcessor::makeHitCountMap ( const std::vector< ldmx::SimTrackerHit > & sim_hits,
std::map< int, std::vector< int > > & hit_count_map )
private

Create a mapping from the selected scoring plane hit objects to the number of hits they associated particle creates in the tracker.

Parameters
sim_hitsvector
hit_count_mapfilled with the hits lefts by each track

Definition at line 472 of file TruthSeedProcessor.cxx.

474 {
475 for (int i_sim_hit = 0; i_sim_hit < sim_hits.size(); i_sim_hit++) {
476 auto& sim_hit = sim_hits.at(i_sim_hit);
477 // This track never left a hit before
478 if (!hit_count_map.count(sim_hit.getTrackID())) {
479 hit_count_map[sim_hit.getTrackID()].push_back(i_sim_hit);
480 }
481
482 // This track left a hit before.
483 // Check if it's on a different sensor than the others
484
485 else {
486 int sensor_id = tracking::sim::utils::getSensorID(sim_hit);
487 bool found_hit = false;
488
489 for (auto& i_rhit : hit_count_map[sim_hit.getTrackID()]) {
490 int tmp_sensor_id =
491 tracking::sim::utils::getSensorID(sim_hits.at(i_rhit));
492
493 if (sensor_id == tmp_sensor_id) {
494 found_hit = true;
495 break;
496 }
497 } // loop on the already recorded hits
498
499 if (!found_hit) {
500 hit_count_map[sim_hit.getTrackID()].push_back(i_sim_hit);
501 }
502 }
503 } // loop on sim hits
504}

Referenced by produce().

◆ onNewRun()

void tracking::reco::TruthSeedProcessor::onNewRun ( const ldmx::RunHeader & rh)
overridevirtual

onNewRun is the first function called for each processor after the conditions are fully configured and accessible.

This is where you could create single-processors, multi-event calculation objects.

Reimplemented from framework::EventProcessor.

Definition at line 16 of file TruthSeedProcessor.cxx.

16 {
17 normal_ = std::make_shared<std::normal_distribution<float>>(0., 1.);
18
19 // Custom transformation of the interpolated bfield map
20 auto transform_pos = [](const Acts::Vector3& pos_) {
21 Acts::Vector3 rot_pos;
22 rot_pos(0) = pos_(1);
23 rot_pos(1) = pos_(2);
24 rot_pos(2) = pos_(0) + DIPOLE_OFFSET;
25 return rot_pos;
26 };
27
28 auto transform_b_field = [](const Acts::Vector3& field,
29 const Acts::Vector3& /*pos_*/) {
30 Acts::Vector3 rot_field;
31 rot_field(0) = field(2);
32 rot_field(1) = field(0);
33 rot_field(2) = field(1);
34 return rot_field;
35 };
36
37 // Setup the interpolated bfield map
38 const auto map = std::make_shared<InterpolatedMagneticField3>(
39 loadDefaultBField(field_map_, transform_pos, transform_b_field));
40
41 // Setup the stepper and navigator
42 const auto stepper = Acts::EigenStepper<>{map};
43 Acts::Navigator::Config nav_cfg{geometry().getTG()};
44 nav_cfg.resolveMaterial = true;
45 nav_cfg.resolvePassive = true;
46 nav_cfg.resolveSensitive = true;
47 const Acts::Navigator navigator(nav_cfg);
48
49 propagator_ = std::make_unique<TruthPropagator>(
50 stepper, navigator,
51 Acts::getDefaultLogger("TruthPropagator", Acts::Logging::FATAL));
52 trk_extrap_ = std::make_shared<std::decay_t<decltype(*trk_extrap_)>>(
53 *propagator_, geometryContext(), magneticFieldContext());
54 trk_extrap_->setMaxStepSize(200); // mm
55 trk_extrap_->setPathLimit(3000); // mm
56}

References field_map_.

◆ onProcessStart()

void tracking::reco::TruthSeedProcessor::onProcessStart ( )
inlineoverridevirtual

Callback for the EventProcessor to take any necessary action when the processing of events starts.

For this class, the callback is used to retrieve the GeometryContext from ACTS.

Reimplemented from framework::EventProcessor.

Definition at line 67 of file TruthSeedProcessor.h.

67{};

◆ produce()

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

Main loop that creates the seed tracks for both the tagger and recoil tracker.

Parameters
eventThe event containing the collections to process.

Implements framework::Producer.

Definition at line 560 of file TruthSeedProcessor.cxx.

560 {
561 // Retrieve the particleMap
562 auto particle_map{event.getMap<int, ldmx::SimParticle>(
563 sim_particles_coll_name_, sim_particles_passname_)};
564
565 // Retrieve the target scoring hits
566 // Information is extracted using the
567 // scoring plane hit left by the particle at the target.
568
569 const auto& scoring_hits = event.getCollection<ldmx::SimTrackerHit>(
570 scoring_hits_coll_name_, sp_pass_name_);
571
572 // Retrieve the sim hits in the tagger tracker
573 const auto& tagger_sim_hits = event.getCollection<ldmx::SimTrackerHit>(
575
576 // Retrieve the sim hits in the recoil tracker
577 const auto& recoil_sim_hits = event.getCollection<ldmx::SimTrackerHit>(
579
580 // If sim hit collections are empty throw a warning
581 if (tagger_sim_hits.size() == 0 && !skip_tagger_) {
582 ldmx_log(error) << "Tagger sim hits collection empty for event ";
583 }
584 if (recoil_sim_hits.size() == 0 && !skip_recoil_) {
585 ldmx_log(error) << "Recoil sim hits collection empty for event ";
586 }
587
588 // The map stores which track leaves which sim hits
589 std::map<int, std::vector<int>> hit_count_map_recoil;
590 makeHitCountMap(recoil_sim_hits, hit_count_map_recoil);
591
592 std::map<int, std::vector<int>> hit_count_map_tagger;
593 makeHitCountMap(tagger_sim_hits, hit_count_map_tagger);
594
595 // to keep track of how many sim particles leave hits on the scoring plane
596 std::vector<int> recoil_sh_idxs;
597 std::unordered_map<int, std::vector<int>> recoil_sh_count_map;
598
599 std::vector<int> tagger_sh_idxs;
600 std::unordered_map<int, std::vector<int>> tagger_sh_count_map;
601
602 // Target scoring hits for Tagger will have Z<0, Recoil scoring hits will
603 // have Z>0
604 for (unsigned int i_sh = 0; i_sh < scoring_hits.size(); i_sh++) {
605 const ldmx::SimTrackerHit& hit = scoring_hits.at(i_sh);
606 double zhit = hit.getPosition()[2];
607
608 Acts::Vector3 p_vec{hit.getMomentum()[0], hit.getMomentum()[1],
609 hit.getMomentum()[2]};
610 double tagger_p_max = 0.;
611
612 // Check if it is a tagger track going fwd that passes basic cuts
613 if (zhit < 0.) {
614 // Tagger selection cuts
615 // Negative scoring plane hit, with momentum > p_cut
616 if (p_vec(2) < 0. || p_vec.norm() < p_cut_) continue;
617
618 // Check that the hit was left by a charged particle
619 if (abs(particle_map[hit.getTrackID()].getCharge()) < 1e-8) continue;
620
621 if (p_vec.norm() > tagger_p_max) {
622 tagger_sh_count_map[hit.getTrackID()].push_back(i_sh);
623 }
624 } // Tagger loop
625
626 // Check the recoil hits
627 else {
628 // Recoil selection cuts
629 // Positive scoring plane hit, forward direction with momentum > p_cut
630 if (p_vec(2) < 0. || p_vec.norm() < p_cut_) continue;
631
632 // Check that the hit was left by a charged particle
633 if (abs(particle_map[hit.getTrackID()].getCharge()) < 1e-8) continue;
634
635 recoil_sh_count_map[hit.getTrackID()].push_back(i_sh);
636
637 } // Recoil
638 } // loop on Target scoring plane hits
639
640 for (std::pair<int, std::vector<int>> element : recoil_sh_count_map) {
641 std::sort(
642 element.second.begin(), element.second.end(),
643 [&](const int idx1, int idx2) -> bool {
644 const ldmx::SimTrackerHit& hit1 = scoring_hits.at(idx1);
645 const ldmx::SimTrackerHit& hit2 = scoring_hits.at(idx2);
646
647 Acts::Vector3 phit1{hit1.getMomentum()[0], hit1.getMomentum()[1],
648 hit1.getMomentum()[2]};
649 Acts::Vector3 phit2{hit2.getMomentum()[0], hit2.getMomentum()[1],
650 hit2.getMomentum()[2]};
651
652 return phit1.norm() > phit2.norm();
653 });
654 }
655
656 // Sort tagger hits.
657 for (auto& [_track_id, hit_indices] : tagger_sh_count_map) {
658 std::sort(
659 hit_indices.begin(), hit_indices.end(),
660 [&](const int idx1, int idx2) -> bool {
661 const ldmx::SimTrackerHit& hit1 = scoring_hits.at(idx1);
662 const ldmx::SimTrackerHit& hit2 = scoring_hits.at(idx2);
663
664 Acts::Vector3 phit1{hit1.getMomentum()[0], hit1.getMomentum()[1],
665 hit1.getMomentum()[2]};
666 Acts::Vector3 phit2{hit2.getMomentum()[0], hit2.getMomentum()[1],
667 hit2.getMomentum()[2]};
668
669 return phit1.norm() > phit2.norm();
670 });
671 }
672
673 // Building of the event truth information and the truth seeds
674 // TODO remove the truthtracks in the future as the truth seeds are enough
675
676 std::vector<ldmx::Track> tagger_truth_tracks;
677 std::vector<ldmx::Track> tagger_truth_seeds;
678 std::vector<ldmx::Track> recoil_truth_tracks;
679 std::vector<ldmx::Track> recoil_truth_seeds;
680 std::vector<ldmx::Track> beam_electrons;
681
682 // TODO:: The target should be taken from some conditions DB in the future.
683 // Define the perigee_surface at 0.0.0
684 auto target_surface{Acts::Surface::makeShared<Acts::PerigeeSurface>(
685 Acts::Vector3(0., 0., 0.))};
686
687 // Define the target_surface
688 auto target_unbound_surface = tracking::sim::utils::unboundSurface(0.);
689
690 // ecal
691 auto ecal_surface = tracking::sim::utils::unboundSurface(240.5);
692
693 auto beam_origin_surface{Acts::Surface::makeShared<Acts::PerigeeSurface>(
694 Acts::Vector3(beam_origin_[0], beam_origin_[1], beam_origin_[2]))};
695
696 if (!skip_tagger_) {
697 for (const auto& [track_id, hit_indices] : tagger_sh_count_map) {
698 const ldmx::SimTrackerHit& hit = scoring_hits.at(hit_indices.at(0));
699 const ldmx::SimParticle& phit = particle_map[hit.getTrackID()];
700
701 if (hit_count_map_tagger[hit.getTrackID()].size() > n_min_hits_tagger_) {
702 ldmx::Track truth_tagger_track;
703 createTruthTrack(phit, hit, truth_tagger_track, target_surface);
704 truth_tagger_track.setNhits(
705 hit_count_map_tagger[hit.getTrackID()].size());
706 // Add AtTarget state from the scoring plane hit (pos in mm, mom in MeV,
707 // both already in LDMX global frame)
708 ldmx::Track::TrackState ts_target;
709 ts_target.pos_ = {hit.getPosition()[0], hit.getPosition()[1],
710 hit.getPosition()[2]};
711 ts_target.mom_ = {hit.getMomentum()[0], hit.getMomentum()[1],
712 hit.getMomentum()[2]};
713 ts_target.ts_type_ = ldmx::AtTarget;
714 truth_tagger_track.addTrackState(ts_target);
715 tagger_truth_tracks.push_back(truth_tagger_track);
716
717 if (hit.getPdgID() == 11 && hit.getTrackID() < max_track_id_) {
718 ldmx::Track beam_e_truth_seed =
719 taggerFullSeed(particle_map[hit.getTrackID()], hit.getTrackID(),
720 hit, hit_count_map_tagger, beam_origin_surface,
721 target_unbound_surface);
722 beam_electrons.push_back(beam_e_truth_seed);
723 }
724 }
725 }
726 }
727
728 // Recover the EcalScoring hits
729 const auto& ecal_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
730 ecal_sp_coll_name_, sp_pass_name_);
731 // Select ECAL hits
732 std::vector<ldmx::SimTrackerHit> sel_ecal_sp_hits;
733
734 for (auto sp_hit : ecal_sp_hits) {
735 if (sp_hit.getMomentum()[2] > 0 && ((sp_hit.getID() & 0xfff) == 31)) {
736 sel_ecal_sp_hits.push_back(sp_hit);
737 }
738 }
739
740 // Recoil target surface for truth and seed tracks is the target
741
742 for (std::pair<int, std::vector<int>> element : recoil_sh_count_map) {
743 // Only take the first entry of the vector: it should be the scoring plane
744 // hit with the highest momentum.
745 const ldmx::SimTrackerHit& hit = scoring_hits.at(element.second.at(0));
746 const ldmx::SimParticle& phit = particle_map[hit.getTrackID()];
747 ldmx::SimTrackerHit ecal_hit;
748
749 bool found_ecal_hit = false;
750 for (auto ecal_sp_hit : sel_ecal_sp_hits) {
751 if (ecal_sp_hit.getTrackID() == hit.getTrackID()) {
752 ecal_hit = ecal_sp_hit;
753 found_ecal_hit = true;
754 break;
755 }
756 }
757
758 // Findable particle selection
759 // ldmx_log(trace) << "!!! n_recoil_sim_hits found: " <<
760 // hit_count_map_recoil[hit.getTrackID()].size();
761 if (hit_count_map_recoil[hit.getTrackID()].size() > n_min_hits_recoil_ &&
762 found_ecal_hit && !skip_recoil_) {
763 ldmx::Track truth_recoil_track;
764 createTruthTrack(phit, hit, truth_recoil_track, target_surface);
765 truth_recoil_track.setTrackID(hit.getTrackID());
766
767 // AtTarget state from target scoring plane hit (pos mm, mom MeV, LDMX
768 // frame)
769 ldmx::Track::TrackState ts_target;
770 ts_target.pos_ = {hit.getPosition()[0], hit.getPosition()[1],
771 hit.getPosition()[2]};
772 ts_target.mom_ = {hit.getMomentum()[0], hit.getMomentum()[1],
773 hit.getMomentum()[2]};
774 ts_target.ts_type_ = ldmx::AtTarget;
775 truth_recoil_track.addTrackState(ts_target);
776
777 // Express truth ECAL state in the bound parametrization of ecal_surface
778 // (same surface definition used by CKFProcessor).
779 {
780 Acts::Vector3 ep{ecal_hit.getPosition()[0], ecal_hit.getPosition()[1],
781 ecal_hit.getPosition()[2]};
782 Acts::Vector3 em{ecal_hit.getMomentum()[0], ecal_hit.getMomentum()[1],
783 ecal_hit.getMomentum()[2]};
784 ep = tracking::sim::utils::ldmx2Acts(ep);
785 em = tracking::sim::utils::ldmx2Acts(em);
786 // Linearly extrapolate transverse coordinates to ACTS x = 240.5 mm
787 // (= LDMX z = 240.5 mm), correcting for the track slope over the small
788 // z-offset between the scoring plane and the ECAL surface.
789 if (std::abs(em[0]) > 0) {
790 double delta = 240.5 - ep[0];
791 ep[1] += delta * em[1] / em[0];
792 ep[2] += delta * em[2] / em[0];
793 ep[0] = 240.5;
794 }
795 double q_ecal = phit.getCharge() * Acts::UnitConstants::e;
796 auto ecal_free = tracking::sim::utils::toFreeParameters(ep, em, q_ecal);
797 auto ecal_bound = Acts::transformFreeToBoundParameters(
798 ecal_free, *ecal_surface, geometryContext());
799 if (ecal_bound.ok()) {
800 auto part{Acts::ParticleHypothesis(
801 Acts::PdgParticle(particle_hypothesis_))};
802 Acts::BoundTrackParameters ecal_pars(ecal_surface, ecal_bound.value(),
803 Acts::BoundMatrix::Identity(),
804 part);
805 truth_recoil_track.addTrackState(tracking::sim::utils::makeTrackState(
806 geometryContext(), ecal_pars, ldmx::AtECAL));
807 }
808 }
809
810 // Attach sim hit indices
811 int nhits = 0;
812 for (auto sim_hit_idx : hit_count_map_recoil.at(hit.getTrackID())) {
813 truth_recoil_track.addMeasurementIndex(sim_hit_idx);
814 nhits++;
815 }
816 truth_recoil_track.setNhits(nhits);
817
818 recoil_truth_tracks.push_back(truth_recoil_track);
819 }
820 }
821
822 /*
823 for (std::pair<int,std::vector<int>> element : recoil_sh_count_map) {
824
825 const ldmx::SimTrackerHit& hit = scoring_hits.at(element.second.at(0));
826 const ldmx::SimParticle& phit = particleMap[hit.getTrackID()];
827
828 if (hit_count_map_recoil[hit.getTrackID()].size() > n_min_hits_recoil_) {
829 ldmx::Track truth_recoil_track;
830 createTruthTrack(phit,hit,truth_recoil_track,targetSurface);
831 truth_recoil_track.setNhits(hit_count_map_recoil[hit.getTrackID()].size());
832 recoil_truth_tracks.push_back(truth_recoil_track);
833 }
834 }
835 */
836
837 // Form a truth seed from a truth track
838
839 for (auto& tt : tagger_truth_tracks) {
840 ldmx::Track seed = seedFromTruth(tt, seed_smearing_);
841
842 tagger_truth_seeds.push_back(seed);
843 }
844
845 ldmx_log(debug) << "Forming seeds from truth";
846 for (auto& tt : recoil_truth_tracks) {
847 ldmx_log(debug) << "Smearing truth track";
848
849 ldmx::Track seed = seedFromTruth(tt, seed_smearing_);
850
851 recoil_truth_seeds.push_back(seed);
852 }
853
854 // even if skip_tagger/recoil_ is true, still make the collections in the
855 // event
856 event.add(beam_electrons_collection_, beam_electrons);
857 event.add(tagger_truth_collection_, tagger_truth_tracks);
858 event.add(recoil_truth_collection_, recoil_truth_tracks);
859 event.add(tagger_seeds_collection_, tagger_truth_seeds);
860 event.add(recoil_seeds_collection_, recoil_truth_seeds);
861}
Class representing a simulated particle.
Definition SimParticle.h:25
Represents a simulated tracker hit in the simulation.
Implementation of a track object.
Definition Track.h:54
void makeHitCountMap(const std::vector< ldmx::SimTrackerHit > &sim_hits, std::map< int, std::vector< int > > &hit_count_map)
Create a mapping from the selected scoring plane hit objects to the number of hits they associated pa...
ldmx::Track taggerFullSeed(const ldmx::SimParticle &beam_electron, const int trackID, const ldmx::SimTrackerHit &hit, const std::map< int, std::vector< int > > &hit_count_map, const std::shared_ptr< Acts::Surface > &origin_surface, const std::shared_ptr< Acts::Surface > &target_surface)
This method retrieves the beam electron and forms a full seed The seed parameters are the truth param...
ldmx::Track seedFromTruth(const ldmx::Track &tt, bool seed_smearing)
Create a track seed from a truth track applying a smearing to the truth parameters as well as an infl...

References ldmx::SimTrackerHit::getMomentum(), ldmx::SimTrackerHit::getPosition(), ldmx::SimTrackerHit::getTrackID(), input_pass_name_, makeHitCountMap(), p_cut_, recoil_sim_hits_coll_name_, scoring_hits_coll_name_, and tagger_sim_hits_coll_name_.

◆ recoilFullSeed()

ldmx::Track tracking::reco::TruthSeedProcessor::recoilFullSeed ( const ldmx::SimParticle & particle,
const int trackID,
const ldmx::SimTrackerHit & hit,
const ldmx::SimTrackerHit & ecal_hit,
const std::map< int, std::vector< int > > & hit_count_map,
const std::shared_ptr< Acts::Surface > & origin_surface,
const std::shared_ptr< Acts::Surface > & target_surface,
const std::shared_ptr< Acts::Surface > & ecal_surface )
private

Definition at line 223 of file TruthSeedProcessor.cxx.

229 {
230 ldmx::Track truth_recoil_track;
231 createTruthTrack(particle, hit, truth_recoil_track, origin_surface);
232 truth_recoil_track.setTrackID(trackID);
233
234 // Seed at the target location
235 ldmx::Track smeared_truth_track = seedFromTruth(truth_recoil_track, false);
236
237 // Add truth track state at the target: use scoring plane hit (already LDMX
238 // frame)
239 ldmx::Track::TrackState ts_truth_target;
240 ts_truth_target.pos_ = {hit.getPosition()[0], hit.getPosition()[1],
241 hit.getPosition()[2]};
242 ts_truth_target.mom_ = {hit.getMomentum()[0], hit.getMomentum()[1],
243 hit.getMomentum()[2]};
244 ts_truth_target.ts_type_ = ldmx::AtTarget;
245 smeared_truth_track.addTrackState(ts_truth_target);
246
247 // Express truth ECAL state in the bound parametrization of ecal_surface
248 // (same surface definition used by CKFProcessor) rather than storing raw
249 // scoring plane hit coordinates.
250 {
251 Acts::Vector3 ep{ecal_hit.getPosition()[0], ecal_hit.getPosition()[1],
252 ecal_hit.getPosition()[2]};
253 Acts::Vector3 em{ecal_hit.getMomentum()[0], ecal_hit.getMomentum()[1],
254 ecal_hit.getMomentum()[2]};
255 ep = tracking::sim::utils::ldmx2Acts(ep);
256 em = tracking::sim::utils::ldmx2Acts(em);
257 // Linearly extrapolate transverse coordinates to ACTS x = 240.5 mm
258 // (= LDMX z = 240.5 mm), correcting for the track slope over the small
259 // z-offset between the scoring plane and the ECAL surface.
260 if (std::abs(em[0]) > 0) {
261 double delta = 240.5 - ep[0];
262 ep[1] += delta * em[1] / em[0];
263 ep[2] += delta * em[2] / em[0];
264 ep[0] = 240.5;
265 }
266 double q_ecal = particle.getCharge() * Acts::UnitConstants::e;
267 auto ecal_free = tracking::sim::utils::toFreeParameters(ep, em, q_ecal);
268 auto ecal_bound = Acts::transformFreeToBoundParameters(
269 ecal_free, *ecal_surface, geometryContext());
270 if (ecal_bound.ok()) {
271 auto part{
272 Acts::ParticleHypothesis(Acts::PdgParticle(particle_hypothesis_))};
273 Acts::BoundTrackParameters ecal_pars(ecal_surface, ecal_bound.value(),
274 Acts::BoundMatrix::Identity(), part);
275 smeared_truth_track.addTrackState(tracking::sim::utils::makeTrackState(
276 geometryContext(), ecal_pars, ldmx::AtECAL));
277 }
278 }
279
280 // Add the hits
281 int nhits = 0;
282
283 for (auto sim_hit_idx : hit_count_map.at(smeared_truth_track.getTrackID())) {
284 smeared_truth_track.addMeasurementIndex(sim_hit_idx);
285 nhits += 1;
286 }
287
288 smeared_truth_track.setNhits(nhits);
289
290 return smeared_truth_track;
291}

◆ scoringPlaneHitFilter()

bool tracking::reco::TruthSeedProcessor::scoringPlaneHitFilter ( const ldmx::SimTrackerHit & hit,
const std::vector< ldmx::SimTrackerHit > & ecal_sp_hits )
private

Filter that checks if a scoring plane passes specified momentum cuts as well as if the associated SimParticle hits the ECal.

Parameters
hitThe target scoring plane hit to check.
ecal_sp_hitsThe ECal scoring plane hit used to check if the associated particle hits the ECal.

Definition at line 506 of file TruthSeedProcessor.cxx.

508 {
509 // Clean some of the hits we don't want
510 if (hit.getPosition()[2] < z_min_) return false;
511
512 // Check if the track_id was requested
513 if (track_id_ > 0 && hit.getTrackID() != track_id_) return false;
514
515 // Check if we are requesting particular particles
516 if (std::find(pdg_ids_.begin(), pdg_ids_.end(), hit.getPdgID()) ==
517 pdg_ids_.end())
518 return false;
519
520 Acts::Vector3 p_vec{hit.getMomentum()[0], hit.getMomentum()[1],
521 hit.getMomentum()[2]};
522
523 // p cut
524 if (p_cut_ >= 0. && p_vec.norm() < p_cut_) return false;
525
526 // p cut Max
527 if (p_cut_ < 100000. && p_vec.norm() > p_cut_max_) return false;
528
529 // pz cut
530 if (pz_cut_ > -9999 && p_vec(2) < pz_cut_) return false;
531
532 // Check the ecal scoring plane
533 bool pass_ecal_scoring_plane = true;
534
535 if (p_cut_ecal_ > 0) { // only check if we care about it.
536
537 for (auto& e_sp_hit : ecal_sp_hits) {
538 if (e_sp_hit.getTrackID() == hit.getTrackID() &&
539 e_sp_hit.getPdgID() == hit.getPdgID()) {
540 Acts::Vector3 e_sp_p{e_sp_hit.getMomentum()[0],
541 e_sp_hit.getMomentum()[1],
542 e_sp_hit.getMomentum()[2]};
543
544 if (e_sp_p.norm() < p_cut_ecal_) pass_ecal_scoring_plane = false;
545
546 // Skip the rest of the scoring plane hits since we already found the
547 // track we care about
548 break;
549
550 } // check that the hit belongs to the inital particle from the target
551 // scoring plane hit
552 } // loop on Ecal scoring plane hits
553 } // pcutEcal
554
555 if (!pass_ecal_scoring_plane) return false;
556
557 return true;
558}

References ldmx::SimTrackerHit::getMomentum(), ldmx::SimTrackerHit::getPdgID(), ldmx::SimTrackerHit::getPosition(), ldmx::SimTrackerHit::getTrackID(), p_cut_, p_cut_max_, pdg_ids_, pz_cut_, track_id_, and z_min_.

◆ seedFromTruth()

ldmx::Track tracking::reco::TruthSeedProcessor::seedFromTruth ( const ldmx::Track & tt,
bool seed_smearing )
private

Create a track seed from a truth track applying a smearing to the truth parameters as well as an inflation to the covariance matrix.

Parameters
ttTruthTrack to be used to form a seed
Returns
seed The seed track

Definition at line 358 of file TruthSeedProcessor.cxx.

359 {
360 ldmx::Track seed = ldmx::Track();
361 seed.setPerigeeLocation(tt.getPerigeeLocation()[0],
362 tt.getPerigeeLocation()[1],
363 tt.getPerigeeLocation()[2]);
364 seed.setChi2(0.);
365 seed.setNhits(tt.getNhits());
366 seed.setNdf(0);
367 seed.setNsharedHits(0);
368 seed.setTrackID(tt.getTrackID());
369 seed.setPdgID(tt.getPdgID());
370 seed.setTruthProb(1.);
371
372 Acts::BoundVector bound_params;
373 Acts::BoundVector stddev;
374
375 if (seed_smearing) {
376 ldmx_log(debug) << "Smear track and inflate covariance";
377
378 /*
379 double sigma_d0 = rel_smearfactors_[Acts::eBoundLoc0] * tt.getD0();
380 double sigma_z0 = rel_smearfactors_[Acts::eBoundLoc1] * tt.getZ0();
381 double sigma_phi = rel_smearfactors_[Acts::eBoundPhi] * tt.getPhi();
382 double sigma_theta = rel_smearfactors_[Acts::eBoundTheta] *
383 tt.getTheta(); double sigma_p = rel_smearfactors_[Acts::eBoundQOverP]
384 * abs(1/tt.getQoP()); double sigma_t =
385 rel_smearfactors_[Acts::eBoundTime] * tt.getT();
386 */
387
388 double sigma_d0 = d0smear_[0];
389 double sigma_z0 = z0smear_[0];
390 double sigma_phi = phismear_;
391 double sigma_theta = thetasmear_;
392 double sigma_p = relpsmear_ * abs(1 / tt.getQoP());
393 double sigma_t = 1. * Acts::UnitConstants::ns;
394
395 double smear = (*normal_)(generator_);
396 double d0smear = tt.getD0() + smear * sigma_d0;
397
398 smear = (*normal_)(generator_);
399 double z0smear = tt.getZ0() + smear * sigma_z0;
400
401 smear = (*normal_)(generator_);
402 double phismear = tt.getPhi() + smear * sigma_phi;
403
404 smear = (*normal_)(generator_);
405 double thetasmear = tt.getTheta() + smear * sigma_theta;
406
407 double p = std::abs(1. / tt.getQoP());
408 smear = (*normal_)(generator_);
409 double psmear = p + smear * sigma_p;
410
411 double q = tt.getQoP() < 0 ? -1. : 1.;
412 double qo_psmear = q / psmear;
413
414 smear = (*normal_)(generator_);
415 double tsmear = tt.getT() + smear * sigma_t;
416
417 bound_params << d0smear, z0smear, phismear, thetasmear, qo_psmear, tsmear;
418
419 stddev[Acts::eBoundLoc0] =
420 inflate_factors_[Acts::eBoundLoc0] * sigma_d0 * Acts::UnitConstants::mm;
421 stddev[Acts::eBoundLoc1] =
422 inflate_factors_[Acts::eBoundLoc1] * sigma_z0 * Acts::UnitConstants::mm;
423 stddev[Acts::eBoundPhi] = inflate_factors_[Acts::eBoundPhi] * sigma_phi;
424 stddev[Acts::eBoundTheta] =
425 inflate_factors_[Acts::eBoundTheta] * sigma_theta;
426 stddev[Acts::eBoundQOverP] =
427 inflate_factors_[Acts::eBoundQOverP] * (1. / p) * (1. / p) * sigma_p;
428 stddev[Acts::eBoundTime] =
429 inflate_factors_[Acts::eBoundTime] * sigma_t * Acts::UnitConstants::ns;
430
431 ldmx_log(debug) << stddev;
432
433 std::vector<double> v_seed_params(
434 (bound_params).data(),
435 bound_params.data() + bound_params.rows() * bound_params.cols());
436
437 Acts::BoundMatrix bound_cov = stddev.cwiseProduct(stddev).asDiagonal();
438 std::vector<double> v_seed_cov;
439 tracking::sim::utils::flatCov(bound_cov, v_seed_cov);
440 seed.setPerigeeParameters(v_seed_params);
441 seed.setPerigeeCov(v_seed_cov);
442
443 } else {
444 // Do not smear the seed
445
446 bound_params << tt.getD0(), tt.getZ0(), tt.getPhi(), tt.getTheta(),
447 tt.getQoP(), tt.getT();
448
449 std::vector<double> v_seed_params(
450 (bound_params).data(),
451 bound_params.data() + bound_params.rows() * bound_params.cols());
452
453 double p = std::abs(1. / tt.getQoP());
454 double sigma_p = 0.75 * p * Acts::UnitConstants::GeV;
455 stddev[Acts::eBoundLoc0] = 2 * Acts::UnitConstants::mm;
456 stddev[Acts::eBoundLoc1] = 5 * Acts::UnitConstants::mm;
457 stddev[Acts::eBoundTime] = 1000 * Acts::UnitConstants::ns;
458 stddev[Acts::eBoundPhi] = 5 * Acts::UnitConstants::degree;
459 stddev[Acts::eBoundTheta] = 5 * Acts::UnitConstants::degree;
460 stddev[Acts::eBoundQOverP] = (1. / p) * (1. / p) * sigma_p;
461
462 Acts::BoundMatrix bound_cov = stddev.cwiseProduct(stddev).asDiagonal();
463 std::vector<double> v_seed_cov;
464 tracking::sim::utils::flatCov(bound_cov, v_seed_cov);
465 seed.setPerigeeParameters(v_seed_params);
466 seed.setPerigeeCov(v_seed_cov);
467 }
468
469 return seed;
470}

Referenced by taggerFullSeed().

◆ taggerFullSeed()

ldmx::Track tracking::reco::TruthSeedProcessor::taggerFullSeed ( const ldmx::SimParticle & beam_electron,
const int trackID,
const ldmx::SimTrackerHit & hit,
const std::map< int, std::vector< int > > & hit_count_map,
const std::shared_ptr< Acts::Surface > & origin_surface,
const std::shared_ptr< Acts::Surface > & target_surface )
private

This method retrieves the beam electron and forms a full seed The seed parameters are the truth parameters from the beam electron stored at the beam origin Additionally, the foolowing track states are stored ts_smeared : the truth smeared perigee state at the beam origin ts_truth_target : the truth on-surface state at the target Linear extrapolations are done from the origin of the particle to the reference surfaces This track also contains the list of hits belonging to the beam electron on the sensitive surfaces on the tagger tracker, for acceptance studies.

Parameters
beam_electron: the beam electron particle
hit: the scoring hit at the target from the beam electron particle survived
hit_count_map: the sim hit on track map
origin_surface: where to express the track origin parameters. Can be perigee, plane...
target_surface: the target surface for the truth target state

Definition at line 293 of file TruthSeedProcessor.cxx.

298 {
299 ldmx::Track truth_track;
300
301 createTruthTrack(beam_electron, truth_track, origin_surface);
302 truth_track.setTrackID(trackID);
303
304 // Smeared track at the beam origin
305 ldmx::Track smeared_truth_track = seedFromTruth(truth_track, true);
306
307 ldmx_log(debug) << "Truth parameters at beam origin";
308 for (auto par : truth_track.getPerigeeParameters())
309 ldmx_log(debug) << par << " ";
310 ldmx_log(debug);
311
312 // Add the truth track state at the target using the scoring plane hit
313 // (position and momentum are already in LDMX global frame)
314 ldmx::Track::TrackState ts_truth_target;
315 ts_truth_target.pos_ = {hit.getPosition()[0], hit.getPosition()[1],
316 hit.getPosition()[2]};
317 ts_truth_target.mom_ = {hit.getMomentum()[0], hit.getMomentum()[1],
318 hit.getMomentum()[2]};
319 ts_truth_target.ts_type_ = ldmx::AtTarget;
320 smeared_truth_track.addTrackState(ts_truth_target);
321
322 ldmx_log(debug) << "Truth position at target: " << hit.getPosition()[0] << " "
323 << hit.getPosition()[1] << " " << hit.getPosition()[2];
324
325 // Add the truth track state at the beam origin using particle vertex/momentum
326 // (SimParticle vertex and momentum are in LDMX global frame)
327 ldmx::Track::TrackState ts_truth_beam_origin;
328 ts_truth_beam_origin.pos_ = {beam_electron.getVertex()[0],
329 beam_electron.getVertex()[1],
330 beam_electron.getVertex()[2]};
331 ts_truth_beam_origin.mom_ = {beam_electron.getMomentum()[0],
332 beam_electron.getMomentum()[1],
333 beam_electron.getMomentum()[2]};
334 ts_truth_beam_origin.ts_type_ = ldmx::AtBeamOrigin;
335 smeared_truth_track.addTrackState(ts_truth_beam_origin);
336
337 ldmx_log(debug) << "Smeared parameters at origin";
338 for (auto par : smeared_truth_track.getPerigeeParameters())
339 ldmx_log(debug) << par << " ";
340
341 // assign the sim hit indices
342 // TODO this is not fully correct as the sim hits
343 // might be duplicated on sensors
344 // and should be merged if that is the case
345
346 int nhits = 0;
347
348 for (auto sim_hit_idx : hit_count_map.at(smeared_truth_track.getTrackID())) {
349 smeared_truth_track.addMeasurementIndex(sim_hit_idx);
350 nhits += 1;
351 }
352
353 smeared_truth_track.setNhits(nhits);
354
355 return smeared_truth_track;
356}

References createTruthTrack(), ldmx::SimParticle::getMomentum(), ldmx::SimTrackerHit::getMomentum(), ldmx::SimTrackerHit::getPosition(), ldmx::SimParticle::getVertex(), and seedFromTruth().

Member Data Documentation

◆ beam_electrons_collection_

std::string tracking::reco::TruthSeedProcessor::beam_electrons_collection_
private

Definition at line 279 of file TruthSeedProcessor.h.

◆ beam_origin_

std::vector<double> tracking::reco::TruthSeedProcessor::beam_origin_ {-880.1, -44., 0.}
private

Definition at line 276 of file TruthSeedProcessor.h.

276{-880.1, -44., 0.};

◆ d0smear_

std::vector<double> tracking::reco::TruthSeedProcessor::d0smear_
private

Definition at line 269 of file TruthSeedProcessor.h.

◆ ecal_sp_coll_name_

std::string tracking::reco::TruthSeedProcessor::ecal_sp_coll_name_ {"EcalScoringPlaneHits"}
private

Definition at line 190 of file TruthSeedProcessor.h.

190{"EcalScoringPlaneHits"};

◆ field_map_

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

Path to the magnetic field map.

Definition at line 260 of file TruthSeedProcessor.h.

260{""};

Referenced by configure(), and onNewRun().

◆ generator_

std::default_random_engine tracking::reco::TruthSeedProcessor::generator_
private

Definition at line 264 of file TruthSeedProcessor.h.

◆ inflate_factors_

std::vector<double> tracking::reco::TruthSeedProcessor::inflate_factors_
private

Definition at line 275 of file TruthSeedProcessor.h.

◆ input_pass_name_

std::string tracking::reco::TruthSeedProcessor::input_pass_name_ {""}
private

Pass name for the sim hit collections.

Definition at line 200 of file TruthSeedProcessor.h.

200{""};

Referenced by configure(), and produce().

◆ max_track_id_

int tracking::reco::TruthSeedProcessor::max_track_id_ {5}
private

Definition at line 251 of file TruthSeedProcessor.h.

251{5};

◆ n_min_hits_recoil_

int tracking::reco::TruthSeedProcessor::n_min_hits_recoil_ {7}
private

Minimum number of hits left in the recoil tracker to consider the seed as findable.

Definition at line 215 of file TruthSeedProcessor.h.

215{7};

Referenced by configure().

◆ n_min_hits_tagger_

int tracking::reco::TruthSeedProcessor::n_min_hits_tagger_ {7}
private

Minimum number of hits left in the recoil tracker to consider the seed as findable.

Definition at line 209 of file TruthSeedProcessor.h.

209{7};

Referenced by configure().

◆ normal_

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

Definition at line 265 of file TruthSeedProcessor.h.

◆ p_cut_

double tracking::reco::TruthSeedProcessor::p_cut_ {0.}
private

Ask for a minimum p for the seeds.

Definition at line 230 of file TruthSeedProcessor.h.

230{0.};

Referenced by configure(), produce(), and scoringPlaneHitFilter().

◆ p_cut_ecal_

double tracking::reco::TruthSeedProcessor::p_cut_ecal_ {-1.}
private

Definition at line 236 of file TruthSeedProcessor.h.

236{-1.};

◆ p_cut_max_

double tracking::reco::TruthSeedProcessor::p_cut_max_ {100000.}
private

Ask for a maximum p for the seeds.

Definition at line 233 of file TruthSeedProcessor.h.

233{100000.};

Referenced by configure(), and scoringPlaneHitFilter().

◆ particle_hypothesis_

int tracking::reco::TruthSeedProcessor::particle_hypothesis_
private

Definition at line 277 of file TruthSeedProcessor.h.

◆ pdg_ids_

std::vector<int> tracking::reco::TruthSeedProcessor::pdg_ids_ {11}
private

pdg_ids of the particles we want to select for the seeds

Definition at line 186 of file TruthSeedProcessor.h.

186{11};

Referenced by configure(), and scoringPlaneHitFilter().

◆ phismear_

double tracking::reco::TruthSeedProcessor::phismear_
private

Definition at line 271 of file TruthSeedProcessor.h.

◆ propagator_

std::unique_ptr<const TruthPropagator> tracking::reco::TruthSeedProcessor::propagator_
private

Definition at line 253 of file TruthSeedProcessor.h.

◆ pz_cut_

double tracking::reco::TruthSeedProcessor::pz_cut_ {-9999}
private

Ask for a minimum pz for the seeds.

Definition at line 227 of file TruthSeedProcessor.h.

227{-9999};

Referenced by configure(), and scoringPlaneHitFilter().

◆ recoil_seeds_collection_

std::string tracking::reco::TruthSeedProcessor::recoil_seeds_collection_
private

Definition at line 283 of file TruthSeedProcessor.h.

◆ recoil_sim_hits_coll_name_

std::string tracking::reco::TruthSeedProcessor::recoil_sim_hits_coll_name_ {"RecoilSimHits"}
private

Sim hits to check if the truth seed is findable.

Definition at line 197 of file TruthSeedProcessor.h.

197{"RecoilSimHits"};

Referenced by configure(), and produce().

◆ recoil_sp_

bool tracking::reco::TruthSeedProcessor::recoil_sp_ {true}
private

Definition at line 239 of file TruthSeedProcessor.h.

239{true};

◆ recoil_truth_collection_

std::string tracking::reco::TruthSeedProcessor::recoil_truth_collection_
private

Definition at line 281 of file TruthSeedProcessor.h.

◆ rel_smearfactors_

std::vector<double> tracking::reco::TruthSeedProcessor::rel_smearfactors_
private

Definition at line 274 of file TruthSeedProcessor.h.

◆ relpsmear_

double tracking::reco::TruthSeedProcessor::relpsmear_
private

Definition at line 273 of file TruthSeedProcessor.h.

◆ scoring_hits_coll_name_

std::string tracking::reco::TruthSeedProcessor::scoring_hits_coll_name_ {"TargetScoringPlaneHits"}
private

Which scoring plane hits to use for the truth seeds generation.

Definition at line 189 of file TruthSeedProcessor.h.

189{"TargetScoringPlaneHits"};

Referenced by configure(), and produce().

◆ seed_smearing_

bool tracking::reco::TruthSeedProcessor::seed_smearing_ {false}
private

Definition at line 267 of file TruthSeedProcessor.h.

267{false};

◆ sim_particles_coll_name_

std::string tracking::reco::TruthSeedProcessor::sim_particles_coll_name_
private

Definition at line 202 of file TruthSeedProcessor.h.

◆ sim_particles_passname_

std::string tracking::reco::TruthSeedProcessor::sim_particles_passname_
private

Definition at line 203 of file TruthSeedProcessor.h.

◆ skip_recoil_

bool tracking::reco::TruthSeedProcessor::skip_recoil_ {false}
private

Definition at line 248 of file TruthSeedProcessor.h.

248{false};

◆ skip_tagger_

bool tracking::reco::TruthSeedProcessor::skip_tagger_ {false}
private

Definition at line 245 of file TruthSeedProcessor.h.

245{false};

◆ sp_pass_name_

std::string tracking::reco::TruthSeedProcessor::sp_pass_name_ {""}
private

Definition at line 191 of file TruthSeedProcessor.h.

191{""};

◆ tagger_seeds_collection_

std::string tracking::reco::TruthSeedProcessor::tagger_seeds_collection_
private

Definition at line 282 of file TruthSeedProcessor.h.

◆ tagger_sim_hits_coll_name_

std::string tracking::reco::TruthSeedProcessor::tagger_sim_hits_coll_name_ {"TaggerSimHits"}
private

Sim hits to check if the truth seed is findable.

Definition at line 194 of file TruthSeedProcessor.h.

194{"TaggerSimHits"};

Referenced by configure(), and produce().

◆ tagger_truth_collection_

std::string tracking::reco::TruthSeedProcessor::tagger_truth_collection_
private

Definition at line 280 of file TruthSeedProcessor.h.

◆ target_sp_

bool tracking::reco::TruthSeedProcessor::target_sp_ {true}
private

Definition at line 242 of file TruthSeedProcessor.h.

242{true};

◆ thetasmear_

double tracking::reco::TruthSeedProcessor::thetasmear_
private

Definition at line 272 of file TruthSeedProcessor.h.

◆ track_id_

int tracking::reco::TruthSeedProcessor::track_id_ {-999}
private

Only select a particular trackID.

Definition at line 224 of file TruthSeedProcessor.h.

224{-999};

Referenced by configure(), and scoringPlaneHitFilter().

◆ trk_extrap_

std::shared_ptr<tracking::reco::TrackExtrapolatorTool<TruthPropagator> > tracking::reco::TruthSeedProcessor::trk_extrap_
private

Definition at line 257 of file TruthSeedProcessor.h.

◆ z0smear_

std::vector<double> tracking::reco::TruthSeedProcessor::z0smear_
private

Definition at line 270 of file TruthSeedProcessor.h.

◆ z_min_

float tracking::reco::TruthSeedProcessor::z_min_ {-999}
private

Min cut on the z_ of the scoring hit.

It could be used to clean the scoring hits if desired.

Definition at line 221 of file TruthSeedProcessor.h.

221{-999};

Referenced by configure(), and scoringPlaneHitFilter().


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