LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OpHit3DDrawer_tool.cc
Go to the documentation of this file.
1 
11 
13 
17 
18 #include "TPolyLine3D.h"
19 
20 // Eigen
21 #include <Eigen/Core>
22 
23 namespace evdb_tool {
24 
25  class OpHit3DDrawer : public I3DDrawer {
26  public:
27  explicit OpHit3DDrawer(const fhicl::ParameterSet&);
28 
30 
31  void Draw(const art::Event&, evdb::View3D*) const override;
32 
33  private:
35  const Eigen::Vector3f&,
36  const Eigen::Vector3f&,
37  int,
38  int,
39  int) const;
40  };
41 
42  //----------------------------------------------------------------------
43  // Constructor.
45  {
46  return;
47  }
48 
50 
52  {
54 
55  if (recoOpt->fDrawOpHits == 0) return;
56 
57  // Service recovery
60 
62 
63  // This seems like a time waster but we want to get the full color scale for all OpHits... so loops away...
64  std::vector<float> opHitPEVec;
65 
66  // This is almost identically the same for loop we will re-excute below... sigh...
67  // But the idea is to get a min/max range for the drawing colors...
68  for (size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++) {
69  art::InputTag opHitProducer = recoOpt->fOpHitLabels[idx];
70 
71  event.getByLabel(opHitProducer, opHitHandle);
72 
73  if (!opHitHandle.isValid()) continue;
74  if (opHitHandle->size() == 0) continue;
75 
76  // Start the loop over flashes
77  for (const auto& opHit : *opHitHandle) {
78  // Make some selections...
79  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
80  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
81  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
82 
83  opHitPEVec.push_back(opHit.PE());
84  }
85  }
86 
87  // Do we have any flashes and hits?
88  if (!opHitPEVec.empty()) {
89  // Sorting is good for mind and body...
90  std::sort(opHitPEVec.begin(), opHitPEVec.end());
91 
92  float minTotalPE = opHitPEVec.front();
93  float maxTotalPE = opHitPEVec[0.9 * opHitPEVec.size()];
94 
95  // Now we can set the scaling factor for PE
96  float opHitPEScale((cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) /
97  (maxTotalPE - minTotalPE));
98 
99  // We are meant to draw the flashes/hits, so loop over the list of input flashes
100  for (size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++) {
101  art::InputTag opHitProducer = recoOpt->fOpHitLabels[idx];
102 
103  event.getByLabel(opHitProducer, opHitHandle);
104 
105  if (!opHitHandle.isValid()) continue;
106  if (opHitHandle->size() == 0) continue;
107 
108  // Start the loop over flashes
109  for (const auto& opHit : *opHitHandle) {
110  // Make some selections...
111  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
112  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
113  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
114 
115  unsigned int opChannel = opHit.OpChannel();
116  const geo::OpDetGeo& opHitGeo = geo->OpDetGeoFromOpChannel(opChannel);
117  const geo::Point_t& opHitPos = opHitGeo.GetCenter();
118  float xWidth = opHit.Width();
119  float zWidth = opHitGeo.HalfW();
120  float yWidth = opHitGeo.HalfH();
121 
122  Eigen::Vector3f opHitLo(
123  opHitPos.X() - xWidth, opHitPos.Y() - yWidth, opHitPos.Z() - zWidth);
124  Eigen::Vector3f opHitHi(
125  opHitPos.X() + xWidth, opHitPos.Y() + yWidth, opHitPos.Z() + zWidth);
126 
127  float peFactor = cst->fRecoQLow[geo::kCollection] +
128  opHitPEScale * std::min(maxTotalPE, float(opHit.PE()));
129 
130  int chargeColorIdx = cst->CalQ(geo::kCollection).GetColor(peFactor);
131 
132  DrawRectangularBox(view, opHitLo, opHitHi, chargeColorIdx, 2, 1);
133  }
134  }
135  }
136 
137  return;
138  }
139 
141  const Eigen::Vector3f& coordsLo,
142  const Eigen::Vector3f& coordsHi,
143  int color,
144  int width,
145  int style) const
146  {
147  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
148  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
149  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
150  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
151  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
152  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
153 
154  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
155  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
156  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
157  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
158  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
159  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
160 
161  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
162  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
163  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
164  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
165  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
166  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
167 
168  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
169  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
170  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
171  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
172  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
173  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
174 
175  return;
176  }
177 
179 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
OpHit3DDrawer(const fhicl::ParameterSet &)
int GetColor(double x) const
Definition: ColorScale.cxx:126
double fFlashTMin
Minimal time for a flash to be displayed.
std::vector< double > fRecoQHigh
high edge of ADC values for drawing raw digits
double fFlashTMax
Maximum time for a flash to be displayed.
std::vector< double > fRecoQLow
low edge of ADC values for drawing raw digits
bool isValid() const noexcept
Definition: Handle.h:203
The color scales used by the event display.
double HalfW() const
Definition: OpDetGeo.cxx:52
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
void Draw(const art::Event &, evdb::View3D *) const override
const evdb::ColorScale & CalQ(geo::SigType_t st) const
double fFlashMinPE
Minimal PE for a flash to be displayed.
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:72
std::size_t color(std::string const &procname)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
double HalfH() const
Definition: OpDetGeo.cxx:60
A collection of 3D drawable objects.
Namespace collecting geometry-related classes utilities.
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
std::vector< art::InputTag > fOpHitLabels
module labels that produced events
art framework interface to geometry description
Event finding and building.
void DrawRectangularBox(evdb::View3D *, const Eigen::Vector3f &, const Eigen::Vector3f &, int, int, int) const
Signal from collection planes.
Definition: geo_types.h:152