LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
PhotonLibraryAnalyzer_module.cc
Go to the documentation of this file.
1 #ifndef PHOTLIBANALYZER_H
2 #define PHOTLIBANALYZER_H
3 
4 //
5 // Name: PhotonLibraryAnalyzer.h
6 //
7 //
8 // Ben Jones, MIT, April 2012
9 // bjpjones@mit.edu
10 //
11 #include <iostream>
12 #include <vector>
13 
20 
25 
26 #include "TH1D.h"
27 #include "TH2D.h"
28 #include "TH3D.h"
29 
30 namespace phot {
31 
33  {
34  public:
35 
36  // Constructors, destructor
37 
38  explicit PhotonLibraryAnalyzer(fhicl::ParameterSet const& pset);
39  virtual ~PhotonLibraryAnalyzer();
40 
41  // Overrides.
42 
43  void reconfigure(fhicl::ParameterSet const& pset);
44  void beginJob();
45  void analyze(const art::Event& evt);
46 
47  void endJob();
48 
49 
50 
51  private:
52  std::string fAltXAxis;
53  int fOpDet;
54  bool fEachSlice;
56  };
57 
58 }
59 
60 #endif
61 
62 namespace phot {
63 
64  //----------------------------------------------------------------------------
66  : EDAnalyzer(pset)
67  {
68  reconfigure(pset);
69  std::cout<<"Photon library analyzer constructor "<<std::endl;
70  }
71 
72  //----------------------------------------------------------------------------
74  {
75  }
76 
77  //----------------------------------------------------------------------------
79  {
80  fAltXAxis = pset.get<std::string>("alt_x_axis");
81  fOpDet = pset.get<int>("opdet");
82  fEachSlice = pset.get<bool>("each_slice");
83  fEachDetector = pset.get<bool>("each_detector");
84  }
85 
86  //----------------------------------------------------------------------------
88 
89  {
90  mf::LogInfo("PhotonLibraryAnalyzer")<<"Analyzing photon library - begin"<< std::endl;
91 
92 
96 
97  int NOpDet = pvs->NOpChannels();
98 
99  sim::PhotonVoxelDef TheVoxelDef = pvs->GetVoxelDef();
100  TVector3 Steps = TheVoxelDef.GetSteps();
101  TVector3 UpperCorner = TheVoxelDef.GetRegionUpperCorner();
102  TVector3 LowerCorner = TheVoxelDef.GetRegionLowerCorner();
103 
104  mf::LogInfo("PhotonLibraryAnalyzer") << "UpperCorner: " << UpperCorner[0] << " " << UpperCorner[1] << " " << UpperCorner[2] << "\n"
105  << "LowerCorner: " << LowerCorner[0] << " " << LowerCorner[1] << " " << LowerCorner[2];
106 
107  int XSteps = int(Steps[0]);
108  int YSteps = int(Steps[1]);
109  int ZSteps = int(Steps[2]);
110 
111  // for c2: FullVolume is unused, just call tfs->make
112  // TH3D *FullVolume = tfs->make<TH3D>("FullVolume","FullVolume",
113  tfs->make<TH3D>("FullVolume","FullVolume",
114  XSteps,LowerCorner[0],UpperCorner[0],
115  YSteps,LowerCorner[1],UpperCorner[1],
116  ZSteps,LowerCorner[2],UpperCorner[2]);
117 
118 
119  int reportnum=10000;
120 
121  int newX, newY;
122  if (fAltXAxis == "Z") {
123  newX = 2; // Z
124  newY = 1; // Y
125  }
126  else {
127  newX = 1; // Y
128  newY = 2; // Z
129  }
130 
131 
132 
133  mf::LogInfo("PhotonLibraryAnalyzer")<<"Analyzing photon library - making historams"<< std::endl;
134 
135  TH2D* XProjection;
136  if (fAltXAxis == "Z") XProjection = tfs->make<TH2D>("XProjection","XProjection",ZSteps,0,ZSteps,YSteps,0,YSteps);
137  else XProjection = tfs->make<TH2D>("XProjection","XProjection",YSteps,0,YSteps,ZSteps,0,ZSteps);
138  TH2D* YProjection = tfs->make<TH2D>("YProjection","YProjection",XSteps,0,XSteps,ZSteps,0,ZSteps);
139  TH2D* ZProjection = tfs->make<TH2D>("ZProjection","ZProjection",XSteps,0,XSteps,YSteps,0,YSteps);
140 
141  // TH1D * PMTsNoVisibility = tfs->make<TH1D>("PMTsNoVisibility","PMTsNoVisibility", NOpDet,0,NOpDet);
142 
143  TH1D* VisByN = tfs->make<TH1D>("VisByN","VisByN", NOpDet, 0, NOpDet);
144 
145  TH2D* XInvisibles;
146  if (fAltXAxis == "Z") XInvisibles = tfs->make<TH2D>("XInvisibles","XInvisibles",ZSteps,0,ZSteps,YSteps,0,YSteps);
147  else XInvisibles = tfs->make<TH2D>("XInvisibles","XInvisibles",YSteps,0,YSteps,ZSteps,0,ZSteps);
148  TH2D* YInvisibles = tfs->make<TH2D>("YInvisibles","YInvisibles",XSteps,0,XSteps,ZSteps,0,ZSteps);
149  TH2D* ZInvisibles = tfs->make<TH2D>("ZInvisibles","ZInvisibles",XSteps,0,XSteps,YSteps,0,YSteps);
150 
151 
152 
153 
154 
155  std::vector<TH2D*> TheXCrossSections;
156  std::vector<TH2D*> TheYCrossSections;
157  std::vector<TH2D*> TheZCrossSections;
158  if (fEachSlice) {
159 
160 
161  for(int i=0; i!=XSteps; ++i)
162  {
163  std::stringstream ss("");
164  ss.flush();
165  ss<<"projX"<<i;
166  if (fAltXAxis == "Z")
167  TheXCrossSections.push_back(tfs->make<TH2D>(ss.str().c_str(),ss.str().c_str(), ZSteps, 0,ZSteps, YSteps, 0,YSteps));
168  else
169  TheXCrossSections.push_back(tfs->make<TH2D>(ss.str().c_str(),ss.str().c_str(), YSteps, 0,YSteps, ZSteps, 0,ZSteps));
170 
171 
172  }
173 
174  for(int i=0; i!=YSteps; ++i)
175  {
176  std::stringstream ss("");
177  ss.flush();
178  ss<<"projY"<<i;
179  TheYCrossSections.push_back(tfs->make<TH2D>(ss.str().c_str(),ss.str().c_str(), XSteps, 0,XSteps, ZSteps, 0, ZSteps));
180 
181  }
182 
183  for(int i=0; i!=ZSteps; ++i)
184  {
185  std::stringstream ss("");
186  ss.flush();
187  ss<<"projZ"<<i;
188  TheZCrossSections.push_back(tfs->make<TH2D>(ss.str().c_str(),ss.str().c_str(), XSteps, 0,XSteps, YSteps, 0,YSteps));
189 
190  }
191  }
192 
193 
194  std::vector<TH2D*> TheXProjections;
195  std::vector<TH2D*> TheYProjections;
196  std::vector<TH2D*> TheZProjections;
197 
198  if (fEachDetector) {
199 
200  mf::LogInfo("PhotonLibraryAnalyzer")<<"Making projections for each of " << NOpDet << " photon detectors" << std::endl;
201 
202  for(int i=0; i<NOpDet; ++i)
203  {
204  char ss[99];
205 
206  sprintf(ss, "ProjXOpDet%d", i);
207  if (fAltXAxis == "Z")
208  TheXProjections.push_back(tfs->make<TH2D>(ss, ss, ZSteps, 0,ZSteps, YSteps, 0,YSteps));
209  else
210  TheXProjections.push_back(tfs->make<TH2D>(ss, ss, YSteps, 0,YSteps, ZSteps, 0,ZSteps));
211 
212  sprintf(ss, "ProjYOpDet%d", i);
213  TheYProjections.push_back(tfs->make<TH2D>(ss, ss, XSteps, 0,XSteps, ZSteps, 0, ZSteps));
214 
215  sprintf(ss, "ProjZOpDet%d", i);
216  TheZProjections.push_back(tfs->make<TH2D>(ss, ss, XSteps, 0,XSteps, YSteps, 0,YSteps));
217  }
218  }
219 
220 
221  mf::LogInfo("PhotonLibraryAnalyzer")<<"Analyzing photon library - running through voxels "<< std::endl;
222 
223 
224  for(int i=0; i!=TheVoxelDef.GetNVoxels(); ++i)
225  {
226  if(i%reportnum==0) std::cout<<"Photon library analyzer at voxel " << i<<std::endl;
227 
228  std::vector<int> Coords = TheVoxelDef.GetVoxelCoords(i);
229 
230  const float* Visibilities = pvs->GetLibraryEntries(i);
231  size_t NOpChannels = pvs->NOpChannels();
232 
233  float TotalVis=0;
234  if (fOpDet < 0) {
235  for(size_t ichan=0; ichan!=NOpChannels; ++ichan)
236  {
237  TotalVis+=Visibilities[ichan];
238  }
239  }
240  else {
241  TotalVis = Visibilities[fOpDet];
242  }
243 
244  VisByN->Fill(NOpChannels);
245 
246  if(TotalVis==0)
247  {
248  XInvisibles->Fill(Coords[newX],Coords[newY]);
249  YInvisibles->Fill(Coords[0],Coords[2]);
250  ZInvisibles->Fill(Coords[0],Coords[1]);
251  }
252 
253  if (fEachSlice) {
254  TheXCrossSections.at(Coords.at(0))->Fill(Coords[newX],Coords[newY],TotalVis);
255  TheYCrossSections.at(Coords.at(1))->Fill(Coords[0],Coords[2],TotalVis);
256  TheZCrossSections.at(Coords.at(2))->Fill(Coords[0],Coords[1],TotalVis);
257  }
258 
259  if (fEachDetector) {
260  for(size_t ichan=0; ichan!=NOpChannels; ++ichan) {
261  TheXProjections.at(ichan)->Fill(Coords[newX],Coords[newY],Visibilities[ichan]);
262  TheYProjections.at(ichan)->Fill(Coords[0],Coords[2],Visibilities[ichan]);
263  TheZProjections.at(ichan)->Fill(Coords[0],Coords[1],Visibilities[ichan]);
264  }
265  }
266 
267  // Always make the summed projections
268  XProjection->Fill(Coords[newX], Coords[newY], TotalVis);
269  YProjection->Fill(Coords[0], Coords[2], TotalVis);
270  ZProjection->Fill(Coords[0], Coords[1], TotalVis);
271 
272  }
273 
274  mf::LogInfo("PhotonLibraryAnalyzer")<<"Analyzing photon library - end"<< std::endl;
275  }
276 
277  //----------------------------------------------------------------------------
279  {
280 
281  }
282 
283 
284 
285 
286  //----------------------------------------------------------------------------
288  {
289 
290  }
291 }
292 
293 
294 namespace phot {
296 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
TNtupleSim Fill(f1, f2, f3, f4)
TVector3 GetSteps() const
Float_t ss
Definition: plot.C:23
TVector3 GetRegionLowerCorner() const
PhotonLibraryAnalyzer(fhicl::ParameterSet const &pset)
TVector3 GetRegionUpperCorner() const
int GetNVoxels() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
std::vector< int > GetVoxelCoords(int ID) const
General LArSoft Utilities.
T * make(ARGS...args) const
Utility object to perform functions of association.
void reconfigure(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:5
Eigen::Vector3f Coords
Definition: DCEL.h:36
art framework interface to geometry description