LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
PlotSpacePoints_module.cc
Go to the documentation of this file.
1 // Christopher Backhouse - bckhouse@fnal.gov
2 
3 #include <string>
4 #include <vector>
5 
14 
17 
19 
20 #include "TGraph.h"
21 #include "TPad.h"
22 
23 namespace reco3d
24 {
25 
27 {
28 public:
29  explicit PlotSpacePoints(const fhicl::ParameterSet& pset);
30 
31  void analyze(const art::Event& evt);
32 
33 protected:
34  void Plot(const std::vector<recob::SpacePoint>& pts,
35  const std::string& suffix) const;
36 
37  void Plot3D(const std::vector<recob::SpacePoint>& pts,
38  const std::string& suffix) const;
39 
40  std::vector<recob::SpacePoint> TrueSpacePoints(art::Handle<std::vector<recob::Hit>> hits) const;
41 
43 
44  std::string fHitLabel;
45 
46  std::string fSuffix;
47 
48  bool fPlots;
49  bool fPlots3D;
50  bool fPlotsTrue;
51 };
52 
54 
55 // ---------------------------------------------------------------------------
56 PlotSpacePoints::PlotSpacePoints(const fhicl::ParameterSet& pset)
57  : EDAnalyzer(pset),
58  fSpacePointTag(art::InputTag(pset.get<std::string>("SpacePointLabel"),
59  pset.get<std::string>("SpacePointInstanceLabel"))),
60  fHitLabel(pset.get<std::string>("HitLabel")),
61  fSuffix(pset.get<std::string>("Suffix")),
62  fPlots(pset.get<bool>("Plots")),
63  fPlots3D(pset.get<bool>("Plots3D")),
64  fPlotsTrue(pset.get<bool>("PlotsTrue"))
65 {
66  if(!fSuffix.empty()) fSuffix = "_"+fSuffix;
67 }
68 
69 // ---------------------------------------------------------------------------
70 void PlotSpacePoints::Plot(const std::vector<recob::SpacePoint>& pts,
71  const std::string& suffix) const
72 {
73  TGraph gZX;
74  TGraph gYX;
75  TGraph gZY;
76 
77  gZX.SetTitle(";z;x");
78  gYX.SetTitle(";y;x");
79  gZY.SetTitle(";z;y");
80 
81  for(const recob::SpacePoint& pt: pts){
82  const double* xyz = pt.XYZ();
83  const double x = xyz[0];
84  const double y = xyz[1];
85  const double z = xyz[2];
86  gZX.SetPoint(gZX.GetN(), z, x);
87  gYX.SetPoint(gYX.GetN(), y, x);
88  gZY.SetPoint(gZY.GetN(), z, y);
89  }
90 
91  if(gZX.GetN() == 0) gZX.SetPoint(0, 0, 0);
92  if(gYX.GetN() == 0) gYX.SetPoint(0, 0, 0);
93  if(gZY.GetN() == 0) gZY.SetPoint(0, 0, 0);
94 
95  gZX.Draw("ap");
96  gPad->Print(("plots/evd"+suffix+".png").c_str());
97 
98  gYX.Draw("ap");
99  gPad->Print(("plots/evd_ortho"+suffix+".png").c_str());
100  gZY.Draw("ap");
101  gPad->Print(("plots/evd_zy"+suffix+".png").c_str());
102 }
103 
104 // ---------------------------------------------------------------------------
105 std::vector<recob::SpacePoint> PlotSpacePoints::
106 TrueSpacePoints(art::Handle<std::vector<recob::Hit>> hits) const
107 {
108  std::vector<recob::SpacePoint> pts_true;
109 
110  const double err[6] = {0,};
111 
113  for(unsigned int i = 0; i < hits->size(); ++i){
114  try{
115  const std::vector<double> xyz = bt_serv->HitToXYZ(art::Ptr<recob::Hit>(hits, i));
116  pts_true.emplace_back(&xyz[0], err, 0);
117  }
118  catch(...){} // 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 = TString::Format(("anim/evd3d"+suffix+"_%03d.png").c_str(), frame++).Data();
163  g.SetTitle(fname.c_str());
164  if(g.GetN()) g.Draw("ap");
165  gPad->Print(fname.c_str());
166  }
167  }
168 }
169 
171 {
172  if(fPlots){
174  evt.getByLabel(fSpacePointTag, pts);
175 
176  const std::string suffix = TString::Format("%s_%d", fSuffix.c_str(), evt.event()).Data();
177 
178  if(!pts->empty()){
179  Plot(*pts, suffix);
180 
181  if(fPlots3D) Plot3D(*pts, suffix);
182  }
183  }
184 
185  if(fPlotsTrue){
187  evt.getByLabel(fHitLabel, hits);
188  const std::vector<recob::SpacePoint> pts = TrueSpacePoints(hits);
189 
190  const std::string suffix = TString::Format("%s_true_%d", fSuffix.c_str(), evt.event()).Data();
191 
192  Plot(pts, suffix);
193 
194  if(fPlots3D) Plot3D(pts, suffix);
195  }
196 }
197 
198 } // namespace
Float_t x
Definition: compare.C:6
std::vector< recob::SpacePoint > TrueSpacePoints(art::Handle< std::vector< recob::Hit >> hits) const
const std::vector< double > HitToXYZ(const recob::Hit &hit)
Declaration of signal hit object.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
PlotSpacePoints(const fhicl::ParameterSet &pset)
STL namespace.
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
parameter set interface
TMarker * pt
Definition: egs.C:25
EventNumber_t event() const
Definition: Event.h:67
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
void Plot3D(const std::vector< recob::SpacePoint > &pts, const std::string &suffix) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void analyze(const art::Event &evt)
HLT enums.
TCEvent evt
Definition: DataStructs.cxx:5
void Plot(const std::vector< recob::SpacePoint > &pts, const std::string &suffix) const