41 float centreScale = 0.7;
43 float scaleFrac = (log(charge) / log(1000));
44 truncateCorr = ceil(centreScale * scaleFrac * 255.0);
47 peCorrChunk = (1000.) / 255.0;
48 truncateCorr = ceil((charge) / (peCorrChunk));
50 if (truncateCorr > 255)
51 return (
unsigned char)255;
53 return (
unsigned char)truncateCorr;
70 if (reverseViews.size() != 3) {
71 std::cout <<
"Expected three views for view reversals... using defaults." << std::endl;
91 std::vector<unsigned char>& pix)
97 std::vector<float> v0pe = pm.
fPEX;
98 std::vector<float> v1pe = pm.
fPEY;
99 std::vector<float> v2pe = pm.
fPEZ;
105 std::vector<float>& v1pe,
106 std::vector<float>& v2pe,
107 std::vector<unsigned char>& pix)
117 for (
unsigned int view = 0; view <
fNViews; ++view) {
118 for (
unsigned int wire = 0; wire <
fNWires; ++wire) {
119 for (
unsigned int time = 0; time <
fNTDCs; ++time) {
121 unsigned char val = 0;
123 if (view == 0) { val = view0[wire][time]; }
124 if (view == 1) { val = view1[wire][time]; }
125 if (view == 2) { val = view2[wire][time]; }
128 unsigned int i = time + fNTDCs * (wire + fNWires * view);
144 std::vector<float> v0pe = pm.
fPEX;
145 std::vector<float> v1pe = pm.
fPEY;
146 std::vector<float> v2pe = pm.
fPEZ;
158 std::vector<float> v0pe = pm.
fPEX;
159 std::vector<float> v1pe = pm.
fPEY;
160 std::vector<float> v2pe = pm.
fPEZ;
166 std::vector<float>& v1pe,
167 std::vector<float>& v2pe,
183 std::vector<float>& v1pe,
184 std::vector<float>& v2pe,
205 std::vector<float>& v1pe,
206 std::vector<float>& v2pe,
218 std::vector<std::vector<float>> wireCharges;
219 for (
unsigned int view = 0; view <
fNViews; ++view) {
221 std::vector<float> tempChargeVec;
227 unsigned int element = time + fPixelMapTDCs * wire;
228 if (view == 0) { val = v0pe[element]; }
229 if (view == 1) { val = v1pe[element]; }
230 if (view == 2) { val = v2pe[element]; }
233 tempChargeVec.push_back(totCharge);
235 wireCharges.push_back(tempChargeVec);
239 std::vector<std::vector<float>> tdcCharges;
240 for (
unsigned int view = 0; view <
fNViews; ++view) {
242 std::vector<float> tempChargeVec;
249 unsigned int element = time + fPixelMapTDCs * wire;
250 if (view == 0) { val = v0pe[element]; }
251 if (view == 1) { val = v1pe[element]; }
252 if (view == 2) { val = v2pe[element]; }
255 tempChargeVec.push_back(totCharge);
257 tdcCharges.push_back(tempChargeVec);
262 std::vector<unsigned int> imageStartWire(3, 0);
263 std::vector<unsigned int> imageEndWire(3, 0);
265 std::vector<unsigned int> imageStartTDC(3, 0);
266 std::vector<unsigned int> imageEndTDC(3, 0);
270 for (
unsigned int view = 0; view < wireCharges.size(); ++view) {
271 GetMinMaxWires(wireCharges[view], imageStartWire[view], imageEndWire[view]);
272 GetMinMaxTDCs(tdcCharges[view], imageStartTDC[view], imageEndTDC[view]);
278 for (
unsigned int i = 0; i < imageStartWire.size(); ++i) {
279 imageStartWire[i] = 0;
281 imageStartTDC[i] = 0;
287 for (
unsigned int view = 0; view <
fNViews; ++view) {
289 for (
unsigned int wire = imageStartWire[view]; wire <= imageEndWire[view]; ++wire) {
290 std::vector<unsigned char> wireTDCVec;
291 for (
unsigned int time = imageStartTDC[view]; time <= imageEndTDC[view]; ++time) {
297 unsigned char val = 0;
301 wireTDCVec.push_back(val);
303 viewChargeVec.push_back(wireTDCVec);
305 if (view == 0) view0 = viewChargeVec;
306 if (view == 1) view1 = viewChargeVec;
307 if (view == 2) view2 = viewChargeVec;
314 const std::vector<unsigned char>& pixelArray,
324 for (
unsigned int v = 0; v <
fNViews; ++v) {
326 std::vector<float> wireVec;
327 for (
unsigned int t = 0; t <
fNTDCs; ++t) {
328 unsigned int index = t + fNTDCs * (
w + fNWires * v);
329 wireVec.push_back(pixelArray[index]);
331 if (v == 0) view0.push_back(wireVec);
332 if (v == 1) view1.push_back(wireVec);
333 if (v == 2) view2.push_back(wireVec);
341 unsigned int& minWire,
342 unsigned int& maxWire)
348 for (
unsigned int wire = 0; wire < wireCharges.size(); ++wire) {
351 if (wireCharges.size() - wire ==
fNWires) {
break; }
355 for (
unsigned int nextWire = wire + 1; nextWire <= wire + 20; ++nextWire) {
356 if (wireCharges[nextWire] == 0.0) ++nEmpty;
366 float maxCharge = 0.;
367 unsigned int firstWire = 0;
368 for (
unsigned int wire = 0; wire < wireCharges.size() -
fNWires; ++wire) {
369 float windowCharge = 0.;
370 for (
unsigned int nextwire = wire; nextwire < wire +
fNWires; ++nextwire) {
371 windowCharge += wireCharges[nextwire];
373 if (windowCharge > maxCharge) {
374 maxCharge = windowCharge;
379 maxWire = firstWire +
fNWires - 1;
382 <<
"Used alternate method to get min and max wires due to vertex determination failure: " 383 << minWire <<
", " << maxWire << std::endl;
387 unsigned int& minTDC,
388 unsigned int& maxTDC)
394 for (
unsigned int tdc = 0; tdc < tdcCharges.size(); ++tdc) {
397 if (tdcCharges.size() - tdc ==
fNTDCs) {
break; }
401 for (
unsigned int nextTDC = tdc + 1; nextTDC <= tdc + 20; ++nextTDC) {
402 if (tdcCharges[nextTDC] == 0.0) ++nEmpty;
406 maxTDC = tdc +
fNTDCs - 1;
413 float maxCharge = 0.;
414 unsigned int firstTDC = 0;
415 for (
unsigned int tdc = 0; tdc < tdcCharges.size() -
fNTDCs; ++tdc) {
416 float windowCharge = 0.;
417 for (
unsigned int nexttdc = tdc; nexttdc < tdc +
fNTDCs; ++nexttdc) {
418 windowCharge += tdcCharges[nexttdc];
420 if (windowCharge > maxCharge) {
421 maxCharge = windowCharge;
426 maxTDC = firstTDC +
fNTDCs - 1;
428 std::cout <<
"Used alternate method to get min and max tdcs due to vertex determination failure: " 429 << minTDC <<
", " << maxTDC << std::endl;
435 std::vector<float> vecCopy(peVec.size(), 0.);
439 unsigned int newPlane = fPixelMapWires -
w - 1;
442 float val = peVec[t + fPixelMapTDCs *
w];
443 vecCopy[t + fPixelMapTDCs * newPlane] = val;
448 peVec = move(vecCopy);
455 newVec.reserve(view.size());
456 for (
size_t w = 0;
w < view.size(); ++
w) {
457 std::vector<float> thisWire;
458 thisWire.reserve(view[
w].
size());
459 for (
size_t t = 0; t < view[
w].size(); ++t) {
460 float chargeSC =
static_cast<float>(view[
w][t]);
461 thisWire.push_back(chargeSC);
463 newVec.push_back(move(thisWire));
472 newImage.reserve(image.size());
473 for (
size_t w = 0;
w < image.size(); ++
w) {
475 thisWire.reserve(image[
w].
size());
476 for (
size_t t = 0; t < image[
w].size(); ++t) {
477 std::vector<float> thisTime;
478 thisTime.reserve(image[
w][t].
size());
479 for (
size_t v = 0; v < image[
w][t].size(); ++v) {
480 float chargeSC =
static_cast<float>(image[
w][t][v]);
481 thisTime.push_back(chargeSC);
483 thisWire.push_back(move(thisTime));
485 newImage.push_back(move(thisWire));
497 image.reserve(v0.size());
498 for (
unsigned int w = 0;
w < v0.size(); ++
w) {
499 std::vector<std::vector<unsigned char>> wireVec;
500 wireVec.reserve(v0[0].
size());
501 for (
unsigned int t = 0; t < v0[0].size(); ++t) {
502 std::vector<unsigned char> timeVec;
503 timeVec.push_back(v0[
w][t]);
504 timeVec.push_back(v1[
w][t]);
505 timeVec.push_back(v2[
w][t]);
506 wireVec.push_back(move(timeVec));
508 image.push_back(move(wireVec));
521 image.reserve(v0.size());
522 for (
unsigned int w = 0;
w < v0.size(); ++
w) {
523 std::vector<std::vector<float>> wireVec;
524 wireVec.reserve(v0[0].
size());
525 for (
unsigned int t = 0; t < v0[0].size(); ++t) {
526 std::vector<float> timeVec;
527 timeVec.push_back(v0[
w][t]);
528 timeVec.push_back(v1[
w][t]);
529 timeVec.push_back(v2[
w][t]);
530 wireVec.push_back(move(timeVec));
532 image.push_back(move(wireVec));
ImageVectorF BuildImageVectorF(ViewVectorF &v0, ViewVectorF &v1, ViewVectorF &v2)
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.
void ConvertChargeVectorsToPixelArray(std::vector< float > &v0pe, std::vector< float > &v1pe, std::vector< float > &v2pe, std::vector< unsigned char > &pix)
unsigned int fPixelMapTDCs
ViewVectorF ConvertViewVecToViewVecF(ViewVector &view)
Convert a ViewVector into a ViewVectorF.
void ConvertPixelArrayToImageVectorF(const std::vector< unsigned char > &pixelArray, ImageVectorF &imageVec)
Convert a pixel array into a ImageVectorF.
std::vector< std::vector< unsigned char > > ViewVector
Useful typedefs.
void ReverseView(std::vector< float > &peVec)
Funtion to actually reverse the view.
PixelMap, basic input to CVN neural net.
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 ConvertPixelMapToImageVectorF(const PixelMap &pm, ImageVectorF &imageVec)
Convert a pixel map into an image vector (float version)
bool fDisableRegionSelection
Disable the region finding?
unsigned char ConvertChargeToChar(float charge)
Convert the hit charge into the range 0 to 255 required by the CVN.
void SetLogScale(bool setLog)
Set the log scale for charge.
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::vector< float > fPEX
Vector of X PE measurements for pixels.
Utilities for producing images for the CVN.
bool fUseLogScale
Use a log scale for charge?
unsigned int NWire() const
Length in wires.
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.
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.
std::vector< ViewVector > ImageVector
unsigned int fNViews
Number of views of each event.
unsigned int fNTDCs
Number of TDCs to use for the image height.
ImageVector BuildImageVector(ViewVector &v0, ViewVector &v1, ViewVector &v2)
Make the image vector from the view vectors.
std::vector< float > fPEZ
Vector of Y PE measurements for pixels.
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)
void EnableRegionSelection()
Enable the selection of the wire region.
ImageVectorF ConvertImageVecToImageVecF(ImageVector &image)
Convert a ImageVector into a ImageVectorF.
unsigned int fPixelMapWires
Input pixel map sizes.
std::vector< std::vector< float > > ViewVectorF
void DisableRegionSelection()
Disable the selection of the wire region and just use the first 500 wires.
std::vector< bool > fViewReverse
Vector of bools to decide if any views need to be reversed.
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.
unsigned int NTdc() const
Width in tdcs.
std::vector< ViewVectorF > ImageVectorF
unsigned int fNWires
Number of wires to use for the image width.
void ConvertPixelMapToImageVector(const PixelMap &pm, ImageVector &imageVec)
Convert a pixel map into an image vector (contains all three views)
void SetImageSize(unsigned int nWires, unsigned int nTDCs, unsigned int nViews)
Set up the image size that we want to have.
std::vector< float > fPEY
Vector of Y PE measurements for pixels.
void SetViewReversal(bool reverseX, bool reverseY, bool reverseZ)
Function to set any views that need reversing.