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 cms::DDSpecParRegistry *, const dd4hep::sim::Geant4GeometryMaps::VolumeMap *, int, bool)
 
 DDG4ProductionCuts (const G4LogicalVolumeToDDLogicalPartMap *, int, bool)
 
 ~DDG4ProductionCuts ()
 

Private Member Functions

void dd4hepInitialize ()
 
void initialize ()
 
void setProdCuts (const cms::DDSpecPar *, G4Region *)
 
void setProdCuts (const DDLogicalPart, G4Region *)
 

Private Attributes

const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_ = nullptr
 
std::vector< std::pair< G4LogicalVolume *, const cms::DDSpecPar * > > dd4hepVec_
 
const std::string keywordRegion_
 
const G4LogicalVolumeToDDLogicalPartMapmap_ = nullptr
 
const bool protonCut_
 
const cms::DDSpecParRegistryspecPars_
 
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 50 of file DDG4ProductionCuts.cc.

51  : map_(map), keywordRegion_("CMSCutsRegion"), verbosity_(verb), protonCut_(pcut) {
52  initialize();
53 }

References initialize().

◆ DDG4ProductionCuts() [2/2]

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

Definition at line 55 of file DDG4ProductionCuts.cc.

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

References dd4hepInitialize().

◆ ~DDG4ProductionCuts()

DDG4ProductionCuts::~DDG4ProductionCuts ( )

Definition at line 63 of file DDG4ProductionCuts.cc.

63 {}

Member Function Documentation

◆ dd4hepInitialize()

void DDG4ProductionCuts::dd4hepInitialize ( )
private

Definition at line 111 of file DDG4ProductionCuts.cc.

111  {
114 
115  for (auto const& it : *dd4hepMap_) {
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));
120  }
121  }
122  }
123  }
124  // sort all root volumes - to get the same sequence at every run of the application.
125  sort(begin(dd4hepVec_), end(dd4hepVec_), &sortByName);
126 
127  // Now generate all the regions
128  for (auto const& it : dd4hepVec_) {
129  auto regName = it.second->strValue(keywordRegion_);
130  G4Region* region = G4RegionStore::GetInstance()->FindOrCreateRegion({regName.data(), regName.size()});
131  region->AddRootLogicalVolume(it.first);
132  edm::LogVerbatim("Geometry") << it.first->GetName() << ": " << it.second->strValue(keywordRegion_);
133  edm::LogVerbatim("Geometry") << " MakeRegions: added " << it.first->GetName() << " to region " << region->GetName();
134  edm::LogVerbatim("Geometry").log([&](auto& log) {
135  for (auto const& sit : it.second->spars) {
136  log << sit.first << " = " << sit.second[0] << "\n";
137  }
138  });
139  setProdCuts(it.second, region);
140  }
141 
142  if (verbosity_ > 0) {
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].first << " , " << dd4hepVec_[jj].second;
148  }
149 }

References begin, cms::dd::compareEqual(), dd4hepMap_, dd4hepVec_, end, cms::DDSpecParRegistry::filter(), findQualityFiles::jj, keywordRegion_, dqm-mbProfile::log, edm::LogVerbatim::log(), LogDebug, cms::dd::noNamespace(), cms::dd::realTopName(), HLT_2018_cff::region, setProdCuts(), specPars_, HistogramManager_cfi::specs, and verbosity_.

Referenced by DDG4ProductionCuts().

◆ initialize()

void DDG4ProductionCuts::initialize ( void  )
private

Definition at line 65 of file DDG4ProductionCuts.cc.

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

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

Referenced by DDG4ProductionCuts().

◆ setProdCuts() [1/2]

void DDG4ProductionCuts::setProdCuts ( const cms::DDSpecPar spec,
G4Region *  region 
)
private

Definition at line 212 of file DDG4ProductionCuts.cc.

