All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpHit3DDrawer_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file OpHit3DDrawer_tool.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
11 
12 #include "nuevdb/EventDisplayBase/View3D.h"
13 
14 #include "art/Framework/Principal/Event.h"
15 #include "art/Framework/Services/Registry/ServiceHandle.h"
16 #include "art/Utilities/ToolMacros.h"
17 
18 #include "TPolyLine3D.h"
19 
20 // Eigen
21 #include <Eigen/Core>
22 
23 namespace evdb_tool
24 {
25 
26 class OpHit3DDrawer : public I3DDrawer
27 {
28 public:
29  explicit OpHit3DDrawer(const fhicl::ParameterSet&);
30 
32 
33  void Draw(const art::Event&, evdb::View3D*) const override;
34 
35 private:
36  void DrawRectangularBox(evdb::View3D*, const Eigen::Vector3f&, const Eigen::Vector3f&, int, int, int) const;
37 };
38 
39 //----------------------------------------------------------------------
40 // Constructor.
41 OpHit3DDrawer::OpHit3DDrawer(const fhicl::ParameterSet& pset)
42 {
43  return;
44 }
45 
47 {
48 }
49 
50 void OpHit3DDrawer::Draw(const art::Event& event, evdb::View3D* view) const
51 {
52  art::ServiceHandle<evd::RecoDrawingOptions> recoOpt;
53 
54  if (recoOpt->fDrawOpHits == 0) return;
55 
56  // Service recovery
57  art::ServiceHandle<geo::Geometry> geo;
58  art::ServiceHandle<evd::ColorDrawingOptions> cst;
59 
60  art::Handle<std::vector<recob::OpHit>> opHitHandle;
61 
62  // This seems like a time waster but we want to get the full color scale for all OpHits... so loops away...
63  std::vector<float> opHitPEVec;
64 
65  // This is almost identically the same for loop we will re-excute below... sigh...
66  // But the idea is to get a min/max range for the drawing colors...
67  for(size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++)
68  {
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  {
79  // Make some selections...
80  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
81  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
82  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
83 
84  opHitPEVec.push_back(opHit.PE());
85  }
86  }
87 
88  // Do we have any flashes and hits?
89  if (!opHitPEVec.empty())
90  {
91  // Sorting is good for mind and body...
92  std::sort(opHitPEVec.begin(),opHitPEVec.end());
93 
94  float minTotalPE = opHitPEVec.front();
95  float maxTotalPE = opHitPEVec[0.9 * opHitPEVec.size()];
96 
97  // Now we can set the scaling factor for PE
98  float opHitPEScale((cst->fRecoQHigh[geo::kCollection] - cst->fRecoQLow[geo::kCollection]) / (maxTotalPE - minTotalPE));
99 
100  // We are meant to draw the flashes/hits, so loop over the list of input flashes
101  for(size_t idx = 0; idx < recoOpt->fOpHitLabels.size(); idx++)
102  {
103  art::InputTag opHitProducer = recoOpt->fOpHitLabels[idx];
104 
105  event.getByLabel(opHitProducer, opHitHandle);
106 
107  if (!opHitHandle.isValid() ) continue;
108  if ( opHitHandle->size() == 0) continue;
109 
110  // Start the loop over flashes
111  for(const auto& opHit : *opHitHandle)
112  {
113  // Make some selections...
114  if (opHit.PE() < recoOpt->fFlashMinPE) continue;
115  if (opHit.PeakTime() < recoOpt->fFlashTMin) continue;
116  if (opHit.PeakTime() > recoOpt->fFlashTMax) continue;
117 
118  unsigned int opChannel = opHit.OpChannel();
119  const geo::OpDetGeo& opHitGeo = geo->OpDetGeoFromOpChannel(opChannel);
120  const geo::Point_t& opHitPos = opHitGeo.GetCenter();
121  float xWidth = opHit.Width();
122  float zWidth = opHitGeo.HalfW();
123  float yWidth = opHitGeo.HalfH();
124 
125  Eigen::Vector3f opHitLo(opHitPos.X() - xWidth, opHitPos.Y() - yWidth, opHitPos.Z() - zWidth);
126  Eigen::Vector3f opHitHi(opHitPos.X() + xWidth, opHitPos.Y() + yWidth, opHitPos.Z() + zWidth);
127 
128  float peFactor = cst->fRecoQLow[geo::kCollection] + 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 
140 void OpHit3DDrawer::DrawRectangularBox(evdb::View3D* view, const Eigen::Vector3f& coordsLo, const Eigen::Vector3f& coordsHi, int color, int width, int style) const
141 {
142  TPolyLine3D& top = view->AddPolyLine3D(5, color, width, style);
143  top.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
144  top.SetPoint(1, coordsHi[0], coordsHi[1], coordsLo[2]);
145  top.SetPoint(2, coordsHi[0], coordsHi[1], coordsHi[2]);
146  top.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
147  top.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
148 
149  TPolyLine3D& side = view->AddPolyLine3D(5, color, width, style);
150  side.SetPoint(0, coordsHi[0], coordsHi[1], coordsLo[2]);
151  side.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
152  side.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
153  side.SetPoint(3, coordsHi[0], coordsHi[1], coordsHi[2]);
154  side.SetPoint(4, coordsHi[0], coordsHi[1], coordsLo[2]);
155 
156  TPolyLine3D& side2 = view->AddPolyLine3D(5, color, width, style);
157  side2.SetPoint(0, coordsLo[0], coordsHi[1], coordsLo[2]);
158  side2.SetPoint(1, coordsLo[0], coordsLo[1], coordsLo[2]);
159  side2.SetPoint(2, coordsLo[0], coordsLo[1], coordsHi[2]);
160  side2.SetPoint(3, coordsLo[0], coordsHi[1], coordsHi[2]);
161  side2.SetPoint(4, coordsLo[0], coordsHi[1], coordsLo[2]);
162 
163  TPolyLine3D& bottom = view->AddPolyLine3D(5, color, width, style);
164  bottom.SetPoint(0, coordsLo[0], coordsLo[1], coordsLo[2]);
165  bottom.SetPoint(1, coordsHi[0], coordsLo[1], coordsLo[2]);
166  bottom.SetPoint(2, coordsHi[0], coordsLo[1], coordsHi[2]);
167  bottom.SetPoint(3, coordsLo[0], coordsLo[1], coordsHi[2]);
168  bottom.SetPoint(4, coordsLo[0], coordsLo[1], coordsLo[2]);
169 
170  return;
171 }
172 
173 
174 DEFINE_ART_CLASS_TOOL(OpHit3DDrawer)
175 }
walls no bottom
Definition: selectors.fcl:105
OpHit3DDrawer(const fhicl::ParameterSet &)
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
def style
Definition: util.py:237
walls no top
Definition: selectors.fcl:105
The color scales used by the event display.
double HalfW() const
Definition: OpDetGeo.cxx:71
void Draw(const art::Event &, evdb::View3D *) const override
double HalfH() const
Definition: OpDetGeo.cxx:79
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
art framework interface to geometry description
void DrawRectangularBox(evdb::View3D *, const Eigen::Vector3f &, const Eigen::Vector3f &, int, int, int) const
Signal from collection planes.
Definition: geo_types.h:146