CMS 3D CMS Logo

MCTruthUtil.cc
Go to the documentation of this file.
1 
4 
6 #include "G4Track.hh"
7 
8 void MCTruthUtil::primary(G4Track *aTrack) {
9  TrackInformation *trkInfo = new TrackInformation();
10  trkInfo->setPrimary(true);
11  trkInfo->setStoreTrack();
12  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
13  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
14  trkInfo->setMCTruthID(aTrack->GetTrackID());
15  aTrack->SetUserInformation(trkInfo);
16 }
17 
18 void MCTruthUtil::secondary(G4Track *aTrack, const G4Track &mother, int flag) {
19  auto motherInfo = static_cast<const TrackInformation *>(mother.GetUserInformation());
20  auto trkInfo = new TrackInformation();
21  LogDebug("SimG4CoreApplication") << "MCTruthUtil called for " << aTrack->GetTrackID() << " mother "
22  << motherInfo->isPrimary() << " flag " << flag;
23 
24  // Take care of cascade decays
25  if (flag == 1) {
26  trkInfo->setPrimary(true);
27  trkInfo->setStoreTrack();
28  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
29  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
30  trkInfo->setMCTruthID(aTrack->GetTrackID());
31  } else {
32  // secondary
33  trkInfo->setGenParticlePID(motherInfo->genParticlePID());
34  trkInfo->setGenParticleP(motherInfo->genParticleP());
35  trkInfo->setMCTruthID(motherInfo->mcTruthID());
36  }
37 
38  // Store if decay or conversion
39  if (flag > 0) {
40  trkInfo->setStoreTrack();
41  trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
42  motherInfo->getIDCaloVolume(),
43  motherInfo->getIDLastVolume(),
44  aTrack->GetDefinition()->GetPDGEncoding(),
45  aTrack->GetMomentum().mag());
46  } else {
47  // transfer calo ID from mother (to be checked in TrackingAction)
48  trkInfo->setIDonCaloSurface(motherInfo->getIDonCaloSurface(),
49  motherInfo->getIDCaloVolume(),
50  motherInfo->getIDLastVolume(),
51  motherInfo->caloSurfaceParticlePID(),
52  motherInfo->caloSurfaceParticleP());
53  }
54 
55  // for Run1 and Run2
56  if (motherInfo->hasCastorHit()) {
57  trkInfo->setCastorHitPID(motherInfo->getCastorHitPID());
58  }
59 
60  // manage ID of tracks in BTL to map them to SimTracks to be stored
61  if (isInBTL(aTrack)) {
62  if ((motherInfo->storeTrack() && motherInfo->isFromTtoBTL()) || motherInfo->isBTLdaughter()) {
63  trkInfo->setBTLdaughter();
64  trkInfo->setIdAtBTLentrance(motherInfo->idAtBTLentrance());
65  LogDebug("SimG4CoreApplication") << "NewTrackAction: secondary in BTL " << trkInfo->isBTLdaughter()
66  << " from mother ID " << trkInfo->idAtBTLentrance();
67  }
68  }
69 
70  aTrack->SetUserInformation(trkInfo);
71 }
72 
73 bool MCTruthUtil::isInBTL(const G4Track *aTrack) {
74  bool out = false;
75  G4String tName(aTrack->GetVolume()->GetLogicalVolume()->GetRegion()->GetName());
76  if (tName == "FastTimerRegionBTL" || tName == "FastTimerRegionSensBTL") {
77  out = true;
78  }
79  return out;
80 }
void setStoreTrack()
can only be set to true, cannot be reset to false!
static void secondary(G4Track *aSecondary, const G4Track &mother, int)
Definition: MCTruthUtil.cc:18
void setGenParticlePID(int id)
static bool isInBTL(const G4Track *)
Definition: MCTruthUtil.cc:73
void setPrimary(bool v)
void setMCTruthID(int id)
void setGenParticleP(double p)
static void primary(G4Track *aPrimary)
Definition: MCTruthUtil.cc:8
#define LogDebug(id)