Public Member Functions | Private Member Functions | Private Attributes | List of all members
cnn::RegCNNImageUtils Class Reference

Class containing some utility functions for all things RegCNN. More...

#include <RegCNNImageUtils.h>

Public Member Functions

 RegCNNImageUtils ()
 
 RegCNNImageUtils (unsigned int nWires, unsigned int nTDCs, unsigned int nViews)
 
 ~RegCNNImageUtils ()
 
void SetViewReversal (bool reverseX, bool reverseY, bool reverseZ)
 Function to set any views that need reversing. More...
 
void SetViewReversal (std::vector< bool > reverseViews)
 
void SetPixelMapSize (unsigned int nWires, unsigned int nTDCs)
 Set the input pixel map size. More...
 
float ConvertToScaledCharge (float charge)
 
void ConvertPixelMapToImageVectorF (const RegPixelMap &pm, ImageVectorF &imageVec)
 Convert a pixel map into an image vector (float version) More...
 
void ConvertChargeVectorsToImageVectorF (std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ImageVectorF &imageVec)
 Float version of conversion for convenience of TF interface. More...
 

Private Member Functions

void ConvertChargeVectorsToViewVectors (std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ViewVectorF &view0, ViewVectorF &view1, ViewVectorF &view2)
 Base function for conversion of the Pixel Map to our required output format. More...
 
ImageVectorF BuildImageVectorF (ViewVectorF v0, ViewVectorF v1, ViewVectorF v2)
 Make the image vector from the view vectors. More...
 
void ReverseView (std::vector< float > &peVec)
 Funtion to actually reverse the view. More...
 

Private Attributes

unsigned int fNViews
 Number of views of each event. More...
 
unsigned int fPixelMapWires
 Input pixel map sizes. More...
 
unsigned int fPixelMapTDCs
 
std::vector< boolfViewReverse
 Vector of bools to decide if any views need to be reversed. More...
 

Detailed Description

Class containing some utility functions for all things RegCNN.

Definition at line 22 of file RegCNNImageUtils.h.

Constructor & Destructor Documentation

cnn::RegCNNImageUtils::RegCNNImageUtils ( )

Definition at line 6 of file RegCNNImageUtils.cxx.

6  {
7  // Set a default image size
8  SetPixelMapSize(2880,500);
9  fViewReverse = {false,false,false};
10  fNViews = 3;
11 }
std::vector< bool > fViewReverse
Vector of bools to decide if any views need to be reversed.
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.
unsigned int fNViews
Number of views of each event.
cnn::RegCNNImageUtils::RegCNNImageUtils ( unsigned int  nWires,
unsigned int  nTDCs,
unsigned int  nViews 
)

Definition at line 13 of file RegCNNImageUtils.cxx.

13  {
14  SetPixelMapSize(2880,500);
15 }
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.
cnn::RegCNNImageUtils::~RegCNNImageUtils ( )

Definition at line 17 of file RegCNNImageUtils.cxx.

17  {
18 
19 }

Member Function Documentation

cnn::ImageVectorF cnn::RegCNNImageUtils::BuildImageVectorF ( cnn::ViewVectorF  v0,
cnn::ViewVectorF  v1,
cnn::ViewVectorF  v2 
)
private

Make the image vector from the view vectors.

Definition at line 139 of file RegCNNImageUtils.cxx.

139  {
140 
141  // Tensorflow wants things in the arrangement <wires, TDCs, views>
142  cnn::ImageVectorF image;
143  for(unsigned int w = 0; w < v0.size(); ++w){
144  std::vector<std::vector<float> > wireVec;
145  for(unsigned int t = 0; t < v0[0].size(); ++t){
146  std::vector<float> timeVec;
147  timeVec.push_back(v0[w][t]);
148  timeVec.push_back(v1[w][t]);
149  timeVec.push_back(v2[w][t]);
150  wireVec.push_back(timeVec);
151  } // Loop over tdcs
152  image.push_back(wireVec);
153  } // Loop over wires
154 
155 
156 
157  return image;
158 }
std::vector< ViewVectorF > ImageVectorF
void cnn::RegCNNImageUtils::ConvertChargeVectorsToImageVectorF ( std::vector< float > &  v0pe,
std::vector< float > &  v1pe,
std::vector< float > &  v2pe,
cnn::ImageVectorF imageVec 
)

