Skip to content

Commit

Permalink
move ReadNoiseFromFileTool for theta-based readout to new tool in FCC…
Browse files Browse the repository at this point in the history
…ee subdirectory
  • Loading branch information
giovannimarchiori committed Sep 29, 2023
1 parent b491630 commit 68792c4
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 89 deletions.
97 changes: 19 additions & 78 deletions RecCalorimeter/src/components/ReadNoiseFromFileTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ DECLARE_COMPONENT(ReadNoiseFromFileTool)
ReadNoiseFromFileTool::ReadNoiseFromFileTool(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
declareInterface<INoiseConstTool>(this);
declareProperty("cellPositionsTool", m_cellPositionsTool, "Handle for tool to retrieve cell positions");
}

StatusCode ReadNoiseFromFileTool::initialize() {
Expand All @@ -30,26 +29,10 @@ StatusCode ReadNoiseFromFileTool::initialize() {
<< "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg;
return StatusCode::FAILURE;
}

// Check if cell position tool available if m_useSeg==false; if tool not
// available, try using segmentation instead
if (!m_useSeg){
if (!m_cellPositionsTool.retrieve()) {
info() << "Unable to retrieve cell positions tool, try eta-phi segmentation." << endmsg;
m_useSeg = true;
}
}

// Get PhiEta segmentation
if (m_useSeg) {
m_segmentation = dynamic_cast<dd4hep::DDSegmentation::FCCSWGridPhiEta*>(
m_geoSvc->getDetector()->readout(m_readoutName).segmentation().segmentation());
if (m_segmentation == nullptr) {
error() << "There is no phi-eta segmentation." << endmsg;
return StatusCode::FAILURE;
}
else
info() << "Found phi-eta segmentation." << endmsg;
m_segmentation = dynamic_cast<dd4hep::DDSegmentation::FCCSWGridPhiEta*>(m_geoSvc->getDetector()->readout(m_readoutName).segmentation().segmentation());
if (m_segmentation == nullptr) {
error() << "There is no phi-eta segmentation!!!!" << endmsg;
return StatusCode::FAILURE;
}

// open and check file, read the histograms with noise constants
Expand All @@ -60,10 +43,6 @@ StatusCode ReadNoiseFromFileTool::initialize() {

// Take readout bitfield decoder from GeoSvc
m_decoder = m_geoSvc->getDetector()->readout(m_readoutName).idSpec().decoder();
if (m_decoder == nullptr) {
error() << "Cannot create decore for readout " << m_readoutName << endmsg;
return StatusCode::FAILURE;
}

StatusCode sc = GaudiTool::initialize();
if (sc.isFailure()) return sc;
Expand Down Expand Up @@ -153,45 +132,27 @@ double ReadNoiseFromFileTool::getNoiseConstantPerCell(uint64_t aCellId) {
double elecNoise = 0.;
double pileupNoise = 0.;

// Get cell coordinates: eta/theta and radial layer
// Get cell coordinates: eta and radial layer
dd4hep::DDSegmentation::CellID cID = aCellId;
double cellEta, cellTheta;
if (m_useSeg)
cellEta = m_segmentation->eta(aCellId);
else
cellTheta = m_cellPositionsTool->xyzPosition(aCellId).Theta();
double cellEta = m_segmentation->eta(cID);

unsigned cellLayer = m_decoder->get(cID, m_activeFieldName);

// All histograms have same binning, all bins with same size
// Using the histogram in the first layer to get the bin size
unsigned index = 0;
if (m_histoElecNoiseConst.size() != 0) {
int Nbins = m_histoElecNoiseConst.at(index).GetNbinsX();
// GM: basically the same as FindBin ...
/*
double deltaEtaBin =
(m_histoElecNoiseConst.at(index).GetBinLowEdge(Nbins) + m_histoElecNoiseConst.at(index).GetBinWidth(Nbins) -
m_histoElecNoiseConst.at(index).GetBinLowEdge(1)) /
Nbins;
// find the eta bin for the cell
int ibin = floor(fabs(cellEta) / deltaEtaBin) + 1;
*/
int ibin;
if (m_useSeg) {
ibin = m_histoElecNoiseConst.at(index).FindBin(fabs(cellEta));
if (ibin > Nbins) {
error() << "eta outside range of the histograms! Cell eta: " << cellEta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}
}
else {
ibin = m_histoElecNoiseConst.at(index).FindBin(cellTheta);
if (ibin > Nbins) {
error() << "theta outside range of the histograms! Cell theta: " << cellTheta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}
if (ibin > Nbins) {
error() << "eta outside range of the histograms! Cell eta: " << cellEta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}
// Check that there are not more layers than the constants are provided for
if (cellLayer < m_histoElecNoiseConst.size()) {
Expand Down Expand Up @@ -228,45 +189,25 @@ double ReadNoiseFromFileTool::getNoiseOffsetPerCell(uint64_t aCellId) {

// Get cell coordinates: eta and radial layer
dd4hep::DDSegmentation::CellID cID = aCellId;
double cellEta, cellTheta;
if (m_useSeg)
cellEta = m_segmentation->eta(aCellId);
else
cellTheta = m_cellPositionsTool->xyzPosition(aCellId).Theta();
double cellEta = m_segmentation->eta(cID);
unsigned cellLayer = m_decoder->get(cID, m_activeFieldName);

// All histograms have same binning, all bins with same size
// Using the histogram in the first layer to get the bin size
unsigned index = 0;
if (m_histoElecNoiseOffset.size() != 0) {
int Nbins = m_histoElecNoiseOffset.at(index).GetNbinsX();
// find the eta bin for the cell
// GM: basically the same as FindBin ...
/*
double deltaEtaBin =
double deltaEtaBin =
(m_histoElecNoiseOffset.at(index).GetBinLowEdge(Nbins) + m_histoElecNoiseOffset.at(index).GetBinWidth(Nbins) -
m_histoElecNoiseOffset.at(index).GetBinLowEdge(1)) /
Nbins;
int ibin = floor(fabs(cellEta) / deltaEtaBin) + 1;
*/
int ibin;
if (m_useSeg) {
ibin = m_histoElecNoiseOffset.at(index).FindBin(fabs(cellEta));
if (ibin > Nbins) {
error() << "eta outside range of the histograms! Cell eta: " << cellEta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}
}
else {
ibin = m_histoElecNoiseOffset.at(index).FindBin(cellTheta);
if (ibin > Nbins) {
error() << "theta outside range of the histograms! Cell theta: " << cellTheta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}
// find the eta bin for the cell
int ibin = floor(fabs(cellEta) / deltaEtaBin) + 1;
if (ibin > Nbins) {
error() << "eta outside range of the histograms! Cell eta: " << cellEta << " Nbins in histogram: " << Nbins
<< endmsg;
ibin = Nbins;
}

// Check that there are not more layers than the constants are provided for
if (cellLayer < m_histoElecNoiseOffset.size()) {
elecNoise = m_histoElecNoiseOffset.at(cellLayer).GetBinContent(ibin);
Expand Down
19 changes: 10 additions & 9 deletions RecCalorimeter/src/components/ReadNoiseFromFileTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

// FCCSW
#include "k4FWCore/DataHandle.h"
#include "DetSegmentation/FCCSWGridPhiEta.h"
#include "k4Interface/ICalorimeterTool.h"
#include "k4Interface/INoiseConstTool.h"
#include "k4Interface/ICellPositionsTool.h"

#include "DetSegmentation/FCCSWGridPhiEta.h"

class IGeoSvc;

// Root
Expand All @@ -21,7 +20,7 @@ class TH1F;
/** @class ReadNoiseFromFileTool
*
* Tool to read the stored noise constant per cell in the calorimeters
* Access noise constants from TH1F histogram (noise vs. |eta| or theta)
* Access noise constants from TH1F histogram (noise vs. |eta|)
*
* @author Jana Faltova, Coralie Neubueser
* @date 2018-01
Expand All @@ -44,18 +43,15 @@ class ReadNoiseFromFileTool : public GaudiTool, virtual public INoiseConstTool {
double getNoiseOffsetPerCell(uint64_t aCellID);

private:
/// Handle for tool to get cell positions
ToolHandle<ICellPositionsTool> m_cellPositionsTool;
/// use segmentation (eta-phi only so far!) in case no cell position tool is defined
Gaudi::Property<bool> m_useSeg{this, "useSegmentation", true, "Specify if segmentation is used to determine cell position."};
/// Add pileup contribution to the electronics noise? (only if read from file)
Gaudi::Property<bool> m_addPileup{this, "addPileup", true,
"Add pileup contribution to the electronics noise? (only if read from file)"};
/// Noise offset, if false, mean is set to 0
Gaudi::Property<bool> m_setNoiseOffset{this, "setNoiseOffset", true, "Set a noise offset per cell"};

/// Name of the file with noise constants
Gaudi::Property<std::string> m_noiseFileName{this, "noiseFileName", "", "Name of the file with noise constants"};
/// Name of the detector readout (needed to get the decoder to extract e.g. layer information)
/// Name of the detector readout
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "ECalHitsPhiEta", "Name of the detector readout"};
/// Name of active layers for sampling calorimeter
Gaudi::Property<std::string> m_activeFieldName{this, "activeFieldName", "active_layer",
Expand All @@ -70,23 +66,28 @@ class ReadNoiseFromFileTool : public GaudiTool, virtual public INoiseConstTool {
"Name of electronics noise offset histogram"};
/// Name of pileup offset histogram
Gaudi::Property<std::string> m_pileupOffsetHistoName{this, "pileupOffsetHistoName", "h_pileup_layer", "Name of pileup offset histogram"};

/// Number of radial layers
Gaudi::Property<uint> m_numRadialLayers{this, "numRadialLayers", 3, "Number of radial layers"};

/// Factor to apply to the noise values to get them in GeV if e.g. they were produced in MeV
Gaudi::Property<float> m_scaleFactor{this, "scaleFactor", 1, "Factor to apply to the noise values"};

/// Histograms with pileup constants (index in array - radial layer)
std::vector<TH1F> m_histoPileupConst;
/// Histograms with electronics noise constants (index in array - radial layer)
std::vector<TH1F> m_histoElecNoiseConst;

/// Histograms with pileup offset (index in array - radial layer)
std::vector<TH1F> m_histoPileupOffset;
/// Histograms with electronics noise offset (index in array - radial layer)
std::vector<TH1F> m_histoElecNoiseOffset;

/// Pointer to the geometry service
SmartIF<IGeoSvc> m_geoSvc;
/// PhiEta segmentation
dd4hep::DDSegmentation::FCCSWGridPhiEta* m_segmentation;
// Decoder for ECal layers
// Decoder
dd4hep::DDSegmentation::BitFieldCoder* m_decoder;

};
Expand Down
3 changes: 1 addition & 2 deletions RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Segmentation;
}
}

/** @class CaloTopoClusterFCCeeAlgorithm Reconstruction/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.h
* CombinedCaloTopoCluster.h
/** @class CaloTopoClusterFCCee k4RecCalorimeter/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.h
*
* Algorithm building the topological clusters for the energy reconstruction, following ATLAS note
* ATL-LARG-PUB-2008-002.
Expand Down
Loading

0 comments on commit 68792c4

Please sign in to comment.