7 #include <DD4hep/Filter.h>
8 #include <DD4hep/SpecParRegistry.h>
10 #include "G4ProductionCuts.hh"
11 #include "G4RegionStore.hh"
12 #include "G4Region.hh"
13 #include "G4LogicalVolume.hh"
14 #include "G4LogicalVolumeStore.hh"
24 bool dd_is_greater(
const std::pair<G4LogicalVolume*, DDLogicalPart>&
p1,
25 const std::pair<G4LogicalVolume*, DDLogicalPart>&
p2) {
27 if (
p1.second.name().ns() >
p2.second.name().ns()) {
30 if (
p1.second.name().ns() ==
p2.second.name().ns()) {
31 if (
p1.second.name().name() >
p2.second.name().name()) {
34 if (
p1.second.name().name() ==
p2.second.name().name()) {
35 if (
p1.first->GetName() >
p2.first->GetName()) {
43 bool sortByName(
const std::pair<G4LogicalVolume*, const dd4hep::SpecPar*>&
p1,
44 const std::pair<G4LogicalVolume*, const dd4hep::SpecPar*>&
p2) {
46 if (
p1.first->GetName() >
p2.first->GetName()) {
54 : map_(
map), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
59 const dd4hep::sim::Geant4GeometryMaps::VolumeMap*
map,
62 : dd4hepMap_(
map), specPars_(specPars), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
74 edm::LogVerbatim(
"Geometry") <<
" DDG4ProductionCuts : got " <<
vec_.size() <<
" region roots.\n"
75 <<
" DDG4ProductionCuts : List of all roots:";
76 for (
auto const& vv :
vec_)
77 edm::LogVerbatim(
"Geometry") <<
" " << vv.first->GetName() <<
" : " << vv.second.name();
83 G4Region*
region =
nullptr;
84 G4RegionStore* store = G4RegionStore::GetInstance();
85 for (
auto const& vv :
vec_) {
87 edm::LogVerbatim(
"Geometry") <<
" num " <<
num <<
" regionName: " << regionName <<
", the store of size "
90 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
92 if (regionName != curName) {
93 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : regionName " << regionName <<
", the store of size "
95 region = store->FindOrCreateRegion(regionName);
98 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
100 curName = regionName;
101 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : new G4Region " << vv.first->GetName();
105 region->AddRootLogicalVolume(vv.first);
113 dd4hep::SpecParRefs
specs;
118 bool foundMatch =
false;
121 for (
auto const& pit :
fit.second->paths) {
122 const std::string_view
selection = dd4hep::dd::noNamespace(dd4hep::dd::realTopName(pit));
123 const std::string_view
name = dd4hep::dd::noNamespace(it.first.name());
127 dd4hepVec_.emplace_back(std::make_pair<G4LogicalVolume*, const dd4hep::SpecPar*>(&*it.second, &*
fit.second));
143 G4Region*
region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
145 region->AddRootLogicalVolume(it.first);
147 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << it.first->GetName() <<
" to region " <<
region->GetName();
150 const G4String& nonReflectedG4Name = it.first->GetName();
151 const G4String& reflectedG4Name = nonReflectedG4Name +
"_refl";
152 const G4LogicalVolumeStore*
const allG4LogicalVolumes = G4LogicalVolumeStore::GetInstance();
153 const auto reflectedG4LogicalVolumeIt = std::find_if(
154 allG4LogicalVolumes->begin(), allG4LogicalVolumes->end(), [&](
const G4LogicalVolume*
const aG4LogicalVolume) {
155 return (aG4LogicalVolume->GetName() == reflectedG4Name);
158 if (reflectedG4LogicalVolumeIt != allG4LogicalVolumes->end()) {
159 region->AddRootLogicalVolume(*reflectedG4LogicalVolumeIt);
160 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << (*reflectedG4LogicalVolumeIt)->GetName()
161 <<
" to region " <<
region->GetName();
165 for (
auto const& sit : it.second->spars) {
166 log << sit.first <<
" = " << sit.second[0] <<
"\n";
173 edm::LogVerbatim(
"SimG4CoreGeometry") <<
" DDG4ProductionCuts (New) : starting\n"
174 <<
" DDG4ProductionCuts : Got " <<
dd4hepVec_.size() <<
" region roots.\n"
175 <<
" DDG4ProductionCuts : List of all roots:";
187 double gammacut = 0.0;
188 double electroncut = 0.0;
189 double positroncut = 0.0;
190 double protoncut = 0.0;
195 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
201 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
207 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
214 protoncut = electroncut;
218 }
else if (
temp != 1) {
221 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
227 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
229 prodCuts =
new G4ProductionCuts();
230 region->SetProductionCuts(prodCuts);
232 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
233 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
234 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
235 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
238 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
239 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
247 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
253 double gammacut = spec->dblValue(
"ProdCutsForGamma") / dd4hep::mm;
254 double electroncut = spec->dblValue(
"ProdCutsForElectrons") / dd4hep::mm;
255 double positroncut = spec->dblValue(
"ProdCutsForPositrons") / dd4hep::mm;
256 double protoncut = spec->dblValue(
"ProdCutsForProtons") / dd4hep::mm;
257 if (protoncut == 0) {
258 protoncut = electroncut;
261 prodCuts =
new G4ProductionCuts();
262 region->SetProductionCuts(prodCuts);
264 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
265 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
266 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
267 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
270 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
271 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
276 <<
"DDG4ProductionCuts : Cuts are already set for " <<
region->GetName()
277 <<
"\n Electrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4ElectronCut)
278 <<
"\n Positrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4PositronCut)
279 <<
"\n Gamma : " <<
region->GetProductionCuts()->GetProductionCut(idxG4GammaCut)
280 <<
"\n Proton : " <<
region->GetProductionCuts()->GetProductionCut(idxG4ProtonCut);