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

fix noise filtering bug in calo digitisation, and restore defaults #113

Merged
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
15 changes: 14 additions & 1 deletion RecCalorimeter/src/components/CreateCaloCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ StatusCode CreateCaloCells::initialize() {
error() << "Unable to create empty cells!" << endmsg;
return StatusCode::FAILURE;
}
verbose() << "Initialised empty cell map with size " << m_cellsMap.size() << endmsg;
// noise filtering erases cells from the cell map after each event, so we need
// to backup the empty cell map for later reuse
if (m_addCellNoise && m_filterCellNoise) {
m_emptyCellsMap = m_cellsMap;
}
}
if (m_addPosition){
m_volman = m_geoSvc->getDetector()->volumeManager();
Expand All @@ -93,7 +99,14 @@ StatusCode CreateCaloCells::execute(const EventContext&) const {

// 0. Clear all cells
if (m_addCellNoise) {
std::for_each(m_cellsMap.begin(), m_cellsMap.end(), [](std::pair<const uint64_t, double>& p) { p.second = 0; });
// if cells are not filtered, the map has same size in each event, equal to the total number
// of cells in the calorimeter, so we can just reset the values to 0
// if cells are filtered, during each event they are removed from the cellsMap, so one has to
// restore the initial map of all empty cells
if (!m_filterCellNoise)
std::for_each(m_cellsMap.begin(), m_cellsMap.end(), [](std::pair<const uint64_t, double>& p) { p.second = 0; });
else
m_cellsMap = m_emptyCellsMap;
} else {
m_cellsMap.clear();
}
Expand Down
10 changes: 6 additions & 4 deletions RecCalorimeter/src/components/CreateCaloCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IGeoSvc;
/** @class CreateCaloCells
*
* Algorithm for creating calorimeter cells from Geant4 hits.
* Tube geometry with ModuleThetaMerged segmentation expected.
* Tube geometry with PhiEta segmentation expected.
*
* Flow of the program:
* 1/ Merge Geant4 energy deposits with same cellID
Expand Down Expand Up @@ -70,7 +70,7 @@ class CreateCaloCells : public Gaudi::Algorithm {
/// Handle for the calorimeter cells noise tool
mutable ToolHandle<INoiseCaloCellsTool> m_noiseTool{"NoiseCaloCellsFlatTool", this};
/// Handle for the geometry tool
ToolHandle<ICalorimeterTool> m_geoTool{"TubeLayerModuleThetaMergedCaloTool", this};
ToolHandle<ICalorimeterTool> m_geoTool{"TubeLayerPhiEtaCaloTool", this};

/// Add crosstalk to cells?
Gaudi::Property<bool> m_addCrosstalk{this, "addCrosstalk", false, "Add crosstalk effect?"};
Expand All @@ -92,7 +92,7 @@ class CreateCaloCells : public Gaudi::Algorithm {
mutable DataHandle<edm4hep::CalorimeterHitCollection> m_cells{"cells", Gaudi::DataHandle::Writer, this};
MetaDataHandle<std::string> m_cellsCellIDEncoding{m_cells, edm4hep::labels::CellIDEncoding, Gaudi::DataHandle::Writer};
/// Name of the detector readout
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "ECalBarrelModuleThetaMerged", "Name of the detector readout"};
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "ECalBarrelPhiEta", "Name of the detector readout"};
/// Name of active volumes
Gaudi::Property<std::string> m_activeVolumeName{this, "activeVolumeName", "_sensitive", "Name of the active volumes"};
/// Name of active layers for sampling calorimeter
Expand All @@ -116,7 +116,7 @@ class CreateCaloCells : public Gaudi::Algorithm {
* This property won't be needed anymore.
*/
unsigned int m_activeVolumesNumber;
/// Use only volume ID? If false, using ModuleThetaMergedSegmentation
/// Use only volume ID? If false, using PhiEtaSegmentation
bool m_useVolumeIdOnly;

/// Pointer to the geometry service
Expand All @@ -126,6 +126,8 @@ class CreateCaloCells : public Gaudi::Algorithm {
mutable std::unordered_map<uint64_t, double> m_cellsMap;
/// Maps of cell IDs (corresponding to DD4hep IDs) on transfer of signals due to crosstalk
mutable std::unordered_map<uint64_t, double> m_CrosstalkCellsMap;
/// Maps of cell IDs with zero energy, for all cells in calo (needed if addCellNoise and filterCellNoise are both set)
mutable std::unordered_map<uint64_t, double> m_emptyCellsMap;
};

#endif /* RECCALORIMETER_CREATECALOCELLS_H */
15 changes: 14 additions & 1 deletion RecCalorimeter/src/components/CreatePositionedCaloCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ StatusCode CreatePositionedCaloCells::initialize() {
error() << "Unable to create empty cells!" << endmsg;
return StatusCode::FAILURE;
}
verbose() << "Initialised empty cell map with size " << m_cellsMap.size() << endmsg;
// noise filtering erases cells from the cell map after each event, so we need
// to backup the empty cell map for later reuse
if (m_addCellNoise && m_filterCellNoise) {
m_emptyCellsMap = m_cellsMap;
}
}

// Copy over the CellIDEncoding string from the input collection to the output collection
Expand All @@ -88,7 +94,14 @@ StatusCode CreatePositionedCaloCells::execute(const EventContext&) const {

// 0. Clear all cells
if (m_addCellNoise) {
std::for_each(m_cellsMap.begin(), m_cellsMap.end(), [](std::pair<const uint64_t, double>& p) { p.second = 0; });
// if cells are not filtered, the map has same size in each event, equal to the total number
// of cells in the calorimeter, so we can just reset the values to 0
// if cells are filtered, during each event they are removed from the cellsMap, so one has to
// restore the initial map of all empty cells
if (!m_filterCellNoise)
std::for_each(m_cellsMap.begin(), m_cellsMap.end(), [](std::pair<const uint64_t, double>& p) { p.second = 0; });
else
m_cellsMap = m_emptyCellsMap;
} else {
m_cellsMap.clear();
}
Expand Down
3 changes: 2 additions & 1 deletion RecCalorimeter/src/components/CreatePositionedCaloCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class CreatePositionedCaloCells : public Gaudi::Algorithm {
mutable std::unordered_map<uint64_t, double> m_cellsMap;
/// Maps of cell IDs (corresponding to DD4hep IDs) on transfer of signals due to crosstalk
mutable std::unordered_map<uint64_t, double> m_crosstalkCellsMap;

/// Maps of cell IDs with zero energy, for all cells in calo (needed if addNoise and filterNoise are both set)
mutable std::unordered_map<uint64_t, double> m_emptyCellsMap;
/// Cache position vs cellID
mutable std::unordered_map<dd4hep::DDSegmentation::CellID, edm4hep::Vector3f> m_positions_cache{};
};
Expand Down
Loading