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,
59 : dd4hepMap_(
map), specPars_(specPars), keywordRegion_(
"CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
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);
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);
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:";
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.");
170 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
176 " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
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);
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);
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);