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 &)
 
 SimG4FluxProducer (const edm::ParameterSet &p)
 
virtual ~SimG4FluxProducer ()
 
- Public Member Functions inherited from SimProducer
void registerProducts (edm::ProducerBase &iProd)
 
 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 &)
 
 SimG4FluxProducer (const SimG4FluxProducer &)
 
void update (const BeginOfRun *run)
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfEvent *evt)
 This routine will be called when the appropriate signal arrives. More...
 
void update (const G4Step *step)
 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::SimG4FluxProducer ( const edm::ParameterSet p)

Definition at line 18 of file SimG4FluxProducer.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), gen::k, LVNames_, and LVTypes_.

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

Definition at line 33 of file SimG4FluxProducer.cc.

33 { }
SimG4FluxProducer::SimG4FluxProducer ( const SimG4FluxProducer )
private

Member Function Documentation

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

Definition at line 126 of file SimG4FluxProducer.cc.

References gather_cfg::cout, plotBeamSpotDB::first, ParticleFlux::getComponents(), ParticleFlux::getFlux(), ParticleFlux::getId(), ParticleFlux::getName(), gen::k, mapLV_, and store_.

Referenced by produce().

126  {
127 
128  bool done(false);
129  for (const auto& element : store_) {
130  G4LogicalVolume* lv = (element.first).first;
131  auto it = mapLV_.find(lv);
132  if (it != mapLV_.end()) {
133  if ((it->second).first == k) {
134  flux = element.second;
135  done = true;
136 #ifdef EDM_ML_DEBUG
137  std::cout << "SimG4FluxProducer[" << k << "] Flux " << flux.getName()
138  << ":" << flux.getId() << " with " << flux.getComponents()
139  << " elements" << std::endl;
140  std::vector<ParticleFlux::flux> fluxes = flux.getFlux() ;
141  unsigned int k(0);
142  for (auto element : fluxes) {
143  std::cout << "Flux[" << k << "] PDGId " << element.pdgId << " VT "
144  << element.vxType << " ToF " << element.tof << " Vertex "
145  << element.vertex << " Hit " << element.hitPoint << " p "
146  << element.momentum << std::endl;
147  ++k;
148  }
149 #endif
150  }
151  }
152  if (done) break;
153  }
154 }
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
int k[5][pyjets_maxn]
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > >::iterator SimG4FluxProducer::findLV ( G4LogicalVolume *  plv)
private

Definition at line 160 of file SimG4FluxProducer.cc.

References gen::k, LVNames_, mapLV_, dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by update().

160  {
161  auto itr = mapLV_.find(plv);
162  if (itr == mapLV_.end()) {
163  std::string name = plv->GetName();
164  for (unsigned int k=0; k<LVNames_.size(); ++k) {
165  if (name.find(LVNames_[k]) != std::string::npos) {
166  mapLV_[plv] = std::pair<unsigned int,std::string>(k,name);
167  itr = mapLV_.find(plv);
168  break;
169  }
170  }
171  }
172  return itr;
173 }
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
std::vector< std::string > LVNames_
int k[5][pyjets_maxn]
G4VPhysicalVolume * SimG4FluxProducer::getTopPV ( )
private

Definition at line 156 of file SimG4FluxProducer.cc.

Referenced by update().

156  {
157  return G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
158 }
const SimG4FluxProducer& SimG4FluxProducer::operator= ( const SimG4FluxProducer )
private
void SimG4FluxProducer::produce ( edm::Event e,
const edm::EventSetup  
)
virtual

Implements SimProducer.

Definition at line 35 of file SimG4FluxProducer.cc.

References endOfEvent(), gen::k, LVNames_, eostools::move(), dataset::name, edm::Event::put(), and AlCaHLTBitMon_QueryRunRegistry::string.

