SdCalibPlotter.cc
Go to the documentation of this file.
1 #include "HistoView.h"
2 #include "BaselineView.h"
3 #include "FADCTraceView.h"
4 #include "VEMTraceView.h"
5 #include "AddText.h"
6 #include "SdCalibPlotter.h"
7 
8 #include <utl/String.h>
9 #include <utl/UTCDateTime.h>
10 #include <evt/Event.h>
11 #include <sevt/SEvent.h>
12 #include <sevt/Header.h>
13 #include <sevt/PMTCalibData.h>
14 #include <sevt/Station.h>
15 
16 #include <det/Detector.h>
17 #include <sdet/SDetector.h>
18 #include <sdet/Station.h>
19 
20 #include <TROOT.h>
21 #include <TStyle.h>
22 #include <TCanvas.h>
23 #include <TGaxis.h>
24 #include <TPaveText.h>
25 #include <TError.h>
26 
27 #include <boost/format.hpp>
28 
29 using namespace evt;
30 using namespace sevt;
31 using namespace utl;
32 using namespace fwk;
33 using namespace boost;
34 using namespace std;
35 using namespace SdCalibPlotterOG;
36 
37 
38 namespace SdCalibPlotterOG {
39 
41  public:
42  SaveCurrentTErrorIgnoreLevel(const int newLevel) : fLevel(gErrorIgnoreLevel) { gErrorIgnoreLevel = newLevel; }
43  ~SaveCurrentTErrorIgnoreLevel() { gErrorIgnoreLevel = fLevel; }
44  private:
45  const int fLevel;
46  };
47 
48 
49  void
50  AddHeader(TPaveText& pt, const Event& event, const Station& station, bool addLine = true)
51  {
52  pt.SetBorderSize(0);
53  pt.SetFillColor(kWhite);
54  pt.SetTextAlign(12);
55  ostringstream os;
56  os << "Event: " << event.GetSEvent().GetHeader().GetId() << " " << UTCDateTime(event.GetHeader().GetTime());
57  pt.AddText(os.str().c_str());
58  os.str("");
59  os << "Station: " << station.GetId();
60  pt.AddText(os.str().c_str());
61  os.str("");
62  os << "Reject flags: " << AsBinary(station.GetRejectionStatus(), StationConstants::eNumRejectionStatusBits);
63  TText* const rt = pt.AddText(os.str().c_str());
64  if (station.GetRejectionStatus())
65  rt->SetTextColor(kRed);
66  os.str("");
67  os << "Calibration version: " << station.GetCalibData().GetVersion();
68  pt.AddText(os.str().c_str());
69  if (addLine)
70  pt.AddText("");
71  }
72 
73 
76  {
77  fDrawHistograms = true;
78  fDrawBaselines = true;
79  fDrawFADCTraces = true;
80  fDrawVEMTraces = true;
81 
82  fROOTFile = new TFile((fFilename + ".root").c_str(), "recreate", fFilename.c_str(), 9);
83  fROOTFile->cd();
84 
85  const double scale = 2.5;
86  gROOT->SetStyle("Plain");
87  gROOT->SetBatch(true);
88  gStyle->SetPalette(1, 0);
89  //gStyle->SetOptTitle(0);
90  gStyle->SetNumberContours(99);
91  gStyle->SetLabelFont(12, "XYZ");
92  gStyle->SetLabelSize(0.03*scale, "XYZ");
93  gStyle->SetTitleFont(12, "XYZ");
94  gStyle->SetTitleSize(0.03*scale, "XYZ");
95  gStyle->SetStripDecimals(false);
96  TGaxis::SetMaxDigits(5);
97  gStyle->SetLineStyleString(11, "3 8");
98 
99  gStyle->SetPaperSize(TStyle::kA4);
100  gStyle->SetTitlePS("Offline SdCalibrator");
101 
102  fMultipage = "(";
103 
104  fRunCounter = 0;
105 
106  return eSuccess;
107  }
108 
109 
111  SdCalibPlotter::Run(Event& event)
112  {
113  if (!event.HasSEvent())
114  return eSuccess;
115  const auto& sEvent = event.GetSEvent();
116 
117  const int firstPMT = sdet::Station::GetFirstPMTId();
118 
119  const auto eventId = sEvent.GetHeader().GetId();
120 
121  bool inEventDir = false;
122 
123  const auto eventDirName = (format("Event_%04d") % eventId).str();
124 
125  for (const auto& station : sEvent.StationsRange()) {
126  if (!station.HasCalibData())
127  continue;
128  const StationCalibData& sCalib = station.GetCalibData();
129  const int calibVersion = sCalib.GetVersion();
130  if (!inEventDir) {
131  inEventDir = fROOTFile->mkdir(eventDirName.c_str());
132  fROOTFile->cd(eventDirName.c_str());
133  }
134  const int sId = station.GetId();
135  const auto& dStation = det::Detector::GetInstance().GetSDetector().GetStation(sId);
136 
137  // histograms
138  if (fDrawHistograms) {
139  const auto canvasName = (format("Station_%04d_Histograms") % sId).str();
140  TCanvas canvas(canvasName.c_str(), canvasName.c_str(), 720, 1000);
141  HistoView::DividePage(canvas);
142 
143  MuonPeakView muPeakView[3];
144  MuonChargeView muChargeView[3];
145  MuonShapeView muShapeView[3];
146  PMTBaselineView baselineView[3];
147 
148  for (int p = 0; p < 3; ++p) {
149  const int pmtId = p + firstPMT;
150  const auto& pmt = station.GetPMT(pmtId);
151 
152  // peak
153  canvas.cd(2*p + 2);
154  muPeakView[p].Draw(dStation, station, pmt, p+1);
155 
156  // charge
157  canvas.cd(2*p + 3);
158  muChargeView[p].Draw(dStation, station, pmt, p+1);
159 
160  // shape
161  canvas.cd(8+p);
162  muShapeView[p].Draw(dStation, pmt, p+1, calibVersion);
163 
164  // baseline
165  canvas.cd(11+p);
166  baselineView[p].Draw(dStation, pmt, p+1);
167  }
168 
169  // header
170  canvas.cd(1);
171  TPaveText pt(0,0.1,0.5,0.9, "br");
172  pt.SetTextSize(0.13);
173  AddHeader(pt, event, station);
174  pt.Draw();
175 
176  canvas.Update();
177  canvas.Write(canvasName.c_str());
178  SaveCurrentTErrorIgnoreLevel save(kWarning);
179  canvas.Print((fFilename + "_Histograms.pdf" + fMultipage).c_str(), "pdf");
180  }
181 
182  // baselines
183  if (fDrawBaselines) {
184  const auto canvasName = (format("Station_%04d_Baselines") % sId).str();
185  TCanvas canvas(canvasName.c_str(), canvasName.c_str(), 1500, 1060);
186  BaselineView::DividePage(canvas);
187 
188  LowGainBaselineView lgView[3];
189  HighGainBaselineView hgView[3];
190 
191  for (int p = 0; p < 3; ++p) {
192  const int pmtId = p + firstPMT;
193  const auto& pmt = station.GetPMT(pmtId);
194 
195  // high gain
196  canvas.cd(2+p);
197  hgView[p].Draw(pmt);
198 
199  // low gain
200  canvas.cd(5+p);
201  lgView[p].Draw(pmt);
202 
203  }
204 
205  // header
206  canvas.cd(1);
207  TPaveText pt(0,0.86,1,1, "br");
208  pt.SetTextSize(0.055);
209  AddHeader(pt, event, station);
210  pt.Draw();
211 
212  canvas.Update();
213  canvas.Write(canvasName.c_str());
214  SaveCurrentTErrorIgnoreLevel save(kWarning);
215  canvas.Print((fFilename + "_Baselines.pdf" + fMultipage).c_str(), "pdf");
216  }
217 
218  // fadc traces
219  if (fDrawFADCTraces) {
220  const auto canvasName = (format("Station_%04d_FADCTraces") % sId).str();
221  TCanvas canvas(canvasName.c_str(), canvasName.c_str(), 1500, 1060);
222  FADCTraceView::DividePage(canvas);
223 
224  LowGainFADCTraceView lgView[3];
225  HighGainFADCTraceView hgView[3];
226 
227  for (int p = 0; p < 3; ++p) {
228  const int pmtId = p + firstPMT;
229  const auto& pmt = station.GetPMT(pmtId);
230 
231  // high gain
232  canvas.cd(2+p);
233  hgView[p].Draw(pmt);
234 
235  // low gain
236  canvas.cd(5+p);
237  lgView[p].Draw(pmt);
238 
239  }
240 
241  // header
242  canvas.cd(1);
243  TPaveText pt(0,0.86,1,1, "br");
244  pt.SetTextSize(0.055);
245  AddHeader(pt, event, station);
246  pt.Draw();
247 
248  canvas.Update();
249  canvas.Write(canvasName.c_str());
250  SaveCurrentTErrorIgnoreLevel save(kWarning);
251  canvas.Print((fFilename + "_FADCTraces.pdf" + fMultipage).c_str(), "pdf");
252  }
253 
254  // vem traces
255  if (fDrawVEMTraces) {
256  const auto canvasName = (format("Station_%04d_VEMTraces") % sId).str();
257  TCanvas canvas(canvasName.c_str(), canvasName.c_str(), 1500, 1060);
258  VEMTraceView::DividePage(canvas);
259 
260  PMTVEMTraceView pmtView[3];
261  StationVEMTraceView stationView;
262 
263  int stationStart = -1;
264  int stationStop = -1;
265  if (station.HasRecData()) {
266  const auto& stRec = station.GetRecData();
267  stationStart = stRec.GetSignalStartSlot();
268  stationStop = stRec.GetSignalEndSlot();
269  }
270 
271  for (int p = 0; p < 3; ++p) {
272  const int pmtId = p + firstPMT;
273  const auto& pmt = station.GetPMT(pmtId);
274  // high gain
275  canvas.cd(2+p);
276  pmtView[p].Draw(pmt, stationStart, stationStop);
277  }
278 
279  canvas.cd(5);
280  stationView.Draw(station);
281 
282  // header
283  canvas.cd(1);
284  TPaveText pt(0,0.86,1,1, "br");
285  pt.SetTextSize(0.055);
286  AddHeader(pt, event, station);
287  pt.Draw();
288 
289  canvas.Update();
290  canvas.Write(canvasName.c_str());
291  SaveCurrentTErrorIgnoreLevel save(kWarning);
292  canvas.Print((fFilename + "_VEMTraces.pdf" + fMultipage).c_str(), "pdf");
293  }
294 
295  fMultipage = "";
296  }
297 
298  fROOTFile->cd();
299 
300  ++fRunCounter;
301  if (!(fRunCounter % 10)) {
302  INFO("Flushing.");
303  fROOTFile->Flush();
304  }
305 
306  return eSuccess;
307  }
308 
309 
311  SdCalibPlotter::Finish()
312  {
313  fMultipage = ")";
314 
315  SaveCurrentTErrorIgnoreLevel save(kWarning);
316 
317  TCanvas c;
318  if (fDrawHistograms)
319  c.Print((fFilename + "_Histograms.pdf" + fMultipage).c_str(), "pdf");
320  if (fDrawBaselines)
321  c.Print((fFilename + "_Baselines.pdf" + fMultipage).c_str(), "pdf");
322  if (fDrawFADCTraces)
323  c.Print((fFilename + "_FADCTraces.pdf" + fMultipage).c_str(), "pdf");
324  if (fDrawVEMTraces)
325  c.Print((fFilename + "_VEMTraces.pdf" + fMultipage).c_str(), "pdf");
326 
327  fROOTFile->Close();
328  delete fROOTFile;
329  fROOTFile = nullptr;
330 
331  return eSuccess;
332  }
333 
334 }
int GetId() const
Get the station Id.
void Draw(const sevt::PMT &pmt)
Definition: BaselineView.cc:62
evt::Header & GetHeader()
void Draw(const sdet::Station &dStation, const sevt::Station &sStation, const sevt::PMT &pmt, const int pmtId)
Definition: HistoView.cc:30
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
class to hold data at Station level
std::string AsBinary(const T &number, const int maxBits=8 *sizeof(T), const char separator= ' ', const int stride=4)
converts integer-type numbers into a string of binary representation
Definition: String.h:135
void Draw(const sdet::Station &dStation, const sevt::PMT &pmt, const int pmtId, const int calibrationVersion)
Definition: HistoView.cc:87
Station Calibration data
sevt::StationCalibData & GetCalibData()
Get calibration data for the station.
void Draw(const sevt::Station &station)
void Draw(const sevt::PMT &pmt, const int stationStart, const int stationStop)
Definition: VEMTraceView.cc:64
void Draw(const sdet::Station &dStation, const sevt::PMT &pmt, const int pmtId)
Definition: HistoView.cc:111
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetRejectionStatus() const
static unsigned int GetFirstPMTId()
Id of first pmt in station.
int GetVersion() const
version of the onboard calibration
void Draw(const sdet::Station &dStation, const sevt::Station &sStation, const sevt::PMT &pmt, const int pmtId)
Definition: HistoView.cc:57
void Draw(const sevt::PMT &pmt)
void AddHeader(TPaveText &pt, const Event &event, const Station &station, bool addLine=true)
bool HasSEvent() const

, generated on Tue Sep 26 2023.