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.");
93 if (regionName != curName) {
94 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : regionName " << regionName <<
", the store of size " 96 region = store->FindOrCreateRegion(regionName);
99 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
102 curName = regionName;
103 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : new G4Region " << vv.first->GetName();
107 region->AddRootLogicalVolume(vv.first);
115 dd4hep::SpecParRefs
specs;
120 bool foundMatch =
false;
123 for (
auto const& pit :
fit.second->paths) {
124 const std::string_view
selection = dd4hep::dd::noNamespace(dd4hep::dd::realTopName(pit));
125 const std::string_view
name = dd4hep::dd::noNamespace(it.first.name());
129 dd4hepVec_.emplace_back(std::make_pair<G4LogicalVolume*, const dd4hep::SpecPar*>(&*it.second, &*
fit.second));
145 G4Region*
region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
147 region->AddRootLogicalVolume(it.first);
149 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << it.first->GetName() <<
" to region " <<
region->GetName();
152 const G4String& nonReflectedG4Name = it.first->GetName();
153 const G4String& reflectedG4Name = nonReflectedG4Name +
"_refl";
154 const G4LogicalVolumeStore*
const allG4LogicalVolumes = G4LogicalVolumeStore::GetInstance();
155 const auto reflectedG4LogicalVolumeIt = std::find_if(
156 allG4LogicalVolumes->begin(), allG4LogicalVolumes->end(), [&](
const G4LogicalVolume*
const aG4LogicalVolume) {
157 return (aG4LogicalVolume->GetName() == reflectedG4Name);
160 if (reflectedG4LogicalVolumeIt != allG4LogicalVolumes->end()) {
161 region->AddRootLogicalVolume(*reflectedG4LogicalVolumeIt);
162 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << (*reflectedG4LogicalVolumeIt)->GetName()
163 <<
" to region " <<
region->GetName();
167 for (
auto const& sit : it.second->spars) {
168 log << sit.first <<
" = " << sit.second[0] <<
"\n";
175 edm::LogVerbatim(
"SimG4CoreGeometry") <<
" DDG4ProductionCuts (New) : starting\n" 176 <<
" DDG4ProductionCuts : Got " <<
dd4hepVec_.size() <<
" region roots.\n" 177 <<
" DDG4ProductionCuts : List of all roots:";
189 double gammacut = 0.0;
190 double electroncut = 0.0;
191 double positroncut = 0.0;
192 double protoncut = 0.0;
197 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
203 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
209 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
216 protoncut = electroncut;
220 }
else if (
temp != 1) {
223 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
229 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
230 if (
nullptr == prodCuts) {
231 prodCuts =
new G4ProductionCuts();
232 region->SetProductionCuts(prodCuts);
234 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
235 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
236 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
237 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
240 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
241 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
249 G4ProductionCuts* prodCuts =
region->GetProductionCuts();
255 double gammacut = spec->dblValue(
"ProdCutsForGamma") / dd4hep::mm;
256 double electroncut = spec->dblValue(
"ProdCutsForElectrons") / dd4hep::mm;
257 double positroncut = spec->dblValue(
"ProdCutsForPositrons") / dd4hep::mm;
258 double protoncut = spec->dblValue(
"ProdCutsForProtons") / dd4hep::mm;
259 if (protoncut == 0) {
260 protoncut = electroncut;
263 prodCuts =
new G4ProductionCuts();
264 region->SetProductionCuts(prodCuts);
266 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
267 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
268 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
269 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
272 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
273 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
278 <<
"DDG4ProductionCuts : Cuts are already set for " <<
region->GetName()
279 <<
"\n Electrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4ElectronCut)
280 <<
"\n Positrons: " <<
region->GetProductionCuts()->GetProductionCut(idxG4PositronCut)
281 <<
"\n Gamma : " <<
region->GetProductionCuts()->GetProductionCut(idxG4GammaCut)
282 <<
"\n Proton : " <<
region->GetProductionCuts()->GetProductionCut(idxG4ProtonCut);
Log< level::Info, true > LogVerbatim
DDG4ProductionCuts(const G4LogicalVolumeToDDLogicalPartMap *, int, bool)
std::vector< std::pair< G4LogicalVolume *, const dd4hep::SpecPar * > > dd4hepVec_
const dd4hep::SpecParRegistry * specPars_
const std::string keywordRegion_
const G4LogicalVolumeToDDLogicalPartMap * map_
unsigned int toString(const std::string &name, const KeyType &key, std::string &value, unsigned int pos=0) const
same as toDouble but for std::string-valued values of named parameters
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
void setProdCuts(const DDLogicalPart, G4Region *)
const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_
Vector all(const std::string &name, const std::string &value) const
get all std::mapped instances which have a specific 'name' with value 'value'
unsigned int toDouble(const std::string &name, const KeyType &key, double &value, unsigned int pos=0) const
returns the number specific parameters named 'name' and the corrsponding double