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

A class that computes unique IDs for each touchable. More...

#include <GGSUniqueTouchableIDComputer.h>

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

Public Member Functions

int ComputeTouchableID (G4Step *aStep)
 Computes the touchable ID in a unique way. More...
 
- Public Member Functions inherited from GGSTouchableIDComputer
virtual ~GGSTouchableIDComputer ()
 Destructor.
 

Detailed Description

A class that computes unique IDs for each touchable.

This class computes a unique ID for each touchable belonging to a given detector logical volume. It works only for a given volume hierarchy, i.e. for those touchables that are inside the same hierarchy of volumes up to the world volume. For example, a sensitive logical L might be placed as G4PVPlacement twice in the logical container L1 and three times in the logical container L2; L1 and L2 are then placed N1 and N2 times inside the world volume. In this case, the computed IDs will be unique among the physical volumes inside the various L1s, and the same for L2, but the IDs for volumes in L1 and in L2 might be the same.

To obtain unique IDs the various placements of the sensitive volume and all its mother volumes must have different copy numbers.

Definition at line 32 of file GGSUniqueTouchableIDComputer.h.

Member Function Documentation

int GGSUniqueTouchableIDComputer::ComputeTouchableID ( G4Step *  aStep)
virtual

Computes the touchable ID in a unique way.

The ID is computed starting from the replica number and taking into account the multiplicity of the touchable and of all its mother volumes. This requires all the volumes to have unique copy/replica number. For example, consider three sensitive volumes (copy no. 0, 1 and 2) in a container placed two times (copy no.* 0 and 1). Volume 0 in container 0 will have ID 0, volume 0 in container 1 will have ID 3 = copy n. + multiplicity * mother copy n. = 0 + 3*1.

Parameters
aStepThe current step.
Returns
the unique ID of the touchable where the current step is happening.

Implements GGSTouchableIDComputer.

Definition at line 14 of file GGSUniqueTouchableIDComputer.cpp.

14  {
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 }

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