CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SimG4FluxProducer Class Reference

#include <SimG4FluxProducer.h>

Inheritance diagram for SimG4FluxProducer:
SimProducer Observer< const BeginOfRun * > Observer< const BeginOfEvent * > Observer< const G4Step * > SimWatcher

Public Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 
 SimG4FluxProducer (const edm::ParameterSet &p)
 
 ~SimG4FluxProducer () override
 
- Public Member Functions inherited from SimProducer
void registerProducts (edm::ProducesCollector producesCollector)
 
 SimProducer ()
 
- Public Member Functions inherited from SimWatcher
 SimWatcher ()
 
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 ()
 
const SimG4FluxProduceroperator= (const SimG4FluxProducer &)=delete
 
 SimG4FluxProducer (const SimG4FluxProducer &)=delete
 
void update (const BeginOfEvent *evt) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfRun *run) 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)
 

Detailed Description

Definition at line 25 of file SimG4FluxProducer.h.

Constructor & Destructor Documentation

◆ SimG4FluxProducer() [1/2]

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

Definition at line 18 of file SimG4FluxProducer.cc.

18  : count_(0), init_(false) {
19  edm::ParameterSet m_FP = p.getParameter<edm::ParameterSet>("SimG4FluxProducer");
20  LVNames_ = m_FP.getUntrackedParameter<std::vector<std::string>>("LVNames");
21  LVTypes_ = m_FP.getUntrackedParameter<std::vector<int>>("LVTypes");
22 
23  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
24  produces<ParticleFlux>(Form("%sParticleFlux", LVNames_[k].c_str()));
25 #ifdef EDM_ML_DEBUG
26  std::cout << "Collection name[" << k << "] ParticleFlux" << LVNames_[k] << " and type " << LVTypes_[k] << std::endl;
27 #endif
28  }
29 }

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

◆ ~SimG4FluxProducer()

SimG4FluxProducer::~SimG4FluxProducer ( )
override

Definition at line 31 of file SimG4FluxProducer.cc.

31 {}

◆ SimG4FluxProducer() [2/2]

SimG4FluxProducer::SimG4FluxProducer ( const SimG4FluxProducer )
privatedelete

Member Function Documentation

◆ endOfEvent()

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

Definition at line 113 of file SimG4FluxProducer.cc.

113  {
114  bool done(false);
115  for (const auto& element : store_) {
116  G4LogicalVolume* lv = (element.first).first;
117  auto it = mapLV_.find(lv);
118  if (it != mapLV_.end()) {
119  if ((it->second).first == k) {
120  flux = element.second;
121  done = true;
122 #ifdef EDM_ML_DEBUG
123  std::cout << "SimG4FluxProducer[" << k << "] Flux " << flux.getName() << ":" << flux.getId() << " with "
124  << flux.getComponents() << " elements" << std::endl;
125  std::vector<ParticleFlux::flux> fluxes = flux.getFlux();
126  unsigned int k(0);
127  for (auto element : fluxes) {
128  std::cout << "Flux[" << k << "] PDGId " << element.pdgId << " VT " << element.vxType << " ToF " << element.tof
129  << " Vertex " << element.vertex << " Hit " << element.hitPoint << " p " << element.momentum
130  << std::endl;
131  ++k;
132  }
133 #endif
134  }
135  }
136  if (done)
137  break;
138  }
139 }

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

Referenced by produce().

◆ findLV()

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

Definition at line 145 of file SimG4FluxProducer.cc.

146  {
147  auto itr = mapLV_.find(plv);
148  if (itr == mapLV_.end()) {
149  std::string name = plv->GetName();
150  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
151  if (name.find(LVNames_[k]) != std::string::npos) {
152  mapLV_[plv] = std::pair<unsigned int, std::string>(k, name);
153  itr = mapLV_.find(plv);
154  break;
155  }
156  }
157  }
158  return itr;
159 }

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

