39 float centreScale = 0.7;
41 float scaleFrac=(log(charge)/log(1000));
42 truncateCorr= ceil(centreScale*scaleFrac*255.0);
45 peCorrChunk = (1000.) / 255.0;
46 truncateCorr = ceil((charge)/(peCorrChunk));
48 if (truncateCorr > 255)
return (
unsigned char)255;
49 else return (
unsigned char)truncateCorr;
64 if(reverseViews.size() != 3){
65 std::cout <<
"Expected three views for view reversals... using defaults." <<
std::endl;
87 std::vector<float> v0pe = pm.
fPEX;
88 std::vector<float> v1pe = pm.
fPEY;
89 std::vector<float> v2pe = pm.
fPEZ;
97 std::vector<float> &v2pe, std::vector<unsigned char> &pix){
106 for (
unsigned int view = 0; view <
fNViews; ++view){
107 for (
unsigned int wire = 0; wire <
fNWires; ++wire){
110 unsigned char val = 0;
112 if(view == 0 ){ val = view0[wire][
time]; }
113 if(view == 1 ){ val = view1[wire][
time]; }
114 if(view == 2 ){ val = view2[wire][
time]; }
117 unsigned int i =
time + fNTDCs * (wire + fNWires * view);
133 std::vector<float> v0pe = pm.
fPEX;
134 std::vector<float> v1pe = pm.
fPEY;
135 std::vector<float> v2pe = pm.
fPEZ;
145 std::vector<float> v0pe = pm.
fPEX;
146 std::vector<float> v1pe = pm.
fPEY;
147 std::vector<float> v2pe = pm.
fPEZ;
195 std::vector< std::vector<float> > wireCharges;
196 for (
unsigned int view = 0; view <
fNViews; ++view){
198 std::vector<float> tempChargeVec;
204 unsigned int element =
time + fPixelMapTDCs * wire;
205 if(view == 0 ){ val = v0pe[element]; }
206 if(view == 1 ){ val = v1pe[element]; }
207 if(view == 2 ){ val = v2pe[element]; }
210 tempChargeVec.push_back(totCharge);
212 wireCharges.push_back(tempChargeVec);
216 std::vector< std::vector<float> > tdcCharges;
217 for (
unsigned int view = 0; view <
fNViews; ++view){
219 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 tdcCharges.push_back(tempChargeVec);
240 std::vector<unsigned int> imageStartWire(3,0);
241 std::vector<unsigned int> imageEndWire(3,0);
243 std::vector<unsigned int> imageStartTDC(3,0);
244 std::vector<unsigned int> imageEndTDC(3,0);
248 for(
unsigned int view = 0; view < wireCharges.size(); ++view){
249 GetMinMaxWires(wireCharges[view],imageStartWire[view],imageEndWire[view]);
250 GetMinMaxTDCs(tdcCharges[view],imageStartTDC[view],imageEndTDC[view]);
259 for(
unsigned int i = 0; i < imageStartWire.size(); ++i){
260 imageStartWire[i] = 0;
262 imageStartTDC[i] = 0;
268 for (
unsigned int view = 0; view <
fNViews; ++view){
270 for (
unsigned int wire = imageStartWire[view]; wire <= imageEndWire[view]; ++wire){
271 std::vector<unsigned char> wireTDCVec;
272 for (
unsigned int time = imageStartTDC[view];
time <= imageEndTDC[view]; ++
time){
278 unsigned char val = 0;
282 wireTDCVec.push_back(val);
284 viewChargeVec.push_back(wireTDCVec);
286 if(view == 0) view0 = viewChargeVec;
287 if(view == 1) view1 = viewChargeVec;
288 if(view == 2) view2 = viewChargeVec;
303 for(
unsigned int v = 0; v <
fNViews; ++v){
305 std::vector<float> wireVec;
306 for(
unsigned int t = 0;
t <
fNTDCs; ++
t){
307 unsigned int index =
t + fNTDCs*(
w + fNWires*v);
308 wireVec.push_back(pixelArray[index]);
310 if(v==0) view0.push_back(wireVec);
311 if(v==1) view1.push_back(wireVec);
312 if(v==2) view2.push_back(wireVec);
325 for(
unsigned int wire = 0; wire < wireCharges.size(); ++wire){
328 if(wireCharges.size() - wire ==
fNWires){
334 for(
unsigned int nextWire = wire + 1; nextWire <= wire + 20; ++nextWire){
335 if(wireCharges[nextWire] == 0.0) ++nEmpty;
346 float maxCharge = 0.;
347 unsigned int firstWire = 0;
348 for(
unsigned int wire = 0; wire < wireCharges.size() -
fNWires; ++wire){
349 float windowCharge = 0.;
350 for(
unsigned int nextwire = wire; nextwire < wire +
fNWires; ++nextwire){
351 windowCharge += wireCharges[nextwire];
353 if(windowCharge > maxCharge){
354 maxCharge = windowCharge;
359 maxWire = firstWire +
fNWires - 1;
361 std::cout <<
"Used alternate method to get min and max wires due to vertex determination failure: " << minWire <<
", " << maxWire <<
std::endl;
370 for(
unsigned int tdc = 0; tdc < tdcCharges.size(); ++tdc){
373 if(tdcCharges.size() - tdc ==
fNTDCs){
379 for(
unsigned int nextTDC = tdc + 1; nextTDC <= tdc + 20; ++nextTDC){
380 if(tdcCharges[nextTDC] == 0.0) ++nEmpty;
384 maxTDC = tdc +
fNTDCs - 1;
391 float maxCharge = 0.;
392 unsigned int firstTDC = 0;
393 for(
unsigned int tdc = 0; tdc < tdcCharges.size() -
fNTDCs; ++tdc){
394 float windowCharge = 0.;
395 for(
unsigned int nexttdc = tdc; nexttdc < tdc +
fNTDCs; ++nexttdc){
396 windowCharge += tdcCharges[nexttdc];
398 if(windowCharge > maxCharge){
399 maxCharge = windowCharge;
404 maxTDC = firstTDC +
fNTDCs - 1;
406 std::cout <<
"Used alternate method to get min and max tdcs due to vertex determination failure: " << minTDC <<
", " << maxTDC <<
std::endl;
413 std::vector<float> vecCopy(peVec.size(),0.);
418 unsigned int newPlane = fPixelMapWires -
w - 1;
422 float val = peVec[
t + fPixelMapTDCs *
w];
423 vecCopy[
t + fPixelMapTDCs * newPlane] =
val;
428 for(
unsigned int e = 0;
e < peVec.size(); ++
e){
429 float val = vecCopy[
e];
438 for(
size_t w = 0;
w < view.size(); ++
w){
439 std::vector<float> thisWire;
440 for(
size_t t = 0;
t < view[
w].size(); ++
t){
441 float chargeSC =
static_cast<float>(view[
w][
t]);
442 thisWire.push_back(chargeSC);
444 newVec.push_back(thisWire);
452 for(
size_t w = 0;
w < image.size(); ++
w){
454 for(
size_t t = 0;
t < image[
w].size(); ++
t){
455 std::vector<float> thisTime;
456 for(
size_t v = 0; v < image[
w][
t].size(); ++v){
457 float chargeSC =
static_cast<float>(image[
w][
t][v]);
458 thisTime.push_back(chargeSC);
460 thisWire.push_back(thisTime);
462 newImage.push_back(thisWire);
471 for(
unsigned int w = 0;
w < v0.size(); ++
w){
472 std::vector<std::vector<unsigned char> > wireVec;
473 for(
unsigned int t = 0;
t < v0[0].size(); ++
t){
474 std::vector<unsigned char> timeVec;
475 timeVec.push_back(v0[
w][
t]);
476 timeVec.push_back(v1[
w][t]);
477 timeVec.push_back(v2[
w][t]);
478 wireVec.push_back(timeVec);
480 image.push_back(wireVec);
491 for(
unsigned int w = 0;
w < v0.size(); ++
w){
492 std::vector<std::vector<float> > wireVec;
493 for(
unsigned int t = 0;
t < v0[0].size(); ++
t){
494 std::vector<float> timeVec;
495 timeVec.push_back(v0[
w][
t]);
496 timeVec.push_back(v1[
w][t]);
497 timeVec.push_back(v2[
w][t]);
498 wireVec.push_back(timeVec);
500 image.push_back(wireVec);
std::vector< ViewVectorF > ImageVectorF
std::vector< std::vector< float > > ViewVectorF
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.
std::vector< float > fPEY
Vector of Y PE measurements for pixels.
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)
unsigned int fNWire
Number of wires, length of pixel map.
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
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.
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.
std::vector< float > fPEZ
Vector of Y PE measurements for pixels.
void ConvertPixelMapToImageVector(const PixelMap &pm, ImageVector &imageVec)
Convert a pixel map into an image vector (contains all three views)
Utilities for producing images for the CVN.
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< float > fPEX
Vector of X PE measurements for pixels.
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)
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.
std::vector< std::vector< unsigned char > > ViewVector
Useful typedefs.
unsigned int fNTdc
Number of tdcs, width of pixel map.
QTextStream & endl(QTextStream &s)
void SetPixelMapSize(unsigned int nWires, unsigned int nTDCs)
Set the input pixel map size.