CMS 3D CMS Logo

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

#include <RHStopTracer.h>

Inheritance diagram for RHStopTracer:
SimProducer Observer< const BeginOfRun *> Observer< const BeginOfEvent *> Observer< const BeginOfTrack *> Observer< const EndOfTrack *> SimWatcher

Classes

struct  StopPoint
 

Public Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 
 RHStopTracer (edm::ParameterSet const &p)
 
void update (const BeginOfRun *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfEvent *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfTrack *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const EndOfTrack *) override
 This routine will be called when the appropriate signal arrives. More...
 
 ~RHStopTracer () override=default
 
- 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 BeginOfTrack *>
 Observer ()
 
void slotForUpdate (const BeginOfTrack * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const EndOfTrack *>
 Observer ()
 
void slotForUpdate (const EndOfTrack * iT)
 
virtual ~Observer ()
 

Private Attributes

int maxPdgId
 
int minPdgId
 
std::vector< StopPointmStopPoints
 
bool mStopRegular
 
double mTraceEnergy
 
std::string mTraceParticleName
 
int otherPdgId
 
std::regex rePartName
 

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 18 of file RHStopTracer.h.

Constructor & Destructor Documentation

◆ RHStopTracer()

RHStopTracer::RHStopTracer ( edm::ParameterSet const &  p)

Definition at line 20 of file RHStopTracer.cc.

References maxPdgId, minPdgId, mStopRegular, mTraceEnergy, mTraceParticleName, otherPdgId, AlCaHLTBitMon_ParallelJobs::p, rePartName, SimWatcher::setMT(), and AlCaHLTBitMon_QueryRunRegistry::string.

20  {
21  edm::ParameterSet parameters = p.getParameter<edm::ParameterSet>("RHStopTracer");
22  mStopRegular = parameters.getUntrackedParameter<bool>("stopRegularParticles", false);
23  mTraceEnergy = parameters.getUntrackedParameter<double>("traceEnergy", 1.e20);
24  mTraceParticleName = parameters.getParameter<std::string>("traceParticle");
25  minPdgId = parameters.getUntrackedParameter<int>("minPdgId", 1000000);
26  maxPdgId = parameters.getUntrackedParameter<int>("maxPdgId", 2000000);
27  otherPdgId = parameters.getUntrackedParameter<int>("otherPdgId", 17);
28  produces<std::vector<std::string> >("StoppedParticlesName");
29  produces<std::vector<float> >("StoppedParticlesX");
30  produces<std::vector<float> >("StoppedParticlesY");
31  produces<std::vector<float> >("StoppedParticlesZ");
32  produces<std::vector<float> >("StoppedParticlesTime");
33  produces<std::vector<int> >("StoppedParticlesPdgId");
34  produces<std::vector<float> >("StoppedParticlesMass");
35  produces<std::vector<float> >("StoppedParticlesCharge");
36 
37  mTraceEnergy *= CLHEP::GeV;
39  setMT(true);
40 
41  edm::LogVerbatim("SimG4CoreCustomPhysics")
42  << "RHStopTracer::RHStopTracer " << mTraceParticleName << " Eth(GeV)= " << mTraceEnergy;
43 }
Log< level::Info, true > LogVerbatim
void setMT(bool val)
Definition: SimWatcher.h:47
double mTraceEnergy
Definition: RHStopTracer.h:47
std::string mTraceParticleName
Definition: RHStopTracer.h:51
bool mStopRegular
Definition: RHStopTracer.h:46
std::regex rePartName
Definition: RHStopTracer.h:52

◆ ~RHStopTracer()

RHStopTracer::~RHStopTracer ( )
overridedefault

Member Function Documentation

◆ produce()

void RHStopTracer::produce ( edm::Event fEvent,
const edm::EventSetup  
)
overridevirtual

Implements SimProducer.

Definition at line 104 of file RHStopTracer.cc.

References CosmicGenFilterHelix_cfi::charges, hcaldqm::fEvent, LogDebug, particleFlowDisplacedVertex_cfi::masses, eostools::move(), mStopPoints, and names.

104  {
105  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";
106 
107  std::unique_ptr<std::vector<std::string> > names(new std::vector<std::string>);
108  std::unique_ptr<std::vector<float> > xs(new std::vector<float>);
109  std::unique_ptr<std::vector<float> > ys(new std::vector<float>);
110  std::unique_ptr<std::vector<float> > zs(new std::vector<float>);
111  std::unique_ptr<std::vector<float> > ts(new std::vector<float>);
112  std::unique_ptr<std::vector<int> > ids(new std::vector<int>);
113  std::unique_ptr<std::vector<float> > masses(new std::vector<float>);
114  std::unique_ptr<std::vector<float> > charges(new std::vector<float>);
115 
116  std::vector<StopPoint>::const_iterator stopPoint = mStopPoints.begin();
117  for (; stopPoint != mStopPoints.end(); ++stopPoint) {
118  names->push_back(stopPoint->name);
119  xs->push_back(stopPoint->x);
120  ys->push_back(stopPoint->y);
121  zs->push_back(stopPoint->z);
122  ts->push_back(stopPoint->t);
123  ids->push_back(stopPoint->id);
124  masses->push_back(stopPoint->mass);
125  charges->push_back(stopPoint->charge);
126  }
127  fEvent.put(std::move(names), "StoppedParticlesName");
128  fEvent.put(std::move(xs), "StoppedParticlesX");
129  fEvent.put(std::move(ys), "StoppedParticlesY");
130  fEvent.put(std::move(zs), "StoppedParticlesZ");
131  fEvent.put(std::move(ts), "StoppedParticlesTime");
132  fEvent.put(std::move(ids), "StoppedParticlesPdgId");
133  fEvent.put(std::move(masses), "StoppedParticlesMass");
134  fEvent.put(std::move(charges), "StoppedParticlesCharge");
135  mStopPoints.clear();
136 }
const std::string names[nVars_]
charges
only generated particles of these IDs are considered
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:53
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

◆ update() [1/4]

void RHStopTracer::update ( const BeginOfRun )
overridevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 45 of file RHStopTracer.cc.

References LogDebug.

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

45  {
46  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
47 }
#define LogDebug(id)

◆ update() [2/4]

void RHStopTracer::update ( const BeginOfEvent )
overridevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 49 of file RHStopTracer.cc.

References LogDebug.

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

49  {
50  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
51 }
#define LogDebug(id)

◆ update() [3/4]

void RHStopTracer::update ( const BeginOfTrack )
overridevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfTrack *>.

Definition at line 53 of file RHStopTracer.cc.

References funct::abs(), LogDebug, muonTagProbeFilters_cff::matched, maxPdgId, minPdgId, mStopRegular, mTraceEnergy, otherPdgId, EgammaValidation_cff::pdgid, rePartName, AlCaHLTBitMon_QueryRunRegistry::string, and HLT_2023v12_cff::track.

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

53  {
54  const G4Track* track = (*fTrack)();
55  const G4ParticleDefinition* part = track->GetDefinition();
56  const std::string& stringPartName = part->GetParticleName();
57  bool matched = false;
58  int pdgid = std::abs(part->GetPDGEncoding());
59  if ((pdgid > minPdgId && pdgid < maxPdgId) || pdgid == otherPdgId)
60  matched = std::regex_match(stringPartName, rePartName);
61  if (matched || track->GetKineticEnergy() > mTraceEnergy) {
62  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
63  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
64  << part->GetPDGEncoding() << '/' << part->GetPDGMass() / GeV << " GeV/"
65  << part->GetPDGCharge() << '/' << track->GetParentID()
66  << " Position: " << track->GetPosition() << ' '
67  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
68  << " 4vec " << track->GetMomentum();
69  } else if (mStopRegular) { // kill regular particles
70  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
71  }
72 }
double mTraceEnergy
Definition: RHStopTracer.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool mStopRegular
Definition: RHStopTracer.h:46
part
Definition: HCALResponse.h:20
std::regex rePartName
Definition: RHStopTracer.h:52
#define LogDebug(id)

◆ update() [4/4]

void RHStopTracer::update ( const EndOfTrack )
overridevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfTrack *>.

Definition at line 74 of file RHStopTracer.cc.

References funct::abs(), LogDebug, muonTagProbeFilters_cff::matched, maxPdgId, minPdgId, mStopPoints, mTraceEnergy, otherPdgId, EgammaValidation_cff::pdgid, rePartName, AlCaHLTBitMon_QueryRunRegistry::string, and HLT_2023v12_cff::track.

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

74  {
75  const G4Track* track = (*fTrack)();
76  const G4ParticleDefinition* part = track->GetDefinition();
77  const std::string& stringPartName = part->GetParticleName();
78  bool matched = false;
79  int pdgid = std::abs(part->GetPDGEncoding());
80  if ((pdgid > minPdgId && pdgid < maxPdgId) || pdgid == otherPdgId)
81  matched = std::regex_match(stringPartName, rePartName);
82  if (matched || track->GetKineticEnergy() > mTraceEnergy) {
83  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
84  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
85  << part->GetPDGEncoding() << '/' << part->GetPDGMass() / GeV << " GeV/"
86  << part->GetPDGCharge() << '/' << track->GetParentID()
87  << " Position: " << track->GetPosition() << ' '
88  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
89  << " 4vec " << track->GetMomentum();
90  if (track->GetMomentum().mag() < 0.001) {
91  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer:: track has stopped, so making StopPoint";
92  mStopPoints.push_back(StopPoint(track->GetDefinition()->GetParticleName(),
93  track->GetPosition().x(),
94  track->GetPosition().y(),
95  track->GetPosition().z(),
96  track->GetGlobalTime(),
97  track->GetDefinition()->GetPDGEncoding(),
98  track->GetDefinition()->GetPDGMass() / GeV,
99  track->GetDefinition()->GetPDGCharge()));
100  }
101  }
102 }
double mTraceEnergy
Definition: RHStopTracer.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20
std::regex rePartName
Definition: RHStopTracer.h:52
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:53
#define LogDebug(id)

Member Data Documentation

◆ maxPdgId

int RHStopTracer::maxPdgId
private

Definition at line 49 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().

◆ minPdgId

int RHStopTracer::minPdgId
private

Definition at line 48 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().

◆ mStopPoints

std::vector<StopPoint> RHStopTracer::mStopPoints
private

Definition at line 53 of file RHStopTracer.h.

Referenced by produce(), and update().

◆ mStopRegular

bool RHStopTracer::mStopRegular
private

Definition at line 46 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().

◆ mTraceEnergy

double RHStopTracer::mTraceEnergy
private

Definition at line 47 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().

◆ mTraceParticleName

std::string RHStopTracer::mTraceParticleName
private

Definition at line 51 of file RHStopTracer.h.

Referenced by RHStopTracer().

◆ otherPdgId

int RHStopTracer::otherPdgId
private

Definition at line 50 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().

◆ rePartName

std::regex RHStopTracer::rePartName
private

Definition at line 52 of file RHStopTracer.h.

Referenced by RHStopTracer(), and update().