212  {
213  //
214  // Create and fill production cuts
215  //
216  G4ProductionCuts* prodCuts = region->GetProductionCuts();
217  if (!prodCuts) {
218  // FIXME: Here we use a dd4hep string to double evaluator
219  // Beware of the units!!!
220 
221  //
222  // search for production cuts
223  // you must have four of them: e+ e- gamma proton
224  //
225  double gammacut = 0.0;
226  double electroncut = 0.0;
227  double positroncut = 0.0;
228  double protoncut = 0.0;
229 
230  auto gammacutStr = spec->strValue("ProdCutsForGamma");
231  if (gammacutStr.empty()) {
232  throw cms::Exception(
233  "SimG4CorePhysics",
234  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
235  }
236  gammacut = dd4hep::_toDouble({gammacutStr.data(), gammacutStr.size()});
237 
238  auto electroncutStr = spec->strValue("ProdCutsForElectrons");
239  if (electroncutStr.empty()) {
240  throw cms::Exception(
241  "SimG4CorePhysics",
242  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
243  }
244  electroncut = dd4hep::_toDouble({electroncutStr.data(), electroncutStr.size()});
245 
246  auto positroncutStr = spec->strValue("ProdCutsForPositrons");
247  if (positroncutStr.empty()) {
248  throw cms::Exception(
249  "SimG4CorePhysics",
250  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
251  }
252  positroncut = dd4hep::_toDouble({positroncutStr.data(), positroncutStr.size()});
253 
254  if (!spec->hasValue("ProdCutsForProtons")) {
255  // There is no ProdCutsForProtons set in XML,
256  // check if it's a legacy geometry scenario without it
257  if (protonCut_) {
258  protoncut = electroncut;
259  } else {
260  protoncut = 0.;
261  }
262  } else {
263  auto protoncutStr = spec->strValue("ProdCutsForProtons");
264  if (protoncutStr.empty()) {
265  throw cms::Exception(
266  "SimG4CorePhysics",
267  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
268  }
269  protoncut = dd4hep::_toDouble({protoncutStr.data(), protoncutStr.size()});
270  }
271 
272  prodCuts = new G4ProductionCuts();
273  region->SetProductionCuts(prodCuts);
274 
275  prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
276  prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
277  prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
278  prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
279  if (verbosity_ > 0) {
280  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : Setting cuts for " << region->GetName()
281  << "\n Electrons: " << electroncut << "\n Positrons: " << positroncut
282  << "\n Gamma : " << gammacut << "\n Proton : " << protoncut;
283  }
284  } else {
285  if (verbosity_ > 0) {
286  edm::LogVerbatim("Geometry")
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);
292  }
293  }
294 }

References Exception, cms::DDSpecPar::hasValue(), protonCut_, HLT_2018_cff::region, cms::DDSpecPar::strValue(), and verbosity_.

◆ setProdCuts() [2/2]

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

Definition at line 151 of file DDG4ProductionCuts.cc.

151  {
152  //
153  // search for production cuts
154  // you must have four of them: e+ e- gamma proton
155  //
156  double gammacut = 0.0;
157  double electroncut = 0.0;
158  double positroncut = 0.0;
159  double protoncut = 0.0;
160  int temp = map_->toDouble("ProdCutsForGamma", lpart, gammacut);
161  if (temp != 1) {
162  throw cms::Exception(
163  "SimG4CorePhysics",
164  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
165  }
166  temp = map_->toDouble("ProdCutsForElectrons", lpart, electroncut);
167  if (temp != 1) {
168  throw cms::Exception(
169  "SimG4CorePhysics",
170  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
171  }
172  temp = map_->toDouble("ProdCutsForPositrons", lpart, positroncut);
173  if (temp != 1) {
174  throw cms::Exception(
175  "SimG4CorePhysics",
176  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
177  }
178  temp = map_->toDouble("ProdCutsForProtons", lpart, protoncut);
179  if (temp == 0) {
180  // There is no ProdCutsForProtons set in XML,
181  // check if it's a legacy geometry scenario without it
182  if (protonCut_) {
183  protoncut = electroncut;
184  } else {
185  protoncut = 0.;
186  }
187  } else if (temp != 1) {
188  throw cms::Exception(
189  "SimG4CorePhysics",
190  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - more than one ProdCutsForProtons.");
191  }
192 
193  //
194  // Create and fill production cuts
195  //
196  G4ProductionCuts* prodCuts = region->GetProductionCuts();
197  if (!prodCuts) {
198  prodCuts = new G4ProductionCuts();
199  region->SetProductionCuts(prodCuts);
200  }
201  prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
202  prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
203  prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
204  prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
205  if (verbosity_ > 0) {
206  edm::LogVerbatim("Geometry") << "DDG4ProductionCuts : Setting cuts for " << region->GetName()
207  << "\n Electrons: " << electroncut << "\n Positrons: " << positroncut
208  << "\n Gamma : " << gammacut << "\n Proton : " << protoncut;
209  }
210 }

References Exception, map_, protonCut_, HLT_2018_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 41 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ dd4hepVec_

std::vector<std::pair<G4LogicalVolume*, const cms::DDSpecPar*> > DDG4ProductionCuts::dd4hepVec_
private

Definition at line 42 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ keywordRegion_

const std::string DDG4ProductionCuts::keywordRegion_
private

Definition at line 47 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize(), and initialize().

◆ map_

const G4LogicalVolumeToDDLogicalPartMap* DDG4ProductionCuts::map_ = nullptr
private

Definition at line 32 of file DDG4ProductionCuts.h.

Referenced by initialize(), and setProdCuts().

◆ protonCut_

const bool DDG4ProductionCuts::protonCut_
private

Definition at line 49 of file DDG4ProductionCuts.h.

Referenced by setProdCuts().

◆ specPars_

const cms::DDSpecParRegistry* DDG4ProductionCuts::specPars_
private

Definition at line 43 of file DDG4ProductionCuts.h.

Referenced by dd4hepInitialize().

◆ vec_

G4LogicalVolumeToDDLogicalPartMap::Vector DDG4ProductionCuts::vec_
private

Definition at line 33 of file DDG4ProductionCuts.h.

Referenced by initialize().

◆ verbosity_

const int DDG4ProductionCuts::verbosity_
private

Definition at line 48 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
cms::dd::realTopName
std::string_view realTopName(std::string_view)
DDG4ProductionCuts::verbosity_
const int verbosity_
Definition: DDG4ProductionCuts.h:48
HistogramManager_cfi.specs
specs
Definition: HistogramManager_cfi.py:80
DDG4ProductionCuts::dd4hepMap_
const dd4hep::sim::Geant4GeometryMaps::VolumeMap * dd4hepMap_
Definition: DDG4ProductionCuts.h:41
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DDG4ProductionCuts::protonCut_
const bool protonCut_
Definition: DDG4ProductionCuts.h:49
end
#define end
Definition: vmac.h:39
DDG4ProductionCuts::map_
const G4LogicalVolumeToDDLogicalPartMap * map_
Definition: DDG4ProductionCuts.h:32
cms::dd::noNamespace
std::string_view noNamespace(std::string_view)
Definition: Filter.cc:63
cms::DDSpecParRefs
std::vector< const DDSpecPar * > DDSpecParRefs
Definition: DDSpecParRegistry.h:30
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDG4ProductionCuts::dd4hepVec_
std::vector< std::pair< G4LogicalVolume *, const cms::DDSpecPar * > > dd4hepVec_
Definition: DDG4ProductionCuts.h:42
cms::DDSpecPar::strValue
std::string_view strValue(const std::string &) const
Definition: DDSpecparRegistry.cc:10
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
DDG4ProductionCuts::keywordRegion_
const std::string keywordRegion_
Definition: DDG4ProductionCuts.h:47
edm::LogVerbatim::log
LogVerbatim & log(F &&iF)
Definition: MessageLogger.h:327
edm::LogVerbatim
Definition: MessageLogger.h:297
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
DDG4ProductionCuts::specPars_
const cms::DDSpecParRegistry * specPars_
Definition: DDG4ProductionCuts.h:43
cms::dd::compareEqual
bool compareEqual(std::string_view, std::string_view)
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
DDG4ProductionCuts::vec_
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
Definition: DDG4ProductionCuts.h:33
cms::DDSpecParRegistry::filter
void filter(DDSpecParRefs &, const std::string &, const std::string &="") const
Definition: DDSpecparRegistry.cc:98
Exception
Definition: hltDiff.cc:246
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
DDG4ProductionCuts::initialize
void initialize()
Definition: DDG4ProductionCuts.cc:65
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
cms::DDSpecPar::hasValue
bool hasValue(const std::string &key) const
Definition: DDSpecparRegistry.cc: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:151
DDG4ProductionCuts::dd4hepInitialize
void dd4hepInitialize()
Definition: DDG4ProductionCuts.cc:111
begin
#define begin
Definition: vmac.h:32
fit
Definition: CombinedChiSquaredLikelihood.h:6