Float version of conversion for convenience of TF interface.

Definition at line 57 of file RegCNNImageUtils.cxx.

58  {
59 
60  cnn::ViewVectorF view0;
61  cnn::ViewVectorF view1;
62  cnn::ViewVectorF view2;
63 
64  ConvertChargeVectorsToViewVectors(v0pe, v1pe, v2pe, view0, view1, view2);
65 
66  cnn::ImageVectorF newImage = BuildImageVectorF(view0,view1,view2);
67 
68  imageVec = newImage;
69 }
void ConvertChargeVectorsToViewVectors(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ViewVectorF &view0, ViewVectorF &view1, ViewVectorF &view2)
Base function for conversion of the Pixel Map to our required output format.
std::vector< std::vector< float > > ViewVectorF
Useful typedefs.
std::vector< ViewVectorF > ImageVectorF
ImageVectorF BuildImageVectorF(ViewVectorF v0, ViewVectorF v1, ViewVectorF v2)
Make the image vector from the view vectors.
void cnn::RegCNNImageUtils::ConvertChargeVectorsToViewVectors ( std::vector< float > &  v0pe,
std::vector< float > &  v1pe,
std::vector< float > &  v2pe,
cnn::ViewVectorF view0,
cnn::ViewVectorF view1,
cnn::ViewVectorF view2 
)
private

Base function for conversion of the Pixel Map to our required output format.

Definition at line 71 of file RegCNNImageUtils.cxx.

72  {
73 
74  // Reverse requested views
75  if(fViewReverse[0]) ReverseView(v0pe);
76  if(fViewReverse[1]) ReverseView(v1pe);
77  if(fViewReverse[2]) ReverseView(v2pe);
78 
79  // Write the values to the three vectors
80  for (unsigned int view = 0; view < fNViews; ++view){
81  cnn::ViewVectorF viewChargeVec;
82  //for (unsigned int wire = 0; wire < fPixelMapWires; ++wire){
83  for (unsigned int wire = 0; wire < fPixelMapWires+1; ++wire){
84  std::vector<float> wireTDCVec;
85  //for (unsigned int time = 0; time < fPixelMapTDCs; ++time){
86  for (unsigned int time = 0; time < fPixelMapTDCs+1; ++time) {
87 
88  // Get the index for the pixel map
89  unsigned int element = time + fPixelMapTDCs * wire;
90  // FIXME: needs to add additional dimensions because of TF model
91  if (time < fPixelMapTDCs && wire < fPixelMapWires){
92  // Scale Charges
93  float val = 0;
94  if(view == 0){ val = ConvertToScaledCharge(v0pe[element]); }
95  if(view == 1){ val = ConvertToScaledCharge(v1pe[element]); }
96  if(view == 2){ val = ConvertToScaledCharge(v2pe[element]); }
97  wireTDCVec.push_back(val);
98  } else {
99  wireTDCVec.push_back(0.);
100  }
101  }
102  viewChargeVec.push_back(wireTDCVec);
103  }
104  if(view == 0) view0 = viewChargeVec;
105  if(view == 1) view1 = viewChargeVec;
106  if(view == 2) view2 = viewChargeVec;
107  }
108 
109  return;
110 
111 }
std::vector< bool > fViewReverse
Vector of bools to decide if any views need to be reversed.
void ReverseView(std::vector< float > &peVec)
Funtion to actually reverse the view.
std::vector< std::vector< float > > ViewVectorF
Useful typedefs.
unsigned int fPixelMapWires
Input pixel map sizes.
float ConvertToScaledCharge(float charge)
unsigned int fNViews
Number of views of each event.
unsigned int fPixelMapTDCs
void cnn::RegCNNImageUtils::ConvertPixelMapToImageVectorF ( const RegPixelMap pm,
cnn::ImageVectorF imageVec 
)

Convert a pixel map into an image vector (float version)

