GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSUniqueTouchableIDComputer.cpp
1 /*
2  * GGSUniqueTouchableIDComputer.cpp
3  *
4  * Created on: 3 Jun 2020
5  * Author: Nicola Mori
6  */
7 
8 #include "montecarlo/scoring/GGSUniqueTouchableIDComputer.h"
9 
10 #include "G4Step.hh"
11 
12 RegisterTIDC(GGSUniqueTouchableIDComputer);
13 
15 
16  G4TouchableHandle touchable = aStep->GetPreStepPoint()->GetTouchableHandle();
17  G4ThreeVector volPos = touchable->GetTranslation(); // Absolute volume translation
18 
19  // Build the absolute touchable ID
20  // Definition: the multiplicity of a physical volume is defined as the number of that volumes inside a given mother
21  // logical volume. Definition: given a history, the multiplicity at depth i is the multiplicity of the volume in
22  // history at depth i Definition: given a history, the copy number at depth i is the copy number of the volume in
23  // history at depth i Being N_i and M_i the copy number and multiplicity at depth i, the absolute ID of the touchable
24  // at history depth 0 is defined as:
25  // ID = N_0 + M_0*N_1 + M_0*M_1*N_2 + ...
26  // At each step, the product M_0*M_1*N_2*... is stored in the variable totMult.
27 
28  int historyDepth = touchable->GetHistoryDepth();
29  int totMult = 1;
30  int touchableID = 0;
31  // Map to store the multiplicity of each physical volume
32 
33  for (int iDepth = 0; iDepth < historyDepth; iDepth++) { // This loop will go up in history up to the daughter of the
34  // world volume (i.e. iDepth == historyDepth - 1)
35  touchableID += totMult * touchable->GetCopyNumber(iDepth);
36  // Compute total multiplicity for next step
37  if (iDepth != historyDepth - 1) { // No need to compute the total multiplicity on last step
38  int currVolMult = 0;
39  if (!(touchable->GetVolume(iDepth)->IsReplicated())) {
40  // See if the multiplicity for the current non-replicated volume has been computed before
41  auto storedMult = _multMap.find(touchable->GetVolume(iDepth));
42  if (storedMult == _multMap.end()) {
43  // Compute the multiplicity for non-replicated volumes placed inside the current mother logical
44  G4LogicalVolume *currLogVol = touchable->GetVolume(iDepth)->GetLogicalVolume();
45  G4LogicalVolume *motherLogVol = touchable->GetVolume(iDepth)->GetMotherLogical();
46  int nDaughters = motherLogVol->GetNoDaughters();
47  for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
48  if (motherLogVol->GetDaughter(iDaughter)->GetLogicalVolume() == currLogVol)
49  currVolMult++;
50  }
51  // Store the computed multiplicity
52  _multMap[touchable->GetVolume(iDepth)] = currVolMult;
53  } else {
54  // Use the stored multiplicity
55  currVolMult = storedMult->second;
56  }
57  } else {
58  // Use the multiplicity of the replicated volume
59  EAxis axis;
60  G4int nReplicas;
61  G4double width, offset;
62  G4bool consuming;
63  touchable->GetVolume(iDepth)->GetReplicationData(axis, nReplicas, width, offset, consuming);
64  currVolMult = nReplicas;
65  }
66  totMult *= currVolMult;
67  }
68  }
69 
70  return touchableID;
71 }
A class that computes unique IDs for each touchable.
int ComputeTouchableID(G4Step *aStep)
Computes the touchable ID in a unique way.