2 #include "PixMonitor.hh"
10 #include <TTimeStamp.h>
11 #include <TDirectory.h>
18 PixMonitor::PixMonitor(
pxarCore *a): fApi(a), fIana(0.), fIdig(0.) {
22 PixMonitor::~PixMonitor() {
23 LOG(logDEBUG) <<
"PixMonitor dtor";
27 void PixMonitor::init() {
28 LOG(logDEBUG) <<
"PixMonitor init";
32 void PixMonitor::dumpSummaries() {
34 LOG(logDEBUG) <<
"PixMonitor::dumpSummaries";
35 if (fMeasurements.size() < 1)
return;
36 ULong_t begSec = fMeasurements[0].first;
37 ULong_t endSec = fMeasurements[fMeasurements.size()-1].first+1;
38 TTimeStamp ts(begSec);
40 TH1D *ha =
new TH1D(
"HA", Form(
"analog current measurements, start: %s / sec:%ld", ts.AsString(
"lc"), begSec), endSec-begSec, 0., endSec-begSec);
41 ha->SetXTitle(Form(
"seconds after %s", ts.AsString(
"lc")));
42 ha->SetTitleSize(0.03,
"X");
43 ha->SetTitleOffset(1.5,
"X");
45 TH1D *hd =
new TH1D(
"HD", Form(
"digital current measurements, start: %s / sec:%ld", ts.AsString(
"lc"), begSec), endSec-begSec, 0., endSec-begSec);
46 hd->SetXTitle(Form(
"seconds after %s", ts.AsString(
"lc")));
47 hd->SetTitleSize(0.03,
"X");
48 hd->SetTitleOffset(1.5,
"X");
50 for (
unsigned int i = 0; i < fMeasurements.size(); ++i) {
51 int ibin = fMeasurements[i].first - begSec;
52 ha->SetBinContent(ibin+1, fMeasurements[i].second.first);
53 hd->SetBinContent(ibin+1, fMeasurements[i].second.second);
59 ha->SetDirectory(gFile);
62 hd->SetDirectory(gFile);
67 void PixMonitor::update() {
73 ULong_t seconds = ts.GetSec();
75 TH1D *ha = (TH1D*)gDirectory->Get(
"ha");
77 ha =
new TH1D(
"ha", Form(
"analog current, start: %s / sec:%ld", ts.AsString(
"lc"), seconds), NBINS, 0, NBINS);
78 ha->SetXTitle(Form(
"seconds after %s", ts.AsString(
"lc")));
79 ha->SetTitleSize(0.03,
"X");
80 ha->SetTitleOffset(1.5,
"X");
82 int histMinSec = getHistMinSec(ha);
83 int ibin = seconds - histMinSec;
85 if (ibin > ha->GetNbinsX()) ha = extendHist(ha, ibin);
86 ha->SetBinContent(ibin+1, fIana);
88 TH1D *hd = (TH1D*)gDirectory->Get(
"hd");
90 hd =
new TH1D(
"hd", Form(
"digital current, start: %s / sec:%ld", ts.AsString(
"lc"), seconds), NBINS, 0, NBINS);
91 hd->SetXTitle(Form(
"seconds after %s", ts.AsString(
"lc")));
92 hd->SetTitleSize(0.03,
"X");
93 hd->SetTitleOffset(1.5,
"X");
95 if (ibin > hd->GetNbinsX()) hd = extendHist(hd, ibin);
96 hd->SetBinContent(ibin+1, fIdig);
98 fMeasurements.push_back(make_pair(seconds, make_pair(fIana, fIdig)));
104 void PixMonitor::drawHist(
string hname) {
106 ULong_t begSec = fMeasurements[0].first;
107 ULong_t endSec = fMeasurements[fMeasurements.size()-1].first+1;
108 TTimeStamp ts(begSec);
111 if (hname ==
"iana") title =
"analog";
112 if (hname ==
"idig") title =
"digital";
113 TH1D *ha = (TH1D*)gDirectory->Get(
"HA");
115 ha =
new TH1D(
"HA", Form(
"%s current measurements, start: %s / sec:%ld", title.c_str(), ts.AsString(
"lc"), begSec),
116 endSec-begSec, 0., endSec-begSec);
117 ha->SetXTitle(Form(
"seconds after %s", ts.AsString(
"lc")));
118 ha->SetTitleSize(0.03,
"X");
119 ha->SetTitleOffset(1.5,
"X");
121 ha->SetMarkerStyle(20);
122 ha->SetMarkerSize(1);
125 if (hname ==
"iana") {
126 for (
unsigned int i = 0; i < fMeasurements.size(); ++i) {
127 int ibin = fMeasurements[i].first - begSec;
128 ha->SetBinContent(ibin+1, fMeasurements[i].second.first);
132 if (hname ==
"idig") {
133 for (
unsigned int i = 0; i < fMeasurements.size(); ++i) {
134 int ibin = fMeasurements[i].first - begSec;
135 ha->SetBinContent(ibin+1, fMeasurements[i].second.second);
146 TH1D* PixMonitor::extendHist(TH1D *h,
int ibin) {
147 if (0 == h)
return 0;
148 int nbins = h->GetNbinsX();
149 TH1D *hnew =
new TH1D(
"nhew", h->GetTitle(), ibin + 10, 0, ibin + 10);
150 for (
int i = 1; i <= nbins; ++i) {
151 hnew->SetBinContent(i, h->GetBinContent(i));
152 hnew->SetXTitle(h->GetXaxis()->GetTitle());
153 hnew->SetTitleSize(0.03,
"X");
154 hnew->SetTitleOffset(1.5,
"X");
156 string hname = h->GetName();
158 hnew->SetName(hname.c_str());
164 UInt_t PixMonitor::getHistMinSec(TH1D *h) {
165 string htitle = h->GetTitle();
166 string::size_type s1 = htitle.rfind(
"sec:");
167 string sseconds = htitle.substr(s1+4);
168 UInt_t seconds = atoi(sseconds.c_str());