File indexing completed on 2024-05-10 02:21:28
0001 #include "SimG4Core/SaveSimTrackAction/interface/SaveSimTrack.h"
0002
0003 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
0004 #include "SimG4Core/Notification/interface/TrackInformation.h"
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008 #include "G4PhysicalConstants.hh"
0009 #include <CLHEP/Units/SystemOfUnits.h>
0010 #include "G4Track.hh"
0011 #include <algorithm>
0012
0013 SaveSimTrack::SaveSimTrack(edm::ParameterSet const &p) {
0014 edm::ParameterSet ps = p.getParameter<edm::ParameterSet>("SaveSimTrack");
0015 pdgs_ = ps.getUntrackedParameter<std::vector<int>>("PDGCodes");
0016
0017 edm::LogVerbatim("SaveSimTrack") << "SaveSimTrack:: Save Sim Track if PDG code "
0018 << "is one from the list of " << pdgs_.size() << " items";
0019 for (unsigned int k = 0; k < pdgs_.size(); ++k)
0020 edm::LogVerbatim("SaveSimTrack") << "[" << k << "] " << pdgs_[k];
0021 }
0022
0023 SaveSimTrack::~SaveSimTrack() {}
0024
0025 void SaveSimTrack::update(const BeginOfTrack *trk) {
0026 const G4Track *theTrack = (*trk)();
0027 TrackInformation *trkInfo = reinterpret_cast<TrackInformation *>(theTrack->GetUserInformation());
0028 if (nullptr != trkInfo) {
0029 int pdg = theTrack->GetDefinition()->GetPDGEncoding();
0030 if (std::find(pdgs_.begin(), pdgs_.end(), pdg) != pdgs_.end()) {
0031 trkInfo->setStoreTrack();
0032 LogDebug("SaveSimTrack") << "Save SimTrack the Track " << theTrack->GetTrackID() << " Type "
0033 << theTrack->GetDefinition()->GetParticleName() << " Momentum "
0034 << theTrack->GetMomentum() / CLHEP::MeV << " MeV/c";
0035 }
0036 }
0037 }