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

Run3-hcx345 Try to fix ieta=16 issue for HCAL simulation in the GEN-SIM step #42105

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions Geometry/HcalCommonData/src/CaloSimulationConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

CaloSimulationConstants::CaloSimulationConstants(const CaloSimulationParameters* csp) : calospar_(csp) {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom")
<< "CaloSimulationConstants::CaloSimulationConstants (const CaloSimulationParameters* csp) constructor\n";
edm::LogVerbatim("HCalGeom")
<< "CaloSimulationConstants::CaloSimulationConstants (const CaloSimulationParameters* csp) constructor";
#endif
}

CaloSimulationConstants::~CaloSimulationConstants() {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "CaloSimulationConstants::destructed!!!\n";
edm::LogVerbatim("HCalGeom") << "CaloSimulationConstants::destructed!!!";
#endif
}
39 changes: 18 additions & 21 deletions Geometry/HcalCommonData/src/HcalDDDSimConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/Math/interface/GeantUnits.h"

//#define EDM_ML_DEBUG
#define EDM_ML_DEBUG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bsunanda , please, comment out debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

using namespace geant_units::operators;

HcalDDDSimConstants::HcalDDDSimConstants(const HcalParameters* hp) : hpar(hp) {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants::HcalDDDSimConstants (const HcalParameters* hp) constructor\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants::HcalDDDSimConstants (const HcalParameters* hp) constructor";
#endif

initialize();
#ifdef EDM_ML_DEBUG
std::vector<HcalCellType> cellTypes = HcalCellTypes();
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << cellTypes.size() << " cells of type HCal (All)\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << cellTypes.size() << " cells of type HCal (All)";
#endif
}

HcalDDDSimConstants::~HcalDDDSimConstants() {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants::destructed!!!\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants::destructed!!!";
#endif
}

