GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Public Member Functions
GGSIntHitSD Class Reference

Sensitive detector class for integrated hits. More...

#include <GGSIntHitSD.h>

Inheritance diagram for GGSIntHitSD:
Inheritance graph
[legend]
Collaboration diagram for GGSIntHitSD:
Collaboration graph
[legend]

Public Member Functions

 GGSIntHitSD (G4String name)
 Constructor. More...
 
 ~GGSIntHitSD ()
 Destructor.
 
void Initialize (G4HCofThisEvent *hitCollection)
 Initializes the sensitive detector. More...
 
G4bool ProcessHits (G4Step *aStep, G4TouchableHistory *ROHist)
 The hit processing method. More...
 
void EndOfEvent (G4HCofThisEvent *hitCollection)
 Sets the hits collection, as required by specifications of mother class. More...
 
void SetTimeBin (G4double time)
 Time bins setter. More...
 
const std::vector< G4double > & GetTimeBins ()
 Time bins getter. More...
 
void SetPartHitsStorage (bool store)
 Turn on or off the storage (i.e. persistency) of particle hits. More...
 
void SetTouchableIDComputer (const std::string &tidcClassName)
 Sets the touchable ID computer class. More...
 
bool GetPartHitsStorage ()
 Return current status of particle hits storage (i.e. persistence). More...
 
void SetPosHitsStorage (bool store)
 Turn on or off the storage (i.e. persistence) of position hits. More...
 
bool GetPosHitsStorage ()
 Return current status of particle hits storage (i.e. persistence). More...
 
void SetIntHitThreshold (float minEnergy)
 Sets the minimum energy for integrated hits. More...
 
void SetPartHitThreshold (float minEnergy)
 Sets the minimum energy for particle hits. More...
 
void SetPosHitThreshold (float minEnergy)
 Sets the minimum energy for position hits. More...
 

Detailed Description

Sensitive detector class for integrated hits.

This sensitive detector takes care of summing up all energy releases inside the sensitive volume it manages, so that a single hit is produced for each single volume with non-zero energy release for each event.

Definition at line 29 of file GGSIntHitSD.h.

Constructor & Destructor Documentation

GGSIntHitSD::GGSIntHitSD ( G4String  name)

Constructor.

Parameters
nameThe sensitive detector's name.

Definition at line 23 of file GGSIntHitSD.cpp.

24  : G4VSensitiveDetector(name), _intHitCollection(NULL), _timeBins(0), _intHitClass("GGSIntHit"),
25  _partHitClass("GGSPartHit"), _posHitClass("GGSPosHit"), _storePartHits(false), _storePosHits(false),
26  _idComputer(nullptr), _intHitThreshold{0.}, _partHitThreshold{0.}, _posHitThreshold{0.}, _currPartHit{nullptr} {
27 
28  collectionName.insert(name);
29  _messenger = new GGSIntHitSDMessenger(this);
30 
31  auto params = name.substr(name.find_first_of('.') + 1); // Remove volume name
32  auto secondPointPos = params.find_first_of('.');
33  if (secondPointPos != std::string::npos) {
34  // Parameters have been specified so let's handle them
35  params = params.substr(secondPointPos + 1); // Remove GGSIntHitSD
36  if (params.size() > 0) {
37  // Retrieve hit classes
38  std::string intHitClassName, partHitClassName, posHitClassName;
39  auto start = params.find_first_of('[');
40  auto end = params.find_first_of(']');
41  if (start < std::string::npos && end != std::string::npos) {
42  intHitClassName = params.substr(start + 1, end - start - 1);
43  } else {
44  throw std::runtime_error(
45  std::string("[GGSIntHitSD::GGSIntHitSD] Missing definition of custom integrated hit class in \"") + params +
46  ("\""));
47  }
48 
49  start = params.find_first_of('[', end + 1);
50  end = params.find_first_of(']', start + 1);
51  if (start != std::string::npos && end != std::string::npos) {
52  partHitClassName = params.substr(start + 1, end - start - 1);
53  } else {
54  throw std::runtime_error(
55  std::string("[GGSIntHitSD::GGSIntHitSD] Missing definition of custom particle hit class in \"") + params +
56  ("\""));
57  }
58 
59  start = params.find_first_of('[', end + 1);
60  end = params.find_first_of(']', start + 1);
61  if (start != std::string::npos && end != std::string::npos) {
62  posHitClassName = params.substr(start + 1, end - start - 1);
63  } else {
64  throw std::runtime_error(
65  std::string("[GGSIntHitSD::GGSIntHitSD] Missing definition of custom position hit class in \"") + params +
66  ("\""));
67  }
68 
69  if (intHitClassName.size() > 0) {
71  if (std::find(buildersList.begin(), buildersList.end(), intHitClassName) == buildersList.end()) {
72  throw std::runtime_error(std::string("[GGSIntHitSD::GGSIntHitSD] Integrated hit class \"") + intHitClassName +
73  "\" not found.");
74  }
75  _intHitClass = intHitClassName;
76  }
77  if (partHitClassName.size() > 0) {
79  if (std::find(buildersList.begin(), buildersList.end(), partHitClassName) == buildersList.end()) {
80  throw std::runtime_error(std::string("[GGSIntHitSD::GGSIntHitSD] Particle hit class \"") + partHitClassName +
81  "\" not found.");
82  }
83  _partHitClass = partHitClassName;
84  }
85  if (posHitClassName.size() > 0) {
87  if (std::find(buildersList.begin(), buildersList.end(), posHitClassName) == buildersList.end()) {
88  throw std::runtime_error(std::string("[GGSIntHitSD::GGSIntHitSD] Position hit class \"") + posHitClassName +
89  "\" not found.");
90  }
91  _posHitClass = posHitClassName;
92  }
93  }
94  }
95 
96  // Create the default ID computer
97  SetTouchableIDComputer("GGSUniqueTouchableIDComputer");
98 }
const std::vector< std::string > & GetListOfRegisteredBuilders()
Gets a vector containing the names of available registered builders.
Definition: GGSFactory.h:110
static GGSFactory & GetInstance()
Getter method for singleton pointer.
Definition: GGSFactory.h:71
The integrated hit SD messenger class.
void SetTouchableIDComputer(const std::string &tidcClassName)
Sets the touchable ID computer class.

