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->putInHistory();
13  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
14  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
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->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
28  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
29  } else {
30  trkInfo->setGenParticlePID(motherInfo->genParticlePID());
31  trkInfo->setGenParticleP(motherInfo->genParticleP());
32  }
33 
34  // Store if decay or conversion
35  if (flag > 0) {
36  trkInfo->setStoreTrack();
37  trkInfo->putInHistory();
38  trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
39  motherInfo->getIDCaloVolume(),
40  motherInfo->getIDLastVolume(),
41  aTrack->GetDefinition()->GetPDGEncoding(),
42  aTrack->GetMomentum().mag());
43  } else {
44  // transfer calo ID from mother (to be checked in TrackingAction)
45  trkInfo->setIDonCaloSurface(motherInfo->getIDonCaloSurface(),
46  motherInfo->getIDCaloVolume(),
47  motherInfo->getIDLastVolume(),
48  motherInfo->caloSurfaceParticlePID(),
49  motherInfo->caloSurfaceParticleP());
50  }
51 
52  // for Run1 and Run2
53  if (motherInfo->hasCastorHit()) {
54  trkInfo->setCastorHitPID(motherInfo->getCastorHitPID());
55  }
56 
57  // manage ID of tracks in BTL to map them to SimTracks to be stored
58  if (isInBTL(aTrack)) {
59  if ((motherInfo->storeTrack() && motherInfo->isFromTtoBTL()) || motherInfo->isBTLdaughter()) {
60  trkInfo->setBTLdaughter();
61  trkInfo->setIdAtBTLentrance(motherInfo->idAtBTLentrance());
62  LogDebug("SimG4CoreApplication") << "NewTrackAction: secondary in BTL " << trkInfo->isBTLdaughter()
63  << " from mother ID " << trkInfo->idAtBTLentrance();
64  }
65  }
66 
67  aTrack->SetUserInformation(trkInfo);
68 }
69 
70 bool MCTruthUtil::isInBTL(const G4Track *aTrack) {
71  bool out = false;
72  G4String tName(aTrack->GetVolume()->GetLogicalVolume()->GetRegion()->GetName());
73  if (tName == "FastTimerRegionBTL" || tName == "FastTimerRegionSensBTL") {
74  out = true;
75  }
76  return out;
77 }
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:70
void setPrimary(bool v)
void setGenParticleP(double p)
static void primary(G4Track *aPrimary)
Definition: MCTruthUtil.cc:8
#define LogDebug(id)