LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PhotonLibraryAnalyzer_module.cc
Go to the documentation of this file.
1 //
2 // Name: PhotonLibraryAnalyzer.h
3 //
4 //
5 // Ben Jones, MIT, April 2012
6 // bjpjones@mit.edu
7 //
9 #include "larcorealg/CoreUtils/DumpUtils.h" // lar::dump::vector3D()
12 
16 #include "art_root_io/TFileService.h"
17 #include "fhiclcpp/ParameterSet.h"
19 
20 #include "TH1D.h"
21 #include "TH2D.h"
22 #include "TH3D.h"
23 
24 #include <iostream>
25 
26 namespace phot {
27 
29  public:
30  // Constructors, destructor
31 
32  explicit PhotonLibraryAnalyzer(fhicl::ParameterSet const& pset);
33 
34  // Overrides.
35 
36  void beginJob();
37  void analyze(const art::Event& evt);
38 
39  private:
40  std::string fAltXAxis;
41  int fOpDet;
42  bool fEachSlice;
44  };
45 
46 }
47 
48 namespace phot {
49 
50  //----------------------------------------------------------------------------
52  : EDAnalyzer(pset)
53  , fAltXAxis{pset.get<std::string>("alt_x_axis")}
54  , fOpDet{pset.get<int>("opdet")}
55  , fEachSlice{pset.get<bool>("each_slice")}
56  , fEachDetector{pset.get<bool>("each_detector")}
57  {
58  std::cout << "Photon library analyzer constructor " << std::endl;
59  }
60 
61  //----------------------------------------------------------------------------
63 
64  {
65  mf::LogInfo("PhotonLibraryAnalyzer") << "Analyzing photon library - begin" << std::endl;
66 
70 
71  int NOpDet = pvs->NOpChannels();
72 
73  sim::PhotonVoxelDef TheVoxelDef = pvs->GetVoxelDef();
74  auto const& UpperCorner = TheVoxelDef.GetRegionUpperCorner();
75  auto const& LowerCorner = TheVoxelDef.GetRegionLowerCorner();
76 
77  mf::LogInfo("PhotonLibraryAnalyzer")
78  << "UpperCorner: " << lar::dump::vector3D(UpperCorner) << "\n"
79  << "LowerCorner: " << lar::dump::vector3D(LowerCorner);
80 
81  auto const [XSteps, YSteps, ZSteps] = TheVoxelDef.GetSteps(); // unsigned int
82 
83  // for c2: FullVolume is unused, just call tfs->make
84  // TH3D *FullVolume = tfs->make<TH3D>("FullVolume","FullVolume",
85  tfs->make<TH3D>("FullVolume",
86  "FullVolume",
87  XSteps,
88  LowerCorner.X(),
89  UpperCorner.X(),
90  YSteps,
91  LowerCorner.Y(),
92  UpperCorner.Y(),
93  ZSteps,
94  LowerCorner.Z(),
95  UpperCorner.Z());
96 
97  int reportnum = 10000;
98 
99  int newX, newY;
100  if (fAltXAxis == "Z") {
101  newX = 2; // Z
102  newY = 1; // Y
103  }
104  else {
105  newX = 1; // Y
106  newY = 2; // Z
107  }
108 
109  mf::LogInfo("PhotonLibraryAnalyzer")
110  << "Analyzing photon library - making historams" << std::endl;
111 
112  TH2D* XProjection;
113  if (fAltXAxis == "Z")
114  XProjection =
115  tfs->make<TH2D>("XProjection", "XProjection", ZSteps, 0, ZSteps, YSteps, 0, YSteps);
116  else
117  XProjection =
118  tfs->make<TH2D>("XProjection", "XProjection", YSteps, 0, YSteps, ZSteps, 0, ZSteps);
119  TH2D* YProjection =
120  tfs->make<TH2D>("YProjection", "YProjection", XSteps, 0, XSteps, ZSteps, 0, ZSteps);
121  TH2D* ZProjection =
122  tfs->make<TH2D>("ZProjection", "ZProjection", XSteps, 0, XSteps, YSteps, 0, YSteps);
123 
124  // TH1D * PMTsNoVisibility = tfs->make<TH1D>("PMTsNoVisibility","PMTsNoVisibility", NOpDet,0,NOpDet);
125 
126  TH1D* VisByN = tfs->make<TH1D>("VisByN", "VisByN", NOpDet, 0, NOpDet);
127 
128  TH2D* XInvisibles;
129  if (fAltXAxis == "Z")
130  XInvisibles =
131  tfs->make<TH2D>("XInvisibles", "XInvisibles", ZSteps, 0, ZSteps, YSteps, 0, YSteps);
132  else
133  XInvisibles =
134  tfs->make<TH2D>("XInvisibles", "XInvisibles", YSteps, 0, YSteps, ZSteps, 0, ZSteps);
135  TH2D* YInvisibles =
136  tfs->make<TH2D>("YInvisibles", "YInvisibles", XSteps, 0, XSteps, ZSteps, 0, ZSteps);
137  TH2D* ZInvisibles =
138  tfs->make<TH2D>("ZInvisibles", "ZInvisibles", XSteps, 0, XSteps, YSteps, 0, YSteps);
139 
140  std::vector<TH2D*> TheXCrossSections;
141  std::vector<TH2D*> TheYCrossSections;
142  std::vector<TH2D*> TheZCrossSections;
143  if (fEachSlice) {
144 
145  for (unsigned int i = 0; i != XSteps; ++i) {
146  std::stringstream ss("");
147  ss.flush();
148  ss << "projX" << i;
149  if (fAltXAxis == "Z")
150  TheXCrossSections.push_back(tfs->make<TH2D>(
151  ss.str().c_str(), ss.str().c_str(), ZSteps, 0, ZSteps, YSteps, 0, YSteps));
152  else
153  TheXCrossSections.push_back(tfs->make<TH2D>(
154  ss.str().c_str(), ss.str().c_str(), YSteps, 0, YSteps, ZSteps, 0, ZSteps));
155  }
156 
157  for (unsigned int i = 0; i != YSteps; ++i) {
158  std::stringstream ss("");
159  ss.flush();
160  ss << "projY" << i;
161  TheYCrossSections.push_back(tfs->make<TH2D>(
162  ss.str().c_str(), ss.str().c_str(), XSteps, 0, XSteps, ZSteps, 0, ZSteps));
163  }
164 
165  for (unsigned int i = 0; i != ZSteps; ++i) {
166  std::stringstream ss("");
167  ss.flush();
168  ss << "projZ" << i;
169  TheZCrossSections.push_back(tfs->make<TH2D>(
170  ss.str().c_str(), ss.str().c_str(), XSteps, 0, XSteps, YSteps, 0, YSteps));
171  }
172  }
173 
174  std::vector<TH2D*> TheXProjections;
175  std::vector<TH2D*> TheYProjections;
176  std::vector<TH2D*> TheZProjections;
177 
178  if (fEachDetector) {
179 
180  mf::LogInfo("PhotonLibraryAnalyzer")
181  << "Making projections for each of " << NOpDet << " photon detectors" << std::endl;
182 
183  for (int i = 0; i < NOpDet; ++i) {
184  char ss[99];
185 
186  sprintf(ss, "ProjXOpDet%d", i);
187  if (fAltXAxis == "Z")
188  TheXProjections.push_back(tfs->make<TH2D>(ss, ss, ZSteps, 0, ZSteps, YSteps, 0, YSteps));
189  else
190  TheXProjections.push_back(tfs->make<TH2D>(ss, ss, YSteps, 0, YSteps, ZSteps, 0, ZSteps));
191 
192  sprintf(ss, "ProjYOpDet%d", i);
193  TheYProjections.push_back(tfs->make<TH2D>(ss, ss, XSteps, 0, XSteps, ZSteps, 0, ZSteps));
194 
195  sprintf(ss, "ProjZOpDet%d", i);
196  TheZProjections.push_back(tfs->make<TH2D>(ss, ss, XSteps, 0, XSteps, YSteps, 0, YSteps));
197  }
198  }
199 
200  mf::LogInfo("PhotonLibraryAnalyzer")
201  << "Analyzing photon library - running through voxels " << std::endl;
202 
203  for (unsigned int i = 0; i != TheVoxelDef.GetNVoxels(); ++i) {
204  if (i % reportnum == 0) std::cout << "Photon library analyzer at voxel " << i << std::endl;
205 
206  auto const Coords = TheVoxelDef.GetVoxelCoords(i);
207 
208  const float* Visibilities = pvs->GetLibraryEntries(i);
209  size_t NOpChannels = pvs->NOpChannels();
210 
211  float TotalVis = 0;
212  if (fOpDet < 0) {
213  for (size_t ichan = 0; ichan != NOpChannels; ++ichan) {
214  TotalVis += Visibilities[ichan];
215  }
216  }
217  else {
218  TotalVis = Visibilities[fOpDet];
219  }
220 
221  VisByN->Fill(NOpChannels);
222 
223  if (TotalVis == 0) {
224  XInvisibles->Fill(Coords[newX], Coords[newY]);
225  YInvisibles->Fill(Coords[0], Coords[2]);
226  ZInvisibles->Fill(Coords[0], Coords[1]);
227  }
228 
229  if (fEachSlice) {
230  TheXCrossSections.at(Coords.at(0))->Fill(Coords[newX], Coords[newY], TotalVis);
231  TheYCrossSections.at(Coords.at(1))->Fill(Coords[0], Coords[2], TotalVis);
232  TheZCrossSections.at(Coords.at(2))->Fill(Coords[0], Coords[1], TotalVis);
233  }
234 
235  if (fEachDetector) {
236  for (size_t ichan = 0; ichan != NOpChannels; ++ichan) {
237  TheXProjections.at(ichan)->Fill(Coords[newX], Coords[newY], Visibilities[ichan]);
238  TheYProjections.at(ichan)->Fill(Coords[0], Coords[2], Visibilities[ichan]);
239  TheZProjections.at(ichan)->Fill(Coords[0], Coords[1], Visibilities[ichan]);
240  }
241  }
242 
243  // Always make the summed projections
244  XProjection->Fill(Coords[newX], Coords[newY], TotalVis);
245  YProjection->Fill(Coords[0], Coords[2], TotalVis);
246  ZProjection->Fill(Coords[0], Coords[1], TotalVis);
247  }
248 
249  mf::LogInfo("PhotonLibraryAnalyzer") << "Analyzing photon library - end" << std::endl;
250  }
251 
252  //----------------------------------------------------------------------------
254 
255 }
256 
257 namespace phot {
259 }
Definitions of voxel data structures.
auto vector3D(Vector3D const &v)
Returns a manipulator which will print the specified vector.
Definition: DumpUtils.h:326
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
TNtupleSim Fill(f1, f2, f3, f4)
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
PhotonLibraryAnalyzer(fhicl::ParameterSet const &pset)
std::array< int, 3U > GetVoxelCoords(int ID) const
Utilities to dump objects into a stream.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
decltype(auto) GetRegionUpperCorner() const
Returns the volume vertex (type Point) with the highest coordinates.
T get(std::string const &key) const
Definition: ParameterSet.h:314
General LArSoft Utilities.
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
std::array< unsigned int, 3U > GetSteps() const
Returns the number of voxels along each of the three dimensions.
TCEvent evt
Definition: DataStructs.cxx:8
Eigen::Vector3f Coords
Definition: DCEL.h:44
art framework interface to geometry description
decltype(auto) GetRegionLowerCorner() const
Returns the volume vertex (type Point) with the lowest coordinates.