35  {
36 
37  for (unsigned int k=0; k<LVNames_.size(); ++k) {
38  std::unique_ptr<ParticleFlux> pflux(new ParticleFlux);
39  endOfEvent(*pflux, k);
40  std::string name = LVNames_[k] + "ParticleFlux";
41  e.put(std::move(pflux),name);
42  }
43 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
std::vector< std::string > LVNames_
int k[5][pyjets_maxn]
void endOfEvent(ParticleFlux &pflx, unsigned int k)
def move(src, dest)
Definition: eostools.py:510
void SimG4FluxProducer::update ( const BeginOfRun )
privatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 45 of file SimG4FluxProducer.cc.

References gather_cfg::cout, findLV(), plotBeamSpotDB::first, getTopPV(), init_, gen::k, mapLV_, and topPV_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

45  {
46 
47  topPV_ = getTopPV();
48  if (topPV_ == 0) {
49  edm::LogWarning("SimG4FluxProducer") << "Cannot find top level volume\n";
50  } else {
51  init_ = true;
52  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
53  for (auto lvcite : *lvs) {
54  findLV(lvcite);
55  }
56 
57 #ifdef EDM_ML_DEBUG
58  std::cout << "SimG4FluxProducer::Finds " << mapLV_.size() << " logical volumes\n";
59  unsigned int k(0);
60  for (const auto& lvs : mapLV_) {
61  std::cout << "Entry[" << k << "] " << lvs.first << ": ("
62  << (lvs.second).first << ", " << (lvs.second).second << ")\n";
63  ++k;
64  }
65 #endif
66  }
67 }
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()
int k[5][pyjets_maxn]
void SimG4FluxProducer::update ( const BeginOfEvent )
privatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 69 of file SimG4FluxProducer.cc.

References count_, and store_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

69  {
70 
71  int iev = (*evt)()->GetEventID();
72  edm::LogInfo("ValidHGCal") << "SimG4FluxProducer: =====> Begin event = "
73  << iev << std::endl;
74  ++count_;
75  store_.clear();
76 }
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
void SimG4FluxProducer::update ( const G4Step *  )
privatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 78 of file SimG4FluxProducer.cc.

References popcon2dropbox::copy(), gather_cfg::cout, findLV(), plotBeamSpotDB::first, ParticleFlux::flux::hitPoint, init_, createfilelist::int, crabWrapper::key, LVTypes_, mapLV_, ParticleFlux::flux::momentum, NULL, BPhysicsValidation_cfi::pdgid, store_, ntuplemaker::time, HiIsolationCommonParameters_cff::track, and ParticleFlux::flux::vertex.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

78  {
79 
80  if (aStep != NULL) {
81 
82  G4TouchableHistory* touchable = (G4TouchableHistory*)aStep->GetPreStepPoint()->GetTouchable();
83  G4LogicalVolume* plv = (G4LogicalVolume*)touchable->GetVolume()->GetLogicalVolume();
84  auto it = (init_) ? mapLV_.find(plv) : findLV(plv);
85 // std::cout << plv->GetName() << " Flag " << (it != mapLV_.end()) << " step " << aStep->IsFirstStepInVolume() << ":" << aStep->IsLastStepInVolume() << std::endl;
86  if (it != mapLV_.end()) {
87  int type = LVTypes_[(it->second).first];
88  if ((type == 0 && aStep->IsFirstStepInVolume()) ||
89  (type == 1 && aStep->IsLastStepInVolume())) {
90  unsigned int copy = (unsigned int)(touchable->GetReplicaNumber(0));
91  std::pair<G4LogicalVolume*,unsigned int> key(plv,copy);
92  auto itr = store_.find(key);
93  if (itr == store_.end()) {
94  store_[key] = ParticleFlux((it->second).second,copy);
95  itr = store_.find(key);
96  }
97  G4Track* track = aStep->GetTrack();
98  int pdgid = track->GetDefinition()->GetPDGEncoding();
99  int vxtyp = (track->GetCreatorProcess() == nullptr) ? 0 : 1;
100  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
101  const double mmTocm(0.1), MeVToGeV(0.001);
102  ParticleFlux::flux flx(pdgid,vxtyp,time);
103  flx.vertex = math::GlobalPoint(mmTocm*track->GetVertexPosition().x(),
104  mmTocm*track->GetVertexPosition().y(),
105  mmTocm*track->GetVertexPosition().z());
106  flx.hitPoint = math::GlobalPoint(mmTocm*track->GetPosition().x(),
107  mmTocm*track->GetPosition().y(),
108  mmTocm*track->GetPosition().z());
109  flx.momentum = math::GlobalVector(MeVToGeV*track->GetMomentum().x(),
110  MeVToGeV*track->GetMomentum().y(),
111  MeVToGeV*track->GetMomentum().z());
112  (itr->second).addFlux(flx);
113 #ifdef EDM_ML_DEBUG
114  std::cout << "SimG4FluxProducer: Element " << (it->second).first << ":"
115  << (it->second).second << ":" << copy << " ID " << pdgid
116  << " VxType " << vxtyp << " TOF " << time << " Hit Point "
117  << flx.hitPoint << " p " << flx.momentum << " Vertex "
118  << flx.vertex << std::endl;
119 #endif
120  }//if(Step ok)
121  }//if( it != map.end() )
122  }//if (aStep != NULL)
123 
124 }
type
Definition: HCALResponse.h:21
std::map< std::pair< G4LogicalVolume *, unsigned int >, ParticleFlux > store_
std::map< G4LogicalVolume *, std::pair< unsigned int, std::string > > mapLV_
std::vector< int > LVTypes_
#define NULL
Definition: scimark2.h:8
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:27
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float >, ROOT::Math::GlobalCoordinateSystemTag > GlobalPoint
point in global coordinate system
Definition: Point3D.h:17

Member Data Documentation

unsigned int SimG4FluxProducer::count_
private

Definition at line 58 of file SimG4FluxProducer.h.

Referenced by update().

bool SimG4FluxProducer::init_
private

Definition at line 59 of file SimG4FluxProducer.h.

Referenced by update().

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

Definition at line 52 of file SimG4FluxProducer.h.

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

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

Definition at line 53 of file SimG4FluxProducer.h.

Referenced by SimG4FluxProducer(), and update().

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

Definition at line 55 of file SimG4FluxProducer.h.

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

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

Definition at line 60 of file SimG4FluxProducer.h.

Referenced by endOfEvent(), and update().

G4VPhysicalVolume* SimG4FluxProducer::topPV_
private

Definition at line 54 of file SimG4FluxProducer.h.

Referenced by update().