SegmentationMuIDAlg.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 = "MuID";
24  _description = "Muon system segmentation with cross-strips depending on the slice";
25 
26  std::cout << "######### gar::geo::seg::SegmentationMuIDAlg() " << 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 = "MuID";
37  _description = "Muon system segmentation with cross-strips depending on the slice";
38 
39  std::cout << "######### gar::geo::seg::SegmentationMuIDAlg() " << std::endl ;
40 
41  this->reconfigure(pset);
42  }
43 
44  //----------------------------------------------------------------------------
46  {
47  }
48 
49  //----------------------------------------------------------------------------
51  {
52  _stripSizeY = pset.get<double>("strip_size_y");
54  _encoding = pset.get<std::string>("cellEncoding");
55 
56  _xId = pset.get<std::string>("identifier_x");
57  _yId = pset.get<std::string>("identifier_y");
58  _layerId = pset.get<std::string>("identifier_layer");
59  _sliceId = pset.get<std::string>("identifier_slice");
60 
61  _nLayers = pset.get<unsigned int>("nlayers");
62 
63  _frac = 1./3.;
64 
65  this->PrintParameters();
66 
67  return;
68  }
69 
70  //----------------------------------------------------------------------------
72  {
73 
74  }
75 
76  //----------------------------------------------------------------------------
77  std::array<double, 3> SegmentationMuIDAlg::GetPosition(const gar::geo::GeometryCore& , const gar::raw::CellID_t& cID) const
78  {
79  std::array<double, 3> cellPosition;
80 
81  int cellIndexX = _decoder->get(cID, _xId);
82  int cellIndexY = _decoder->get(cID, _yId);
83  int layer = _decoder->get(cID, "layer");
84 
85  if (layer % 2 == 0)
86  {
87  //Segmentation in Y
88  int nCellsX = 1;
89  // int nCellsY = int(_layer_dim_Y / _stripSizeY);
90 
91  cellPosition[0] = ( cellIndexX + 0.5 ) * (_layer_dim_X / nCellsX ) - (_layer_dim_X / 2.);
92  cellPosition[1] = ( cellIndexY + 0.5 ) * _stripSizeY;
93  cellPosition[2] = 0.;
94  }
95 
96  if(layer % 2 != 0) {
97  //Segmentation in X
98  int nCellsY = 1;
99  // int nCellsX = int(_layer_dim_Y / _stripSizeY);
100 
101  cellPosition[0] = ( cellIndexX + 0.5 ) * _stripSizeX;
102  cellPosition[1] = ( cellIndexY + 0.5 ) * (_layer_dim_Y / nCellsY ) - (_layer_dim_Y / 2.);
103  cellPosition[2] = 0.;
104  }
105 
106  return cellPosition;
107  }
108 
109  //----------------------------------------------------------------------------
110  /// determine the cell ID based on the position
111  gar::raw::CellID_t SegmentationMuIDAlg::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
112  {
113  gar::raw::CellID_t cID = 0;
114 
115  _decoder->set(cID, "system", det_id);
116  _decoder->set(cID, "module", module);
117  _decoder->set(cID, "stave", stave);
118  _decoder->set(cID, "layer", layer);
119  _decoder->set(cID, "slice", slice);
120 
121  double localX = localPosition[0];
122  double localY = localPosition[1];
123 
124  //Segmentation depending on the slice in the layer (1 layer with Sc/Fe/Sc/Fe/Sc)
125  //Slices 1/3/5 active
126  int nCellsX = 1;
127  int nCellsY = 1;
128 
129  if(layer % 2 == 0) {
130  //Segmentation in Y
131  nCellsX = 1;
132  nCellsY = int(_layer_dim_Y / _stripSizeY);
133 
134  }
135 
136  if(layer % 2 != 0) {
137  //Segmentation in X
138  nCellsY = 1;
139  nCellsX = int(_layer_dim_X / _stripSizeX);
140  }
141 
142  int _cellIndexX = int ( localX / ( _layer_dim_X / nCellsX ) );
143  int _cellIndexY = int ( localY / ( _layer_dim_Y / nCellsY ) );
144 
145  _decoder->set(cID, _xId, _cellIndexX);
146  _decoder->set(cID, _yId, _cellIndexY);
147 
148  return cID;
149  }
150 
151  //----------------------------------------------------------------------------
153  {
154  std::cout << "cell encoding: " << _encoding << std::endl;
155  std::cout << "identifier_x: " << _xId << std::endl;
156  std::cout << "identifier_y: " << _yId << std::endl;
157  std::cout << "strip_size_x: " << _stripSizeX << " cm" << std::endl;
158  std::cout << "strip_size_y: " << _stripSizeY << " cm" << std::endl;
159 
160  std::cout << "identifier_layer: " << _layerId << std::endl;
161  std::cout << "identifier_slice: " << _sliceId << std::endl;
162  std::cout << "nLayers: " << _nLayers << std::endl;
163  }
164 
165  //----------------------------------------------------------------------------
167  {
168  return false;
169  }
170 
171  //----------------------------------------------------------------------------
173  {
174  return true;
175  }
176 
177  //----------------------------------------------------------------------------
178  double SegmentationMuIDAlg::getStripLength(const gar::geo::GeometryCore& , const std::array<double, 3> & , const gar::raw::CellID_t& cID) const
179  {
180  double stripLength = 0.;
181  int layer = _decoder->get(cID, "layer");
182 
183  if(layer == 1 || layer == 3) stripLength = _layer_dim_X;
184  if(layer == 2) stripLength = _layer_dim_Y;
185 
186  return stripLength;
187  }
188 
189  //----------------------------------------------------------------------------
190  std::pair<TVector3, TVector3> SegmentationMuIDAlg::getStripEnds(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& cID) const
191  {
192  int layer = _decoder->get(cID, "layer");
193 
194  TVector3 stripEnd1(0., 0., 0.);
195  TVector3 stripEnd2(0., 0., 0.);
196 
197  if(layer == 1 || layer == 3) {
198  stripEnd1.SetX(-_layer_dim_X/2.);
199  stripEnd2.SetX(_layer_dim_X/2.);
200  stripEnd1.SetY(local[1]);
201  stripEnd2.SetY(local[1]);
202  stripEnd1.SetZ(local[2]);
203  stripEnd2.SetZ(local[2]);
204  }
205 
206  if(layer == 2) {
207  stripEnd1.SetY(-_layer_dim_Y/2.);
208  stripEnd2.SetY(_layer_dim_Y/2.);
209  stripEnd1.SetX(local[0]);
210  stripEnd2.SetX(local[0]);
211  stripEnd1.SetZ(local[2]);
212  stripEnd2.SetZ(local[2]);
213  }
214 
215 
216  return std::make_pair(stripEnd1, stripEnd2);
217  }
218 
219  //----------------------------------------------------------------------------
220  std::pair<float, float> SegmentationMuIDAlg::CalculateLightPropagation(const gar::geo::GeometryCore& , const std::array<double, 3> &local, const gar::raw::CellID_t& cID) const
221  {
222  float c = (CLHEP::c_light * CLHEP::mm / CLHEP::ns) / CLHEP::cm; // in cm/ns
223  //time1 is left SiPM
224  float time1 = 0.;
225  //time2 is right SiPM
226  float time2 = 0.;
227 
228  int layer = _decoder->get(cID, "layer");
229 
230  if(layer == 1 || layer == 3) {
231  time1 = ( _layer_dim_X / 2 + local[0] ) / c;
232  time2 = ( _layer_dim_X / 2 - local[0] ) / c;
233  }
234 
235  if(layer == 2) {
236  time1 = ( _layer_dim_Y / 2 + local[1] ) / c;
237  time2 = ( _layer_dim_Y / 2 - local[1] ) / c;
238  }
239 
240  return std::make_pair(time1, time2);
241  }
242 
243  //----------------------------------------------------------------------------
244  std::array<double, 3> SegmentationMuIDAlg::ReconstructStripHitPosition(const gar::geo::GeometryCore& geo, const std::array<double, 3> &local, const float &xlocal, const gar::raw::CellID_t& cID) const
245  {
246  int layer = _decoder->get(cID, "layer");
247  float pos = xlocal;
248  std::array<double, 3> newlocal;
249 
250  //Need to check if the local position is bigger than the strip length!
251  // bool isBarrel = this->isBarrel(cID);
252  float stripLength = this->getStripLength(geo, local, cID);
253 
254  if( std::abs(pos) > stripLength / 2. ) pos = (pos > 0) ? stripLength / 2. : -stripLength / 2.;
255 
256  if(layer == 1 || layer == 3) {
257  newlocal = {pos, local[1], local[2]};
258  }
259 
260  if(layer == 2) {
261  newlocal = {local[0], pos, local[2]};
262  }
263 
264  return newlocal;
265  }
266 
267  }//seg
268  } // geo
269 } //gar
static constexpr double cm
Definition: Units.h:68
double _stripSizeY
the strip size in Y
const BitFieldCoder * _decoder
double _layer_dim_Y
layer dimension in Y
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
void Initialize(const gar::geo::GeometryCore &geo) override
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::array< double, 3 > GetPosition(const gar::geo::GeometryCore &geo, const gar::raw::CellID_t &cID) const override
double _stripSizeX
the strip size in X
bool isBarrel(const gar::raw::CellID_t &cID) const override
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
SegmentationMuIDAlg(fhicl::ParameterSet const &pset)
Default constructor used by derived classes passing the encoding string.
bool isTile(const gar::raw::CellID_t &cID) const override
T abs(T value)
std::string _yId
the field name used for Y
std::string _sliceId
the field name used for slice
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::string _layerId
the field name used for layer
std::pair< TVector3, TVector3 > getStripEnds(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
std::string _xId
the field name used for X
std::string _encoding
the encoding string
General GArSoft Utilities.
long64 get(long64 bitfield, size_t index) const
double _frac
fraction of tiles to remove at the edge
double getStripLength(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
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
unsigned int _nLayers
number of layers
void decode(std::any const &a, Hep2Vector &result)
Definition: CLHEP_ps.h:12
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double _layer_dim_X
layer dimension in X
QAsciiDict< Entry > ns
QTextStream & endl(QTextStream &s)
void reconfigure(fhicl::ParameterSet const &pset) override