test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RHStopTracer.cc
Go to the documentation of this file.
1 #include "RHStopTracer.h"
2 
9 
12 
13 #include "G4Track.hh"
14 #include "G4Run.hh"
15 #include "G4Event.hh"
16 #include "G4SystemOfUnits.hh"
17 
20  mStopRegular = parameters.getUntrackedParameter<bool>("stopRegularParticles", false);
21  mTraceEnergy = 1000 * parameters.getUntrackedParameter<double>("traceEnergy", 1.e20); // GeV->KeV
22  mTraceParticleNameRegex = parameters.getParameter<std::string>("traceParticle");
23  produces< std::vector<std::string> >("StoppedParticlesName");
24  produces< std::vector<float> >("StoppedParticlesX");
25  produces< std::vector<float> >("StoppedParticlesY");
26  produces< std::vector<float> >("StoppedParticlesZ");
27  produces< std::vector<float> >("StoppedParticlesTime");
28  produces< std::vector<int> >("StoppedParticlesPdgId");
29  produces< std::vector<float> >("StoppedParticlesMass");
30  produces< std::vector<float> >("StoppedParticlesCharge");
31 
32  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::RHStopTracer->"
33  << mTraceParticleNameRegex << '/' << mTraceEnergy;
34 }
35 
37 }
38 
39 void RHStopTracer::update (const BeginOfRun * fRun) {
40  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
41 }
42 
43 void RHStopTracer::update (const BeginOfEvent * fEvent) {
44  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
45 }
46 
47 void RHStopTracer::update (const BeginOfTrack * fTrack) {
48  const G4Track* track = (*fTrack)();
49  if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
50  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
51  << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
52  << track->GetDefinition()->GetPDGEncoding() << '/'
53  << track->GetDefinition()->GetPDGMass()/GeV <<" GeV/" << track->GetDefinition()->GetPDGCharge() << '/'
54  << track->GetParentID()
55  << " position X/Y/Z: " << track->GetPosition().x() << '/'
56  << track->GetPosition().y() << '/' << track->GetPosition().z()
57  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
58  << " px/py/pz/p=" << track->GetMomentum().x() << '/'
59  << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag();
60  }
61  if (mStopRegular && !matched (track->GetDefinition()->GetParticleName())) { // kill regular particles
62  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
63  }
64 }
65 
66 void RHStopTracer::update (const EndOfTrack * fTrack) {
67  const G4Track* track = (*fTrack)();
68  if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
69  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
70  << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
71  << track->GetDefinition()->GetPDGEncoding() << '/'
72  << track->GetDefinition()->GetPDGMass()/GeV <<" GeV/" << track->GetDefinition()->GetPDGCharge() << '/'
73  << track->GetParentID()
74  << " position X/Y/Z: " << track->GetPosition().x() << '/'
75  << track->GetPosition().y() << '/' << track->GetPosition().z()
76  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
77  << " px/py/pz/p=" << track->GetMomentum().x() << '/'
78  << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag();
79  if (track->GetMomentum().mag () < 0.001) {
80  mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
81  track->GetPosition().x(),
82  track->GetPosition().y(),
83  track->GetPosition().z(),
84  track->GetGlobalTime(),
85  track->GetDefinition()->GetPDGEncoding(),
86  track->GetDefinition()->GetPDGMass()/GeV,
87  track->GetDefinition()->GetPDGCharge() ));
88  }
89  }
90 }
91 
93  return boost::regex_match (fName, mTraceParticleNameRegex);
94 }
95 
97  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";
98 
99  std::auto_ptr<std::vector<std::string> > names (new std::vector<std::string>);
100  std::auto_ptr<std::vector<float> > xs (new std::vector<float>);
101  std::auto_ptr<std::vector<float> > ys (new std::vector<float>);
102  std::auto_ptr<std::vector<float> > zs (new std::vector<float>);
103  std::auto_ptr<std::vector<float> > ts (new std::vector<float>);
104  std::auto_ptr<std::vector<int> > ids (new std::vector<int>);
105  std::auto_ptr<std::vector<float> > masses (new std::vector<float>);
106  std::auto_ptr<std::vector<float> > charges (new std::vector<float>);
107 
108  std::vector <StopPoint>::const_iterator stopPoint = mStopPoints.begin ();
109  for (; stopPoint != mStopPoints.end(); ++stopPoint) {
110  names->push_back (stopPoint->name);
111  xs->push_back (stopPoint->x);
112  ys->push_back (stopPoint->y);
113  zs->push_back (stopPoint->z);
114  ts->push_back (stopPoint->t);
115  ids->push_back (stopPoint->id);
116  masses->push_back (stopPoint->mass);
117  charges->push_back (stopPoint->charge);
118  }
119  fEvent.put (names, "StoppedParticlesName");
120  fEvent.put (xs, "StoppedParticlesX");
121  fEvent.put (ys, "StoppedParticlesY");
122  fEvent.put (zs, "StoppedParticlesZ");
123  fEvent.put (ts, "StoppedParticlesTime");
124  fEvent.put (ids, "StoppedParticlesPdgId");
125  fEvent.put (masses, "StoppedParticlesMass");
126  fEvent.put (charges, "StoppedParticlesCharge");
127  mStopPoints.clear ();
128  }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
const double GeV
Definition: MathUtil.h:16
static const HistoName names[]
void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
Definition: RHStopTracer.cc:39
bool matched(const std::string &fName) const
Definition: RHStopTracer.cc:92
boost::regex mTraceParticleNameRegex
Definition: RHStopTracer.h:45
virtual ~RHStopTracer()
Definition: RHStopTracer.cc:36
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
double mTraceEnergy
Definition: RHStopTracer.h:44
RHStopTracer(edm::ParameterSet const &p)
Definition: RHStopTracer.cc:18
void produce(edm::Event &, const edm::EventSetup &)
Definition: RHStopTracer.cc:96
bool mStopRegular
Definition: RHStopTracer.h:43
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:46