20 #include "G4LogicalVolumeStore.hh" 21 #include "G4PhysicalVolumeStore.hh" 23 #include "G4TransportationManager.hh" 24 #include "G4TouchableHistory.hh" 26 #include "DD4hep/Filter.h" 38 public Observer<const BeginOfEvent *>,
57 typedef std::map<G4LogicalVolume *, std::pair<unsigned int, std::string>>::iterator
volumeIterator;
70 std::map<G4LogicalVolume *, std::pair<unsigned int, std::string>>
mapLV_;
75 std::map<std::pair<G4LogicalVolume *, unsigned int>, std::array<double, 3>>
store_;
81 motherName_(m_Passive.getParameter<
std::
string>(
"MotherName")),
82 addlevel_((m_Passive.getParameter<
bool>(
"IfDD4hep")) ? 1 : 0),
92 produces<edm::PassiveHitContainer>(Form(
"%sPassiveHits",
name.c_str()));
103 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
116 const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
117 for (
auto lvcite : *lvs) {
124 for (
const auto &lvs :
mapLV_) {
126 << (lvs.second).second <<
")";
135 int iev = (*evt)()->GetEventID();
145 if (aStep !=
nullptr) {
146 G4VSensitiveDetector *curSD = aStep->GetPreStepPoint()->GetSensitiveDetector();
147 const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
149 int level = (touchable->GetHistoryDepth());
150 if (curSD ==
nullptr) {
151 G4LogicalVolume *plv = touchable->GetVolume()->GetLogicalVolume();
153 double time = aStep->GetTrack()->GetGlobalTime();
154 double energy = (aStep->GetTotalEnergyDeposit()) / CLHEP::GeV;
156 unsigned int copy(0);
157 if (((aStep->GetPostStepPoint() ==
nullptr) || (aStep->GetTrack()->GetNextVolume() ==
nullptr)) &&
158 (aStep->IsLastStepInVolume())) {
161 << aStep->IsFirstStepInVolume() <<
":" << aStep->IsLastStepInVolume() <<
" Position" 162 << aStep->GetPreStepPoint()->GetPosition() <<
" Track " 163 << aStep->GetTrack()->GetDefinition()->GetParticleName() <<
" at" 164 << aStep->GetTrack()->GetPosition() <<
" Volume " << aStep->GetTrack()->GetVolume()
165 <<
":" << aStep->GetTrack()->GetNextVolume() <<
" Status " 166 << aStep->GetTrack()->GetTrackStatus() <<
" KE " 167 << aStep->GetTrack()->GetKineticEnergy() <<
" Deposit " 168 << aStep->GetTotalEnergyDeposit() <<
" Map " << (it !=
mapLV_.end());
170 energy += (aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::GeV);
172 time = (aStep->GetPostStepPoint()->GetGlobalTime());
175 : static_cast<unsigned int>(touchable->GetReplicaNumber(0) + 1000 * touchable->GetReplicaNumber(1));
179 }
else if (
topLV_ !=
nullptr) {
181 if (itr !=
mapLV_.end()) {
189 double energy = (aStep->GetTotalEnergyDeposit()) / CLHEP::GeV;
190 double time = (aStep->GetTrack()->GetGlobalTime());
193 G4LogicalVolume *plv = touchable->GetVolume(
i)->GetLogicalVolume();
197 <<
static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName()))
198 <<
" flag in the List " << (it !=
mapLV_.end());
203 : (
unsigned int)(touchable->GetReplicaNumber(
i) + 1000 * touchable->GetReplicaNumber(
i + 1));
216 unsigned int kount(0);
218 for (
const auto &element :
store_) {
219 G4LogicalVolume *lv = (element.first).
first;
220 auto it =
mapLV_.find(lv);
222 if ((it->second).first ==
k) {
224 (it->second).second, (element.first).second, (element.second)[1], (element.second)[2], (element.second)[0]);
225 hgcPH.push_back(
hit);
236 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
240 auto itr =
mapLV_.find(plv);
241 if (itr ==
mapLV_.end()) {
243 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
245 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);
252 if (static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName())) ==
motherName_)
259 G4LogicalVolume *plv,
264 std::pair<G4LogicalVolume *, unsigned int>
key(plv,
copy);
267 if (itr ==
store_.end()) {
270 (itr->second)[1] += ee;
271 (itr->second)[2] +=
energy;
275 edm::LogVerbatim(
"HGCSim") <<
"HGCPassive: Element " << (it->second).
first <<
":" << (it->second).second <<
":" 276 <<
copy <<
" T " << (itr->second)[0] <<
" E " << (itr->second)[1] <<
":" Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
void storeInfo(const volumeIterator itr, G4LogicalVolume *plv, unsigned int copy, double time, double energy, bool flag)
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator volumeIterator
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
void endOfEvent(edm::PassiveHitContainer &hgcPH, unsigned int k)
volumeIterator findLV(G4LogicalVolume *plv)
G4VPhysicalVolume * topPV_
G4VPhysicalVolume * getTopPV()
HGCPassive(const edm::ParameterSet &p)
const std::string motherName_
const edm::ParameterSet m_Passive
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< PassiveHit > PassiveHitContainer
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
const std::vector< std::string > LVNames_
Log< level::Warning, false > LogWarning
const HGCPassive & operator=(const HGCPassive &)=delete
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_