Two Sensitive Detectors - definition

Hi guys,

I have two different logic volumes. Each volume constains an array of layers. I want to define the two arrays as my sensitive detectors.

If I work with one of them everything is fine, but how can I define two sensitive detectors?
For one of them I write:
fScoringVolume = “name of first sensitive logic volume”
Have I to write “fScoringVolume = “name of second sensitive Logic volume”” for the second? or what?

And then, have I to copy what I do for the first sennsitive detector or is there a more efficient way?

Cheers,

did you actually define a sensitive detector, as in the documentation, or do you check for the “name of sensitive logic volume” in a G4UserSteppingAction, as e.g. in example B1?

Depending on how much effort you are willing to put in: the efficient way would be to define your own sensitiveDetector, and attach it to both logical volumes (or rather to the array of layers?).

A practicable solution would be to copy the whole fScoringVolume stuff (there can only be one fScoringVolume-value, but you could have a fScoringVolume2), and then either duplicate what you do for the first, or put
if (!(volume == fScoringVolume || volume == fScoringVolume2)) return;
(or the appropriate check in your code, this is from example B1)

Hi @weller,
Thanks for you reply. I did some trials, and I think that there is a problem here:

//sensitive detector for one layer //
SensitiveDetector::~SensitiveDetector() {}

void SensitiveDetector::Initialize(G4HCofThisEvent* hce) {
// Create hits collection
fHitsCollection = new HitsCollection(SensitiveDetectorName, collectionName[0]);

// Add this collection in hce
auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
hce->AddHitsCollection(hcID, fHitsCollection);

// Create hit for each scintillator layer
for (G4int i=0; i<fNofLayers; i++) fHitsCollection->insert(new class Hit());
}

When I try to generalize to two sensitive volume (I defined fScoringVolume = “name” and fScoringVolume1 = “name” in DetectorConstruction.cc class), I cannot run my simulation. I tried to copy and paste in this way:

/*
//sensitive detector for the second layer

void SensitiveDetector::Initialize(G4HCofThisEvent* hce1) {
// Create hits collection
fHitsCollection1 = new HitsCollection(SensitiveDetectorName, collectionName[1]);

// Add this collection in hce
auto hcID1 = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]);
hce1->AddHitsCollection(hcID1, fHitsCollection1);

// Create hit for each scintillator layer
for (G4int j=0; j<fNofLayers; j++) fHitsCollection->insert(new class Hit());
}
*/
But I get an error when building, as if I defined twice the function Initialize.

rename the class after duplicating, not the parameters :slight_smile:

//sensitive detector for one layer //
SensitiveDetectorA::~SensitiveDetectorA() {}

void SensitiveDetectorA::Initialize(G4HCofThisEvent* hce) {
// Create hits collection
fHitsCollection = new HitsCollection(SensitiveDetectorName, collectionName[0]);

// Add this collection in hce
auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
hce->AddHitsCollection(hcID, fHitsCollection);

// Create hit for each scintillator layer
for (G4int i=0; i<fNofLayers; i++) fHitsCollection->insert(new class Hit());
}

//sensitive detector for the second layer
void SensitiveDetectorB::Initialize(G4HCofThisEvent* hce) {
// Create hits collection
fHitsCollection = new HitsCollection(SensitiveDetectorName, collectionName[0]);

// Add this collection in hce
auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
hce->AddHitsCollection(hcID, fHitsCollection);

// Create hit for each scintillator layer
for (G4int j=0; j<fNofLayers; j++) fHitsCollection->insert(new class Hit());
}