8 #include <DD4hep/Filter.h>
9 #include <DD4hep/SpecParRegistry.h>
11 #include "G4ProductionCuts.hh"
12 #include "G4RegionStore.hh"
13 #include "G4Region.hh"
14 #include "G4LogicalVolume.hh"
20 #ifdef HAVE_GEANT4_UNITS
32 bool dd_is_greater(
const std::pair<G4LogicalVolume*, DDLogicalPart>&
p1,
33 const std::pair<G4LogicalVolume*, DDLogicalPart>&
p2) {
35 if (
p1.second.name().ns() >
p2.second.name().ns()) {
38 if (
p1.second.name().ns() ==
p2.second.name().ns()) {
39 if (
p1.second.name().name() >
p2.second.name().name()) {
42 if (
p1.second.name().name() ==
p2.second.name().name()) {
43 if (
p1.first->GetName() >
p2.first->GetName()) {
51 bool sortByName(
const std::pair<G4LogicalVolume*, const dd4hep::SpecPar*>&
p1,
52 const std::pair<G4LogicalVolume*, const dd4hep::SpecPar*>&
p2) {
54 if (
p1.first->GetName() >
p2.first->GetName()) {
62 : map_(
map), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
67 const dd4hep::sim::Geant4GeometryMaps::VolumeMap*
map,
70 : dd4hepMap_(
map), specPars_(specPars), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
80 sort(
vec_.begin(),
vec_.end(), &dd_is_greater);
82 edm::LogVerbatim(
"Geometry") <<
" DDG4ProductionCuts : got " <<
vec_.size() <<
" region roots.\n"
83 <<
" DDG4ProductionCuts : List of all roots:";
84 for (
auto const& vv :
vec_)
85 edm::LogVerbatim(
"Geometry") <<
" " << vv.first->GetName() <<
" : " << vv.second.name();
91 G4Region*
region =
nullptr;
92 G4RegionStore* store = G4RegionStore::GetInstance();
93 for (
auto const& vv :
vec_) {
95 edm::LogVerbatim(
"Geometry") <<
" num " <<
num <<
" regionName: " << regionName <<
", the store of size "
98 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
100 if (regionName != curName) {
101 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : regionName " << regionName <<
", the store of size "
103 region = store->FindOrCreateRegion(regionName);
106 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
108 curName = regionName;
109 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : new G4Region " << vv.first->GetName();
113 region->AddRootLogicalVolume(vv.first);
121 dd4hep::SpecParRefs
specs;
126 for (
auto const& pit :
fit.second->paths) {
127 const std::string_view
selection = dd4hep::dd::realTopName(pit);
128 const std::string_view
name = dd4hep::dd::noNamespace(it.first.name());
132 dd4hepVec_.emplace_back(std::make_pair<G4LogicalVolume*, const dd4hep::SpecPar*>(&*it.second, &*
fit.second));
143 G4Region*
region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
144 region->AddRootLogicalVolume(it.first);
146 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << it.first->GetName() <<
" to region " <<
region->GetName();
148 for (
auto const& sit : it.second->spars) {
149 log << sit.first <<
" = " << sit.second[0] <<
"\n";
156 edm::LogVerbatim(
"SimG4CoreGeometry") <<
" DDG4ProductionCuts (New) : starting\n"
157 <<
" DDG4ProductionCuts : Got " <<
dd4hepVec_.size() <<
" region roots.\n"
158 <<
" DDG4ProductionCuts : List of all roots:";
170 double gammacut = 0.0;
171 double electroncut = 0.0;
172 double positroncut = 0.0;
173 double protoncut = 0.0;
178 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
184 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
190 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
197 protoncut = electroncut;
201 }
else if (
temp != 1) {
204 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
210 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
212 prodCuts =
new G4ProductionCuts();
213 region->SetProductionCuts(prodCuts);
215 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
216 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
217 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
218 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
221 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
222 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
230 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
236 double gammacut = spec->dblValue(
"ProdCutsForGamma") /
MM_2_CM;
237 double electroncut = spec->dblValue(
"ProdCutsForElectrons") /
MM_2_CM;
238 double positroncut = spec->dblValue(
"ProdCutsForPositrons") /
MM_2_CM;
239 double protoncut = spec->dblValue(
"ProdCutsForProtons") /
MM_2_CM;
240 if (protoncut == 0) {
241 protoncut = electroncut;
244 prodCuts =
new G4ProductionCuts();
245 region->SetProductionCuts(prodCuts);
247 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
248 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
249 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
250 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
253 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
254 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
259 <<
"DDG4ProductionCuts : Cuts are already set for " <<
region->GetName()
260 <<
"\n Electrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4ElectronCut)
261 <<
"\n Positrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4PositronCut)
262 <<
"\n Gamma : " <<
region->GetProductionCuts()->GetProductionCut(idxG4GammaCut)
263 <<
"\n Proton : " <<
region->GetProductionCuts()->GetProductionCut(idxG4ProtonCut);