CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 = 1.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 
117  //==============================================================================
118  // IterationSeedPartition
119  //==============================================================================
120 
122  public:
123  std::vector<int> m_region;
124  std::vector<float> m_sort_score;
125 
127  };
128 
129  //==============================================================================
130  // IterationConfig
131  //==============================================================================
132 
134  public:
135  using partition_seeds_foo = void(const TrackerInfo &,
136  const TrackVec &,
137  const EventOfHits &,
139 
142 
146 
147  bool m_backward_search = false;
149 
150  int m_backward_fit_min_hits = -1; // Min number of hits to keep when m_backward_drop_seed_hits is true
151 
152  // Iteration parameters (could be a ptr)
155 
156  int m_n_regions = -1;
157  std::vector<int> m_region_order;
158  std::vector<SteeringParams> m_steering_params;
159  std::vector<IterationLayerConfig> m_layer_configs;
160 
161  std::function<partition_seeds_foo> m_partition_seeds;
162 
163  //----------------------------------------------------------------------------
164 
166 
167  // -------- Getter functions
168 
171 
173 
174  // -------- Setup function
175 
177  // Clone common settings for an iteration.
178  // m_iteration_index, m_track_algorithm, cleaning and bkw-search flags,
179  // and IterationParams are not copied.
180 
185 
187  }
188 
189  void set_iteration_index_and_track_algorithm(int idx, int trk_alg) {
190  m_iteration_index = idx;
191  m_track_algorithm = trk_alg;
192  }
193 
194  void set_qf_flags() {
197  }
198 
199  void set_qf_params(int minHits, float sharedFrac) {
201  m_params.fracSharedHits = sharedFrac;
202  }
203 
205 
206  void set_dupl_params(float sharedFrac, float drthCentral, float drthObarrel, float drthForward) {
207  m_params.fracSharedHits = sharedFrac;
208  m_params.drth_central = drthCentral;
209  m_params.drth_obarrel = drthObarrel;
210  m_params.drth_forward = drthForward;
211  }
212 
213  void set_seed_cleaning_params(float pt_thr,
214  float dzmax_bh,
215  float drmax_bh,
216  float dzmax_bl,
217  float drmax_bl,
218  float dzmax_eh,
219  float drmax_eh,
220  float dzmax_el,
221  float drmax_el) {
222  m_params.c_ptthr_hpt = pt_thr;
223  m_params.c_drmax_bh = drmax_bh;
224  m_params.c_dzmax_bh = dzmax_bh;
225  m_params.c_drmax_eh = drmax_eh;
226  m_params.c_dzmax_eh = dzmax_eh;
227  m_params.c_drmax_bl = drmax_bl;
228  m_params.c_dzmax_bl = dzmax_bl;
229  m_params.c_drmax_el = drmax_el;
230  m_params.c_dzmax_el = dzmax_el;
231  }
232 
233  void set_num_regions_layers(int nreg, int nlay) {
234  m_n_regions = nreg;
235  m_region_order.resize(nreg);
236  m_steering_params.resize(nreg);
237  for (int i = 0; i < nreg; ++i)
238  m_steering_params[i].m_region = i;
239  m_layer_configs.resize(nlay);
240  }
241  };
242 
243  //==============================================================================
244  // IterationsInfo
245  //==============================================================================
246 
248  public:
249  std::vector<IterationConfig> m_iterations;
250 
252 
253  void resize(int ni) { m_iterations.resize(ni); }
254 
255  int size() const { return m_iterations.size(); }
256 
258  const IterationConfig &operator[](int i) const { return m_iterations[i]; }
259  };
260 
261  //==============================================================================
262 
263  // IterationConfig instances are created in Geoms/CMS-2017.cc, Create_CMS_2017(),
264  // filling the IterationsInfo object passed in by reference.
265 
266  //==============================================================================
267  // JSON config interface
268  //==============================================================================
269 
271  public:
272  struct PatchReport {
273  int n_files = 0;
275  int n_replacements = 0;
276 
277  void inc_counts(int f, int e, int r) {
278  n_files += f;
279  n_json_entities += e;
280  n_replacements += r;
281  }
282  void inc_counts(const PatchReport &pr) {
283  n_files += pr.n_files;
286  }
288  };
289 
290  private:
291  std::unique_ptr<nlohmann::json> m_json;
293 
294  // add stack and cd_up() ? also, name stack for exceptions and printouts
295  std::vector<nlohmann::json *> m_json_stack;
296  std::vector<std::string> m_path_stack;
297 
298  bool m_verbose = false;
299 
300  std::string get_abs_path() const;
301  std::string exc_hdr(const char *func = nullptr) const;
302 
303  public:
304  ConfigJsonPatcher(bool verbose = false);
306 
307  template <class T>
308  void load(const T &o);
309  template <class T>
310  void save(T &o);
311 
312  void cd(const std::string &path);
313  void cd_up(const std::string &path = "");
314  void cd_top(const std::string &path = "");
315 
316  template <typename T>
317  void replace(const std::string &path, T val);
318 
319  template <typename T>
320  void replace(int first, int last, const std::string &path, T val);
321 
322  nlohmann::json &get(const std::string &path);
323 
324  int replace(const nlohmann::json &j);
325 
326  std::string dump(int indent = 2);
327  };
328 
329  class ConfigJson {
330  public:
331  ConfigJson(bool verbose = false) : m_verbose(verbose) {}
332 
333  // Patch IterationsInfo from a vector of files.
334  // Assumes patch files include iteration-info preambles, i.e., they
335  // were saved with include_iter_info_preamble=true.
336  // If report is non-null counts are added to existing object.
337  void patch_Files(IterationsInfo &its_info,
338  const std::vector<std::string> &fnames,
340 
341  // Load a single iteration from JSON file.
342  // Searches for a match between m_algorithm in its_info and in JSON file to decide
343  // which IterationConfig it will clone and patch-load the JSON file over.
344  // The IterationConfig in question *must* match in structure to what is on file,
345  // in particular, arrays must be of same lengths.
346  // Assumes JSON file has been saved WITHOUT iteration-info preamble.
347  // Returns a unique_ptr to the cloned IterationConfig.
348  // If report is non-null counts are added to existing object.
349  std::unique_ptr<IterationConfig> patchLoad_File(const IterationsInfo &its_info,
350  const std::string &fname,
352 
353  // Load a single iteration from JSON file.
354  // This leaves IterationConfig data-members that are not registered
355  // in JSON schema at their default values.
356  // The only such member is std::function m_partition_seeds.
357  // Assumes JSON file has been saved WITHOUT iteration-info preamble.
358  // Returns a unique_ptr to the cloned IterationConfig.
359  std::unique_ptr<IterationConfig> load_File(const std::string &fname);
360 
361  void save_Iterations(IterationsInfo &its_info, const std::string &fname_fmt, bool include_iter_info_preamble);
362 
363  void dump(IterationsInfo &its_info);
364 
365  void test_Direct(IterationConfig &it_cfg);
366  void test_Patcher(IterationConfig &it_cfg);
367 
368  private:
369  bool m_verbose = false;
370  };
371 } // end namespace mkfit
372 
373 #endif
nlohmann::json * m_current
IterationParams m_params
IterationParams m_backward_params
const TString p2
Definition: fwPaths.cc:13
SteeringParams & steering_params(int region)
nlohmann::json json
bool verbose
virtual const std::vector< bool > * get_mask_for_layer(int layer) const
std::string get_abs_path() const
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)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
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
constexpr std::array< uint8_t, layerIndexSize > layer
void replace(const std::string &path, T val)
tuple report
Definition: zeeHLT_cff.py:9
void test_Direct(IterationConfig &it_cfg)
void patch_Files(IterationsInfo &its_info, const std::vector< std::string > &fnames, ConfigJsonPatcher::PatchReport *report=nullptr)
bool merge_seed_hits_during_cleaning() 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::string exc_hdr(const char *func=nullptr) const
const TString p1
Definition: fwPaths.cc:12
std::unique_ptr< IterationConfig > patchLoad_File(const IterationsInfo &its_info, const std::string &fname, ConfigJsonPatcher::PatchReport *report=nullptr)
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)
std::vector< float > m_sort_score
void(const TrackerInfo &, const TrackVec &, const EventOfHits &, IterationSeedPartition &) partition_seeds_foo
std::vector< Track > TrackVec
void cloneLayerSteerCore(const IterationConfig &o)
std::unique_ptr< IterationConfig > load_File(const std::string &fname)
IterationConfig & operator[](int i)
void dump(IterationsInfo &its_info)
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)
const IterationConfig & operator[](int i) const
std::function< partition_seeds_foo > m_partition_seeds
std::vector< std::vector< bool > > m_mask_vector
tuple last
Definition: dqmdumpme.py:56
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
tuple size
Write out results.