PandaRoot
PndDiscSensorGrid.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 //-------------------------------------------------------------------------
14 // Author: Oliver Merle (Oliver.Merle@exp2.physik.uni-giessen.de)
15 // Changes: Mustafa Schmidt (Mustafa.A.Schmidt@physik.uni-giessen.de)
16 // Date: 30.11.2015
17 // Description: Definition of sensor grid
18 //-------------------------------------------------------------------------
19 
20 #ifndef SENSOR_GRID_HH_
21 #define SENSOR_GRID_HH_
22 
23 #include <vector>
24 //#include <tr1/memory>
25 
26 namespace SensorGrid {
27 
28 // ======================
29 // = Next steps: =
30 // ======================
31 //
32 // - add similar counting like pixel number, but for dead time entity ... 0%
33 // - add pixel iteration (return number and position) ... to test
34 //
35 
36 // Compute number of pixels in
37 // a Grid and number them as:
38 // pixel_number_offset + ix + iy*cells_per_row
39 
40 struct PixelInfo {
42  int grid_id;
45 };
46 
48 
54  public:
55  SensorGridBase() : pixel_number_offset(0), user_row_offset(0), user_col_offset(0), number_of_pixels(0), locked(false) {}
56  virtual ~SensorGridBase() {}
57  void SetUserColumnOffset(int ofs) { user_col_offset = ofs; }
58  void SetUserRowOffset(int ofs) { user_row_offset = ofs; }
59  void LockGrid(bool lock); // Function for the user to lock the root grid - will trigger enumeration.
60  bool IsLocked() { return locked; }
61 
62  int GetNumberOfPixels() { return number_of_pixels; }
63  virtual bool PositionToPixel(const double &x, const double &y, PixelInfo &pixel_info) const = 0;
64  virtual bool PixelToPosition(PixelInfo &pixel_info, double &x, double &y) const = 0;
65 
66  virtual bool NextPixel(double &x, double &y, PixelInfo &pixel_number) const; // Pixel enumeration
67 
68  protected:
69  virtual void EnumerateGrids(int &id, int &pixel_offset) = 0; // used to enumerate grids and pixel offsets.
70  virtual void LockChilds(bool) {} // used to forward lock to children // lock//[R.K.03/2017] unused variable(s)
71  void SetPixelNumberOffset(int offset) { pixel_number_offset = offset; }
72 
73  // Proxys to method in siblings through base class:
74  void EnumerateGridsProxy(SensorGridBase *b, int &grid_id, int &pixel_number) { b->EnumerateGrids(grid_id, pixel_number); }
75  void LockChildsProxy(SensorGridBase *b, bool lock) { b->LockChilds(lock); }
76 
77  protected:
83  bool locked;
84 };
85 
87 class BasicGrid : public SensorGridBase {
88  public:
89  BasicGrid();
90  BasicGrid(const double &x_min, const double &x_width, const double &x_pitch, int n_x, const double &y_min, const double &y_width, const double &y_pitch, int n_y);
91  virtual ~BasicGrid();
92 
93  void SetXDivision(const double &x_min, const double &x_width, const double &x_pitch, int n_x);
94  void SetYDivision(const double &y_min, const double &y_width, const double &y_pitch, int n_y);
95 
96  virtual bool PositionToPixel(const double &x, const double &y, PixelInfo &pixel_info) const;
97  virtual bool PixelToPosition(PixelInfo &pixel_info, double &x, double &y) const;
98 
99  virtual void EnumerateGrids(int &id, int &pixel_offset);
100 
101  protected:
102  double x_min, x_width, x_pitch, x_width_over_two_pitch;
103  double y_min, y_width, y_pitch, y_width_over_two_pitch;
104  int n_x, n_y;
105  double x_max, y_max;
106 };
107 
110  public:
111  MultipleGrids();
112  virtual ~MultipleGrids();
113 
114  void AddGrid(SensorGridBase *grid); // Policy: this instance will take over the ownership of grid. Do not use the grid in userspace.
115 
116  virtual void EnumerateGrids(int &id, int &pixel_offset);
117 
118  virtual bool PositionToPixel(const double &x, const double &y, PixelInfo &pixel_info) const;
119  virtual bool PixelToPosition(PixelInfo &pixel_number, double &x, double &y) const;
120 
121  protected:
122  virtual void LockChilds(bool lock);
123 
124  std::vector<SensorGridBase *> grids;
125 };
126 
127 } // namespace SensorGrid
128 #endif
bool locked
The total number of pixels in this grid (or its childs)
int user_row_offset
The pixel number of the first pixel in this grid (or its childs)
Common base class for sensor grids.
std::vector< SensorGridBase * > grids
int number_of_pixels
user prowided offset to add to column on grid value in PixelInfo
A generic regular pixel grid with dead space between cells.
void EnumerateGridsProxy(SensorGridBase *b, int &grid_id, int &pixel_number)
A grid to group other grids or to create nested grids.
virtual void LockChilds(bool)
void SetPixelNumberOffset(int offset)
int user_col_offset
user prowided offset to add to row on grid value in PixelInfo
virtual void EnumerateGrids(int &id, int &pixel_offset)=0
void LockChildsProxy(SensorGridBase *b, bool lock)