Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-20 03:14:15

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