15.5. Assigning Sensitive Detectors
Table of Contents
Connecting detectors to logical volumes
In Geant4 a sensitive detector is never attached directly to a solid or a physical volume. It is always connected to a logical volume. Every copy or replica of that logical volume in the geometry then shares the same sensitive detector and produces hits according to the same rules.
You normally perform this connection in the DetectorConstruction class, inside the Construct() method or in a helper method that is called from it. By the time you assign a sensitive detector, the logical volume must already exist and have its material and shape defined.
The core idea is simple. You create an instance of your class derived from G4VSensitiveDetector, register it with the Geant4 sensitive detector manager, then attach it to one or more logical volumes using the SetSensitiveDetector method.
A **sensitive detector is always attached to a G4LogicalVolume, not to a G4VPhysicalVolume or a solid. All physical placements that share that logical volume will be sensitive.
To manage sensitive detectors Geant4 provides the singleton G4SDManager. It keeps a list of all sensitive detectors and assigns each of them an internal ID. A typical pattern is to obtain it once in your DetectorConstruction code then add your detectors to it before you attach them to logical volumes.
A minimal example follows this sequence. First you retrieve the pointer to the manager:
auto sdManager = G4SDManager::GetSDMpointer();
Next you create your sensitive detector object. For example, if you defined a class MyDetectorSD that inherits from G4VSensitiveDetector:
auto mySD = new MyDetectorSD("MyDetectorSD");The string passed to the constructor is the sensitive detector name. It must be unique within your application. You then register it with the manager:
sdManager->AddNewDetector(mySD);
After the detector is registered, you attach it to the desired logical volume. Suppose you have previously created a logical volume called detectorLV:
detectorLV->SetSensitiveDetector(mySD);
From this point, whenever a particle step occurs inside any physical volume based on detectorLV, Geant4 will call the ProcessHits method of MyDetectorSD. The sensitive detector can then create and store hits in its hit collection.
You can attach the same sensitive detector instance to several logical volumes. This is common when you want to treat many detector cells in the same way and distinguish them later by copy number or another identifier. For example:
cellLV->SetSensitiveDetector(mySD);
vetoLV->SetSensitiveDetector(mySD);In contrast, if you want different parts of the detector to be handled by completely different hit classes, you create multiple sensitive detector objects, give them different names, register each one, and attach them to different logical volumes.
It is important to perform this setup only once, before the first run is initialized. If you modify sensitive detector assignments after /run/initialize, you must reinitialize the geometry so that Geant4 can rebuild its internal tables. Usually this means either changing the geometry before the first run, or issuing appropriate run manager commands to notify Geant4 of geometry changes.
Geant4 also provides an optional G4SDParticleFilter and other filters that you can attach to a sensitive detector to restrict which particles generate hits. You do not attach filters directly to the logical volume. Instead, you configure them inside the sensitive detector object, after it has been created and before you start the simulation.
In more complex setups, especially with many repeated detector elements, the link between a hit and a particular detector element is often made through the copy number of the physical volume. Even in those cases, the fundamental connection is still between the sensitive detector and the shared logical volume. The sensitive detector can then read the copy number from the step information inside ProcessHits and use it as a detector ID.
In summary, to connect detectors to logical volumes you create the sensitive detector, register it with G4SDManager, and use SetSensitiveDetector on the appropriate logical volumes. This establishes the path from particle steps in your geometry to hit creation in your sensitive detector classes and is the key link between your detector geometry and your simulated readout.
Views: 4
KAHIBARO