8 #include "G4ProductionCuts.hh" 9 #include "G4RegionStore.hh" 10 #include "G4Region.hh" 11 #include "G4LogicalVolume.hh" 21 bool dd_is_greater(
const std::pair<G4LogicalVolume*, DDLogicalPart>&
p1,
22 const std::pair<G4LogicalVolume*, DDLogicalPart>&
p2) {
24 if (p1.second.name().ns() > p2.second.name().ns()) {
27 if (p1.second.name().ns() == p2.second.name().ns()) {
28 if (p1.second.name().name() > p2.second.name().name()) {
31 if (p1.second.name().name() == p2.second.name().name()) {
32 if (p1.first->GetName() > p2.first->GetName()) {
40 bool sortByName(
const std::pair<G4LogicalVolume*, const cms::DDSpecPar*>& p1,
41 const std::pair<G4LogicalVolume*, const cms::DDSpecPar*>& p2) {
43 if (p1.first->GetName() > p2.first->GetName()) {
51 : map_(map), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
56 const dd4hep::sim::Geant4GeometryMaps::VolumeMap*
map,
71 sort(
vec_.begin(),
vec_.end(), &dd_is_greater);
73 edm::LogVerbatim(
"Geometry") <<
" DDG4ProductionCuts : got " <<
vec_.size() <<
" region roots.\n" 74 <<
" DDG4ProductionCuts : List of all roots:";
75 for (
auto const& vv :
vec_)
76 edm::LogVerbatim(
"Geometry") <<
" " << vv.first->GetName() <<
" : " << vv.second.name();
82 G4Region*
region =
nullptr;
83 G4RegionStore* store = G4RegionStore::GetInstance();
84 for (
auto const& vv :
vec_) {
86 edm::LogVerbatim(
"Geometry") <<
" num " << num <<
" regionName: " << regionName <<
", the store of size " 89 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
91 if (regionName != curName) {
92 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : regionName " << regionName <<
", the store of size " 94 region = store->FindOrCreateRegion(regionName);
95 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : region " << region->GetName();
97 throw cms::Exception(
"SimG4CoreGeometry",
" DDG4ProductionCuts::initialize: Problem with Region tags.");
100 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : new G4Region " << vv.first->GetName();
104 region->AddRootLogicalVolume(vv.first);
107 edm::LogVerbatim(
"Geometry") <<
" added " << vv.first->GetName() <<
" to region " << region->GetName();
116 for (
auto const&
fit : specs) {
117 for (
auto const& pit :
fit->paths) {
119 dd4hepVec_.emplace_back(std::make_pair<G4LogicalVolume*, const cms::DDSpecPar*>(&*it.second, &*
fit));
130 G4Region*
region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
131 region->AddRootLogicalVolume(it.first);
133 edm::LogVerbatim(
"Geometry") <<
" MakeRegions: added " << it.first->GetName() <<
" to region " << region->GetName();
135 for (
auto const& sit : it.second->spars) {
136 log << sit.first <<
" = " << sit.second[0] <<
"\n";
143 LogDebug(
"Geometry") <<
" DDG4ProductionCuts (New) : starting\n" 144 <<
" DDG4ProductionCuts : Got " << dd4hepVec_.size() <<
" region roots.\n" 145 <<
" DDG4ProductionCuts : List of all roots:";
146 for (
size_t jj = 0;
jj < dd4hepVec_.size(); ++
jj)
147 LogDebug(
"Geometry") <<
" DDG4ProductionCuts : root=" << dd4hepVec_[
jj];
156 double gammacut = 0.0;
157 double electroncut = 0.0;
158 double positroncut = 0.0;
159 double protoncut = 0.0;
164 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
166 temp =
map_->
toDouble(
"ProdCutsForElectrons", lpart, electroncut);
170 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
172 temp =
map_->
toDouble(
"ProdCutsForPositrons", lpart, positroncut);
176 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
178 temp =
map_->
toDouble(
"ProdCutsForProtons", lpart, protoncut);
183 protoncut = electroncut;
187 }
else if (temp != 1) {
190 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
196 G4ProductionCuts* prodCuts = region->GetProductionCuts();
198 prodCuts =
new G4ProductionCuts();
199 region->SetProductionCuts(prodCuts);
201 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
202 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
203 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
204 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
206 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : Setting cuts for " << region->GetName()
207 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
208 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
216 G4ProductionCuts* prodCuts = region->GetProductionCuts();
225 double gammacut = 0.0;
226 double electroncut = 0.0;
227 double positroncut = 0.0;
228 double protoncut = 0.0;
230 auto gammacutStr = spec->
strValue(
"ProdCutsForGamma");
231 if (gammacutStr.empty()) {
234 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
236 gammacut = dd4hep::_toDouble({gammacutStr.data(), gammacutStr.size()});
238 auto electroncutStr = spec->
strValue(
"ProdCutsForElectrons");
239 if (electroncutStr.empty()) {
242 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
244 electroncut = dd4hep::_toDouble({electroncutStr.data(), electroncutStr.size()});
246 auto positroncutStr = spec->
strValue(
"ProdCutsForPositrons");
247 if (positroncutStr.empty()) {
250 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
252 positroncut = dd4hep::_toDouble({positroncutStr.data(), positroncutStr.size()});
254 if (!spec->
hasValue(
"ProdCutsForProtons")) {
258 protoncut = electroncut;
263 auto protoncutStr = spec->
strValue(
"ProdCutsForProtons");
264 if (protoncutStr.empty()) {
267 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
269 protoncut = dd4hep::_toDouble({protoncutStr.data(), protoncutStr.size()});
272 prodCuts =
new G4ProductionCuts();
273 region->SetProductionCuts(prodCuts);
275 prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
276 prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
277 prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
278 prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
280 edm::LogVerbatim(
"Geometry") <<
"DDG4ProductionCuts : Setting cuts for " << region->GetName()
281 <<
"\n Electrons: " << electroncut <<
"\n Positrons: " << positroncut
282 <<
"\n Gamma : " << gammacut <<
"\n Proton : " << protoncut;
287 <<
"DDG4ProductionCuts : Cuts are already set for " << region->GetName()
288 <<
"\n Electrons: " << region->GetProductionCuts()->GetProductionCut(idxG4ElectronCut)
289 <<
"\n Positrons: " << region->GetProductionCuts()->GetProductionCut(idxG4PositronCut)
290 <<
"\n Gamma : " << region->GetProductionCuts()->GetProductionCut(idxG4GammaCut)
291 <<
"\n Proton : " << region->GetProductionCuts()->GetProductionCut(idxG4ProtonCut);
DDG4ProductionCuts(const G4LogicalVolumeToDDLogicalPartMap *, int, bool)
std::string_view realTopName(std::string_view)
bool hasValue(const std::string &key) const
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
std::string_view strValue(const std::string &) const
std::vector< std::pair< G4LogicalVolume *, const cms::DDSpecPar * > > dd4hepVec_
void filter(DDSpecParRefs &, std::string_view, std::string_view) const
std::string_view noNamespace(std::string_view)
const std::string keywordRegion_
const G4LogicalVolumeToDDLogicalPartMap * map_
LogVerbatim & log(F &&iF)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
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
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
void setProdCuts(const DDLogicalPart, G4Region *)
bool compareEqual(std::string_view, std::string_view)
std::vector< const DDSpecPar * > DDSpecParRefs
const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_
const cms::DDSpecParRegistry * specPars_
Vector all(const std::string &name, const std::string &value) const
get all std::mapped instances which have a specific 'name' with value 'value'