15 #include "G4LogicalVolumeStore.hh" 16 #include "G4PhysicalVolumeStore.hh" 18 #include "G4TouchableHistory.hh" 19 #include "G4TransportationManager.hh" 21 #include <CLHEP/Units/GlobalSystemOfUnits.h> 22 #include <CLHEP/Units/GlobalPhysicalConstants.h> 37 public Observer<const BeginOfEvent *>,
55 std::map<G4LogicalVolume *, std::pair<unsigned int, std::string>>::iterator
findLV(G4LogicalVolume *plv);
60 std::map<G4LogicalVolume *, std::pair<unsigned int, std::string>>
mapLV_;
73 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
74 produces<ParticleFlux>(Form(
"%sParticleFlux",
LVNames_[
k].c_str()));
77 <<
"SimG4FluxProducer::Collection name[" <<
k <<
"] ParticleFlux" <<
LVNames_[
k] <<
" and type " <<
LVTypes_[
k];
88 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
98 edm::LogVerbatim(
"SimG4FluxProducer") <<
"SimG4FluxProducer: enters BeginOfRun";
102 edm::LogWarning(
"SimG4FluxProducer") <<
"Cannot find top level volume\n";
105 const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
106 for (
auto lvcite : *lvs) {
111 edm::LogVerbatim(
"SimG4FluxProducer") <<
"SimG4FluxProducer::Finds " <<
mapLV_.size() <<
" logical volumes";
113 for (
const auto &lvs :
mapLV_) {
115 <<
"Entry[" <<
k <<
"] " << lvs.first <<
": (" << (lvs.second).
first <<
", " << (lvs.second).second <<
")";
123 int iev = (*evt)()->GetEventID();
124 edm::LogVerbatim(
"SimG4FluxProducer") <<
"SimG4FluxProducer: =====> Begin event = " <<
iev;
130 if (aStep !=
nullptr) {
131 G4TouchableHistory *touchable = (G4TouchableHistory *)aStep->GetPreStepPoint()->GetTouchable();
132 G4LogicalVolume *plv = (G4LogicalVolume *)touchable->GetVolume()->GetLogicalVolume();
137 if ((
type == 0 && aStep->IsFirstStepInVolume()) || (
type == 1 && aStep->IsLastStepInVolume())) {
138 unsigned int copy = (
unsigned int)(touchable->GetReplicaNumber(0));
139 std::pair<G4LogicalVolume *, unsigned int>
key(plv,
copy);
141 if (itr ==
store_.end()) {
145 G4Track *
track = aStep->GetTrack();
146 int pdgid =
track->GetDefinition()->GetPDGEncoding();
147 int vxtyp = (
track->GetCreatorProcess() ==
nullptr) ? 0 : 1;
148 double time = (aStep->GetPostStepPoint()->GetGlobalTime());
149 const double mmTocm(0.1), MeVToGeV(0.001);
152 mmTocm *
track->GetVertexPosition().y(),
153 mmTocm *
track->GetVertexPosition().z());
155 mmTocm *
track->GetPosition().x(), mmTocm *
track->GetPosition().y(), mmTocm *
track->GetPosition().z());
157 MeVToGeV *
track->GetMomentum().y(),
158 MeVToGeV *
track->GetMomentum().z());
159 (itr->second).addFlux(flx);
162 <<
"SimG4FluxProducer: Element " << (
it->second).
first <<
":" << (
it->second).second <<
":" <<
copy 163 <<
" ID " <<
pdgid <<
" VxType " << vxtyp <<
" TOF " <<
time <<
" Hit Point " << flx.
hitPoint <<
" p " 173 for (
const auto &element :
store_) {
174 G4LogicalVolume *lv = (element.first).
first;
177 if ((
it->second).first ==
k) {
178 flux = element.second;
183 std::vector<ParticleFlux::flux> fluxes = flux.
getFlux();
185 for (
auto element : fluxes) {
187 <<
"Flux[" <<
k <<
"] PDGId " << element.pdgId <<
" VT " << element.vxType <<
" ToF " << element.tof
188 <<
" Vertex " << element.vertex <<
" Hit " << element.hitPoint <<
" p " << element.momentum;
200 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
204 G4LogicalVolume *plv) {
205 auto itr =
mapLV_.find(plv);
206 if (itr ==
mapLV_.end()) {
208 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
210 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);
Log< level::Info, true > LogVerbatim
unsigned int getComponents() const
#define DEFINE_SIMWATCHER(type)
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
const SimG4FluxProducer & operator=(const SimG4FluxProducer &)=delete
SimG4FluxProducer(const edm::ParameterSet &p)
~SimG4FluxProducer() override
void produce(edm::Event &, const edm::EventSetup &) override
G4VPhysicalVolume * topPV_
std::vector< int > LVTypes_
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator findLV(G4LogicalVolume *plv)
std::string const & getName() const
T getUntrackedParameter(std::string const &, T const &) const
math::GlobalVector momentum
key
prepare the HTCondor submission files and eventually submit them
G4VPhysicalVolume * getTopPV()
std::vector< std::string > LVNames_
void endOfEvent(ParticleFlux &pflx, unsigned int k)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
math::GlobalPoint hitPoint
std::vector< ParticleFlux::flux > getFlux() const &
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
Log< level::Warning, false > LogWarning