Skip to content

Commit

Permalink
Adding option to set all volumes as sensitive (#306)
Browse files Browse the repository at this point in the history
Adds the option `--allsensitive` for example 1 so that the SD
information in the geometry will be ignored and all volumes marked as
sensitive.

This mode is useful in order to quickly validate geometries which don't
contain SD info.
  • Loading branch information
JuanGonzalezCaminero authored Sep 4, 2024
1 parent 8f183c5 commit 2526590
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 40 deletions.
36 changes: 19 additions & 17 deletions examples/Example1/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int main(int argc, char **argv)
G4String batchMacroName;
G4bool useInteractiveMode = true;
G4bool useAdePT = true;
G4bool allSensitive = false; // If set, ignores the sensitive detector flags in the GDML and marks all volumes as
// sensitive. Useful for validation of geometries with no SD info
G4String helpMsg("Usage: " + G4String(argv[0]) +
" [option(s)] \n No additional arguments triggers an interactive mode "
"executing vis.mac macro. \n Options:\n\t-h\t\tdisplay this help "
Expand All @@ -37,6 +39,8 @@ int main(int argc, char **argv)
++i;
} else if (argument == "--noadept") {
useAdePT = false;
} else if (argument == "--allsensitive") {
allSensitive = true;
} else {
G4Exception("main", "Unknown argument", FatalErrorInArgument,
("Unknown argument passed to " + G4String(argv[0]) + " : " + argument + "\n" + helpMsg).c_str());
Expand All @@ -45,34 +49,32 @@ int main(int argc, char **argv)

// Initialization of default Run manager
auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
//auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);
// auto *runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);

// Detector geometry:
auto detector = new DetectorConstruction();
auto detector = new DetectorConstruction(allSensitive);
runManager->SetUserInitialization(detector);

// Physics list
//
G4VUserPhysicsList *physicsList;
// Physics list
//
G4VUserPhysicsList *physicsList;

if(useAdePT){
physicsList = new FTFP_BERT_AdePT();
}
else{
physicsList = new FTFP_BERT_HepEm();
}
if (useAdePT) {
physicsList = new FTFP_BERT_AdePT();
} else {
physicsList = new FTFP_BERT_HepEm();
}

runManager->SetUserInitialization(physicsList);
runManager->SetUserInitialization(physicsList);

// reduce verbosity of physics lists
G4EmParameters::Instance()->SetVerbose(0);
G4HadronicProcessStore::Instance()->SetVerbose(0);
// reduce verbosity of physics lists
G4EmParameters::Instance()->SetVerbose(0);
G4HadronicProcessStore::Instance()->SetVerbose(0);

//-------------------------------
// UserAction classes
//-------------------------------
runManager->SetUserInitialization(
new ActionInitialisation());
runManager->SetUserInitialization(new ActionInitialisation());

G4UImanager *UImanager = G4UImanager::GetUIpointer();
G4String command = "/control/execute ";
Expand Down
3 changes: 2 additions & 1 deletion examples/Example1/include/DetectorConstruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DetectorMessenger;

class DetectorConstruction : public G4VUserDetectorConstruction {
public:
DetectorConstruction();
DetectorConstruction(bool allSensitive = false);
virtual ~DetectorConstruction();

virtual G4VPhysicalVolume *Construct() final;
Expand All @@ -57,6 +57,7 @@ private:
G4ThreeVector fMagFieldVector;

G4GDMLParser fParser;
bool fAllSensitive;
};

#endif /* DETECTORCONSTRUCTION_H */
63 changes: 41 additions & 22 deletions examples/Example1/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction()
DetectorConstruction::DetectorConstruction(bool allSensitive) : fAllSensitive(allSensitive), G4VUserDetectorConstruction()
{
fDetectorMessenger = new DetectorMessenger(this);
}
Expand Down Expand Up @@ -95,28 +95,47 @@ void DetectorConstruction::ConstructSDandField()
int nd = lvol->GetNoDaughters();
numTouchables++;

// Check if the LogicalVolume is sensitive
auto aAuxInfoList = fParser.GetVolumeAuxiliaryInformation(lvol);
for (auto iaux = aAuxInfoList.begin(); iaux != aAuxInfoList.end(); iaux++) {
G4String str = iaux->type;
G4String val = iaux->value;
G4String unit = iaux->unit;

if (str == "SensDet") {
// If it is, record the PV
if (caloSD->fSensitivePhysicalVolumes.find(pvol) == caloSD->fSensitivePhysicalVolumes.end()) {
caloSD->fSensitivePhysicalVolumes.insert(pvol);
}
// If this is the first time we see this LV
if (std::find(caloSD->fSensitiveLogicalVolumes.begin(), caloSD->fSensitiveLogicalVolumes.end(), lvol) ==
caloSD->fSensitiveLogicalVolumes.end()) {
// Make LogicalVolume sensitive by registering a SensitiveDetector for it
SetSensitiveDetector(lvol, caloSD);
// We keep a list of Logical sensitive volumes, used for initializing AdePTTransport
caloSD->fSensitiveLogicalVolumes.push_back(lvol);
if(fAllSensitive) // For easier validation of geometries with no SD info, we may set all volumes as sensitive
{
// Record the PV
if (caloSD->fSensitivePhysicalVolumes.find(pvol) == caloSD->fSensitivePhysicalVolumes.end()) {
caloSD->fSensitivePhysicalVolumes.insert(pvol);
}
// If this is the first time we see this LV
if (std::find(caloSD->fSensitiveLogicalVolumes.begin(), caloSD->fSensitiveLogicalVolumes.end(), lvol) ==
caloSD->fSensitiveLogicalVolumes.end()) {
// Make LogicalVolume sensitive by registering a SensitiveDetector for it
SetSensitiveDetector(lvol, caloSD);
// We keep a list of Logical sensitive volumes, used for initializing AdePTTransport
caloSD->fSensitiveLogicalVolumes.push_back(lvol);
}
numSensitiveTouchables++;
}
else
{
// Check if the LogicalVolume is marked as sensitive in the geometry
auto aAuxInfoList = fParser.GetVolumeAuxiliaryInformation(lvol);
for (auto iaux = aAuxInfoList.begin(); iaux != aAuxInfoList.end(); iaux++) {
G4String str = iaux->type;
G4String val = iaux->value;
G4String unit = iaux->unit;

if (str == "SensDet") {
// If it is, record the PV
if (caloSD->fSensitivePhysicalVolumes.find(pvol) == caloSD->fSensitivePhysicalVolumes.end()) {
caloSD->fSensitivePhysicalVolumes.insert(pvol);
}
// If this is the first time we see this LV
if (std::find(caloSD->fSensitiveLogicalVolumes.begin(), caloSD->fSensitiveLogicalVolumes.end(), lvol) ==
caloSD->fSensitiveLogicalVolumes.end()) {
// Make LogicalVolume sensitive by registering a SensitiveDetector for it
SetSensitiveDetector(lvol, caloSD);
// We keep a list of Logical sensitive volumes, used for initializing AdePTTransport
caloSD->fSensitiveLogicalVolumes.push_back(lvol);
}
numSensitiveTouchables++;
break;
}
numSensitiveTouchables++;
break;
}
}

Expand Down

0 comments on commit 2526590

Please sign in to comment.