PixelMap.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file PixelMap.h
3 /// \brief PixelMap for CVN
4 /// \author Alexander Radovic - a.radovic@gmail.com
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include <cassert>
8 #include <iostream>
9 #include <ostream>
11 
12 namespace cvn
13 {
14 
15  PixelMap::PixelMap(unsigned int nWire, unsigned int nTdc,
16  const Boundary& bound):
17  fNWire(nWire),
18  fNTdc(nTdc),
19  fPE(nWire*nTdc),
20  fPEX(nWire*nTdc),
21  fPEY(nWire*nTdc),
22  fPEZ(nWire*nTdc),
23  fPur(nWire*nTdc),
24  fPurX(nWire*nTdc),
25  fPurY(nWire*nTdc),
26  fPurZ(nWire*nTdc),
27  fLab(nWire*nTdc),
28  fLabX(nWire*nTdc),
29  fLabY(nWire*nTdc),
30  fLabZ(nWire*nTdc),
31  fBound(bound)
32  { fTotHits = 0; }
33 
34  void PixelMap::FillInputVector(float* input) const
35  {
36  unsigned int i = 0;
37 
38  for(const auto& pe:fPE){
39  input[i] = pe;
40  ++i;
41  }
42 
43  }
44 
45 
46  void PixelMap::Add(const unsigned int& wire, const double& tdc, const unsigned int& view, const double& pe)
47  {
48  const HitType label = kEmptyHit;
49  const double purity=0.0;
50  if(fBound.IsWithin(wire, tdc, view)){
51  fPE[GlobalToIndex(wire,tdc, view)] += pe;
52  fLab[GlobalToIndex(wire,tdc, view)] = label;
53  fPur[GlobalToIndexSingle(wire,tdc, view)] = purity;
54  if(view==0){
55  fPEX[GlobalToIndexSingle(wire,tdc, view)] += pe;//Why +=?
56  fLabX[GlobalToIndexSingle(wire,tdc, view)] = label;
57  fPurX[GlobalToIndexSingle(wire,tdc, view)] = purity;
58  }
59  if(view==1){
60  fPEY[GlobalToIndexSingle(wire,tdc, view)] += pe;
61  fLabY[GlobalToIndexSingle(wire,tdc, view)] = label;
62  fPurY[GlobalToIndexSingle(wire,tdc, view)] = purity;
63  }
64  if(view==2){
65  fPEZ[GlobalToIndexSingle(wire,tdc, view)] += pe;
66  fLabZ[GlobalToIndexSingle(wire,tdc, view)] = label;
67  fPurZ[GlobalToIndexSingle(wire,tdc, view)] = purity;
68  }
69  }
70  }
71 
72  unsigned int PixelMap::GlobalToIndex(const unsigned int& wire,
73  const double& tdc,
74  const unsigned int& view)
75  {
76 
77  unsigned int internalWire = wire - fBound.FirstWire(view);
78 
79  double upperTL=fBound.LastTDC(view);
80  double lowerTL=fBound.FirstTDC(view);
81  double timestep=(upperTL-lowerTL)/double(fNTdc);
82  double roundChannel=round((tdc-lowerTL)/timestep);
83 
84  unsigned int internalTdc = roundChannel;
85 
86  unsigned int index = internalWire * fNTdc + internalTdc % fNTdc;
87 
88  assert(index < fPE.size());
89 
90  return index;
91  }
92 
93  unsigned int PixelMap::LocalToIndex(const unsigned int& wire,
94  const unsigned int& tdc) const
95  {
96  unsigned int index = wire * fNTdc + tdc % fNTdc;
97 
98  assert(index < fPE.size());
99  return index;
100  }
101 
102  unsigned int PixelMap::GlobalToIndexSingle(const unsigned int& wire,
103  const double& tdc,
104  const unsigned int& view)
105 
106  {
107 
108  unsigned int internalWire = wire - fBound.FirstWire(view);
109 
110  double upperTL=fBound.LastTDC(view);
111  double lowerTL=fBound.FirstTDC(view);
112  double timestep=(upperTL-lowerTL)/double(fNTdc);
113  double roundChannel=round((tdc-lowerTL)/timestep);
114 
115  unsigned int internalTdc = roundChannel;
116 
117  unsigned int index = internalWire * fNTdc + internalTdc % fNTdc;
118 
119  assert(index < fPEX.size());
120 
121  return index;
122  }
123 
124  void PixelMap::Print() const
125  {
126 
127  // Start by doing even wires
128  for(unsigned int iTdc = 0; iTdc < fNTdc; ++iTdc)
129  {
130  for(unsigned int iWire = 0; iWire < fNWire; iWire += 2)
131  {
132  unsigned int index = LocalToIndex(iWire, iTdc);
133  if( fPE[index] > 0)
134  {
135  std::cout << "*";
136  }
137  else
138  {
139  std::cout << " ";
140  }
141 
142  }
143  std::cout << std::endl;
144  }
145  // Then do odd wires
146  for(unsigned int iTdc = 0; iTdc < fNTdc; ++iTdc)
147  {
148  for(unsigned int iWire = 1; iWire < fNWire; iWire += 2)
149  {
150  unsigned int index = LocalToIndex(iWire, iTdc);
151  if( fPE[index] > 0)
152  {
153  std::cout << "*";
154  }
155  else
156  {
157  std::cout << " ";
158  }
159 
160  }
161  std::cout << std::endl;
162  }
163 
164  }
165 
166  TH2F* PixelMap::ToTH2() const
167  {
168 
169  // Create a histogram, use twice as many tdcs to distinguish views
170  TH2F* hist = new TH2F("PixelMap", ";Wire;Tdc", fNWire, 0, fNWire,
171  fNTdc*3, 0, fNTdc*3);
172 
173  for(unsigned int iWire = 0; iWire < fNWire; ++iWire)
174  {
175  for(unsigned int iTdc = 0; iTdc < fNTdc; ++iTdc)
176  {
177  // Add 1 to in each bin to skip underflow
178  hist->SetBinContent(iWire+1, iTdc + fNTdc*(iWire%3) + 1,
179  fPE[LocalToIndex(iWire, iTdc)]);
180 
181  }
182  }
183  return hist;
184  }
185 
186  TH2F* PixelMap::ToLabTH2() const
187  {
188 
189  // Create a histogram, use twice as many tdcs to distinguish views
190  TH2F* hist = new TH2F("PixelMap", ";Wire;Tdc", fNWire, 0, fNWire,
191  fNTdc*3, 0, fNTdc*3);
192 
193  for(unsigned int iWire = 0; iWire < fNWire; ++iWire)
194  {
195  for(unsigned int iTdc = 0; iTdc < fNTdc; ++iTdc)
196  {
197  // Add 1 to in each bin to skip underflow
198  hist->SetBinContent(iWire+1, iTdc + fNTdc*(iWire%3) + 1,
199  (double)fLab[LocalToIndex(iWire, iTdc)]);
200 
201  }
202  }
203  return hist;
204  }
205 
206  TH2F* PixelMap::SingleViewToTH2(const unsigned int& view) const
207  {
208 
209  // Create a histogram
210  TH2F* hist = new TH2F("PixelMap", ";Wire;Tdc", fNWire, 0,
211  fNWire,
212  fNTdc, 0, fNTdc);
213 
214  for(unsigned int iWire = 0; iWire < fNWire; ++iWire)
215  {
216  for(unsigned int iTdc = 0; iTdc < fNTdc; ++iTdc)
217  {
218  // Add 1 to in each bin to skip underflow
219  if(view==0){
220  hist->SetBinContent(iWire+1, iTdc + 1,
221  fPEX[LocalToIndex(iWire, iTdc)]);
222  }
223  if(view==1){
224  hist->SetBinContent(iWire+1, iTdc + 1,
225  fPEY[LocalToIndex(iWire, iTdc)]);
226  }
227  if(view==2){
228  hist->SetBinContent(iWire+1, iTdc + 1,
229  fPEZ[LocalToIndex(iWire, iTdc)]);
230  }
231  }
232  }
233  return hist;
234  }
235 
236  std::ostream& operator<<(std::ostream& os, const PixelMap& m)
237  {
238  os << "PixelMap with " << m.NPixel() << " pixels, "
239  << m.NWire() << " wires"
240  << " by " << m.NTdc() << " tdcs" ;
241  return os;
242  }
243 }
void Print() const
Definition: PixelMap.cxx:124
enum cvn::HType HitType
std::vector< float > fPEY
Vector of Y PE measurements for pixels.
Definition: PixelMap.h:82
unsigned int NPixel() const
Total number of pixels in map.
Definition: PixelMap.h:35
TH2F * SingleViewToTH2(const unsigned int &view) const
Definition: PixelMap.cxx:206
unsigned int fNWire
Number of wires, length of pixel map.
Definition: PixelMap.h:78
std::ostream & operator<<(std::ostream &os, const PixelMapProducer &p)
void FillInputVector(float *input) const
Definition: PixelMap.cxx:34
TH2F * ToLabTH2() const
Definition: PixelMap.cxx:186
PixelMap for CVN.
Utility class for truth labels.
TH2F * ToTH2() const
Return the pixel map as a 2D histogram for visualization.
Definition: PixelMap.cxx:166
std::vector< float > fPE
Vector of PE measurements for pixels.
Definition: PixelMap.h:80
unsigned int GlobalToIndexSingle(const unsigned int &wire, const double &tdc, const unsigned int &view)
Take global wire, tdc (detector) and return index in fPE vector.
Definition: PixelMap.cxx:102
std::vector< float > fPEZ
Vector of Y PE measurements for pixels.
Definition: PixelMap.h:83
std::vector< HitType > fLabY
Vector of Y Truth labels for pixels.
Definition: PixelMap.h:90
static int input(void)
Definition: code.cpp:15695
void Add(const unsigned int &wire, const double &tdc, const unsigned int &view, const double &pe)
Definition: PixelMap.cxx:46
std::vector< float > fPEX
Vector of X PE measurements for pixels.
Definition: PixelMap.h:81
double FirstTDC(const unsigned int &view) const
Definition: Boundary.h:46
unsigned int GlobalToIndex(const unsigned int &wire, const double &tdc, const unsigned int &view)
Take global wire, tdc (detector) and return index in fPE vector.
Definition: PixelMap.cxx:72
int FirstWire(const unsigned int &view) const
Definition: Boundary.h:44
unsigned int NTdc() const
Width in tdcs.
Definition: PixelMap.h:32
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:22
std::vector< double > fPurY
Vector of Y purity for pixels.
Definition: PixelMap.h:86
std::vector< HitType > fLabX
Vector of X Truth labels for pixels.
Definition: PixelMap.h:89
std::vector< double > fPurZ
Vector of Y purity for pixels.
Definition: PixelMap.h:87
std::vector< HitType > fLab
Vector of Truth labels for pixels.
Definition: PixelMap.h:88
unsigned int fTotHits
Number of hits that make up the pixel map.
Definition: PixelMap.h:92
unsigned int fNTdc
Number of tdcs, width of pixel map.
Definition: PixelMap.h:79
Boundary fBound
Definition: PixelMap.h:94
std::vector< HitType > fLabZ
Vector of Y Truth labels for pixels.
Definition: PixelMap.h:91
unsigned int NWire() const
Length in wires.
Definition: PixelMap.h:29
double LastTDC(const unsigned int &view) const
Definition: Boundary.h:47
unsigned int LocalToIndex(const unsigned int &wire, const unsigned int &tdc) const
Take local wire, tdc (within map) and return index in fPE vector.
Definition: PixelMap.cxx:93
QTextStream & endl(QTextStream &s)
std::vector< double > fPur
Vector of purity for pixels.
Definition: PixelMap.h:84
std::vector< double > fPurX
Vector of X purity for pixels.
Definition: PixelMap.h:85
bool IsWithin(const unsigned int &wire, const double &cell, const unsigned int &view)
Definition: Boundary.cxx:45