SegmentationStripXAlg.cxx
Go to the documentation of this file.
2 
4 
6 
7 #include "Geometry/GeometryCore.h"
8 
9 #include <algorithm>
10 #include <sstream>
11 #include <iostream>
12 #include <cmath>
13 
14 namespace gar {
15  namespace geo {
16  namespace seg {
17 
18  //----------------------------------------------------------------------------
19  /// Default constructor used by derived classes passing the encoding string
21  : SegmentationAlg(pset)
22  {
23  _type = "StripX";
24  _description = "Cartesian segmentation in the local XY-plane with strip along the Y direction";
25 
26  std::cout << "######### gar::geo::seg::SegmentationStripXAlg() " << std::endl ;
27 
28  this->reconfigure(pset);
29  }
30 
31  //----------------------------------------------------------------------------
32  /// Default constructor used by derived classes passing an existing decoder
34  : SegmentationAlg(decode, pset)
35  {
36  _type = "StripX";
37  _description = "Cartesian segmentation in the local XY-plane with strip along the Y direction";
38 
39  std::cout << "######### gar::geo::seg::SegmentationStripXAlg() " << std::endl ;
40 
41  this->reconfigure(pset);
42  }
43 
44  //----------------------------------------------------------------------------
46  {
47  }
48 
49  //----------------------------------------------------------------------------
51  {
52  _stripSizeX = pset.get<double>("strip_size_x");
53  _encoding = pset.get<std::string>("cellEncoding");
54 
55  _xId = pset.get<std::string>("identifier_x");
56  _yId = pset.get<std::string>("identifier_y");
57  _layerId = pset.get<std::string>("identifier_layer");
58  _sliceId = pset.get<std::string>("identifier_slice");
59 
60  _nLayers = pset.get<unsigned int>("nlayers");
61 
62  _frac = 1./3.;
63 
64  this->PrintParameters();
65 
66  return;
67  }
68 
69  //----------------------------------------------------------------------------
71  {
72 
73  }
74 
75  //----------------------------------------------------------------------------
76  std::array<double, 3> SegmentationStripXAlg::GetPosition(const gar::geo::GeometryCore& , const gar::raw::CellID_t& cID) const
77  {
78  std::array<double, 3> cellPosition;
79 
80  int cellIndexX = _decoder->get(cID,_xId);
81  int cellIndexY = _decoder->get(cID,_yId);
82 
83  int nCellsY = 1;
84 
85  cellPosition[0] = ( cellIndexX + 0.5 ) * _stripSizeX;
86  cellPosition[1] = ( cellIndexY + 0.5 ) * (_layer_dim_Y / nCellsY ) - (_layer_dim_Y / 2.);
87  cellPosition[2] = 0.;
88 
89  return cellPosition;
90  }
91 
92  //----------------------------------------------------------------------------
93  /// determine the cell ID based on the position
94  gar::raw::CellID_t SegmentationStripXAlg::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
95  {
96  gar::raw::CellID_t cID = 0;
97 
98  _decoder->set(cID, "system", det_id);
99  _decoder->set(cID, "module", module);
100  _decoder->set(cID, "stave", stave);
101  _decoder->set(cID, "layer", layer);
102  _decoder->set(cID, "slice", slice);
103 
104  double localX = localPosition[0];
105  double localY = localPosition[1];
106 
107  //Segmentation in X
108  int nCellsX = int(_layer_dim_X / _stripSizeX);
109  int nCellsY = 1;
110 
111  int _cellIndexX = int ( localX / ( _layer_dim_X / nCellsX ) );
112  int _cellIndexY = int ( localY / ( _layer_dim_Y / nCellsY ) );
113 
114  _decoder->set(cID, _xId, _cellIndexX);
115  _decoder->set(cID, _yId, _cellIndexY);
116 
117  return cID;
118  }
119 
120  //----------------------------------------------------------------------------
122  {
123  std::cout << "cell encoding: " << _encoding << std::endl;
124  std::cout << "identifier_x: " << _xId << std::endl;
125  std::cout << "identifier_y: " << _yId << std::endl;
126  std::cout << "strip_size_x: " << _stripSizeX << " cm" << std::endl;
127 
128  std::cout << "identifier_layer: " << _layerId << std::endl;
129  std::cout << "identifier_slice: " << _sliceId << std::endl;
130  }
131 
132  //----------------------------------------------------------------------------
134  {
135  return false;
136  }
137 
138  //----------------------------------------------------------------------------
140  {
141  return true;
142  }
143 
144  //----------------------------------------------------------------------------
145  double SegmentationStripXAlg::getStripLength(const gar::geo::GeometryCore& , const std::array<double, 3> & , const gar::raw::CellID_t& ) const
146  {
147  return _layer_dim_Y;
148  }
149 
150  //----------------------------------------------------------------------------
151  std::pair<TVector3, TVector3> SegmentationStripXAlg::getStripEnds(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& ) const
152  {
153  TVector3 stripEnd1(0., 0., 0.);
154  TVector3 stripEnd2(0., 0., 0.);
155 
156  stripEnd1.SetY(-_layer_dim_Y/2.);
157  stripEnd2.SetY(_layer_dim_Y/2.);
158  stripEnd1.SetX(local[0]);
159  stripEnd2.SetX(local[0]);
160  stripEnd1.SetZ(local[2]);
161  stripEnd2.SetZ(local[2]);
162 
163  return std::make_pair(stripEnd1, stripEnd2);
164  }
165 
166  //----------------------------------------------------------------------------
167  std::pair<float, float> SegmentationStripXAlg::CalculateLightPropagation(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& ) const
168  {
169  float c = (CLHEP::c_light * CLHEP::mm / CLHEP::ns) / CLHEP::cm; // in cm/ns
170  //time1 is left SiPM
171  float time1 = 0.;
172  //time2 is right SiPM
173  float time2 = 0.;
174 
175  time1 = ( _layer_dim_Y / 2 + local[1] ) / c;
176  time2 = ( _layer_dim_Y / 2 - local[1] ) / c;
177 
178  return std::make_pair(time1, time2);
179  }
180 
181  //----------------------------------------------------------------------------
182  std::array<double, 3> SegmentationStripXAlg::ReconstructStripHitPosition(const gar::geo::GeometryCore& geo, const std::array<double, 3> &local, const float &xlocal, const gar::raw::CellID_t& cID) const
183  {
184  float pos = xlocal;
185  //Need to check if the local position is bigger than the strip length!
186  // bool isBarrel = this->isBarrel(cID);
187  float stripLength = this->getStripLength(geo, local, cID);
188 
189  if( std::abs(pos) > stripLength / 2. ) pos = (pos > 0) ? stripLength / 2. : -stripLength / 2.;
190 
191  std::array<double, 3> newlocal = {local[0], pos, local[2]};
192  return newlocal;
193  }
194 
195  }//seg
196  } // geo
197 } //gar
static constexpr double cm
Definition: Units.h:68
const BitFieldCoder * _decoder
bool isTile(const gar::raw::CellID_t &cID) const override
std::array< double, 3 > GetPosition(const gar::geo::GeometryCore &geo, const gar::raw::CellID_t &cID) const override
std::pair< float, float > CalculateLightPropagation(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const gar::raw::CellID_t &cID) const override
void set(long64 &bitfield, size_t index, ulong64 value) const
std::string string
Definition: nybbler.cc:12
double _stripSizeX
the strip size in X
void reconfigure(fhicl::ParameterSet const &pset) override
double _layer_dim_X
layer dimension in X
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
double _layer_dim_Y
layer dimension in Y
std::string _layerId
the field name used for layer
std::string _xId
the field name used for X
std::string _yId
the field name used for Y
T abs(T value)
double getStripLength(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const gar::raw::CellID_t &cID) const 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
std::array< double, 3 > ReconstructStripHitPosition(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const float &xlocal, const gar::raw::CellID_t &cID) const override
std::string _sliceId
the field name used for slice
long long int CellID_t
Definition: CaloRawDigit.h:24
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
double _frac
fraction of tiles to remove at the edge
General GArSoft Utilities.
long64 get(long64 bitfield, size_t index) const
static constexpr double mm
Definition: Units.h:65
unsigned int _nLayers
number of layers
std::pair< TVector3, TVector3 > getStripEnds(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const gar::raw::CellID_t &cID) const override
void decode(std::any const &a, Hep2Vector &result)
Definition: CLHEP_ps.h:12
std::string _encoding
the encoding string
SegmentationStripXAlg(fhicl::ParameterSet const &pset)
Default constructor used by derived classes passing the encoding string.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
QAsciiDict< Entry > ns
QTextStream & endl(QTextStream &s)
void Initialize(const gar::geo::GeometryCore &geo) override
bool isBarrel(const gar::raw::CellID_t &cID) const override