Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:52

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "Geometry/EcalCommonData/interface/EcalBarrelNumberingScheme.h"
0003 #include "Geometry/EcalCommonData/interface/EcalBaseNumber.h"
0004 #include "Geometry/EcalCommonData/interface/EcalEndcapNumberingScheme.h"
0005 #include "Geometry/EcalCommonData/interface/EcalPreshowerNumberingScheme.h"
0006 #include "SimG4Core/Geometry/interface/DD4hep2DDDName.h"
0007 #include "SimG4CMS/Calo/interface/EcalDumpGeometry.h"
0008 
0009 #include <iostream>
0010 
0011 EcalDumpGeometry::EcalDumpGeometry(const std::vector<std::string_view>& names,
0012                                    const std::string& name1,
0013                                    const std::string& name2,
0014                                    int type)
0015     : name1_(name1), name2_(name2), type_(type) {
0016   std::stringstream ss;
0017   for (const auto& lvname : names)
0018     ss << " " << lvname;
0019   G4cout << " Type: " << type << " Depth Names " << name1_ << ":" << name2_ << " with " << names.size()
0020          << " LVs: " << ss.str() << G4endl;
0021   for (const auto& name : names) {
0022     std::string namex = DD4hep2DDDName::noNameSpace(static_cast<std::string>(name)).substr(0, 4);
0023     if (std::find(names_.begin(), names_.end(), namex) == names_.end())
0024       names_.emplace_back(namex);
0025   }
0026   G4cout << "EcalDumpGeometry:: dump geometry information for detector of type " << type_ << " with " << names_.size()
0027          << " elements:" << G4endl;
0028   for (unsigned int k = 0; k < names_.size(); ++k)
0029     G4cout << "[" << k << "] : " << names_[k] << G4endl;
0030 }
0031 
0032 void EcalDumpGeometry::update() {
0033   G4VPhysicalVolume* theTopPV =
0034       G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
0035   G4cout << "EcalDumpGeometry entered with entry of top PV at " << theTopPV << G4endl;
0036 
0037   dumpTouch(theTopPV, 0);
0038   fHistory_.SetFirstEntry(theTopPV);
0039   G4cout << "EcalDumpGeometry finds " << infoVec_.size() << " touchables" << G4endl;
0040   sort(infoVec_.begin(), infoVec_.end(), CaloDetInfoLess());
0041   unsigned int k(0);
0042   for (const auto& info : infoVec_) {
0043     G4cout << "[" << k << "] " << info << G4endl;
0044     if (info.flag() && (info.solid() != nullptr)) {
0045       info.solid()->DumpInfo();
0046       G4cout << G4endl;
0047     }
0048     ++k;
0049   }
0050 }
0051 
0052 void EcalDumpGeometry::dumpTouch(G4VPhysicalVolume* pv, unsigned int leafDepth) {
0053   if (leafDepth == 0)
0054     fHistory_.SetFirstEntry(pv);
0055   else
0056     fHistory_.NewLevel(pv, kNormal, pv->GetCopyNo());
0057 
0058   G4ThreeVector globalpoint = fHistory_.GetTopTransform().Inverse().TransformPoint(G4ThreeVector(0, 0, 0));
0059   G4LogicalVolume* lv = pv->GetLogicalVolume();
0060 
0061   bool flag = ((type_ / 10) % 10 > 0);
0062   std::string lvname = DD4hep2DDDName::noNameSpace(static_cast<std::string>(lv->GetName()));
0063   std::string namex = lvname.substr(0, 4);
0064   EcalBaseNumber theBaseNumber;
0065   for (unsigned int k = 0; k < names_.size(); ++k) {
0066     if (namex == names_[k]) {
0067       int theSize = fHistory_.GetDepth();
0068       //Get name and copy numbers
0069       if (theSize > 5) {
0070         theBaseNumber.reset();
0071         if (theBaseNumber.getCapacity() < theSize + 1)
0072           theBaseNumber.setSize(theSize + 1);
0073         std::stringstream ss;
0074         for (int ii = theSize; ii >= 0; --ii) {
0075           std::string name = DD4hep2DDDName::noNameSpace(static_cast<std::string>(fHistory_.GetVolume(ii)->GetName()));
0076           theBaseNumber.addLevel(name, fHistory_.GetVolume(ii)->GetCopyNo());
0077           ss << " " << ii << " " << name << ":" << fHistory_.GetVolume(ii)->GetCopyNo();
0078         }
0079         uint32_t id = (((type_ % 10) == 0) ? ebNumbering_.getUnitID(theBaseNumber)
0080                                            : (((type_ % 10) == 1) ? eeNumbering_.getUnitID(theBaseNumber)
0081                                                                   : esNumbering_.getUnitID(theBaseNumber)));
0082         uint32_t depth(0);
0083         if ((!name1_.empty()) && (namex == name1_))
0084           depth = 1;
0085         if ((!name2_.empty()) && (namex == name2_))
0086           depth = 2;
0087         double r = globalpoint.rho();
0088         G4cout << " Field: " << ss.str() << " ID " << std::hex << id << std::dec << ":" << depth << ":" << r << G4endl;
0089         G4VSolid* solid = (lv->GetSolid());
0090         if (((type_ / 100) % 10) != 0)
0091           infoVec_.emplace_back(CaloDetInfo(id, depth, r, noRefl(lvname), globalpoint, solid, flag));
0092         else
0093           infoVec_.emplace_back(CaloDetInfo(id, depth, r, lvname, globalpoint, solid, flag));
0094       }
0095       break;
0096     }
0097   }
0098 
0099   int NoDaughters = lv->GetNoDaughters();
0100   while ((NoDaughters--) > 0) {
0101     G4VPhysicalVolume* pvD = lv->GetDaughter(NoDaughters);
0102     if (!pvD->IsReplicated())
0103       dumpTouch(pvD, leafDepth + 1);
0104   }
0105 
0106   if (leafDepth > 0)
0107     fHistory_.BackLevel();
0108 }
0109 
0110 std::string EcalDumpGeometry::noRefl(const std::string& name) {
0111   if (name.find("_refl") == std::string::npos) {
0112     return name;
0113   } else {
0114     size_t n = name.size();
0115     return name.substr(0, n - 5);
0116   }
0117 }