CMS 3D CMS Logo

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

Public Member Functions

const SimG4FluxProduceroperator= (const SimG4FluxProducer &)=delete
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 SimG4FluxProducer (const edm::ParameterSet &p)
 
 SimG4FluxProducer (const SimG4FluxProducer &)=delete
 
 ~SimG4FluxProducer () 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 Member Functions

void endOfEvent (ParticleFlux &pflx, unsigned int k)
 
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator findLV (G4LogicalVolume *plv)
 
G4VPhysicalVolume * getTopPV ()
 
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

unsigned int count_
 
bool init_
 
std::vector< std::string > LVNames_
 
std::vector< int > LVTypes_
 
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
 
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFluxstore_
 
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 35 of file SimG4FluxProducer.cc.

Constructor & Destructor Documentation

◆ SimG4FluxProducer() [1/2]

SimG4FluxProducer::SimG4FluxProducer ( const edm::ParameterSet p)

Definition at line 68 of file SimG4FluxProducer.cc.

References edm::ParameterSet::getUntrackedParameter(), dqmdumpme::k, LVNames_, LVTypes_, and AlCaHLTBitMon_ParallelJobs::p.

68  : count_(0), init_(false) {
69  edm::ParameterSet m_FP = p.getParameter<edm::ParameterSet>("SimG4FluxProducer");
70  LVNames_ = m_FP.getUntrackedParameter<std::vector<std::string>>("LVNames");
71  LVTypes_ = m_FP.getUntrackedParameter<std::vector<int>>("LVTypes");
72 
73  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
74  produces<ParticleFlux>(Form("%sParticleFlux", LVNames_[k].c_str()));
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("SimG4FluxProducer")
77  << "SimG4FluxProducer::Collection name[" << k << "] ParticleFlux" << LVNames_[k] << " and type " << LVTypes_[k];
78 #endif
79  }
80 }
Log< level::Info, true > LogVerbatim
std::vector< int > LVTypes_
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > LVNames_

◆ SimG4FluxProducer() [2/2]

SimG4FluxProducer::SimG4FluxProducer ( const SimG4FluxProducer )
delete

◆ ~SimG4FluxProducer()

SimG4FluxProducer::~SimG4FluxProducer ( )
override

Definition at line 82 of file SimG4FluxProducer.cc.

82 {}

Member Function Documentation

◆ endOfEvent()

void SimG4FluxProducer::endOfEvent ( ParticleFlux pflx,
unsigned int  k 
)
private

Definition at line 171 of file SimG4FluxProducer.cc.

References fileCollector::done, first, ParticleFlux::getComponents(), ParticleFlux::getFlux(), ParticleFlux::getId(), ParticleFlux::getName(), dqmdumpme::k, mapLV_, and store_.

Referenced by produce().

171  {
172  bool done(false);
173  for (const auto &element : store_) {
174  G4LogicalVolume *lv = (element.first).first;
175  auto it = mapLV_.find(lv);
176  if (it != mapLV_.end()) {
177  if ((it->second).first == k) {
178  flux = element.second;
179  done = true;
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("SimG4FluxProducer") << "SimG4FluxProducer[" << k << "] Flux " << flux.getName() << ":"
182  << flux.getId() << " with " << flux.getComponents() << " elements";
183  std::vector<ParticleFlux::flux> fluxes = flux.getFlux();
184  unsigned int k(0);
185  for (auto element : fluxes) {
186  edm::LogVerbatim("SimG4FluxProducer")
187  << "Flux[" << k << "] PDGId " << element.pdgId << " VT " << element.vxType << " ToF " << element.tof
188  << " Vertex " << element.vertex << " Hit " << element.hitPoint << " p " << element.momentum;
189  ++k;
190  }
191 #endif
192  }
193  }
194  if (done)
195  break;
196  }
197 }
Log< level::Info, true > LogVerbatim
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_

◆ findLV()

std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator SimG4FluxProducer::findLV ( G4LogicalVolume *  plv)
private

Definition at line 203 of file SimG4FluxProducer.cc.

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

