CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
DDG4ProductionCuts Class Reference

#include <DDG4ProductionCuts.h>

Public Member Functions

 DDG4ProductionCuts (const dd4hep::SpecParRegistry *, const dd4hep::sim::Geant4GeometryMaps::VolumeMap *, int, bool)
 
 DDG4ProductionCuts (const G4LogicalVolumeToDDLogicalPartMap *, int, bool)
 

Private Member Functions

void dd4hepInitialize ()
 
void initialize ()
 
void setProdCuts (const dd4hep::SpecPar *, G4Region *)
 
void setProdCuts (const DDLogicalPart, G4Region *)
 

Private Attributes

const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_ = nullptr
 
std::vector< std::pair< G4LogicalVolume *, const dd4hep::SpecPar * > > dd4hepVec_
 
const std::string keywordRegion_
 
const G4LogicalVolumeToDDLogicalPartMapmap_ = nullptr
 
const bool protonCut_
 
const dd4hep::SpecParRegistry * specPars_
 
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
 
const int verbosity_
 

Detailed Description

Definition at line 15 of file DDG4ProductionCuts.h.

Constructor & Destructor Documentation

◆ DDG4ProductionCuts() [1/2]

DDG4ProductionCuts::DDG4ProductionCuts ( const G4LogicalVolumeToDDLogicalPartMap map,
int  verb,
bool  pcut 
)
explicit

Definition at line 53 of file DDG4ProductionCuts.cc.

54  : map_(map), keywordRegion_("CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
55  initialize();
56 }

References initialize().

◆ DDG4ProductionCuts() [2/2]

DDG4ProductionCuts::DDG4ProductionCuts ( const dd4hep::SpecParRegistry *  specPars,
const dd4hep::sim::Geant4GeometryMaps::VolumeMap *  map,
int  verb,
bool  pcut 
)
explicit

Definition at line 58 of file DDG4ProductionCuts.cc.

62  : dd4hepMap_(map), specPars_(specPars), keywordRegion_("CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
64 }

References dd4hepInitialize().

Member Function Documentation

◆ dd4hepInitialize()

void DDG4ProductionCuts::dd4hepInitialize ( )
private

Definition at line 112 of file DDG4ProductionCuts.cc.

112  {
113  dd4hep::SpecParRefs specs;
114  specPars_->filter(specs, keywordRegion_);
115 
116  // LOOP ON ALL LOGICAL VOLUMES
117  for (auto const& it : *dd4hepMap_) {
118  bool foundMatch = false; // Same behavior as in DDD: when matching SpecPar is found, stop search!
119  // SEARCH ON ALL SPECPARS
120  for (auto const& fit : specs) {
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());
124  if (!(dd4hep::dd::isRegex(selection))
125  ? dd4hep::dd::compareEqual(name, selection)
126  : std::regex_match(name.begin(), name.end(), std::regex(selection.begin(), selection.end()))) {
127  dd4hepVec_.emplace_back(std::make_pair<G4LogicalVolume*, const dd4hep::SpecPar*>(&*it.second, &*fit.second));
128  foundMatch = true;
129  break;
130  }
131  }
132  if (foundMatch)
133  break;
134  } // Search on all SpecPars
135  } // Loop on all logical volumes
136 
137  // sort all root volumes - to get the same sequence at every run of the application.
138  sort(begin(dd4hepVec_), end(dd4hepVec_), &sortByName);
139 
140  // Now generate all the regions
141  for (auto const& it : dd4hepVec_) {
142  auto regName = it.second->strValue(keywordRegion_);
143  G4Region* region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
144 
145  region->AddRootLogicalVolume(it.first);
146  edm::LogVerbatim("Geometry") << it.first->GetName() << ": " << regName;
147  edm::LogVerbatim("Geometry") << " MakeRegions: added " << it.first->GetName() << " to region " << region->GetName();
148 
149  // Also treat reflected volumes
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);
156  });
157  // If G4 Logical volume has a reflected volume, add it to the region as well.
158  if (reflectedG4LogicalVolumeIt != allG4LogicalVolumes->end()) {
159  region->AddRootLogicalVolume(*reflectedG4LogicalVolumeIt);
160  edm::LogVerbatim("Geometry") << " MakeRegions: added " << (*reflectedG4LogicalVolumeIt)->GetName()
161  << " to region " << region->GetName();
162  }
163 
164  edm::LogVerbatim("Geometry").log([&](auto& log) {
165  for (auto const& sit : it.second->spars) {
166  log << sit.first << " = " << sit.second[0] << "\n";
167  }
168  });
169  setProdCuts(it.second, region);
170  }
171 
172  if (verbosity_ > 0) {
173  edm::LogVerbatim("SimG4CoreGeometry") << " DDG4ProductionCuts (New) : starting\n"
174  << " DDG4ProductionCuts : Got " << dd4hepVec_.size() << " region roots.\n"
175  << " DDG4ProductionCuts : List of all roots:";
176  for (size_t jj = 0; jj < dd4hepVec_.size(); ++jj)
177  edm::LogVerbatim("SimG4CoreGeometry") << " DDG4ProductionCuts : root=" << dd4hepVec_[jj].first->GetName()
178  << " , " << dd4hepVec_[jj].second->paths.at(0);
179  }
180 }

