CMS 3D CMS Logo

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