SegmentationStripYAlg.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 = "StripY";
24  _description = "Cartesian segmentation in the local XY-plane with strip along the Y direction";
25 
26  std::cout << "######### gar::geo::seg::SegmentationStripYAlg() " << 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 = "StripY";
37  _description = "Cartesian segmentation in the local XY-plane with strip along the Y direction";
38 
39  std::cout << "######### gar::geo::seg::SegmentationStripYAlg() " << std::endl ;
40 
41  this->reconfigure(pset);
42  }
43 
44  //----------------------------------------------------------------------------
46  {
47  }
48 
49  //----------------------------------------------------------------------------
51  {
52  _stripSizeY = pset.get<double>("strip_size_y");
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> SegmentationStripYAlg::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  //Segmentation in Y
84  int nCellsX = 1;
85  // int nCellsY = int(_layer_dim_Y / _stripSizeY);
86 
87  cellPosition[0] = ( cellIndexX + 0.5 ) * (_layer_dim_X / nCellsX ) - (_layer_dim_X / 2.);
88  cellPosition[1] = ( cellIndexY + 0.5 ) * _stripSizeY;
89  cellPosition[2] = 0.;
90 
91  return cellPosition;
92  }
93 
94  //----------------------------------------------------------------------------
95  /// determine the cell ID based on the position
96  gar::raw::CellID_t SegmentationStripYAlg::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
97  {
98  gar::raw::CellID_t cID = 0;
99 
100  _decoder->set(cID, "system", det_id);
101  _decoder->set(cID, "module", module);
102  _decoder->set(cID, "stave", stave);
103  _decoder->set(cID, "layer", layer);
104  _decoder->set(cID, "slice", slice);
105 
106  double localX = localPosition[0];
107  double localY = localPosition[1];
108 
109  //Segmentation in Y
110  int nCellsX = 1;
111  int nCellsY = int(_layer_dim_Y / _stripSizeY);
112 
113  int _cellIndexX = int ( localX / ( _layer_dim_X / nCellsX ) );
114  int _cellIndexY = int ( localY / ( _layer_dim_Y / nCellsY ) );
115 
116  _decoder->set(cID, _xId, _cellIndexX);
117  _decoder->set(cID, _yId, _cellIndexY);
118 
119  return cID;
120  }
121 
122  //----------------------------------------------------------------------------
124  {
125  std::cout << "cell encoding: " << _encoding << std::endl;
126  std::cout << "identifier_x: " << _xId << std::endl;
127  std::cout << "identifier_y: " << _yId << std::endl;
128  std::cout << "strip_size_y: " << _stripSizeY << " cm" << std::endl;
129 
130  std::cout << "identifier_layer: " << _layerId << std::endl;
131  std::cout << "identifier_slice: " << _sliceId << std::endl;
132  }
133 
134  //----------------------------------------------------------------------------
136  {
137  return false;
138  }
139 
140  //----------------------------------------------------------------------------
142  {
143  return true;
144  }
145 
146  //----------------------------------------------------------------------------
147  double SegmentationStripYAlg::getStripLength(const gar::geo::GeometryCore& , const std::array<double, 3> & , const gar::raw::CellID_t& ) const
148  {
149  return _layer_dim_X;
150  }
151 
152  //----------------------------------------------------------------------------
153  std::pair<TVector3, TVector3> SegmentationStripYAlg::getStripEnds(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& ) const
154  {
155  TVector3 stripEnd1(0., 0., 0.);
156  TVector3 stripEnd2(0., 0., 0.);
157 
158  stripEnd1.SetX(-_layer_dim_X/2.);
159  stripEnd2.SetX(_layer_dim_X/2.);
160  stripEnd1.SetY(local[1]);
161  stripEnd2.SetY(local[1]);
162  stripEnd1.SetZ(local[2]);
163  stripEnd2.SetZ(local[2]);
164 
165  return std::make_pair(stripEnd1, stripEnd2);
166  }
167 
168  //----------------------------------------------------------------------------
169  std::pair<float, float> SegmentationStripYAlg::CalculateLightPropagation(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& ) const
170  {
171  float c = (CLHEP::c_light * CLHEP::mm / CLHEP::ns) / CLHEP::cm; // in cm/ns
172  //time1 is left SiPM
173  float time1 = 0.;
174  //time2 is right SiPM
175  float time2 = 0.;
176 
177  time1 = ( _layer_dim_X / 2 + local[0] ) / c;
178  time2 = ( _layer_dim_X / 2 - local[0] ) / c;
179 
180  return std::make_pair(time1, time2);
181  }
182 
183  //----------------------------------------------------------------------------
184  std::array<double, 3> SegmentationStripYAlg::ReconstructStripHitPosition(const gar::geo::GeometryCore& geo, const std::array<double, 3> &local, const float &xlocal, const gar::raw::CellID_t& cID) const
185  {
186  float pos = xlocal;
187  //Need to check if the local position is bigger than the strip length!
188  // bool isBarrel = this->isBarrel(cID);
189  float stripLength = this->getStripLength(geo, local, cID);
190 
191  if( std::abs(pos) > stripLength / 2. ) pos = (pos > 0) ? stripLength / 2. : -stripLength / 2.;
192 
193  std::array<double, 3> newlocal = {pos, local[1], local[2]};
194  return newlocal;
195  }
196 
197  }//seg
198  } // geo
199 } //gar
static constexpr double cm
Definition: Units.h:68
const BitFieldCoder * _decoder
bool isBarrel(const gar::raw::CellID_t &cID) const override
double _frac
fraction of tiles to remove at the edge
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
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
double _layer_dim_X
layer dimension in X
SegmentationStripYAlg(fhicl::ParameterSet const &pset)
Default constructor used by derived classes passing the encoding string.
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
double _layer_dim_Y
layer dimension in Y
T abs(T value)
std::array< double, 3 > GetPosition(const gar::geo::GeometryCore &geo, 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
void Initialize(const gar::geo::GeometryCore &geo) override
double getStripLength(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const gar::raw::CellID_t &cID) const override
long long int CellID_t
Definition: CaloRawDigit.h:24
unsigned int _nLayers
number of layers
double _stripSizeY
the strip size in Y
General GArSoft Utilities.
long64 get(long64 bitfield, size_t index) const
std::string _sliceId
the field name used for slice
bool isTile(const gar::raw::CellID_t &cID) const override
std::string _yId
the field name used for Y
void reconfigure(fhicl::ParameterSet const &pset) override
std::pair< TVector3, TVector3 > getStripEnds(const gar::geo::GeometryCore &geo, const std::array< double, 3 > &local, const gar::raw::CellID_t &cID) const override
static constexpr double mm
Definition: Units.h:65
void decode(std::any const &a, Hep2Vector &result)
Definition: CLHEP_ps.h:12
std::string _encoding
the encoding string
LArSoft geometry interface.
Definition: ChannelGeo.h:16
QAsciiDict< Entry > ns
std::string _xId
the field name used for X
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
QTextStream & endl(QTextStream &s)
std::string _layerId
the field name used for layer