References dd4hepMap_, dd4hepVec_, mps_fire::end, findQualityFiles::jj, keywordRegion_, dqm-mbProfile::log, Skims_PA_cff::name, HLT_FULL_cff::region, corrVsCorr::selection, setProdCuts(), jetUpdater_cfi::sort, specPars_, HistogramManager_cfi::specs, and verbosity_.

Referenced by DDG4ProductionCuts().

◆ initialize()

void DDG4ProductionCuts::initialize ( void  )
private

Definition at line 66 of file DDG4ProductionCuts.cc.

66  {
68  // sort all root volumes - to get the same sequence at every run of the application.
69  // (otherwise, the sequence will depend on the pointer (memory address) of the
70  // involved objects, because 'new' does no guarantee that you allways get a
71  // higher (or lower) address when allocating an object of the same type ...
72  sort(vec_.begin(), vec_.end(), &dd_is_greater);
73  if (verbosity_ > 0) {
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();
78  }
79 
80  // Now generate all the regions
81  std::string curName = "";
82  std::string regionName = "";
83  G4Region* region = nullptr;
84  G4RegionStore* store = G4RegionStore::GetInstance();
85  for (auto const& vv : vec_) {
86  unsigned int num = map_->toString(keywordRegion_, vv.second, regionName);
87  edm::LogVerbatim("Geometry") << " num " << num << " regionName: " << regionName << ", the store of size "
88  << store->size();
89  if (num != 1) {
90  throw cms::Exception("SimG4CoreGeometry", " DDG4ProductionCuts::initialize: Problem with Region tags.");
91  }
92  if (regionName != curName) {
93  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : regionName " << regionName << ", the store of size "
94  << store->size();
95  region = store->FindOrCreateRegion(regionName);
96  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : region " << region->GetName();
97  if (!region) {
98  throw cms::Exception("SimG4CoreGeometry", " DDG4ProductionCuts::initialize: Problem with Region tags.");
99  }
100  curName = regionName;
101  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : new G4Region " << vv.first->GetName();
102  setProdCuts(vv.second, region);
103  }
104 
105  region->AddRootLogicalVolume(vv.first);
106 
107  if (verbosity_ > 0)
108  edm::LogVerbatim("Geometry") << " added " << vv.first->GetName() << " to region " << region->GetName();
109  }
110 }

References DDMapper< KeyType, ValueType >::all(), Exception, keywordRegion_, map_, EgammaValidation_cff::num, HLT_FULL_cff::region, setProdCuts(), jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, DDMapper< KeyType, ValueType >::toString(), vec_, and verbosity_.

Referenced by DDG4ProductionCuts().

◆ setProdCuts() [1/2]

void DDG4ProductionCuts::setProdCuts ( const dd4hep::SpecPar *  spec,
G4Region *  region 
)
private

Definition at line 243 of file DDG4ProductionCuts.cc.

243  {
244  //
245  // Create and fill production cuts
246  //
247  G4ProductionCuts* prodCuts = region->GetProductionCuts();
248  if (!prodCuts) {
249  //
250  // search for production cuts
251  // you must have four of them: e+ e- gamma proton
252  //
253  double gammacut = spec->dblValue("ProdCutsForGamma") / dd4hep::mm; // Convert from DD4hep units to 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;
259  }
260 
261  prodCuts = new G4ProductionCuts();
262  region->SetProductionCuts(prodCuts);
263 
264  prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
265  prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
266  prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
267  prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
268  if (verbosity_ > 0) {
269  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : Setting cuts for " << region->GetName()
270  << "\n Electrons: " << electroncut << "\n Positrons: " << positroncut
271  << "\n Gamma : " << gammacut << "\n Proton : " << protoncut;
272  }
273  } else {
274  if (verbosity_ > 0) {
275  edm::LogVerbatim("Geometry")
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);
281  }
282  }
283 }

References HLT_FULL_cff::region, and verbosity_.

◆ setProdCuts() [2/2]

void DDG4ProductionCuts::setProdCuts ( const DDLogicalPart  lpart,
G4Region *  region 
)
private

Definition at line 182 of file DDG4ProductionCuts.cc.