Member Function Documentation

void GGSIntHitSD::EndOfEvent ( G4HCofThisEvent *  hitCollection)

Sets the hits collection, as required by specifications of mother class.

Parameters
hitCollectionThe hits collection.

Definition at line 249 of file GGSIntHitSD.cpp.

249  {
250 
251  G4int IHID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
252  hitCollection->AddHitsCollection(IHID, _intHitCollection);
253 }
bool GGSIntHitSD::GetPartHitsStorage ( )
inline

Return current status of particle hits storage (i.e. persistence).

Returns
true if particle hits are going to be stored.

Definition at line 117 of file GGSIntHitSD.h.

117 { return _storePartHits; }
bool GGSIntHitSD::GetPosHitsStorage ( )
inline

Return current status of particle hits storage (i.e. persistence).

Returns
true if particle hits are going to be stored.

Definition at line 142 of file GGSIntHitSD.h.

142 { return _storePosHits; }
const std::vector<G4double>& GGSIntHitSD::GetTimeBins ( )
inline

Time bins getter.

First element is the end time of first bin (which always starts at t=0). Last element is the ending time of last bin but one, which corresponds to start time of last bin (last bin always ends at the end of event).

Returns
Vector of time bins.

Definition at line 83 of file GGSIntHitSD.h.

83 { return _timeBins; }
void GGSIntHitSD::Initialize ( G4HCofThisEvent *  hitCollection)

Initializes the sensitive detector.

Parameters
hitCollectionUnused (needed by the interface).

Definition at line 109 of file GGSIntHitSD.cpp.

109  {
110 
111  // The hits collection is added to G4HCofThisEvent in EndOfEvent.
112  // It is automatically deleted at the end of the event so it must be recreated every time.
113  // However, G4Allocator should provide fast memory allocation for this purpose.
114  _intHitCollection = new GGSIntHitsCollection(SensitiveDetectorName, collectionName[0]);
115 }
G4THitsCollection< GGSIntHit > GGSIntHitsCollection
Alias for G4 template hits collection for GGSIntHit.
Definition: GGSIntHit.h:256
G4bool GGSIntHitSD::ProcessHits ( G4Step *  aStep,
G4TouchableHistory *  ROHist 
)

The hit processing method.

For each physical sensitive volume, this method sums up the total energy release during this step to the total releases of previous steps.

Parameters
aStepThe current step
ROHistUnused (needed by the interface).
Returns
true if energy deposit of current step is greater than 0.

Definition at line 117 of file GGSIntHitSD.cpp.

