CMS 3D CMS Logo

MCTruthUtil.cc
Go to the documentation of this file.
3 
5 #include "G4Track.hh"
6 
7 void MCTruthUtil::primary(G4Track *aTrack) {
8  TrackInformation *trkInfo = new TrackInformation();
9  trkInfo->setPrimary(true);
10  trkInfo->setStoreTrack();
11  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
12  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
13  trkInfo->setMCTruthID(aTrack->GetTrackID());
14  aTrack->SetUserInformation(trkInfo);
15 }
16 
17 void MCTruthUtil::secondary(G4Track *aTrack, const G4Track &mother, int flag) {
18  auto motherInfo = static_cast<const TrackInformation *>(mother.GetUserInformation());
19  auto trkInfo = new TrackInformation();
20 
21  // Take care of cascade decays
22  if (flag == 1) {
23  trkInfo->setPrimary(true);
24  trkInfo->setStoreTrack();
25  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
26  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
27  trkInfo->setMCTruthID(aTrack->GetTrackID());
28  } else {
29  // secondary
30  trkInfo->setGenParticlePID(motherInfo->genParticlePID());
31  trkInfo->setGenParticleP(motherInfo->genParticleP());
32  trkInfo->setMCTruthID(motherInfo->mcTruthID());
33  }
34 
35  // Store if decay or conversion
36  if (flag > 0) {
37  trkInfo->setStoreTrack();
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  // for MTD
58  if (!trkInfo->isPrimary() && !isInBTL(aTrack)) {
59  trkInfo->setExtSecondary();
60  }
61  if (motherInfo->isExtSecondary()) {
62  trkInfo->setExtSecondary();
63  }
64  if (motherInfo->isBTLlooper()) {
65  trkInfo->setBTLlooper();
66  }
67  if (motherInfo->isInTrkFromBackscattering()) {
68  trkInfo->setInTrkFromBackscattering();
69  }
70 
71  aTrack->SetUserInformation(trkInfo);
72 #ifdef EDM_ML_DEBUG
73  LogTrace("SimG4CoreApplication") << "MCTruthUtil called for " << aTrack->GetTrackID() << " mother "
74  << motherInfo->isPrimary() << " flag " << flag;
75  trkInfo->Print();
76 #endif
77 }
78 
79 bool MCTruthUtil::isInBTL(const G4Track *aTrack) {
80  bool out = false;
81  G4String tName(aTrack->GetVolume()->GetLogicalVolume()->GetRegion()->GetName());
82  if (tName == "FastTimerRegionBTL" || tName == "FastTimerRegionSensBTL") {
83  out = true;
84  }
85  return out;
86 }
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:17
void setGenParticlePID(int id)
static bool isInBTL(const G4Track *)
Definition: MCTruthUtil.cc:79
void setPrimary(bool v)
#define LogTrace(id)
void setMCTruthID(int id)
void setGenParticleP(double p)
static void primary(G4Track *aPrimary)
Definition: MCTruthUtil.cc:7