182  {
183  //
184  // search for production cuts
185  // you must have four of them: e+ e- gamma proton
186  //
187  double gammacut = 0.0;
188  double electroncut = 0.0;
189  double positroncut = 0.0;
190  double protoncut = 0.0;
191  int temp = map_->toDouble("ProdCutsForGamma", lpart, gammacut);
192  if (temp != 1) {
193  throw cms::Exception(
194  "SimG4CorePhysics",
195  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
196  }
197  temp = map_->toDouble("ProdCutsForElectrons", lpart, electroncut);
198  if (temp != 1) {
199  throw cms::Exception(
200  "SimG4CorePhysics",
201  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
202  }
203  temp = map_->toDouble("ProdCutsForPositrons", lpart, positroncut);
204  if (temp != 1) {
205  throw cms::Exception(
206  "SimG4CorePhysics",
207  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
208  }
209  temp = map_->toDouble("ProdCutsForProtons", lpart, protoncut);
210  if (temp == 0) {
211  // There is no ProdCutsForProtons set in XML,
212  // check if it's a legacy geometry scenario without it
213  if (protonCut_) {
214  protoncut = electroncut;
215  } else {
216  protoncut = 0.;
217  }
218  } else if (temp != 1) {
219  throw cms::Exception(
220  "SimG4CorePhysics",
221  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
222  }
223 
224  //
225  // Create and fill production cuts
226  //
227  G4ProductionCuts* prodCuts = region->GetProductionCuts();
228  if (!prodCuts) {
229  prodCuts = new G4ProductionCuts();
230  region->SetProductionCuts(prodCuts);
231  }
232  prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
233  prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
234  prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
235  prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
236  if (verbosity_ > 0) {
237  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : Setting cuts for " << region->GetName()
238  << "\n Electrons: " << electroncut << "\n Positrons: " << positroncut
239  << "\n Gamma : " << gammacut << "\n Proton : " << protoncut;
240  }
241 }

References Exception, map_, protonCut_, HLT_FULL_cff::region, groupFilesInBlocks::temp, DDMapper< KeyType, ValueType >::toDouble(), and verbosity_.

Referenced by dd4hepInitialize(), and initialize().

Member Data Documentation

◆ dd4hepMap_

const dd4hep::sim::Geant4GeometryMaps::VolumeMap* DDG4ProductionCuts::dd4hepMap_ = nullptr
private

Definition at line 37 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ dd4hepVec_

std::vector<std::pair<G4LogicalVolume*, const dd4hep::SpecPar*> > DDG4ProductionCuts::dd4hepVec_
private

Definition at line 38 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ keywordRegion_

const std::string DDG4ProductionCuts::keywordRegion_
private

Definition at line 43 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize(), and initialize().

◆ map_

const G4LogicalVolumeToDDLogicalPartMap* DDG4ProductionCuts::map_ = nullptr
private

Definition at line 28 of file DDG4ProductionCuts.h.

Referenced by initialize(), and setProdCuts().

◆ protonCut_

const bool DDG4ProductionCuts::protonCut_
private

Definition at line 45 of file DDG4ProductionCuts.h.

Referenced by setProdCuts().

◆ specPars_

const dd4hep::SpecParRegistry* DDG4ProductionCuts::specPars_
private

Definition at line 39 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ vec_

G4LogicalVolumeToDDLogicalPartMap::Vector DDG4ProductionCuts::vec_
private

Definition at line 29 of file DDG4ProductionCuts.h.

Referenced by initialize().

◆ verbosity_

const int DDG4ProductionCuts::verbosity_
private

Definition at line 44 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize(), initialize(), and setProdCuts().

DDMapper::toDouble
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
Definition: DDMapper.h:111
DDG4ProductionCuts::verbosity_
const int verbosity_
Definition: DDG4ProductionCuts.h:44
HistogramManager_cfi.specs
specs
Definition: HistogramManager_cfi.py:83
DDG4ProductionCuts::dd4hepMap_
const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_
Definition: DDG4ProductionCuts.h:37
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DDG4ProductionCuts::protonCut_
const bool protonCut_
Definition: DDG4ProductionCuts.h:45
DDG4ProductionCuts::map_
const G4LogicalVolumeToDDLogicalPartMap * map_
Definition: DDG4ProductionCuts.h:28
mps_fire.end
end
Definition: mps_fire.py:242
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDG4ProductionCuts::keywordRegion_
const std::string keywordRegion_
Definition: DDG4ProductionCuts.h:43
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88267
DDG4ProductionCuts::dd4hepVec_
std::vector< std::pair< G4LogicalVolume *, const dd4hep::SpecPar * > > dd4hepVec_
Definition: DDG4ProductionCuts.h:38
DDG4ProductionCuts::specPars_
const dd4hep::SpecParRegistry * specPars_
Definition: DDG4ProductionCuts.h:39
DDMapper::toString
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
Definition: DDMapper.h:172
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
std
Definition: JetResolutionObject.h:76
DDG4ProductionCuts::vec_
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
Definition: DDG4ProductionCuts.h:29
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
DDG4ProductionCuts::initialize
void initialize()
Definition: DDG4ProductionCuts.cc:66
DDMapper::all
Vector all(const std::string &name, const std::string &value) const
get all std::mapped instances which have a specific 'name' with value 'value'
Definition: DDMapper.h:199
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
genParticles_cff.map
map
Definition: genParticles_cff.py:11
DDG4ProductionCuts::setProdCuts
void setProdCuts(const DDLogicalPart, G4Region *)
Definition: DDG4ProductionCuts.cc:182
edm::Log
Definition: MessageLogger.h:70
DDG4ProductionCuts::dd4hepInitialize
void dd4hepInitialize()
Definition: DDG4ProductionCuts.cc:112
fit
Definition: CombinedChiSquaredLikelihood.h:6