SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
PairConvFilter.cc
Go to the documentation of this file.
1 #include "PairConvFilter.hh"
2 
3 //------------//
4 // Geant4 //
5 //------------//
6 #include "G4RunManager.hh"
7 
8 namespace slic {
9 
10 G4ClassificationOfNewTrack PairConvFilter::stackingClassifyNewTrack(
11  const G4Track *track, const G4ClassificationOfNewTrack &currentTrackClass) {
12 
13  if (track == currentTrack_) {
14  currentTrack_ = nullptr;
15  //std::cout << "[ PairConvFilter ]: Pushing track to waiting stack."
16  // << std::endl;
17  return fWaiting;
18  }
19 
20  // Use current classification by default so values from other plugins are
21  // not overridden.
22  return currentTrackClass;
23 }
24 
25 void PairConvFilter::stepping(const G4Step *step) {
26 
27  if (hasPairConv_) return;
28 
29  // Get the track associated with this step.
30  auto track{step->GetTrack()};
31 
32  // Get the particle type.
33  auto particleName{track->GetParticleDefinition()->GetParticleName()};
34 
35  // Get the kinetic energy of the particle.
36  auto incidentParticleEnergy{step->GetPostStepPoint()->GetTotalEnergy()};
37 
38  auto pdgID{track->GetParticleDefinition()->GetPDGEncoding()};
39 
40  // Get the volume the particle is in.
41  auto volume{track->GetVolume()};
42  auto volumeName{volume->GetName()};
43 
44  /*
45  std::cout << "*******************************" << std::endl;
46  std::cout << "* Step " << track->GetCurrentStepNumber() << std::endl;
47  std::cout << "********************************\n"
48  << "\tTotal energy of " << particleName << " ( PDG ID: " << pdgID
49  << " ) : " << incidentParticleEnergy << " MeV\n"
50  << "\tTrack ID: " << track->GetTrackID() << "\n"
51  << "\tParticle currently in " << volumeName << "\n"
52  << "\tPost step process: "
53  << step->GetPostStepPoint()->GetStepStatus() << std::endl;*/
54 
55  // Get the PDG ID of the track and make sure it's a photon. If another
56  // particle type is found, push it to the waiting stack until the photon has
57  // been processed.
58  if (pdgID != 22) {
59  currentTrack_ = track;
60  track->SetTrackStatus(fSuspend);
61  return;
62  }
63 
64  // Only conversions that happen in the target, and layers 1-3
65  // of the tracker are of interest. If the photon has propagated past
66  // the second layer and didn't convert, kill the event.
67  // TODO: OM: This really should be done with regions.
68  if (volumeName.find("module_L4") != std::string::npos) {
69  //std::cout << "[ PairConvFilter ]: Photon is beyond the sensitive"
70  // << " detectors of interest. Killing event." << std::endl;
71  track->SetTrackStatus(fKillTrackAndSecondaries);
72  G4RunManager::GetRunManager()->AbortEvent();
73  return;
74  } else if ((volumeName.find("module_L1") == std::string::npos) &&
75  (volumeName.find("module_L2") == std::string::npos) &&
76  (volumeName.find("module_L3") == std::string::npos)) {
77  //std::cout << "[ PairConvFilter ]: Photon is not within sensitive "
78  // << " detectors of interest." << std::endl;
79  return;
80  }
81 
82  // Check if any secondaries were produced in the volume.
83  const std::vector<const G4Track *> *secondaries =
84  step->GetSecondaryInCurrentStep();
85 
86  //std::cout << "[ PairConvFilter ]: "
87  // << particleName << " produced " << secondaries->size()
88  // << " secondaries." << std::endl;
89 
90  // If the particle didn't produce any secondaries, stop processing
91  // the event.
92  if (secondaries->size() == 0) {
93  //std::cout << "[ PairConvFilter ]: "
94  // << "Primary did not produce secondaries!"
95  // << std::endl;
96  return;
97  }
98 
99  auto processName{(*secondaries)[0]->GetCreatorProcess()->GetProcessName()};
100  if (processName.compareTo("conv") == 0) {
101  hasPairConv_ = true;
102  ++pairConvCount_;
103  std::cout << "[ PairConvFilter ]: "
104  << "WAB converted in " << volumeName << std::endl;
105 
106  } else {
107  track->SetTrackStatus(fKillTrackAndSecondaries);
108  G4RunManager::GetRunManager()->AbortEvent();
109  return;
110  }
111 }
112 
113 void PairConvFilter::endEvent(const G4Event *) { hasPairConv_ = false; }
114 
115 void PairConvFilter::endRun(const G4Run* run) {
116  std::cout << "[ PairConvFilter ]: "
117  << "Total number of pair conversions: " << pairConvCount_
118  << std::endl;
119 }
120 
121 } // namespace slic
122 
123 DECLARE_PLUGIN(slic, PairConvFilter)
#define DECLARE_PLUGIN(NS, NAME)
bool hasPairConv_
Flag that denotes whether a conversion has been found.
void endRun(const G4Run *run) final override
G4ClassificationOfNewTrack stackingClassifyNewTrack(const G4Track *, const G4ClassificationOfNewTrack &currentTrackClass) final override
short pairConvCount_
Counter to keep track of the pair conversion count.
G4Track * currentTrack_
Pointer to the current track being processed.
void endEvent(const G4Event *) final override
void stepping(const G4Step *step) final override
@ endl
Definition: LogStream.hh:26