forked from HEP-FCC/k4RecCalorimeter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tools for the implmentation of noise for ALLEGRO v3 (HEP-FCC#107)
* Add tools for the implmentation of noise for ALLEGRO v3 * Steering file for addNoise * Conflict: remove ALLEGRO tests * Temporarily add the test for ALLEGRO addNoise (to be moved to ddsim+k4run) * Try to get the new test working --------- Co-authored-by: Zhibo Wu <zhibo@lxplus912.cern.ch> Co-authored-by: Zhibo Wu <zhibo@lxplus997.cern.ch>
- Loading branch information
1 parent
54c0674
commit af83315
Showing
5 changed files
with
762 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
RecCalorimeter/src/components/TubeLayerModuleThetaMergedCaloTool.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "TubeLayerModuleThetaMergedCaloTool.h" | ||
|
||
// segm | ||
#include "DD4hep/Detector.h" | ||
#include "DD4hep/MultiSegmentation.h" | ||
#include "detectorCommon/DetUtils_k4geo.h" | ||
#include "k4Interface/IGeoSvc.h" | ||
|
||
DECLARE_COMPONENT(TubeLayerModuleThetaMergedCaloTool) | ||
|
||
TubeLayerModuleThetaMergedCaloTool::TubeLayerModuleThetaMergedCaloTool(const std::string& type, const std::string& name, | ||
const IInterface* parent) | ||
: AlgTool(type, name, parent), m_geoSvc("GeoSvc", name) { | ||
declareInterface<ICalorimeterTool>(this); | ||
} | ||
|
||
StatusCode TubeLayerModuleThetaMergedCaloTool::initialize() { | ||
StatusCode sc = AlgTool::initialize(); | ||
if (sc.isFailure()) return sc; | ||
|
||
if (!m_geoSvc) { | ||
error() << "Unable to locate Geometry Service. " | ||
<< "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg; | ||
return StatusCode::FAILURE; | ||
} | ||
if (m_readoutName != "") { | ||
// Check if readouts exist | ||
info() << "Readout: " << m_readoutName << endmsg; | ||
if (m_geoSvc->getDetector()->readouts().find(m_readoutName) == m_geoSvc->getDetector()->readouts().end()) { | ||
error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; | ||
return StatusCode::FAILURE; | ||
} | ||
} | ||
return sc; | ||
} | ||
|
||
StatusCode TubeLayerModuleThetaMergedCaloTool::finalize() { return AlgTool::finalize(); } | ||
|
||
StatusCode TubeLayerModuleThetaMergedCaloTool::prepareEmptyCells(std::unordered_map<uint64_t, double>& aCells) { | ||
// Get the total number of active volumes in the geometry | ||
auto highestVol = gGeoManager->GetTopVolume(); | ||
unsigned int numLayers; | ||
if (!m_activeVolumesNumber) { | ||
numLayers = det::utils::countPlacedVolumes(highestVol, m_activeVolumeName); | ||
} else { | ||
// used when MergeLayers tool is used. To be removed once MergeLayer gets replaced by RedoSegmentation. | ||
numLayers = m_activeVolumesNumber; | ||
} | ||
info() << "Number of active layers " << numLayers << endmsg; | ||
|
||
// get segmentation | ||
dd4hep::DDSegmentation::Segmentation *aSegmentation = m_geoSvc->getDetector()->readout(m_readoutName).segmentation().segmentation(); | ||
std::string segmentationType = aSegmentation->type(); | ||
info() << "Segmentation type : " << segmentationType << endmsg; | ||
|
||
dd4hep::DDSegmentation::FCCSWGridModuleThetaMerged_k4geo *moduleThetaSegmentation = nullptr; | ||
if (segmentationType == "FCCSWGridModuleThetaMerged_k4geo") { | ||
moduleThetaSegmentation = dynamic_cast<dd4hep::DDSegmentation::FCCSWGridModuleThetaMerged_k4geo *>(aSegmentation); | ||
info() << "Segmentation: bins in Module " << moduleThetaSegmentation->nModules() << endmsg; | ||
} | ||
else { | ||
error() << "Unable to cast segmentation pointer!!!! Tool only applicable to FCCSWGridModuleThetaMerged_k4geo segmentation." << endmsg; | ||
return StatusCode::FAILURE; | ||
} | ||
|
||
// get decoder and extrema | ||
auto decoder = m_geoSvc->getDetector()->readout(m_readoutName).idSpec().decoder(); | ||
std::vector<std::pair<int, int>> extrema; | ||
extrema.push_back(std::make_pair(0, numLayers - 1)); | ||
extrema.push_back(std::make_pair(0, 0)); | ||
extrema.push_back(std::make_pair(0, 0)); | ||
|
||
for (unsigned int ilayer = 0; ilayer < numLayers; ilayer++) { | ||
dd4hep::DDSegmentation::CellID volumeId = 0; | ||
(*decoder)["system"].set(volumeId, 4); | ||
(*decoder)["layer"].set(volumeId, ilayer); | ||
(*decoder)["theta"].set(volumeId, 0); | ||
(*decoder)["module"].set(volumeId, 0); | ||
// Get number of segmentation cells within the active volume, for given layer | ||
auto numCells = det::utils::numberOfCells(volumeId, *moduleThetaSegmentation); | ||
// extrema[1]: Range of module ID (0, max module ID) | ||
extrema[1] = std::make_pair(0, (numCells[0] - 1) * moduleThetaSegmentation->mergedModules(ilayer)); | ||
// extrema[2]: Range of theta ID (min theta ID, max theta ID | ||
extrema[2] = std::make_pair(numCells[2], numCells[2] + (numCells[1] - 1) * moduleThetaSegmentation->mergedThetaCells(ilayer)); | ||
debug() << "Layer: " << ilayer << endmsg; | ||
debug() << "Number of segmentation cells in (module, theta): " << numCells << endmsg; | ||
// Loop over segmentation cells | ||
for (unsigned int imodule = 0; imodule < numCells[0]; imodule++) { | ||
for (unsigned int itheta = 0; itheta < numCells[1]; itheta++) { | ||
dd4hep::DDSegmentation::CellID cellId = volumeId; | ||
decoder->set(cellId, "module", imodule * moduleThetaSegmentation->mergedModules(ilayer)); | ||
decoder->set(cellId, "theta", numCells[2] + itheta * moduleThetaSegmentation->mergedThetaCells(ilayer)); // start from the minimum existing theta cell in this layer | ||
aCells.insert(std::pair<dd4hep::DDSegmentation::CellID, double>(cellId, 0)); | ||
} | ||
} | ||
} | ||
|
||
return StatusCode::SUCCESS; | ||
} |
59 changes: 59 additions & 0 deletions
59
RecCalorimeter/src/components/TubeLayerModuleThetaMergedCaloTool.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef RECCALORIMETER_TUBELAYERMODULETHETAMERGEDCALOTOOL_H | ||
#define RECCALORIMETER_TUBELAYERMODULETHETAMERGEDCALOTOOL_H | ||
|
||
// from Gaudi | ||
#include "GaudiKernel/AlgTool.h" | ||
|
||
// k4FWCore | ||
#include "k4Interface/ICalorimeterTool.h" | ||
|
||
class IGeoSvc; | ||
|
||
/** @class TubeLayerModuleThetaMergedCaloTool Reconstruction/RecCalorimeter/src/components/TubeLayerModuleThetaMergedCaloTool.h | ||
*TubeLayerModuleThetaMergedCaloTool.h | ||
* | ||
* Tool for geometry-dependent settings of the digitisation. | ||
* It assumes cylindrical geometry (layers) and phi-theta segmentation. | ||
* | ||
* @author Anna Zaborowska | ||
* @author Zhibo Wu | ||
*/ | ||
|
||
class TubeLayerModuleThetaMergedCaloTool : public AlgTool, virtual public ICalorimeterTool { | ||
public: | ||
TubeLayerModuleThetaMergedCaloTool(const std::string& type, const std::string& name, const IInterface* parent); | ||
virtual ~TubeLayerModuleThetaMergedCaloTool() = default; | ||
virtual StatusCode initialize() final; | ||
virtual StatusCode finalize() final; | ||
/** Prepare a map of all existing cells in current geometry. | ||
* Active layers (cylindrical tubes) are looked in the geometry manager by name ('\b activeVolumeName'). | ||
* Corresponding bitfield name is given in '\b activeFieldName'. | ||
* If users wants to limit the number of active layers, it is possible by setting '\b activeVolumesNumber'. | ||
* The total number of cells N = n_layer * n_theta * n_phi, where | ||
* n_layer is number of layers (taken from geometry if activeVolumesNumber not set), | ||
* n_theta is number of eta bins in that layer, | ||
* n_phi is number of phi bins (the same for each layer). | ||
* For more explanation please [see reconstruction documentation](@ref md_reconstruction_doc_reccalorimeter). | ||
* @param[out] aCells map of existing cells (and deposited energy, set to 0) | ||
* return Status code. | ||
*/ | ||
virtual StatusCode prepareEmptyCells(std::unordered_map<uint64_t, double>& aCells) final; | ||
|
||
private: | ||
/// Pointer to the geometry service | ||
ServiceHandle<IGeoSvc> m_geoSvc; | ||
/// Name of the detector readout | ||
Gaudi::Property<std::string> m_readoutName{this, "readoutName", ""}; | ||
/// Name of active volumes | ||
Gaudi::Property<std::string> m_activeVolumeName{this, "activeVolumeName", "LAr_sensitive"}; | ||
/// Name of active layers for sampling calorimeter | ||
Gaudi::Property<std::string> m_activeFieldName{this, "activeFieldName", "active_layer"}; | ||
/// Name of the fields describing the segmented volume | ||
Gaudi::Property<std::vector<std::string>> m_fieldNames{this, "fieldNames"}; | ||
/// Values of the fields describing the segmented volume | ||
Gaudi::Property<std::vector<int>> m_fieldValues{this, "fieldValues"}; | ||
/// Temporary: for use with MergeLayer tool | ||
Gaudi::Property<unsigned int> m_activeVolumesNumber{this, "activeVolumesNumber", 0}; | ||
}; | ||
|
||
#endif /* RECCALORIMETER_TUBELAYERMODULETHETAMERGEDCALOTOOL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.