File indexing completed on 2023-01-23 02:42:43
0001 #ifndef RecoTracker_MkFitCore_interface_IterationConfig_h
0002 #define RecoTracker_MkFitCore_interface_IterationConfig_h
0003
0004 #include "RecoTracker/MkFitCore/interface/FunctionTypes.h"
0005 #include "RecoTracker/MkFitCore/interface/SteeringParams.h"
0006
0007 #include "nlohmann/json_fwd.hpp"
0008
0009 #include <functional>
0010
0011 namespace mkfit {
0012
0013
0014
0015
0016
0017 struct IterationMaskIfcBase {
0018 virtual ~IterationMaskIfcBase() {}
0019
0020 virtual const std::vector<bool> *get_mask_for_layer(int layer) const { return nullptr; }
0021 };
0022
0023 struct IterationMaskIfc : public IterationMaskIfcBase {
0024 std::vector<std::vector<bool>> m_mask_vector;
0025
0026 const std::vector<bool> *get_mask_for_layer(int layer) const override { return &m_mask_vector[layer]; }
0027 };
0028
0029
0030
0031
0032
0033 class IterationConfig;
0034
0035 class IterationLayerConfig {
0036 public:
0037 int m_layer = -1;
0038
0039 float m_select_min_dphi;
0040 float m_select_max_dphi;
0041 float m_select_min_dq;
0042 float m_select_max_dq;
0043
0044 void set_selection_limits(float p1, float p2, float q1, float q2) {
0045 m_select_min_dphi = p1;
0046 m_select_max_dphi = p2;
0047 m_select_min_dq = q1;
0048 m_select_max_dq = q2;
0049 }
0050
0051
0052
0053 float min_dphi() const { return m_select_min_dphi; }
0054 float max_dphi() const { return m_select_max_dphi; }
0055 float min_dq() const { return m_select_min_dq; }
0056 float max_dq() const { return m_select_max_dq; }
0057
0058
0059
0060 float c_dp_sf = 1.1;
0061 float c_dp_0 = 0.0;
0062 float c_dp_1 = 0.0;
0063 float c_dp_2 = 0.0;
0064
0065 float c_dq_sf = 1.1;
0066 float c_dq_0 = 0.0;
0067 float c_dq_1 = 0.0;
0068 float c_dq_2 = 0.0;
0069
0070 float c_c2_sf = 1.1;
0071 float c_c2_0 = 0.0;
0072 float c_c2_1 = 0.0;
0073 float c_c2_2 = 0.0;
0074
0075
0076
0077 IterationLayerConfig() {}
0078 };
0079
0080
0081
0082
0083
0084 class IterationParams {
0085 public:
0086 int nlayers_per_seed = 3;
0087 int maxCandsPerSeed = 5;
0088 int maxHolesPerCand = 4;
0089 int maxConsecHoles = 1;
0090 float chi2Cut_min = 15.0;
0091 float chi2CutOverlap = 3.5;
0092 float pTCutOverlap = 0.0;
0093
0094
0095 int minHitsQF = 4;
0096
0097
0098 float minPtCut = 0.0;
0099
0100
0101 unsigned int maxClusterSize = 8;
0102 };
0103
0104
0105
0106
0107
0108 class IterationSeedPartition {
0109 public:
0110 using register_seed_phi_eta_foo = void(float, float);
0111
0112 std::vector<int> m_region;
0113 std::function<register_seed_phi_eta_foo> m_phi_eta_foo;
0114
0115 IterationSeedPartition(int size) : m_region(size) {}
0116 };
0117
0118
0119
0120
0121
0122 class IterationConfig {
0123 public:
0124 int m_iteration_index = -1;
0125 int m_track_algorithm = -1;
0126
0127 bool m_requires_seed_hit_sorting = false;
0128
0129 bool m_backward_search = false;
0130 bool m_backward_drop_seed_hits = false;
0131
0132 int m_backward_fit_min_hits = -1;
0133
0134
0135 float sc_ptthr_hpt = 2.0;
0136 float sc_drmax_bh = 0.010;
0137 float sc_dzmax_bh = 0.005;
0138 float sc_drmax_eh = 0.020;
0139 float sc_dzmax_eh = 0.020;
0140 float sc_drmax_bl = 0.010;
0141 float sc_dzmax_bl = 0.005;
0142 float sc_drmax_el = 0.030;
0143 float sc_dzmax_el = 0.030;
0144
0145
0146 float dc_fracSharedHits = 0.19;
0147 float dc_drth_central = 0.001;
0148 float dc_drth_obarrel = 0.001;
0149 float dc_drth_forward = 0.001;
0150
0151
0152 IterationParams m_params;
0153 IterationParams m_backward_params;
0154
0155 int m_n_regions = -1;
0156 std::vector<int> m_region_order;
0157 std::vector<SteeringParams> m_steering_params;
0158 std::vector<IterationLayerConfig> m_layer_configs;
0159
0160
0161
0162 clean_seeds_func m_seed_cleaner;
0163
0164 partition_seeds_func m_seed_partitioner;
0165
0166 filter_candidates_func m_pre_bkfit_filter, m_post_bkfit_filter;
0167
0168 clean_duplicates_func m_duplicate_cleaner;
0169
0170 track_score_func m_default_track_scorer;
0171
0172
0173 std::string m_seed_cleaner_name;
0174 std::string m_seed_partitioner_name;
0175 std::string m_pre_bkfit_filter_name, m_post_bkfit_filter_name;
0176 std::string m_duplicate_cleaner_name;
0177 std::string m_default_track_scorer_name = "default";
0178
0179
0180
0181 IterationConfig() {}
0182
0183
0184
0185 IterationLayerConfig &layer(int i) { return m_layer_configs[i]; }
0186 SteeringParams &steering_params(int region) { return m_steering_params[region]; }
0187
0188 bool merge_seed_hits_during_cleaning() const { return m_backward_search && m_backward_drop_seed_hits; }
0189
0190
0191
0192 void setupStandardFunctionsFromNames();
0193
0194 void cloneLayerSteerCore(const IterationConfig &o) {
0195
0196
0197
0198
0199
0200
0201 m_n_regions = o.m_n_regions;
0202 m_region_order = o.m_region_order;
0203 m_steering_params = o.m_steering_params;
0204 m_layer_configs = o.m_layer_configs;
0205
0206 m_seed_cleaner_name = o.m_seed_cleaner_name;
0207 m_seed_partitioner_name = o.m_seed_partitioner_name;
0208 m_pre_bkfit_filter_name = o.m_pre_bkfit_filter_name;
0209 m_post_bkfit_filter_name = o.m_post_bkfit_filter_name;
0210 m_duplicate_cleaner_name = o.m_duplicate_cleaner_name;
0211 m_default_track_scorer_name = o.m_default_track_scorer_name;
0212 }
0213
0214 void set_iteration_index_and_track_algorithm(int idx, int trk_alg) {
0215 m_iteration_index = idx;
0216 m_track_algorithm = trk_alg;
0217 }
0218
0219 void set_dupl_params(float sharedFrac, float drthCentral, float drthObarrel, float drthForward) {
0220 dc_fracSharedHits = sharedFrac;
0221 dc_drth_central = drthCentral;
0222 dc_drth_obarrel = drthObarrel;
0223 dc_drth_forward = drthForward;
0224 }
0225
0226 void set_seed_cleaning_params(float pt_thr,
0227 float dzmax_bh,
0228 float drmax_bh,
0229 float dzmax_bl,
0230 float drmax_bl,
0231 float dzmax_eh,
0232 float drmax_eh,
0233 float dzmax_el,
0234 float drmax_el) {
0235 sc_ptthr_hpt = pt_thr;
0236 sc_drmax_bh = drmax_bh;
0237 sc_dzmax_bh = dzmax_bh;
0238 sc_drmax_eh = drmax_eh;
0239 sc_dzmax_eh = dzmax_eh;
0240 sc_drmax_bl = drmax_bl;
0241 sc_dzmax_bl = dzmax_bl;
0242 sc_drmax_el = drmax_el;
0243 sc_dzmax_el = dzmax_el;
0244 }
0245
0246 void set_num_regions_layers(int nreg, int nlay) {
0247 m_n_regions = nreg;
0248 m_region_order.resize(nreg);
0249 m_steering_params.resize(nreg);
0250 for (int i = 0; i < nreg; ++i)
0251 m_steering_params[i].m_region = i;
0252 m_layer_configs.resize(nlay);
0253 for (int i = 0; i < nlay; ++i)
0254 m_layer_configs[i].m_layer = i;
0255 }
0256
0257
0258 static void register_seed_cleaner(const std::string &name, clean_seeds_func func);
0259 static void register_seed_partitioner(const std::string &name, partition_seeds_func func);
0260 static void register_candidate_filter(const std::string &name, filter_candidates_func func);
0261 static void register_duplicate_cleaner(const std::string &name, clean_duplicates_func func);
0262 static void register_track_scorer(const std::string &name, track_score_func func);
0263
0264 static clean_seeds_func get_seed_cleaner(const std::string &name);
0265 static partition_seeds_func get_seed_partitioner(const std::string &name);
0266 static filter_candidates_func get_candidate_filter(const std::string &name);
0267 static clean_duplicates_func get_duplicate_cleaner(const std::string &name);
0268 static track_score_func get_track_scorer(const std::string &name);
0269 };
0270
0271
0272
0273
0274
0275 class IterationsInfo {
0276 public:
0277 std::vector<IterationConfig> m_iterations;
0278
0279 IterationsInfo() {}
0280
0281 void resize(int ni) { m_iterations.resize(ni); }
0282
0283 int size() const { return m_iterations.size(); }
0284
0285 IterationConfig &operator[](int i) { return m_iterations[i]; }
0286 const IterationConfig &operator[](int i) const { return m_iterations[i]; }
0287
0288 void setupStandardFunctionsFromNames() {
0289 for (auto &i : m_iterations)
0290 i.setupStandardFunctionsFromNames();
0291 }
0292 };
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303 class ConfigJsonPatcher {
0304 public:
0305 struct PatchReport {
0306 int n_files = 0;
0307 int n_json_entities = 0;
0308 int n_replacements = 0;
0309
0310 void inc_counts(int f, int e, int r) {
0311 n_files += f;
0312 n_json_entities += e;
0313 n_replacements += r;
0314 }
0315 void inc_counts(const PatchReport &pr) {
0316 n_files += pr.n_files;
0317 n_json_entities += pr.n_json_entities;
0318 n_replacements += pr.n_replacements;
0319 }
0320 void reset() { n_files = n_json_entities = n_replacements = 0; }
0321 };
0322
0323 private:
0324 std::unique_ptr<nlohmann::json> m_json;
0325 nlohmann::json *m_current = nullptr;
0326
0327
0328 std::vector<nlohmann::json *> m_json_stack;
0329 std::vector<std::string> m_path_stack;
0330
0331 bool m_verbose = false;
0332
0333 std::string get_abs_path() const;
0334 std::string exc_hdr(const char *func = nullptr) const;
0335
0336 public:
0337 ConfigJsonPatcher(bool verbose = false);
0338 ~ConfigJsonPatcher();
0339
0340 template <class T>
0341 void load(const T &o);
0342 template <class T>
0343 void save(T &o);
0344
0345 void cd(const std::string &path);
0346 void cd_up(const std::string &path = "");
0347 void cd_top(const std::string &path = "");
0348
0349 template <typename T>
0350 void replace(const std::string &path, T val);
0351
0352 template <typename T>
0353 void replace(int first, int last, const std::string &path, T val);
0354
0355 nlohmann::json &get(const std::string &path);
0356
0357 int replace(const nlohmann::json &j);
0358
0359 std::string dump(int indent = 2);
0360 };
0361
0362 class ConfigJson {
0363 public:
0364 ConfigJson(bool verbose = false) : m_verbose(verbose) {}
0365
0366
0367
0368
0369
0370 void patch_Files(IterationsInfo &its_info,
0371 const std::vector<std::string> &fnames,
0372 ConfigJsonPatcher::PatchReport *report = nullptr);
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382 std::unique_ptr<IterationConfig> patchLoad_File(const IterationsInfo &its_info,
0383 const std::string &fname,
0384 ConfigJsonPatcher::PatchReport *report = nullptr);
0385
0386
0387
0388
0389
0390
0391
0392 std::unique_ptr<IterationConfig> load_File(const std::string &fname);
0393
0394 void save_Iterations(IterationsInfo &its_info, const std::string &fname_fmt, bool include_iter_info_preamble);
0395
0396 void dump(IterationsInfo &its_info);
0397
0398 void test_Direct(IterationConfig &it_cfg);
0399 void test_Patcher(IterationConfig &it_cfg);
0400
0401 private:
0402 bool m_verbose = false;
0403 };
0404 }
0405
0406 #endif