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()));
26 std::cout <<
"Collection name[" <<
k <<
"] ParticleFlux" << LVNames_[
k] <<
" and type " << LVTypes_[
k] << std::endl;
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);
83 auto itr =
store_.find(key);
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;
123 std::cout <<
"SimG4FluxProducer[" << k <<
"] Flux " << flux.
getName() <<
":" << flux.
getId() <<
" with " 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) {
147 auto itr =
mapLV_.find(plv);
148 if (itr ==
mapLV_.end()) {
150 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
151 if (name.find(
LVNames_[
k]) != std::string::npos) {
152 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
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
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
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_