Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:10

0001 #include "SimG4CMS/Muon/interface/MuonG4Numbering.h"
0002 #include "SimG4Core/Geometry/interface/DD4hep2DDDName.h"
0003 #include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h"
0004 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
0005 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "G4VPhysicalVolume.hh"
0009 #include "G4VTouchable.hh"
0010 #include "G4Step.hh"
0011 
0012 #include <iostream>
0013 
0014 //#define EDM_ML_DEBUG
0015 
0016 MuonG4Numbering::MuonG4Numbering(const MuonGeometryConstants& muonConstants, const MuonOffsetMap* offMap, bool dd4hep)
0017     : offMap_(offMap), dd4hep_(dd4hep) {
0018   theLevelPart = muonConstants.getValue("level");
0019   theSuperPart = muonConstants.getValue("super");
0020   theBasePart = muonConstants.getValue("base");
0021   theStartCopyNo = muonConstants.getValue("xml_starts_with_copyno");
0022 
0023   // some consistency checks
0024 
0025   if (theBasePart != 1) {
0026     edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual base constant:" << theBasePart;
0027   }
0028   if (theSuperPart < 100) {
0029     edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual super constant:" << theSuperPart;
0030   }
0031   if (theLevelPart < 10 * theSuperPart) {
0032     edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual level constant:" << theLevelPart;
0033   }
0034   if ((theStartCopyNo != 0) && (theStartCopyNo != 1)) {
0035     edm::LogVerbatim("MuonSim") << "MuonGeometryNumbering finds unusual start value for copy numbers:"
0036                                 << theStartCopyNo;
0037   }
0038 
0039 #ifdef EDM_ML_DEBUG
0040   edm::LogVerbatim("MuonSim") << "StartCopyNo = " << theStartCopyNo;
0041   edm::LogVerbatim("MuonSim") << "MuonG4Numbering configured with Level = " << theLevelPart
0042                               << " Super = " << theSuperPart << " Base = " << theBasePart
0043                               << " StartCopyNo = " << theStartCopyNo;
0044   edm::LogVerbatim("MuonSim") << "dd4hep flag set to " << dd4hep_ << " and offsetmap at " << offMap_;
0045 #endif
0046 }
0047 
0048 MuonBaseNumber MuonG4Numbering::PhysicalVolumeToBaseNumber(const G4Step* aStep) {
0049   MuonBaseNumber num;
0050   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0051 
0052   for (int ii = 0; ii < touch->GetHistoryDepth(); ii++) {
0053     G4VPhysicalVolume* vol = touch->GetVolume(ii);
0054     int copyno = vol->GetCopyNo();
0055     int extra(0);
0056     if (dd4hep_ && (offMap_ != nullptr)) {
0057       std::string namx = DD4hep2DDDName::noNameSpace(static_cast<std::string>(vol->GetName()));
0058       std::size_t last = namx.rfind('_');
0059       std::string name = ((last == std::string::npos) ? namx : (namx.substr(0, last)));
0060       auto itr = offMap_->muonMap_.find(name);
0061       if (itr != offMap_->muonMap_.end())
0062         extra = (itr->second).first + (itr->second).second;
0063 #ifdef EDM_ML_DEBUG
0064       edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << namx << ":" << name << " iterator "
0065                                   << (itr != offMap_->muonMap_.end()) << " Extra " << extra;
0066 #endif
0067     }
0068     copyno += extra;
0069 #ifdef EDM_ML_DEBUG
0070     edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << vol->GetName() << " " << copyno << " Split "
0071                                 << copyNoRelevant(copyno) << ":" << theLevelPart << ":" << theSuperPart << " ";
0072 #endif
0073     if (copyNoRelevant(copyno)) {
0074       num.addBase(getCopyNoLevel(copyno), getCopyNoSuperNo(copyno), getCopyNoBaseNo(copyno) - theStartCopyNo);
0075 #ifdef EDM_ML_DEBUG
0076       edm::LogVerbatim("MuonSim") << " NoLevel " << getCopyNoLevel(copyno) << " Super " << getCopyNoSuperNo(copyno)
0077                                   << " Base " << getCopyNoBaseNo(copyno) << " Start " << theStartCopyNo;
0078 #endif
0079     }
0080   }
0081 
0082   return num;
0083 }
0084 
0085 const int MuonG4Numbering::getCopyNoLevel(const int copyno) { return copyno / theLevelPart; }
0086 
0087 const int MuonG4Numbering::getCopyNoSuperNo(const int copyno) { return (copyno % theLevelPart) / theSuperPart; }
0088 
0089 const int MuonG4Numbering::getCopyNoBaseNo(const int copyno) { return copyno % theSuperPart; }
0090 
0091 const bool MuonG4Numbering::copyNoRelevant(const int copyno) { return (copyno / theLevelPart) > 0; }