Skip to content

Commit

Permalink
[CreateCaloCells] Switch cross-talk to false by default (#92)
Browse files Browse the repository at this point in the history
* [CreateCaloCells] Switch cross-talk to false by default

* [CreateCaloCells] Avoid loading crosstalk tools when not needed

* [CreateCaloCells] Remove an unnecessary map for crosstalk

* [CreateCaloCells] tabs/indentation
  • Loading branch information
BrieucF committed Jul 9, 2024
1 parent 5f27a43 commit ac3feb5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
44 changes: 24 additions & 20 deletions RecCalorimeter/src/components/CreateCaloCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ StatusCode CreateCaloCells::initialize() {
info() << "add cell noise : " << m_addCellNoise << endmsg;
info() << "remove cells below threshold : " << m_filterCellNoise << endmsg;
info() << "add position information to the cell : " << m_addPosition << endmsg;
info() << "emulate crosstalk : " << m_addCrosstalk << endmsg;

// Initialization of tools
// Cell crosstalk tool
if (!m_crosstalksTool.retrieve()) {
error() << "Unable to retrieve the cell crosstalk tool!!!" << endmsg;
return StatusCode::FAILURE;
if (m_addCrosstalk) {
if (!m_crosstalksTool.retrieve()) {
error() << "Unable to retrieve the cell crosstalk tool!!!" << endmsg;
return StatusCode::FAILURE;
}
}
// Calibrate Geant4 energy to EM scale tool
if (m_doCellCalibration) {
Expand Down Expand Up @@ -95,59 +98,60 @@ StatusCode CreateCaloCells::execute() {
m_cellsMap.clear();
}

std::unordered_map<uint64_t, double> HitCellsMap;

// 1. Merge energy deposits into cells
// If running with noise map already was prepared. Otherwise it is being
// created below
for (const auto& hit : *hits) {
verbose() << "CellID : " << hit.getCellID() << endmsg;
if(m_addCrosstalk) { // Crosstalk only applies to energy deposits caused by EM shower hits. Therefore, cell noise needs to be excluded.
HitCellsMap[hit.getCellID()] += hit.getEnergy();
}
m_cellsMap[hit.getCellID()] += hit.getEnergy();
}
debug() << "Number of calorimeter cells after merging of hits: " << m_cellsMap.size() << endmsg;

// 2. Emulate cross-talk (if asked)
if(m_addCrosstalk) {
m_CrosstalkCellsMap.clear();
// loop over cells that get actual EM shower hits
for (const auto& this_cell : HitCellsMap) {
uint64_t this_cellId=this_cell.first;
// Derive the cross-talk contributions without affecting yet the nominal energy
// (one has to emulate crosstalk based on cells free from any cross-talk contributions)
m_CrosstalkCellsMap.clear(); // this is a temporary map to hold energy exchange due to cross-talk, without affecting yet the nominal energy
// loop over cells with nominal energies
for (const auto& this_cell : m_cellsMap) {
uint64_t this_cellId = this_cell.first;
auto vec_neighbours = m_crosstalksTool->getNeighbours(this_cellId); // a vector of neighbour IDs
auto vec_crosstalks = m_crosstalksTool->getCrosstalks(this_cellId); // a vector of crosstalk coefficients
// loop over crosstalk neighbrous of the cell under study
// loop over crosstalk neighbours of the cell under study
for (unsigned int i_cell=0; i_cell<vec_neighbours.size(); i_cell++) {
// signal transfer = energy deposit brought by EM shower hits * crosstalk coefficient
// signal transfer = energy deposit brought by EM shower hits * crosstalk coefficient
double signal_transfer = this_cell.second * vec_crosstalks[i_cell];
// for the cell under study, record the signal transfer that will be subtracted from its final cell energy
// for the cell under study, record the signal transfer that will be subtracted from its final cell energy
m_CrosstalkCellsMap[this_cellId] -= signal_transfer;
// for the crosstalk neighbour, record the signal transfer that will be added to its final cell energy
// for the crosstalk neighbour, record the signal transfer that will be added to its final cell energy
m_CrosstalkCellsMap[vec_neighbours[i_cell]] += signal_transfer;
}
}

// apply the cross-talk contributions on the nominal cell-energy map
for (const auto& this_cell : m_CrosstalkCellsMap) {
m_cellsMap[this_cell.first] += this_cell.second;
}

}
debug() << "Number of calorimeter cells after merging of hits: " << m_cellsMap.size() << endmsg;

// 2. Calibrate simulation energy to EM scale
// 3. Calibrate simulation energy to EM scale
if (m_doCellCalibration) {
m_calibTool->calibrate(m_cellsMap);
}

// 3. Add noise to all cells
// 4. Add noise to all cells
if (m_addCellNoise) {
m_noiseTool->addRandomCellNoise(m_cellsMap);
}

// 4. Filter cells
// 5. Filter cells
if (m_filterCellNoise) {
m_noiseTool->filterCellNoise(m_cellsMap);
}

// 5. Copy information to CaloHitCollection
// 6. Copy information to CaloHitCollection
edm4hep::CalorimeterHitCollection* edmCellsCollection = new edm4hep::CalorimeterHitCollection();
for (const auto& cell : m_cellsMap) {
if (m_addCellNoise || (!m_addCellNoise && cell.second != 0)) {
Expand Down
14 changes: 9 additions & 5 deletions RecCalorimeter/src/components/CreateCaloCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class IGeoSvc;
*
* Flow of the program:
* 1/ Merge Geant4 energy deposits with same cellID
* 2/ Calibrate to electromagnetic scale (if calibration switched on)
* 3/ Add random noise to each cell (if noise switched on)
* 4/ Filter cells and remove those with energy below threshold (if noise +
* 2/ Emulate cross-talk (if switched on)
* 3/ Calibrate to electromagnetic scale (if calibration switched on)
* 4/ Add random noise to each cell (if noise switched on)
* 5/ Filter cells and remove those with energy below threshold (if noise +
* filtering switched on)
*
* Tools called:
* - CalibrateCaloHitsTool
* - NoiseCaloCellsTool
* - CaloReadCrosstalkMap
* - CalorimeterTool (for geometry)
*
* @author Jana Faltova
* @author Anna Zaborowska
Expand Down Expand Up @@ -70,7 +73,7 @@ class CreateCaloCells : public GaudiAlgorithm {
ToolHandle<ICalorimeterTool> m_geoTool{"TubeLayerPhiEtaCaloTool", this};

/// Add crosstalk to cells?
Gaudi::Property<bool> m_addCrosstalk{this, "addCrosstalk", true, "Add crosstalk effect?"};
Gaudi::Property<bool> m_addCrosstalk{this, "addCrosstalk", false, "Add crosstalk effect?"};
/// Calibrate to EM scale?
Gaudi::Property<bool> m_doCellCalibration{this, "doCellCalibration", true, "Calibrate to EM scale?"};
/// Add noise to cells?
Expand Down Expand Up @@ -119,8 +122,9 @@ class CreateCaloCells : public GaudiAlgorithm {
/// Pointer to the geometry service
ServiceHandle<IGeoSvc> m_geoSvc;
dd4hep::VolumeManager m_volman;
/// Maps of cell IDs (corresponding to DD4hep IDs) on (1) final energies to be used for clustering, (2) transfer of signals due to crosstalk
/// Maps of cell IDs (corresponding to DD4hep IDs) on final energies to be used for clustering
std::unordered_map<uint64_t, double> m_cellsMap;
/// Maps of cell IDs (corresponding to DD4hep IDs) on transfer of signals due to crosstalk
std::unordered_map<uint64_t, double> m_CrosstalkCellsMap;
};

Expand Down

0 comments on commit ac3feb5

Please sign in to comment.