8 #include "Identifier/Identifier.h"
18 #include "CLHEP/Random/RandPoisson.h"
19 #include "CLHEP/Random/RandFlat.h"
22 unsigned int makeCheckerboard(
unsigned int pixel_idx,
unsigned int n_rows,
unsigned int n_columns,
26 unsigned int row_i=pixel_idx / n_columns;
27 unsigned int col_i = pixel_idx % n_columns;
28 unsigned int row_odd = row_i < n_rows/2 || !odd_row_toggle ? 1 : 0;
29 unsigned int div_row = n_rows/7;
30 unsigned int div_cols = n_columns/7;
31 row_i =
std::min((((row_i / div_row ) & (0xffff-1)) + row_odd)*div_row + (row_i%div_row), n_rows-1);
32 unsigned int col_odd = col_i < n_columns/2 || !odd_col_toggle ? 1 : 0;
33 col_i =
std::min((((col_i / div_cols ) & (0xffff-1)) + col_odd)*div_cols + (col_i%div_cols),n_columns-1);
34 pixel_idx= row_i * n_columns + (col_i % n_columns);
41 : m_mutex( !disable ? &a_mutex : nullptr)
43 if (m_mutex) {m_mutex->lock(); }
46 if (m_mutex) {m_mutex->unlock(); }
54 using namespace InDet;
57 m_idHelper(nullptr) {}
71 constexpr
unsigned int n_different_pixel_matrices_max=6;
72 m_dimPerHist.reserve(n_different_pixel_matrices_max);
73 m_hist.reserve(n_different_pixel_matrices_max);
74 std::array<TH2 *,3>
hists {};
75 std::array<std::string,3> hist_name {
"defects_per_module",
76 "corecolumn_defects_per_module",
77 "matrix_type_id_per_module"};
78 std::array<std::string,3> hist_title{
"Defects per module",
79 "Core column defects per module",
80 "Matrix type id per module"};
81 for (
unsigned int hist_i=0; hist_i<
hists.size(); ++hist_i) {
83 hists.at(hist_i) =
new TH2F(hist_name.at(hist_i).c_str(), hist_title.at(hist_i).c_str(),
87 hists[hist_i]->GetXaxis()->SetTitle(
"ID hash % 100");
88 hists[hist_i]->GetYaxis()->SetTitle(
"ID hash / 100");
90 return StatusCode::FAILURE;
93 m_moduleDefectsHist =
hists[0];
94 m_moduleCoreColDefectsHist =
hists[1];
95 m_matrixHist =
hists[2];
98 return StatusCode::SUCCESS;
102 return StatusCode::SUCCESS;
108 return StatusCode::SUCCESS;
114 unsigned int n_pixel=0
u;
115 unsigned int n_error=0
u;
116 unsigned int max_n_defects=0
u;
117 unsigned int max_n_col_group_defects=0
u;
118 unsigned int n_col_group_defects_total=0
u;
119 std::unique_ptr<InDet::PixelEmulatedDefects>
defects = std::make_unique<InDet::PixelEmulatedDefects>();
120 defects->m_detectorElements=pixelDetEleColl.
cptr();
122 unsigned int n_defects_total=0;
126 CLHEP::HepRandomEngine *rndmEngine = rngWrapper->
getEngine(ctx);
127 unsigned int module_i=0;
138 unsigned int pixels =
helper.nPixels();
146 unsigned int n_col_group_defects=
static_cast<unsigned int>(
std::max(0,
static_cast<int>(CLHEP::RandPoisson::shoot(rndmEngine,
helper.nColumns()
148 n_col_group_defects_total += n_col_group_defects;
149 max_n_col_group_defects =
std::max(max_n_col_group_defects, n_col_group_defects);
151 unsigned int n_defects=
static_cast<unsigned int>(
std::max(0,
static_cast<int>(CLHEP::RandPoisson::shoot(rndmEngine,pixels *
m_pixelDefectProbability.value()))));
152 max_n_defects =
std::max(max_n_defects,n_defects);
154 std::vector<unsigned int> &module_defects=(*defects).at(module_i);
155 module_defects.reserve(n_defects + n_col_group_defects);
156 for (
unsigned int defect_i=0; defect_i < n_col_group_defects; ++defect_i) {
157 unsigned int pixel_idx=CLHEP::RandFlat::shoot(rndmEngine,pixels);
164 unsigned int key =
helper.columnGroupDefect(pixel_idx /
helper.nColumns(), pixel_idx %
helper.nColumns());
166 if (insert_iter == end_iter) {
167 module_defects.push_back(
key);
169 std::array<unsigned int,4> ranges_row_col =
helper.offlineRange(
key);
170 for (
unsigned int row_i=ranges_row_col[0]; row_i<ranges_row_col[1]; ++row_i) {
171 for (
unsigned int col_i=ranges_row_col[2]; col_i<ranges_row_col[3]; ++col_i) {
172 h2->Fill(col_i, row_i);
179 if (!
helper.isSameDefectWithGroups(*insert_iter,
key)) {
180 module_defects.insert( insert_iter,
key);
182 std::array<unsigned int,4> ranges_row_col =
helper.offlineRange(
key);
183 for (
unsigned int row_i=ranges_row_col[0]; row_i<ranges_row_col[1]; ++row_i) {
184 for (
unsigned int col_i=ranges_row_col[2]; col_i<ranges_row_col[3]; ++col_i) {
185 h2->Fill(col_i, row_i);
192 unsigned int n_col_group_defects_registered=module_defects.size();
194 for (
unsigned int defect_i=0; defect_i < n_defects; ++defect_i) {
195 unsigned int pixel_idx=CLHEP::RandFlat::shoot(rndmEngine,pixels);
202 unsigned int key =
helper.hardwareCoordinates(pixel_idx /
helper.nColumns(), pixel_idx %
helper.nColumns());
206 if (insert_iter == end_iter) {
207 module_defects.push_back(
key);
209 std::array<unsigned int,4> ranges_row_col =
helper.offlineRange(
key);
210 for (
unsigned int row_i=ranges_row_col[0]; row_i<ranges_row_col[1]; ++row_i) {
211 for (
unsigned int col_i=ranges_row_col[2]; col_i<ranges_row_col[3]; ++col_i) {
212 h2->Fill(col_i, row_i);
217 else if (
helper.isSameDefectWithGroups(*insert_iter,
key)) {
221 module_defects.insert( insert_iter,
key);
223 std::array<unsigned int,4> ranges_row_col =
helper.offlineRange(
key);
224 for (
unsigned int row_i=ranges_row_col[0]; row_i<ranges_row_col[1]; ++row_i) {
225 for (
unsigned int col_i=ranges_row_col[2]; col_i<ranges_row_col[3]; ++col_i) {
226 h2->Fill(col_i, row_i);
235 unsigned int ids_per_col =
static_cast<unsigned int>(m_moduleDefectsHist->GetNbinsX());
236 unsigned int bin_i=m_moduleDefectsHist->GetBin( module_i%ids_per_col+1, module_i/ids_per_col+1);
237 m_moduleDefectsHist->SetBinContent(bin_i, module_defects.size()-n_col_group_defects_registered );
238 m_moduleCoreColDefectsHist->SetBinContent(bin_i, n_col_group_defects_registered );
240 for (
unsigned int hist_i=0; hist_i < m_hist.size(); ++hist_i) {
241 if (m_hist[hist_i]==h2) {
242 m_matrixHist->SetBinContent(bin_i, hist_i+1);
247 n_defects_total+=module_defects.size();
254 ATH_MSG_INFO(
"Total pixel " << n_pixel <<
" non-pixel modules " << n_error <<
" defects " << n_defects_total <<
" max /mod " << max_n_defects
255 <<
" core column defects " << n_col_group_defects_total <<
" max. / mod " << max_n_col_group_defects);
257 return StatusCode::SUCCESS;
261 unsigned int key=(n_rows << 16) | n_cols;
262 std::vector<unsigned int>::const_iterator iter =
std::find(m_dimPerHist.begin(),m_dimPerHist.end(),
key );
263 if (iter == m_dimPerHist.end()) {
264 if (m_dimPerHist.size() == m_dimPerHist.capacity()) {
265 if (m_dimPerHist.capacity()==0) {
268 return m_hist.back();
271 std::stringstream
name;
272 name <<
"defects_" << (m_hist.size()+1) <<
"_" << n_rows <<
"_" << n_cols;
273 std::stringstream
title;
274 title <<
"Defects for " << n_rows <<
"(rows) #times " << n_cols <<
" (columns) ID " << (m_hist.size()+1);
275 m_hist.push_back(
new TH2F(
name.str().c_str(),
title.str().c_str(),
276 n_cols, -0.5, n_cols-0.5,
277 n_rows, -0.5, n_rows-0.5
279 m_hist.back()->GetXaxis()->SetTitle(
"offline column");
280 m_hist.back()->GetYaxis()->SetTitle(
"offline row");
282 throw std::runtime_error(
"Failed to register histogram.");
284 m_dimPerHist.push_back(
key);
285 return m_hist.back();
289 return m_hist.at(iter-m_dimPerHist.begin());