LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PlotSpacePoints_module.cc
Go to the documentation of this file.
1 // Christopher Backhouse - bckhouse@fnal.gov
2 
3 #include <string>
4 
11 #include "fhiclcpp/ParameterSet.h"
12 
17 
18 #include "TGraph.h"
19 #include "TString.h"
20 #include "TVirtualPad.h"
21 
22 namespace reco3d {
23 
25  public:
26  explicit PlotSpacePoints(const fhicl::ParameterSet& pset);
27 
28  private:
29  void analyze(const art::Event& evt) override;
30 
31  void Plot(const std::vector<recob::SpacePoint>& pts, const std::string& suffix) const;
32 
33  void Plot3D(const std::vector<recob::SpacePoint>& pts, const std::string& suffix) const;
34 
35  std::vector<recob::SpacePoint> TrueSpacePoints(detinfo::DetectorClocksData const& clockData,
36  art::Handle<std::vector<recob::Hit>> hits) const;
37 
39 
40  std::string fHitLabel;
41 
42  std::string fSuffix;
43 
44  bool fPlots;
45  bool fPlots3D;
46  bool fPlotsTrue;
47  };
48 
50 
51  // ---------------------------------------------------------------------------
52  PlotSpacePoints::PlotSpacePoints(const fhicl::ParameterSet& pset)
53  : EDAnalyzer(pset)
54  , fSpacePointTag(art::InputTag(pset.get<std::string>("SpacePointLabel"),
55  pset.get<std::string>("SpacePointInstanceLabel")))
56  , fHitLabel(pset.get<std::string>("HitLabel"))
57  , fSuffix(pset.get<std::string>("Suffix"))
58  , fPlots(pset.get<bool>("Plots"))
59  , fPlots3D(pset.get<bool>("Plots3D"))
60  , fPlotsTrue(pset.get<bool>("PlotsTrue"))
61  {
62  if (!fSuffix.empty()) fSuffix = "_" + fSuffix;
63  }
64 
65  // ---------------------------------------------------------------------------
66  void PlotSpacePoints::Plot(const std::vector<recob::SpacePoint>& pts,
67  const std::string& suffix) const
68  {
69  TGraph gZX;
70  TGraph gYX;
71  TGraph gZY;
72 
73  gZX.SetTitle(";z;x");
74  gYX.SetTitle(";y;x");
75  gZY.SetTitle(";z;y");
76 
77  for (const recob::SpacePoint& pt : pts) {
78  const double* xyz = pt.XYZ();
79  const double x = xyz[0];
80  const double y = xyz[1];
81  const double z = xyz[2];
82  gZX.SetPoint(gZX.GetN(), z, x);
83  gYX.SetPoint(gYX.GetN(), y, x);
84  gZY.SetPoint(gZY.GetN(), z, y);
85  }
86 
87  if (gZX.GetN() == 0) gZX.SetPoint(0, 0, 0);
88  if (gYX.GetN() == 0) gYX.SetPoint(0, 0, 0);
89  if (gZY.GetN() == 0) gZY.SetPoint(0, 0, 0);
90 
91  gZX.Draw("ap");
92  gPad->Print(("plots/evd" + suffix + ".png").c_str());
93 
94  gYX.Draw("ap");
95  gPad->Print(("plots/evd_ortho" + suffix + ".png").c_str());
96  gZY.Draw("ap");
97  gPad->Print(("plots/evd_zy" + suffix + ".png").c_str());
98  }
99 
100  // ---------------------------------------------------------------------------
101  std::vector<recob::SpacePoint> PlotSpacePoints::TrueSpacePoints(
102  detinfo::DetectorClocksData const& clockData,
103  art::Handle<std::vector<recob::Hit>> hits) const
104  {
105  std::vector<recob::SpacePoint> pts_true;
106 
107  const double err[6] = {
108  0,
109  };
110 
112  for (unsigned int i = 0; i < hits->size(); ++i) {
113  try {
114  const std::vector<double> xyz = bt_serv->HitToXYZ(clockData, art::Ptr<recob::Hit>(hits, i));
115  pts_true.emplace_back(&xyz[0], err, 0);
116  }
117  catch (...) {
118  } // some hits have no electrons?
119  }
120 
121  return pts_true;
122  }
123 
124  // ---------------------------------------------------------------------------
125  void PlotSpacePoints::Plot3D(const std::vector<recob::SpacePoint>& pts,
126  const std::string& suffix) const
127  {
128  int frame = 0;
129  for (int phase = 0; phase < 4; ++phase) {
130  const int Nang = 20;
131  for (int iang = 0; iang < Nang; ++iang) {
132  const double ang = M_PI / 2 * iang / double(Nang);
133 
134  TGraph g;
135 
136  for (const recob::SpacePoint& p : pts) {
137  const double* xyz = p.XYZ();
138 
139  double x{}, y{};
140  if (phase == 0) {
141  x = cos(ang) * xyz[1] + sin(ang) * xyz[2];
142  y = xyz[0];
143  }
144  if (phase == 1) {
145  x = xyz[2];
146  y = cos(ang) * xyz[0] + sin(ang) * xyz[1];
147  }
148  if (phase == 2) {
149  x = cos(ang) * xyz[2] - sin(ang) * xyz[0];
150  y = xyz[1];
151  }
152  if (phase == 3) {
153  x = -cos(ang) * xyz[0] + sin(ang) * xyz[1];
154  y = cos(ang) * xyz[1] + sin(ang) * xyz[0];
155  }
156 
157  // const double phi = phase/3.*M_PI/2 + ang/3;
158  const double phi = 0;
159  g.SetPoint(g.GetN(), cos(phi) * x + sin(phi) * y, cos(phi) * y - sin(phi) * x);
160  }
161 
162  std::string fname =
163  TString::Format(("anim/evd3d" + suffix + "_%03d.png").c_str(), frame++).Data();
164  g.SetTitle(fname.c_str());
165  if (g.GetN()) g.Draw("ap");
166  gPad->Print(fname.c_str());
167  }
168  }
169  }
170 
172  {
173  if (fPlots) {
175  evt.getByLabel(fSpacePointTag, pts);
176 
177  const std::string suffix = TString::Format("%s_%d", fSuffix.c_str(), evt.event()).Data();
178 
179  if (!pts->empty()) {
180  Plot(*pts, suffix);
181 
182  if (fPlots3D) Plot3D(*pts, suffix);
183  }
184  }
185 
186  if (fPlotsTrue) {
188  evt.getByLabel(fHitLabel, hits);
189  auto const clockData =
191  const std::vector<recob::SpacePoint> pts = TrueSpacePoints(clockData, hits);
192 
193  const std::string suffix = TString::Format("%s_true_%d", fSuffix.c_str(), evt.event()).Data();
194 
195  Plot(pts, suffix);
196 
197  if (fPlots3D) Plot3D(pts, suffix);
198  }
199  }
200 
201 } // namespace
Float_t x
Definition: compare.C:6
std::vector< recob::SpacePoint > TrueSpacePoints(detinfo::DetectorClocksData const &clockData, art::Handle< std::vector< recob::Hit >> hits) const
Declaration of signal hit object.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
PlotSpacePoints(const fhicl::ParameterSet &pset)
STL namespace.
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
parameter set interface
TMarker * pt
Definition: egs.C:25
EventNumber_t event() const
Definition: Event.cc:41
void Plot3D(const std::vector< recob::SpacePoint > &pts, const std::string &suffix) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Contains all timing reference information for the detector.
Definition: MVAAlg.h:12
TCEvent evt
Definition: DataStructs.cxx:8
void Plot(const std::vector< recob::SpacePoint > &pts, const std::string &suffix) const
void analyze(const art::Event &evt) override