Sensitive Detectors

Hello,
I am trying to build my detectors as follows:

void DetectorConstruction::ConstructSDandField()
{
G4SDManager* SDman = G4SDManager::GetSDMpointer();
G4String SDname;

G4VSensitiveDetector* AISTHPGe = new DetectorSD(SDname="/AISTHPGe1");
SDman -> AddNewDetector(AISTHPGe);
Ge_Detector -> SetSensitiveDetector(AISTHPGe);

G4VSensitiveDetector* LaBrSDDetector = new DetectorSD(SDname="/LaBrSDDetector1");
SDman -> AddNewDetector(LaBrSDDetector);
LaBr_Detector -> SetSensitiveDetector(LaBrSDDetector);
}

But I always have this error:


[  8%] Building CXX object CMakeFiles/NRF_CT.dir/src/DetectorConstruction.cc.o
In file included from /home/ali/GEANT4/Tests/Daito/NRFcode-Ali (Ask in fourm)/src/DetectorConstruction.cc:15:
/home/ali/GEANT4/Tests/Daito/NRFcode-Ali (Ask in fourm)/include/DetectorSD.hh:21:7: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
       const G4int GetCopyNoOffset() { return CopyNoOffset;};
       ^~~~~
/home/ali/GEANT4/Tests/Daito/NRFcode-Ali (Ask in fourm)/src/DetectorConstruction.cc: In member function ‘virtual void DetectorConstruction::ConstructSDandField()’:
/home/ali/GEANT4/Tests/Daito/NRFcode-Ali (Ask in fourm)/src/DetectorConstruction.cc:95:38: error: expected type-specifier before ‘DetectorSD’
 G4VSensitiveDetector* AISTHPGe = new DetectorSD(SDname="/AISTHPGe1");
                                      ^~~~~~~~~~
/home/ali/GEANT4/Tests/Daito/NRFcode-Ali (Ask in fourm)/src/DetectorConstruction.cc:99:44: error: expected type-specifier before ‘DetectorSD’
 G4VSensitiveDetector* LaBrSDDetector = new DetectorSD(SDname="/LaBrSDDetector1");
                                            ^~~~~~~~~~
make[2]: *** [CMakeFiles/NRF_CT.dir/build.make:104: CMakeFiles/NRF_CT.dir/src/DetectorConstruction.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/NRF_CT.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Can you guide me to the mistake!
Thank you a lot in advance for any suggestions!

1 Like

You’re missing #include "DetectorSD.hh" in your DetectorConstruction.cc file. If DetectorSD() is a function, rather than a class, then you don’t use “new.”

DetectorConstruction.cc (4.7 KB)

I get almost the same error.
Can you please check the attached file!!