OpDetSensitiveDetector.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file OpDetSensitiveDetector.cxx
3 //
4 /// \author bjpjones@mit.edu
5 ////////////////////////////////////////////////////////////////////////
6 // Implementation of the OpDetSensitiveDetector
7 //
8 // See comments in OpDetSensitiveDetector.h
9 //
10 // Ben Jones, MIT, 06/04/2010
11 //
12 
14 #include "Geant4/G4SDManager.hh"
18 
19 namespace {
20 
21  /// Converts a photon `energy` [eV] into its Wavelength [nm]
22  constexpr double Wavelength(double energy);
23 
24 } // local namespace
25 
26 namespace larg4 {
27 
29  bool useLitePhotons /* = false */)
30  : G4VSensitiveDetector(DetectorUniqueName), fUseLitePhotons(useLitePhotons)
31  {
32  // Register self with sensitive detector manager
33  G4SDManager::GetSDMpointer()->AddNewDetector(this);
34 
35  // Get instances of singleton classes
38  }
39 
40  //--------------------------------------------------------
41 
42  void
43  OpDetSensitiveDetector::AddLitePhoton(G4Step const* aStep, int OpDet)
44  {
45 
46  double const time = aStep->GetTrack()->GetGlobalTime();
47 
48  // the guideline: if it's VUV (~128 nm) is direct, otherwise it is reflected
49  double const energy = aStep->GetTrack()->GetVertexKineticEnergy() / CLHEP::eV;
50  bool const reflected = Wavelength(energy) > 200.0; // nm
51 
52  // Add this photon to the detected photons table
53  fThePhotonTable->AddLitePhoton(OpDet, static_cast<int>(time), 1, reflected);
54 
55  } // OpDetSensitiveDetector::AddLitePhoton()
56 
57  //--------------------------------------------------------
58 
59  void
60  OpDetSensitiveDetector::AddPhoton(G4Step const* aStep, int OpDet)
61  {
62  sim::OnePhoton ThePhoton;
63 
64  // Get photon data to store in the hit
65 
66  ThePhoton.SetInSD = true;
67 
68  auto const& track = *(aStep->GetTrack());
69  auto const& startPos = track.GetVertexPosition();
70  ThePhoton.InitialPosition = {startPos.x(), startPos.y(), startPos.z()};
71 
72  //ThePhoton.Time = track.GetGlobalTime() - fGlobalTimeOffset;
73  ThePhoton.Time = track.GetGlobalTime();
74 
75  ThePhoton.Energy = track.GetVertexKineticEnergy();
76 
77  // Lookup which OpDet we are in
78  G4StepPoint const* preStepPoint = aStep->GetPreStepPoint();
79 
80  // Store relative position on the photon detector
81  G4ThreeVector worldPosition = preStepPoint->GetPosition();
82  G4ThreeVector localPosition =
83  preStepPoint->GetTouchableHandle()->GetHistory()->GetTopTransform().TransformPoint(
84  worldPosition);
85  ThePhoton.FinalLocalPosition = {
86  localPosition.x() / CLHEP::cm, localPosition.y() / CLHEP::cm, localPosition.z() / CLHEP::cm};
87 
88  // Add this photon to the detected photons table
89  fThePhotonTable->AddPhoton(OpDet, std::move(ThePhoton));
90 
91  } // OpDetSensitiveDetector::AddPhoton()
92 
93  //--------------------------------------------------------
94 
95  G4bool
96  OpDetSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
97  {
98  // Lookup which OpDet we are in
99  int const OpDet = fTheOpDetLookup->GetOpDet(aStep->GetPreStepPoint()->GetPhysicalVolume());
100 
101  // Add this photon to the detected photons table
102  if (fUseLitePhotons)
103  AddLitePhoton(aStep, OpDet);
104  else
105  AddPhoton(aStep, OpDet);
106 
107  // Kill this photon track
108  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
109 
110  return true;
111  }
112 
113  //--------------------------------------------------------
114 
115  void
117  {}
118 
119 }
120 
121 //--------------------------------------------------------
122 namespace {
123 
124  constexpr double
125  Wavelength(double energy)
126  {
127 
128  // SI 2019 (eV nm):
129  constexpr double hc = 6.62607015e-34 * 299792458.0 / 1.602176634e-19 * 1e9;
130 
131  return hc / energy; // nm
132 
133  } // Wavelength()
134 
135 } // local namespace
136 
137 //--------------------------------------------------------
static constexpr double cm
Definition: Units.h:68
bool const fUseLitePhotons
Fill simplified lite photons instead of full information photons.
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
Geant4 interface.
void AddLitePhoton(G4Step const *aStep, int OpDet)
Adds the photon at the specified step with reduced information.
geo::Point_t InitialPosition
Scintillation position in world coordinates [cm].
Definition: SimPhotons.h:67
Simulation objects for optical detectors.
void AddPhoton(size_t opchannel, sim::OnePhoton &&photon, bool Reflected=false)
static constexpr double eV
Definition: Units.h:127
def move(depos, offset)
Definition: depos.py:107
void AddLitePhoton(int opchannel, int time, int nphotons, bool Reflected=false)
static OpDetLookup * Instance()
Definition: OpDetLookup.cxx:33
void AddPhoton(G4Step const *aStep, int OpDet)
Adds the photon at the specified step with full information.
int GetOpDet(G4VPhysicalVolume *)
Definition: OpDetLookup.cxx:48
static OpDetPhotonTable * Instance(bool LitePhotons=false)
bool SetInSD
Whether the photon reaches the sensitive detector.
Definition: SimPhotons.h:88
geo::OpticalPoint_t FinalLocalPosition
Where photon enters the optical detector in local coordinates [cm].
Definition: SimPhotons.h:75
virtual void Initialize(G4HCofThisEvent *)
OpDetSensitiveDetector(G4String name, bool useLitePhotons=false)
float Energy
Scintillation photon energy [GeV].
Definition: SimPhotons.h:82
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)