File indexing completed on 2023-08-06 22:43:36
0001 #include "SimG4Core/Notification/interface/MCTruthUtil.h"
0002 #include "SimG4Core/Notification/interface/TrackInformation.h"
0003
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "G4Track.hh"
0006
0007 void MCTruthUtil::primary(G4Track *aTrack) {
0008 TrackInformation *trkInfo = new TrackInformation();
0009 trkInfo->setPrimary(true);
0010 trkInfo->setStoreTrack();
0011 trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
0012 trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
0013 trkInfo->setMCTruthID(aTrack->GetTrackID());
0014 aTrack->SetUserInformation(trkInfo);
0015 }
0016
0017 void MCTruthUtil::secondary(G4Track *aTrack, const G4Track &mother, int flag) {
0018 auto motherInfo = static_cast<const TrackInformation *>(mother.GetUserInformation());
0019 auto trkInfo = new TrackInformation();
0020
0021
0022 if (flag == 1) {
0023 trkInfo->setPrimary(true);
0024 trkInfo->setStoreTrack();
0025 trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
0026 trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
0027 trkInfo->setMCTruthID(aTrack->GetTrackID());
0028 } else {
0029
0030 trkInfo->setGenParticlePID(motherInfo->genParticlePID());
0031 trkInfo->setGenParticleP(motherInfo->genParticleP());
0032 trkInfo->setMCTruthID(motherInfo->mcTruthID());
0033 }
0034
0035
0036 if (flag > 0) {
0037 trkInfo->setStoreTrack();
0038 trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
0039 motherInfo->getIDCaloVolume(),
0040 motherInfo->getIDLastVolume(),
0041 aTrack->GetDefinition()->GetPDGEncoding(),
0042 aTrack->GetMomentum().mag());
0043 } else {
0044
0045 trkInfo->setIDonCaloSurface(motherInfo->getIDonCaloSurface(),
0046 motherInfo->getIDCaloVolume(),
0047 motherInfo->getIDLastVolume(),
0048 motherInfo->caloSurfaceParticlePID(),
0049 motherInfo->caloSurfaceParticleP());
0050 }
0051
0052
0053 if (motherInfo->hasCastorHit()) {
0054 trkInfo->setCastorHitPID(motherInfo->getCastorHitPID());
0055 }
0056
0057
0058 if (!trkInfo->isPrimary() && !isInBTL(aTrack)) {
0059 trkInfo->setExtSecondary();
0060 }
0061 if (motherInfo->isExtSecondary()) {
0062 trkInfo->setExtSecondary();
0063 }
0064 if (motherInfo->isBTLlooper()) {
0065 trkInfo->setBTLlooper();
0066 }
0067 if (motherInfo->isInTrkFromBackscattering()) {
0068 trkInfo->setInTrkFromBackscattering();
0069 }
0070
0071 aTrack->SetUserInformation(trkInfo);
0072 #ifdef EDM_ML_DEBUG
0073 LogTrace("SimG4CoreApplication") << "MCTruthUtil called for " << aTrack->GetTrackID() << " mother "
0074 << motherInfo->isPrimary() << " flag " << flag;
0075 trkInfo->Print();
0076 #endif
0077 }
0078
0079 bool MCTruthUtil::isInBTL(const G4Track *aTrack) {
0080 bool out = false;
0081 G4String tName(aTrack->GetVolume()->GetLogicalVolume()->GetRegion()->GetName());
0082 if (tName == "FastTimerRegionBTL" || tName == "FastTimerRegionSensBTL") {
0083 out = true;
0084 }
0085 return out;
0086 }