Referenced by update().

204  {
205  auto itr = mapLV_.find(plv);
206  if (itr == mapLV_.end()) {
207  std::string name = plv->GetName();
208  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
209  if (name.find(LVNames_[k]) != std::string::npos) {
210  mapLV_[plv] = std::pair<unsigned int, std::string>(k, name);
211  itr = mapLV_.find(plv);
212  break;
213  }
214  }
215  }
216  return itr;
217 }
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
std::vector< std::string > LVNames_

◆ getTopPV()

G4VPhysicalVolume * SimG4FluxProducer::getTopPV ( )
private

Definition at line 199 of file SimG4FluxProducer.cc.

Referenced by update().

199  {
200  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
201 }

◆ operator=()

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

◆ produce()

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

Implements SimProducer.

Definition at line 84 of file SimG4FluxProducer.cc.

References MillePedeFileConverter_cfg::e, endOfEvent(), dqmdumpme::k, LVNames_, eostools::move(), Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

84  {
85 #ifdef EDM_ML_DEBUG
86  edm::LogVerbatim("SimG4FluxProducer") << "SimG4FluxProducer: enters produce with " << LVNames_.size() << " LV's";
87 #endif
88  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
89  std::unique_ptr<ParticleFlux> pflux(new ParticleFlux);
90  endOfEvent(*pflux, k);
91  std::string name = LVNames_[k] + "ParticleFlux";
92  e.put(std::move(pflux), name);
93  }
94 }
Log< level::Info, true > LogVerbatim
std::vector< std::string > LVNames_
void endOfEvent(ParticleFlux &pflx, unsigned int k)
def move(src, dest)
Definition: eostools.py:511

◆ update() [1/3]

void SimG4FluxProducer::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 96 of file SimG4FluxProducer.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().

96  {
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("SimG4FluxProducer") << "SimG4FluxProducer: enters BeginOfRun";
99 #endif
100  topPV_ = getTopPV();
101  if (topPV_ == nullptr) {
102  edm::LogWarning("SimG4FluxProducer") << "Cannot find top level volume\n";
103  } else {
104  init_ = true;
105  const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
106  for (auto lvcite : *lvs) {
107  findLV(lvcite);
108  }
109 
110 #ifdef EDM_ML_DEBUG
111  edm::LogVerbatim("SimG4FluxProducer") << "SimG4FluxProducer::Finds " << mapLV_.size() << " logical volumes";
112  unsigned int k(0);
113  for (const auto &lvs : mapLV_) {
114  edm::LogVerbatim("SimG4FluxProducer")
115  << "Entry[" << k << "] " << lvs.first << ": (" << (lvs.second).first << ", " << (lvs.second).second << ")";
116  ++k;
117  }
118 #endif
119  }
120 }
Log< level::Info, true > LogVerbatim
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
G4VPhysicalVolume * topPV_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator findLV(G4LogicalVolume *plv)
G4VPhysicalVolume * getTopPV()
Log< level::Warning, false > LogWarning

◆ update() [2/3]

void SimG4FluxProducer::update ( const BeginOfEvent )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 122 of file SimG4FluxProducer.cc.

References count_, iev, and store_.

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

122  {
123  int iev = (*evt)()->GetEventID();
124  edm::LogVerbatim("SimG4FluxProducer") << "SimG4FluxProducer: =====> Begin event = " << iev;
125  ++count_;
126  store_.clear();
127 }
Log< level::Info, true > LogVerbatim
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int32_t int iev
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_

◆ update() [3/3]

void SimG4FluxProducer::update ( const G4Step *  )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step *>.

Definition at line 129 of file SimG4FluxProducer.cc.

References filterCSVwithJSON::copy, findLV(), first, ParticleFlux::flux::hitPoint, init_, createfilelist::int, crabWrapper::key, LVTypes_, mapLV_, ParticleFlux::flux::momentum, EgammaValidation_cff::pdgid, store_, protons_cff::time, HLT_2022v15_cff::track, and ParticleFlux::flux::vertex.

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

