Falaise  4.0.1
SuperNEMO Software Toolkit
xcalo_locator.h
Go to the documentation of this file.
1 /// \file falaise/snemo/geometry/xcalo_locator.h
2 /* Author(s) : Xavier Garrido <garrido@lal.in2p3.fr>
3  * Creation date : 2012-06-11
4  * Last modified : 2015-09-19
5  *
6  * Copyright (C) 2011-2015 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * X-Calorimeter scintillator block locator for one module of the SuperNEMO detector
26  *
27  * History:
28  *
29  */
30 
31 #ifndef FALAISE_SNEMO_GEOMETRY_XCALO_LOCATOR_H
32 #define FALAISE_SNEMO_GEOMETRY_XCALO_LOCATOR_H 1
33 
34 // Standard library:
35 #include <string>
36 
37 // Third party:
38 // - Boost :
39 #include <boost/cstdint.hpp>
40 // - Bayeux/geomtools:
41 #include <geomtools/i_locator.h>
42 
43 // This project:
45 
46 /** forward declaration */
47 namespace geomtools {
48 class mapping;
49 class id_mgr;
50 class manager;
51 class placement;
52 class i_shape_3d;
53 class box;
54 } // namespace geomtools
55 
56 namespace snemo {
57 
58 namespace geometry {
59 
60 /// \brief Fast locator class for SuperNEMO X calorimeter scintillator block volumes
62  public:
63  /// Number of X-calorimeter walls per side (on the Y-axis)
64  static const unsigned int NWALLS_PER_SIDE = 2;
65 
66  /// \brief Wall identifier constants (SuperNEMO module Y axis)
67  enum wall_type {
68  WALL_INVALID = -1, //!< Invalid/undefined wall
69  WALL_LEFT = 0, //!< Left wall
70  WALL_RIGHT = 1 //!< Right wall
71  };
72 
73  virtual bool is_initialized() const;
74 
75  /// Constructor
76  xcalo_locator();
77 
78  /// Constructor:
79  xcalo_locator(const ::geomtools::manager& gmgr_, uint32_t module_number_);
80 
81  /// Destructor
82  virtual ~xcalo_locator();
83 
84  virtual void initialize(const datatools::properties& config_);
85 
86  virtual void reset();
87 
88  void initialize();
89 
90  bool has_submodule(uint32_t side_) const;
91 
92  bool id_is_valid(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_) const;
93 
94  // Interfaces from geomtools::i_locator :
95  virtual bool find_geom_id(const geomtools::vector_3d& world_position_, int type_,
96  geomtools::geom_id& gid_,
97  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
98 
99  bool find_block_geom_id(const geomtools::vector_3d& world_position_, geomtools::geom_id& gid_,
100  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
101 
102  protected:
103  /**
104  */
105  bool find_block_geom_id_(const geomtools::vector_3d& in_module_position_,
106  geomtools::geom_id& gid_,
107  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE);
108 
109  /** Checks if the locator has been intialized or throw an exception.
110  */
111  void _assert_initialized(const std::string& where_) const;
112 
113  void _set_defaults_();
114 
115  public:
116  /**! @return the number of the module (>=0).
117  */
118  uint32_t get_module_number() const;
119 
120  /**! set the number of the module for this locator.
121  */
122  void set_module_number(uint32_t module_number_);
123 
124  /**! check if block is partitioned in the current setup.
125  */
126  bool is_block_partitioned() const;
127 
128  /**! @return the width of a calorimeter block.
129  */
130  double get_block_width() const;
131 
132  /**! @return the height of a calorimeter block.
133  */
134  double get_block_height() const;
135 
136  /**! @return the thickness of a block.
137  */
138  double get_block_thickness() const;
139 
140  /**! @return the number of sides on the calorimeter.
141  */
142  size_t get_number_of_sides() const;
143 
144  /**! @return the number of walls on the calorimeter.
145  */
146  size_t get_number_of_walls() const;
147 
148  /**! @return the number of columns in one side and one wall of the calorimeter.
149  */
150  size_t get_number_of_columns(uint32_t side_, uint32_t wall_) const;
151 
152  /**! @return the number of rows in one side and one wall of the calorimeter.
153  */
154  size_t get_number_of_rows(uint32_t side_, uint32_t wall_) const;
155 
156  /**! @return the Y-position of a wall for specific side and wall (in module coordinate system).
157  */
158  double get_wall_y(uint32_t side_, uint32_t wall_) const;
159 
160  /**! @return the Y-position of the entrance window of a wall for specific side and wall (in module
161  * coordinate system).
162  */
163  double get_wall_window_y(uint32_t side_, uint32_t wall_) const;
164 
165  /**! @return the X-position of a block for specific side, wall and column (in module coordinate
166  * system).
167  */
168  double get_column_x(uint32_t side_, uint32_t wall_, uint32_t column_) const;
169 
170  /**! @return the Z-position of a block for specific side, wall and row (in module coordinate
171  * system).
172  */
173  double get_row_z(uint32_t side_, uint32_t wall_, uint32_t row_) const;
174 
175  /**! Compute the position of a block
176  * for specific side, wall, column and row (in module coordinate system).
177  */
178  void compute_block_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_,
179  geomtools::vector_3d& module_position_) const;
180 
181  /**! Compute the position of the center of the entrance window of a block
182  * for specific side, column and row (in module coordinate system).
183  */
184  void compute_block_window_position(uint32_t side_, uint32_t wall_, uint32_t column_,
185  uint32_t row_, geomtools::vector_3d& module_position_) const;
186 
187  /**! @return the position of a block for specific side, wall, column and row (in module coordinate
188  * system).
189  */
190  geomtools::vector_3d get_block_position(uint32_t side_, uint32_t wall_, uint32_t column_,
191  uint32_t row_) const;
192 
193  /**! @return the position of the center of the entrance window of a block
194  * for specific side, wall, column and row (in module coordinate system).
195  */
196  geomtools::vector_3d get_block_window_position(uint32_t side_, uint32_t wall_, uint32_t column_,
197  uint32_t row_) const;
198 
199  /** Tranform a world coordinate system position to the corresponding module coordinate system
200  * position.
201  */
202  void transform_world_to_module(const geomtools::vector_3d& world_position_,
203  geomtools::vector_3d& module_position_) const;
204 
205  /** Tranform a module coordinate system position to the corresponding world coordinate system
206  * position.
207  */
208  void transform_module_to_world(const geomtools::vector_3d& module_position_,
209  geomtools::vector_3d& world_position_) const;
210 
211  /** Check if a world coordinate system position is in the module virtual volume (its bounding
212  * envelope).
213  */
214  bool is_world_position_in_module(const geomtools::vector_3d& world_position_,
215  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
216 
217  /** Check if a module coordinate system position is in the module virtual volume (its bounding
218  * envelope).
219  */
220  bool is_in_module(const geomtools::vector_3d& module_position_,
221  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
222 
223  /** Check if a module coordinate system position is in a specific block virtual volume (its
224  * bounding envelope).
225  */
226  bool is_in_block(const geomtools::vector_3d& module_position_, uint32_t side_, uint32_t wall_,
227  uint32_t column_, uint32_t row_,
228  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
229 
230  /** Check if a world coordinate system position is in a specific block virtual volume (its
231  * bounding envelope).
232  */
233  bool is_world_position_in_block(const geomtools::vector_3d& world_position_, uint32_t side_,
234  uint32_t wall_, uint32_t column_, uint32_t row_,
235  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
236 
237  /** Given a block at specific side, wall, column and row, returns the number of neighbouring
238  * blocks.
239  */
240  size_t get_number_of_neighbours(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_,
241  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
242 
243  /** Given a block with a specific geometry ID, returns the number of neighbouring blocks.
244  */
245  size_t get_number_of_neighbours(const geomtools::geom_id& gid_,
246  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
247 
248  /** Given a block at specific side, wall, column and row, compute the array of geometry IDs for
249  * associated neighbouring blocks.
250  */
251  void get_neighbours_ids(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_,
252  std::vector<geomtools::geom_id>& ids_,
253  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
254 
255  /** Given a block with a specific geometry IDs, compute the array of geometry IDs for associated
256  * neighbouring blocks.
257  */
258  void get_neighbours_ids(const geomtools::geom_id& gid_, std::vector<geomtools::geom_id>& ids_,
259  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
260 
261  /** Given a block with a specific geometry IDs, compute its position in the module coordinate
262  * system.
263  */
264  void get_block_position(const geomtools::geom_id& gid_, geomtools::vector_3d& position_) const;
265 
266  /** Given a block with a specific side, wall, column and row, compute its position in the module
267  * coordinate system.
268  */
269  void get_block_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_,
270  geomtools::vector_3d& position_) const;
271 
272  int get_module_address_index() const;
273 
274  int get_side_address_index() const;
275 
276  int get_wall_address_index() const;
277 
278  int get_column_address_index() const;
279 
280  int get_row_address_index() const;
281 
282  int get_part_address_index() const;
283 
284  uint32_t extract_module(const geomtools::geom_id& gid_) const;
285 
286  uint32_t extract_side(const geomtools::geom_id& gid_) const;
287 
288  uint32_t extract_wall(const geomtools::geom_id& gid_) const;
289 
290  uint32_t extract_column(const geomtools::geom_id& gid_) const;
291 
292  uint32_t extract_row(const geomtools::geom_id& gid_) const;
293 
294  uint32_t extract_part(const geomtools::geom_id& gid_) const;
295 
296  bool is_calo_block(const geomtools::geom_id& gid_) const;
297 
298  bool is_calo_block_in_current_module(const geomtools::geom_id& gid_) const;
299 
300  /// Smart print
301  virtual void tree_dump(std::ostream& out_ = std::clog, const std::string& title_ = "",
302  const std::string& indent_ = "", bool inherit_ = false) const;
303 
304  /// Dump
305  void dump(std::ostream& out_) const;
306 
307  protected:
308  void _construct();
309 
310  /// Hack trace
311  void _hack_trace();
312 
313  private:
314  bool _initialized_;
315 
316  // Logging priority
317  datatools::logger::priority _logging_priority_;
318 
319  // Configuration parameters :
320  const geomtools::manager* _geom_manager_;
321  uint32_t _module_number_;
322  uint32_t _block_part_;
323 
324  // Running values :
325  uint32_t _module_type_;
326  uint32_t _tracker_submodule_type_;
327  uint32_t _block_type_;
328  uint32_t _wrapper_type_;
329  bool _block_partitioned_;
330 
331  const geomtools::mapping* _mapping_;
332  const geomtools::id_mgr* _id_manager_;
333 
334  const geomtools::geom_info* _module_ginfo_;
335  const geomtools::placement* _module_world_placement_;
336  const geomtools::box* _module_box_;
337  const geomtools::i_shape_3d* _block_shape_;
338  bool _composite_block_shape_;
339  const geomtools::box* _block_box_;
340  double _block_y_[2][NWALLS_PER_SIDE];
341  double _block_window_y_[2][NWALLS_PER_SIDE];
342  std::vector<double> _back_block_z_[NWALLS_PER_SIDE];
343  std::vector<double> _front_block_z_[NWALLS_PER_SIDE];
344  std::vector<double> _back_block_x_[NWALLS_PER_SIDE];
345  std::vector<double> _front_block_x_[NWALLS_PER_SIDE];
346 
347  double _block_width_;
348  double _block_height_;
349  double _block_thickness_;
350 
351  // Block GID addressing :
352  int _module_address_index_;
353  int _side_address_index_;
354  int _wall_address_index_;
355  int _column_address_index_;
356  int _row_address_index_;
357  int _part_address_index_;
358 
359  // Submodules are present :
360  bool _submodules_[2];
361 };
362 
363 } // end of namespace geometry
364 
365 } // end of namespace snemo
366 
367 #endif // FALAISE_SNEMO_GEOMETRY_XCALO_LOCATOR_H
368 
369 /*
370 ** Local Variables: --
371 ** mode: c++ --
372 ** c-file-style: "gnu" --
373 ** tab-width: 2 --
374 ** End: --
375 */
bool find_block_geom_id(const geomtools::vector_3d &world_position_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
double get_wall_y(uint32_t side_, uint32_t wall_) const
void _hack_trace()
Hack trace.
double get_row_z(uint32_t side_, uint32_t wall_, uint32_t row_) const
geomtools::vector_3d get_block_window_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_) const
void transform_module_to_world(const geomtools::vector_3d &module_position_, geomtools::vector_3d &world_position_) const
bool is_world_position_in_block(const geomtools::vector_3d &world_position_, uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
static const unsigned int NWALLS_PER_SIDE
Number of X-calorimeter walls per side (on the Y-axis)
Definition: xcalo_locator.h:64
bool is_in_block(const geomtools::vector_3d &module_position_, uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
uint32_t extract_column(const geomtools::geom_id &gid_) const
uint32_t extract_module(const geomtools::geom_id &gid_) const
double get_wall_window_y(uint32_t side_, uint32_t wall_) const
Fast locator class for SuperNEMO X calorimeter scintillator block volumes.
Definition: xcalo_locator.h:61
double get_block_thickness() const
bool has_submodule(uint32_t side_) const
bool is_in_module(const geomtools::vector_3d &module_position_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
bool id_is_valid(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_) const
uint32_t extract_row(const geomtools::geom_id &gid_) const
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
Right wall.
Definition: xcalo_locator.h:70
D : nearest diagonal.
Definition: utils.h:91
void dump(std::ostream &out_) const
Dump.
bool is_calo_block(const geomtools::geom_id &gid_) const
Definition: calo_tapered_scin_box_model.h:54
void set_module_number(uint32_t module_number_)
uint32_t extract_wall(const geomtools::geom_id &gid_) const
uint32_t get_module_number() const
virtual bool is_initialized() const
geomtools::vector_3d get_block_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_) const
CLHEP::Hep3Vector vector_3d
wall_type
Wall identifier constants (SuperNEMO module Y axis)
Definition: xcalo_locator.h:67
Invalid/undefined wall.
Definition: xcalo_locator.h:68
void transform_world_to_module(const geomtools::vector_3d &world_position_, geomtools::vector_3d &module_position_) const
size_t get_number_of_neighbours(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, uint8_t mask_=utils::NEIGHBOUR_FIRST) const
virtual ~xcalo_locator()
Destructor.
void compute_block_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, geomtools::vector_3d &module_position_) const
uint32_t extract_part(const geomtools::geom_id &gid_) const
size_t get_number_of_walls() const
void compute_block_window_position(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, geomtools::vector_3d &module_position_) const
uint32_t extract_side(const geomtools::geom_id &gid_) const
Left wall.
Definition: xcalo_locator.h:69
double get_column_x(uint32_t side_, uint32_t wall_, uint32_t column_) const
size_t get_number_of_rows(uint32_t side_, uint32_t wall_) const
bool is_world_position_in_module(const geomtools::vector_3d &world_position_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
virtual bool find_geom_id(const geomtools::vector_3d &world_position_, int type_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
size_t get_number_of_columns(uint32_t side_, uint32_t wall_) const
void _assert_initialized(const std::string &where_) const
bool is_calo_block_in_current_module(const geomtools::geom_id &gid_) const
size_t get_number_of_sides() const
bool find_block_geom_id_(const geomtools::vector_3d &in_module_position_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE)
void get_neighbours_ids(uint32_t side_, uint32_t wall_, uint32_t column_, uint32_t row_, std::vector< geomtools::geom_id > &ids_, uint8_t mask_=utils::NEIGHBOUR_FIRST) const