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