129  {
130  if (aStep != nullptr) {
131  G4TouchableHistory *touchable = (G4TouchableHistory *)aStep->GetPreStepPoint()->GetTouchable();
132  G4LogicalVolume *plv = (G4LogicalVolume *)touchable->GetVolume()->GetLogicalVolume();
133  auto it = (init_) ? mapLV_.find(plv) : findLV(plv);
134  // edm::LogVerbatim("SimG4FluxProducer") << plv->GetName() << " Flag " << (it != mapLV_.end()) << " step " << aStep->IsFirstStepInVolume() << ":" << aStep->IsLastStepInVolume();
135  if (it != mapLV_.end()) {
136  int type = LVTypes_[(it->second).first];
137  if ((type == 0 && aStep->IsFirstStepInVolume()) || (type == 1 && aStep->IsLastStepInVolume())) {
138  unsigned int copy = (unsigned int)(touchable->GetReplicaNumber(0));
139  std::pair<G4LogicalVolume *, unsigned int> key(plv, copy);
140  auto itr = store_.find(key);
141  if (itr == store_.end()) {
142  store_[key] = ParticleFlux((it->second).second, copy);
143  itr = store_.find(key);
144  }
145  G4Track *track = aStep->GetTrack();
146  int pdgid = track->GetDefinition()->GetPDGEncoding();
147  int vxtyp = (track->GetCreatorProcess() == nullptr) ? 0 : 1;
148  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
149  const double mmTocm(0.1), MeVToGeV(0.001);
150  ParticleFlux::flux flx(pdgid, vxtyp, time);
151  flx.vertex = math::GlobalPoint(mmTocm * track->GetVertexPosition().x(),
152  mmTocm * track->GetVertexPosition().y(),
153  mmTocm * track->GetVertexPosition().z());
154  flx.hitPoint = math::GlobalPoint(
155  mmTocm * track->GetPosition().x(), mmTocm * track->GetPosition().y(), mmTocm * track->GetPosition().z());
156  flx.momentum = math::GlobalVector(MeVToGeV * track->GetMomentum().x(),
157  MeVToGeV * track->GetMomentum().y(),
158  MeVToGeV * track->GetMomentum().z());
159  (itr->second).addFlux(flx);
160 #ifdef EDM_ML_DEBUG
161  edm::LogVerbatim("SimG4FluxProducer")
162  << "SimG4FluxProducer: Element " << (it->second).first << ":" << (it->second).second << ":" << copy
163  << " ID " << pdgid << " VxType " << vxtyp << " TOF " << time << " Hit Point " << flx.hitPoint << " p "
164  << flx.momentum << " Vertex " << flx.vertex;
165 #endif
166  } //if(Step ok)
167  } //if( it != map.end() )
168  } //if (aStep != NULL)
169 }
Log< level::Info, true > LogVerbatim
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
std::vector< int > LVTypes_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator findLV(G4LogicalVolume *plv)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
Definition: Vector3D.h:28
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_

Member Data Documentation

◆ count_

unsigned int SimG4FluxProducer::count_
private

Definition at line 63 of file SimG4FluxProducer.cc.

Referenced by update().

◆ init_

bool SimG4FluxProducer::init_
private

Definition at line 64 of file SimG4FluxProducer.cc.

Referenced by update().

◆ LVNames_

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

Definition at line 57 of file SimG4FluxProducer.cc.

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

◆ LVTypes_

std::vector<int> SimG4FluxProducer::LVTypes_
private

Definition at line 58 of file SimG4FluxProducer.cc.

Referenced by SimG4FluxProducer(), and update().

◆ mapLV_

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

Definition at line 60 of file SimG4FluxProducer.cc.

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

◆ store_

std::map<std::pair<G4LogicalVolume *, unsigned int>, ParticleFlux> SimG4FluxProducer::store_
private

Definition at line 65 of file SimG4FluxProducer.cc.

Referenced by endOfEvent(), and update().

◆ topPV_

G4VPhysicalVolume* SimG4FluxProducer::topPV_
private

Definition at line 59 of file SimG4FluxProducer.cc.

Referenced by update().