All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RayTraceBox_tool.cc
Go to the documentation of this file.
1 /**
2  *
3  */
4 
5 // Framework Includes
6 #include "art/Framework/Principal/Event.h"
7 #include "art/Framework/Principal/Handle.h"
8 #include "art/Framework/Services/Registry/ServiceHandle.h"
9 #include "art/Persistency/Common/PtrMaker.h"
10 #include "art/Utilities/ToolMacros.h"
11 #include "cetlib/cpu_timer.h"
12 #include "fhiclcpp/ParameterSet.h"
13 #include "messagefacility/MessageLogger/MessageLogger.h"
14 
15 // local includes
16 #include "IRayTrace.h"
18 
19 // LArSoft includes
24 
25 // std includes
26 #include <string>
27 #include <iostream>
28 #include <memory>
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 // implementation follows
32 
33 namespace evgen {
34 namespace ldm {
35 /**
36  * @brief RayTraceBox class definiton
37  */
38 class RayTraceBox : public IRayTrace
39 {
40 public:
41  /**
42  * @brief Constructor
43  */
44  RayTraceBox(fhicl::ParameterSet const &pset);
45 
46  /**
47  * @brief Destructor
48  */
49  ~RayTraceBox();
50 
51  void configure(const fhicl::ParameterSet&) override;
52 
53  bool IntersectDetector(MeVPrtlFlux &flux, std::array<TVector3, 2> &intersection, double &weight) override;
54 
55  // no weights
56  double MaxWeight() override { return -1.; }
57 
58 private:
60 };
61 
62 RayTraceBox::RayTraceBox(fhicl::ParameterSet const &pset):
63  IMeVPrtlStage("RayTraceBox")
64 {
65  this->configure(pset);
66 }
67 
68 //------------------------------------------------------------------------------------------------------------------------------------------
69 
71 {
72 }
73 
74 //------------------------------------------------------------------------------------------------------------------------------------------
75 void RayTraceBox::configure(fhicl::ParameterSet const &pset)
76 {
77  if (pset.has_key("Box")) {
78  std::array<double, 6> box_config = pset.get<std::array<double, 6>>("Box");
79  // xmin, xmax, ymin, ymax, zmin, zmax
80  fBox = geo::BoxBoundedGeo(box_config[0], box_config[1], box_config[2], box_config[3], box_config[4], box_config[5]);
81  }
82  else {
83  const geo::GeometryCore *geometry = lar::providerFrom<geo::Geometry>();
84  fBox = geometry->DetectorEnclosureBox(pset.get<std::string>("Volume"));
85  }
86 
87  std::cout << "Detector Box." << std::endl;
88  std::cout << "X " << fBox.MinX() << " " << fBox.MaxX() << std::endl;
89  std::cout << "Y " << fBox.MinY() << " " << fBox.MaxY() << std::endl;
90  std::cout << "Z " << fBox.MinZ() << " " << fBox.MaxZ() << std::endl;
91 
92 }
93 
94 
95 bool RayTraceBox::IntersectDetector(MeVPrtlFlux &flux, std::array<TVector3, 2> &intersection, double &weight) {
96  std::vector<TVector3> box_intersections = fBox.GetIntersections(flux.pos.Vect(), flux.mom.Vect().Unit());
97 
98  if (box_intersections.size() != 2) return false;
99 
100  TVector3 A = box_intersections[0];
101  TVector3 B = box_intersections[1];
102 
103  // make sure that the flux start lies outside the detector
104  if ((flux.pos.Vect() - A).Mag() < (A-B).Mag() && (flux.pos.Vect() - B).Mag() < (A-B).Mag()) {
105  throw cet::exception("RayTraceBox Exception", "Input portal flux starts inside detector volume: "
106  "MeVPrtl start At: (" + std::to_string(flux.pos.X()) + ", " + std::to_string(flux.pos.Y()) + ", " + std::to_string(flux.pos.Z()) + "). "
107  "Intersection A At: " + std::to_string(A.X()) + ", " + std::to_string(A.Y()) + ", " + std::to_string(A.Z()) + "). "
108  "Intersection B At: " + std::to_string(B.X()) + ", " + std::to_string(B.Y()) + ", " + std::to_string(B.Z()) + ").\n"
109  );
110  }
111 
112  // if the ray points the wrong way, it doesn't intersect
113  if (flux.mom.Vect().Unit().Dot((A - flux.pos.Vect()).Unit()) < 0.) {
114  std::cout << "RAYTRACE: MeVPrtl points wrong way" << std::endl;
115  return false;
116  }
117 
118  if ((flux.pos.Vect() - A).Mag() < (flux.pos.Vect() - B).Mag()) {
119  intersection = {A, B}; // A is entry, B is exit
120  }
121  else {
122  intersection = {B, A}; // reversed
123  }
124 
125  weight = 1.;
126  return true;
127 }
128 
129 DEFINE_ART_CLASS_TOOL(RayTraceBox)
130 
131 } // namespace ldm
132 } // namespace evgen
Utilities related to art service access.
TLorentzVector mom
Definition: MeVPrtlFlux.h:14
const geo::GeometryCore * geometry
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
geo::BoxBoundedGeo DetectorEnclosureBox(std::string const &name="volDetEnclosure") const
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
bool IntersectDetector(MeVPrtlFlux &flux, std::array< TVector3, 2 > &intersection, double &weight) override
double MaxWeight() override
Access the description of detector geometry.
geo::BoxBoundedGeo fBox
double MinZ() const
Returns the world z coordinate of the start of the box.
IMeVPrtlStage interface class definiton. General interface behind each stage. Provides random number ...
Definition: IMeVPrtlStage.h:36
Description of geometry of one entire detector.
IRayTrace interface class definiton.
Definition: IRayTrace.h:39
Provides a base class aware of world box coordinates.
double MaxY() const
Returns the world y coordinate of the end of the box.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
RayTraceBox class definiton.
std::string to_string(WindowPattern const &pattern)
double MaxZ() const
Returns the world z coordinate of the end of the box.
RayTraceBox(fhicl::ParameterSet const &pset)
Constructor.
TLorentzVector pos
Definition: MeVPrtlFlux.h:11
std::vector< TVector3 > GetIntersections(TVector3 const &TrajectoryStart, TVector3 const &TrajectoryDirect) const
Calculates the entry and exit points of a trajectory on the box surface.
void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
float A
Definition: dedx.py:137
This provides an interface for an art tool which ray traces &quot;Prtl&quot; (massive) particles from their pro...
double MinY() const
Returns the world y coordinate of the start of the box.
art framework interface to geometry description
BEGIN_PROLOG could also be cout