Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mini-PR: Fix EcalBaseNumber::getCopyNumber behavior #31963

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Geometry/EcalCommonData/src/EcalBaseNumber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int EcalBaseNumber::getCopyNumber(int level) const { return _sortedCopyNumber[le

int EcalBaseNumber::getCopyNumber(const std::string& levelName) const {
for (int iLevel = 0; iLevel < _theLevels; iLevel++) {
if (_sortedName[iLevel].find(levelName) != std::string::npos) {
if (_sortedName[iLevel] == levelName) {
return _sortedCopyNumber[iLevel];
}
}
Expand Down
1 change: 1 addition & 0 deletions SimG4CMS/Calo/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<use name="CommonTools/UtilAlgos"/>
<use name="boost"/>
<use name="clhep"/>
<use name="dd4hep"/>
<use name="geant4core"/>
<use name="hepmc"/>
<use name="root"/>
Expand Down
1 change: 0 additions & 1 deletion SimG4CMS/Calo/interface/ECalSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ECalSD : public CaloSD {

void getBaseNumber(const G4Step *);
double getBirkL3(const G4Step *);
std::string getNameNoNS(const std::string &name);

// initialised before run
const EcalSimulationParameters *ecalSimParameters_;
Expand Down
38 changes: 15 additions & 23 deletions SimG4CMS/Calo/src/ECalSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"

#include "DD4hep/Filter.h"

#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Step.hh"
#include "G4Track.hh"
#include "G4VProcess.hh"

#include "G4SystemOfUnits.hh"

#include <algorithm>
Expand Down Expand Up @@ -221,9 +222,9 @@ double ECalSD::getEnergyDeposit(const G4Step* aStep) {
edep *= wt2;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EcalSim") << lv->GetName() << " " << getNameNoNS(lv->GetName()) << " Light Collection Efficiency "
<< weight << ":" << wt1 << " wt2= " << wt2 << " Weighted Energy Deposit "
<< edep / CLHEP::MeV << " MeV";
edm::LogVerbatim("EcalSim") << lv->GetName() << " " << dd4hep::dd::noNamespace(lv->GetName())
<< " Light Collection Efficiency " << weight << ":" << wt1 << " wt2= " << wt2
<< " Weighted Energy Deposit " << edep / CLHEP::MeV << " MeV";
#endif
return edep;
}
Expand Down Expand Up @@ -296,7 +297,7 @@ uint16_t ECalSD::getRadiationLength(const G4StepPoint* hitPoint, const G4Logical
#endif
#ifdef EDM_ML_DEBUG
G4ThreeVector localPoint = setToLocal(hitPoint->GetPosition(), hitPoint->GetTouchable());
edm::LogVerbatim("EcalSim") << lv->GetName() << " " << getNameNoNS(lv->GetName()) << " Global "
edm::LogVerbatim("EcalSim") << lv->GetName() << " " << dd4hep::dd::noNamespace(lv->GetName()) << " Global "
<< hitPoint->GetPosition() << ":" << (hitPoint->GetPosition()).rho() << " Local "
<< localPoint << " Crystal Length " << crystalLength << " Radl " << radl
<< " crystalDepth " << crystalDepth << " Index " << thisX0 << " : "
Expand Down Expand Up @@ -334,7 +335,7 @@ void ECalSD::initMap() {
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
std::map<const std::string, const G4LogicalVolume*> nameMap;
for (auto lvi = lvs->begin(), lve = lvs->end(); lvi != lve; ++lvi)
nameMap.emplace(getNameNoNS((*lvi)->GetName()), *lvi);
nameMap.emplace(dd4hep::dd::noNamespace((*lvi)->GetName()), *lvi);

for (unsigned int it = 0; it < ecalSimParameters_->lvNames_.size(); ++it) {
const std::string& matname = ecalSimParameters_->matNames_[it];
Expand Down Expand Up @@ -436,7 +437,7 @@ double ECalSD::curve_LY(const G4LogicalVolume* lv) {
} else {
edm::LogWarning("EcalSim") << "ECalSD: light coll curve : wrong distance "
<< "to APD " << dapd << " crlength = " << crystalLength
<< " crystal name = " << lv->GetName() << " " << getNameNoNS(lv->GetName())
<< " crystal name = " << lv->GetName() << " " << dd4hep::dd::noNamespace(lv->GetName())
<< " z of localPoint = " << currentLocalPoint.z() << " take weight = " << weight;
}
}
Expand All @@ -452,11 +453,11 @@ void ECalSD::getBaseNumber(const G4Step* aStep) {
//Get name and copy numbers
if (theSize > 1) {
for (int ii = 0; ii < theSize; ii++) {
theBaseNumber.addLevel(getNameNoNS(touch->GetVolume(ii)->GetName()), touch->GetReplicaNumber(ii));
std::string_view name = dd4hep::dd::noNamespace(touch->GetVolume(ii)->GetName());
theBaseNumber.addLevel(std::string(name), touch->GetReplicaNumber(ii));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EcalSim") << "ECalSD::getBaseNumber(): Adding level " << ii << ": "
<< getNameNoNS(touch->GetVolume(ii)->GetName()) << "[" << touch->GetReplicaNumber(ii)
<< "]";
edm::LogVerbatim("EcalSim") << "ECalSD::getBaseNumber(): Adding level " << ii << ": " << name << "["
<< touch->GetReplicaNumber(ii) << "]";
#endif
}
}
Expand All @@ -480,19 +481,10 @@ double ECalSD::getBirkL3(const G4Step* aStep) {
weight = 1.;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EcalSim") << "ECalSD::getBirkL3 in " << getNameNoNS(mat->GetName()) << " Charge " << charge
<< " dE/dx " << dedx << " Birk Const " << rkb << " Weight = " << weight << " dE "
<< aStep->GetTotalEnergyDeposit();
edm::LogVerbatim("EcalSim") << "ECalSD::getBirkL3 in " << dd4hep::dd::noNamespace(mat->GetName()) << " Charge "
<< charge << " dE/dx " << dedx << " Birk Const " << rkb << " Weight = " << weight
<< " dE " << aStep->GetTotalEnergyDeposit();
#endif
}
return weight;
}

std::string ECalSD::getNameNoNS(const std::string& name) {
if (name.find(':') == std::string::npos) {
return name;
} else {
auto n1 = name.find(':') + 1;
return name.substr(n1, (name.size() - n1));
}
}