ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CaloCellsCounterCPU Class Reference

Outputs counts of cells, both by type and cluster presence, with each cluster being identified by its cell with the largest signal-to-noise ratio. More...

#include <CaloCellsCounterCPU.h>

Inheritance diagram for CaloCellsCounterCPU:
Collaboration diagram for CaloCellsCounterCPU:

Public Member Functions

 CaloCellsCounterCPU (const std::string &type, const std::string &name, const IInterface *parent)
 
virtual StatusCode initialize () override
 
virtual StatusCode execute (const EventContext &ctx, xAOD::CaloClusterContainer *cluster_collection) const override
 
virtual ~CaloCellsCounterCPU ()=default
 
virtual StatusCode execute (const EventContext &ctx, xAOD::CaloClusterContainer *collection) const=0
 Execute on an entire collection of clusters. More...
 
virtual StatusCode execute (xAOD::CaloClusterContainer *collection) final
 Execute on an entire collection of clusters. More...
 

Private Attributes

Gaudi::Property< std::string > m_savePath {this, "SavePath", "./cell_counts", "Path to where the files should be saved"}
 The path specifying the folder to which the files should be saved. More...
 
Gaudi::Property< std::string > m_filePrefix {this, "FilePrefix", "", "Prefix of the saved files"}
 The prefix of the saved files. More...
 
Gaudi::Property< std::string > m_fileSuffix {this, "FileSuffix", "", "Suffix of the saved files"}
 The suffix of the saved files. More...
 
Gaudi::Property< unsigned int > m_numWidth {this, "NumberWidth", 9, "The number of digits to reserve for the events"}
 The number of digits to reserve for the events. More...
 
SG::ReadHandleKey< CaloCellContainerm_cellsKey {this, "CellsName", "", "Name(s) of Cell Containers"}
 vector of names of the cell containers to use as input. More...
 
SG::ReadCondHandleKey< CaloNoisem_noiseCDOKey {this, "CaloNoiseKey", "totalNoise", "SG Key of CaloNoise data object"}
 Key of the CaloNoise Conditions data object. More...
 
Gaudi::Property< float > m_seedThreshold {this, "SeedThresholdOnEorAbsEinSigma", 4., "Seed threshold (in units of noise Sigma)"}
 Value to consider for the seed threshold. More...
 
Gaudi::Property< float > m_growThreshold {this, "NeighborThresholdOnEorAbsEinSigma", 2., "Neighbor (grow) threshold (in units of noise Sigma)"}
 Value to consider for the seed threshold. More...
 
Gaudi::Property< float > m_cellThreshold {this, "CellThresholdOnEorAbsEinSigma", 0., "Cell (terminal) threshold (in units of noise Sigma)"}
 Value to consider for the seed threshold. More...
 
const CaloCell_IDm_calo_id {nullptr}
 Pointer to Calo ID Helper. More...
 

Detailed Description

Outputs counts of cells, both by type and cluster presence, with each cluster being identified by its cell with the largest signal-to-noise ratio.

Author
Nuno Fernandes nuno..nosp@m.dos..nosp@m.santo.nosp@m.s.fe.nosp@m.rnand.nosp@m.es@c.nosp@m.ern.c.nosp@m.h
Date
20 July 2022

Definition at line 27 of file CaloCellsCounterCPU.h.

Constructor & Destructor Documentation

◆ CaloCellsCounterCPU()

CaloCellsCounterCPU::CaloCellsCounterCPU ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 18 of file CaloCellsCounterCPU.cxx.

18  :
19  base_class(type, name, parent)
20 {
21 }

◆ ~CaloCellsCounterCPU()

virtual CaloCellsCounterCPU::~CaloCellsCounterCPU ( )
virtualdefault

Member Function Documentation

◆ execute() [1/3]

StatusCode CaloCellsCounterCPU::execute ( const EventContext &  ctx,
xAOD::CaloClusterContainer cluster_collection 
) const
overridevirtual

Definition at line 61 of file CaloCellsCounterCPU.cxx.