Referenced by update().

◆ getTopPV()

G4VPhysicalVolume * SimG4FluxProducer::getTopPV ( )
private

Definition at line 141 of file SimG4FluxProducer.cc.

141  {
142  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
143 }

Referenced by update().

◆ operator=()

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

◆ produce()

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

Implements SimProducer.

Definition at line 33 of file SimG4FluxProducer.cc.

33  {
34  for (unsigned int k = 0; k < LVNames_.size(); ++k) {
35  std::unique_ptr<ParticleFlux> pflux(new ParticleFlux);
36  endOfEvent(*pflux, k);
37  std::string name = LVNames_[k] + "ParticleFlux";
38  e.put(std::move(pflux), name);
39  }
40 }

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

◆ update() [1/3]

void SimG4FluxProducer::update ( const BeginOfEvent )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 65 of file SimG4FluxProducer.cc.

65  {
66  int iev = (*evt)()->GetEventID();
67  edm::LogInfo("ValidHGCal") << "SimG4FluxProducer: =====> Begin event = " << iev << std::endl;
68  ++count_;
69  store_.clear();
70 }

References count_, and store_.

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

◆ update() [2/3]

void SimG4FluxProducer::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 42 of file SimG4FluxProducer.cc.

42  {
43  topPV_ = getTopPV();
44  if (topPV_ == nullptr) {
45  edm::LogWarning("SimG4FluxProducer") << "Cannot find top level volume\n";
46  } else {
47  init_ = true;
48  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
49  for (auto lvcite : *lvs) {
50  findLV(lvcite);
51  }
52 
53 #ifdef EDM_ML_DEBUG
54  std::cout << "SimG4FluxProducer::Finds " << mapLV_.size() << " logical volumes\n";
55  unsigned int k(0);
56  for (const auto& lvs : mapLV_) {
57  std::cout << "Entry[" << k << "] " << lvs.first << ": (" << (lvs.second).first << ", " << (lvs.second).second
58  << ")\n";
59  ++k;
60  }
61 #endif
62  }
63 }

References gather_cfg::cout, findLV(), dqmdumpme::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().

◆ 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 72 of file SimG4FluxProducer.cc.

72  {
73  if (aStep != nullptr) {
74  G4TouchableHistory* touchable = (G4TouchableHistory*)aStep->GetPreStepPoint()->GetTouchable();
75  G4LogicalVolume* plv = (G4LogicalVolume*)touchable->GetVolume()->GetLogicalVolume();
76  auto it = (init_) ? mapLV_.find(plv) : findLV(plv);
77  // std::cout << plv->GetName() << " Flag " << (it != mapLV_.end()) << " step " << aStep->IsFirstStepInVolume() << ":" << aStep->IsLastStepInVolume() << std::endl;
78  if (it != mapLV_.end()) {
79  int type = LVTypes_[(it->second).first];
80  if ((type == 0 && aStep->IsFirstStepInVolume()) || (type == 1 && aStep->IsLastStepInVolume())) {
81  unsigned int copy = (unsigned int)(touchable->GetReplicaNumber(0));
82  std::pair<G4LogicalVolume*, unsigned int> key(plv, copy);
83  auto itr = store_.find(key);
84  if (itr == store_.end()) {
85  store_[key] = ParticleFlux((it->second).second, copy);
86  itr = store_.find(key);
87  }
88  G4Track* track = aStep->GetTrack();
89  int pdgid = track->GetDefinition()->GetPDGEncoding();
90  int vxtyp = (track->GetCreatorProcess() == nullptr) ? 0 : 1;
91  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
92  const double mmTocm(0.1), MeVToGeV(0.001);
93  ParticleFlux::flux flx(pdgid, vxtyp, time);
94  flx.vertex = math::GlobalPoint(mmTocm * track->GetVertexPosition().x(),
95  mmTocm * track->GetVertexPosition().y(),
96  mmTocm * track->GetVertexPosition().z());
97  flx.hitPoint = math::GlobalPoint(
98  mmTocm * track->GetPosition().x(), mmTocm * track->GetPosition().y(), mmTocm * track->GetPosition().z());
99  flx.momentum = math::GlobalVector(MeVToGeV * track->GetMomentum().x(),
100  MeVToGeV * track->GetMomentum().y(),
101  MeVToGeV * track->GetMomentum().z());
102  (itr->second).addFlux(flx);
103 #ifdef EDM_ML_DEBUG
104  std::cout << "SimG4FluxProducer: Element " << (it->second).first << ":" << (it->second).second << ":" << copy
105  << " ID " << pdgid << " VxType " << vxtyp << " TOF " << time << " Hit Point " << flx.hitPoint << " p "
106  << flx.momentum << " Vertex " << flx.vertex << std::endl;
107 #endif
108  } //if(Step ok)
109  } //if( it != map.end() )
110  } //if (aStep != NULL)
111 }

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

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

