CMS 3D CMS Logo

EcalDumpGeometry.cc
Go to the documentation of this file.
8 
9 #include <iostream>
10 
11 EcalDumpGeometry::EcalDumpGeometry(const std::vector<std::string_view>& names,
12  const std::string& name1,
13  const std::string& name2,
14  int type)
15  : name1_(name1), name2_(name2), type_(type) {
16  std::stringstream ss;
17  for (const auto& lvname : names)
18  ss << " " << lvname;
19  G4cout << " Type: " << type << " Depth Names " << name1_ << ":" << name2_ << " with " << names.size()
20  << " LVs: " << ss.str() << G4endl;
21  for (const auto& name : names) {
22  std::string namex = DD4hep2DDDName::noNameSpace(static_cast<std::string>(name)).substr(0, 4);
23  if (std::find(names_.begin(), names_.end(), namex) == names_.end())
24  names_.emplace_back(namex);
25  }
26  G4cout << "EcalDumpGeometry:: dump geometry information for detector of type " << type_ << " with " << names_.size()
27  << " elements:" << G4endl;
28  for (unsigned int k = 0; k < names_.size(); ++k)
29  G4cout << "[" << k << "] : " << names_[k] << G4endl;
30 }
31 
33  G4VPhysicalVolume* theTopPV =
34  G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
35  G4cout << "EcalDumpGeometry entered with entry of top PV at " << theTopPV << G4endl;
36 
37  dumpTouch(theTopPV, 0);
38  fHistory_.SetFirstEntry(theTopPV);
39  G4cout << "EcalDumpGeometry finds " << infoVec_.size() << " touchables" << G4endl;
40  sort(infoVec_.begin(), infoVec_.end(), CaloDetInfoLess());
41  unsigned int k(0);
42  for (const auto& info : infoVec_) {
43  G4cout << "[" << k << "] " << info << G4endl;
44  if (info.flag() && (info.solid() != nullptr)) {
45  info.solid()->DumpInfo();
46  G4cout << G4endl;
47  }
48  ++k;
49  }
50 }
51 
52 void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) {
53  if (leafDepth == 0)
54  fHistory_.SetFirstEntry(pv);
55  else
56  fHistory_.NewLevel(pv, kNormal, pv->GetCopyNo());
57 
58  G4ThreeVector globalpoint = fHistory_.GetTopTransform().Inverse().TransformPoint(G4ThreeVector(0, 0, 0));
59  G4LogicalVolume* lv = pv->GetLogicalVolume();
60 
61  bool flag = ((type_ / 10) % 10 > 0);
62  std::string lvname = DD4hep2DDDName::noNameSpace(static_cast<std::string>(lv->GetName()));
63  std::string namex = lvname.substr(0, 4);
64  EcalBaseNumber theBaseNumber;
65  for (unsigned int k = 0; k < names_.size(); ++k) {
66  if (namex == names_[k]) {
67  int theSize = fHistory_.GetDepth();
68  //Get name and copy numbers
69  if (theSize > 5) {
70  theBaseNumber.reset();
71  if (theBaseNumber.getCapacity() < theSize + 1)
72  theBaseNumber.setSize(theSize + 1);
73  std::stringstream ss;
74  for (int ii = theSize; ii >= 0; --ii) {
75  std::string name = DD4hep2DDDName::noNameSpace(static_cast<std::string>(fHistory_.GetVolume(ii)->GetName()));
76  theBaseNumber.addLevel(name, fHistory_.GetVolume(ii)->GetCopyNo());
77  ss << " " << ii << " " << name << ":" << fHistory_.GetVolume(ii)->GetCopyNo();
78  }
79  uint32_t id = (((type_ % 10) == 0) ? ebNumbering_.getUnitID(theBaseNumber)
80  : (((type_ % 10) == 1) ? eeNumbering_.getUnitID(theBaseNumber)
81  : esNumbering_.getUnitID(theBaseNumber)));
82  uint32_t depth(0);
83  if ((!name1_.empty()) && (namex == name1_))
84  depth = 1;
85  if ((!name2_.empty()) && (namex == name2_))
86  depth = 2;
87  double r = globalpoint.rho();
88  G4cout << " Field: " << ss.str() << " ID " << std::hex << id << std::dec << ":" << depth << ":" << r << G4endl;
89  G4VSolid* solid = (lv->GetSolid());
90  if (((type_ / 100) % 10) != 0)
91  infoVec_.emplace_back(CaloDetInfo(id, depth, r, noRefl(lvname), globalpoint, solid, flag));
92  else
93  infoVec_.emplace_back(CaloDetInfo(id, depth, r, lvname, globalpoint, solid, flag));
94  }
95  break;
96  }
97  }
98 
99  int NoDaughters = lv->GetNoDaughters();
100  while ((NoDaughters--) > 0) {
101  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
102  if (!pvD->IsReplicated())
103  dumpTouch(pvD, leafDepth + 1);
104  }
105 
106  if (leafDepth > 0)
107  fHistory_.BackLevel();
108 }
109 
111  if (name.find("_refl") == std::string::npos) {
112  return name;
113  } else {
114  size_t n = name.size();
115  return name.substr(0, n - 5);
116  }
117 }
static const TGPicture * info(bool iBackgroundIsBlack)
std::string noRefl(const std::string &name)
EcalPreshowerNumberingScheme esNumbering_
EcalDumpGeometry(const std::vector< std::string_view > &, const std::string &, const std::string &, int)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const std::string names[nVars_]
void addLevel(const std::string &name, const int &copyNumber)
uint32_t getUnitID(const EcalBaseNumber &baseNumber) const override
uint32_t getUnitID(const EcalBaseNumber &baseNumber) const override
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth)
std::vector< CaloDetInfo > infoVec_
std::vector< std::string > names_
ii
Definition: cuy.py:589
EcalEndcapNumberingScheme eeNumbering_
G4NavigationHistory fHistory_
uint32_t getUnitID(const EcalBaseNumber &baseNumber) const override
const std::string name1_
EcalBarrelNumberingScheme ebNumbering_
const std::string name2_
std::string noNameSpace(const std::string &name)
void setSize(const int &size)