CMS 3D CMS Logo

IterationConfig.h
Go to the documentation of this file.
1 #ifndef RecoTracker_MkFitCore_interface_IterationConfig_h
2 #define RecoTracker_MkFitCore_interface_IterationConfig_h
3 
5 
6 #include "nlohmann/json_fwd.hpp"
7 
8 #include <functional>
9 
10 namespace mkfit {
11 
12  class EventOfHits;
13  class TrackerInfo;
14  class Track;
15 
16  typedef std::vector<Track> TrackVec;
17 
18  //==============================================================================
19  // Hit masks / IterationMaskIfc
20  //==============================================================================
21 
23  virtual ~IterationMaskIfcBase() {}
24 
25  virtual const std::vector<bool> *get_mask_for_layer(int layer) const { return nullptr; }
26  };
27 
29  std::vector<std::vector<bool>> m_mask_vector;
30 
31  const std::vector<bool> *get_mask_for_layer(int layer) const override { return &m_mask_vector[layer]; }
32  };
33 
34  //==============================================================================
35  // IterationLayerConfig
36  //==============================================================================
37 
38  class IterationConfig;
39 
41  public:
42  // Selection limits.
47 
48  void set_selection_limits(float p1, float p2, float q1, float q2) {
51  m_select_min_dq = q1;
52  m_select_max_dq = q2;
53  }
54 
55  //----------------------------------------------------------------------------
56 
57  float min_dphi() const { return m_select_min_dphi; }
58  float max_dphi() const { return m_select_max_dphi; }
59  float min_dq() const { return m_select_min_dq; }
60  float max_dq() const { return m_select_max_dq; }
61 
62  //Hit selection windows: 2D fit/layer (72 in phase-1 CMS geometry)
63  //cut = [0]*1/pT + [1]*std::fabs(theta-pi/2) + [2])
64  float c_dp_sf = 1.1;
65  float c_dp_0 = 0.0;
66  float c_dp_1 = 0.0;
67  float c_dp_2 = 0.0;
68  //
69  float c_dq_sf = 1.1;
70  float c_dq_0 = 0.0;
71  float c_dq_1 = 0.0;
72  float c_dq_2 = 0.0;
73  //
74  float c_c2_sf = 1.1;
75  float c_c2_0 = 0.0;
76  float c_c2_1 = 0.0;
77  float c_c2_2 = 0.0;
78 
79  //----------------------------------------------------------------------------
80 
82  };
83 
84  //==============================================================================
85  // IterationParams
86  //==============================================================================
87 
89  public:
91  int maxCandsPerSeed = 5;
92  int maxHolesPerCand = 4;
93  int maxConsecHoles = 1;
94  float chi2Cut_min = 15.0;
95  float chi2CutOverlap = 3.5;
96  float pTCutOverlap = 0.0;
97 
98  //seed cleaning params
99  float c_ptthr_hpt = 2.0;
100  //initial
101  float c_drmax_bh = 0.010;
102  float c_dzmax_bh = 0.005;
103  float c_drmax_eh = 0.020;
104  float c_dzmax_eh = 0.020;
105  float c_drmax_bl = 0.010;
106  float c_dzmax_bl = 0.005;
107  float c_drmax_el = 0.030;
108  float c_dzmax_el = 0.030;
109 
110  int minHitsQF = 4;
111  float fracSharedHits = 0.19;
112  float drth_central = 0.001;
113  float drth_obarrel = 0.001;
114  float drth_forward = 0.001;
115 
116  //min pT cut
117  float minPtCut = 0.0;
118 
119  //max cluster size cut for SiStrip hits
120  unsigned int maxClusterSize = 8;
121  };
122 
123  //==============================================================================
124  // IterationSeedPartition
125  //==============================================================================
126 
128  public:
129  using register_seed_phi_eta_foo = void(float, float);
130 
131  std::vector<int> m_region;
132  std::function<register_seed_phi_eta_foo> m_phi_eta_foo;
133 
135  };
136 
137  //==============================================================================
138  // IterationConfig
139  //==============================================================================
140 
142  public:
143  using partition_seeds_foo = void(const TrackerInfo &,
144  const TrackVec &,
145  const EventOfHits &,
147 
150 
154 
155  bool m_backward_search = false;
157 
158  int m_backward_fit_min_hits = -1; // Min number of hits to keep when m_backward_drop_seed_hits is true
159 
160  // Iteration parameters (could be a ptr)
163 
164  int m_n_regions = -1;
165  std::vector<int> m_region_order;
166  std::vector<SteeringParams> m_steering_params;
167  std::vector<IterationLayerConfig> m_layer_configs;
168 
169  std::function<partition_seeds_foo> m_partition_seeds;
170 
171  //----------------------------------------------------------------------------
172 
174 
175  // -------- Getter functions
176 
179 
181 
182  // -------- Setup function
183 
185  // Clone common settings for an iteration.
186  // m_iteration_index, m_track_algorithm, cleaning and bkw-search flags,
187  // and IterationParams are not copied.
188 
189  m_n_regions = o.m_n_regions;
190  m_region_order = o.m_region_order;
191  m_steering_params = o.m_steering_params;
192  m_layer_configs = o.m_layer_configs;
193 
194  m_partition_seeds = o.m_partition_seeds;
195  }
196 
199  m_track_algorithm = trk_alg;
200  }
201 
202  void set_qf_flags() {
205  }
206 
207  void set_qf_params(int minHits, float sharedFrac) {
210  }
211 
213 
214  void set_dupl_params(float sharedFrac, float drthCentral, float drthObarrel, float drthForward) {
216  m_params.drth_central = drthCentral;
217  m_params.drth_obarrel = drthObarrel;
218  m_params.drth_forward = drthForward;
219  }
220 
221  void set_seed_cleaning_params(float pt_thr,
222  float dzmax_bh,
223  float drmax_bh,
224  float dzmax_bl,
225  float drmax_bl,
226  float dzmax_eh,
227  float drmax_eh,
228  float dzmax_el,
229  float drmax_el) {
230  m_params.c_ptthr_hpt = pt_thr;
231  m_params.c_drmax_bh = drmax_bh;
232  m_params.c_dzmax_bh = dzmax_bh;
233  m_params.c_drmax_eh = drmax_eh;
234  m_params.c_dzmax_eh = dzmax_eh;
235  m_params.c_drmax_bl = drmax_bl;
236  m_params.c_dzmax_bl = dzmax_bl;
237  m_params.c_drmax_el = drmax_el;
238  m_params.c_dzmax_el = dzmax_el;
239  }
240 
241  void set_num_regions_layers(int nreg, int nlay) {
242  m_n_regions = nreg;
243  m_region_order.resize(nreg);
244  m_steering_params.resize(nreg);
245  for (int i = 0; i < nreg; ++i)
246  m_steering_params[i].m_region = i;
247  m_layer_configs.resize(nlay);
248  }
249  };
250 
251  //==============================================================================
252  // IterationsInfo
253  //==============================================================================
254 
256  public:
257  std::vector<IterationConfig> m_iterations;
258 
260 
261  void resize(int ni) { m_iterations.resize(ni); }
262 
263  int size() const { return m_iterations.size(); }
264 
266  const IterationConfig &operator[](int i) const { return m_iterations[i]; }
267  };
268 
269  //==============================================================================
270 
271  // IterationConfig instances are created in Geoms/CMS-2017.cc, Create_CMS_2017(),
272  // filling the IterationsInfo object passed in by reference.
273 
274  //==============================================================================
275  // JSON config interface
276  //==============================================================================
277 
279  public:
280  struct PatchReport {
281  int n_files = 0;
283  int n_replacements = 0;
284 
285  void inc_counts(int f, int e, int r) {
286  n_files += f;
287  n_json_entities += e;
288  n_replacements += r;
289  }
290  void inc_counts(const PatchReport &pr) {
291  n_files += pr.n_files;
292  n_json_entities += pr.n_json_entities;
293  n_replacements += pr.n_replacements;
294  }
296  };
297 
298  private:
299  std::unique_ptr<nlohmann::json> m_json;
301 
302  // add stack and cd_up() ? also, name stack for exceptions and printouts
303  std::vector<nlohmann::json *> m_json_stack;
304  std::vector<std::string> m_path_stack;
305 
306  bool m_verbose = false;
307 
308  std::string get_abs_path() const;
309  std::string exc_hdr(const char *func = nullptr) const;
310 
311  public:
312  ConfigJsonPatcher(bool verbose = false);
314 
315  template <class T>
316  void load(const T &o);
317  template <class T>
318  void save(T &o);
319 
320  void cd(const std::string &path);
321  void cd_up(const std::string &path = "");
322  void cd_top(const std::string &path = "");
323 
324  template <typename T>
325  void replace(const std::string &path, T val);
326 
327  template <typename T>
328  void replace(int first, int last, const std::string &path, T val);
329 
330  nlohmann::json &get(const std::string &path);
331 
332  int replace(const nlohmann::json &j);
333 
334  std::string dump(int indent = 2);
335  };
336 
337  class ConfigJson {
338  public:
339  ConfigJson(bool verbose = false) : m_verbose(verbose) {}
340 
341  // Patch IterationsInfo from a vector of files.
342  // Assumes patch files include iteration-info preambles, i.e., they
343  // were saved with include_iter_info_preamble=true.
344  // If report is non-null counts are added to existing object.
345  void patch_Files(IterationsInfo &its_info,
346  const std::vector<std::string> &fnames,
348 
349  // Load a single iteration from JSON file.
350  // Searches for a match between m_algorithm in its_info and in JSON file to decide
351  // which IterationConfig it will clone and patch-load the JSON file over.
352  // The IterationConfig in question *must* match in structure to what is on file,
353  // in particular, arrays must be of same lengths.
354  // Assumes JSON file has been saved WITHOUT iteration-info preamble.
355  // Returns a unique_ptr to the cloned IterationConfig.
356  // If report is non-null counts are added to existing object.
357  std::unique_ptr<IterationConfig> patchLoad_File(const IterationsInfo &its_info,
358  const std::string &fname,
360 
361  // Load a single iteration from JSON file.
362  // This leaves IterationConfig data-members that are not registered
363  // in JSON schema at their default values.
364  // The only such member is std::function m_partition_seeds.
365  // Assumes JSON file has been saved WITHOUT iteration-info preamble.
366  // Returns a unique_ptr to the cloned IterationConfig.
367  std::unique_ptr<IterationConfig> load_File(const std::string &fname);
368 
369  void save_Iterations(IterationsInfo &its_info, const std::string &fname_fmt, bool include_iter_info_preamble);
370 
371  void dump(IterationsInfo &its_info);
372 
373  void test_Direct(IterationConfig &it_cfg);
374  void test_Patcher(IterationConfig &it_cfg);
375 
376  private:
377  bool m_verbose = false;
378  };
379 } // end namespace mkfit
380 
381 #endif
size
Write out results.
nlohmann::json * m_current
IterationParams m_params
IterationParams m_backward_params
std::function< register_seed_phi_eta_foo > m_phi_eta_foo
SteeringParams & steering_params(int region)
nlohmann::json json
bool verbose
void inc_counts(const PatchReport &pr)
void set_seed_cleaning_params(float pt_thr, float dzmax_bh, float drmax_bh, float dzmax_bl, float drmax_bl, float dzmax_eh, float drmax_eh, float dzmax_el, float drmax_el)
std::string dump(int indent=2)
void inc_counts(int f, int e, int r)
void set_dupl_params(float sharedFrac, float drthCentral, float drthObarrel, float drthForward)
std::vector< int > m_region_order
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
constexpr std::array< uint8_t, layerIndexSize > layer
void replace(const std::string &path, T val)
void test_Direct(IterationConfig &it_cfg)
void patch_Files(IterationsInfo &its_info, const std::vector< std::string > &fnames, ConfigJsonPatcher::PatchReport *report=nullptr)
std::string exc_hdr(const char *func=nullptr) const
std::vector< nlohmann::json * > m_json_stack
std::vector< IterationLayerConfig > m_layer_configs
void set_selection_limits(float p1, float p2, float q1, float q2)
const std::vector< bool > * get_mask_for_layer(int layer) const override
void set_qf_params(int minHits, float sharedFrac)
std::unique_ptr< IterationConfig > patchLoad_File(const IterationsInfo &its_info, const std::string &fname, ConfigJsonPatcher::PatchReport *report=nullptr)
double f[11][100]
void cd(const std::string &path)
void set_iteration_index_and_track_algorithm(int idx, int trk_alg)
std::vector< std::string > m_path_stack
void save_Iterations(IterationsInfo &its_info, const std::string &fname_fmt, bool include_iter_info_preamble)
void test_Patcher(IterationConfig &it_cfg)
void(const TrackerInfo &, const TrackVec &, const EventOfHits &, IterationSeedPartition &) partition_seeds_foo
std::vector< Track > TrackVec
bool merge_seed_hits_during_cleaning() const
void cloneLayerSteerCore(const IterationConfig &o)
std::unique_ptr< IterationConfig > load_File(const std::string &fname)
const IterationConfig & operator[](int i) const
IterationConfig & operator[](int i)
void dump(IterationsInfo &its_info)
void(float, float) register_seed_phi_eta_foo
void set_num_regions_layers(int nreg, int nlay)
string fname
main script
std::unique_ptr< nlohmann::json > m_json
void cd_up(const std::string &path="")
IterationLayerConfig & layer(int i)
ConfigJsonPatcher(bool verbose=false)
std::function< partition_seeds_foo > m_partition_seeds
std::vector< std::vector< bool > > m_mask_vector
void cd_top(const std::string &path="")
std::vector< IterationConfig > m_iterations
long double T
ConfigJson(bool verbose=false)
std::vector< SteeringParams > m_steering_params
virtual const std::vector< bool > * get_mask_for_layer(int layer) const
std::string get_abs_path() const