CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalDumpGeometry.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 #include <memory>
7 
8 //#define EDM_ML_DEBUG
9 
10 HcalDumpGeometry::HcalDumpGeometry(const std::vector<std::string_view>& names,
11  const HcalNumberingFromDDD* hcn,
12  bool test,
13  bool flag)
14  : numberingFromDDD_(hcn), flag_(flag) {
15  if (test)
16  numberingScheme_.reset(dynamic_cast<HcalNumberingScheme*>(new HcalTestNumberingScheme(false)));
17  else
18  numberingScheme_ = std::make_unique<HcalNumberingScheme>();
19  std::stringstream ss;
20  for (const auto& lvname : names)
21  ss << " " << lvname;
22  edm::LogVerbatim("HCalGeom") << " Testmode: " << test << " with " << names.size() << " LVs: " << ss.str();
23  const std::vector<std::string> namg = {"HBS", "HES", "HTS", "HVQ"};
24  for (const auto& name : names) {
25  std::string namex = (getNameNoNS(static_cast<std::string>(name))).substr(0, 3);
26  if (std::find(namg.begin(), namg.end(), namex) != namg.end()) {
27  if (std::find(names_.begin(), names_.end(), namex) == names_.end())
28  names_.emplace_back(namex);
29  }
30  }
31  edm::LogVerbatim("HCalGeom") << "HcalDumpGeometry:: dump geometry information for Hcal with " << names_.size()
32  << " elements:";
33  for (unsigned int k = 0; k < names_.size(); ++k)
34  edm::LogVerbatim("HCalGeom") << "[" << k << "] : " << names_[k];
35 }
36 
38  G4VPhysicalVolume* theTopPV =
39  G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
40  edm::LogVerbatim("HCalGeom") << "HcalDumpGeometry entered with entry of top PV at " << theTopPV;
41 
42  dumpTouch(theTopPV, 0);
43  fHistory_.SetFirstEntry(theTopPV);
44  edm::LogVerbatim("HCalGeom") << "HcalDumpGeometry finds " << infoVec_.size() << " touchables";
45  sort(infoVec_.begin(), infoVec_.end(), CaloDetInfoLess());
46  unsigned int k(0);
47  for (const auto& info : infoVec_) {
48  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << info;
49  if (info.flag() && (info.solid() != nullptr)) {
50  info.solid()->DumpInfo();
51  G4cout << G4endl;
52  }
53  ++k;
54  }
55 }
56 
57 void HcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) {
58  if (leafDepth == 0)
59  fHistory_.SetFirstEntry(pv);
60  else
61  fHistory_.NewLevel(pv, kNormal, pv->GetCopyNo());
62 
63  G4ThreeVector globalpoint = fHistory_.GetTopTransform().Inverse().TransformPoint(G4ThreeVector(0, 0, 0));
64  G4LogicalVolume* lv = pv->GetLogicalVolume();
65 
66  const std::string& lvname = lv->GetName();
67  std::string namex = (getNameNoNS(lvname)).substr(0, 3);
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  int depth = (fHistory_.GetVolume(theSize)->GetCopyNo()) % 10 + 1;
74  int lay = (fHistory_.GetVolume(theSize)->GetCopyNo() / 10) % 100 + 1;
75  int det = (fHistory_.GetVolume(theSize - 1)->GetCopyNo()) / 1000;
77  det, math::XYZVectorD(globalpoint.x(), globalpoint.y(), globalpoint.z()), depth, lay);
78  uint32_t id = numberingScheme_->getUnitID(tmp);
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HCalGeom") << "Det " << det << " Layer " << lay << ":" << depth << " Volume "
81  << fHistory_.GetVolume(theSize)->GetName() << ":"
82  << fHistory_.GetVolume(theSize - 1)->GetName() << " ID " << std::hex << id
83  << std::dec;
84 #endif
85 
86  G4VSolid* solid = lv->GetSolid();
87  infoVec_.emplace_back(CaloDetInfo(id, 0, 0, getNameNoNS(lvname), globalpoint, solid, flag_));
88  }
89  break;
90  }
91  }
92 
93  int NoDaughters = lv->GetNoDaughters();
94  while ((NoDaughters--) > 0) {
95  G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
96  if (!pvD->IsReplicated())
97  dumpTouch(pvD, leafDepth + 1);
98  }
99 
100  if (leafDepth > 0)
101  fHistory_.BackLevel();
102 }
103 
105  if (name.find(':') == std::string::npos) {
106  return name;
107  } else {
108  auto n1 = name.find(':') + 1;
109  return name.substr(n1, (name.size() - n1));
110  }
111 }
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
struct @724 flag_
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_]
std::vector< std::string > names_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
std::string getNameNoNS(const std::string &name)
std::vector< CaloDetInfo > infoVec_
HcalID unitID(int det, const math::XYZVectorD &pos, int depth, int lay=-1) const
G4NavigationHistory fHistory_
HcalDumpGeometry(const std::vector< std::string_view > &, const HcalNumberingFromDDD *, bool, bool flag=false)
const HcalNumberingFromDDD * numberingFromDDD_
std::unique_ptr< HcalNumberingScheme > numberingScheme_
tmp
align.sh
Definition: createJobs.py:716
void dumpTouch(G4VPhysicalVolume *pv, unsigned int leafDepth)