RegPixelMap3D.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file RegPixelMap3D.cxx
3 /// \brief RegPixelMap3D for RegCNN modifed from PixelMap.cxx
4 /// \author Wenjie Wu - wenjieww@uci.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include <cassert>
8 #include <iostream>
9 #include <ostream>
10 #include <iomanip>
12 
13 namespace cnn
14 {
15 
16  RegPixelMap3D::RegPixelMap3D(const RegCNNBoundary3D& bound, const bool& cropped, const bool& prongOnly):
17  fBound(bound),
18  fCropped(cropped),
19  fProngOnly(prongOnly),
20  fInPM(0),
21  fPE(fBound.NBins(0)*fBound.NBins(1)*fBound.NBins(2)),
22  fPECropped(32*32*32), // Fixed to 32x32x32
23  fProngTag(fBound.NBins(0)*fBound.NBins(1)*fBound.NBins(2))
24  {
28  }
29 
30  void RegPixelMap3D::AddHit(float rel_x, float rel_y, float rel_z, float charge, int hit_prong_tag)
31  {
32  if (fBound.IsWithin(rel_x, rel_y, rel_z)) {
33  fInPM = 1;
34  int xbin = x_axis.FindBin(rel_x);
35  int ybin = y_axis.FindBin(rel_y);
36  int zbin = z_axis.FindBin(rel_z);
37  fPE[LocalToIndex(xbin-1, ybin-1, zbin-1)] += charge;
38  fProngTag[LocalToIndex(xbin-1, ybin-1, zbin-1)] = hit_prong_tag;
39  }
40  }
41 
43  // fProngOnly=True means only the primary prong is selected to creat pixel maps
44  // and that prong needs to be either a muon or antimuon (FIXIT)?
45  // Caveat 1: the prong tag of that pixel is determined by the track id of the track
46  // associlated with the last hit that associated with that pixel. It means
47  // if this pixel-associated hits belong to different prongs, we could
48  // either add deposited energy from other prongs (if other prongs' hit is
49  // in the front), or throw the energy from primary prong away (if there is
50  // one or more hits from other prongs in the last). A better way could be
51  // determining the prong tag by looping the hits, instead of the pixels.
52  // That means we should create a new pixel map only with the spacepoints
53  // associated with the primary prong, instead of using the prong tag
54  // (little effect on the results, ignored for now)
55  if (fProngOnly) {
56  std::cout<<"Do Prong Only selection ......"<<std::endl;
57  for (unsigned int i_p= 0; i_p< fPE.size(); ++i_p) {
58  if (fProngTag[i_p] != 0)
59  fPE[i_p] = 0;
60  } // end of i_p
61  } // end of fProngOnly
62 
63  if (fCropped) {
64  std::cout<<"Crop pixel size to 32x32x32 ......"<<std::endl;
65  int cropped_xbin_low = 50 - 16; //int cropped_xbin_high = 50 + 16;
66  int cropped_ybin_low = 50 - 16; //int cropped_ybin_high = 50 + 16;
67  int cropped_zbin_low = 0; //int cropped_zbin_high = 32;
68  for (int i_x= 0; i_x< 32; ++i_x) {
69  for (int i_y= 0; i_y< 32; ++i_y) {
70  for (int i_z= 0; i_z< 32; ++i_z) {
71  int cropped_index = i_x*32*32 + i_y*32 + i_z%32;
72  int ii_x = i_x + cropped_xbin_low;
73  int ii_y = i_y + cropped_ybin_low;
74  int ii_z = i_z + cropped_zbin_low;
75  int index = LocalToIndex(ii_x, ii_y, ii_z);
76  fPECropped[cropped_index] = fPE[index];
77  } // end of i_z
78  } // end of i_y
79  } // end of i_x
80  } // end of fCropped
81  }
82 
83  unsigned int RegPixelMap3D::LocalToIndex(const unsigned int& bin_x,
84  const unsigned int& bin_y, const unsigned int& bin_z) const
85  {
86  unsigned int index = bin_x*fBound.NBins(1)*fBound.NBins(2) + bin_y*fBound.NBins(2) + bin_z%fBound.NBins(2);
87  assert(index < fPE.size());
88  return index;
89  }
90 
91  TH3F* RegPixelMap3D::ToTH3() const {
92  // Create a histogram
93  TH3F* hist = new TH3F("RegPixelMap3D", "X:Y:Z", fBound.NBins(0), fBound.StartPos(0), fBound.StopPos(0),
96  for (int ix= 0; ix< fBound.NBins(0); ++ix) {
97  for (int iy= 0; iy< fBound.NBins(1); ++iy) {
98  for (int iz= 0; iz< fBound.NBins(2); ++iz) {
99  hist->SetBinContent(ix+1, iy+1, iz+1, fPE[LocalToIndex(ix, iy, iz)]);
100  }
101  }
102  }
103  return hist;
104  }
105 
107  // Create a histogram
108  TH3F* hist = new TH3F("RegCroppedPixelMap3D", "X:Y:Z", 32, 0, 32*x_axis.GetBinWidth(0),
109  32, 0, 32*y_axis.GetBinWidth(0),
110  32, 0, 32*z_axis.GetBinWidth(0));
111  for (int ix= 0; ix< 32; ++ix) {
112  for (int iy= 0; iy< 32; ++iy) {
113  for (int iz= 0; iz< 32; ++iz) {
114  int cropped_index = ix*32*32 + iy*32 + iz%32;
115  hist->SetBinContent(ix+1, iy+1, iz+1, fPECropped[cropped_index]);
116  }
117  }
118  }
119  return hist;
120  }
121 
122  std::ostream& operator<<(std::ostream& os, const RegPixelMap3D& m)
123  {
124  os << "RegPixelMap3D...... ";
125  return os;
126  }
127 }
TH3F * ToCroppedTH3() const
std::vector< int > fProngTag
Definition: RegPixelMap3D.h:50
TH3F * ToTH3() const
float StopPos(const unsigned int &axis) const
bool IsWithin(const float &rel_x, const float &rel_y, const float &rel_z)
float StartPos(const unsigned int &axis) const
unsigned int LocalToIndex(const unsigned int &bin_x, const unsigned int &bin_y, const unsigned int &bin_z) const
std::vector< float > fPE
Definition: RegPixelMap3D.h:48
int NBins(const unsigned int &axis) const
RegPixelMap3D for RegCNN modified from PixelMap.h.
Defines an enumeration for cellhit classification.
RegCNNBoundary3D fBound
Definition: RegPixelMap3D.h:44
void AddHit(float rel_x, float rel_y, float rel_z, float charge, int hit_prong_tag)
std::ostream & operator<<(std::ostream &os, const RegPixelMap3DProducer &p)
unsigned int fInPM
Definition: RegPixelMap3D.h:47
RegPixelMap3D, input to 3D CNN neural net.
Definition: RegPixelMap3D.h:22
std::vector< float > fPECropped
Definition: RegPixelMap3D.h:49
QTextStream & endl(QTextStream &s)