Skip to content

Commit

Permalink
fix debug print and better format code
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraPerego committed Dec 17, 2024
1 parent 349f19c commit 774e317
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions SimDataFormats/Track/interface/SimTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SimTrack : public CoreSimTrack {
bool noVertex() const { return ivert == -1; }

/// index of the corresponding Generator particle in the Event container (-1 if no Genpart)
bool isPrimary() const { return (trackInfo_ >> 1) & 1; }
int genpartIndex() const { return isPrimary() ? igenpart : -1; }
bool noGenpart() const { return isPrimary() ? igenpart == -1 : true; }

Expand All @@ -52,7 +53,7 @@ class SimTrack : public CoreSimTrack {
math::XYZTLorentzVectorF positionAtBoundary,
math::XYZTLorentzVectorF momentumAtBoundary) {
if (crossedBoundary)
trackInfo_ |= 1 << 2;
trackInfo_ |= (1 << 2);
idAtBoundary_ = idAtBoundary;
positionAtBoundary_ = positionAtBoundary;
momentumAtBoundary_ = momentumAtBoundary;
Expand All @@ -62,11 +63,10 @@ class SimTrack : public CoreSimTrack {
const math::XYZTLorentzVectorF& getMomentumAtBoundary() const { return momentumAtBoundary_; }
int getIDAtBoundary() const { return idAtBoundary_; }

bool isFromBackScattering() const { return (trackInfo_ >> 0) & 1; }
void setFromBackScattering() { trackInfo_ |= 1 << 0; }
bool isFromBackScattering() const { return trackInfo_ & 1; }
void setFromBackScattering() { trackInfo_ |= 1; }

bool isPrimary() const { return (trackInfo_ >> 1) & 1; }
void setIsPrimary() { trackInfo_ |= 1 << 1; }
void setIsPrimary() { trackInfo_ |= (1 << 1); }
void setGenParticleID(const int idx) { igenpart = idx; }
int getPrimaryID() const { return igenpart; }
uint8_t getTrackInfo() const { return trackInfo_; }
Expand Down
11 changes: 7 additions & 4 deletions SimG4Core/Application/plugins/OscarMTProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void OscarMTProducer::produce(edm::Event& e, const edm::EventSetup& es) {

if (0 < m_verbose) {
edm::LogVerbatim("SimG4CoreApplication")
<< "Produced " << p2->size() << " SimVertecies: position(cm), time(s), parentID, vertexID, processType";
<< "Produced " << p2->size() << " SimVertices: position(cm), time(s), parentID, vertexID, processType";
if (1 < m_verbose) {
int nn = p2->size();
for (int i = 0; i < nn; ++i) {
Expand All @@ -260,12 +260,15 @@ void OscarMTProducer::produce(edm::Event& e, const edm::EventSetup& es) {
}
edm::LogVerbatim("SimG4CoreApplication")
<< "Produced " << p1->size()
<< " SimTracks: pdg, 4-momentum(GeV), vertexID, mcTruthID, flagBoundary, trackID at boundary";
<< " SimTracks: G4 Id, pdg, 4-momentum(GeV), vertexID, mcTruthID, crossedBoundary, trackID at boundary, from "
"backscattering, isPrimary, getPrimary";
if (1 < m_verbose) {
int nn = p1->size();
for (int i = 0; i < nn; ++i) {
edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i] << " " << (*p1)[i].crossedBoundary() << " "
<< (*p1)[i].getIDAtBoundary();
edm::LogVerbatim("Track") << " " << i << ". " << (*p1)[i].trackId() << " " << (*p1)[i] << " "
<< (*p1)[i].crossedBoundary() << " " << (*p1)[i].getIDAtBoundary() << " "
<< (*p1)[i].isFromBackScattering() << " " << (*p1)[i].isPrimary() << " "
<< (*p1)[i].getPrimaryID();
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions SimG4Core/Notification/src/SimTrackManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void SimTrackManager::addTrack(TrackWithHistory* iTrack, const G4Track* track, b
std::pair<int, int> thePair(iTrack->trackID(), iTrack->parentID());
idsave.push_back(thePair);
if (inHistory) {
auto info = static_cast<const TrackInformation *>(track->GetUserInformation());
auto info = static_cast<const TrackInformation*>(track->GetUserInformation());
if (info->isInTrkFromBackscattering())
iTrack->setFromBackScattering();
// set there *for all the tracks* the genParticle ID associated with the G4Track
Expand Down Expand Up @@ -131,18 +131,18 @@ void SimTrackManager::storeTracks() {
void SimTrackManager::reallyStoreTracks() {
// loop over the (now ordered) vector and really save the tracks
#ifdef DebugLog
edm::LogVerbatim("SimTrackManager") << "reallyStoreTracks() NtracksWithHistory= " << m_trackContainer->size();
edm::LogVerbatim("SimTrackManager") << "reallyStoreTracks() NtracksWithHistory= " << m_trackContainer.size();
#endif

int nn = m_endPoints.size();
for (auto& trkH : m_trackContainer) {
// at this stage there is one vertex per track,
// so the vertex id of track N is also N
int iParentID = trkH->parentID();
int ig = trkH->genParticleID(); // filled only for primary tracks
int ig = trkH->genParticleID(); // filled only for primary tracks
bool isBackScatter = trkH->isFromBackScattering();
bool isPrimary = trkH->isPrimary();
int primaryGenPartId = trkH->getPrimaryID(); // filled if the G4Track had this info
int primaryGenPartId = trkH->getPrimaryID(); // filled if the G4Track had this info
int ivertex = getOrCreateVertex(trkH, iParentID);

auto ptr = trkH;
Expand Down Expand Up @@ -319,7 +319,7 @@ void SimTrackManager::cleanTracksWithHistory() {
std::stable_sort(idsave.begin(), idsave.end());

#ifdef DebugLog
LogDebug("SimTrackManager") << " SimTrackManager::cleanTracksWithHistory knows " << m_trksForThisEvent->size()
LogDebug("SimTrackManager") << " SimTrackManager::cleanTracksWithHistory knows " << m_trackContainer.size()
<< " tracks with history before branching";
for (unsigned int it = 0; it < m_trackContainer.size(); it++) {
LogDebug("SimTrackManager") << " 1 - Track in position " << it << " G4 track number "
Expand Down
2 changes: 1 addition & 1 deletion SimG4Core/Notification/src/TmpSimEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void TmpSimEvent::load(edm::SimTrackContainer& c) const {
int id = trk->id();
bool isBackScatter = trk->isFromBackScattering();
bool isPrimary = trk->isPrimary();
int primaryGenPartId = trk->getPrimaryID(); // filled if the G4Track had this info
int primaryGenPartId = trk->getPrimaryID(); // filled if the G4Track had this info
// ip = particle ID as PDG
// p = 4-momentum in GeV
// iv = corresponding TmpSimVertex index
Expand Down

0 comments on commit 774e317

Please sign in to comment.