CMS 3D CMS Logo

MuonG4Numbering.cc
Go to the documentation of this file.
7 
8 #include "G4VPhysicalVolume.hh"
9 #include "G4VTouchable.hh"
10 #include "G4Step.hh"
11 
12 #include <iostream>
13 
14 //#define EDM_ML_DEBUG
15 
17  : offMap_(offMap), dd4hep_(dd4hep) {
18  theLevelPart = muonConstants.getValue("level");
19  theSuperPart = muonConstants.getValue("super");
20  theBasePart = muonConstants.getValue("base");
21  theStartCopyNo = muonConstants.getValue("xml_starts_with_copyno");
22 
23  // some consistency checks
24 
25  if (theBasePart != 1) {
26  edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual base constant:" << theBasePart;
27  }
28  if (theSuperPart < 100) {
29  edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual super constant:" << theSuperPart;
30  }
31  if (theLevelPart < 10 * theSuperPart) {
32  edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual level constant:" << theLevelPart;
33  }
34  if ((theStartCopyNo != 0) && (theStartCopyNo != 1)) {
35  edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual start value for copy numbers:"
36  << theStartCopyNo;
37  }
38 
39 #ifdef EDM_ML_DEBUG
40  edm::LogVerbatim("MuonSim") << "StartCopyNo = " << theStartCopyNo;
41  edm::LogVerbatim("MuonSim") << "MuonG4Numbering configured with Level = " << theLevelPart
42  << " Super = " << theSuperPart << " Base = " << theBasePart
43  << " StartCopyNo = " << theStartCopyNo;
44  edm::LogVerbatim("MuonSim") << "dd4hep flag set to " << dd4hep_ << " and offsetmap at " << offMap_;
45 #endif
46 }
47 
50  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
51 
52  for (int ii = 0; ii < touch->GetHistoryDepth(); ii++) {
53  G4VPhysicalVolume* vol = touch->GetVolume(ii);
54  int copyno = vol->GetCopyNo();
55  int extra(0);
56  if (dd4hep_ && (offMap_ != nullptr)) {
57  std::string namx = DD4hep2DDDName::noNameSpace(static_cast<std::string>(vol->GetName()));
58  std::size_t last = namx.rfind('_');
59  std::string name = ((last == std::string::npos) ? namx : (namx.substr(0, last)));
60  auto itr = offMap_->muonMap_.find(name);
61  if (itr != offMap_->muonMap_.end())
62  extra = (itr->second).first + (itr->second).second;
63 #ifdef EDM_ML_DEBUG
64  edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << namx << ":" << name << " iterator "
65  << (itr != offMap_->muonMap_.end()) << " Extra " << extra;
66 #endif
67  }
68  copyno += extra;
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << vol->GetName() << " " << copyno << " Split "
71  << copyNoRelevant(copyno) << ":" << theLevelPart << ":" << theSuperPart << " ";
72 #endif
73  if (copyNoRelevant(copyno)) {
74  num.addBase(getCopyNoLevel(copyno), getCopyNoSuperNo(copyno), getCopyNoBaseNo(copyno) - theStartCopyNo);
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("MuonSim") << " NoLevel " << getCopyNoLevel(copyno) << " Super " << getCopyNoSuperNo(copyno)
77  << " Base " << getCopyNoBaseNo(copyno) << " Start " << theStartCopyNo;
78 #endif
79  }
80  }
81 
82  return num;
83 }
84 
85 const int MuonG4Numbering::getCopyNoLevel(const int copyno) { return copyno / theLevelPart; }
86 
87 const int MuonG4Numbering::getCopyNoSuperNo(const int copyno) { return (copyno % theLevelPart) / theSuperPart; }
88 
89 const int MuonG4Numbering::getCopyNoBaseNo(const int copyno) { return copyno % theSuperPart; }
90 
91 const bool MuonG4Numbering::copyNoRelevant(const int copyno) { return (copyno / theLevelPart) > 0; }
int getValue(const std::string &name) const
Log< level::Info, true > LogVerbatim
const int getCopyNoLevel(const int)
const MuonOffsetMap * offMap_
const int getCopyNoBaseNo(const int)
U second(std::pair< T, U > const &p)
const bool dd4hep_
ii
Definition: cuy.py:589
MuonBaseNumber PhysicalVolumeToBaseNumber(const G4Step *aStep)
const bool copyNoRelevant(const int)
std::string noNameSpace(const std::string &name)
const int getCopyNoSuperNo(const int)
MuonG4Numbering(const MuonGeometryConstants &muonConstants, const MuonOffsetMap *offMap, bool dd4hep)
std::unordered_map< std::string, std::pair< int, int > > muonMap_
Definition: MuonOffsetMap.h:14