Skip to content

Commit

Permalink
Systematic classification of different BTL hit types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocos committed Jul 28, 2023
1 parent 37c1c54 commit c6eabe5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 53 deletions.
40 changes: 11 additions & 29 deletions SimG4CMS/Forward/src/MtdSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,41 +106,23 @@ int MtdSD::getTrackID(const G4Track* aTrack) {
trkInfo->Print();
#endif
if (rname == "FastTimerRegionSensBTL") {
if (trkInfo->isInTrkFromBackscattering()) {
theID = trkInfo->mcTruthID() + k_idFromCaloOffset;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->idAtBTLentrance() << ":" << theID;
#endif
return theID;
}
if (trkInfo->isBTLlooper()) {
theID = trkInfo->mcTruthID() + k_idloopOffset;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->idAtBTLentrance() << ":" << theID;
#endif
return theID;
theID = trkInfo->mcTruthID();
if (trkInfo->isExtSecondary() && !trkInfo->isInTrkFromBackscattering()) {
theID += k_idsecOffset;
} else if (trkInfo->isInTrkFromBackscattering()) {
theID += k_idFromCaloOffset;
} else if (trkInfo->isBTLlooper()) {
theID += k_idloopOffset;
}
if (!trkInfo->isBTLdaughter() && trkInfo->mcTruthID() != aTrack->GetTrackID()) {
theID = trkInfo->mcTruthID() + k_idsecOffset;
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->idAtBTLentrance() << ":" << theID;
edm::LogVerbatim("MtdSim") << "MtdSD: Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->mcTruthID() << ":" << theID;
#endif
return theID;
}
if (trkInfo->isBTLdaughter()) {
theID = trkInfo->mcTruthID();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "Track ID: " << aTrack->GetTrackID()
<< " BTL Track ID: " << trkInfo->idAtBTLentrance() << ":" << theID;
#endif
}
} else if (rname == "FastTimerRegionSensETL") {
theID = trkInfo->getIDonCaloSurface();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "ETL Track ID: " << trkInfo->getIDonCaloSurface() << ":" << theID;
edm::LogVerbatim("MtdSim") << "MtdSD: Track ID: " << aTrack->GetTrackID()
<< " ETL Track ID: " << trkInfo->mcTruthID() << ":" << theID;
#endif
} else {
throw cms::Exception("MtdSDError") << "MtdSD called in incorrect region " << rname;
Expand Down
5 changes: 1 addition & 4 deletions SimG4Core/Application/src/Phase2SteppingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,14 @@ void Phase2SteppingAction::UserSteppingAction(const G4Step* aStep) {
TrackInformation* trkinfo = static_cast<TrackInformation*>(theTrack->GetUserInformation());
if (!trkinfo->isFromTtoBTL() && !trkinfo->isFromBTLtoT()) {
trkinfo->setFromTtoBTL();
trkinfo->setIdAtBTLentrance(trkinfo->mcTruthID());
#ifdef DebugLog
LogDebug("SimG4CoreApplication") << "Setting flag for Tracker -> BTL " << trkinfo->isFromTtoBTL()
<< " IdAtBTLentrance = " << trkinfo->idAtBTLentrance();
<< " IdAtBTLentrance = " << trkinfo->mcTruthID();
#endif
} else {
trkinfo->setBTLlooper();
trkinfo->setIdAtBTLentrance(trkinfo->mcTruthID());
#ifdef DebugLog
LogDebug("SimG4CoreApplication") << "Setting flag for BTL looper " << trkinfo->isBTLlooper();
trkinfo->Print();
#endif
}
} else if (preStep->GetPhysicalVolume() == btl && postStep->GetPhysicalVolume() == tracker) {
Expand Down
16 changes: 6 additions & 10 deletions SimG4Core/Notification/interface/TrackInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,12 @@ class TrackInformation : public G4VUserTrackInformation {
bool isFromTtoBTL() const { return (mtdStatus_ >> 0) & 1; }
void setFromBTLtoT() { mtdStatus_ |= 1 << 1; } // 2nd bit
bool isFromBTLtoT() const { return (mtdStatus_ >> 1) & 1; }
void setBTLdaughter() { mtdStatus_ |= 1 << 2; } // 3rd bit
bool isBTLdaughter() const { return (mtdStatus_ >> 2) & 1; }
void setBTLlooper() { mtdStatus_ |= 1 << 3; } // 4th bit
bool isBTLlooper() const { return (mtdStatus_ >> 3) & 1; }
void setInTrkFromBackscattering() { mtdStatus_ |= 1 << 4; } // 5th bit
bool isInTrkFromBackscattering() const { return (mtdStatus_ >> 4) & 1; }

int idAtBTLentrance() const { return idAtBTLentrance_; }
void setIdAtBTLentrance(int id) { idAtBTLentrance_ = id; }
void setBTLlooper() { mtdStatus_ |= 1 << 2; } // 3th bit
bool isBTLlooper() const { return (mtdStatus_ >> 2) & 1; }
void setInTrkFromBackscattering() { mtdStatus_ |= 1 << 3; } // 4th bit
bool isInTrkFromBackscattering() const { return (mtdStatus_ >> 3) & 1; }
void setExtSecondary() { mtdStatus_ |= 1 << 4; } //5th bit
bool isExtSecondary() const { return (mtdStatus_ >> 4) & 1; }

void Print() const override;

Expand All @@ -121,7 +118,6 @@ class TrackInformation : public G4VUserTrackInformation {
int mcTruthID_{-1};
int caloSurfaceParticlePID_{0};
int castorHitPID_{0};
int idAtBTLentrance_{0};
uint8_t mtdStatus_{0};
double genParticleP_{0.};
double caloSurfaceParticleP_{0.};
Expand Down
17 changes: 9 additions & 8 deletions SimG4Core/Notification/src/MCTruthUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ void MCTruthUtil::secondary(G4Track *aTrack, const G4Track &mother, int flag) {
trkInfo->setCastorHitPID(motherInfo->getCastorHitPID());
}

// manage ID of tracks in BTL to map them to SimTracks to be stored
if (isInBTL(aTrack)) {
trkInfo->setBTLdaughter();
if (motherInfo->isFromTtoBTL() || motherInfo->isBTLdaughter()) {
trkInfo->setIdAtBTLentrance(motherInfo->mcTruthID());
}
LogDebug("SimG4CoreApplication") << "MCTruthUtil: secondary in BTL " << trkInfo->isBTLdaughter()
<< " from mother ID " << trkInfo->idAtBTLentrance();
// for MTD
if (!trkInfo->isPrimary() && !isInBTL(aTrack)) {
trkInfo->setExtSecondary();
}
if (motherInfo->isExtSecondary()) {
trkInfo->setExtSecondary();
}
if (motherInfo->isBTLlooper()) {
trkInfo->setBTLlooper();
}
if (motherInfo->isInTrkFromBackscattering()) {
trkInfo->setInTrkFromBackscattering();
Expand Down
3 changes: 1 addition & 2 deletions SimG4Core/Notification/src/TrackInformation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ void TrackInformation::Print() const {
<< " idLastVolume = " << idLastVolume_ << "\n"
<< " isFromTtoBTL = " << isFromTtoBTL() << "\n"
<< " isFromBTLtoT = " << isFromBTLtoT() << "\n"
<< " isBTLdaughter = " << isBTLdaughter() << "\n"
<< " isBTLlooper = " << isBTLlooper() << "\n"
<< " isInTrkFromBackscattering = " << isInTrkFromBackscattering()
<< "\n"
<< " idAtBTLentrance = " << idAtBTLentrance_;
<< " isExtSecondary = " << isExtSecondary();
}

0 comments on commit c6eabe5

Please sign in to comment.