CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

int addlevel_
 
unsigned int count_
 
bool init_
 
std::vector< std::string > LVNames_
 
std::map< G4LogicalVolume
*, std::pair< unsigned int,
std::string > > 
mapLV_
 
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

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::HGCPassive ( const edm::ParameterSet p)

Definition at line 77 of file HGCPassive.cc.

References addlevel_, dd4hep_cff::dd4hep, edm::ParameterSet::getParameter(), isotrackApplyRegressor::k, LVNames_, motherName_, mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 97 of file HGCPassive.cc.

97 {}

Member Function Documentation

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

Definition at line 211 of file HGCPassive.cc.

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

Referenced by produce().

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

Definition at line 236 of file HGCPassive.cc.

References isotrackApplyRegressor::k, LVNames_, mapLV_, motherName_, mergeVDriftHistosByStation::name, AlCaHLTBitMon_QueryRunRegistry::string, and topLV_.

Referenced by update().

236  {
237  auto itr = mapLV_.find(plv);
238  if (itr == mapLV_.end()) {
239  std::string name = static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName()));
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);
243  itr = mapLV_.find(plv);
244  break;
245  }
246  }
247  }
248  if (topLV_ == nullptr) {
249  if (static_cast<std::string>(dd4hep::dd::noNamespace(plv->GetName())) == motherName_)
250  topLV_ = plv;
251  }
252  return itr;
253 }
G4LogicalVolume * topLV_
Definition: HGCPassive.cc:66
std::vector< std::string > LVNames_
Definition: HGCPassive.cc:64
std::string motherName_
Definition: HGCPassive.cc:68
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: HGCPassive.cc:67
G4VPhysicalVolume * HGCPassive::getTopPV ( )
private

Definition at line 232 of file HGCPassive.cc.

Referenced by update().

232  {
233  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
234 }
const HGCPassive& HGCPassive::operator= ( const HGCPassive )
delete
void HGCPassive::produce ( edm::Event e,
const edm::EventSetup  
)
overridevirtual

Implements SimProducer.

Definition at line 99 of file HGCPassive.cc.

References endOfEvent(), isotrackApplyRegressor::k, LVNames_, eostools::move(), and edm::Event::put().

99  {
100  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
101  std::unique_ptr<edm::PassiveHitContainer> hgcPH(new edm::PassiveHitContainer);
102  endOfEvent(*hgcPH, k);
103  e.put(std::move(hgcPH), Form("%sPassiveHits", LVNames_[k].c_str()));
104  }
105 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void endOfEvent(edm::PassiveHitContainer &hgcPH, unsigned int k)
Definition: HGCPassive.cc:211
std::vector< std::string > LVNames_
Definition: HGCPassive.cc:64
def move
Definition: eostools.py:511
std::vector< PassiveHit > PassiveHitContainer
Definition: PassiveHit.h:100
void HGCPassive::storeInfo ( const volumeIterator  itr,
G4LogicalVolume *  plv,
unsigned int  copy,
double  time,
double  energy,
bool  flag 
)
private

Definition at line 255 of file HGCPassive.cc.

References relval_parameters_module::energy, first, submitPVResolutionJobs::key, and store_.

Referenced by update().

260  {
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()) {
265  store_[key] = {{time, energy, energy}};
266  } else {
267  (itr->second)[1] += ee;
268  (itr->second)[2] += energy;
269  }
270 #ifdef EDM_ML_DEBUG
271  itr = store_.find(key);
272  edm::LogVerbatim("HGCSim") << "HGCPassive: Element " << (it->second).first << ":" << (it->second).second << ":"
273  << copy << " T " << (itr->second)[0] << " E " << (itr->second)[1] << ":"
274  << (itr->second)[2];
275 #endif
276 }
Log< level::Info, true > LogVerbatim
tuple key
prepare the HTCondor submission files and eventually submit them
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
Definition: HGCPassive.cc:74
void HGCPassive::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 107 of file HGCPassive.cc.

References findLV(), 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().

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

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 131 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().

131  {
132  int iev = (*evt)()->GetEventID();
133  edm::LogVerbatim("HGCSim") << "HGCPassive: =====> Begin event = " << iev << std::endl;
134 
135  ++count_;
136  store_.clear();
137 }
Log< level::Info, true > LogVerbatim
unsigned int count_
Definition: HGCPassive.cc:72
std::map< std::pair< G4LogicalVolume *, unsigned int >, std::array< double, 3 > > store_
Definition: HGCPassive.cc:74
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int iev
void HGCPassive::update ( const G4Step *  )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 141 of file HGCPassive.cc.

References filterCSVwithJSON::copy, relval_parameters_module::energy, findLV(), GeV, mps_fire::i, init_, testEve_cfg::level, mapLV_, storeInfo(), AlCaHLTBitMon_QueryRunRegistry::string, and topLV_.

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

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

Member Data Documentation

int HGCPassive::addlevel_
private

Definition at line 69 of file HGCPassive.cc.

Referenced by HGCPassive().

unsigned int HGCPassive::count_
private

Definition at line 72 of file HGCPassive.cc.

Referenced by update().

bool HGCPassive::init_
private

Definition at line 73 of file HGCPassive.cc.

Referenced by update().

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

Definition at line 64 of file HGCPassive.cc.

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

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

Definition at line 67 of file HGCPassive.cc.

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

std::string HGCPassive::motherName_
private

Definition at line 68 of file HGCPassive.cc.

Referenced by findLV(), and HGCPassive().

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

Definition at line 74 of file HGCPassive.cc.

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

G4LogicalVolume* HGCPassive::topLV_
private

Definition at line 66 of file HGCPassive.cc.

Referenced by findLV(), and update().

G4VPhysicalVolume* HGCPassive::topPV_
private

Definition at line 65 of file HGCPassive.cc.

Referenced by update().