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;
67 std::map<G4LogicalVolume *, std::pair<unsigned int, std::string>>
mapLV_;
74 std::map<std::pair<G4LogicalVolume *, unsigned int>, std::array<double, 3>>
store_;
88 for (
const auto &
name : LVNames_) {
89 produces<edm::PassiveHitContainer>(Form(
"%sPassiveHits",
name.c_str()));
100 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
113 const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
114 for (
auto lvcite : *lvs) {
121 for (
const auto &lvs :
mapLV_) {
122 edm::LogVerbatim(
"HGCSim") <<
"Entry[" << k <<
"] " << lvs.first <<
": (" << (lvs.second).
first <<
", "
123 << (lvs.second).second <<
")";
132 int iev = (*evt)()->GetEventID();
133 edm::LogVerbatim(
"HGCSim") <<
"HGCPassive: =====> Begin event = " << iev << std::endl;
142 if (aStep !=
nullptr) {
143 G4VSensitiveDetector *curSD = aStep->GetPreStepPoint()->GetSensitiveDetector();
144 const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
146 int level = (touchable->GetHistoryDepth());
147 if (curSD ==
nullptr) {
148 G4LogicalVolume *plv = touchable->GetVolume()->GetLogicalVolume();
150 double time = aStep->GetTrack()->GetGlobalTime();
153 unsigned int copy(0);
154 if (((aStep->GetPostStepPoint() ==
nullptr) || (aStep->GetTrack()->GetNextVolume() ==
nullptr)) &&
155 (aStep->IsLastStepInVolume())) {
158 << aStep->IsFirstStepInVolume() <<
":" << aStep->IsLastStepInVolume() <<
" Position"
159 << aStep->GetPreStepPoint()->GetPosition() <<
" Track "
160 << aStep->GetTrack()->GetDefinition()->GetParticleName() <<
" at"
161 << aStep->GetTrack()->GetPosition() <<
" Volume " << aStep->GetTrack()->GetVolume()
162 <<
":" << aStep->GetTrack()->GetNextVolume() <<
" Status "
163 << aStep->GetTrack()->GetTrackStatus() <<
" KE "
164 << aStep->GetTrack()->GetKineticEnergy() <<
" Deposit "
165 << aStep->GetTotalEnergyDeposit() <<
" Map " << (it !=
mapLV_.end());
167 energy += (aStep->GetPreStepPoint()->GetKineticEnergy() /
CLHEP::GeV);
169 time = (aStep->GetPostStepPoint()->GetGlobalTime());
172 : static_cast<unsigned int>(touchable->GetReplicaNumber(0) + 1000 * touchable->GetReplicaNumber(1));
175 storeInfo(it, plv, copy, time, energy,
true);
176 }
else if (
topLV_ !=
nullptr) {
178 if (itr !=
mapLV_.end()) {
187 double time = (aStep->GetTrack()->GetGlobalTime());
189 for (
int i = level;
i > 0; --
i) {
190 G4LogicalVolume *plv = touchable->GetVolume(
i)->GetLogicalVolume();
194 <<
static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName()))
195 <<
" flag in the List " << (it !=
mapLV_.end());
200 : (
unsigned int)(touchable->GetReplicaNumber(
i) + 1000 * touchable->GetReplicaNumber(
i + 1));
201 storeInfo(it, plv, copy, time, energy,
false);
213 unsigned int kount(0);
215 for (
const auto &element :
store_) {
216 G4LogicalVolume *lv = (element.first).
first;
217 auto it =
mapLV_.find(lv);
219 if ((it->second).first ==
k) {
221 (it->second).second, (element.first).second, (element.second)[1], (element.second)[2], (element.second)[0]);
222 hgcPH.push_back(hit);
224 edm::LogVerbatim(
"HGCSim") <<
"HGCPassive[" << k <<
"] Hit[" << kount <<
"] " << hit;
233 return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
237 auto itr =
mapLV_.find(plv);
238 if (itr ==
mapLV_.end()) {
240 for (
unsigned int k = 0;
k <
LVNames_.size(); ++
k) {
241 if (name.find(
LVNames_[
k]) != std::string::npos) {
242 mapLV_[plv] = std::pair<unsigned int, std::string>(
k,
name);
249 if (static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName())) ==
motherName_)
256 G4LogicalVolume *plv,
261 std::pair<G4LogicalVolume *, unsigned int>
key(plv, copy);
262 auto itr =
store_.find(key);
263 double ee = (flag) ? energy : 0;
264 if (itr ==
store_.end()) {
267 (itr->second)[1] += ee;
268 (itr->second)[2] += energy;
272 edm::LogVerbatim(
"HGCSim") <<
"HGCPassive: Element " << (it->second).
first <<
":" << (it->second).second <<
":"
273 << copy <<
" T " << (itr->second)[0] <<
" E " << (itr->second)[1] <<
":"
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
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
void endOfEvent(edm::PassiveHitContainer &hgcPH, unsigned int k)
volumeIterator findLV(G4LogicalVolume *plv)
G4VPhysicalVolume * topPV_
G4VPhysicalVolume * getTopPV()
HGCPassive(const edm::ParameterSet &p)
std::vector< std::string > LVNames_
tuple key
prepare the HTCondor submission files and eventually submit them
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< PassiveHit > PassiveHitContainer
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
T getParameter(std::string const &) const
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
Log< level::Warning, false > LogWarning
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int iev
const HGCPassive & operator=(const HGCPassive &)=delete
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_