HitMap.h
Go to the documentation of this file.
1 #ifndef NOISEHITMAP__H
2 #define NOISEHITMAP__H
4 
5 #include <exception>
6 #include <array>
7 
8 namespace novaddt{
9 namespace calib{
10 
11  template <size_t Nx, size_t Ny>
12  struct dimensions{
13  enum {NX=Nx, NY=Ny, length=Nx*Ny};
14  static size_t index(size_t nx, size_t ny){return nx+ny*NX;}
15  };
16 
17  template <typename T, typename Dimension> class HitMap;
18 
19  const size_t FD_NUM_PLANES = 896;
20  const size_t FD_NUM_CELLS = 384;
21  const size_t ND_NUM_PLANES = 256;
22  const size_t ND_NUM_CELLS = 96;
25  }
26 }
27 
28 //a template class to keep array of Planes*Cells, accessible by hits
29 template <typename T, typename Dimension>
30 class novaddt::calib::HitMap: public Dimension{
31 public:
32  HitMap() { }
33  void reset(){std::fill(data.begin(),data.end(),0);}
34  static size_t Nplanes() {return Dimension::NX;}
35  static size_t Ncells () {return Dimension::NY;}
36  static size_t Length() {return Dimension::length;}
37  void Scale(T koeff){
38  /// scale the map contents (normalize to N events)
39  for(auto &d:data){
40  d*=koeff;
41  }
42  }
43 ///access operators by plane&cell numbers
45  { return data[Dimension::index(plane.val,cell.val)]; }
47  { return data[Dimension::index(plane.val,cell.val)]; }
48 
50  { return at(plane,cell); }
51 
52 const T& operator() (novaddt::Plane plane, novaddt::Cell cell) const
53  { return at(plane,cell); }
54 ///access operators by hit
55  T& operator [](const novaddt::DAQHit& h)
56  { return at(h.Plane(),h.Cell()); }
57 
58 const T& operator [](const novaddt::DAQHit& h) const
59  { return at(h.Plane(),h.Cell()); }
60 ///access operators by index
61 const T& operator [](size_t n){return data[n];}
62 
63 public:
64  std::array<T,Dimension::length> data;
65 };
66 
67 //couple of useful methods: serializing map
68 std::istream& operator >> (std::istream& s, novaddt::calib::FDHitMap& map)
69 {
70  size_t length = sizeof(map);
71  char *buffer=reinterpret_cast<char*>(&map);
72  s.read(buffer,length);
73  return s;
74 }
75 
76 std::ostream& operator << (std::ostream& s, const novaddt::calib::FDHitMap& map)
77 {
78  size_t length = sizeof(map);
79  const char *buffer=reinterpret_cast<const char*>(&map);
80  s.write(buffer,length);
81  return s;
82 }
83 #endif
84 
novaddt::Plane const & Plane() const
Definition: DAQHit.h:70
value_type val
Definition: BaseProducts.h:109
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
const XML_Char const XML_Char * data
Definition: expat.h:268
const XML_Char * s
Definition: expat.h:262
const size_t FD_NUM_PLANES
Definition: HitMap.h:19
const T & at(novaddt::Plane plane, novaddt::Cell cell) const
Definition: HitMap.h:46
CDPStorage service.
length
Definition: demo0.py:21
static size_t Ncells()
Definition: HitMap.h:35
static size_t Nplanes()
Definition: HitMap.h:34
const size_t FD_NUM_CELLS
Definition: HitMap.h:20
static size_t Length()
Definition: HitMap.h:36
static size_t index(size_t nx, size_t ny)
Definition: HitMap.h:14
Float_t d
Definition: plot.C:236
value_type val
Definition: BaseProducts.h:84
std::istream & operator>>(std::istream &s, novaddt::calib::FDHitMap &map)
Definition: HitMap.h:68
std::ostream & operator<<(std::ostream &s, const novaddt::calib::FDHitMap &map)
Definition: HitMap.h:76
void Scale(T koeff)
Definition: HitMap.h:37
std::array< T, Dimension::length > data
Definition: HitMap.h:64
novaddt::Cell const & Cell() const
Definition: DAQHit.h:71
void fill(std::vector< T > &x, const S &y)
Definition: fill.hpp:22
double T
Definition: Xdiff_gwt.C:5
T & at(novaddt::Plane plane, novaddt::Cell cell)
access operators by plane&cell numbers
Definition: HitMap.h:44
const size_t ND_NUM_CELLS
Definition: HitMap.h:22
const size_t ND_NUM_PLANES
Definition: HitMap.h:21