117  {
118  static const std::string routineName("GGSIntHitSD::ProcessHits");
119 
120  // The G4TouchableHistory argument of this method is non-null only if a readout geometry has been
121  // defined. Since this feature is not supported, it is currently always null.
122  // TODO: investigate the possibility to define a readout geometry
123 
124  if (aStep->GetTotalEnergyDeposit() == 0. && !_storePartHits)
125  return false;
126 
127  int touchableID = _idComputer->ComputeTouchableID(aStep);
128  G4TouchableHandle touchable = aStep->GetPreStepPoint()->GetTouchableHandle();
129  G4ThreeVector volPos = touchable->GetTranslation(); // Absolute volume translation
130  G4VPhysicalVolume *physVol = touchable->GetVolume();
131 
132  /* *** Add step to integrated hit *** */
133  GGSIntHit *intHit = nullptr;
134  bool intFound = false;
135  // Search for existing integrated hit for this volume
136  auto nIntHits = _intHitCollection->entries();
137  for (int iHit = nIntHits - 1; iHit >= 0; iHit--) {
138  intHit = (*(_intHitCollection))[iHit];
139  if (physVol == intHit->GetVolume() && touchableID == intHit->GetID() && volPos == intHit->GetAbsTranslation()) {
140  intFound = true;
141  break;
142  }
143  }
144  if (!intFound) {
145  // If we reach this point, then this is a new hit
146  intHit = GGSIntHitFactory::GetInstance().CreateObject(_intHitClass, _timeBins).release();
147  if (!intHit) {
148  throw std::runtime_error(
149  std::string("[GGSIntHitSD::ProcessHits] Can't create integrated hit of class ").append(_intHitClass));
150  }
151  // Set global hit properties
152  intHit->SetAbsTranslation(volPos);
153  intHit->SetID(touchableID);
154  intHit->SetVolume(physVol);
155  intHit->SetPartHitsStorage(_storePartHits);
156  intHit->SetPosHitsStorage(_storePosHits);
157  // Call the user initialization routine
158  intHit->UserInit(aStep);
159  // Insert the new integrated hit into the hit collection
160  _intHitCollection->insert(intHit);
161  }
162  // Add the current step to the hit
163  intHit->AddStep(*aStep);
164 
165  if (_storePartHits) {
166  /* *** Add step to particle hit *** */
167  // Create the particle hit if it does not exists, i.e. on first step inside the sensitive volume.
168  // If a particle entered in the volume in previous step and immediately got stopped but not killed then
169  // IsFirstStepInVolume for the current step will be true, so check also that kinetic energy is non-zero for pre-step
170  if (aStep->IsFirstStepInVolume() && aStep->GetPreStepPoint()->GetKineticEnergy() != 0) {
171  if (_currPartHit != nullptr) {
172  // On first step there must be no current hit
173  throw std::runtime_error("GGSIntHitSD::ProcessHit: existing particle hit on first step in sensitive volume");
174  }
175  _currPartHit = GGSPartHitFactory::GetInstance().CreateObject(_partHitClass).release();
176  if (!_currPartHit) {
177  throw std::runtime_error(
178  std::string("[GGSIntHitSD::ProcessHits] Can't create particle hit of class ").append(_partHitClass));
179  }
180  // Set global hit properties
181  _currPartHit->SetPosHitsStorage(_storePosHits);
182  }
183 
184  if (_currPartHit != nullptr) {
185  // Add the current step to the hit
186  _currPartHit->AddStep(*aStep);
187 
188  // Check if this is the last step in the volume
189  // Do not use aStep->IsLastStepInVolume(); see https://geant4-forum.web.cern.ch/t/last-step-in-a-volume/856
190  if ((aStep->GetPostStepPoint()->GetStepStatus() == G4StepStatus::fGeomBoundary &&
191  aStep->GetTrack()->GetTrackStatus() != G4TrackStatus::fStopButAlive) ||
192  aStep->GetTrack()->GetTrackStatus() == G4TrackStatus::fStopAndKill ||
193  aStep->GetTrack()->GetTrackStatus() == G4TrackStatus::fKillTrackAndSecondaries) {
194  if (_currPartHit->GetEnergyDeposit() > _partHitThreshold) {
195  // Hit above threshold: insert it into the hit collection
196  intHit->GetPartHits()->insert(_currPartHit);
197  } else {
198  // Hit below threshold: delete it
199  delete _currPartHit;
200  }
201  // Do not point at the hit anymore (at this point, it's either stored in the collection or deleted)
202  _currPartHit = nullptr;
203  }
204 
205  if (_storePosHits && aStep->GetTotalEnergyDeposit() > _posHitThreshold) {
206  /* *** Create position hit for current step *** */
207  GGSPosHit *posHit = GGSPosHitFactory::GetInstance().CreateObject(_posHitClass).release();
208  if (!posHit) {
209  throw std::runtime_error(
210  std::string("[GGSIntHitSD::ProcessHits] Can't create position hit of class ").append(_posHitClass));
211  }
212  // Insert the new position hit into the hit collection
213  auto *partHit =
214  (_currPartHit ? _currPartHit : (*(intHit->GetPartHits()))[intHit->GetPartHits()->GetSize() - 1]);
215  partHit->GetPosHits()->insert(posHit);
216  // Set members of the position hit
217  posHit->SetStep(*aStep);
218  }
219  } else {
220  std::vector<std::string> statusNames{
221  "fAlive", "fStopButAlive", "fStopAndKill", "fKillTrackAndSecondaries", "fSuspend", "fPostponeToNextEvent"};
222  COUT(WARNING) << "No particle hit has been created for particle:\n";
223  CCOUT(WARNING) << " - type: "
224  << aStep->GetTrack()->GetDynamicParticle()->GetParticleDefinition()->GetParticleName() << "\n";
225  CCOUT(WARNING) << " - creator process: " << aStep->GetTrack()->GetCreatorProcess()->GetProcessName() << "\n";
226  CCOUT(WARNING) << " - trackID: " << aStep->GetTrack()->GetTrackID() << "\n";
227  CCOUT(WARNING) << " - status: " << statusNames[static_cast<int>(aStep->GetTrack()->GetTrackStatus())] << "\n";
228  CCOUT(WARNING) << " - eDep: " << aStep->GetTotalEnergyDeposit() / CLHEP::MeV << " MeV \n";
229  CCOUT(WARNING) << " - kin. energy (pre) : " << aStep->GetPreStepPoint()->GetKineticEnergy() / CLHEP::MeV
230  << " MeV \n";
231  CCOUT(WARNING) << " - kin. energy (post): " << aStep->GetPostStepPoint()->GetKineticEnergy() / CLHEP::MeV
232  << " MeV \n";
233  CCOUT(WARNING) << " - process (pre) : "
234  << (aStep->GetPreStepPoint()->GetProcessDefinedStep()
235  ? aStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName()
236  : "none")
237  << "\n";
238  CCOUT(WARNING) << " - process (post): "
239  << (aStep->GetPostStepPoint()->GetProcessDefinedStep()
240  ? aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName()
241  : "none")
242  << "\n";
243  }
244  }
245 
246  return true;
247 }
virtual void AddStep(const G4Step &step)
Adds a step to the particle hit.
Definition: GGSIntHit.cpp:93
const G4ThreeVector & GetAbsTranslation()
Getter of absolute position of sensitive element.
Definition: GGSIntHit.h:232
virtual void AddStep(const G4Step &step)
Adds a step to the particle hit.
Definition: GGSPartHit.cpp:101
G4double GetEnergyDeposit() const
Energy deposit getter.
Definition: GGSPartHit.h:148
GGSPartHitsCollection * GetPartHits()
Getter of container of particle hits.
Definition: GGSIntHit.h:226
std::unique_ptr< T > CreateObject(const std::string &name, ConstructorArgs...arguments)
Create an object.
Definition: GGSFactory.h:115
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
void SetAbsTranslation(const G4ThreeVector &pos)
Set the position in global coordinates of the sensitive element.
Definition: GGSIntHit.h:144
void SetPosHitsStorage(bool flag)
Turn on or off the storage of position hits.
Definition: GGSIntHit.cpp:114
const G4VPhysicalVolume * GetVolume()
Getter for volume.
Definition: GGSIntHit.h:218
Definition of GGS Position Hit.
Definition: GGSPosHit.h:33
virtual void UserInit(G4Step *aStep)
User initialization of hit global properties.
Definition: GGSIntHit.h:89
virtual void SetStep(const G4Step &step)
Definition: GGSPosHit.cpp:60
G4int GetID()
Getter for volume ID.
Definition: GGSIntHit.h:238
#define CCOUT(level)
Smart log utility which prints no header at the beginning of the line.
Definition: GGSSmartLog.h:100
void SetID(G4int id)
Setter for volume ID.
Definition: GGSIntHit.h:176
void SetPosHitsStorage(bool flag)
Turn on or off the storage of position hits.
Definition: GGSPartHit.cpp:121
void SetVolume(const G4VPhysicalVolume *volume)
Setter for volume.
Definition: GGSIntHit.h:109
Definition of GGS Integrated Hit.
Definition: GGSIntHit.h:32
static GGSFactory & GetInstance()
Getter method for singleton pointer.
Definition: GGSFactory.h:71
void SetPartHitsStorage(bool flag)
Turn on or off the storage of particle hits.
Definition: GGSIntHit.cpp:132
void GGSIntHitSD::SetIntHitThreshold ( float  minEnergy)
inline

