Difficulties in setting a sensitive detector

Hello,

I am trying to add an EventAction class just like in example B4d, however when I set the SensitiveDetectors in ConstructSDandField the particles doesn’t interact with the geometry of the detectors at all.

Here is a part of my code where I try to set my sensitive detectors, just like in example B4d

void MyDetectorConstruction::ConstructSDandField()
{
    G4SDManager::GetSDMpointer()->SetVerboseLevel(1);

    auto caloDec = new G4MultiFunctionalDetector("CalorimeterDetector");
    G4SDManager::GetSDMpointer()->AddNewDetector(caloDec);

    G4VPrimitiveScorer* primitive;
    primitive = new G4PSEnergyDeposit("Edep");
    caloDec->RegisterPrimitive(primitive);

    primitive = new G4PSTrackLength("TrackLength");
    auto charged = new G4SDChargedFilter("chargedFilter");
    primitive->SetFilter(charged);
    caloDec->RegisterPrimitive(primitive);

    SetSensitiveDetector("caloDetector", caloDec);

    auto posDec = new G4MultiFunctionalDetector("PositronDec");
    G4SDManager::GetSDMpointer()->AddNewDetector(posDec);

    primitive = new G4PSEnergyDeposit("Edep");
    posDec->RegisterPrimitive(primitive);

    primitive = new G4PSTrackLength("TrackLength");
    primitive ->SetFilter(charged);
    posDec->RegisterPrimitive(primitive);

    SetSensitiveDetector("positronDetector", posDec);

Thank you.

Just an additional comment here: the GUI interface shows all geometry pieces in the correct positions, however the particles don’t interact with the medium.

Hi @silveira,

Just a silly question: are the particles interacting with the geometry otherwise? I mean, without implementing the sensitive detector.
I ask cause the first thing I can think of the lack of interactions is actually some problems in the hierarchy of your geometry. But more experienced users could give a better help.

We had a previous version that was working, but we wanted to have better control of the energy of the particles, so we decided to move to using primitives as example B4d. It seems that we fail to assign the SD and primitives correctly.

Hello! I decided to include a few more lines of code so it might be easier to find the issue for anyone trying to help:

    G4Box *calorimeterS = new G4Box("Calorimeter", boxWidth, boxWidth, 0.01*m);

    calorimeterLV = new G4LogicalVolume(calorimeterS, worldMat, "CalorimeterLV");

    G4VPhysicalVolume *physDetector = new G4PVPlacement(0, G4ThreeVector(0, 0, 3.01*m), calorimeterLV, "Calorimeter", logicWorld, false, 0, true);



    G4Box *positronDetectorS = new G4Box("PositronDetector", boxWidth, 0.5*m, 0.01*m);

    positronDetectorLV = new G4LogicalVolume(positronDetectorS, worldMat, "PositronDetectorLV");

    auto detectorRot = new G4RotationMatrix();
    detectorRot->rotateX(-33.69*deg);

    G4VPhysicalVolume *physDetector2 = new G4PVPlacement(detectorRot, G4ThreeVector(0, -1.25*m, 2.21*m), positronDetectorLV, "PositronDetector", logicWorld, false, 0, true);

I’ve also made small changes on the code shared above, so I’ll share the new version too

    G4SDManager::GetSDMpointer()->SetVerboseLevel(1);

    auto caloDetector = new G4MultiFunctionalDetector("Calorimeter");
    G4SDManager::GetSDMpointer()->AddNewDetector(caloDetector);

    G4VPrimitiveScorer* primitive;
    primitive = new G4PSEnergyDeposit("Edep");
    caloDetector->RegisterPrimitive(primitive);

    primitive = new G4PSTrackLength("TrackLength");
    auto charged = new G4SDChargedFilter("chargedFilter");
    primitive->SetFilter(charged);
    caloDetector->RegisterPrimitive(primitive);

    SetSensitiveDetector("CalorimeterLV", caloDetector);

    auto posDec = new G4MultiFunctionalDetector("PositronDetector");
    G4SDManager::GetSDMpointer()->AddNewDetector(posDec);

    primitive = new G4PSEnergyDeposit("Edep");
    posDec->RegisterPrimitive(primitive);

    primitive = new G4PSTrackLength("TrackLength");
    primitive->SetFilter(charged);
    posDec->RegisterPrimitive(primitive);

    SetSensitiveDetector("PositronDetectorLV", posDec);

I’ve tried to follow the same structure as example B4d, but didn’t have much success, the same problem still occurs.