CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
HGCPassive Class Reference
Inheritance diagram for HGCPassive:
SimProducer Observer< const BeginOfRun *> Observer< const BeginOfEvent *> Observer< const G4Step *> SimWatcher

Public Member Functions

 HGCPassive (const edm::ParameterSet &p)
 
 HGCPassive (const HGCPassive &)=delete
 
const HGCPassiveoperator= (const HGCPassive &)=delete
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~HGCPassive () override
 
- Public Member Functions inherited from SimProducer
const SimProduceroperator= (const SimProducer &)=delete
 
void registerProducts (edm::ProducesCollector producesCollector)
 
 SimProducer ()
 
 SimProducer (const SimProducer &)=delete
 
- Public Member Functions inherited from SimWatcher
virtual void beginRun (edm::EventSetup const &)
 
bool isMT () const
 
const SimWatcheroperator= (const SimWatcher &)=delete
 
virtual void registerConsumes (edm::ConsumesCollector)
 
 SimWatcher ()
 
 SimWatcher (const SimWatcher &)=delete
 
virtual ~SimWatcher ()
 
- Public Member Functions inherited from Observer< const BeginOfRun *>
 Observer ()
 
void slotForUpdate (const BeginOfRun * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfEvent *>
 Observer ()
 
void slotForUpdate (const BeginOfEvent * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const G4Step *>
 Observer ()
 
void slotForUpdate (const G4Step * iT)
 
virtual ~Observer ()
 

Private Types

typedef std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator volumeIterator
 

Private Member Functions

void endOfEvent (edm::PassiveHitContainer &hgcPH, unsigned int k)
 
volumeIterator findLV (G4LogicalVolume *plv)
 
G4VPhysicalVolume * getTopPV ()
 
void storeInfo (const volumeIterator itr, G4LogicalVolume *plv, unsigned int copy, double time, double energy, bool flag)
 
void update (const BeginOfRun *run) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfEvent *evt) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const G4Step *step) override
 This routine will be called when the appropriate signal arrives. More...
 

Private Attributes

const int addlevel_
 
unsigned int count_
 
bool init_
 
const std::vector< std::string > LVNames_
 
const edm::ParameterSet m_Passive
 
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
 
const std::string motherName_
 
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
 
G4LogicalVolume * topLV_
 
G4VPhysicalVolume * topPV_
 

Additional Inherited Members

- Protected Member Functions inherited from SimProducer
template<class T >
void produces ()
 
template<class T >
void produces (const std::string &instanceName)
 
- Protected Member Functions inherited from SimWatcher
void setMT (bool val)
 

Detailed Description

Definition at line 36 of file HGCPassive.cc.

Member Typedef Documentation

◆ volumeIterator

typedef std::map<G4LogicalVolume *, std::pair<unsigned int, std::string> >::iterator HGCPassive::volumeIterator
private

Definition at line 57 of file HGCPassive.cc.

Constructor & Destructor Documentation

◆ HGCPassive() [1/2]

HGCPassive::HGCPassive ( const edm::ParameterSet p)

Definition at line 78 of file HGCPassive.cc.

References addlevel_, dqmdumpme::k, LVNames_, motherName_, and Skims_PA_cff::name.

