LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PhotonLibraryHybrid.cxx
Go to the documentation of this file.
2 
4 
6 
8 
9 #include "TFile.h"
10 #include "TTree.h"
11 #include "TVectorD.h"
12 
13 #include <iostream>
14 
15 namespace {
16  bool fatal(const std::string& msg)
17  {
18  std::cerr << "FATAL: PhotonLibraryHybrid: " << msg << std::endl;
19  abort();
20  }
21 }
22 
23 namespace phot {
24  //--------------------------------------------------------------------
25  PhotonLibraryHybrid::PhotonLibraryHybrid(const std::string& fname,
26  const sim::PhotonVoxelDef& voxdef)
27  : fVoxDef(voxdef)
28  {
29  TFile f(fname.c_str());
30  !f.IsZombie() || fatal("Could not open PhotonLibrary " + fname);
31 
32  for (int opdetIdx = 0; true; ++opdetIdx) {
33  const std::string dirname = TString::Format("opdet_%d", opdetIdx).Data();
34  TDirectory* dir = (TDirectory*)f.Get(dirname.c_str());
35  if (!dir) break; // Ran out of opdets
36 
37  OpDetRecord rec;
38 
39  TVectorD* fit = (TVectorD*)dir->Get("fit");
40  fit || fatal("Didn't find " + dirname + "/fit in " + fname);
41  rec.fit = FitFunc((*fit)[0], (*fit)[1]);
42 
43  TTree* tr = (TTree*)dir->Get("tr");
44  tr || fatal("Didn't find " + dirname + "/tr in " + fname);
45  int vox;
46  float vis;
47  tr->SetBranchAddress("vox", &vox);
48  tr->SetBranchAddress("vis", &vis);
49 
50  rec.exceptions.reserve(tr->GetEntries());
51  for (int i = 0; i < tr->GetEntries(); ++i) {
52  tr->GetEntry(i);
53  vox < NVoxels() || fatal("Voxel out of range");
54  rec.exceptions.emplace_back(vox, vis);
55  }
56  rec.exceptions.shrink_to_fit(); // In case we don't trust reserve()
57 
58  // In case they weren't sorted in the file
59  std::sort(rec.exceptions.begin(), rec.exceptions.end());
60 
61  fRecords.push_back(rec);
62  } // end for opdetIdx
63 
64  !fRecords.empty() || fatal("No opdet_*/ directories in " + fname);
65 
67  geom->NOpDets() == fRecords.size() || fatal("Number of opdets mismatch");
68 
69  fRecords.shrink_to_fit(); // save memory
70  }
71 
72  //--------------------------------------------------------------------
74 
75  //--------------------------------------------------------------------
77  {
78  return fVoxDef.GetNVoxels();
79  }
80 
81  //--------------------------------------------------------------------
82  const float* PhotonLibraryHybrid::GetCounts(size_t vox) const
83  {
84  // The concept of GetCounts() conflicts fairly badly with how this library
85  // works. This is probably the best we can do.
86 
87  static float* counts = 0;
88  if (!counts) counts = new float[NOpChannels()];
89  for (int od = 0; od < NOpChannels(); ++od)
90  counts[od] = GetCount(vox, od);
91  return counts;
92  }
93 
94  //--------------------------------------------------------------------
95  float PhotonLibraryHybrid::GetCount(size_t vox, size_t opchan) const
96  {
97  int(vox) < NVoxels() || fatal("GetCount(): Voxel out of range");
98  int(opchan) < NOpChannels() || fatal("GetCount(): OpChan out of range");
99 
100  const OpDetRecord& rec = fRecords[opchan];
101 
102  auto it2 = std::lower_bound(rec.exceptions.begin(), rec.exceptions.end(), vox);
103  if (it2->vox == vox) return it2->vis;
104 
105  // Otherwise, we use the interpolation, which requires a distance
106 
108  const geo::OpDetGeo& opdet = geom->OpDetGeoFromOpDet(opchan);
109 
110  const auto voxvec = fVoxDef.GetPhotonVoxel(vox).GetCenter();
111 
112  const double dist = opdet.DistanceToPoint(voxvec);
113 
114  return rec.fit.Eval(dist);
115  }
116 }
Definitions of voxel data structures.
OpDetGeo const & OpDetGeoFromOpDet(unsigned int OpDet) const
Returns the geo::OpDetGeo object for the given detector number.
virtual const float * GetCounts(size_t Voxel) const override
Returns a pointer to NOpChannels() visibility values, one per channel.
Float_t vox
Definition: plot.C:38
Representation of a region of space diced into voxels.
Definition: PhotonVoxels.h:58
PhotonLibraryHybrid(const std::string &fname, const sim::PhotonVoxelDef &voxdef)
TFile f
Definition: plotHisto.C:6
virtual int NVoxels() const override
counts_as<> counts
Number of ADC counts, represented by signed short int.
Definition: electronics.h:112
const sim::PhotonVoxelDef & fVoxDef
virtual int NOpChannels() const override
unsigned int NOpDets() const
Number of OpDets in the whole detector.
double DistanceToPoint(geo::Point_t const &point) const
Returns the distance of the specified point from detector center [cm].
Definition: OpDetGeo.cxx:98
General LArSoft Utilities.
TDirectory * dir
Definition: macro.C:5
virtual float GetCount(size_t Voxel, size_t OpChannel) const override
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Point GetCenter() const
Returns the center of the voxel (type Point).
Definition: PhotonVoxels.h:186
unsigned int GetNVoxels() const
Returns the total number of voxels in the volume.
std::vector< OpDetRecord > fRecords
art framework interface to geometry description
PhotonVoxel GetPhotonVoxel(int ID) const