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 
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 
39 
40  edm::LogInfo("SimG4CoreCustomPhysics") << "RHStopTracer::RHStopTracer " << mTraceParticleName
41  << " Eth(GeV)= " << mTraceEnergy;
42 }
43 
45 
46 void RHStopTracer::update(const BeginOfRun* fRun) {
47  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the run " << (*fRun)()->GetRunID();
48 }
49 
51  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> begin of the event " << (*fEvent)()->GetEventID();
52 }
53 
54 void RHStopTracer::update(const BeginOfTrack* fTrack) {
55  const G4Track* track = (*fTrack)();
56  const G4ParticleDefinition* part = track->GetDefinition();
57  const std::string& stringPartName = part->GetParticleName();
58  bool matched = false;
59  int pdgid = std::abs(part->GetPDGEncoding());
60  if ((pdgid > minPdgId && pdgid < maxPdgId) || pdgid == otherPdgId)
61  matched = std::regex_match(stringPartName, rePartName);
62  if (matched || track->GetKineticEnergy() > mTraceEnergy) {
63  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> new track: ID/Name/pdgId/mass/charge/Parent: "
64  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
65  << part->GetPDGEncoding() << '/' << part->GetPDGMass() / GeV << " GeV/"
66  << part->GetPDGCharge() << '/' << track->GetParentID()
67  << " Position: " << track->GetPosition() << ' '
68  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
69  << " 4vec " << track->GetMomentum();
70  } else if (mStopRegular) { // kill regular particles
71  const_cast<G4Track*>(track)->SetTrackStatus(fStopAndKill);
72  }
73 }
74 
75 void RHStopTracer::update(const EndOfTrack* fTrack) {
76  const G4Track* track = (*fTrack)();
77  const G4ParticleDefinition* part = track->GetDefinition();
78  const std::string& stringPartName = part->GetParticleName();
79  bool matched = false;
80  int pdgid = std::abs(part->GetPDGEncoding());
81  if ((pdgid > minPdgId && pdgid < maxPdgId) || pdgid == otherPdgId)
82  matched = std::regex_match(stringPartName, rePartName);
83  if (matched || track->GetKineticEnergy() > mTraceEnergy) {
84  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::update-> stop track: ID/Name/pdgId/mass/charge/Parent: "
85  << track->GetTrackID() << '/' << part->GetParticleName() << '/'
86  << part->GetPDGEncoding() << '/' << part->GetPDGMass() / GeV << " GeV/"
87  << part->GetPDGCharge() << '/' << track->GetParentID()
88  << " Position: " << track->GetPosition() << ' '
89  << " R/phi: " << track->GetPosition().perp() << '/' << track->GetPosition().phi()
90  << " 4vec " << track->GetMomentum();
91  if (track->GetMomentum().mag() < 0.001) {
92  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer:: track has stopped, so making StopPoint";
93  mStopPoints.push_back(StopPoint(track->GetDefinition()->GetParticleName(),
94  track->GetPosition().x(),
95  track->GetPosition().y(),
96  track->GetPosition().z(),
97  track->GetGlobalTime(),
98  track->GetDefinition()->GetPDGEncoding(),
99  track->GetDefinition()->GetPDGMass() / GeV,
100  track->GetDefinition()->GetPDGCharge()));
101  }
102  }
103 }
104 
106  LogDebug("SimG4CoreCustomPhysics") << "RHStopTracer::produce->";
107 
108  std::unique_ptr<std::vector<std::string> > names(new std::vector<std::string>);
109  std::unique_ptr<std::vector<float> > xs(new std::vector<float>);
110  std::unique_ptr<std::vector<float> > ys(new std::vector<float>);
111  std::unique_ptr<std::vector<float> > zs(new std::vector<float>);
112  std::unique_ptr<std::vector<float> > ts(new std::vector<float>);
113  std::unique_ptr<std::vector<int> > ids(new std::vector<int>);
114  std::unique_ptr<std::vector<float> > masses(new std::vector<float>);
115  std::unique_ptr<std::vector<float> > charges(new std::vector<float>);
116 
117  std::vector<StopPoint>::const_iterator stopPoint = mStopPoints.begin();
118  for (; stopPoint != mStopPoints.end(); ++stopPoint) {
119  names->push_back(stopPoint->name);
120  xs->push_back(stopPoint->x);
121  ys->push_back(stopPoint->y);
122  zs->push_back(stopPoint->z);
123  ts->push_back(stopPoint->t);
124  ids->push_back(stopPoint->id);
125  masses->push_back(stopPoint->mass);
126  charges->push_back(stopPoint->charge);
127  }
128  fEvent.put(std::move(names), "StoppedParticlesName");
129  fEvent.put(std::move(xs), "StoppedParticlesX");
130  fEvent.put(std::move(ys), "StoppedParticlesY");
131  fEvent.put(std::move(zs), "StoppedParticlesZ");
132  fEvent.put(std::move(ts), "StoppedParticlesTime");
133  fEvent.put(std::move(ids), "StoppedParticlesPdgId");
134  fEvent.put(std::move(masses), "StoppedParticlesMass");
135  fEvent.put(std::move(charges), "StoppedParticlesCharge");
136  mStopPoints.clear();
137 }
RHStopTracer::RHStopTracer
RHStopTracer(edm::ParameterSet const &p)
Definition: RHStopTracer.cc:20
muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
CosmicGenFilterHelix_cfi.charges
charges
only generated particles of these IDs are considered
Definition: CosmicGenFilterHelix_cfi.py:6
RHStopTracer::mTraceParticleName
std::string mTraceParticleName
Definition: RHStopTracer.h:51
TrackingAction.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
MessageLogger.h
RHStopTracer::minPdgId
int minPdgId
Definition: RHStopTracer.h:48
RHStopTracer::rePartName
std::regex rePartName
Definition: RHStopTracer.h:52
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
RHStopTracer::mStopRegular
bool mStopRegular
Definition: RHStopTracer.h:46
EndOfTrack.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
EndOfTrack
Definition: EndOfTrack.h:6
RHStopTracer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: RHStopTracer.cc:105
RHStopTracer::update
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: RHStopTracer.cc:46
BeginOfTrack.h
RHStopTracer::maxPdgId
int maxPdgId
Definition: RHStopTracer.h:49
RHStopTracer.h
RHStopTracer::mTraceEnergy
double mTraceEnergy
Definition: RHStopTracer.h:47
BeginOfRun.h
part
part
Definition: HCALResponse.h:20
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
RHStopTracer::mStopPoints
std::vector< StopPoint > mStopPoints
Definition: RHStopTracer.h:53
RHStopTracer::otherPdgId
int otherPdgId
Definition: RHStopTracer.h:50
BeginOfTrack
Definition: BeginOfTrack.h:6
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
GeV
const double GeV
Definition: MathUtil.h:16
RHStopTracer::~RHStopTracer
~RHStopTracer() override
Definition: RHStopTracer.cc:44
BeginOfEvent.h
BeginOfEvent
Definition: BeginOfEvent.h:6
BeginOfRun
Definition: BeginOfRun.h:6
edm::EventSetup
Definition: EventSetup.h:58
TrackInformation.h
particleFlowDisplacedVertex_cfi.masses
masses
Definition: particleFlowDisplacedVertex_cfi.py:80
hcaldqm::fEvent
Definition: DQTask.h:32
eostools.move
def move(src, dest)
Definition: eostools.py:511
RHStopTracer::StopPoint
Definition: RHStopTracer.h:33
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Event
Definition: Event.h:73
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:30