79  : m_Passive(p.getParameter<edm::ParameterSet>("HGCPassive")),
80  LVNames_(m_Passive.getParameter<std::vector<std::string>>("LVNames")),
82  addlevel_((m_Passive.getParameter<bool>("IfDD4hep")) ? 1 : 0),
83  topPV_(nullptr),
84  topLV_(nullptr),
85  count_(0),
86  init_(false) {
87 #ifdef EDM_ML_DEBUG
88  edm::LogVerbatim("HGCSim") << "Name of the mother volume " << motherName_ << " AddLevel " << addlevel_;
89  unsigned k(0);
90 #endif
91  for (const auto &name : LVNames_) {
92  produces<edm::PassiveHitContainer>(Form("%sPassiveHits", name.c_str()));
93 #ifdef EDM_ML_DEBUG
94  edm::LogVerbatim("HGCSim") << "Collection name[" << k << "] " << name;
95  ++k;
96 #endif
97  }
98 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
G4LogicalVolume * topLV_
Definition: HGCPassive.cc:69
const int addlevel_
Definition: HGCPassive.cc:67
G4VPhysicalVolume * topPV_
Definition: HGCPassive.cc:68
const std::string motherName_
Definition: HGCPassive.cc:66
const edm::ParameterSet m_Passive
Definition: HGCPassive.cc:64
unsigned int count_
Definition: HGCPassive.cc:73
const std::vector< std::string > LVNames_
Definition: HGCPassive.cc:65
bool init_
Definition: HGCPassive.cc:74

◆ HGCPassive() [2/2]

HGCPassive::HGCPassive ( const HGCPassive )
delete

◆ ~HGCPassive()

HGCPassive::~HGCPassive ( )
override

Definition at line 100 of file HGCPassive.cc.

100 {}

Member Function Documentation

◆ endOfEvent()

void HGCPassive::endOfEvent ( edm::PassiveHitContainer hgcPH,
unsigned int  k 
)
private

Definition at line 214 of file HGCPassive.cc.

References first, dqmdumpme::k, mapLV_, and store_.

Referenced by produce().

214  {
215 #ifdef EDM_ML_DEBUG
216  unsigned int kount(0);
217 #endif
218  for (const auto &element : store_) {
219  G4LogicalVolume *lv = (element.first).first;
220  auto it = mapLV_.find(lv);
221  if (it != mapLV_.end()) {
222  if ((it->second).first == k) {
223  PassiveHit hit(
224  (it->second).second, (element.first).second, (element.second)[1], (element.second)[2], (element.second)[0]);
225  hgcPH.push_back(hit);
226 #ifdef EDM_ML_DEBUG
227  edm::LogVerbatim("HGCSim") << "HGCPassive[" << k << "] Hit[" << kount << "] " << hit;
228  ++kount;
229 #endif
230  }
231  }
232  }
233 }
Log< level::Info, true > LogVerbatim
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
Definition: HGCPassive.cc:75
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: HGCPassive.cc:70

◆ findLV()

HGCPassive::volumeIterator HGCPassive::findLV ( G4LogicalVolume *  plv)
private

Definition at line 239 of file HGCPassive.cc.

References dqmdumpme::k, LVNames_, mapLV_, motherName_, Skims_PA_cff::name, AlCaHLTBitMon_QueryRunRegistry::string, and topLV_.

Referenced by update().

239  {
240  auto itr = mapLV_.find(plv);
241  if (itr == mapLV_.end()) {
242  std::string name = static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName()));
243  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
244  if (name.find(LVNames_[k]) != std::string::npos) {
245  mapLV_[plv] = std::pair<unsigned int, std::string>(k, name);
246  itr = mapLV_.find(plv);
247  break;
248  }
249  }
250  }
251  if (topLV_ == nullptr) {
252  if (static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName())) == motherName_)
253  topLV_ = plv;
254  }
255  return itr;
256 }
G4LogicalVolume * topLV_
Definition: HGCPassive.cc:69
const std::string motherName_
Definition: HGCPassive.cc:66
const std::vector< std::string > LVNames_
Definition: HGCPassive.cc:65
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: HGCPassive.cc:70

◆ getTopPV()

G4VPhysicalVolume * HGCPassive::getTopPV ( )
private

Definition at line 235 of file HGCPassive.cc.

Referenced by update().

235  {
236  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
237 }

◆ operator=()

const HGCPassive& HGCPassive::operator= ( const HGCPassive )
delete

◆ produce()

void HGCPassive::produce ( edm::Event e,
const edm::EventSetup  
)
overridevirtual

Implements SimProducer.

Definition at line 102 of file HGCPassive.cc.

References MillePedeFileConverter_cfg::e, endOfEvent(), dqmdumpme::k, LVNames_, and eostools::move().

102  {
103  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
104  std::unique_ptr<edm::PassiveHitContainer> hgcPH(new edm::PassiveHitContainer);
105  endOfEvent(*hgcPH, k);
106  e.put(std::move(hgcPH), Form("%sPassiveHits", LVNames_[k].c_str()));
107  }
108 }
void endOfEvent(edm::PassiveHitContainer &hgcPH, unsigned int k)
Definition: HGCPassive.cc:214
std::vector< PassiveHit > PassiveHitContainer
Definition: PassiveHit.h:100
const std::vector< std::string > LVNames_
Definition: HGCPassive.cc:65
def move(src, dest)
Definition: eostools.py:511