Sets the minimum energy for integrated hits.

Hits below this threshold will be removed from the hits array.

Parameters
minEnergyThe minimum energy for integrated hits.

Definition at line 150 of file GGSIntHitSD.h.

150 { _intHitThreshold = minEnergy; }
void GGSIntHitSD::SetPartHitsStorage ( bool  store)
inline

Turn on or off the storage (i.e. persistency) of particle hits.

This method tells to the SD whether to activate the storage of particle hits or not. By default, storage is not activated.

Calling this method with "false" parameter will automatically disable position hits storage, i.e., it will call SetPartsHitStorage(false).

Parameters
storeif true, steps will be stored as position hits.
See Also
SetPosHitsStorage
GGSIntHit::SetPosHitsStorage

Definition at line 97 of file GGSIntHitSD.h.

97  {
98  _storePartHits = store;
99  if (store == false) {
100  SetPosHitsStorage(false);
101  }
102  }
void SetPosHitsStorage(bool store)
Turn on or off the storage (i.e. persistence) of position hits.
Definition: GGSIntHitSD.h:131
void GGSIntHitSD::SetPartHitThreshold ( float  minEnergy)
inline

Sets the minimum energy for particle hits.

Hits below this threshold will be removed from the hits array.

Parameters
minEnergyThe minimum energy for particle hits.

