1#include "SimCore/Generators/FromScoringPlane.h"
3#include <unordered_map>
5#include "DetDescr/SimSpecialID.h"
7#include "G4PrimaryParticle.hh"
17 coll_name_{parameters.get<std::string>(
"coll_name")},
18 pass_name_{parameters.get<std::string>(
"pass_name")},
19 select_planes_{parameters.get<std::vector<int>>(
"select_planes")} {}
22 ldmx_log(debug) <<
"preparing event";
23 const auto& scoring_plane_hits{
25 std::unordered_map<int, std::vector<const ldmx::SimTrackerHit*>>
27 for (
const auto& hit : scoring_plane_hits) {
33 ldmx_log(trace) <<
"hit with plane = " <<
id.plane() <<
" is "
34 << (keep ?
"used" :
"ignored");
37 hits_by_track_id[hit.getTrackID()].push_back(&hit);
43 for (
auto& [track_id, hits] : hits_by_track_id) {
44 auto earliest_hit_it = std::min_element(
45 hits.begin(), hits.end(), [](
const auto& hit_lhs,
const auto& hit_rhs) {
46 return hit_lhs->getTime() < hit_rhs->getTime();
48 const auto* earliest_hit = (*earliest_hit_it);
50 G4PrimaryParticle* particle =
new G4PrimaryParticle;
52 particle->SetPDGcode(earliest_hit->getPdgID());
54 auto momentum{earliest_hit->getMomentum()};
55 auto energy{earliest_hit->getEnergy()};
56 particle->Set4Momentum(momentum[0], momentum[1], momentum[2], energy);
58 particle->SetProperTime(earliest_hit->getTime());
62 particle->SetUserInformation(uppi);
69 auto pos{earliest_hit->getPosition()};
70 G4PrimaryVertex* vertex =
new G4PrimaryVertex;
71 vertex->SetPosition(pos[0], pos[1], pos[2]);
73 vertex->SetPrimary(particle);
80 ldmx_log(debug) <<
"generating primary vertex";
82 anEvent->AddPrimaryVertex(primary_vertex);
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class which encapsulates information from a hit in a simulated tracking detector.
Class that provides extra information for Geant4 primary particles.
Implements an event buffer system for storing event data.
Class encapsulating parameters for configuring a processor.
Implements detector ids for special simulation-derived hits like scoring planes.
Represents a simulated tracker hit in the simulation.
Interface that defines a simulation primary generator.
Defines extra information attached to a Geant4 primary particle.
void setHepEvtStatus(int hepEvtStatus)
Set the HEP event status (generator status) e.g.
Copy particles from a particular scoring plane in as primaries of a new simulation.
std::string coll_name_
name of scoring plane collection we should use
std::vector< G4PrimaryVertex * > primary_vertices_
list of primary vertices we will give over to the G4Event
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
void GeneratePrimaryVertex(G4Event *anEvent) override
Generate vertices in the Geant4 event.
FromScoringPlane(const std::string &name, const framework::config::Parameters ¶meters)
Class constructor.
void prepEvent(const framework::Event &event) override
Retrieve the collection of scoring plane hits and copy the selected hits into our copies of primary p...
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record configuration information.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...