62 {
63 
64  SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
65  if ( !cell_collection.isValid() )
66  {
67  ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
68  return StatusCode::FAILURE;
69  }
70 
71 
73  const CaloNoise * noise_tool = *noise_handle;
74 
75  unsigned int gain_counts[GainConversion::num_gain_values()] = {0};
76 
77  size_struct global_counts, global_cluster_counts;
78 
79  for (CaloCellContainer::const_iterator iCells = cell_collection->begin(); iCells != cell_collection->end(); ++iCells)
80  {
81  const CaloCell * cell = (*iCells);
82 
83  const float energy = cell->energy();
84 
85  float SNR = energy / noise_tool->getNoise(m_calo_id->calo_cell_hash(cell->ID()), cell->gain());
86 
87  const unsigned int gain = GainConversion::from_standard_gain(cell->gain());
88 
89  ++gain_counts[gain - GainConversion::min_gain_value()];
90 
91  SNR = std::abs(SNR);
92 
93  if (SNR > m_seedThreshold)
94  {
95  ++global_counts.seed;
96  }
97  else if (SNR > m_growThreshold)
98  {
99  ++global_counts.grow;
100  }
101  else if (SNR > m_cellThreshold)
102  {
103  ++global_counts.term;
104  }
105  else
106  {
107  ++global_counts.invalid;
108  }
109  }
110 
111  struct cluster_cell_info
112  {
113  const xAOD::CaloCluster * cl_1 = nullptr, * cl_2 = nullptr;
114  double w_1 = -1, w_2 = -1, energy = -9e99, SNR = -9e99;
115  void add_cluster(const int cell_id, const xAOD::CaloCluster * cl, const double w)
116  {
117  if (cl_1 == nullptr)
118  {
119  cl_1 = cl;
120  w_1 = w;
121  }
122  else if (cl_2 == nullptr)
123  {
124  cl_2 = cl;
125  w_2 = w;
126  }
127  else
128  {
129  std::cout << "WARNING! Multiple shared cell: " << cell_id << " " << cl_1 << " " << cl_2 << " " << cl << std::endl;
130  }
131  }
132 
133  bool is_shared() const
134  {
135  return cl_1 != nullptr && cl_2 != nullptr;
136  }
137 
138  };
139 
140  std::map<int, cluster_cell_info> cluster_cells;
141 
142 
143  for (const xAOD::CaloCluster * cluster : *cluster_collection)
144  {
145  //const xAOD::CaloCluster * cluster = (*cluster_iter);
146  const CaloClusterCellLink * cell_links = cluster->getCellLinks();
147  if (!cell_links)
148  {
149  ATH_MSG_ERROR("Can't get valid links to CaloCells (CaloClusterCellLink)!");
150  return StatusCode::FAILURE;
151  }
152 
153  for (auto it = cell_links->begin(); it != cell_links->end(); ++it)
154  {
155  const CaloCell * cell = *it;
156  const float weight = it.weight();
157 
158  const float this_energy = std::abs(cell->energy());
159 
160  const float this_snr = std::abs(this_energy / noise_tool->getNoise(m_calo_id->calo_cell_hash(cell->ID()), cell->gain()));
161 
162  const IdentifierHash this_hash = m_calo_id->calo_cell_hash(cell->ID());
163 
164  auto & info = cluster_cells[this_hash];
165 
166  info.energy = this_energy;
167  info.SNR = this_snr;
168 
169  info.add_cluster(this_hash, cluster, weight);
170 
171  }
172  }
173 
174  std::unordered_map<const xAOD::CaloCluster *, cluster_info_struct> cluster_sizes;
175 
176  auto update_clusters = [&](const cluster_cell_info & cci, const int cell)
177  {
178  auto update_one = [&](const xAOD::CaloCluster * cl)
179  {
180  if (cl)
181  {
182  auto & c_info = cluster_sizes[cl];
183  ++c_info.size.total;
184  if (cci.SNR > m_seedThreshold)
185  {
186  ++c_info.size.seed;
187  }
188  else if (cci.SNR > m_growThreshold)
189  {
190  ++c_info.size.grow;
191  }
192  else if (cci.SNR > m_cellThreshold)
193  {
194  ++c_info.size.term;
195  }
196  else
197  {
198  ++c_info.size.invalid;
199  }
200 
201  if (cci.is_shared())
202  {
203  ++c_info.size.shared;
204  }
205  else
206  {
207  if (cci.SNR > c_info.seed_snr || (cci.SNR == c_info.seed_snr && cell > c_info.seed_index))
208  {
209  c_info.seed_index = cell;
210  c_info.seed_snr = cci.SNR;
211  c_info.seed_energy = cci.energy;
212  }
213  }
214  }
215  };
216 
217  if (cci.cl_1 != nullptr || cci.cl_2 != nullptr)
218  {
219  ++global_cluster_counts.total;
220  if (cci.SNR > m_seedThreshold)
221  {
222  ++global_cluster_counts.seed;
223  }
224  else if (cci.SNR > m_growThreshold)
225  {
226  ++global_cluster_counts.grow;
227  }
228  else if (cci.SNR > m_cellThreshold)
229  {
230  ++global_cluster_counts.term;
231  }
232  else
233  {
234  ++global_cluster_counts.invalid;
235  }
236  if (cci.is_shared())
237  {
238  ++global_cluster_counts.shared;
239  }
240  }
241 
242  update_one(cci.cl_1);
243  update_one(cci.cl_2);
244  };
245 
246  for (auto & it : cluster_cells)
247  {
248  update_clusters(it.second, it.first);
249  }
250 
251  std::vector<cluster_info_struct> sorted_info;
252 
253  sorted_info.reserve(cluster_sizes.size());
254 
255  for (auto & v : cluster_sizes)
256  {
257  sorted_info.push_back(v.second);
258  }
259 
260  std::sort(sorted_info.begin(), sorted_info.end(),
261  [](const auto & a, const auto & b)
262  {
263  return a.seed_index < b.seed_index;
264  });
265 
266 
267  const auto err1 = StandaloneDataIO::prepare_folder_for_output(std::string(m_savePath));
269  {
270  return StatusCode::FAILURE;
271  }
272 
273  const std::filesystem::path save_file = m_savePath + "/" + StandaloneDataIO::build_filename((m_filePrefix.size() > 0 ? m_filePrefix + "_counts" : "counts"),
274  ctx.evt(), m_fileSuffix, "txt", m_numWidth);
275 
276  std::ofstream out_file(save_file);
277 
278  if (!out_file.is_open())
279  {
280  return StatusCode::FAILURE;
281  }
282 
283  out_file << "Cell counts: " << global_counts << "\n\n";
284 
285  out_file << "Cells in clusters count: " << global_cluster_counts << "\n\n";
286  out_file << "Clusters:\n\n";
287 
288  for (const auto & info : sorted_info)
289  {
290  out_file << info << "\n";
291  }
292 
293  out_file << std::endl;
294 
295  if (!out_file.good())
296  {
297  return StatusCode::FAILURE;
298  }
299 
300  out_file.close();
301 
302  return StatusCode::SUCCESS;
303 
304 }

