5 #include "G4TouchableHistory.hh"
6 #include "G4TransportationManager.hh"
7 #include "CLHEP/Units/GlobalSystemOfUnits.h"
8 #include "CLHEP/Units/GlobalPhysicalConstants.h"
23 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
24 produces<ParticleFlux>(Form(
"%sParticleFlux",
LVNames_[
k].c_str()));
27 <<
"SimG4FluxProducer::Collection name[" <<
k <<
"] ParticleFlux" <<
LVNames_[
k] <<
" and type " <<
LVTypes_[
k];
38 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
48 edm::LogVerbatim(
"SimG4FluxProducer") <<
"SimG4FluxProducer: enters BeginOfRun";
52 edm::LogWarning(
"SimG4FluxProducer") <<
"Cannot find top level volume\n";
55 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
56 for (
auto lvcite : *lvs) {
61 edm::LogVerbatim(
"SimG4FluxProducer") <<
"SimG4FluxProducer::Finds " <<
mapLV_.size() <<
" logical volumes";
63 for (
const auto& lvs :
mapLV_) {
65 <<
"Entry[" <<
k <<
"] " << lvs.first <<
": (" << (lvs.second).
first <<
", " << (lvs.second).second <<
")";
73 int iev = (*evt)()->GetEventID();
80 if (aStep !=
nullptr) {
81 G4TouchableHistory* touchable = (G4TouchableHistory*)aStep->GetPreStepPoint()->GetTouchable();
82 G4LogicalVolume* plv = (G4LogicalVolume*)touchable->GetVolume()->GetLogicalVolume();
87 if ((
type == 0 && aStep->IsFirstStepInVolume()) || (
type == 1 && aStep->IsLastStepInVolume())) {
88 unsigned int copy = (
unsigned int)(touchable->GetReplicaNumber(0));
89 std::pair<G4LogicalVolume*, unsigned int>
key(plv,
copy);
95 G4Track*
track = aStep->GetTrack();
96 int pdgid =
track->GetDefinition()->GetPDGEncoding();
97 int vxtyp = (
track->GetCreatorProcess() ==
nullptr) ? 0 : 1;
98 double time = (aStep->GetPostStepPoint()->GetGlobalTime());
99 const double mmTocm(0.1), MeVToGeV(0.001);
102 mmTocm *
track->GetVertexPosition().y(),
103 mmTocm *
track->GetVertexPosition().z());
105 mmTocm *
track->GetPosition().x(), mmTocm *
track->GetPosition().y(), mmTocm *
track->GetPosition().z());
107 MeVToGeV *
track->GetMomentum().y(),
108 MeVToGeV *
track->GetMomentum().z());
109 (itr->second).addFlux(flx);
112 <<
"SimG4FluxProducer: Element " << (it->second).
first <<
":" << (it->second).second <<
":" <<
copy
113 <<
" ID " <<
pdgid <<
" VxType " << vxtyp <<
" TOF " <<
time <<
" Hit Point " << flx.
hitPoint <<
" p "
123 for (
const auto& element :
store_) {
124 G4LogicalVolume* lv = (element.first).
first;
125 auto it =
mapLV_.find(lv);
127 if ((it->second).first ==
k) {
128 flux = element.second;
133 std::vector<ParticleFlux::flux> fluxes = flux.
getFlux();
135 for (
auto element : fluxes) {
137 <<
"Flux[" <<
k <<
"] PDGId " << element.pdgId <<
" VT " << element.vxType <<
" ToF " << element.tof
138 <<
" Vertex " << element.vertex <<
" Hit " << element.hitPoint <<
" p " << element.momentum;
150 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
154 G4LogicalVolume* plv) {
155 auto itr =
mapLV_.find(plv);
156 if (itr ==
mapLV_.end()) {
158 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
160 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);