LDMX Software
simcore::generators::FromScoringPlane Class Reference

Copy particles from a particular scoring plane in as primaries of a new simulation. More...

#include <FromScoringPlane.h>

Public Member Functions

 FromScoringPlane (const std::string &name, const framework::config::Parameters &parameters)
 Class constructor.
 
virtual ~FromScoringPlane ()=default
 Class destructor.
 
void prepEvent (const framework::Event &event) override
 Retrieve the collection of scoring plane hits and copy the selected hits into our copies of primary particles.
 
void GeneratePrimaryVertex (G4Event *anEvent) override
 Generate vertices in the Geant4 event.
 
void RecordConfig (const std::string &id, ldmx::RunHeader &rh) override
 Record configuration information.
 
- Public Member Functions inherited from simcore::PrimaryGenerator
 PrimaryGenerator (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
 DECLARE_FACTORY_WITH_WAREHOUSE (PrimaryGenerator, std::shared_ptr< PrimaryGenerator >, const std::string &, const framework::config::Parameters &)
 
virtual ~PrimaryGenerator ()=default
 Destructor.
 
std::string name ()
 
void smearBeamspot (G4PrimaryVertex *primary_vertex)
 Apply beam spot smearing to a primary vertex.
 
bool useBeamspot () const
 Check if beam spot smearing is enabled for this generator.
 

Private Attributes

std::string coll_name_
 name of scoring plane collection we should use
 
std::string pass_name_
 name of pass for scoring plane collection we should use
 
std::vector< int > select_planes_
 list of plane ID numbers to select for (use all hits if empty)
 
std::vector< G4PrimaryVertex * > primary_vertices_
 list of primary vertices we will give over to the G4Event
 

Additional Inherited Members

- Protected Attributes inherited from simcore::PrimaryGenerator
std::string name_ {""}
 Name of the PrimaryGenerator.
 
bool use_beamspot_ {false}
 Flag denoting whether beam spot smearing is enabled for this generator.
 
double beamspot_x_size_ {0}
 Extent of the beamspot in x [mm].
 
double beamspot_y_size_ {0}
 Extent of the beamspot in y [mm].
 
double beamspot_z_size_ {0}
 Extent of the beamspot in z [mm].
 

Detailed Description

Copy particles from a particular scoring plane in as primaries of a new simulation.

Definition at line 28 of file FromScoringPlane.h.

Constructor & Destructor Documentation

◆ FromScoringPlane()

simcore::generators::FromScoringPlane::FromScoringPlane ( const std::string & name,
const framework::config::Parameters & parameters )

Class constructor.

Parameters
nameThe name of the generator.
parametersConfiguration parameters.

Definition at line 13 of file FromScoringPlane.cxx.

15 : PrimaryGenerator(name, parameters),
16 coll_name_{parameters.get<std::string>("coll_name")},
17 pass_name_{parameters.get<std::string>("pass_name")},
18 select_planes_{parameters.get<std::vector<int>>("select_planes")} {}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
std::string coll_name_
name of scoring plane collection we should use
std::vector< int > select_planes_
list of plane ID numbers to select for (use all hits if empty)
std::string pass_name_
name of pass for scoring plane collection we should use

Member Function Documentation

◆ GeneratePrimaryVertex()

void simcore::generators::FromScoringPlane::GeneratePrimaryVertex ( G4Event * anEvent)
overridevirtual

Generate vertices in the Geant4 event.

Parameters
anEventThe Geant4 event.

Implements simcore::PrimaryGenerator.

Definition at line 78 of file FromScoringPlane.cxx.

78 {
79 ldmx_log(debug) << "generating primary vertex";
80 for (auto* primary_vertex : primary_vertices_) {
81 anEvent->AddPrimaryVertex(primary_vertex);
82 }
83}
std::vector< G4PrimaryVertex * > primary_vertices_
list of primary vertices we will give over to the G4Event

References primary_vertices_.

◆ prepEvent()

void simcore::generators::FromScoringPlane::prepEvent ( const framework::Event & event)
overridevirtual

Retrieve the collection of scoring plane hits and copy the selected hits into our copies of primary particles.

The particles are copied into the G4Event in GeneratePrimaryVertex

Exceptions
framework::Exceptionif the requested scoring plane hits are not available, most often because the input file containing them was not requested
Parameters
[in]eventframework::Event containing necessary scoring plane hits

Reimplemented from simcore::PrimaryGenerator.

Definition at line 20 of file FromScoringPlane.cxx.

20 {
21 ldmx_log(debug) << "preparing event";
22 const auto& scoring_plane_hits{
23 event.getCollection<ldmx::SimTrackerHit>(coll_name_, pass_name_)};
24 std::unordered_map<int, std::vector<const ldmx::SimTrackerHit*>>
25 hits_by_track_id;
26 for (const auto& hit : scoring_plane_hits) {
27 ldmx::SimSpecialID id(hit.getID());
28 bool keep{select_planes_.empty() or
29 std::find(select_planes_.begin(), select_planes_.end(),
30 id.plane()) != select_planes_.end()};
31 // do filtering by layer here
32 ldmx_log(trace) << "hit with plane = " << id.plane() << " is "
33 << (keep ? "used" : "ignored");
34 if (keep) {
35 // sort hits that we are keeping by track ID
36 hits_by_track_id[hit.getTrackID()].push_back(&hit);
37 }
38 }
39
40 // copy earliest hit by track Id in as primary
41 primary_vertices_.clear();
42 for (auto& [track_id, hits] : hits_by_track_id) {
43 auto earliest_hit_it = std::min_element(
44 hits.begin(), hits.end(), [](const auto& hit_lhs, const auto& hit_rhs) {
45 return hit_lhs->getTime() < hit_rhs->getTime();
46 });
47 const auto* earliest_hit = (*earliest_hit_it);
48
49 G4PrimaryParticle* particle = new G4PrimaryParticle;
50 // proper PDG also copies in mass and charge
51 particle->SetPDGcode(earliest_hit->getPdgID());
52
53 auto momentum{earliest_hit->getMomentum()};
54 auto energy{earliest_hit->getEnergy()};
55 particle->Set4Momentum(momentum[0], momentum[1], momentum[2], energy);
56 // probably not correct from a relativistic perspective
57 particle->SetProperTime(earliest_hit->getTime());
58 // label this particle as a primary for purposes of serialization
59 UserPrimaryParticleInformation* uppi = new UserPrimaryParticleInformation;
60 uppi->setHepEvtStatus(1);
61 particle->SetUserInformation(uppi);
62 // NOT copying over the TrackID into the primary because
63 // (as of Geant4.10.2.3) the track IDs of particles created
64 // in this simulation do not start at the primary's number and
65 // count up which is what I would want to make this understandable
66 // particle->SetTrackID(track_id);
67
68 auto pos{earliest_hit->getPosition()};
69 G4PrimaryVertex* vertex = new G4PrimaryVertex;
70 vertex->SetPosition(pos[0], pos[1], pos[2]);
71 // not setting a weight
72 vertex->SetPrimary(particle);
73
74 primary_vertices_.push_back(vertex);
75 }
76}
Implements detector ids for special simulation-derived hits like scoring planes.
Represents a simulated tracker hit in the simulation.

References coll_name_, pass_name_, primary_vertices_, select_planes_, and simcore::UserPrimaryParticleInformation::setHepEvtStatus().

◆ RecordConfig()

void simcore::generators::FromScoringPlane::RecordConfig ( const std::string & id,
ldmx::RunHeader & rh )
overridevirtual

Record configuration information.

Parameters
idThe configuration ID.
rhThe run header.

Implements simcore::PrimaryGenerator.

Definition at line 85 of file FromScoringPlane.cxx.

86 {
87 rh.setStringParameter(id + " Class", "simcore::generators::FromScoringPlane");
88 rh.setStringParameter(id + " Coll Name", coll_name_);
89 rh.setStringParameter(id + " Pass Name", pass_name_);
90}
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:222

References coll_name_, pass_name_, and ldmx::RunHeader::setStringParameter().

Member Data Documentation

◆ coll_name_

std::string simcore::generators::FromScoringPlane::coll_name_
private

name of scoring plane collection we should use

Definition at line 71 of file FromScoringPlane.h.

Referenced by prepEvent(), and RecordConfig().

◆ pass_name_

std::string simcore::generators::FromScoringPlane::pass_name_
private

name of pass for scoring plane collection we should use

Definition at line 73 of file FromScoringPlane.h.

Referenced by prepEvent(), and RecordConfig().

◆ primary_vertices_

std::vector<G4PrimaryVertex*> simcore::generators::FromScoringPlane::primary_vertices_
private

list of primary vertices we will give over to the G4Event

Definition at line 77 of file FromScoringPlane.h.

Referenced by GeneratePrimaryVertex(), and prepEvent().

◆ select_planes_

std::vector<int> simcore::generators::FromScoringPlane::select_planes_
private

list of plane ID numbers to select for (use all hits if empty)

Definition at line 75 of file FromScoringPlane.h.

Referenced by prepEvent().


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