CMS 3D CMS Logo

RHStopTracer.cc
Go to the documentation of this file.
2 
9 
12 
13 #include "G4Track.hh"
14 #include "G4Run.hh"
15 #include "G4Event.hh"
16 #include "G4SystemOfUnits.hh"
17 #include "G4ParticleTable.hh"
18 #include "G4ParticleDefinition.hh"
19 
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 
40  edm::LogInfo("SimG4CoreCustomPhysics")
41  << "RHStopTracer::RHStopTracer " << mTraceParticleName
42  << " Eth(GeV)= " << mTraceEnergy;
43 
44 }
45 
47 }
48 
49 void RHStopTracer::update (const BeginOfRun * fRun) {
50  LogDebug("SimG4CoreCustomPhysics")
51  << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
52 }
53 
55  LogDebug("SimG4CoreCustomPhysics")
56  << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
57 }
58 
59 void RHStopTracer::update (const BeginOfTrack * fTrack) {
60  const G4Track* track = (*fTrack)();
61  const G4ParticleDefinition* part = track->GetDefinition();
62  const std::string& stringPartName = part->GetParticleName();
63  bool matched = false;
64  int pdgid = std::abs(part->GetPDGEncoding());
65  if( (pdgid>minPdgId && pdgid<maxPdgId) || pdgid==otherPdgId )
66  matched = std::regex_match(stringPartName,rePartName);
67  if( matched || track->GetKineticEnergy() > mTraceEnergy) {
68  LogDebug("SimG4CoreCustomPhysics")
69  << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
70  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
71  << part->GetPDGEncoding() << '/'
72  << part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
73  << track->GetParentID()
74  << " Position: " << track->GetPosition() << ' '
75  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
76  << " 4vec " << track->GetMomentum();
77  } else if (mStopRegular) { // kill regular particles
78  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
79  }
80 }
81 
82 void RHStopTracer::update (const EndOfTrack * fTrack) {
83  const G4Track* track = (*fTrack)();
84  const G4ParticleDefinition* part = track->GetDefinition();
85  const std::string& stringPartName = part->GetParticleName();
86  bool matched = false;
87  int pdgid = std::abs(part->GetPDGEncoding());
88  if( (pdgid>minPdgId && pdgid<maxPdgId) || pdgid==otherPdgId )
89  matched = std::regex_match(stringPartName,rePartName);
90  if( matched || track->GetKineticEnergy() > mTraceEnergy) {
91  LogDebug("SimG4CoreCustomPhysics")
92  << "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
93  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
94  << part->GetPDGEncoding() << '/'
95  << part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
96  << track->GetParentID()
97  << " Position: " << track->GetPosition() << ' '
98  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
99  << " 4vec " << track->GetMomentum();
100  if (track->GetMomentum().mag () < 0.001) {
101  LogDebug("SimG4CoreCustomPhysics") <<
102  "RHStopTracer:: track has stopped, so making StopPoint";
103  mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
104  track->GetPosition().x(),
105  track->GetPosition().y(),
106  track->GetPosition().z(),
107  track->GetGlobalTime(),
108  track->GetDefinition()->GetPDGEncoding(),
109  track->GetDefinition()->GetPDGMass()/GeV,
110  track->GetDefinition()->GetPDGCharge() ));
111  }
112  }
113 }
114 
116  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";
117 
118  std::unique_ptr<std::vector<std::string> > names(new std::vector<std::string>);
119  std::unique_ptr<std::vector<float> > xs(new std::vector<float>);
120  std::unique_ptr<std::vector<float> > ys(new std::vector<float>);
121  std::unique_ptr<std::vector<float> > zs(new std::vector<float>);
122  std::unique_ptr<std::vector<float> > ts(new std::vector<float>);
123  std::unique_ptr<std::vector<int> > ids(new std::vector<int>);
124  std::unique_ptr<std::vector<float> > masses(new std::vector<float>);
125  std::unique_ptr<std::vector<float> > charges(new std::vector<float>);
126 
127  std::vector <StopPoint>::const_iterator stopPoint = mStopPoints.begin ();
128  for (; stopPoint != mStopPoints.end(); ++stopPoint) {
129  names->push_back (stopPoint->name);
130  xs->push_back (stopPoint->x);
131  ys->push_back (stopPoint->y);
132  zs->push_back (stopPoint->z);
133  ts->push_back (stopPoint->t);
134  ids->push_back (stopPoint->id);
135  masses->push_back (stopPoint->mass);
136  charges->push_back (stopPoint->charge);
137  }
138  fEvent.put(std::move(names), "StoppedParticlesName");
139  fEvent.put(std::move(xs), "StoppedParticlesX");
140  fEvent.put(std::move(ys), "StoppedParticlesY");
141  fEvent.put(std::move(zs), "StoppedParticlesZ");
142  fEvent.put(std::move(ts), "StoppedParticlesTime");
143  fEvent.put(std::move(ids), "StoppedParticlesPdgId");
144  fEvent.put(std::move(masses), "StoppedParticlesMass");
145  fEvent.put(std::move(charges), "StoppedParticlesCharge");
146  mStopPoints.clear ();
147 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
const double GeV
Definition: MathUtil.h:16
~RHStopTracer() override
Definition: RHStopTracer.cc:46
static const HistoName names[]
void produce(edm::Event &, const edm::EventSetup &) override
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: RHStopTracer.cc:49
double mTraceEnergy
Definition: RHStopTracer.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string mTraceParticleName
Definition: RHStopTracer.h:51
RHStopTracer(edm::ParameterSet const &p)
Definition: RHStopTracer.cc:20
bool mStopRegular
Definition: RHStopTracer.h:46
part
Definition: HCALResponse.h:20
std::regex rePartName
Definition: RHStopTracer.h:52
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:53
def move(src, dest)
Definition: eostools.py:510