All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FMWKInterface.cxx
Go to the documentation of this file.
1 #ifndef __OPT0FINDERFMWKINTERFACE_CXX__
2 #define __OPT0FINDERFMWKINTERFACE_CXX__
3 
4 #include "FMWKInterface.h"
5 #include <assert.h>
6 
7 namespace flashmatch{
8  DetectorSpecs* DetectorSpecs::_me = nullptr;
9 }
10 
11 #if USING_LARSOFT == 0
14 namespace flashmatch{
15 
17 
18  assert(!filename.empty());
19  if(filename.find("/") != 0)
20  filename = std::string(getenv("FMATCH_DATADIR")) + "/" + filename;
21 
22  auto cfg = CreatePSetFromFile(filename,"cfg");
23  auto const& p = cfg.get<::flashmatch::Config_t>("DetectorSpecs");
24 
25  auto max_pt = p.get<std::vector<double> >("MaxPosition");
26  auto min_pt = p.get<std::vector<double> >("MinPosition");
27  assert(max_pt.size() == 3);
28  assert(min_pt.size() == 3);
29  assert(max_pt[0] >= min_pt[0] &&
30  max_pt[1] >= min_pt[1] &&
31  max_pt[2] >= min_pt[2]);
32  _bbox = geoalgo::AABox(min_pt[0],min_pt[1],min_pt[2],max_pt[0],max_pt[1],max_pt[2]);
33  //std::cout<<_bbox.Min()[0]<<" "<<_bbox.Min()[1]<<" "<<_bbox.Min()[2]<<std::endl;
34  //std::cout<<_bbox.Max()[0]<<" "<<_bbox.Max()[1]<<" "<<_bbox.Max()[2]<<std::endl;
35  size_t ch=0;
36  _pmt_v.clear();
37  while(1) {
38  std::string key = "PMT" + std::to_string(ch);
39  if(!p.contains_value(key)) break;
40  geoalgo::Point_t pmt(p.get<std::vector<double> >(key));
41  assert(pmt.size()==3);
42  _pmt_v.push_back(pmt);
43  ch++;
44  }
45 
46  _drift_velocity = p.get<double>("DriftVelocity");
47 
49 
50  }
51 
52  const geoalgo::AABox& DetectorSpecs::ActiveVolume(int tpc, int cryo) const {
53  auto iter = _bbox_map.find(std::pair<int,int>(tpc, cryo));
54  if (iter == _bbox_map.end()) {
55  FLASH_CRITICAL() << "Boundary box map doesn't contain cryo " << cryo
56  << " or tpc " << tpc << "!" << std::endl;
57  throw OpT0FinderException();
58  }
59  return iter->second;
60  }
61 
62  float DetectorSpecs::GetVisibility(double x, double y, double z, unsigned int opch) const
63  { return phot::PhotonVisibilityService::GetME().GetVisibility(x,y,z,opch); }
64 
65  const std::vector<std::vector<float > >& DetectorSpecs::GetPhotonLibraryData() const
67 }
68 
69 #else
70 namespace flashmatch{
71  DetectorSpecs::DetectorSpecs(std::string filename){
72  ::art::ServiceHandle<geo::Geometry> const geo;
73  auto const clock_data = ::art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
74  auto const det_prop = ::art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clock_data);
75 
76  _drift_velocity = det_prop.DriftVelocity();
77  _pmt_v.clear();
78 
79  _pmt_v.resize(geo->NOpDets());
80 
81  for (size_t opdet = 0; opdet < geo->NOpDets(); opdet++) {
82 
83  std::vector<double> pos(3, 0.);
84  geo->OpDetGeoFromOpDet(opdet).GetCenter(&pos[0]);
85 
86  geoalgo::Point_t pmt(pos);
87  _pmt_v[opdet] = pmt;
88  }
89 
90  double global_x_min = 1e9, global_x_max = -1e9;
91  double global_y_min = 1e9, global_y_max = -1e9;
92  double global_z_min = 1e9, global_z_max = -1e9;
93 
94  _bbox_map.reserve(geo->Ncryostats() * geo->NTPC());
95 
96  for (size_t cryo = 0; cryo < geo->Ncryostats(); cryo++) {
97  for (size_t tpc = 0; tpc < geo->NTPC(cryo); tpc++) {
98  const geo::TPCGeo tpc_geo = geo->TPC(tpc, cryo);
99  double x_min = tpc_geo.GetCenter().X() - tpc_geo.HalfWidth();
100  double x_max = tpc_geo.GetCenter().X() + tpc_geo.HalfWidth();
101 
102  double y_min = tpc_geo.GetCenter().Y() - tpc_geo.HalfHeight();
103  double y_max = tpc_geo.GetCenter().Y() + tpc_geo.HalfHeight();
104 
105  double z_min = tpc_geo.GetCenter().Z() - tpc_geo.HalfLength();
106  double z_max = tpc_geo.GetCenter().Z() + tpc_geo.HalfLength();
107 
108  if (x_min < global_x_min) global_x_min = x_min;
109  if (x_max > global_x_max) global_x_max = x_max;
110  if (y_min < global_y_min) global_y_min = y_min;
111  if (y_max > global_y_max) global_y_max = y_max;
112  if (z_min < global_z_min) global_z_min = z_min;
113  if (z_max > global_z_max) global_z_max = z_max;
114 
115  _bbox_map.emplace(std::make_pair(tpc, cryo), geoalgo::AABox(x_min, y_min, z_min, x_max, y_max, z_max));
116  }
117 
118  _bbox = geoalgo::AABox(global_x_min, global_y_min, global_z_min,
119  global_x_max, global_y_max, global_z_max);
120  }
121 
122  // art::ServiceHandle<phot::PhotonVisibilityService const> pvs;
123  }
124 
125  float DetectorSpecs::GetVisibility(double x, double y, double z, unsigned int opch) const {
126  // double xyz[3];
127  // xyz[0] = x;
128  // xyz[1] = y;
129  // xyz[2] = z;
130  // return pvs.GetVisibility(xyz, opch, false);
131  return -1;
132  }
133 
134  float DetectorSpecs::GetVisibilityReflected(double x, double y, double z, unsigned int opch) const {
135  // double xyz[3];
136  // xyz[0] = x;
137  // xyz[1] = y;
138  // xyz[2] = z;
139  // return pvs.GetVisibility(xyz, opch, true);
140  return -1;
141  }
142 
143  const geoalgo::AABox& DetectorSpecs::ActiveVolume(int tpc, int cryo) const {
144  auto iter = _bbox_map.find(std::pair<int,int>(tpc, cryo));
145  if (iter == _bbox_map.end()) {
146  FLASH_CRITICAL() << "Boundary box map doesn't contain cryo " << cryo
147  << " or tpc " << tpc << "!" << std::endl;
148  throw OpT0FinderException();
149  }
150  return iter->second;
151  }
152 
153 }
154 #endif
155 
156 #endif
157 
process_name opflash particleana ie ie ie z
PSet CreatePSetFromFile(std::string fname, std::string cfg_name)
Given a configuration file (full path), create and return flashmatch::PSet.
Definition: PSetUtils.cxx:32
const geoalgo::AABox & ActiveVolume() const
Detector active volume.
Definition: FMWKInterface.h:54
process_name opflash particleana ie x
const std::vector< std::vector< float > > & GetPhotonLibraryData() const
Photon Library data access FIXME.
BEGIN_PROLOG could also be dds filename
pdgs p
Definition: selectors.fcl:22
std::unordered_map< std::pair< int, int >, geoalgo::AABox, boost::hash< std::pair< int, int > > > _bbox_map
A bbox map (cryo,tpc) -&gt; bbox.
Definition: FMWKInterface.h:83
Geometry information for a single TPC.
Definition: TPCGeo.h:38
Representation of a 3D rectangular box which sides are aligned w/ coordinate axis. A representation of an Axis-Aligned-Boundary-Box, a simple &amp; popular representation of 3D boundary box for collision detection. The concept was taken from the reference, Real-Time-Collision-Detection (RTCD), and in particular Ch. 4.2 (page 77): .
double HalfLength() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:117
fhicl::ParameterSet Config_t
Configuration object.
Definition: FMWKInterface.h:31
static PhotonVisibilityService & GetME(std::string filename="PhotonLibrary-20180801.root")
float GetVisibility(double x, double y, double z, unsigned int opch) const
Visibility.
process_name opflash particleana ie ie y
DetectorSpecs(std::string filename="specs.cfg")
#define FLASH_CRITICAL()
Compiler macro for CRITICAL message.
Utility functions in Base/PSet.
double HalfHeight() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:111
std::string to_string(WindowPattern const &pattern)
float GetVisibilityReflected(double x, double y, double z, unsigned int opch) const
Visibility Reflected.
std::vector< geoalgo::Point_t > _pmt_v
Definition: FMWKInterface.h:81
float GetVisibility(Point const &p, unsigned int OpChannel, bool wantReflected=false) const
static DetectorSpecs * _me
Voxel definition.
Definition: FMWKInterface.h:80
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:107
Point GetCenter() const
Returns the center of the TPC volume in world coordinates [cm].
Definition: TPCGeo.h:779