Definition at line 158 of file GGSIntHitSD.h.

158 { _partHitThreshold = minEnergy; }
void GGSIntHitSD::SetPosHitsStorage ( bool  store)
inline

Turn on or off the storage (i.e. persistence) of position hits.

This method tells to the SD whether to activate the storage of position hits or not. By default, storage is not activated.

Calling this method with "true" parameter will automatically enable particle hits storage, i.e., it will call SetPartHitsStorage(true).

Parameters
storeif true, steps will be stored as position hits.
See Also
SetPartHitsStorage
GGSIntHit::SetPosHitsStorage

Definition at line 131 of file GGSIntHitSD.h.

131  {
132  _storePosHits = store;
133  if (store == true) {
134  SetPartHitsStorage(true);
135  }
136  }
void SetPartHitsStorage(bool store)
Turn on or off the storage (i.e. persistency) of particle hits.
Definition: GGSIntHitSD.h:97
void GGSIntHitSD::SetPosHitThreshold ( float  minEnergy)
inline

Sets the minimum energy for position hits.

Hits below this threshold will be removed from the hits array.

Parameters
minEnergyThe minimum energy for position hits.

Definition at line 166 of file GGSIntHitSD.h.

166 { _posHitThreshold = minEnergy; }
void GGSIntHitSD::SetTimeBin ( G4double  time)
inline

Time bins setter.

This method adds a division in the timeline, effectively adding a time bin.

Parameters
timeThe time of first energy deposit.

Definition at line 70 of file GGSIntHitSD.h.

70  {
71  _timeBins.push_back(time);
72  std::sort(_timeBins.begin(), _timeBins.end());
73  }
void GGSIntHitSD::SetTouchableIDComputer ( const std::string &  tidcClassName)

Sets the touchable ID computer class.

This method sets the touchable ID computer class that will be used by the sensitive detector.

Parameters
tidcClassNamethe name of the touchable ID computer class.

Definition at line 102 of file GGSIntHitSD.cpp.

102  {
103  _idComputer = GGSFactory<GGSTouchableIDComputer>::GetInstance().CreateObject(tidcClassName);
104  if (!_idComputer) {
105  throw std::runtime_error("[GGSIntHitSD::GGSIntHitSD] Touchable ID computer class " + tidcClassName + " not found");
106  }
107 }
std::unique_ptr< T > CreateObject(const std::string &name, ConstructorArgs...arguments)
Create an object.
Definition: GGSFactory.h:115
static GGSFactory & GetInstance()
Getter method for singleton pointer.
Definition: GGSFactory.h:71

The documentation for this class was generated from the following files: