Skip to content

Commit

Permalink
remove redundant loop when checking ecal-hcal neighbours
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannimarchiori committed Nov 11, 2024
1 parent b81d7c3 commit f2289d1
Showing 1 changed file with 9 additions and 127 deletions.
136 changes: 9 additions & 127 deletions RecFCCeeCalorimeter/src/components/CreateFCCeeCaloNeighbours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()
//////////////////////////////////////////////////
/// BARREL: connection ECAL + HCAL ///
/////////////////////////////////////////////////
int count = 0;

std::set<dd4hep::DDSegmentation::CellID> linkedCells;

if (m_connectBarrels)
{
Expand Down Expand Up @@ -364,10 +365,7 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()

// retrieve needed parameters
double hCalThetaSize = hcalBarrelSegmentation->gridSizeTheta();
double hCalThetaOffset = hcalBarrelSegmentation->offsetTheta();
double hCalPhiOffset = hcalBarrelSegmentation->offsetPhi();
double hCalPhiSize = hcalBarrelSegmentation->gridSizePhi();
int hCalPhiBins = hcalBarrelSegmentation->phiBins();
double eCalThetaOffset, eCalThetaSize;
double eCalPhiOffset, eCalPhiSize;
int eCalModules(-1);
Expand Down Expand Up @@ -402,124 +400,6 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()
dd4hep::DDSegmentation::CellID cellIdECal = volumeIdECal;
dd4hep::DDSegmentation::CellID cellIdHCal = volumeIdHCal;

// Loop over ECAL segmentation cells to find neighbours in HCAL
if (ecalBarrelModuleThetaSegmentation)
{
for (int imodule = extremaECalLastLayerModule.first; imodule <= extremaECalLastLayerModule.second; imodule += ecalBarrelModuleThetaSegmentation->mergedModules(eCalLastLayer))
{
(*decoderECalBarrel)["module"].set(cellIdECal, imodule);
double dphi = ecalBarrelModuleThetaSegmentation->phi(cellIdECal);
double phiVol = eCalPhiOffset + imodule * eCalPhiSize;
double phi = phiVol + dphi;
double phiMin = phi - 0.5 * eCalPhiSize * ecalBarrelModuleThetaSegmentation->mergedModules(eCalLastLayer);
double phiMax = phi + 0.5 * eCalPhiSize * ecalBarrelModuleThetaSegmentation->mergedModules(eCalLastLayer);
int minPhiHCal = int(floor((phiMin - hCalPhiOffset + 0.5*hCalPhiSize) / hCalPhiSize));
int maxPhiHCal = int(floor((phiMax - hCalPhiOffset + 0.5*hCalPhiSize) / hCalPhiSize));
for (int itheta = extremaECalLastLayerTheta.first; itheta <= extremaECalLastLayerTheta.second; itheta += ecalBarrelModuleThetaSegmentation->mergedThetaCells(eCalLastLayer))
{
(*decoderECalBarrel)["theta"].set(cellIdECal, itheta);
double theta = ecalBarrelModuleThetaSegmentation->theta(cellIdECal);
double thetaMin = theta - eCalThetaSize * ecalBarrelModuleThetaSegmentation->mergedThetaCells(eCalLastLayer) / 2.;
double thetaMax = theta + eCalThetaSize * ecalBarrelModuleThetaSegmentation->mergedThetaCells(eCalLastLayer) / 2.;
int minThetaHCal = int(floor((thetaMin - hCalThetaOffset + 0.5*hCalThetaSize) / hCalThetaSize));
int maxThetaHCal = int(floor((thetaMax - hCalThetaOffset + 0.5*hCalThetaSize) / hCalThetaSize));
debug() << "ECAL cell: cellId = " << cellIdECal << " module = " << imodule << " theta bin = " << itheta << endmsg;
debug() << "ECAL cell: phi = " << phi << " theta = " << theta << endmsg;
debug() << "ECAL cell: thetaMin = " << thetaMin << " thetaMax = " << thetaMax << endmsg;
debug() << "ECAL cell: phiMin = " << phiMin << " phiMax = " << phiMax << endmsg;
debug() << "ECAL cell: theta bin of neighbours in HCAL layer 0 = " << minThetaHCal << " - " << maxThetaHCal << endmsg;
debug() << "ECAL cell: phi bin of neighbours in HCAL layer 0 = " << minPhiHCal << " - " << maxPhiHCal << endmsg;
bool hasNeighbours = false;
for (int iphiHCal = minPhiHCal; iphiHCal <= maxPhiHCal; iphiHCal++)
{
int phiBinHCal = iphiHCal;
// bring phi bin in 0..nbins-1 range
if (phiBinHCal < 0)
phiBinHCal += hCalPhiBins;
if (phiBinHCal >= hCalPhiBins)
phiBinHCal -= hCalPhiBins;
if (phiBinHCal < extremaHCalFirstLayerPhi.first || phiBinHCal > extremaHCalFirstLayerPhi.second)
{
warning() << "phi bin " << phiBinHCal << " out of range, skipping" << endmsg;
continue;
}
(*decoderHCalBarrel)["phi"].set(cellIdHCal, phiBinHCal);
for (int ithetaHCal = minThetaHCal; ithetaHCal <= maxThetaHCal; ithetaHCal++)
{
if (ithetaHCal < extremaHCalFirstLayerTheta.first || ithetaHCal > extremaHCalFirstLayerTheta.second)
{
warning() << "theta bin " << ithetaHCal << " out of range, skipping" << endmsg;
continue;
}
(*decoderHCalBarrel)["theta"].set(cellIdHCal, ithetaHCal);
debug() << "ECAL cell: neighbour in HCAL has cellID = " << cellIdHCal << endmsg;
map.find((uint64_t)cellIdECal)->second.push_back((uint64_t)cellIdHCal);
hasNeighbours = true;
}
}
if (hasNeighbours)
count++;
}
}
}
else
{
for (int iphi = extremaECalLastLayerPhi.first; iphi <= extremaECalLastLayerPhi.second; iphi++)
{
(*decoderECalBarrel)["phi"].set(cellIdECal, iphi);
double phi = ecalBarrelPhiThetaSegmentation->phi(cellIdECal);
double phiMin = phi - 0.5 * eCalPhiSize;
double phiMax = phi + 0.5 * eCalPhiSize;
int minPhiHCal = int(floor((phiMin - hCalPhiOffset + 0.5*hCalPhiSize) / hCalPhiSize));
int maxPhiHCal = int(floor((phiMax - hCalPhiOffset + 0.5*hCalPhiSize) / hCalPhiSize));
for (int itheta = extremaECalLastLayerTheta.first; itheta <= extremaECalLastLayerTheta.second; itheta ++)
{
(*decoderECalBarrel)["theta"].set(cellIdECal, itheta);
double theta = ecalBarrelPhiThetaSegmentation->theta(cellIdECal);
double thetaMin = theta - 0.5 * eCalThetaSize;
double thetaMax = theta + 0.5 * eCalThetaSize;
int minThetaHCal = int(floor((thetaMin - hCalThetaOffset + 0.5*hCalThetaSize) / hCalThetaSize));
int maxThetaHCal = int(floor((thetaMax - hCalThetaOffset + 0.5*hCalThetaSize) / hCalThetaSize));
debug() << "ECAL cell: cellId = " << cellIdECal << " phi bin = " << iphi << " theta bin = " << itheta << endmsg;
debug() << "ECAL cell: phi = " << phi << " theta = " << theta << endmsg;
debug() << "ECAL cell: thetaMin = " << thetaMin << " thetaMax = " << thetaMax << endmsg;
debug() << "ECAL cell: phiMin = " << phiMin << " phiMax = " << phiMax << endmsg;
debug() << "ECAL cell: theta bin of neighbours in HCAL layer 0 = " << minThetaHCal << " - " << maxThetaHCal << endmsg;
debug() << "ECAL cell: phi bin of neighbours in HCAL layer 0 = " << minPhiHCal << " - " << maxPhiHCal << endmsg;
bool hasNeighbours = false;
for (int iphiHCal = minPhiHCal; iphiHCal <= maxPhiHCal; iphiHCal++)
{
int phiBinHCal = iphiHCal;
// bring phi bin in 0..nbins-1 range
if (phiBinHCal < 0)
phiBinHCal += hCalPhiBins;
if (phiBinHCal >= hCalPhiBins)
phiBinHCal -= hCalPhiBins;
if (phiBinHCal < extremaHCalFirstLayerPhi.first || phiBinHCal > extremaHCalFirstLayerPhi.second)
{
warning() << "phi bin " << phiBinHCal << " out of range, skipping" << endmsg;
continue;
}
(*decoderHCalBarrel)["phi"].set(cellIdHCal, phiBinHCal);
for (int ithetaHCal = minThetaHCal; ithetaHCal <= maxThetaHCal; ithetaHCal++)
{
if (ithetaHCal < extremaHCalFirstLayerTheta.first || ithetaHCal > extremaHCalFirstLayerTheta.second)
{
warning() << "theta bin " << ithetaHCal << " out of range, skipping" << endmsg;
continue;
}
(*decoderHCalBarrel)["theta"].set(cellIdHCal, ithetaHCal);
debug() << "ECAL cell: neighbour in HCAL has cellID = " << cellIdHCal << endmsg;
map.find((uint64_t)cellIdECal)->second.push_back((uint64_t)cellIdHCal);
hasNeighbours = true;
}
}
if (hasNeighbours)
count++;
}
}
}

// Loop over HCAL segmentation cells to find neighbours in ECAL
// Loop on phi
for (int iphi = extremaHCalFirstLayerPhi.first; iphi <= extremaHCalFirstLayerPhi.second; iphi++)
Expand Down Expand Up @@ -611,7 +491,9 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()
(*decoderECalBarrel)["module"].set(cellIdECal, module);
debug() << "HCAL cell: neighbour in ECAL has cellID = " << cellIdECal << endmsg;
map.find((uint64_t)cellIdHCal)->second.push_back((uint64_t)cellIdECal);
hasNeighbours = true;
map.find((uint64_t)cellIdECal)->second.push_back((uint64_t)cellIdHCal);
linkedCells.insert(cellIdHCal);
linkedCells.insert(cellIdECal);
}
}
else
Expand All @@ -632,11 +514,11 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()
(*decoderECalBarrel)["phi"].set(cellIdECal, phiBinECal);
debug() << "HCAL cell: neighbour in ECAL has cellID = " << cellIdECal << endmsg;
map.find((uint64_t)cellIdHCal)->second.push_back((uint64_t)cellIdECal);
hasNeighbours = true;
map.find((uint64_t)cellIdECal)->second.push_back((uint64_t)cellIdHCal);
linkedCells.insert(cellIdHCal);
linkedCells.insert(cellIdECal);
}
}
if (hasNeighbours)
count++;
}
}
}
Expand All @@ -659,7 +541,7 @@ StatusCode CreateFCCeeCaloNeighbours::initialize()
}
}
}
debug() << "cells with neighbours across Calo boundaries: " << count << endmsg;
debug() << "cells with neighbours across Calo boundaries: " << linkedCells.size() << endmsg;

// Check if output directory exists
std::string outDirPath = gSystem->DirName(m_outputFileName.c_str());
Expand Down

0 comments on commit f2289d1

Please sign in to comment.