Definition at line 45 of file RegCNNImageUtils.cxx.

45  {
46 
47  SetPixelMapSize(pm.fNWire,pm.fNTdc);
48 
49  // Strip out the charge vectors and use these
50  std::vector<float> v0pe = pm.fPEX;
51  std::vector<float> v1pe = pm.fPEY;
52  std::vector<float> v2pe = pm.fPEZ;
53 
54  ConvertChargeVectorsToImageVectorF(v0pe, v1pe, v2pe, imageVec);
55 }
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.
void ConvertChargeVectorsToImageVectorF(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ImageVectorF &imageVec)
Float version of conversion for convenience of TF interface.
float cnn::RegCNNImageUtils::ConvertToScaledCharge ( float  charge)

Definition at line 41 of file RegCNNImageUtils.cxx.

41  {
42  return charge/500.;
43 }
void cnn::RegCNNImageUtils::ReverseView ( std::vector< float > &  peVec)
private

Funtion to actually reverse the view.

Definition at line 114 of file RegCNNImageUtils.cxx.

114  {
115 
116  std::vector<float> vecCopy(peVec.size(),0.);
117 
118  for (unsigned int w = 0; w < fPixelMapWires; ++w)
119  {
120  // Get our new plane number
121  unsigned int newPlane = fPixelMapWires - w - 1;
122 
123  for (unsigned int t = 0; t < fPixelMapTDCs; ++t)
124  {
125  float val = peVec[t + fPixelMapTDCs * w];
126  vecCopy[t + fPixelMapTDCs * newPlane] = val;
127  }
128  }
129 
130  // Copy the values back into the original vector
131  for(unsigned int e = 0; e < peVec.size(); ++e){
132  float val = vecCopy[e];
133  peVec[e] = val;
134  }
135 
136 }
unsigned int fPixelMapWires
Input pixel map sizes.
const double e
unsigned int fPixelMapTDCs
void cnn::RegCNNImageUtils::SetPixelMapSize ( unsigned int  nWires,
unsigned int  nTDCs 
)

Set the input pixel map size.

Definition at line 35 of file RegCNNImageUtils.cxx.

35  {
36  fPixelMapWires = nWires;
37  fPixelMapTDCs = nTDCs;
38 }
unsigned int fPixelMapWires
Input pixel map sizes.
unsigned int fPixelMapTDCs
void cnn::RegCNNImageUtils::SetViewReversal ( bool  reverseX,
bool  reverseY,
bool  reverseZ 
)

Function to set any views that need reversing.

Definition at line 21 of file RegCNNImageUtils.cxx.

21  {
22  fViewReverse = {reverseX,reverseY,reverseZ};
23 }
std::vector< bool > fViewReverse
Vector of bools to decide if any views need to be reversed.
void cnn::RegCNNImageUtils::SetViewReversal ( std::vector< bool reverseViews)

Definition at line 25 of file RegCNNImageUtils.cxx.

25  {
26  if(reverseViews.size() != 3){
27  std::cout << "Expected three views for view reversals... using defaults." << std::endl;
28  }
29  else{
30  SetViewReversal(reverseViews[0],reverseViews[1],reverseViews[2]);
31  }
32  return;
33 }
void SetViewReversal(bool reverseX, bool reverseY, bool reverseZ)
Function to set any views that need reversing.
QTextStream & endl(QTextStream &s)

Member Data Documentation

unsigned int cnn::RegCNNImageUtils::fNViews
private

Number of views of each event.

Definition at line 63 of file RegCNNImageUtils.h.

unsigned int cnn::RegCNNImageUtils::fPixelMapTDCs
private

Definition at line 67 of file RegCNNImageUtils.h.

unsigned int cnn::RegCNNImageUtils::fPixelMapWires
private

Input pixel map sizes.

Definition at line 66 of file RegCNNImageUtils.h.

std::vector<bool> cnn::RegCNNImageUtils::fViewReverse
private

Vector of bools to decide if any views need to be reversed.

Definition at line 70 of file RegCNNImageUtils.h.


The documentation for this class was generated from the following files: