5 #include "G4TouchableHistory.hh" 6 #include "G4TransportationManager.hh" 7 #include "CLHEP/Units/GlobalSystemOfUnits.h" 8 #include "CLHEP/Units/GlobalPhysicalConstants.h" 24 for (
unsigned int k=0;
k<LVNames_.size(); ++
k) {
25 produces<ParticleFlux>(Form(
"%sParticleFlux",LVNames_[
k].c_str()));
27 std::cout <<
"Collection name[" <<
k <<
"] ParticleFlux" << LVNames_[
k]
28 <<
" and type " << LVTypes_[
k] << std::endl;
49 edm::LogWarning(
"SimG4FluxProducer") <<
"Cannot find top level volume\n";
52 const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
53 for (
auto lvcite : *lvs) {
58 std::cout <<
"SimG4FluxProducer::Finds " <<
mapLV_.size() <<
" logical volumes\n";
60 for (
const auto& lvs :
mapLV_) {
61 std::cout <<
"Entry[" << k <<
"] " << lvs.first <<
": (" 62 << (lvs.second).
first <<
", " << (lvs.second).second <<
")\n";
71 int iev = (*evt)()->GetEventID();
72 edm::LogInfo(
"ValidHGCal") <<
"SimG4FluxProducer: =====> Begin event = " 82 G4TouchableHistory* touchable = (G4TouchableHistory*)aStep->GetPreStepPoint()->GetTouchable();
83 G4LogicalVolume* plv = (G4LogicalVolume*)touchable->GetVolume()->GetLogicalVolume();
88 if ((type == 0 && aStep->IsFirstStepInVolume()) ||
89 (type == 1 && aStep->IsLastStepInVolume())) {
90 unsigned int copy = (
unsigned int)(touchable->GetReplicaNumber(0));
91 std::pair<G4LogicalVolume*,unsigned int>
key(plv,copy);
92 auto itr =
store_.find(key);
97 G4Track*
track = aStep->GetTrack();
98 int pdgid = track->GetDefinition()->GetPDGEncoding();
99 int vxtyp = (track->GetCreatorProcess() ==
nullptr) ? 0 : 1;
100 double time = (aStep->GetPostStepPoint()->GetGlobalTime());
101 const double mmTocm(0.1), MeVToGeV(0.001);
104 mmTocm*track->GetVertexPosition().y(),
105 mmTocm*track->GetVertexPosition().z());
107 mmTocm*track->GetPosition().y(),
108 mmTocm*track->GetPosition().z());
110 MeVToGeV*track->GetMomentum().y(),
111 MeVToGeV*track->GetMomentum().z());
112 (itr->second).addFlux(flx);
114 std::cout <<
"SimG4FluxProducer: Element " << (it->second).
first <<
":" 115 << (it->second).second <<
":" << copy <<
" ID " << pdgid
116 <<
" VxType " << vxtyp <<
" TOF " << time <<
" Hit Point " 118 << flx.
vertex << std::endl;
129 for (
const auto& element :
store_) {
130 G4LogicalVolume* lv = (element.first).
first;
131 auto it =
mapLV_.find(lv);
133 if ((it->second).first ==
k) {
134 flux = element.second;
139 <<
" elements" << std::endl;
140 std::vector<ParticleFlux::flux> fluxes = flux.
getFlux() ;
142 for (
auto element : fluxes) {
143 std::cout <<
"Flux[" << k <<
"] PDGId " << element.pdgId <<
" VT " 144 << element.vxType <<
" ToF " << element.tof <<
" Vertex " 145 << element.vertex <<
" Hit " << element.hitPoint <<
" p " 146 << element.momentum << std::endl;
157 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
161 auto itr =
mapLV_.find(plv);
162 if (itr ==
mapLV_.end()) {
165 if (name.find(
LVNames_[
k]) != std::string::npos) {
166 mapLV_[plv] = std::pair<unsigned int,std::string>(
k,
name);
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
SimG4FluxProducer(const edm::ParameterSet &p)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
G4VPhysicalVolume * topPV_
std::vector< int > LVTypes_
unsigned int getComponents() const
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)
virtual ~SimG4FluxProducer()
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
void produce(edm::Event &, const edm::EventSetup &)
void update(const BeginOfRun *run)
This routine will be called when the appropriate signal arrives.