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 
11 
12 #include "G4Track.hh"
13 #include "G4Run.hh"
14 #include "G4Event.hh"
15 
16 
19  mDebug = parameters.getUntrackedParameter<bool>("verbose", false);
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 
29  if (mDebug) {
30  std::cout << "RHStopTracer::RHStopTracer->"
31  << mTraceParticleNameRegex << '/' << mTraceEnergy << std::endl;
32  }
33 }
34 
36 }
37 
38 void RHStopTracer::update (const BeginOfRun * fRun) {
39  if (mDebug)
40  std::cout << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID () << std::endl;
41 }
42 
43 void RHStopTracer::update (const BeginOfEvent * fEvent) {
44  if (mDebug)
45  std::cout << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID () << std::endl;
46 }
47 
48 void RHStopTracer::update (const BeginOfTrack * fTrack) {
49  const G4Track* track = (*fTrack)();
50  if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
51  if (mDebug)
52  std::cout << "RHStopTracer::update-> new track: ID/Name/mass/Parent: "
53  << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
54  << track->GetDefinition()->GetPDGMass() << '/' << track->GetParentID()
55  << std::endl
56  << " position X/Y/Z: " << track->GetPosition().x() << '/'
57  << track->GetPosition().y() << '/' << track->GetPosition().z()
58  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
59  << std::endl
60  << " px/py/pz/p=" << track->GetMomentum().x() << '/'
61  << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag()
62  << std::endl;
63  }
64  if (mStopRegular && !matched (track->GetDefinition()->GetParticleName())) { // kill regular particles
65  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
66  }
67 }
68 
69 void RHStopTracer::update (const EndOfTrack * fTrack) {
70  const G4Track* track = (*fTrack)();
71  if ((track->GetMomentum().mag()> mTraceEnergy) || matched (track->GetDefinition()->GetParticleName())) {
72  if (mDebug)
73  std::cout << "RHStopTracer::update-> stop track: ID/Name/mass/Parent: "
74  << track->GetTrackID() << '/' << track->GetDefinition()->GetParticleName() << '/'
75  << track->GetDefinition()->GetPDGMass() << '/' << track->GetParentID()
76  << std::endl
77  << " position X/Y/Z: " << track->GetPosition().x() << '/'
78  << track->GetPosition().y() << '/' << track->GetPosition().z()
79  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
80  << std::endl
81  << " px/py/pz/p=" << track->GetMomentum().x() << '/'
82  << track->GetMomentum().y() << '/' << track->GetMomentum().z() << '/'<< track->GetMomentum().mag()
83  << std::endl;
84  if (track->GetMomentum().mag () < 0.001) {
85  mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
86  track->GetPosition().x(),
87  track->GetPosition().y(),
88  track->GetPosition().z(),
89  track->GetGlobalTime()));
90  }
91  }
92 }
93 
94 bool RHStopTracer::matched (const std::string& fName) const {
95  return boost::regex_match (fName, mTraceParticleNameRegex);
96 }
97 
99  if (mDebug) {
100  std::cout << "RHStopTracer::produce->" << std::endl;
101  }
102  std::auto_ptr<std::vector<std::string> > names (new std::vector<std::string>);
103  std::auto_ptr<std::vector<float> > xs (new std::vector<float>);
104  std::auto_ptr<std::vector<float> > ys (new std::vector<float>);
105  std::auto_ptr<std::vector<float> > zs (new std::vector<float>);
106  std::auto_ptr<std::vector<float> > ts (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  }
116  fEvent.put (names, "StoppedParticlesName");
117  fEvent.put (xs, "StoppedParticlesX");
118  fEvent.put (ys, "StoppedParticlesY");
119  fEvent.put (zs, "StoppedParticlesZ");
120  fEvent.put (ts, "StoppedParticlesTime");
121  mStopPoints.clear ();
122  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
dictionary parameters
Definition: Parameters.py:2
static const HistoName names[]
void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
Definition: RHStopTracer.cc:38
bool matched(const std::string &fName) const
Definition: RHStopTracer.cc:94
boost::regex mTraceParticleNameRegex
Definition: RHStopTracer.h:43
virtual ~RHStopTracer()
Definition: RHStopTracer.cc:35
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
double mTraceEnergy
Definition: RHStopTracer.h:42
RHStopTracer(edm::ParameterSet const &p)
Definition: RHStopTracer.cc:17
void produce(edm::Event &, const edm::EventSetup &)
Definition: RHStopTracer.cc:98
bool mStopRegular
Definition: RHStopTracer.h:41
tuple cout
Definition: gather_cfg.py:121
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:44