16 #include "G4LogicalVolumeStore.hh"
19 #include "G4TransportationManager.hh"
20 #include "DD4hep/Filter.h"
22 #include "CLHEP/Units/GlobalPhysicalConstants.h"
23 #include "CLHEP/Units/GlobalSystemOfUnits.h"
38 public Observer<const BeginOfEvent*>,
39 public Observer<const BeginOfTrack*>,
65 int findLV(
const G4VTouchable*);
72 std::map<int, std::pair<G4LogicalVolume*, int> >
mapLV_;
74 std::vector<MaterialInformation>
store_;
84 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolume: Studies Material budget for " << lvNames_.size()
86 std::ostringstream st1;
87 for (
unsigned int k = 0;
k < lvNames_.size(); ++
k)
88 st1 <<
" [" <<
k <<
"] " << lvNames_[
k] <<
" at " << lvLevel_[
k];
89 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolume: Volumes" << st1.str();
91 produces<edm::MaterialInformationContainer>(
"MaterialInformation");
93 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolume: will produce MaterialInformationContainer";
108 <<
" logical volumes with return flag " <<
init_;
114 int iev = (*evt)()->GetEventID();
115 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolume: =====> Begin event = " << iev << std::endl;
127 const G4Track* aTrack = (*trk)();
128 const G4ThreeVector& mom = aTrack->GetMomentum();
129 double theEnergy = aTrack->GetTotalEnergy();
130 int theID =
static_cast<int>(aTrack->GetDefinition()->GetPDGEncoding());
131 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolumme: Track " << aTrack->GetTrackID() <<
" Code " << theID
132 <<
" Energy " << theEnergy / CLHEP::GeV <<
" GeV; Momentum " << mom / CLHEP::GeV
138 G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
139 double step = aStep->GetStepLength();
140 double radl = material->GetRadlen();
141 double intl = material->GetNuclearInterLength();
142 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
151 << touch->GetVolume(0)->GetLogicalVolume()->GetName() <<
" Index " << index
152 <<
" Step " << step <<
" RadL " << step / radl <<
" IntL " << step / intl;
157 const G4Track* aTrack = (*trk)();
158 int id = aTrack->GetTrackID();
159 double eta = aTrack->GetMomentumDirection().eta();
160 double phi = aTrack->GetMomentumDirection().phi();
161 for (
unsigned int k = 0;
k <
lengths_.size(); ++
k) {
163 store_.emplace_back(info);
172 unsigned int kount(0);
174 for (
const auto& element :
store_) {
179 element.stepLength(),
180 element.radiationLength(),
181 element.interactionLength());
182 matbg.push_back(
info);
191 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
193 if (lvs !=
nullptr) {
194 std::vector<G4LogicalVolume*>::const_iterator lvcite;
195 for (
unsigned int i = 0;
i <
lvNames_.size();
i++) {
196 G4LogicalVolume* lv =
nullptr;
198 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
199 std::string namx(dd4hep::dd::noNamespace((*lvcite)->GetName()));
210 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetVolume::Finds " <<
mapLV_.size() <<
" logical volumes";
212 for (
const auto& lvs :
mapLV_) {
213 edm::LogVerbatim(
"MaterialBudget") <<
"Entry[" << k <<
"] " << lvs.first <<
": (" << (lvs.second).
first <<
", "
214 << (lvs.second).second <<
") : " <<
lvNames_[lvs.first];
224 int levels = ((touch->GetHistoryDepth()) + 1);
225 for (
const auto& lvs :
mapLV_) {
226 if ((lvs.second).second <=
levels) {
227 int ii = levels - (lvs.second).
second;
228 if ((touch->GetVolume(ii)->GetLogicalVolume()) == (lvs.second).first) {
236 edm::LogVerbatim(
"MaterialBudget") <<
"findLV: Gets " << level <<
" from " << levels <<
" levels in touchables";
238 edm::LogVerbatim(
"MaterialBudget") <<
"[" << (levels -
i) <<
"] " << touch->GetVolume(
i)->GetLogicalVolume()
239 <<
" : " << touch->GetVolume(
i)->GetLogicalVolume()->GetName();
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
MaterialBudgetVolume(const edm::ParameterSet &p)
std::vector< MatInfo > lengths_
void produce(edm::Event &, const edm::EventSetup &) override
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_
U second(std::pair< T, U > const &p)
std::vector< MaterialInformation > store_
std::vector< std::string > lvNames_
int findLV(const G4VTouchable *)
std::vector< MaterialInformation > MaterialInformationContainer
const MaterialBudgetVolume & operator=(const MaterialBudgetVolume &)=delete
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
std::vector< int > lvLevel_
void endOfEvent(edm::MaterialInformationContainer &matbg)
T getParameter(std::string const &) const
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int32_t int iev
MatInfo(double s=0, double r=0, double l=0)
~MaterialBudgetVolume() override