Falaise  4.0.1
SuperNEMO Software Toolkit
calo_locator.h
Go to the documentation of this file.
1 /// \file falaise/snemo/geometry/calo_locator.h
2 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2011-05-05
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  * Calorimeter scintillator block locator for one module of the SuperNEMO detector
26  *
27  * History:
28  *
29  */
30 
31 #ifndef FALAISE_SNEMO_GEOMETRY_CALO_LOCATOR_H
32 #define FALAISE_SNEMO_GEOMETRY_CALO_LOCATOR_H 1
33 
34 // Standard library:
35 #include <string>
36 
37 // Third party:
38 // - Boost :
39 #include <boost/cstdint.hpp>
40 // - Bayeux/datatools:
41 #include <datatools/i_tree_dump.h>
42 // - Bayeux/geomtools:
43 #include <geomtools/i_locator.h>
44 
45 // This project:
47 
48 // Forward declaration:
49 namespace geomtools {
50 class mapping;
51 class id_mgr;
52 class manager;
53 class placement;
54 class i_shape_3d;
55 class box;
56 } // namespace geomtools
57 
58 namespace snemo {
59 
60 namespace geometry {
61 
62 /// \brief Fast locator class for SuperNEMO main calorimeter scintillator block volumes
64  public:
65  /// Block part identifier (for geometry config snemo::demonstrator >=2.0)
66  /*
67  * Front
68  * +---+ Back
69  * | +------------+
70  * | : .|..
71  * | : . | .....
72  * part=1->| : part=0 : | PMT :
73  * | : . | .....
74  * | : .|..
75  * | :------------+
76  * +---+
77  *
78  */
80  BLOCK_BACK_PART = 0, /// Back volume of scintillator (possibly extruded)
81  BLOCK_FRONT_PART = 1, /// Front volume of scintillator (entrance window)
83  };
84 
85  virtual bool is_initialized() const;
86 
87  /// Default constructor
88  calo_locator();
89 
90  /// Constructor
91  calo_locator(const ::geomtools::manager& mgr_, uint32_t module_number_,
92  uint32_t block_part_ = DEFAULT_BLOCK_PART);
93 
94  /// Destructor
95  virtual ~calo_locator();
96 
97  /// Initialization from parameters
98  virtual void initialize(const datatools::properties& config_);
99 
100  /// Reset
101  virtual void reset();
102 
103  /// Initialization
104  void initialize();
105 
106  /// Check if the calorimeter setup includes submodule with given side number
107  bool has_submodule(uint32_t side_) const;
108 
109  /// Check if a set of calorimeter block identifiers is valid
110  bool id_is_valid(uint32_t side_, uint32_t column_, uint32_t row_) const;
111 
112  // Interfaces from geomtools::i_locator :
113  virtual bool find_geom_id(const geomtools::vector_3d& world_position_, int type_,
114  geomtools::geom_id& gid_,
115  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
116 
117  bool find_block_geom_id(const geomtools::vector_3d& world_position_, geomtools::geom_id& gid_,
118  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
119 
120  protected:
121  /**
122  */
123  bool find_block_geom_id_(const geomtools::vector_3d& in_module_position_,
124  geomtools::geom_id& gid_,
125  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE);
126 
127  void _set_defaults_();
128 
129  public:
130  /**! @return the number of the module(>=0).
131  */
132  uint32_t get_module_number() const;
133 
134  /**! set the number of the module for this locator.
135  */
136  void set_module_number(uint32_t module_number_);
137 
138  /**! set the block part number for this locator.
139  */
140  void set_block_part(uint32_t block_part_);
141 
142  /**! return the block part number for this locator.
143  */
144  uint32_t get_block_part() const;
145 
146  /**! check if block is partitioned in the current setup.
147  */
148  bool is_block_partitioned() const;
149 
150  /**! @return the width of a calorimeter block.
151  */
152  double get_block_width() const;
153 
154  /**! @return the height of a calorimeter block.
155  */
156  double get_block_height() const;
157 
158  /**! @return the thickness of a block.
159  */
160  double get_block_thickness() const;
161 
162  /**! @return the number of sides on the calorimeter.
163  */
164  size_t get_number_of_sides() const;
165 
166  /**! @return the number of columns in one side of the calorimeter.
167  */
168  size_t get_number_of_columns(uint32_t side_) const;
169 
170  /**! @return the number of rows in one side of the calorimeter.
171  */
172  size_t get_number_of_rows(uint32_t side_) const;
173 
174  /**! @return the X-position of a wall for specific side (in module coordinate system).
175  */
176  double get_wall_x(uint32_t side_) const;
177 
178  /**! @return the X-position of the entrance window of a wall for specific side (in module
179  * coordinate system).
180  */
181  double get_wall_window_x(uint32_t side_) const;
182 
183  /**! @return the Y-position of a block for specific side and column (in module coordinate system).
184  */
185  double get_column_y(uint32_t side_, uint32_t column_) const;
186 
187  /**! @return the Z-position of a block for specific side and row (in module coordinate system).
188  */
189  double get_row_z(uint32_t side_, uint32_t row_) const;
190 
191  /**! Compute the position of a block
192  * for specific side, column and row (in module coordinate system).
193  */
194  void compute_block_position(uint32_t side_, uint32_t column_, uint32_t row_,
195  geomtools::vector_3d& module_position_) const;
196 
197  /**! Compute the position of the center of the entrance window of a block
198  * for specific side, column and row (in module coordinate system).
199  */
200  void compute_block_window_position(uint32_t side_, uint32_t column_, uint32_t row_,
201  geomtools::vector_3d& module_position_) const;
202 
203  /**! @return the position of a block for specific side, column and row (in module coordinate
204  * system).
205  */
206  geomtools::vector_3d get_block_position(uint32_t side_, uint32_t column_, uint32_t row_) const;
207 
208  /**! @return the position of the center of the entrance window of a block
209  * for specific side, column and row (in module coordinate system).
210  */
211  geomtools::vector_3d get_block_window_position(uint32_t side_, uint32_t column_,
212  uint32_t row_) const;
213 
214  /** Tranform a world coordinate system position to the corresponding module coordinate system
215  * position.
216  */
217  void transform_world_to_module(const geomtools::vector_3d& world_position_,
218  geomtools::vector_3d& module_position_) const;
219 
220  /** Tranform a module coordinate system position to the corresponding world coordinate system
221  * position.
222  */
223  void transform_module_to_world(const geomtools::vector_3d& module_position_,
224  geomtools::vector_3d& world_position_) const;
225 
226  /** Check if a world coordinate system position is in the module virtual volume (its bounding
227  * envelope).
228  */
229  bool is_world_position_in_module(const geomtools::vector_3d& world_position_,
230  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
231 
232  /** Check if a module coordinate system position is in the module virtual volume (its bounding
233  * envelope).
234  */
235  bool is_in_module(const geomtools::vector_3d& module_position_,
236  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
237 
238  /** Check if a module coordinate system position is in a specific block virtual volume (its
239  * bounding envelope).
240  */
241  bool is_in_block(const geomtools::vector_3d& module_position_, uint32_t side_, uint32_t column_,
242  uint32_t row_, double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
243 
244  /** Check if a world coordinate system position is in a specific block virtual volume (its
245  * bounding envelope).
246  */
247  bool is_world_position_in_block(const geomtools::vector_3d& world_position_, uint32_t side_,
248  uint32_t column_, uint32_t row_,
249  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
250 
251  /** Given a block at specific side, column and row, returns the number of neighbouring blocks.
252  */
253  size_t get_number_of_neighbours(uint32_t side_, uint32_t column_, uint32_t row_,
254  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
255 
256  /** Given a block with a specific geometry ID, returns the number of neighbouring blocks.
257  */
258  size_t get_number_of_neighbours(const geomtools::geom_id& gid_,
259  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
260 
261  /** Given a block at specific side, column and row, compute the array of geometry IDs for
262  * associated neighbouring blocks.
263  */
264  void get_neighbours_ids(uint32_t side_, uint32_t column_, uint32_t row_,
265  std::vector<geomtools::geom_id>& ids_,
266  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
267 
268  /** Given a block with a specific geometry IDs, compute the array of geometry IDs for associated
269  * neighbouring blocks.
270  */
271  void get_neighbours_ids(const geomtools::geom_id& gid_, std::vector<geomtools::geom_id>& ids_,
272  uint8_t mask_ = utils::NEIGHBOUR_FIRST) const;
273 
274  /** Given a block with a specific geometry IDs, compute its position in the module coordinate
275  * system.
276  */
277  void get_block_position(const geomtools::geom_id& gid_, geomtools::vector_3d& position_) const;
278 
279  /** Given a block with a specific side, column and row, compute its position in the module
280  * coordinate system.
281  */
282  void get_block_position(uint32_t side_, uint32_t column_, uint32_t row_,
283  geomtools::vector_3d& position_) const;
284 
285  int get_module_address_index() const;
286 
287  int get_side_address_index() const;
288 
289  int get_column_address_index() const;
290 
291  int get_row_address_index() const;
292 
293  int get_part_address_index() const;
294 
295  uint32_t extract_module(const geomtools::geom_id& gid_) const;
296 
297  uint32_t extract_side(const geomtools::geom_id& gid_) const;
298 
299  uint32_t extract_column(const geomtools::geom_id& gid_) const;
300 
301  uint32_t extract_row(const geomtools::geom_id& gid_) const;
302 
303  uint32_t extract_part(const geomtools::geom_id& gid_) const;
304 
305  bool is_calo_block(const geomtools::geom_id& gid_) const;
306 
307  bool is_calo_block_in_current_module(const geomtools::geom_id& gid_) const;
308 
309  /// Smart print
310  virtual void tree_dump(std::ostream& out_ = std::clog, const std::string& title_ = "",
311  const std::string& indent_ = "", bool inherit_ = false) const;
312 
313  /// Dump
314  void dump(std::ostream& out_) const;
315 
316  protected:
317  void _construct();
318 
319  /// Hack trace
320  void _hack_trace();
321 
322  private:
323  bool _initialized_;
324 
325  // Configuration parameters :
326  uint32_t _module_number_;
327  uint32_t _block_part_;
328 
329  // Running values :
330  uint32_t _module_type_;
331  uint32_t _calorimeter_submodule_type_;
332  uint32_t _block_type_;
333  uint32_t _wrapper_type_;
334  bool _block_partitioned_;
335 
336  const geomtools::mapping* _mapping_;
337  const geomtools::id_mgr* _id_manager_;
338 
339  const geomtools::geom_info* _module_ginfo_;
340  const geomtools::placement* _module_world_placement_;
341  const geomtools::box* _module_box_;
342  const geomtools::i_shape_3d* _block_shape_;
343  bool _composite_block_shape_;
344  const geomtools::box* _block_box_;
345  double _block_x_[2];
346  double _block_window_x_[2];
347  std::vector<double> _back_block_z_;
348  std::vector<double> _front_block_z_;
349  std::vector<double> _back_block_y_;
350  std::vector<double> _front_block_y_;
351 
352  double _block_width_;
353  double _block_height_;
354  double _block_thickness_;
355 
356  // Block GID addressing :
357  int _module_address_index_;
358  int _side_address_index_;
359  int _column_address_index_;
360  int _row_address_index_;
361  int _part_address_index_;
362 
363  // Submodules are present :
364  bool _submodules_[2];
365 };
366 
367 } // end of namespace geometry
368 
369 } // end of namespace snemo
370 
371 #endif // FALAISE_SNEMO_GEOMETRY_CALO_LOCATOR_H
372 
373 /*
374 ** Local Variables: --
375 ** mode: c++ --
376 ** c-file-style: "gnu" --
377 ** tab-width: 2 --
378 ** End: --
379 */
calo_locator()
Default constructor.
double get_row_z(uint32_t side_, uint32_t row_) const
bool find_block_geom_id_(const geomtools::vector_3d &in_module_position_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE)
uint32_t extract_part(const geomtools::geom_id &gid_) const
void compute_block_window_position(uint32_t side_, uint32_t column_, uint32_t row_, geomtools::vector_3d &module_position_) const
void set_module_number(uint32_t module_number_)
geomtools::vector_3d get_block_window_position(uint32_t side_, uint32_t column_, uint32_t row_) const
double get_column_y(uint32_t side_, uint32_t column_) const
void transform_world_to_module(const geomtools::vector_3d &world_position_, geomtools::vector_3d &module_position_) const
bool is_in_block(const geomtools::vector_3d &module_position_, uint32_t side_, uint32_t column_, uint32_t row_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
void initialize()
Initialization.
Front volume of scintillator (entrance window)
Definition: calo_locator.h:82
bool has_submodule(uint32_t side_) const
Check if the calorimeter setup includes submodule with given side number.
double get_wall_window_x(uint32_t side_) const
bool id_is_valid(uint32_t side_, uint32_t column_, uint32_t row_) const
Check if a set of calorimeter block identifiers is valid.
block_part_type
Block part identifier (for geometry config snemo::demonstrator >=2.0)
Definition: calo_locator.h:79
void transform_module_to_world(const geomtools::vector_3d &module_position_, geomtools::vector_3d &world_position_) const
virtual ~calo_locator()
Destructor.
geomtools::vector_3d get_block_position(uint32_t side_, uint32_t column_, uint32_t row_) const
uint32_t get_module_number() const
size_t get_number_of_rows(uint32_t side_) const
uint32_t extract_row(const geomtools::geom_id &gid_) const
size_t get_number_of_sides() const
D : nearest diagonal.
Definition: utils.h:91
void dump(std::ostream &out_) const
Dump.
virtual bool find_geom_id(const geomtools::vector_3d &world_position_, int type_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
virtual void reset()
Reset.
bool find_block_geom_id(const geomtools::vector_3d &world_position_, geomtools::geom_id &gid_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
Definition: calo_tapered_scin_box_model.h:54
uint32_t get_block_part() const
double get_block_thickness() const
uint32_t extract_column(const geomtools::geom_id &gid_) const
uint32_t extract_side(const geomtools::geom_id &gid_) const
CLHEP::Hep3Vector vector_3d
virtual bool is_initialized() const
void _hack_trace()
Hack trace.
bool is_world_position_in_module(const geomtools::vector_3d &world_position_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
bool is_calo_block_in_current_module(const geomtools::geom_id &gid_) const
void compute_block_position(uint32_t side_, uint32_t column_, uint32_t row_, geomtools::vector_3d &module_position_) const
Back volume of scintillator (possibly extruded)
Definition: calo_locator.h:81
size_t get_number_of_neighbours(uint32_t side_, uint32_t column_, uint32_t row_, uint8_t mask_=utils::NEIGHBOUR_FIRST) const
double get_wall_x(uint32_t side_) const
bool is_calo_block(const geomtools::geom_id &gid_) const
bool is_world_position_in_block(const geomtools::vector_3d &world_position_, uint32_t side_, uint32_t column_, uint32_t row_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
uint32_t extract_module(const geomtools::geom_id &gid_) const
size_t get_number_of_columns(uint32_t side_) const
void get_neighbours_ids(uint32_t side_, uint32_t column_, uint32_t row_, std::vector< geomtools::geom_id > &ids_, uint8_t mask_=utils::NEIGHBOUR_FIRST) const
Fast locator class for SuperNEMO main calorimeter scintillator block volumes.
Definition: calo_locator.h:63
void set_block_part(uint32_t block_part_)
bool is_in_module(const geomtools::vector_3d &module_position_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const