Expand Down Expand Up @@ -76,8 +76,8 @@ HcalCellType::HcalCell HcalDDDSimConstants::cell(
} else {
ok = false;
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: wrong eta " << etaR << " (" << ir << "/" << nR
<< ") Detector " << idet << std::endl;
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: wrong eta " << etaR << " (" << ir << "/" << nR
<< ") Detector " << idet;
#endif
}
} else if (etaR <= nEta) {
Expand Down Expand Up @@ -308,9 +308,8 @@ double HcalDDDSimConstants::getEtaHO(const double& etaR, const double& x, const
}
eta = (z >= 0. ? eta : -eta);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "R " << r << " Z " << z << " eta " << etaR << ":" << eta;
if (eta != etaR)
edm::LogInfo("HCalGeom") << "**** Check *****";
std::string chk = (eta != etaR) ? " **** Check *****" : " ";
edm::LogVerbatim("HCalGeom") << "R " << r << " Z " << z << " eta " << etaR << ":" << eta << chk;
#endif
return eta;
} else {
Expand Down Expand Up @@ -505,32 +504,32 @@ std::vector<std::pair<int, double> > HcalDDDSimConstants::getPhis(const int& sub
std::vector<HcalCellType> HcalDDDSimConstants::HcalCellTypes() const {
std::vector<HcalCellType> cellTypes = HcalCellTypes(HcalBarrel);
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: " << cellTypes.size() << " cells of type HCal Barrel\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << cellTypes.size() << " cells of type HCal Barrel";
for (unsigned int i = 0; i < cellTypes.size(); i++)
edm::LogInfo("HCalGeom") << "Cell " << i << " " << cellTypes[i] << "\n";
edm::LogVerbatim("HCalGeom") << "Cell " << i << " " << cellTypes[i];
#endif

std::vector<HcalCellType> hoCells = HcalCellTypes(HcalOuter);
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: " << hoCells.size() << " cells of type HCal Outer\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << hoCells.size() << " cells of type HCal Outer";
for (unsigned int i = 0; i < hoCells.size(); i++)
edm::LogInfo("HCalGeom") << "Cell " << i << " " << hoCells[i] << "\n";
edm::LogVerbatim("HCalGeom") << "Cell " << i << " " << hoCells[i];
#endif
cellTypes.insert(cellTypes.end(), hoCells.begin(), hoCells.end());

std::vector<HcalCellType> heCells = HcalCellTypes(HcalEndcap);
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: " << heCells.size() << " cells of type HCal Endcap\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << heCells.size() << " cells of type HCal Endcap";
for (unsigned int i = 0; i < heCells.size(); i++)
edm::LogInfo("HCalGeom") << "Cell " << i << " " << heCells[i] << "\n";
edm::LogVerbatim("HCalGeom") << "Cell " << i << " " << heCells[i];
#endif
cellTypes.insert(cellTypes.end(), heCells.begin(), heCells.end());

std::vector<HcalCellType> hfCells = HcalCellTypes(HcalForward);
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: " << hfCells.size() << " cells of type HCal Forward\n";
edm::LogVerbatim("HCalGeom") << "HcalDDDSimConstants: " << hfCells.size() << " cells of type HCal Forward";
for (unsigned int i = 0; i < hfCells.size(); i++)
edm::LogInfo("HCalGeom") << "Cell " << i << " " << hfCells[i] << "\n";
edm::LogVerbatim("HCalGeom") << "Cell " << i << " " << hfCells[i];
#endif
cellTypes.insert(cellTypes.end(), hfCells.begin(), hfCells.end());

Expand Down Expand Up @@ -698,8 +697,7 @@ void HcalDDDSimConstants::printTiles() const {
int kphi = (detsp > 0) ? phis[0] : 1;
int zside = (kphi > 0) ? 1 : -1;
int iphi = (kphi > 0) ? kphi : -kphi;
edm::LogVerbatim("HCalGeom") << "Tile Information for HB from " << hpar->etaMin[0] << " to " << hpar->etaMax[0]
<< "\n";
edm::LogVerbatim("HCalGeom") << "Tile Information for HB from " << hpar->etaMin[0] << " to " << hpar->etaMax[0];
for (int eta = hpar->etaMin[0]; eta <= hpar->etaMax[0]; eta++) {
int dmax = getMaxDepth(1, eta, iphi, -zside, false);
for (int depth = 1; depth <= dmax; depth++)
Expand All @@ -711,8 +709,7 @@ void HcalDDDSimConstants::printTiles() const {
}
}

edm::LogVerbatim("HCalGeom") << "\nTile Information for HE from " << hpar->etaMin[1] << " to " << hpar->etaMax[1]
<< "\n";
edm::LogVerbatim("HCalGeom") << "\nTile Information for HE from " << hpar->etaMin[1] << " to " << hpar->etaMax[1];
for (int eta = hpar->etaMin[1]; eta <= hpar->etaMax[1]; eta++) {
int dmin = (eta == hpar->etaMin[1]) ? getDepthEta16(2, iphi, -zside) : 1;
int dmax = getMaxDepth(2, eta, iphi, -zside, false);
Expand Down
9 changes: 6 additions & 3 deletions Geometry/HcalCommonData/src/HcalNumberingFromDDD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ using namespace geant_units::operators;

HcalNumberingFromDDD::HcalNumberingFromDDD(const HcalDDDSimConstants* hcons) : hcalConstants(hcons) {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "Creating HcalNumberingFromDDD\n";
edm::LogVerbatim("HCalGeom") << "Creating HcalNumberingFromDDD";
#endif
}

HcalNumberingFromDDD::~HcalNumberingFromDDD() {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "Deleting HcalNumberingFromDDD\n";
edm::LogVerbatim("HCalGeom") << "Deleting HcalNumberingFromDDD";
#endif
}

Expand Down Expand Up @@ -86,7 +86,7 @@ HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(int det, double etaR,

#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "HcalNumberingFromDDD: etaR = " << etaR << " : " << zside << "/" << ieta << " phi "
<< hphi << " : " << iphi << std::endl;
<< hphi << " : " << iphi;
#endif
return unitID(det, zside, depth, ieta, iphi, lay);
}
Expand All @@ -99,6 +99,9 @@ HcalNumberingFromDDD::HcalID HcalNumberingFromDDD::unitID(
int units = hcalConstants->unitPhi(det, etaR);
int iphi_skip = hcalConstants->phiNumber(phi, units);

if ((lay == 1) && (etaR == 16))
etaR = 15;

std::pair<int, int> etaDepth = hcalConstants->getEtaDepth(det, etaR, iphi_skip, zside, depth, lay);

#ifdef EDM_ML_DEBUG
Expand Down
6 changes: 3 additions & 3 deletions Geometry/HcalCommonData/src/HcalSimulationConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

HcalSimulationConstants::HcalSimulationConstants(const HcalSimulationParameters* hsp) : hspar_(hsp) {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom")
<< "HcalSimulationConstants::HcalSimulationConstants (const HcalSimulationParameters* hsp) constructor\n";
edm::LogVerbatim("HCalGeom")
<< "HcalSimulationConstants::HcalSimulationConstants (const HcalSimulationParameters* hsp) constructor";
#endif
}

HcalSimulationConstants::~HcalSimulationConstants() {
#ifdef EDM_ML_DEBUG
edm::LogInfo("HCalGeom") << "HcalSimulationConstants::destructed!!!\n";
edm::LogVerbatim("HCalGeom") << "HcalSimulationConstants::destructed!!!";
#endif
}
1 change: 1 addition & 0 deletions SimG4CMS/Calo/interface/HCalSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class HCalSD : public CaloSD, public Observer<const BeginOfJob*> {
void plotProfile(const G4Step* step, const G4ThreeVector& pos, double edep, double time, int id);
void plotHF(const G4ThreeVector& pos, bool emType);
void modifyDepth(HcalNumberingFromDDD::HcalID& id);
void printVolume(const G4VTouchable* touch) const;

std::unique_ptr<HcalNumberingFromDDD> numberingFromDDD;
std::unique_ptr<HcalNumberingScheme> numberingScheme;
Expand Down
41 changes: 40 additions & 1 deletion SimG4CMS/Calo/src/HCalSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,28 @@ uint32_t HCalSD::setDetUnitId(const G4Step* aStep) {
int lay = (touch->GetReplicaNumber(0) / 10) % 100 + 1;
int det = (touch->GetReplicaNumber(1)) / 1000;

return setDetUnitId(det, hitPoint, depth, lay);
uint32_t idx = setDetUnitId(det, hitPoint, depth, lay);
#ifdef EDM_ML_DEBUG
if (depth == 1) {
edm::LogVerbatim("HcalSim") << "HCalSD: Check for " << det << ":" << depth << ":" << lay << " ID " << std::hex
<< idx << std::dec;
int det0, z0, depth0, eta0, phi0, lay0(-1);
if (testNumber) {
HcalTestNumbering::unpackHcalIndex(idx, det0, z0, depth0, eta0, phi0, lay0);
} else {
HcalDetId hcid0(idx);
det0 = hcid0.subdetId();
eta0 = hcid0.ietaAbs();
phi0 = hcid0.iphi();
z0 = hcid0.zside();
depth0 = hcid0.depth();
}
edm::LogVerbatim("HcalSim") << "HCalSD: det|z|depth|eta|phi|lay " << det0 << ":" << z0 << ":" << depth0 << ":"
<< eta0 << ":" << phi0 << ":" << lay0;
printVolume(touch);
}
#endif
return idx;
}

void HCalSD::setNumberingScheme(HcalNumberingScheme* scheme) {
Expand Down Expand Up @@ -1096,3 +1117,21 @@ void HCalSD::endEvent() {
<< detNull_[3] << " " << (static_cast<float>(sum) / (sum + detNull_[3]));
#endif
}

void HCalSD::printVolume(const G4VTouchable* touch) const {
if (touch) {
#ifdef EDM_ML_DEBUG
int level = ((touch->GetHistoryDepth()) + 1);
edm::LogVerbatim("CaloSimX") << "HCalSD::printVolume with " << level << " levels";
static const std::string unknown("Unknown");
//Get name and copy numbers
for (int ii = 0; ii < level; ii++) {
int i = level - ii - 1;
G4VPhysicalVolume* pv = touch->GetVolume(i);
G4String name = (pv != nullptr) ? pv->GetName() : unknown;
G4int copyno = touch->GetReplicaNumber(i);
edm::LogVerbatim("HcalSim") << "[" << ii << "] " << name << ":" << copyno;
}
#endif
}
}
4 changes: 2 additions & 2 deletions SimG4CMS/Calo/test/python/ttbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
process.generator.pythiaHepMCVerbosity = False
process.generator.pythiaPylistVerbosity = 0
process.g4SimHits.Physics.type = 'SimG4Core/Physics/FTFP_BERT_EMM'
process.g4SimHits.HCalSD.TestNumberingScheme = False
process.CaloSimHitStudy.TestNumbering = False
#process.g4SimHits.HCalSD.TestNumberingScheme = False
process.CaloSimHitStudy.TestNumbering = True

# Schedule definition
process.schedule = cms.Schedule(process.generation_step,
Expand Down