FADCTraceView.cc
Go to the documentation of this file.
1 #include <sevt/PMT.h>
2 #include <utl/Accumulator.h>
3 
4 #include "AddText.h"
5 #include "FADCTraceView.h"
6 
7 #include <TCanvas.h>
8 #include <TH1D.h>
9 #include <TGraph.h>
10 #include <TGraphErrors.h>
11 #include <TArrow.h>
12 #include <TBox.h>
13 
14 #include <boost/format.hpp>
15 
16 #include <algorithm>
17 #include <sstream>
18 
19 using namespace utl;
20 using namespace sevt;
21 using namespace std;
22 using namespace boost;
23 using namespace SdCalibPlotterOG;
24 
25 
26 void
27 FADCTraceView::DividePage(TCanvas& c)
28 {
29  const double xmargin = 0.003;
30  const double ymargin = 0.003;
31  const double vertDivision = 0.2;
32 
33  TPad* const savePad = (TPad*)gPad;
34  c.cd();
35  const string name = c.GetName();
36  ostringstream os;
37  int n = 1;
38  os.str(""); os << name << "_1";
39  const double x1 = xmargin;
40  const double x2 = vertDivision - 0.5*xmargin;
41  const double x3 = vertDivision + 0.5*xmargin;
42  const double x4 = 1 - xmargin;
43  const double y11 = ymargin;
44  const double y12 = 1 - ymargin;
45  TPad* const pad1 = new TPad(os.str().c_str(), os.str().c_str(), x1, y11, x2, y12, 0);
46  pad1->SetNumber(n++);
47  pad1->Draw();
48  const int nRows = 6;
49  for (int row = 0; row < nRows; ++row) {
50  const double y1 = 1 - (row+1)*(1 - ymargin)/nRows;
51  const double y2 = 1 - ymargin - row*(1 - ymargin)/nRows;
52  os.str(""); os << name << '_' << n;
53  TPad* const pad = new TPad(os.str().c_str(), os.str().c_str(), x3, y1, x4, y2, 0);
54  pad->SetNumber(n++);
55  pad->SetLeftMargin(0.5*pad->GetLeftMargin());
56  pad->SetRightMargin(0);
57  pad->Draw();
58  }
59  savePad->cd();
60 }
61 
62 
63 void
64 FADCTraceView::Draw(const PMT& pmt)
65 {
66  // raw trace
67  if (!pmt.HasFADCTrace()) {
68  Missing("No FADC Trace");
69  return;
70  }
71 
72  const auto& trace = pmt.GetFADCTrace(fGain);
73  const auto traceLength = trace.GetSize();
74  ostringstream os;
75  os << "PMT" << pmt.GetId() << '_'
76  << (fGain == sdet::PMTConstants::eLowGain ? "LowGain" : "HighGain")
77  << "_Trace";
78  auto& th = Add(new TH1D(os.str().c_str(), "", traceLength, 0, traceLength));
79  for (unsigned int i = 0; i < traceLength; ++i)
80  th.SetBinContent(i+1, trace[i]);
81  th.SetStats(false);
82  th.SetLineColor(kRed);
83 
84  if (!pmt.HasRecData()) {
85  Missing("No PMT Rec Data");
86  return;
87  }
88 
89  const auto& pmtRec = pmt.GetRecData();
90 
91  // baseline
92  TH1D* bh = nullptr;
93  if (!pmtRec.HasFADCBaseline(fGain))
94  Missing("No FADC Baseline");
95  else {
96  const auto& baseline = pmtRec.GetFADCBaseline(fGain);
97  bh = &Add(new TH1D((os.str() + "2").c_str(), os.str().c_str(), traceLength, 0, traceLength));
98  for (unsigned int i = 0; i < traceLength; ++i)
99  bh->SetBinContent(i+1, baseline[i]);
100  bh->SetStats(false);
101  bh->SetLineColor(kBlue);
102  bh->GetYaxis()->SetTitle("[FADC]");
103  bh->GetYaxis()->SetTitleOffset(0.23);
104  bh->GetYaxis()->SetTickLength(0.01);
105  bh->Draw();
106  }
107 
108  // min/max
109  const auto& signals = pmtRec.GetSignals();
110  const bool plotSignals =
111  (fGain == sdet::PMTConstants::eHighGain || fGain == pmtRec.GetGainUsed());
112  if (plotSignals) {
113  for (unsigned int s = 0, ns = signals.size(); s < ns; ++s) {
114  Accumulator::MinMax<int> mm(trace[signals[s].fStart]);
115  for (int i = signals[s].fStart+1, n = signals[s].fStop; i < n; ++i)
116  mm(trace[i]);
117  const double diff = 0.075*(mm.GetMax() - mm.GetMin());
118  const double newMin = mm.GetMin() - diff;
119  const double newMax = mm.GetMax() + diff;
120  if (th.GetMinimum() > newMin)
121  th.SetMinimum(newMin);
122  if (th.GetMaximum() < newMax)
123  th.SetMaximum(newMax);
124  }
125  }
126 
127  if (bh) {
128  bh->SetMinimum(th.GetMinimum());
129  bh->SetMaximum(th.GetMaximum());
130  }
131 
132  if (plotSignals) {
133 
134  // raw signals
135  const auto& rawSignals = pmtRec.GetRawSignals();
136  for (unsigned int s = 0, ns = rawSignals.size(); s < ns; ++s) {
137  Accumulator::MinMax<int> mm(trace[rawSignals[s].fStart]);
138  for (int i = rawSignals[s].fStart+1, n = rawSignals[s].fStop; i < n; ++i)
139  mm(trace[i]);
140  const double diff = 0.025*(mm.GetMax() - mm.GetMin());
141  auto& sb = Add(new TBox(rawSignals[s].fStart, mm.GetMin() - diff,
142  rawSignals[s].fStop, mm.GetMax() + diff));
143  sb.SetFillStyle(0);
144  sb.SetLineColor(kGreen);
145  sb.Draw();
146  }
147 
148  // signals
149  for (unsigned int s = 0, ns = signals.size(); s < ns; ++s) {
150  Accumulator::MinMax<int> mm(trace[signals[s].fStart]);
151  for (int i = signals[s].fStart+1, n = signals[s].fStop; i < n; ++i)
152  mm(trace[i]);
153  const int diff = mm.GetMax() - mm.GetMin();
154  const double eps = 0.05*diff;
155  auto& sb = Add(new TBox(signals[s].fStart, mm.GetMin() - eps,
156  signals[s].fStop, mm.GetMax() + eps));
157  sb.SetFillStyle(0);
158  sb.SetLineColor(8); // dark green
159  sb.Draw();
160  const double plotSpan = th.GetMaximum() - th.GetMinimum();
161  if (diff < 0.3*plotSpan) {
162  const double x = 0.5*(signals[s].fStop + signals[s].fStart);
163  auto& a = Add(new TArrow(x, mm.GetMax() + 0.4*plotSpan,
164  x, mm.GetMax() + 0.1*plotSpan, 0.01));
165  a.SetAngle(20);
166  a.SetLineColor(8); // dark green
167  a.Draw();
168  }
169  }
170 
171  }
172 
173  th.Draw("same");
174 
175  // gain used
176  if (fGain == pmtRec.GetGainUsed()) {
177  auto& pt = Add(new TPaveText(0.95,0.77,0.99,0.87, "ndc"));
178  pt.SetBorderSize(2);
179  pt.SetTextAlign(12);
180  pt.SetFillColor(kWhite);
181  pt.AddText("Used");
182  pt.Draw();
183  }
184 
185  // sturated bins
186  if (pmtRec.GetFADCSaturatedBins(fGain)) {
187  auto& pt = Add(new TPaveText(0.94,0.62,0.99,0.74, "ndc"));
188  pt.SetBorderSize(2);
189  pt.SetTextAlign(12);
190  pt.SetFillColor(kCyan);
191  pt.AddText((format("N_{sat} = %d ") % pmtRec.GetFADCSaturatedBins(fGain)).str().c_str());
192  pt.Draw();
193  }
194 
195  if (pmt.HasCalibData()) {
196 
197  const auto& pmtCalib = pmt.GetCalibData();
198 
199  // tube not OK
200  if (!pmtCalib.IsTubeOk()) {
201  auto& pt = Add(new TPaveText(0.69,0.73,0.8,0.87, "ndc"));
202  pt.SetBorderSize(2);
203  pt.SetTextAlign(12);
204  pt.SetFillColor(kRed);
205  pt.AddText("Tube not OK");
206  pt.Draw();
207  }
208 
209  // D/A ratio
210  if (fGain == sdet::PMTConstants::eLowGain) {
211  auto& pt = Add(new TPaveText(0.92,0.90,0.99,1, "ndc"));
212  pt.SetBorderSize(2);
213  pt.SetTextAlign(12);
214  pt.SetFillColor(kWhite);
215  pt.AddText((format("D/A = %.2f (%.2f)") % pmtRec.GetGainRatio() % pmtCalib.GetGainRatio()).str().c_str());
216  pt.Draw();
217  }
218 
219  }
220 }
221 
222 
223 void
224 FADCTraceView::Missing(const string& what)
225 {
226  auto& pt = Add(new TPaveText(0.3,0.4,0.7,0.6, "ndc"));
227  pt.SetBorderSize(2);
228  pt.SetFillColor(kRed);
229  pt.SetTextAlign(12);
230  pt.AddText(what.c_str());
231  pt.Draw();
232 }
constexpr double mm
Definition: AugerUnits.h:113
bool HasRecData() const
Check for existenc of PMT reconstructed data object.
Definition: SEvent/PMT.h:53
class to hold data at PMT level
Definition: SEvent/PMT.h:28
PMTCalibData & GetCalibData()
Get object containing PMT calibration data.
Definition: SEvent/PMT.h:56
PMTRecData & GetRecData()
Get object containing PMT reconstructed data.
Definition: SEvent/PMT.h:48
bool HasCalibData() const
Check for existence of PMT calibration data object.
Definition: SEvent/PMT.h:61
unsigned int GetId() const
Return Id of the PMT.
Definition: SEvent/PMT.h:32
bool HasFADCTrace(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if a FADC trace exists. Trace source may be specified.
Definition: SEvent/PMT.h:83
constexpr double s
Definition: AugerUnits.h:163
SizeType GetSize() const
Definition: Trace.h:156
double eps
utl::TraceI & GetFADCTrace(const sdet::PMTConstants::PMTGain gain=sdet::PMTConstants::eHighGain, const StationConstants::SignalComponent source=StationConstants::eTotal)
Definition: SEvent/PMT.h:72
constexpr double ns
Definition: AugerUnits.h:162
utl::TraceD & GetFADCBaseline(const sdet::PMTConstants::PMTGain gain=sdet::PMTConstants::eHighGain)
Definition: PMTRecData.h:75

, generated on Tue Sep 26 2023.