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()));
34 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
45 edm::LogWarning(
"SimG4FluxProducer") <<
"Cannot find top level volume\n";
48 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
49 for (
auto lvcite : *lvs) {
54 std::cout <<
"SimG4FluxProducer::Finds " <<
mapLV_.size() <<
" logical volumes\n";
56 for (
const auto& lvs :
mapLV_) {
57 std::cout <<
"Entry[" <<
k <<
"] " << lvs.first <<
": (" << (lvs.second).
first <<
", " << (lvs.second).second
66 int iev = (*evt)()->GetEventID();
67 edm::LogInfo(
"ValidHGCal") <<
"SimG4FluxProducer: =====> Begin event = " << iev << std::endl;
73 if (aStep !=
nullptr) {
74 G4TouchableHistory* touchable = (G4TouchableHistory*)aStep->GetPreStepPoint()->GetTouchable();
75 G4LogicalVolume* plv = (G4LogicalVolume*)touchable->GetVolume()->GetLogicalVolume();
80 if ((
type == 0 && aStep->IsFirstStepInVolume()) || (
type == 1 && aStep->IsLastStepInVolume())) {
81 unsigned int copy = (
unsigned int)(touchable->GetReplicaNumber(0));
82 std::pair<G4LogicalVolume*, unsigned int>
key(plv,
copy);
88 G4Track*
track = aStep->GetTrack();
89 int pdgid =
track->GetDefinition()->GetPDGEncoding();
90 int vxtyp = (
track->GetCreatorProcess() ==
nullptr) ? 0 : 1;
91 double time = (aStep->GetPostStepPoint()->GetGlobalTime());
92 const double mmTocm(0.1), MeVToGeV(0.001);
95 mmTocm *
track->GetVertexPosition().y(),
96 mmTocm *
track->GetVertexPosition().z());
98 mmTocm *
track->GetPosition().x(), mmTocm *
track->GetPosition().y(), mmTocm *
track->GetPosition().z());
100 MeVToGeV *
track->GetMomentum().y(),
101 MeVToGeV *
track->GetMomentum().z());
102 (
itr->second).addFlux(flx);
104 std::cout <<
"SimG4FluxProducer: Element " << (it->second).
first <<
":" << (it->second).second <<
":" <<
copy
105 <<
" ID " <<
pdgid <<
" VxType " << vxtyp <<
" TOF " <<
time <<
" Hit Point " << flx.
hitPoint <<
" p "
115 for (
const auto& element :
store_) {
116 G4LogicalVolume* lv = (element.first).
first;
117 auto it =
mapLV_.find(lv);
119 if ((it->second).first ==
k) {
120 flux = element.second;
125 std::vector<ParticleFlux::flux> fluxes = flux.
getFlux();
127 for (
auto element : fluxes) {
128 std::cout <<
"Flux[" <<
k <<
"] PDGId " << element.pdgId <<
" VT " << element.vxType <<
" ToF " << element.tof
129 <<
" Vertex " << element.vertex <<
" Hit " << element.hitPoint <<
" p " << element.momentum
142 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
146 G4LogicalVolume* plv) {
150 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
152 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);