◆ storeInfo()

void HGCPassive::storeInfo ( const volumeIterator  itr,
G4LogicalVolume *  plv,
unsigned int  copy,
double  time,
double  energy,
bool  flag 
)
private

Definition at line 258 of file HGCPassive.cc.

References filterCSVwithJSON::copy, HCALHighEnergyHPDFilter_cfi::energy, first, RemoveAddSevLevel::flag, crabWrapper::key, store_, and protons_cff::time.

Referenced by update().

263  {
264  std::pair<G4LogicalVolume *, unsigned int> key(plv, copy);
265  auto itr = store_.find(key);
266  double ee = (flag) ? energy : 0;
267  if (itr == store_.end()) {
268  store_[key] = {{time, energy, energy}};
269  } else {
270  (itr->second)[1] += ee;
271  (itr->second)[2] += energy;
272  }
273 #ifdef EDM_ML_DEBUG
274  itr = store_.find(key);
275  edm::LogVerbatim("HGCSim") << "HGCPassive: Element " << (it->second).first << ":" << (it->second).second << ":"
276  << copy << " T " << (itr->second)[0] << " E " << (itr->second)[1] << ":"
277  << (itr->second)[2];
278 #endif
279 }
Log< level::Info, true > LogVerbatim
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
Definition: HGCPassive.cc:75

◆ update() [1/3]

void HGCPassive::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 110 of file HGCPassive.cc.

References findLV(), first, getTopPV(), init_, dqmdumpme::k, mapLV_, and topPV_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

110  {
111  topPV_ = getTopPV();
112  if (topPV_ == nullptr) {
113  edm::LogWarning("HGCSim") << "Cannot find top level volume\n";
114  } else {
115  init_ = true;
116  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
117  for (auto lvcite : *lvs) {
118  findLV(lvcite);
119  }
120 
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("HGCSim") << "HGCPassive::Finds " << mapLV_.size() << " logical volumes";
123  unsigned int k(0);
124  for (const auto &lvs : mapLV_) {
125  edm::LogVerbatim("HGCSim") << "Entry[" << k << "] " << lvs.first << ": (" << (lvs.second).first << ", "
126  << (lvs.second).second << ")";
127  ++k;
128  }
129 #endif
130  }
131 }
Log< level::Info, true > LogVerbatim
volumeIterator findLV(G4LogicalVolume *plv)
Definition: HGCPassive.cc:239
G4VPhysicalVolume * topPV_
Definition: HGCPassive.cc:68
G4VPhysicalVolume * getTopPV()
Definition: HGCPassive.cc:235
Log< level::Warning, false > LogWarning
bool init_
Definition: HGCPassive.cc:74
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: HGCPassive.cc:70

◆ update() [2/3]

void HGCPassive::update ( const BeginOfEvent )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 134 of file HGCPassive.cc.

References count_, iev, and store_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

134  {
135  int iev = (*evt)()->GetEventID();
136  edm::LogVerbatim("HGCSim") << "HGCPassive: =====> Begin event = " << iev << std::endl;
137 
138  ++count_;
139  store_.clear();
140 }
Log< level::Info, true > LogVerbatim
unsigned int count_
Definition: HGCPassive.cc:73
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
Definition: HGCPassive.cc:75
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int32_t int iev

◆ update() [3/3]

void HGCPassive::update ( const G4Step *  )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step *>.

Definition at line 144 of file HGCPassive.cc.

References filterCSVwithJSON::copy, HCALHighEnergyHPDFilter_cfi::energy, findLV(), mps_fire::i, init_, personalPlayback::level, mapLV_, storeInfo(), AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::time, and topLV_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

