OpHit3DDrawer_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file OpHit3DDrawer_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
11 
15 
16 #include "TPolyLine3D.h"
17 
18 // Eigen
19 #include <Eigen/Core>
20 
21 namespace evdb_tool
22 {
23 
24 class OpHit3DDrawer : public I3DDrawer
25 {
26 public:
27  explicit OpHit3DDrawer(const fhicl::ParameterSet&);
28 
30 
31  void Draw(const art::Event&, evdb::View3D*) const override;
32 
33 private:
34  void DrawRectangularBox(evdb::View3D*, const Eigen::Vector3f&, const Eigen::Vector3f&, int, int, int) const;
35 };
36 
37 //----------------------------------------------------------------------
38 // Constructor.
40 {
41  return;
42 }
43 
45 {
46 }
47 
48 void OpHit3DDrawer::Draw(const art::Event& event, evdb::View3D* view) const
49 {
51 
52  if (recoOpt->fDrawOpHits == 0) return;
53 
54  // Service recovery
57 
59 
60  // This seems like a time waster but we want to get the full color scale for all OpHits... so loops away...
61  std::vector<float> opHitPEVec;
62 
63  // This is almost identically the same for loop we will re-excute below... sigh...
64  // But the idea is to get a min/max range for the drawing colors...
65  for(size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++)
66  {
67  art::InputTag opHitProducer = recoOpt->fOpHitLabels[idx];
68 
69  event.getByLabel(opHitProducer, opHitHandle);
70 
71  if (!opHitHandle.isValid() ) continue;
72  if ( opHitHandle->size() == 0) continue;
73 
74  // Start the loop over flashes
75  for(const auto& opHit : *opHitHandle)
76  {
77  // Make some selections...
78  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
79  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
80  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
81 
82  opHitPEVec.push_back(opHit.PE());
83  }
84  }
85 
86  // Do we have any flashes and hits?
87  if (!opHitPEVec.empty())
88  {
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]) / (maxTotalPE - minTotalPE));
97 
98  // We are meant to draw the flashes/hits, so loop over the list of input flashes
99  for(size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++)
100  {
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  {
111  // Make some selections...
112  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
113  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
114  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
115 
116  unsigned int opChannel = opHit.OpChannel();
117  const geo::OpDetGeo& opHitGeo = geo->OpDetGeoFromOpChannel(opChannel);
118  const geo::Point_t& opHitPos = opHitGeo.GetCenter();
119  float xWidth = opHit.Width();
120  float zWidth = opHitGeo.HalfW();
121  float yWidth = opHitGeo.HalfH();
122 
123  Eigen::Vector3f opHitLo(opHitPos.X() - xWidth, opHitPos.Y() - yWidth, opHitPos.Z() - zWidth);
124  Eigen::Vector3f opHitHi(opHitPos.X() + xWidth, opHitPos.Y() + yWidth, opHitPos.Z() + zWidth);
125 
126  float peFactor = cst->fRecoQLow[geo::kCollection] + opHitPEScale * std::min(maxTotalPE,float(opHit.PE()));
127 
128  int chargeColorIdx = cst->CalQ(geo::kCollection).GetColor(peFactor);
129 
130  DrawRectangularBox(view, opHitLo, opHitHi, chargeColorIdx, 2, 1);
131  }
132  }
133  }
134 
135  return;
136 }
137 
138 void OpHit3DDrawer::DrawRectangularBox(evdb::View3D* view, const Eigen::Vector3f& coordsLo, const Eigen::Vector3f& coordsHi, int color, int width, int style) const
139 {
140  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
141  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
142  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
143  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
144  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
145  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
146 
147  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
148  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
149  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
150  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
151  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
152  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
153 
154  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
155  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
156  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
157  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
158  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
159  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
160 
161  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
162  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
163  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
164  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
165  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
166  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
167 
168  return;
169 }
170 
171 
173 }
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
OpHit3DDrawer(const fhicl::ParameterSet &)
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
double fFlashTMin
Minimal time for a flash to be displayed.
art framework interface to geometry description
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:191
double HalfW() const
Definition: OpDetGeo.cxx:71
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.
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:184
std::size_t color(std::string const &procname)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
double HalfH() const
Definition: OpDetGeo.cxx:79
LArSoft geometry interface.
Definition: ChannelGeo.h:16
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
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:146