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);
140 auto itr =
store_.find(key);
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;
175 auto it =
mapLV_.find(lv);
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) {
209 if (name.find(
LVNames_[
k]) != std::string::npos) {
210 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) 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)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
~SimG4FluxProducer() override
void produce(edm::Event &, const edm::EventSetup &) override
G4VPhysicalVolume * topPV_
std::vector< int > LVTypes_
unsigned int getComponents() const
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)
math::GlobalVector momentum
tuple 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
std::string const & getName() const
T getParameter(std::string const &) const
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
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int iev