CMS 3D CMS Logo

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