SegmentationGridXYAlg.cxx
Go to the documentation of this file.
2 
4 
5 #include <algorithm>
6 #include <sstream>
7 #include <iostream>
8 #include <cmath>
9 
10 namespace gar {
11  namespace geo {
12  namespace seg {
13 
14  //----------------------------------------------------------------------------
15  /// Default constructor used by derived classes passing the encoding string
17  : SegmentationAlg(pset)
18  {
19  _type = "GridXY";
20  _description = "Cartesian segmentation in the local XY-plane";
21 
22  std::cout << " ######### gar::geo::seg::SegmentationGridXYAlg() " << std::endl ;
23 
24  this->reconfigure(pset);
25  }
26 
27  //----------------------------------------------------------------------------
28  /// Default constructor used by derived classes passing an existing decoder
30  : SegmentationAlg(decode, pset)
31  {
32  _type = "GridXY";
33  _description = "Cartesian segmentation in the local XY-plane";
34 
35  std::cout << " ######### gar::geo::seg::SegmentationGridXYAlg() " << std::endl ;
36 
37  this->reconfigure(pset);
38  }
39 
40  //----------------------------------------------------------------------------
42  {
43  }
44 
45  //----------------------------------------------------------------------------
47  {
48  _xId = pset.get<std::string>("identifier_x");
49  _yId = pset.get<std::string>("identifier_y");
50  _encoding = pset.get<std::string>("cellEncoding");
51 
52  _gridSizeX = pset.get<double>("grid_size_x");
53  _gridSizeY = pset.get<double>("grid_size_y");
54 
55  _offsetX = pset.get<double>("offset_x");
56  _offsetY = pset.get<double>("offset_y");
57 
58  _nLayers = pset.get<unsigned int>("nlayers");
59 
61 
62  return;
63  }
64 
65  //----------------------------------------------------------------------------
67  {
68 
69  }
70 
71  //----------------------------------------------------------------------------
72  std::array<double, 3> SegmentationGridXYAlg::GetPosition(const gar::geo::GeometryCore& , const gar::raw::CellID_t& cID) const
73  {
74  std::array<double, 3> cellPosition;
75  cellPosition[0] = binToPosition(_decoder->get(cID, _xId), _gridSizeX, _offsetX);
76  cellPosition[1] = binToPosition(_decoder->get(cID, _yId), _gridSizeY, _offsetY);
77  cellPosition[2] = 0.;
78 
79  return cellPosition;
80  }
81 
82  //----------------------------------------------------------------------------
83  /// determine the cell ID based on the position
84  gar::raw::CellID_t SegmentationGridXYAlg::GetCellID(const gar::geo::GeometryCore& , const unsigned int& det_id, const unsigned int& stave, const unsigned int& module, const unsigned int& layer, const unsigned int& slice, const std::array<double, 3>& localPosition) const
85  {
86  gar::raw::CellID_t cID = 0;
87 
88  _decoder->set(cID, "system", det_id);
89  _decoder->set(cID, "module", module);
90  _decoder->set(cID, "stave", stave);
91  _decoder->set(cID, "layer", layer);
92  _decoder->set(cID, "slice", slice);
93 
94  _decoder->set(cID, _xId, positionToBin(localPosition[0], _gridSizeX, _offsetX));
95  _decoder->set(cID, _yId, positionToBin(localPosition[1], _gridSizeY, _offsetY));
96 
97  return cID;
98  }
99 
100  //----------------------------------------------------------------------------
102  {
103  bool isBarrel = true;
104 
105  int det_id = _decoder->get(cID, "system");
106  int module = _decoder->get(cID, "module");
107  if( det_id == 2 && (module == 0 || module == 6) ) isBarrel = false;
108 
109  return isBarrel;
110  }
111 
112  //----------------------------------------------------------------------------
114  {
115  std::cout << "cell encoding: " << _encoding << std::endl;
116  std::cout << "identifier_x: " << _xId << std::endl;
117  std::cout << "identifier_y: " << _yId << std::endl;
118  std::cout << "grid_size_x: " << _gridSizeX << " cm" << std::endl;
119  std::cout << "grid_size_y: " << _gridSizeY << " cm" << std::endl;
120  std::cout << "offset_x: " << _offsetX << " cm" << std::endl;
121  std::cout << "offset_y: " << _offsetY << " cm" << std::endl;
122  }
123 
124  }//seg
125  } //geo
126 } //gar
const BitFieldCoder * _decoder
double _offsetY
the coordinate offset in Y
void set(long64 &bitfield, size_t index, ulong64 value) const
std::string string
Definition: nybbler.cc:12
std::string _encoding
the encoding string
void reconfigure(fhicl::ParameterSet const &pset) override
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
std::string _xId
the field name used for X
static int positionToBin(double position, double cellSize, double offset=0)
double _offsetX
the coordinate offset in X
static double binToPosition(gar::raw::CellID_t bin, double cellSize, double offset=0)
gar::raw::CellID_t GetCellID(const gar::geo::GeometryCore &geo, const unsigned int &det_id, const unsigned int &stave, const unsigned int &module, const unsigned int &layer, const unsigned int &slice, const std::array< double, 3 > &localPosition) const override
determine the cell ID based on the position
std::array< double, 3 > GetPosition(const gar::geo::GeometryCore &geo, const gar::raw::CellID_t &cID) const override
void Initialize(const gar::geo::GeometryCore &geo) override
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
T get(std::string const &key) const
Definition: ParameterSet.h:271
long long int CellID_t
Definition: CaloRawDigit.h:24
General GArSoft Utilities.
long64 get(long64 bitfield, size_t index) const
void decode(std::any const &a, Hep2Vector &result)
Definition: CLHEP_ps.h:12
std::string _yId
the field name used for Y
SegmentationGridXYAlg(fhicl::ParameterSet const &pset)
Default constructor used by derived classes passing the encoding string.
unsigned int _nLayers
number of layers
LArSoft geometry interface.
Definition: ChannelGeo.h:16
QTextStream & endl(QTextStream &s)
bool isBarrel(const gar::raw::CellID_t &cID) const override