Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:24

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