Monte Carlo LYSO
Geant4 simulation for the LYSO calorimeter prototype
stepping.cc
Go to the documentation of this file.
1 
5  #include "stepping.hh"
6 
7 MySteppingAction::MySteppingAction(MyEventAction *eventAction) : fEventAction(eventAction)
8 {}
9 
10 
11 
12 void MySteppingAction::UserSteppingAction(const G4Step *step)
13 {
14  // Get the logical volume containing the step
15  G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
16 
17  // Get the detector construction
18  const MyDetectorConstruction *detectorConstruction = static_cast<const MyDetectorConstruction*> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
19 
20  // Settings depending on run mode type
21  G4int modeType = static_cast<const MyPrimaryGenerator*>(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction())->GetModeType();
22  switch(modeType)
23  {
24  case 20: //
25  case 21:
26  SetTimeOfDecay(step);
27  break;
28  case 22: // 176Lu decay with trigger
29  SetTimeOfDecay(step);
30  SteppingForLuDecayBulkSignature(step, volume, detectorConstruction);
31  break;
32  case 30: // Cosmic rays
33  SteppingForCosmicRaysDetectors(step, volume, detectorConstruction);
34  break;
35  }
36 
37  // Get the scoring volume (i.e. the scintillator logic volume)
38  G4LogicalVolume *fScoringVolume = detectorConstruction->GetScoringVolume();
39 
40 
41  // Here I'm selecting that I want data ONLY in the crystal
42  if(volume != fScoringVolume)
43  return;
44 
45  // Do not register optical photons (PDGEncoding == -22), they DON'T respect energy conservation
46  if(step->GetTrack()->GetParticleDefinition()->GetPDGEncoding()==-22)
47  return;
48 
49  // Store time and position of arrival of primary gamma (or daughters)
50  if(step->GetPreStepPoint()->GetStepStatus() == fGeomBoundary)
51  {
52  G4double newtimein = step->GetPreStepPoint()->GetGlobalTime();
53  G4ThreeVector newposin = step->GetPreStepPoint()->GetPosition();
54 
55  G4double newtimeinter = step->GetPostStepPoint()->GetGlobalTime();
56  G4ThreeVector newposinter = step->GetPostStepPoint()->GetPosition();
57 
58  fEventAction->SetArrivalandFirstInteraction(newtimein, newposin, newtimeinter, newposinter);
59  }
60 
61  // Sum the energy deposited in the step
62  G4double edep = step->GetTotalEnergyDeposit();
63  fEventAction->AddEdep(edep);
64 
65  // Check if it is the maximum deposition of energy per unit length.
66  // If yes it will be stored with its position.
67  G4double dx = step->GetStepLength();
68  if(dx == 0) return;
69 
70  G4ThreeVector maxedeppos = (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition())/2;
71  fEventAction->SetMaxEdep(edep/dx, maxedeppos);
72 }
73 
74 
75 
76 void MySteppingAction::SteppingForCosmicRaysDetectors(const G4Step *step, G4LogicalVolume *volume, const MyDetectorConstruction *detectorConstruction)
77 {
78  // Get the scoring volume (i.e. the cosmic rays detector logic volume)
79  G4LogicalVolume *fCosmicVolume = detectorConstruction->GetCosmicTriggerVolume();
80 
81  // Here I'm selecting that I want data ONLY for cosmic rays detectors
82  if(!fCosmicVolume || volume != fCosmicVolume)
83  return;
84 
85  // Should see this condition. Now I'm selecting only primary muon
86  if(step->GetTrack()->GetTrackID() != 1)
87  return;
88 
89  // Up (0) or Bottom (1) detector
90  G4bool isUpOrBottom = step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber();
91 
92  if(!isUpOrBottom) // up
93  fEventAction->SetCosmicTriggerUp(true);
94  else // bottom
95  {
96  fEventAction->SetCosmicTriggerBottom(true);
97  step->GetTrack()->SetTrackStatus(fStopAndKill);
98  }
99 }
100 
101 
102 
103 void MySteppingAction::SetTimeOfDecay(const G4Step *step)
104 {
105  // Set time = 0 ns also for primary data. Instantaneous decay
106  if(step->GetTrack()->GetParentID() == 0 && step->IsFirstStepInVolume())
107  {
108  G4double newtimein = step->GetPreStepPoint()->GetGlobalTime();
109  G4ThreeVector newposin = step->GetPreStepPoint()->GetPosition();
110 
111  fEventAction->SetArrivalandFirstInteraction(newtimein, newposin, newtimein, newposin);
112  }
113 
114  // Find if the primary is killed by radioactive decay
115  if(step->GetTrack()->GetParentID() == 0 && step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessType() == 6)
116  {
117  const auto* fDecayProducts = step->GetSecondaryInCurrentStep();
118 
119  for(auto i = 0; i < fDecayProducts->size(); i++)
120  {
121  G4Track* modifiableTrack = const_cast<G4Track*>((*fDecayProducts)[i]);
122  modifiableTrack->SetGlobalTime(0.);
123  }
124  }
125 }
126 
127 
128 
129 void MySteppingAction::SteppingForLuDecayBulkSignature(const G4Step *step, G4LogicalVolume *volume, const MyDetectorConstruction *detectorConstruction)
130 {
131  // Get the scoring volume (i.e. the cosmic rays detector logic volume)
132  G4LogicalVolume *fSiVolume = detectorConstruction->GetDecayTriggerVolume();
133 
134  // Here I'm selecting that I want data ONLY for Si detectors
135  if(volume != fSiVolume)
136  return;
137 
138  // Save only electrons
139  if(step->GetTrack()->GetParticleDefinition()->GetPDGEncoding() != 11)
140  return;
141 
142  // Save only detector Front-57, default for 176Lu decay Si-Trigger runs
143  if(step->GetPreStepPoint()->GetTouchableHandle()->GetVolume(2)->GetTranslation().z() > GS::zScintillator || step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(2) != 57)
144  return;
145 
146  fEventAction->SetDecayTriggerSi(true);
147 }
Mandatory user initialization concrete class of G4VUserDetectorConstruction. It represents the whole ...
Definition: construction.hh:33
G4LogicalVolume * GetScoringVolume() const
Get the scoring volume. It will be used by MySteppingAction::UserSteppingAction().
Definition: construction.hh:46
User action concrete class of G4UserEventAction. In addition to defining procedures executed at the s...
Definition: event.hh:26
void SetArrivalandFirstInteraction(G4double newtimein, G4ThreeVector newposin, G4double newtimeinter, G4ThreeVector newposinter)
Stores the time and the position of arrival to the crystal of the primary gamma.
Definition: event.hh:55
void AddEdep(G4double edep)
For every G4Step inside the crystal it sums the energy deposit.
Definition: event.hh:75
void SetMaxEdep(G4double edepondx, G4ThreeVector maxedeppos)
Stores the maximum deposit of energy per unit length and its position inside the crystal.
Definition: event.hh:84
Mandatory user action concrete class of G4VUserPrimaryGeneratorAction. It defines the settings for th...
Definition: generator.hh:25
void UserSteppingAction(const G4Step *step) override
For every step updates and stores quantities about the physics inside the crystal by calling the meth...
Definition: stepping.cc:12
MyEventAction * fEventAction
Pointer to the MyEventAction object.
Definition: stepping.hh:43
MySteppingAction(MyEventAction *eventAction)
Constructor of the class.
Definition: stepping.cc:7
constexpr G4double zScintillator
z-position of the scintillator crystal.
Declaration of the class MySteppingAction.