diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h index 9c319ef66298ac3e386e9dccb5a4d922f34e174f..af8eb68c92b508ec2b062bf459b2ab84f259cd82 100644 --- a/DDCore/include/DD4hep/Objects.h +++ b/DDCore/include/DD4hep/Objects.h @@ -556,6 +556,10 @@ namespace DD4hep { double threshold() const; /// Access secondaries flag bool storeSecondaries() const; + /// Access use_default_cut flag + bool useDefaultCut() const; + /// Access was_threshold_set flag + bool wasThresholdSet() const; }; } /* End namespace Geometry */ diff --git a/DDCore/include/DD4hep/objects/ObjectsInterna.h b/DDCore/include/DD4hep/objects/ObjectsInterna.h index d8e900ba39ab7e6e72fb62a6a3a13c392b8b11fc..a8f5e5b442c7d843c43bf6c7c442de12dd66f3f2 100644 --- a/DDCore/include/DD4hep/objects/ObjectsInterna.h +++ b/DDCore/include/DD4hep/objects/ObjectsInterna.h @@ -112,6 +112,8 @@ namespace DD4hep { double threshold; double cut; bool store_secondaries; + bool use_default_cut; + bool was_threshold_set; std::vector<std::string> user_limits; /// Standard constructor RegionObject(); diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index b7d1c9095a13671db6a4ffe5ced6f5700a29a432..f2d02e57ecf360c2ee9c41fe56a0c98347ef73a3 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -444,6 +444,8 @@ Region::Region(const string& nam) { p->store_secondaries = false; p->threshold = 10.0; p->cut = 10.0; + p->use_default_cut = true; + p->was_threshold_set = false; } Region& Region::setStoreSecondaries(bool value) { @@ -453,11 +455,13 @@ Region& Region::setStoreSecondaries(bool value) { Region& Region::setThreshold(double value) { object<Object>().threshold = value; + object<Object>().was_threshold_set = true; return *this; } Region& Region::setCut(double value) { object<Object>().cut = value; + object<Object>().use_default_cut = false; return *this; } @@ -481,6 +485,14 @@ bool Region::storeSecondaries() const { return object<Object>().store_secondaries; } +bool Region::useDefaultCut() const { + return object<Object>().use_default_cut; +} + +bool Region::wasThresholdSet() const { + return object<Object>().was_threshold_set; +} + #undef setAttr #if 0 diff --git a/DDCore/src/ObjectsInterna.cpp b/DDCore/src/ObjectsInterna.cpp index f20e5babd5c5b957be138b6480392c9844aa9922..a842a0d3b8de2b8e6d1c29e811abc2c600f04217 100644 --- a/DDCore/src/ObjectsInterna.cpp +++ b/DDCore/src/ObjectsInterna.cpp @@ -66,7 +66,8 @@ DD4HEP_INSTANTIATE_HANDLE_NAMED(RegionObject); /// Standard constructor RegionObject::RegionObject() - : magic(magic_word()), threshold(10.0), cut(10.0), store_secondaries(false) + : magic(magic_word()), threshold(10.0), cut(10.0), store_secondaries(false), + use_default_cut(true), was_threshold_set(false) { InstanceCount::increment(this); } diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 053a056936eef8b44b52b6f139b7892e1a034159..541723504d89192e4763707782481f9f8da4c516 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -772,11 +772,16 @@ void* Geant4Converter::handleRegion(Region region, const set<const TGeoVolume*>& Region r = Ref_t(region); g4 = new G4Region(r.name()); // set production cut - G4ProductionCuts* cuts = new G4ProductionCuts(); - cuts->SetProductionCut(r.cut()*CLHEP::mm/dd4hep::mm); - g4->SetProductionCuts(cuts); + if( not r.useDefaultCut() ) { + G4ProductionCuts* cuts = new G4ProductionCuts(); + cuts->SetProductionCut(r.cut()*CLHEP::mm/dd4hep::mm); + g4->SetProductionCuts(cuts); + } // create region info with storeSecondaries flag + if( not r.wasThresholdSet() and r.storeSecondaries() ) { + throw runtime_error("G4Region: StoreSecondaries is True, but no explicit threshold set:"); + } G4UserRegionInformation* info = new G4UserRegionInformation(); info->region = r; info->threshold = r.threshold()*CLHEP::MeV/dd4hep::MeV;