CVNImageUtils.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file CVNImageUtils.h
3 /// \brief Utilities for producing images for the CVN
4 /// \author Leigh Whitehead - leigh.howard.whitehead@cern.ch
5 ////////////////////////////////////////////////////////////////////////
6 
7 #ifndef CVN_IMAGE_UTILS_H
8 #define CVN_IMAGE_UTILS_H
9 
10 #include <vector>
11 
13 
14 namespace cvn
15 {
16 
17  /// Useful typedefs
18  typedef std::vector<std::vector<unsigned char> > ViewVector;
19  typedef std::vector<ViewVector> ImageVector;
20  typedef std::vector<std::vector<float> > ViewVectorF;
21  typedef std::vector<ViewVectorF> ImageVectorF;
22 
23  /// Class containing some utility functions for all things CVN
25  {
26  public:
27  CVNImageUtils();
28  CVNImageUtils(unsigned int nWires, unsigned int nTDCs, unsigned int nViews);
30 
31  /// Disable the selection of the wire region and just use the first 500 wires
33  /// Enable the selection of the wire region
34  void EnableRegionSelection();
35 
36  /// Convert the hit charge into the range 0 to 255 required by the CVN
37  unsigned char ConvertChargeToChar(float charge);
38 
39  /// Set up the image size that we want to have
40  void SetImageSize(unsigned int nWires, unsigned int nTDCs, unsigned int nViews);
41 
42  /// Function to set any views that need reversing
43  void SetViewReversal(bool reverseX, bool reverseY, bool reverseZ);
44  void SetViewReversal(std::vector<bool> reverseViews);
45 
46  /// Set the log scale for charge
47  void SetLogScale(bool setLog);
48 
49  /// Set the input pixel map size
50  void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs);
51 
52  /// Convert a Pixel Map object into a single pixel array with an image size nWire x nTDC
53  void ConvertPixelMapToPixelArray(const PixelMap &pm, std::vector<unsigned char> &pix);
54 
55  /// Convert three vectors (sorted in the same way as the vectors in the PixelMap object)
56  /// into a single pixel array with an image size nWire x nTDC
57  void ConvertChargeVectorsToPixelArray(std::vector<float> &v0pe, std::vector<float> &v1pe,
58  std::vector<float> &v2pe, std::vector<unsigned char> &pix);
59 
60  /// Convert a pixel map into an image vector (contains all three views)
61  void ConvertPixelMapToImageVector(const PixelMap &pm, ImageVector &imageVec);
62 
63  /// Convert a pixel map into an image vector (float version)
64  void ConvertPixelMapToImageVectorF(const PixelMap &pm, ImageVectorF &imageVec);
65 
66  /// Convert three adc vectors into an image vector (contains all three views)
67  void ConvertChargeVectorsToImageVector(std::vector<float> &v0pe, std::vector<float> &v1pe,
68  std::vector<float> &v2pe, ImageVector &imageVec);
69 
70  /// Float version of conversion for convenience of TF interface
71  void ConvertChargeVectorsToImageVectorF(std::vector<float> &v0pe, std::vector<float> &v1pe,
72  std::vector<float> &v2pe, ImageVectorF &imageVec);
73 
74  /// Convert a pixel array into a ImageVectorF
75  void ConvertPixelArrayToImageVectorF(const std::vector<unsigned char> &pixelArray, ImageVectorF &imageVec);
76 
77  private:
78 
79  /// Base function for conversion of the Pixel Map to our required output format
80  void ConvertChargeVectorsToViewVectors(std::vector<float> &v0pe, std::vector<float> &v1pe, std::vector<float> &v2pe,
81  ViewVector& view0, ViewVector& view1, ViewVector& view2);
82 
83  /// Make the image vector from the view vectors
84  ImageVector BuildImageVector(ViewVector v0, ViewVector v1, ViewVector v2);
85  ImageVectorF BuildImageVectorF(ViewVectorF v0, ViewVectorF v1, ViewVectorF v2);
86 
87  /// Get the minimum and maximum wires from the pixel map needed to make the image
88  void GetMinMaxWires(std::vector<float> &wireCharges, unsigned int &minWire, unsigned int &maxWire);
89 
90  /// Get the minimum and maximum tdcs from the pixel map needed to make the image
91  void GetMinMaxTDCs(std::vector<float> &tdcCharges, unsigned int &minTDC, unsigned int &maxTDC);
92 
93  /// Funtion to actually reverse the view
94  void ReverseView(std::vector<float> &peVec);
95 
96  /// Convert a ViewVector into a ViewVectorF
97  ViewVectorF ConvertViewVecToViewVecF(ViewVector view);
98 
99  /// Convert a ImageVector into a ImageVectorF
100  ImageVectorF ConvertImageVecToImageVecF(ImageVector image);
101 
102  /// Number of views of each event
103  unsigned int fNViews;
104 
105  /// Number of wires to use for the image width
106  unsigned int fNWires;
107 
108  /// Number of TDCs to use for the image height
109  unsigned int fNTDCs;
110 
111  /// Input pixel map sizes
112  unsigned int fPixelMapWires;
113  unsigned int fPixelMapTDCs;
114 
115  /// Vector of bools to decide if any views need to be reversed
116  std::vector<bool> fViewReverse;
117 
118  /// Disable the region finding?
120 
121  /// Use a log scale for charge?
123 
124  };
125 
126 }
127 
128 #endif // CVN_IMAGE_UTILS_H
std::vector< ViewVectorF > ImageVectorF
Definition: CVNImageUtils.h:21
std::vector< std::vector< float > > ViewVectorF
Definition: CVNImageUtils.h:20
ImageVectorF ConvertImageVecToImageVecF(ImageVector image)
Convert a ImageVector into a ImageVectorF.
void ConvertChargeVectorsToImageVector(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ImageVector &imageVec)
Convert three adc vectors into an image vector (contains all three views)
unsigned int fPixelMapWires
Input pixel map sizes.
void DisableRegionSelection()
Disable the selection of the wire region and just use the first 500 wires.
void ConvertChargeVectorsToPixelArray(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, std::vector< unsigned char > &pix)
void SetViewReversal(bool reverseX, bool reverseY, bool reverseZ)
Function to set any views that need reversing.
void SetLogScale(bool setLog)
Set the log scale for charge.
std::vector< ViewVector > ImageVector
Definition: CVNImageUtils.h:19
void ConvertPixelMapToPixelArray(const PixelMap &pm, std::vector< unsigned char > &pix)
Convert a Pixel Map object into a single pixel array with an image size nWire x nTDC.
void EnableRegionSelection()
Enable the selection of the wire region.
PixelMap for CVN.
Utility class for truth labels.
void ReverseView(std::vector< float > &peVec)
Funtion to actually reverse the view.
void GetMinMaxTDCs(std::vector< float > &tdcCharges, unsigned int &minTDC, unsigned int &maxTDC)
Get the minimum and maximum tdcs from the pixel map needed to make the image.
unsigned char ConvertChargeToChar(float charge)
Convert the hit charge into the range 0 to 255 required by the CVN.
ImageVector BuildImageVector(ViewVector v0, ViewVector v1, ViewVector v2)
Make the image vector from the view vectors.
void ConvertPixelMapToImageVector(const PixelMap &pm, ImageVector &imageVec)
Convert a pixel map into an image vector (contains all three views)
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.
bool fDisableRegionSelection
Disable the region finding?
void GetMinMaxWires(std::vector< float > &wireCharges, unsigned int &minWire, unsigned int &maxWire)
Get the minimum and maximum wires from the pixel map needed to make the image.
std::vector< bool > fViewReverse
Vector of bools to decide if any views need to be reversed.
void ConvertChargeVectorsToViewVectors(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, ViewVector &view0, ViewVector &view1, ViewVector &view2)
Base function for conversion of the Pixel Map to our required output format.
unsigned int fNTDCs
Number of TDCs to use for the image height.
unsigned int fNViews
Number of views of each event.
bool fUseLogScale
Use a log scale for charge?
void ConvertPixelMapToImageVectorF(const PixelMap &pm, ImageVectorF &imageVec)
Convert a pixel map into an image vector (float version)
Class containing some utility functions for all things CVN.
Definition: CVNImageUtils.h:24
ImageVectorF BuildImageVectorF(ViewVectorF v0, ViewVectorF v1, ViewVectorF v2)
void SetImageSize(unsigned int nWires, unsigned int nTDCs, unsigned int nViews)
Set up the image size that we want to have.
void ConvertPixelArrayToImageVectorF(const std::vector< unsigned char > &pixelArray, ImageVectorF &imageVec)
Convert a pixel array into a ImageVectorF.
ViewVectorF ConvertViewVecToViewVecF(ViewVector view)
Convert a ViewVector into a ViewVectorF.
unsigned int fPixelMapTDCs
unsigned int fNWires
Number of wires to use for the image width.
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:22
std::vector< std::vector< unsigned char > > ViewVector
Useful typedefs.
Definition: CVNImageUtils.h:18
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.