◆ execute() [2/3]

virtual StatusCode CaloClusterCollectionProcessor::execute

Execute on an entire collection of clusters.

Parameters
collectionThe container of clusters. param ctx The event context.

◆ execute() [3/3]

virtual StatusCode CaloClusterCollectionProcessor::execute
inlinefinal

Execute on an entire collection of clusters.

Parameters
collectionThe container of clusters. (deprecated)

Definition at line 50 of file CaloClusterCollectionProcessor.h.

51  {
52  return execute (Gaudi::Hive::currentContext(), collection);
53  }

◆ initialize()

StatusCode CaloCellsCounterCPU::initialize ( )
overridevirtual

Definition at line 24 of file CaloCellsCounterCPU.cxx.

25 {
28  ATH_CHECK( detStore()->retrieve(m_calo_id, "CaloCell_ID") );
29  return StatusCode::SUCCESS;
30 }

Member Data Documentation

◆ m_calo_id

const CaloCell_ID* CaloCellsCounterCPU::m_calo_id {nullptr}
private

Pointer to Calo ID Helper.

Definition at line 96 of file CaloCellsCounterCPU.h.

◆ m_cellsKey

SG::ReadHandleKey<CaloCellContainer> CaloCellsCounterCPU::m_cellsKey {this, "CellsName", "", "Name(s) of Cell Containers"}
private

vector of names of the cell containers to use as input.

Definition at line 69 of file CaloCellsCounterCPU.h.

◆ m_cellThreshold

Gaudi::Property<float> CaloCellsCounterCPU::m_cellThreshold {this, "CellThresholdOnEorAbsEinSigma", 0., "Cell (terminal) threshold (in units of noise Sigma)"}
private

Value to consider for the seed threshold.

Should be consistent with the one used in Topological Clustering to ensure cell classification is correct.

Definition at line 89 of file CaloCellsCounterCPU.h.

◆ m_filePrefix

Gaudi::Property<std::string> CaloCellsCounterCPU::m_filePrefix {this, "FilePrefix", "", "Prefix of the saved files"}
private

The prefix of the saved files.

Empty string by default.

Definition at line 54 of file CaloCellsCounterCPU.h.

◆ m_fileSuffix

Gaudi::Property<std::string> CaloCellsCounterCPU::m_fileSuffix {this, "FileSuffix", "", "Suffix of the saved files"}
private

The suffix of the saved files.

Empty string by default.

Definition at line 59 of file CaloCellsCounterCPU.h.

◆ m_growThreshold

Gaudi::Property<float> CaloCellsCounterCPU::m_growThreshold {this, "NeighborThresholdOnEorAbsEinSigma", 2., "Neighbor (grow) threshold (in units of noise Sigma)"}
private

Value to consider for the seed threshold.

Should be consistent with the one used in Topological Clustering to ensure cell classification is correct.

Definition at line 84 of file CaloCellsCounterCPU.h.

◆ m_noiseCDOKey

SG::ReadCondHandleKey<CaloNoise> CaloCellsCounterCPU::m_noiseCDOKey {this, "CaloNoiseKey", "totalNoise", "SG Key of CaloNoise data object"}
private

Key of the CaloNoise Conditions data object.

Typical values are '"electronicNoise', 'pileupNoise', or '"totalNoise' (default)

Definition at line 74 of file CaloCellsCounterCPU.h.

◆ m_numWidth

Gaudi::Property<unsigned int> CaloCellsCounterCPU::m_numWidth {this, "NumberWidth", 9, "The number of digits to reserve for the events"}
private

The number of digits to reserve for the events.

9 by default.

Definition at line 64 of file CaloCellsCounterCPU.h.

◆ m_savePath

Gaudi::Property<std::string> CaloCellsCounterCPU::m_savePath {this, "SavePath", "./cell_counts", "Path to where the files should be saved"}
private

The path specifying the folder to which the files should be saved.

Default ./cell_counts

Definition at line 49 of file CaloCellsCounterCPU.h.

◆ m_seedThreshold

Gaudi::Property<float> CaloCellsCounterCPU::m_seedThreshold {this, "SeedThresholdOnEorAbsEinSigma", 4., "Seed threshold (in units of noise Sigma)"}
private

Value to consider for the seed threshold.

Should be consistent with the one used in Topological Clustering to ensure cell classification is correct.

Definition at line 79 of file CaloCellsCounterCPU.h.


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
StandaloneDataIO::build_filename
static std::string build_filename(const std::string &prefix, const std::string &text, const std::string &suffix, const std::string &ext)
Definition: StandaloneDataIO.h:273
CaloCellsCounterCPU::m_fileSuffix
Gaudi::Property< std::string > m_fileSuffix
The suffix of the saved files.
Definition: CaloCellsCounterCPU.h:59
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
skel.it
it
Definition: skel.GENtoEVGEN.py:407
CaloCellsCounterCPU::m_cellThreshold
Gaudi::Property< float > m_cellThreshold
Value to consider for the seed threshold.
Definition: CaloCellsCounterCPU.h:89
CaloCellsCounterCPU::m_cellsKey
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
Definition: CaloCellsCounterCPU.h:69
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:190
CaloCellsCounterCPU::m_seedThreshold
Gaudi::Property< float > m_seedThreshold
Value to consider for the seed threshold.
Definition: CaloCellsCounterCPU.h:79
StandaloneDataIO::ErrorState::OK
@ OK
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MuonEfficiencyCorrectionsCfg.out_file
out_file
Definition: MuonEfficiencyCorrectionsCfg.py:69
CaloNoise
Definition: CaloNoise.h:16
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
StandaloneDataIO::prepare_folder_for_output
static ErrorState prepare_folder_for_output(const std::filesystem::path &folder, const bool output_errors=true)
Definition: StandaloneDataIO.h:264
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
CaloCellsCounterCPU::m_savePath
Gaudi::Property< std::string > m_savePath
The path specifying the folder to which the files should be saved.
Definition: CaloCellsCounterCPU.h:49
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellsCounterCPU::m_calo_id
const CaloCell_ID * m_calo_id
Pointer to Calo ID Helper.
Definition: CaloCellsCounterCPU.h:96
python.PyAthena.v
v
Definition: PyAthena.py:154
a
TList * a
Definition: liststreamerinfos.cxx:10
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
CaloCellsCounterCPU::m_numWidth
Gaudi::Property< unsigned int > m_numWidth
The number of digits to reserve for the events.
Definition: CaloCellsCounterCPU.h:64
CaloCellsCounterCPU::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Key of the CaloNoise Conditions data object.
Definition: CaloCellsCounterCPU.h:74
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:198
CaloCellsCounterCPU::execute
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *cluster_collection) const override
Definition: CaloCellsCounterCPU.cxx:61
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:25
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
CaloCellsCounterCPU::m_filePrefix
Gaudi::Property< std::string > m_filePrefix
The prefix of the saved files.
Definition: CaloCellsCounterCPU.h:54
CaloCellsCounterCPU::m_growThreshold
Gaudi::Property< float > m_growThreshold
Value to consider for the seed threshold.
Definition: CaloCellsCounterCPU.h:84