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  produces< std::vector<std::string> >("StoppedParticlesName");
26  produces< std::vector<float> >("StoppedParticlesX");
27  produces< std::vector<float> >("StoppedParticlesY");
28  produces< std::vector<float> >("StoppedParticlesZ");
29  produces< std::vector<float> >("StoppedParticlesTime");
30  produces< std::vector<int> >("StoppedParticlesPdgId");
31  produces< std::vector<float> >("StoppedParticlesMass");
32  produces< std::vector<float> >("StoppedParticlesCharge");
33 
34  mParticle = G4ParticleTable::GetParticleTable()->FindParticle(mTraceParticleName);
35 
36  edm::LogInfo("SimG4CoreCustomPhysics")
37  << "RHStopTracer::RHStopTracer " << mTraceParticleName
38  << " Eth(GeV)= " << mTraceEnergy;
39  mTraceEnergy *= CLHEP::GeV;
40 }
41 
43 }
44 
45 void RHStopTracer::update (const BeginOfRun * fRun) {
46  LogDebug("SimG4CoreCustomPhysics")
47  << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
48 }
49 
51  LogDebug("SimG4CoreCustomPhysics")
52  << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
53 }
54 
55 void RHStopTracer::update (const BeginOfTrack * fTrack) {
56  const G4Track* track = (*fTrack)();
57  const G4ParticleDefinition* part = track->GetDefinition();
58  if(part && part == mParticle && track->GetKineticEnergy() > mTraceEnergy) {
59  LogDebug("SimG4CoreCustomPhysics")
60  << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
61  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
62  << part->GetPDGEncoding() << '/'
63  << part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
64  << track->GetParentID()
65  << " Position: " << track->GetPosition() << ' '
66  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
67  << " 4vec " << track->GetMomentum();
68  } else if (mStopRegular) { // kill regular particles
69  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
70  }
71 }
72 
73 void RHStopTracer::update (const EndOfTrack * fTrack) {
74  const G4Track* track = (*fTrack)();
75  const G4ParticleDefinition* part = track->GetDefinition();
76  if(part && part == mParticle && track->GetKineticEnergy() > mTraceEnergy) {
77  LogDebug("SimG4CoreCustomPhysics") <<
78  "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
79  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
80  << part->GetPDGEncoding() << '/'
81  << part->GetPDGMass()/GeV <<" GeV/" << part->GetPDGCharge() << '/'
82  << track->GetParentID()
83  << " Position: " << track->GetPosition() << ' '
84  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
85  << " 4vec " << track->GetMomentum();
86  if (track->GetMomentum().mag () < 0.001) {
87  mStopPoints.push_back (StopPoint (track->GetDefinition()->GetParticleName(),
88  track->GetPosition().x(),
89  track->GetPosition().y(),
90  track->GetPosition().z(),
91  track->GetGlobalTime(),
92  track->GetDefinition()->GetPDGEncoding(),
93  track->GetDefinition()->GetPDGMass()/GeV,
94  track->GetDefinition()->GetPDGCharge() ));
95  }
96  }
97 }
98 
100  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";
101 
102  std::unique_ptr<std::vector<std::string> > names(new std::vector<std::string>);
103  std::unique_ptr<std::vector<float> > xs(new std::vector<float>);
104  std::unique_ptr<std::vector<float> > ys(new std::vector<float>);
105  std::unique_ptr<std::vector<float> > zs(new std::vector<float>);
106  std::unique_ptr<std::vector<float> > ts(new std::vector<float>);
107  std::unique_ptr<std::vector<int> > ids(new std::vector<int>);
108  std::unique_ptr<std::vector<float> > masses(new std::vector<float>);
109  std::unique_ptr<std::vector<float> > charges(new std::vector<float>);
110 
111  std::vector <StopPoint>::const_iterator stopPoint = mStopPoints.begin ();
112  for (; stopPoint != mStopPoints.end(); ++stopPoint) {
113  names->push_back (stopPoint->name);
114  xs->push_back (stopPoint->x);
115  ys->push_back (stopPoint->y);
116  zs->push_back (stopPoint->z);
117  ts->push_back (stopPoint->t);
118  ids->push_back (stopPoint->id);
119  masses->push_back (stopPoint->mass);
120  charges->push_back (stopPoint->charge);
121  }
122  fEvent.put(std::move(names), "StoppedParticlesName");
123  fEvent.put(std::move(xs), "StoppedParticlesX");
124  fEvent.put(std::move(ys), "StoppedParticlesY");
125  fEvent.put(std::move(zs), "StoppedParticlesZ");
126  fEvent.put(std::move(ts), "StoppedParticlesTime");
127  fEvent.put(std::move(ids), "StoppedParticlesPdgId");
128  fEvent.put(std::move(masses), "StoppedParticlesMass");
129  fEvent.put(std::move(charges), "StoppedParticlesCharge");
130  mStopPoints.clear ();
131 }
#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:122
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:45
const G4ParticleDefinition * mParticle
Definition: RHStopTracer.h:47
virtual ~RHStopTracer()
Definition: RHStopTracer.cc:42
double mTraceEnergy
Definition: RHStopTracer.h:45
std::string mTraceParticleName
Definition: RHStopTracer.h:46
RHStopTracer(edm::ParameterSet const &p)
Definition: RHStopTracer.cc:20
void produce(edm::Event &, const edm::EventSetup &)
Definition: RHStopTracer.cc:99
bool mStopRegular
Definition: RHStopTracer.h:44
part
Definition: HCALResponse.h:20
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:48
def move(src, dest)
Definition: eostools.py:510