PixelMap.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file PixelMap.h
3 /// \brief PixelMap for CVN
4 /// \author Dominick Rocco - rocco@physics.umn.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 #ifndef CVN_PIXELMAP_H
8 #define CVN_PIXELMAP_H
9 
10 #include <ostream>
11 #include <fstream>
12 #include <vector>
13 
14 #include "CVN/func/Boundary.h"
15 #include "CVN/func/HitType.h"
16 #include "TH2.h"
17 
18 namespace cvn
19 {
20 
21 
22  /// PixelMap, basic input to CVN neural net
23  class PixelMap
24  {
25  public:
26  PixelMap(unsigned int nPlane, unsigned int nCell, const Boundary& bound,
27  bool PEOnly = false);
28  PixelMap(){};
29 
30  /// Length in planes
31  unsigned int NPlane() const {return fNPlane;};
32 
33  /// Length in planes per view
34  unsigned int NPlanePerView() const { return ((fNPlane/2)+(fNPlane%2)); };
35 
36  /// Width in cells
37  unsigned int NCell() const {return fNCell;};
38 
39  /// Total number of pixels in map
40  unsigned int NPixel() const {return fPE.size();};
41 
42  void SetMinTime(float minTime) {fMinTime = minTime;};
43 
44  void SetMaxTime(float maxTime) {fMaxTime = maxTime;};
45 
46  float MinTime() const {return fMinTime;};
47 
48  float MaxTime() const {return fMaxTime;};
49 
50  /// Map boundary
51  Boundary Bound() const {return fBound;};
52 
53  /// Number of inputs for the neural net
54  unsigned int NInput() const {return NPixel();};
55 
56  void FillInputVector(float* input) const;
57 
58  /// Add a hit to the map if it is contained within the plane, cell rcvne
59  /// Could be expanded later to add to overflow accordingly.
60  void Add(const unsigned int& plane,
61  const unsigned int& cell,
62  const float& pe,
63  unsigned int& view,
64  unsigned int& hitID,
65  const float& time,
66  const HitType label,
67  const double purity,
68  const int object,
69  const int nuIdx);
70 
71 
72  /// Take global plane, cell (detector) and return index in fPE vector
73  unsigned int GlobalToIndex(const unsigned int& plane,
74  const unsigned int& cell,
75  const unsigned int& view);
76 
77  /// Take local plane, cell (within map) and return index in fPE vector
78  unsigned int LocalToIndex(const unsigned int& plane,
79  const unsigned int& cell) const;
80 
81  /// Take global plane, cell (detector) and return index in fPE vector
82  unsigned int GlobalToIndexSingle(const unsigned int& plane,
83  const unsigned int& cell,
84  const unsigned int& view);
85 
86  /// Draw pixel map to the screen. This is pretty hokey and the aspect ratio
87  /// is totally unrealistic.
88  void Print();
89 
90  /// Return the pixel map as a 2D histogram for visualization.
91  void ToFile(std::ofstream & ofs, int batch, bool hits = false) const;
92  TH2F* ToTH2(TString name) const;
93  TH2F* ToLabTH2(TString name) const;
94  TH2F* ToObjTH2(TString name) const;
95  TH2F* SingleViewToTH2(const unsigned int& view,
96  TString name) const;
97 
98  TH2F* SingleViewToLabTH2(const unsigned int& view,
99  TString name,
100  bool time) const;
101  TH2F* SingleViewToObjTH2(const unsigned int& view,
102  TString name,
103  bool nuID) const;
104 
105 
106  std::vector<unsigned char> PixelMapToVector(bool useGeV) const;
107  std::vector<unsigned char> PixelMapToObjVector(bool useLabels) const;
108  unsigned int PixelMapToVectors(std::vector<unsigned int>* planes,
109  std::vector<unsigned int>* cells,
110  std::vector<unsigned int>* chan,
111  std::vector<unsigned char>* values,
112  bool useGeV) const;
113 
114  unsigned char ConvertToChar(float n, bool useGeV) const;
115  unsigned char ConvertHitsToChar(float n) const;
116 
117  unsigned int fNPlane; ///< Number of planes, length of pixel map
118  unsigned int fNCell; ///< Number of cells, width of pixel map
119  float fFracX; ///< fraction of x view hits contained in map
120  float fFracY; ///< fraction of y view hits contained in map
121  float fMinTime; ///< Minimum time considered in pixel map (in nanoseconds)
122  float fMaxTime; ///< Maximum time considered in pixel map (in nanoseconds)
123  unsigned int fOccupiedPixels; ///< Number of non-zero entries in pixel map. Counted when the Add function is called
124  unsigned int fOccupiedPixelsX; ///< Number of non-zero entries in pixel map. Counted when the Add function is called
125  unsigned int fOccupiedPixelsY; ///< Number of non-zero entries in pixel map. Counted when the Add function is called
126 
127  std::vector<float> fPE; ///< Vector of PE measurements for pixels
128  std::vector<float> fPEX; ///< Vector of X PE measurements for pixels
129  std::vector<float> fPEY; ///< Vector of Y PE measurements for pixels
130  std::vector<double> fPur; ///< Vector of purity for pixels
131  std::vector<double> fPurX; ///< Vector of X purity for pixels
132  std::vector<double> fPurY; ///< Vector of Y purity for pixels
133  std::vector<HitType> fLab; ///< Vector of Truth labels for pixels
134  std::vector<HitType> fLabX; ///< Vector of X Truth labels for pixels
135  std::vector<HitType> fLabY; ///< Vector of Y Truth labels for pixels
136  std::vector<float> fT; ///< Vector of Time of hits
137  std::vector<float> fTX; ///< Vector of X Time of hits
138  std::vector<float> fTY; ///< Vector of Y Time of hits
139  std::vector<int> fObj; ///< Vector of Particle Idx of hits
140  std::vector<int> fObjX; ///< Vector of X Particle Idx of hits
141  std::vector<int> fObjY; ///< Vector of Y Particle Idx of hits
142  std::vector<int> fNu; ///< Vector of Nu Index of hits
143  std::vector<int> fNuX; ///< Vector of X Nu Index of hits
144  std::vector<int> fNuY; ///< Vector of Y Nu Index of hits
145 
146  std::vector<unsigned int> fVie; ///< Vector of hit view
147  std::vector<unsigned int> fVieX; ///< Vector of X hit view
148  std::vector<unsigned int> fVieY; ///< Vector of Y hit view
149  std::vector<unsigned int> fHit; ///< Vector of hit IDs
150  std::vector<unsigned int> fHitX; ///< Vector of X hit IDs
151  std::vector<unsigned int> fHitY; ///< Vector of Y hit IDs
152 
153  Boundary fBound; //< Boundary of pixel map
154 
155  bool fPEOnly;
156  };
157 
158  std::ostream& operator<<(std::ostream& os, const PixelMap& m);
159 
160 }
161 
162 #endif // CVN_PIXELMAP_H
const XML_Char * name
Definition: expat.h:151
float fMaxTime
Maximum time considered in pixel map (in nanoseconds)
Definition: PixelMap.h:122
unsigned int fOccupiedPixelsX
Number of non-zero entries in pixel map. Counted when the Add function is called. ...
Definition: PixelMap.h:124
std::vector< unsigned char > PixelMapToObjVector(bool useLabels) const
Definition: PixelMap.cxx:417
TH2F * SingleViewToTH2(const unsigned int &view, TString name) const
Definition: PixelMap.cxx:312
std::vector< float > fT
Vector of Time of hits.
Definition: PixelMap.h:136
bool fPEOnly
Definition: PixelMap.h:155
enum cvn::HType HitType
std::vector< float > fPEY
Vector of Y PE measurements for pixels.
Definition: PixelMap.h:129
unsigned int NPixel() const
Total number of pixels in map.
Definition: PixelMap.h:40
void Print()
Definition: PixelMap.cxx:164
unsigned int fOccupiedPixels
Number of non-zero entries in pixel map. Counted when the Add function is called. ...
Definition: PixelMap.h:123
unsigned int NPlane() const
Length in planes.
Definition: PixelMap.h:31
std::ostream & operator<<(std::ostream &os, const PixelMapProducer &p)
unsigned int fNPlane
Number of planes, length of pixel map.
Definition: PixelMap.h:117
std::vector< int > fObjX
Vector of X Particle Idx of hits.
Definition: PixelMap.h:140
void FillInputVector(float *input) const
Definition: PixelMap.cxx:52
void Add(const unsigned int &plane, const unsigned int &cell, const float &pe, unsigned int &view, unsigned int &hitID, const float &time, const HitType label, const double purity, const int object, const int nuIdx)
Definition: PixelMap.cxx:65
std::vector< unsigned int > fVieX
Vector of X hit view.
Definition: PixelMap.h:147
std::vector< int > fObjY
Vector of Y Particle Idx of hits.
Definition: PixelMap.h:141
float fMinTime
Minimum time considered in pixel map (in nanoseconds)
Definition: PixelMap.h:121
Defines an enumeration for prong classification.
unsigned char ConvertHitsToChar(float n) const
Definition: PixelMap.cxx:410
std::vector< int > fNu
Vector of Nu Index of hits.
Definition: PixelMap.h:142
const char * label
TH2F * ToLabTH2(TString name) const
Definition: PixelMap.cxx:258
void SetMinTime(float minTime)
Definition: PixelMap.h:42
std::vector< float > fPE
Vector of PE measurements for pixels.
Definition: PixelMap.h:127
unsigned int PixelMapToVectors(std::vector< unsigned int > *planes, std::vector< unsigned int > *cells, std::vector< unsigned int > *chan, std::vector< unsigned char > *values, bool useGeV) const
Definition: PixelMap.cxx:476
TH2F * ToTH2(TString name) const
Definition: PixelMap.cxx:236
void hits()
Definition: readHits.C:15
std::vector< HitType > fLabY
Vector of Y Truth labels for pixels.
Definition: PixelMap.h:135
std::vector< unsigned int > fHit
Vector of hit IDs.
Definition: PixelMap.h:149
std::vector< unsigned int > fHitY
Vector of Y hit IDs.
Definition: PixelMap.h:151
std::vector< unsigned char > PixelMapToVector(bool useGeV) const
Definition: PixelMap.cxx:449
std::vector< int > fObj
Vector of Particle Idx of hits.
Definition: PixelMap.h:139
float MaxTime() const
Definition: PixelMap.h:48
std::vector< float > fPEX
Vector of X PE measurements for pixels.
Definition: PixelMap.h:128
std::vector< unsigned int > fVie
Vector of hit view.
Definition: PixelMap.h:146
unsigned int fOccupiedPixelsY
Number of non-zero entries in pixel map. Counted when the Add function is called. ...
Definition: PixelMap.h:125
float fFracY
fraction of y view hits contained in map
Definition: PixelMap.h:120
std::vector< unsigned int > fVieY
Vector of Y hit view.
Definition: PixelMap.h:148
TH2F * ToObjTH2(TString name) const
Definition: PixelMap.cxx:285
Boundary Bound() const
Map boundary.
Definition: PixelMap.h:51
unsigned int NPlanePerView() const
Length in planes per view.
Definition: PixelMap.h:34
TH2F * SingleViewToObjTH2(const unsigned int &view, TString name, bool nuID) const
Definition: PixelMap.cxx:359
unsigned int fNCell
Number of cells, width of pixel map.
Definition: PixelMap.h:118
std::vector< float > fTX
Vector of X Time of hits.
Definition: PixelMap.h:137
void ToFile(std::ofstream &ofs, int batch, bool hits=false) const
Return the pixel map as a 2D histogram for visualization.
Definition: PixelMap.cxx:192
unsigned int LocalToIndex(const unsigned int &plane, const unsigned int &cell) const
Take local plane, cell (within map) and return index in fPE vector.
Definition: PixelMap.cxx:137
unsigned char ConvertToChar(float n, bool useGeV) const
Definition: PixelMap.cxx:396
float fFracX
fraction of x view hits contained in map
Definition: PixelMap.h:119
std::vector< float > fTY
Vector of Y Time of hits.
Definition: PixelMap.h:138
std::vector< int > fNuX
Vector of X Nu Index of hits.
Definition: PixelMap.h:143
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:23
std::vector< double > fPurY
Vector of Y purity for pixels.
Definition: PixelMap.h:132
std::vector< unsigned int > fHitX
Vector of X hit IDs.
Definition: PixelMap.h:150
std::vector< HitType > fLabX
Vector of X Truth labels for pixels.
Definition: PixelMap.h:134
unsigned int GlobalToIndexSingle(const unsigned int &plane, const unsigned int &cell, const unsigned int &view)
Take global plane, cell (detector) and return index in fPE vector.
Definition: PixelMap.cxx:147
unsigned int GlobalToIndex(const unsigned int &plane, const unsigned int &cell, const unsigned int &view)
Take global plane, cell (detector) and return index in fPE vector.
Definition: PixelMap.cxx:121
TH2F * SingleViewToLabTH2(const unsigned int &view, TString name, bool time) const
Definition: PixelMap.cxx:331
std::vector< HitType > fLab
Vector of Truth labels for pixels.
Definition: PixelMap.h:133
unsigned int NInput() const
Number of inputs for the neural net.
Definition: PixelMap.h:54
Boundary fBound
Definition: PixelMap.h:153
std::vector< int > fNuY
Vector of Y Nu Index of hits.
Definition: PixelMap.h:144
void SetMaxTime(float maxTime)
Definition: PixelMap.h:44
float MinTime() const
Definition: PixelMap.h:46
std::vector< double > fPur
Vector of purity for pixels.
Definition: PixelMap.h:130
std::vector< double > fPurX
Vector of X purity for pixels.
Definition: PixelMap.h:131
unsigned int NCell() const
Width in cells.
Definition: PixelMap.h:37