ATLAS Offline Software
Loading...
Searching...
No Matches
DefectsEmulatorCondAlgBase.h
Go to the documentation of this file.
1// -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef INDET_DEFECTSEMULATORCONDALGBASE_H
8#define INDET_DEFECTSEMULATORCONDALGBASE_H
9
11
14
15#include "GaudiKernel/ServiceHandle.h"
16
20#include "GaudiKernel/ITHistSvc.h"
21
22#include "TH2.h"
23
24#include <span>
25
26namespace CLHEP {
27 class HepRandomEngine;
28}
29namespace InDet {
35 {
36 public:
37 DefectsEmulatorCondAlgBase(const std::string& name, ISvcLocator* pSvcLocator);
38 virtual ~DefectsEmulatorCondAlgBase() override = default;
39
40 virtual StatusCode finalize() override;
41
42 protected:
43 StatusCode initializeBase(unsigned int n_masks, unsigned int wafer_hash_max);
44 StatusCode initializeProbabilities(unsigned int n_masks);
45 StatusCode initializeCornerDefects();
46
47 ServiceHandle<IAthRNGSvc> m_rndmSvc{this, "RndmSvc", "AthRNGSvc", ""};
48
49 Gaudi::Property<std::vector<std::vector<int> > > m_modulePattern
50 {this,"ModulePatterns", {},
51 "Integer ranges to select: (0-1) barrel/end-cap range, (2-3) layer, (4-5) eta index range, (6-7) phi index range, "
52 "(8-9) module number of columns or strips, (10) both sides (0,1), (11) all rows (0,1)" };
53 Gaudi::Property<std::vector<std::vector<double> > > m_defectProbability
54 {this,"DefectProbabilities", {},
55 "Defect probabilities per module pattern: defect module, defect strip." };
56 Gaudi::Property<std::vector<std::vector<double> > > m_nDefectFractionsPerPattern
57 {this,"NDefectFractionsPerPattern", {},
58 "List of fractions per pattern for exactly 1 to n defects under the codition that there is a defect, where -1. marks the"
59 "end of this lists, before the fractions for the next mask start." };
60 Gaudi::Property<std::vector<std::vector<double> > > m_cornerDefectParamsPerPattern
61 {this,"CornerDefectParamsPerPattern", {},
62 "Set of corner defect parameters (probability, x-intersection pos min, max, y-intersection pos min, max, sagitta minm max). "
63 "per module pattern. " };
64 Gaudi::Property<std::vector<std::vector<double> > > m_cornerDefectNCornerFractionsPerPattern
65 {this,"NCornerDefectFractionsPerPattern", {},
66 "List of fractions per pattern for exactly 1 to 4 corner defects under the codition that there is a defect." };
67
68 std::vector<std::vector<std::vector<float> > > m_perPatternAndMaskFractions;
69 std::vector<std::vector<float> > m_perPatternCornerDefectNCornerCummulativeProb;
70
71 Gaudi::Property<bool> m_rngPerDefectType
72 {this, "RngPerDefectType", false, "One RNG per defect type to decorrelate randomness of defects."};
73
74 // Properties to add a checker board like pattern to the defects
75 // for debugging
76 Gaudi::Property<bool> m_oddRowToggle
77 {this, "OddRowToggle", false};
78 Gaudi::Property<bool> m_oddColToggle
79 {this, "OddColToggle", false};
80 Gaudi::Property<bool> m_checkerBoardToggle
81 {this, "CheckerBoardDefects", false};
82 Gaudi::Property<unsigned int> m_maxAttempts
83 {this, "MaxRandomPositionAttempts", 10};
84
85 ServiceHandle<ITHistSvc> m_histSvc{this,"HistSvc","THistSvc"};
86 Gaudi::Property<std::string> m_histogramGroupName
87 {this,"HistogramGroupName","", "Histogram group name or empty to disable histogramming"};
88 Gaudi::Property<bool> m_fillHistogramsPerPattern
89 {this, "FillHistogramsPerPattern", false, "If true, histogram per module defects etc. separately per pattern."};
91 {this, "FillEtaPhiHistogramsPerPattern", false, "If true, histogram per eta, phi amd z, R are filled separately per pattern."};
92
93 Gaudi::Property<std::string> m_outputFile
94 {this,"DefectsOutputFile","", "Empty or file name to write out conditions data (.json or .root)."};
95 Gaudi::Property<std::vector<std::string> > m_inputFiles
96 {this,"DefectsInputFiles",{}, "Empty or file name to write out conditions data (.json or .root)."};
97
98 std::vector<std::string> m_rngName;
99
105
111
122
125 StatusCode checkProbabilities(unsigned int n_probabilities) const;
126
132 double totalProbability(const std::vector<unsigned int> &module_pattern_idx, unsigned int prob_idx) const {
133 double total_prob=0;
134 for (unsigned int pattern_i : module_pattern_idx) {
135 assert( prob_idx < m_defectProbability.value().at(pattern_i).size() );
136 total_prob += m_defectProbability.value()[pattern_i][prob_idx];
137 }
138 return total_prob;
139 }
140
147 void makeCumulativeProbabilityDist(std::vector<unsigned int> &module_pattern_idx,
148 unsigned int prob_idx,
149 std::vector<double> &cumulative_prob) const {
150 cumulative_prob.clear();
151 double total_prob=0.f;
152 for (unsigned int pattern_i : module_pattern_idx) {
153 assert( prob_idx < m_defectProbability.value().at(pattern_i).size() );
154 total_prob += m_defectProbability.value()[pattern_i][prob_idx];
155 cumulative_prob.push_back(total_prob);
156 }
157 }
158
168
169 // Get number of cell, and group defects and return total number of defects.
170 // @param rndmEngine random engine which will be used to throw the random number of defects one per mask.
171 // @param module_pattern_idx list of pattern indices which match the module.
172 // @param n_masks the number of defect categories e.g. individual pixel, core-column, chip defect.
173 // @param n_cels the number cells per module e.g. total number of pixel or strips.
174 // @param n_mask_defects output array of number of defects per category.
175 // @return total number of defects i.e. the sum of the number of defects per category.
176 // n_mask_defects will be resized to n_masks and filled with number of defects per category, where the first element
177 // will be the number of individual cell defects.
178 unsigned int throwNumberOfDefects(std::span<CLHEP::HepRandomEngine *> rndmEngine,
179 const std::vector<unsigned int> &module_pattern_idx,
180 unsigned int n_masks,
181 unsigned int n_cells,
182 std::vector<unsigned int> &n_mask_defects) const;
183
184 // Print a message summarizing the defect generation
185 // @param n_masks number of masks.
186 // @param n_error number of modules with wrong module design.
187 // @param n_defects total the total number of generated defects.
188 // @param counts more detailed count per mask which is e.g. pixels, core-columns, chips.
189 void printSummaryOfDefectGeneration(unsigned int n_masks,
190 unsigned int n_error,
191 unsigned int n_defects_total,
192 const std::vector<std::array<unsigned int,kNCounts> > &counts) const;
193
194 // Get histogram index and matrix type id for a certain matrix for a certain module pattern.
195 // calls during execute must be protected by m_histMutex and must not be called if histogramming is
196 // disabled.
197 // will return histogram index, and matrix type id
198 // usage:
199 // <verb>
200 // auto [histogram_index, type_id] = findHist(pattern_i, n_rows, n_cols);
201 // m_hist[pattern_i][histogram_index] or m_nGroupDefectHistspattern_i][histogram_index]
202 // </verb>
203 std::pair<unsigned int, unsigned int> findHist(unsigned int pattern_i, unsigned int n_rows, unsigned int n_cols) const;
204 void histogramDefectModule(unsigned int module_pattern_i, unsigned int hist_pattern_i, unsigned int id_hash, const Amg::Vector3D &center) const;
205 // fill per module histograms
206 // @param module_pattern_i the pattern index for which to histogram the position
207 // @param pattern_hist_i module pattern index or zero if there is only one set of histograms for all patterns
208 // @param matrix_histogram_index an index which is unique for each matrix type defined by the number of rows and columns
209 // @param module_i the ID hash
210 // @param n_masks the number of maskes defined int the module helper e.g. all pixels, core-columns, chips
211 // @param n_mask_defects the number of created defects per mask for the given module
212 // @param center global position of the module
213 // Will fill the number of defects per module and matrix type ID per hash ID histograms. Must not be called
214 // if histogramming is disabled.
215 void fillPerModuleHistograms(unsigned int module_pattern_i,
216 unsigned int pattern_hist_i,
217 unsigned int matrix_histogram_index,
218 unsigned int matrix_index,
219 unsigned int module_i,
220 unsigned int n_masks,
221 const std::vector<unsigned int> &n_mask_defects,
222 const Amg::Vector3D &center) const;
223
224
225 std::vector<std::string> m_groupDefectHistNames; // must be filled with one name per nask except for the first one
226 std::vector<unsigned int> m_maxNGroupDefects; // max number of group defects for histograms; one element per nask starting from the second maske
227 mutable std::mutex m_histMutex ;
228 // during execute the following may only be accessed when m_histMutex is locked
229 mutable std::vector<unsigned int> m_matrixTypeId ATLAS_THREAD_SAFE;
230 mutable std::vector<std::vector<unsigned int> > m_dimPerHist ATLAS_THREAD_SAFE;
231
232 mutable std::vector< std::vector< TH2 *> > m_hist ATLAS_THREAD_SAFE;
233 mutable std::vector< std::vector<std::vector< TH1 *> > > m_groupDefectHists ATLAS_THREAD_SAFE;
234 mutable std::vector< std::vector< TH2 *> > m_moduleHist ATLAS_THREAD_SAFE;
235
241 mutable std::array<std::vector<TH2 *>,kNPosHists> m_defectModuleEtaPhiHist ATLAS_THREAD_SAFE;
242 mutable std::array<std::vector<TH2 *>,kNPosHists> m_defectModuleEtaLayerHist ATLAS_THREAD_SAFE;
243
250
251 mutable std::atomic<unsigned int> m_modulesWithoutDefectParameters {};
252
254 };
255}
256#endif
Property holding a SG store/key/clid from which a WriteHandle is made.
An algorithm that can be simultaneously executed in multiple threads.
double totalProbability(const std::vector< unsigned int > &module_pattern_idx, unsigned int prob_idx) const
Compute the total probability using the probabilities associated to the given list of patterns.
std::atomic< unsigned int > m_modulesWithoutDefectParameters
std::pair< unsigned int, unsigned int > findHist(unsigned int pattern_i, unsigned int n_rows, unsigned int n_cols) const
std::vector< std::string > m_groupDefectHistNames
Gaudi::Property< std::vector< std::vector< double > > > m_cornerDefectNCornerFractionsPerPattern
Gaudi::Property< std::vector< std::vector< int > > > m_modulePattern
std::vector< std::vector< std::vector< float > > > m_perPatternAndMaskFractions
StatusCode checkProbabilities(unsigned int n_probabilities) const
Consistency check of module patterns, probabilities.
Gaudi::Property< std::string > m_outputFile
Gaudi::Property< std::string > m_histogramGroupName
StatusCode initializeProbabilities(unsigned int n_masks)
std::vector< unsigned int > m_maxNGroupDefects
Gaudi::Property< unsigned int > m_maxAttempts
void printSummaryOfDefectGeneration(unsigned int n_masks, unsigned int n_error, unsigned int n_defects_total, const std::vector< std::array< unsigned int, kNCounts > > &counts) const
DefectsEmulatorCondAlgBase(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< std::vector< double > > > m_cornerDefectParamsPerPattern
Gaudi::Property< bool > m_fillEtaPhiHistogramsPerPattern
std::vector< unsigned int > m_matrixTypeId ATLAS_THREAD_SAFE
std::vector< std::vector< float > > m_perPatternCornerDefectNCornerCummulativeProb
void histogramDefectModule(unsigned int module_pattern_i, unsigned int hist_pattern_i, unsigned int id_hash, const Amg::Vector3D &center) const
void makeCumulativeProbabilityDist(std::vector< unsigned int > &module_pattern_idx, unsigned int prob_idx, std::vector< double > &cumulative_prob) const
Create a cumulative distribution from the referenced set of probabilities.
Gaudi::Property< std::vector< std::vector< double > > > m_defectProbability
Gaudi::Property< std::vector< std::vector< double > > > m_nDefectFractionsPerPattern
virtual ~DefectsEmulatorCondAlgBase() override=default
unsigned int throwNumberOfDefects(std::span< CLHEP::HepRandomEngine * > rndmEngine, const std::vector< unsigned int > &module_pattern_idx, unsigned int n_masks, unsigned int n_cells, std::vector< unsigned int > &n_mask_defects) const
Gaudi::Property< std::vector< std::string > > m_inputFiles
void fillPerModuleHistograms(unsigned int module_pattern_i, unsigned int pattern_hist_i, unsigned int matrix_histogram_index, unsigned int matrix_index, unsigned int module_i, unsigned int n_masks, const std::vector< unsigned int > &n_mask_defects, const Amg::Vector3D &center) const
StatusCode initializeBase(unsigned int n_masks, unsigned int wafer_hash_max)
Eigen::Matrix< double, 3, 1 > Vector3D
Primary Vertex Finder.