2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
4# This scripts selects the required set of modules from the geometry.json (contains all the modules from the Strip/Pixel Detectors) obtained using geometry_dat_to_json.py script.
5# Each functions contains a small description of its purpose.
127 - PixelGeometry_1pct_corr.json : Contains 1% of modules from PixelGeometry.json file.
128 - PixelGeometry_5pct_corr.json : Contains 5% of modules from PixelGeometry.json file (Some module can be in the first file but not the second one and vis versa.)
129 '''
130
131if output_dir isNone:
132raise ValueError("No output_dir was provided.")
146 Generate correlated files using a random selection for each fractions, but modules that have been selected are kept in the next files and removed from the input_data file.
152 - PixelGeometry_1pct_corr.json : Contains 1% of modules from PixelGeometry.json file
153 - PixelGeometry_5pct_corr.json : Contains all selected modules in the 1% file + additional Pixel modules to get to a total of 5% module w.r.t to the input file, PixelGeometry.json
154 - PixelGeometry_not_selected.json : Contains all modules that have not been randomly selected.
155
156 '''
157
158if output_dir isNone:
159raise ValueError("No output_dir was provided.")
215 Function used in the generate_corr() function to compute the new fraction of module to select.
216
217 Since the input_data file in select_random() contains less and less modules as one selects them, the fraction of module to be selected has to be recompute to match the desired one.
218
219 Exemple :
220 In file A, there are 100 modules. One wants to create two correlated files :
221 - file B : 10% of modules ( size = 10 modules )
222 - file C : 50% of modules ( size = 50 modules = 10 modules from file A + 40 new modules )
223
224 For file C, one can not use 0.5 as a fraction because it would select 45 modules and file C would contains 55 modules instead of 50, as desired:
225
226 # of selected modules = len(file A - file B) * frac = (100 - 10) * 0.5 = 45
227 So, 45 + 10 = 55 !
228
229 The new fraction should be:
230
231 new_frac = [ (number of wanted modules in final file) - (number of already selected modules) ] / (number of not yet selected modules)
232 = [ (len(file A) * frac) - len(file B) ] / (len(file A - file B))
233 = [ 50 - 10 ] / 90
234 = 4/9 ~ 0.4445
235
236 So the file C contains :
237
238 # of selected modules = len(file A - file B) * new_frac = (100 - 10) * 4/9 = 40
274 Generate 4 uncorrelated files with randomly selected modules according to 1, 5, 10 and 15% of the pixel modules in the input_data file (e.g PixelGeometry.json).