Member Data Documentation

◆ count_

unsigned int SimG4FluxProducer::count_
private

Definition at line 55 of file SimG4FluxProducer.h.

Referenced by update().

◆ init_

bool SimG4FluxProducer::init_
private

Definition at line 56 of file SimG4FluxProducer.h.

Referenced by update().

◆ LVNames_

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

Definition at line 49 of file SimG4FluxProducer.h.

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

◆ LVTypes_

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

Definition at line 50 of file SimG4FluxProducer.h.

Referenced by SimG4FluxProducer(), and update().

◆ mapLV_

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

Definition at line 52 of file SimG4FluxProducer.h.

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

◆ store_

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

Definition at line 57 of file SimG4FluxProducer.h.

Referenced by endOfEvent(), and update().

◆ topPV_

G4VPhysicalVolume* SimG4FluxProducer::topPV_
private

Definition at line 51 of file SimG4FluxProducer.h.

Referenced by update().

SimG4FluxProducer::topPV_
G4VPhysicalVolume * topPV_
Definition: SimG4FluxProducer.h:51
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
SimG4FluxProducer::count_
unsigned int count_
Definition: SimG4FluxProducer.h:55
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SimG4FluxProducer::LVTypes_
std::vector< int > LVTypes_
Definition: SimG4FluxProducer.h:50
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SimG4FluxProducer::findLV
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator findLV(G4LogicalVolume *plv)
Definition: SimG4FluxProducer.cc:145
SimG4FluxProducer::getTopPV
G4VPhysicalVolume * getTopPV()
Definition: SimG4FluxProducer.cc:141
fileCollector.done
done
Definition: fileCollector.py:123
dqmdumpme.k
k
Definition: dqmdumpme.py:60
SimG4FluxProducer::endOfEvent
void endOfEvent(ParticleFlux &pflx, unsigned int k)
Definition: SimG4FluxProducer.cc:113
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SimG4FluxProducer::LVNames_
std::vector< std::string > LVNames_
Definition: SimG4FluxProducer.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
math::GlobalVector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalVector
vector in glovbal coordinate system
Definition: Vector3D.h:28
SimG4FluxProducer::init_
bool init_
Definition: SimG4FluxProducer.h:56
createfilelist.int
int
Definition: createfilelist.py:10
ParticleFlux
Definition: ParticleFlux.h:11
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
eostools.move
def move(src, dest)
Definition: eostools.py:511
ParticleFlux::flux
Definition: ParticleFlux.h:16
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
math::GlobalPoint
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:18
ntuplemaker.time
time
Definition: ntuplemaker.py:310
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:30
crabWrapper.key
key
Definition: crabWrapper.py:19
SimG4FluxProducer::store_
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
Definition: SimG4FluxProducer.h:57
SimG4FluxProducer::mapLV_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
Definition: SimG4FluxProducer.h:52
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37