CMS 3D CMS Logo

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

Public Member Functions

 HGCalTBPassive (const edm::ParameterSet &p)
 
 HGCalTBPassive (const HGCalTBPassive &)=delete
 
const HGCalTBPassiveoperator= (const HGCalTBPassive &)=delete
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~HGCalTBPassive () 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 HGCalTBPassive.cc.

Member Typedef Documentation

◆ volumeIterator

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

Definition at line 57 of file HGCalTBPassive.cc.

Constructor & Destructor Documentation

◆ HGCalTBPassive() [1/2]

HGCalTBPassive::HGCalTBPassive ( const edm::ParameterSet p)

Definition at line 78 of file HGCalTBPassive.cc.

References addlevel_, isotrackApplyRegressor::k, LVNames_, motherName_, and mergeVDriftHistosByStation::name.

79  : m_Passive(p.getParameter<edm::ParameterSet>("HGCalTBPassive")),
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:307
const int addlevel_
const edm::ParameterSet m_Passive
G4LogicalVolume * topLV_
const std::vector< std::string > LVNames_
const std::string motherName_
G4VPhysicalVolume * topPV_
unsigned int count_

◆ HGCalTBPassive() [2/2]

HGCalTBPassive::HGCalTBPassive ( const HGCalTBPassive )
delete

◆ ~HGCalTBPassive()

HGCalTBPassive::~HGCalTBPassive ( )
override

Definition at line 100 of file HGCalTBPassive.cc.

100 {}

Member Function Documentation

◆ endOfEvent()

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

Definition at line 214 of file HGCalTBPassive.cc.

References dqmdumpme::first, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, isotrackApplyRegressor::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") << "HGCalTBPassive[" << 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_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_

◆ findLV()

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

Definition at line 239 of file HGCalTBPassive.cc.

References isotrackApplyRegressor::k, LVNames_, mapLV_, motherName_, mergeVDriftHistosByStation::name, DD4hep2DDDName::noNameSpace(), AlCaHLTBitMon_QueryRunRegistry::string, and topLV_.

Referenced by update().

239  {
240  auto itr = mapLV_.find(plv);
241  if (itr == mapLV_.end()) {
242  std::string name = DD4hep2DDDName::noNameSpace(static_cast<std::string>(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 (DD4hep2DDDName::noNameSpace(static_cast<std::string>(plv->GetName())) == motherName_)
253  topLV_ = plv;
254  }
255  return itr;
256 }
G4LogicalVolume * topLV_
const std::vector< std::string > LVNames_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
const std::string motherName_
std::string noNameSpace(const std::string &name)

◆ getTopPV()

G4VPhysicalVolume * HGCalTBPassive::getTopPV ( )
private

Definition at line 235 of file HGCalTBPassive.cc.

Referenced by update().

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

◆ operator=()

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

◆ produce()

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

Implements SimProducer.

Definition at line 102 of file HGCalTBPassive.cc.

References MillePedeFileConverter_cfg::e, endOfEvent(), isotrackApplyRegressor::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)
std::vector< PassiveHit > PassiveHitContainer
Definition: PassiveHit.h:100
const std::vector< std::string > LVNames_
def move(src, dest)
Definition: eostools.py:511

◆ storeInfo()

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

Definition at line 258 of file HGCalTBPassive.cc.

References filterCSVwithJSON::copy, HBHEDarkening_cff::energy, dqmdumpme::first, RemoveAddSevLevel::flag, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, submitPVResolutionJobs::key, store_, and hcalRecHitTable_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") << "HGCalTBPassive: 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_
key
prepare the HTCondor submission files and eventually submit them

◆ update() [1/3]

void HGCalTBPassive::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 110 of file HGCalTBPassive.cc.

References findLV(), dqmdumpme::first, getTopPV(), init_, isotrackApplyRegressor::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") << "HGCalTBPassive::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
G4VPhysicalVolume * getTopPV()
volumeIterator findLV(G4LogicalVolume *plv)
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
G4VPhysicalVolume * topPV_
Log< level::Warning, false > LogWarning

◆ update() [2/3]

void HGCalTBPassive::update ( const BeginOfEvent )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 134 of file HGCalTBPassive.cc.

References count_, caHitNtupletGeneratorKernels::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") << "HGCalTBPassive: =====> Begin event = " << iev << std::endl;
137 
138  ++count_;
139  store_.clear();
140 }
Log< level::Info, true > LogVerbatim
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
unsigned int count_

◆ update() [3/3]

void HGCalTBPassive::update ( const G4Step *  )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step *>.

Definition at line 144 of file HGCalTBPassive.cc.

References filterCSVwithJSON::copy, HBHEDarkening_cff::energy, findLV(), mps_fire::i, init_, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, gammaJetAnalysis_CHSJECs_cff::level, mapLV_, DD4hep2DDDName::noNameSpace(), storeInfo(), hcalRecHitTable_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") << DD4hep2DDDName::noNameSpace(static_cast<std::string>(plv->GetName()))
161  << " F|L Step " << aStep->IsFirstStepInVolume() << ":" << aStep->IsLastStepInVolume()
162  << " Position" << 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  << DD4hep2DDDName::noNameSpace(static_cast<std::string>(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
volumeIterator findLV(G4LogicalVolume *plv)
G4LogicalVolume * topLV_
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 > > mapLV_
std::string noNameSpace(const std::string &name)

Member Data Documentation

◆ addlevel_

const int HGCalTBPassive::addlevel_
private

Definition at line 67 of file HGCalTBPassive.cc.

Referenced by HGCalTBPassive().

◆ count_

unsigned int HGCalTBPassive::count_
private

Definition at line 73 of file HGCalTBPassive.cc.

Referenced by update().

◆ init_

bool HGCalTBPassive::init_
private

Definition at line 74 of file HGCalTBPassive.cc.

Referenced by update().

◆ LVNames_

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

Definition at line 65 of file HGCalTBPassive.cc.

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

◆ m_Passive

const edm::ParameterSet HGCalTBPassive::m_Passive
private

Definition at line 64 of file HGCalTBPassive.cc.

◆ mapLV_

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

Definition at line 70 of file HGCalTBPassive.cc.

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

◆ motherName_

const std::string HGCalTBPassive::motherName_
private

Definition at line 66 of file HGCalTBPassive.cc.

Referenced by findLV(), and HGCalTBPassive().

◆ store_

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

Definition at line 75 of file HGCalTBPassive.cc.

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

◆ topLV_

G4LogicalVolume* HGCalTBPassive::topLV_
private

Definition at line 69 of file HGCalTBPassive.cc.

Referenced by findLV(), and update().

◆ topPV_

G4VPhysicalVolume* HGCalTBPassive::topPV_
private

Definition at line 68 of file HGCalTBPassive.cc.

Referenced by update().