144  {
145  if (aStep != nullptr) {
146  G4VSensitiveDetector *curSD = aStep->GetPreStepPoint()->GetSensitiveDetector();
147  const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
148 
149  int level = (touchable->GetHistoryDepth());
150  if (curSD == nullptr) {
151  G4LogicalVolume *plv = touchable->GetVolume()->GetLogicalVolume();
152  auto it = (init_) ? mapLV_.find(plv) : findLV(plv);
153  double time = aStep->GetTrack()->GetGlobalTime();
154  double energy = (aStep->GetTotalEnergyDeposit()) / CLHEP::GeV;
155 
156  unsigned int copy(0);
157  if (((aStep->GetPostStepPoint() == nullptr) || (aStep->GetTrack()->GetNextVolume() == nullptr)) &&
158  (aStep->IsLastStepInVolume())) {
159 #ifdef EDM_ML_DEBUG
160  edm::LogVerbatim("HGCSim") << static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName())) << " F|L Step "
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());
169 #endif
170  energy += (aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::GeV);
171  } else {
172  time = (aStep->GetPostStepPoint()->GetGlobalTime());
173  copy = (level < 2)
174  ? 0
175  : static_cast<unsigned int>(touchable->GetReplicaNumber(0) + 1000 * touchable->GetReplicaNumber(1));
176  }
177  if (it != mapLV_.end()) {
178  storeInfo(it, plv, copy, time, energy, true);
179  } else if (topLV_ != nullptr) {
180  auto itr = findLV(topLV_);
181  if (itr != mapLV_.end()) {
182  storeInfo(itr, topLV_, copy, time, energy, true);
183  }
184  }
185  } // if (curSD==NULL)
186 
187  // Now for the mother volumes
188  if (level > 0) {
189  double energy = (aStep->GetTotalEnergyDeposit()) / CLHEP::GeV;
190  double time = (aStep->GetTrack()->GetGlobalTime());
191 
192  for (int i = level; i > 0; --i) {
193  G4LogicalVolume *plv = touchable->GetVolume(i)->GetLogicalVolume();
194  auto it = (init_) ? mapLV_.find(plv) : findLV(plv);
195 #ifdef EDM_ML_DEBUG
196  edm::LogVerbatim("HGCSim") << "Level: " << level << ":" << i << " "
197  << static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName()))
198  << " flag in the List " << (it != mapLV_.end());
199 #endif
200  if (it != mapLV_.end()) {
201  unsigned int copy =
202  (i == level) ? 0
203  : (unsigned int)(touchable->GetReplicaNumber(i) + 1000 * touchable->GetReplicaNumber(i + 1));
204  storeInfo(it, plv, copy, time, energy, false);
205  }
206  }
207  }
208  } // if (aStep != NULL)
209 
210 } // end update aStep
Log< level::Info, true > LogVerbatim
void storeInfo(const volumeIterator itr, G4LogicalVolume *plv, unsigned int copy, double time, double energy, bool flag)
Definition: HGCPassive.cc:258
G4LogicalVolume * topLV_
Definition: HGCPassive.cc:69
volumeIterator findLV(G4LogicalVolume *plv)
Definition: HGCPassive.cc:239
bool init_
Definition: HGCPassive.cc:74
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: HGCPassive.cc:70

Member Data Documentation

◆ addlevel_

const int HGCPassive::addlevel_
private

Definition at line 67 of file HGCPassive.cc.

Referenced by HGCPassive().

◆ count_

unsigned int HGCPassive::count_
private

Definition at line 73 of file HGCPassive.cc.

Referenced by update().

◆ init_

bool HGCPassive::init_
private

Definition at line 74 of file HGCPassive.cc.

Referenced by update().

◆ LVNames_

const std::vector<std::string> HGCPassive::LVNames_
private

Definition at line 65 of file HGCPassive.cc.

Referenced by findLV(), HGCPassive(), and produce().

◆ m_Passive

const edm::ParameterSet HGCPassive::m_Passive
private

Definition at line 64 of file HGCPassive.cc.

◆ mapLV_

std::map<G4LogicalVolume *, std::pair<unsigned int, std::string> > HGCPassive::mapLV_
private

Definition at line 70 of file HGCPassive.cc.

Referenced by endOfEvent(), findLV(), and update().

◆ motherName_

const std::string HGCPassive::motherName_
private

Definition at line 66 of file HGCPassive.cc.

Referenced by findLV(), and HGCPassive().

◆ store_

std::map<std::pair<G4LogicalVolume *, unsigned int>, std::array<double, 3> > HGCPassive::store_
private

Definition at line 75 of file HGCPassive.cc.

Referenced by endOfEvent(), storeInfo(), and update().

◆ topLV_

G4LogicalVolume* HGCPassive::topLV_
private

Definition at line 69 of file HGCPassive.cc.

Referenced by findLV(), and update().

◆ topPV_

G4VPhysicalVolume* HGCPassive::topPV_
private

Definition at line 68 of file HGCPassive.cc.

Referenced by update().