8 #include <TGraphErrors.h>    12 #include <TPaveText.h>    17 #include <TMultiGraph.h>    19 #include <TPaveStats.h>    22 #include <TSQLServer.h>    23 #include <TSQLResult.h>    24 #include <TSQLStatement.h>    43 void graphZoom(TGraph* gr, 
double n_sigma);
    63   bool fMetricTimeGraphLog;
    67   NearlinePlotLogScale(
bool metric_time_graph_log=
true, 
bool histo_1d_log=
true, 
bool histo_2d_log=
true, 
bool bin_by_bin_log=
true){
    68     fMetricTimeGraphLog=metric_time_graph_log;
    69     fHisto1DLog=histo_1d_log;
    70     fHisto2DLog=histo_2d_log;
    71     fBinByBinLog=bin_by_bin_log;
    77   bool fMakeMetricTimeGraph;
    79   bool fMakeBinByBinPlots;
    80   bool fNormaliseHisto1D;
    81   NearlinePlotEnables(
bool normalise_histo_1d=
false, 
bool make_metric_time_graph=
true, 
bool make_2d_histo=
true, 
bool make_bin_by_bin_plots=
false){
    82     fMakeMetricTimeGraph=make_metric_time_graph;
    83     fMake2DHisto=make_2d_histo;
    84     fMakeBinByBinPlots=make_bin_by_bin_plots;
    85     fNormaliseHisto1D=normalise_histo_1d;
    98   std::string GetMetricMeanTimeGraphName(
bool zoom=
false);
    99   std::string GetMetricRmsTimeGraphName(
bool zoom=
false);
   106     fMetricName = metric_name;
   109     fFileExtension = file_extension;
   110     fMetricDetails = metric_details;
   115     if(fChannel >= 0) sprintf(name, 
"%sChan%04i_%.3i_days.%s", fMetricName.c_str(), fChannel, fNumDays, fFileExtension.c_str());
   116     else sprintf(name, 
"%s_%.3i_days.%s", fMetricName.c_str(), fNumDays, fFileExtension.c_str());
   122     if(fChannel >=0) sprintf(name, 
"%sVsTimeChan%04i_%.3i_days.%s", fMetricName.c_str(), fChannel, fNumDays, fFileExtension.c_str());
   123     else sprintf(name, 
"%sVsTime_%.3i_days.%s", fMetricName.c_str(), fNumDays, fFileExtension.c_str());
   130   fMetricDetails = metric_details;
   136   if(fChannel >= 0) sprintf(name, 
"%sMeanTimeChan%04i_%.3i_days", fMetricName.c_str(), fChannel, fNumDays);
   137   else  sprintf(name, 
"%sMeanTime_%.3i_days", fMetricName.c_str(), fNumDays);
   139   if(zoom) sprintf(name, 
"%s_zoom.%s", name, fFileExtension.c_str());
   140   else sprintf(name, 
"%s.%s", name, fFileExtension.c_str());
   147   if(fChannel >= 0) sprintf(name, 
"%sRmsTimeChan%04i_%.3i_days", fMetricName.c_str(), fChannel, fNumDays);
   148   else  sprintf(name, 
"%sRmsTime_%.3i_days", fMetricName.c_str(), fNumDays);
   150   if(zoom) sprintf(name, 
"%s_zoom.%s", name, fFileExtension.c_str());
   151   else sprintf(name, 
"%s.%s", name, fFileExtension.c_str());
   158   if(fChannel>=0) sprintf(name, 
"%sTimeChan%04iBin%u_%.3i_days.%s", fMetricName.c_str(), fChannel, 
bin, fNumDays, fFileExtension.c_str());
   159   else sprintf(name, 
"%sTimeBin%u_%.3i_days.%s", fMetricName.c_str(), 
bin, fNumDays, fFileExtension.c_str());
   177   TH1F* fHistogram2DNormalisation;
   180   TGraph* fGraphMetricTime;
   181   TGraph* fGraphMetricRmsTime;
   182   std::vector<float> fMetricVec;
   183   std::vector<float> fMetricRmsVec;
   184   std::vector<float> fTimeVec;
   187   std::vector<TGraphErrors*> fBinByBinGraphMetricTime;
   188   std::vector<std::vector<float>> fBinByBinMetricVec;
   189   std::vector<std::vector<float>> fBinByBinMetricErrorVec;
   190   std::vector<std::string> fBinByBinLabels;
   197   bool AddHistogram(TFile 
const & file, TTree* header, 
int Xsrtime, 
int XNow, 
int GMToffset, 
int time_ago);
   198   bool AddHistogram1D(TFile 
const & file, TTree* header, 
int Xsrtime, 
int XNow, 
int GMToffset, 
int time_ago);
   199   bool AddHistogram2D(TFile 
const & file, TTree* header, 
int Xsrtime, 
int XNow, 
int GMToffset, 
int time_ago);
   200   void normaliseHisto1D();
   202   TCanvas* makeHistoCanvas(TPaveText* updateText, 
int width=1200, 
int height=800);
   203   TCanvas* makeHisto2DCanvas(TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   204   TCanvas* makeGraphMetricTimeCanvas(TPaveText* updateText, 
int time_ago, 
int XNow, 
bool rms=
false, 
bool zoom=
false, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   205   TCanvas* makeBinByBinGraphTime(
unsigned int bin, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   206   void printPlots(
std::string plot_dir, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   207   void printHistogram1D(
std::string plot_dir, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   208   void printHistogram2D(
std::string plot_dir, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   209   void printGraphs(
std::string plot_dir, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   210   void printBinByBinGraphs(
std::string plot_dir, TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800, 
std::string taxis_labels=
"");
   222   fPlotEnables=this_plot_enable;
   223   fPlotLogScale=this_plot_log_scale;
   226   fHistName = this_hist_name;  
   227   fPlotInfo = this_plot_info;
   231   fHistogram2DNormalisation=0;
   234   fMetricVec.resize(0);
   235   fMetricRmsVec.resize(0);
   238   fGraphMetricTime = 0;
   239   fGraphMetricRmsTime = 0;
   241   fBinByBinGraphMetricTime.resize(0);
   242   fBinByBinMetricVec.resize(0);
   243   fBinByBinMetricErrorVec.resize(0);
   244   fBinByBinLabels.resize(0);
   245   fBinByBinYAxisTitle = 
"";
   249   fHistTitle = hist_title;
   253   fPlotInfo = this_plot_info;
   257   fPlotInfo.AddMetricDetails(metric_details);
   264   result = AddHistogram1D(file, header, Xsrtime, XNow, 
GMToffset, time_ago);
   265   if(fPlotEnables.fMake2DHisto) result = result & AddHistogram2D(file, header, Xsrtime, XNow, 
GMToffset, time_ago);
   272   TH1F *hist_temp = (TH1F*)file.FindObjectAny(fHistName.c_str());    
   275       fHistogram = (TH1F*) hist_temp->Clone((fHistName + 
"_temp").c_str());
   276       if(fHistTitle!=
"") fHistogram->SetTitle(fHistTitle.c_str());
   277       else fHistTitle = fHistogram->GetTitle();
   278       fHistogram->SetDirectory(0);
   281       if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
   285       if(hist_temp->GetEntries() == 0){
   289       fHistogram->Add(hist_temp,1.0);
   296   if(hist_temp != 0 && header != 0 && Xsrtime != XNow - 
GMToffset) {
   297     fTimeVec.push_back(Xsrtime);
   298     fMetricVec.push_back(hist_temp->GetMean(1));
   299     fMetricRmsVec.push_back(hist_temp->GetRMS(1));
   301     if(fPlotEnables.fMakeBinByBinPlots){
   303       if(fBinByBinMetricVec.size()==0){
   304         fBinByBinMetricVec.resize(hist_temp->GetNbinsX());
   305         fBinByBinMetricErrorVec.resize(hist_temp->GetNbinsX());
   306         fBinByBinLabels.resize(hist_temp->GetNbinsX());
   307         fBinByBinYAxisTitle = 
std::string(hist_temp->GetYaxis()->GetTitle());
   308         for(
int bin=1; 
bin<=hist_temp->GetNbinsX();
bin++){
   310           fBinByBinLabels.at(
bin-1) = (
label);
   314       if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
   318       if(hist_temp->GetEntries() == 0){
   322       for(
int bin=1; 
bin<=hist_temp->GetNbinsX();
bin++){
   323         fBinByBinMetricVec.at(
bin-1).push_back(hist_temp->GetBinContent(
bin));
   324         fBinByBinMetricErrorVec.at(
bin-1).push_back(hist_temp->GetBinError(
bin));
   333   std::cerr << 
"NearlinePlot::AddHistogram - Failed - Shouldn't get here" << 
std::endl;
   340   TH1F *hist_temp = (TH1F*)file.FindObjectAny(fHistName.c_str());    
   342     if(fHistogram2D == 0){
   343       int nbinsx = hist_temp->GetNbinsX();
   344       double xmin = hist_temp->GetBinLowEdge(1);
   345       double xmax = hist_temp->GetBinLowEdge(1+nbinsx);
   347       double tmin = time_ago;
   349       fHistogram2D = 
new TH2F((fHistName + 
"_vs_time").c_str(), (
std::string(hist_temp->GetTitle()) + 
" - vs Time").c_str(), nbinst, tmin, tmax, nbinsx, xmin, xmax);
   351       fHistogram2D->GetYaxis()->SetTitle(hist_temp->GetXaxis()->GetTitle());
   352       fHistogram2D->GetZaxis()->SetTitle(hist_temp->GetYaxis()->GetTitle());
   355       fHistogram2DNormalisation = 
new TH1F((fHistName + 
"_normalisation").c_str(), (
std::string(hist_temp->GetName()) + 
" Normalisation").c_str(), nbinst, tmin, tmax);
   358       fHistogram2D->SetDirectory(0);
   359       fHistogram2DNormalisation->SetDirectory(0);
   362       int nbins = hist_temp->GetNbinsX();
   363       for(
int i=0;i<=nbins+1;i++){
   366           fHistogram2D->GetYaxis()->SetBinLabel(i, label.c_str());
   367           fHistogram2D->GetYaxis()->SetLabelSize(hist_temp->GetXaxis()->GetLabelSize());
   376   if(hist_temp != 0 && header != 0 && Xsrtime != XNow - 
GMToffset) {  
   378     int nbins = hist_temp->GetNbinsX();
   379     if(fHistogram->GetNbinsX() != hist_temp->GetNbinsX()){
   383     if(hist_temp->GetEntries() == 0){
   388     for(
int i=0;i<=nbins+1;i++){
   389       double content = hist_temp->GetBinContent(i);
   390       double center = hist_temp->GetBinCenter(i);
   391       fHistogram2D->Fill(Xsrtime, center, content);
   395     fHistogram2DNormalisation->Fill(Xsrtime);
   403   if(fPlotCount>0) fHistogram->Scale(1./fPlotCount);
   408   if(fPlotEnables.fNormaliseHisto1D) normaliseHisto1D();
   413   TCanvas *can = 
new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
   417   if(fPlotLogScale.fHisto1DLog) can->SetLogy();
   418   if(!(fPlotEnables.fNormaliseHisto1D)) gStyle->SetOptStat(111111);
   419   fHistogram->SetLineWidth(2);
   420   fHistogram->SetLineColor(kRed);
   421   fHistogram->SetName(fHistName.c_str());
   432   std::string can_title = fHistName + 
"_vs_time_can";
   434   TCanvas *can = 
new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
   436   if(fPlotLogScale.fHisto2DLog)  can->SetLogz();
   437   can->SetRightMargin(0.15);
   438   gStyle->SetOptStat(0);
   441   if(taxis_labels==
""){
   442     if(fPlotInfo.fNumDays <= 2) taxis_labels = 
"%H:%M";
   443     else taxis_labels = 
"%m/%d";
   446   if(fNormalised!=
true){
   447     for(
int xbin=1;xbin<=fHistogram2D->GetNbinsX();xbin++){
   448       double norm = fHistogram2DNormalisation->GetBinContent(xbin);
   449       if(norm <= 0.0) 
continue;
   450       for(
int ybin=1;ybin<=fHistogram2D->GetNbinsY();ybin++){
   451         int global_bin = fHistogram2D->GetBin(xbin, ybin);
   452         double content = fHistogram2D->GetBinContent(global_bin);
   453         if(content <= 0.0) 
continue;
   454         fHistogram2D->SetBinContent(global_bin, content/norm);
   461   fHistogram2D->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
   462   fHistogram2D->GetXaxis()->SetLimits(time_ago,XNow);
   463   fHistogram2D->GetXaxis()->SetTitle(
"(central time)");
   464   fHistogram2D->GetXaxis()->SetTimeDisplay(1);
   465   fHistogram2D->GetXaxis()->SetLabelSize(0.03);
   466   fHistogram2D->Draw(
"COLZ");
   476   if(
bin >= fBinByBinMetricVec.size()) 
return NULL;
   480   if(fBinByBinLabels.at(
bin) == 
"" ){
   485     can_title += 
" " + fBinByBinLabels.at(
bin);
   488   TCanvas* can = 
new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
   492   TGraphErrors* gr = 
new TGraphErrors(fPlotCount);
   493   for(
int i=0;i<fPlotCount;i++) gr->SetPoint(i, fTimeVec.at(i), fBinByBinMetricVec.at(
bin).at(i));
   494   for(
int i=0;i<fPlotCount;i++) gr->SetPointError(i, 0, fBinByBinMetricErrorVec.at(
bin).at(i));
   496   gr->SetTitle(can_title.c_str());
   497   gr->SetMarkerColor(kBlue);
   498   gr->GetYaxis()->SetTitle(fBinByBinYAxisTitle.c_str());
   499   gr->GetXaxis()->SetTimeDisplay(1);
   500   gr->GetXaxis()->SetLabelSize(0.03);
   502   if(taxis_labels==
""){
   503     if(fPlotInfo.fNumDays <= 2) taxis_labels = 
"%H:%M";
   504     else taxis_labels = 
"%m/%d";
   507   gr->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
   508   gr->GetXaxis()->SetLimits(time_ago,XNow);
   509   gr->GetXaxis()->SetTitle(
"(central time)");
   515   double max  = 0.0, ave = 0.0;
   516   TPaveText *LastPoint = 
new TPaveText(0.3,0.88,0.93,0.93,
"NDC");
   517   LastPoint->SetLineColor(1);
   518   LastPoint->SetFillColor(0);
   519   LastPoint->SetBorderSize(1);
   524   for(
int i = 0; i < fPlotCount; ++i) {
   525     ave += (double)fMetricVec.at(i);
   526     if(fTimeVec.at(i) > maxtime) {
   527       maxtime = fTimeVec.at(i);
   528       max     = fMetricVec.at(i);
   531   if(fPlotCount > 0) ave = ave/(double)fPlotCount;
   532   sprintf(lptext,
"Last Point = %f  /  Average = %f",max,ave);
   534   LastPoint->AddText(lptext);
   547   if(
rms) can_name= fHistName + 
"_rms_time_can";
   548   else can_name= fHistName + 
"_metric_time_can";
   551   if(
rms)  can_title = 
"RMS of " + fHistTitle;
   552   else  can_title = 
"Mean of " + fHistTitle;
   555   if(zoom) can_name += 
"_zoom";
   558   TCanvas* can = 
new TCanvas(can_name.c_str(), can_title.c_str(), width, height);
   563   std::vector<float> yValuesVec;
   565     fGraphMetricRmsTime = 
new TGraph(fPlotCount);
   566     gr = fGraphMetricRmsTime;
   567     yValuesVec = fMetricRmsVec;
   570     fGraphMetricTime = 
new TGraph(fPlotCount);
   571     gr = fGraphMetricTime;
   572     yValuesVec = fMetricVec;
   576   for(
int i=0;i<fPlotCount;i++) gr->SetPoint(i, fTimeVec.at(i), yValuesVec.at(i));
   578   gr->SetMarkerColor(kBlue);
   579   gr->GetXaxis()->SetTimeDisplay(1);
   580   gr->GetXaxis()->SetLabelSize(0.03);
   582   if(taxis_labels==
""){
   583     if(fPlotInfo.fNumDays <= 2) taxis_labels = 
"%H:%M";
   584     else taxis_labels = 
"%m/%d";
   587   gr->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
   588   gr->GetXaxis()->SetLimits(time_ago,XNow);
   589   gr->GetXaxis()->SetTitle(
"(central time)");
   594     gr->SetTitle(
std::string(can_title + 
" - Zoom").c_str());
   596   else   gr->SetTitle(can_title.c_str());
   601   double max  = 0.0, ave = 0.0;
   602   TPaveText *LastPoint = 
new TPaveText(0.3,0.88,0.93,0.93,
"NDC");
   603   LastPoint->SetLineColor(1);
   604   LastPoint->SetFillColor(0);
   605   LastPoint->SetBorderSize(1);
   610   for(
int i = 0; i < fPlotCount; ++i) {
   611     ave += (double)fMetricVec.at(i);
   612     if(fTimeVec.at(i) > maxtime) {
   613       maxtime = fTimeVec.at(i);
   614       max     = fMetricVec.at(i);
   617   if(fPlotCount > 0) ave = ave/(double)fPlotCount;
   618   sprintf(lptext,
"Last Point = %f  /  Average = %f",max,ave);
   620   LastPoint->AddText(lptext);
   631   printHistogram1D(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
   633   if(fPlotEnables.fMake2DHisto) printHistogram2D(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
   635   if(fPlotEnables.fMakeMetricTimeGraph) printGraphs(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
   637   if(fPlotEnables.fMakeBinByBinPlots) printBinByBinGraphs(plot_dir, updateText, time_ago, XNow, width, height, taxis_labels);
   642   TCanvas* can = makeHistoCanvas(updateText,  width,  height);
   643   std::string can_name = plot_dir + 
"/" + fPlotInfo.GetHistOutputName();
   644   can->Print(can_name.c_str());
   649   TCanvas* can = makeHisto2DCanvas(updateText, time_ago, XNow,  width,  height, taxis_labels);
   650   std::string can_name = plot_dir + 
"/" + fPlotInfo.GetHist2DOutputName();
   651   can->Print(can_name.c_str());
   660   for(
unsigned int bin=0;
bin<fBinByBinMetricVec.size();
bin++){ 
   661     can = makeBinByBinGraphTime(
bin, updateText, time_ago, XNow); 
   662     can_name = plot_dir + 
"/" + fPlotInfo.GetBinByBinTimeGraphName(
bin); 
   663     can->Print(can_name.c_str()); 
   679   can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
   680   can_name = plot_dir + 
"/" + fPlotInfo.GetMetricMeanTimeGraphName(zoom);
   681   can->Print(can_name.c_str());
   686   can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
   687   can_name = plot_dir + 
"/" + fPlotInfo.GetMetricMeanTimeGraphName(zoom);
   688   can->Print(can_name.c_str());
   695   can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
   696   can_name = plot_dir + 
"/" + fPlotInfo.GetMetricRmsTimeGraphName(zoom);
   697   can->Print(can_name.c_str());
   702   can = makeGraphMetricTimeCanvas(updateText, time_ago, XNow, rms, zoom);
   703   can_name = plot_dir + 
"/" + fPlotInfo.GetMetricRmsTimeGraphName(zoom);
   704   can->Print(can_name.c_str());
   717     output+=
"<h3>Start Year of the Run VS Run Number.</h3>\n";
   718     output+=
"<figure>\n";
   719     output+=
"<img src=\"" + relative_plot_path + 
"\" width=\"800\">\n";
   720     output+=
"</figure>\n";
   722     output+=
"<b>This plot requires some explanation:</b>\n";
   723     output+=
"I noticed that for a large number of runs, some or all of the data appeared to be missing from the events in the files. This resulted in one of two behaviors:\n";
   725     output+=
"<b>1)</b> The run number was correct in the art::events but the year cooresponding to the event time was 0 (which defaults to 1969.)\n";
   727     output+=
"<b>2)</b> The file from that run was entirely devoid of usable events making the run number and year default to zero (again, 1969 for the year.)\n";
   729     output+=
"Both the run number and the year are obtained from the art::events by the nearline analyzer module. So this plot should be interpreted as a very general DAQ-health indicator. Situation 1 can occur if the art::events are present in the file but there is no RCE information. Situation 2 can occur if there are no good events in the entire file. I would imagine that once the DAQ is stable during normal running, his plot will become obsolete.\n";
   731     output+=
"<BR><BR><BR>\n";
   746     if(channel >=0) output += 
"<h3>" + metric_name + 
" spectrum for channel # " + 
std::to_string(channel);
   747     else output += 
"<h3>" + metric_name + 
" spectrum";
   748     if(metric_details!=
"") output += 
" " + metric_details; 
   749     output += 
".</h3>\n";
   750     output += 
"<figure>\n";
   751     output += 
"<img src=\"" + plot_location + 
"\" width=\"800\">\n"; 
   752     output += 
"</figure>\n"; 
   766     if(channel >= 0)    output += 
"<h3>" + metric_name + 
" spectrum vs. time for channel # " + 
std::to_string(channel);
   767     else     output += 
"<h3>" + metric_name + 
" spectrum vs. time";
   768     if(metric_details!=
"") output += 
" " + metric_details; 
   769     output += 
".</h3>\n";
   770     output += 
"<figure>\n";
   771     output += 
"<img src=\"" + plot_location + 
"\" width=\"800\">\n"; 
   772     output += 
"</figure>\n"; 
   789     if(channel >= 0) output += 
"<h3>" + metric_name + 
" spectrum  for channel # " + 
std::to_string(channel);
   790     output += 
"<h3>" + metric_name + 
" spectrum";
   791     if(metric_details!=
"") output += 
" " + metric_details; 
   792     output += 
".</h3>\n";
   793     output += 
"<table>\n";
   795     output += 
"<td> <img src=\"" + plot_location_histo + 
"\" width=\"800\"></td>\n"; 
   796     output += 
"<td> <img src=\"" + plot_location_histo2d + 
"\" width=\"800\"></td>\n"; 
   798     output += 
"</table>\n";
   825     if(rms) output += 
"RMS of the ";
   826     else output += 
"Mean of the ";
   827     if(channel >= 0) output += metric_name + 
" spectra for channel # " + 
std::to_string(channel);
   828     else output += metric_name + 
" spectra";
   829     if(metric_details!=
"") output += 
" " + metric_details;
   831     output +=
"<table>\n";
   833     output +=
"<td> <img src=\"" + plot_location_unzoom + 
"\" width=\"800\"></td>\n";
   834     output +=
"<td> <img src=\"" + plot_location_zoom + 
"\" width=\"800\"></td>\n";
   836     output +=
"</table>\n";
   851     if(plot_enables.
fMake2DHisto) output += MakeHistogramPair(plot_location, plot) + 
"\n";
   852     else output += MakeHistogram(plot_location, plot) + 
"\n";
   854     if(plot_enables.
fMakeMetricTimeGraph) output += MakeGraphPair(plot_location, plot, 
false) + 
"\n";
   859     output += 
"First plot: " + metric_name + 
" spectra on a specified channel in the specified time period.\n";
   860     output += 
"Second plot: Mean of the top plot over time (each blue dot corresponds to one subrun).\n";
   861     output += 
"Third plot: RMS of the top plot over time (each blue dot corresponds to one subrun).\n";
   863     output += 
"<BR><BR><BR>\n\n";
   884         output += metric_name + 
" - ";
   887         output += 
".</h3>\n";
   888         output += 
"<figure>\n";
   889         output += 
"<img src=\"" + plot_location + 
"/" + plot_name + 
"\" width=\"800\">\n";
   890         output += 
"</figure>\n";
   895         output += 
"<h3>" + metric_name + 
" - ";
   904         output +=
"<table>\n";
   906         output +=
"<td> <img src=\"" + plot_location + 
"/" + plot_name + 
"\" width=\"800\"></td>\n";
   907         output +=
"<td> <img src=\"" + plot_location + 
"/" + plot_name_next + 
"\" width=\"800\"></td>\n";
   909         output +=
"</table>\n";
   923     output+=
"<meta http-equiv=\"refresh\" content=\"60\">\n";
   924     output+=
"</head>\n\n\n";
   925     if(Ndays<=2) output+=
"<h1>35T Nearline Monitoring - 24 Hour Plots</h1>\n\n";
   926     else if(Ndays==7) output+=
"<h1>35T Nearline Monitoring - 7 Days Plots</h1>\n\n";
   927     else if(Ndays==31) output+=
"<h1>35T Nearline Monitoring - 31 Days Plots</h1>\n\n";
   928     else output+=
"<h1>35T Nearline Monitoring - " + 
std::to_string(Ndays) + 
" Days Plots</h1>\n\n";
   929     output+=
"<h2><b>THIS PAGE IS CURRENTLY UNDER CONSTRUCTION.</b></h2>\n";
   930     output+=
"<BR><BR><BR>\n";
   939   std::vector<std::string> fVersionStrings;
   940   std::vector<int> fVersionInts;
   941   std::vector<int> fRuns;
   945     fVersionStrings.resize(0);
   946     fVersionInts.resize(0);
   953     std::string file_location = 
"/lbne/data2/users/lbnedaq/nearline/";
   954     size_t file_location_size = file_location.size();
   956     std::string output = fileName.substr(file_location_size);
   957     output = output.substr(0, output.find(
"/"));
   959     if(output.size()==0){
   962     else if(output.find(
"v") != 0){
   972     int version_index=-1;
   973     for(
size_t i=0;i<fVersionStrings.size();i++){
   974       if(version == fVersionStrings.at(i)) version_index = i;
   976     if(version_index == -1){
   977       version_index = fVersionStrings.size();
   978       fVersionStrings.push_back(version);
   981     fVersionInts.push_back(version_index);
   982     fRuns.push_back(run);    
   983     std::cerr << 
"INFO : " << 
"run " << run << 
" version " << version << 
std::endl;
   988     fGr = 
new TGraph(fRuns.size());
   989     for(
size_t i=0;i<fRuns.size();i++) fGr->SetPoint(i, fRuns.at(i), fVersionInts.at(i));
   994   TCanvas* 
GetVersionCanvas(TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800){
   995     TCanvas* can = 
new TCanvas(
"can_processing_version", 
"can_processing_version", width, height);
   996     can->SetRightMargin(0.20);
   997     TGraph* gr = GetGraph();
  1000     gr->SetTitle(
"Nearline Processing Version");   
  1001     gr->GetXaxis()->SetTitle(
"Run Number");   
  1004     gr->GetYaxis()->Set(fVersionStrings.size(),-0.5,fVersionStrings.size()-0.5);
  1005     gr->GetYaxis()->SetRangeUser(-0.5, fVersionStrings.size()-0.5);
  1006     for(
size_t i=0;i<fVersionStrings.size();i++){
  1007       gr->GetYaxis()->SetBinLabel(i+1, fVersionStrings.at(i).c_str());
  1021     sprintf(name, 
"ProcessingVersion_%.3i_days.png", Ndays);
  1027     TCanvas *can = GetVersionCanvas(updateText, time_ago, XNow, width, height);
  1028     can->Print((plot_dir + 
"/" + GetPlotName(Ndays)).c_str());
  1031     for(
size_t i=0;i<fVersionStrings.size();i++){
  1032       std::cerr << 
"INFO : Versions Used: " << fVersionStrings.at(i) << 
std::endl;
  1041     output+=
"<h3>Nearline Processing Version as a function of Run.</h3>\n";
  1042     output+=
"<figure>\n";
  1043     output+=
"<img src=\"" + relative_plot_dir + 
"/" + GetPlotName(Ndays) + 
"\" width=\"800\">\n";
  1044     output+=
"</figure>\n";
  1045     output+=
"<BR><BR><BR>\n";
  1055     std::ifstream in_file(done_file_name.c_str());
  1058     while(std::getline(in_file, line)){   
  1060       if(line.find(
"NEARLINE_PEDESTAL ") != std::string::npos)  pedestal_file = line.substr(
std::string(
"NEARLINE_PEDESTAL ").size());
  1063     return pedestal_file;
  1066   std::vector<std::string> fPedestalStrings;
  1067   std::vector<int> fPedestalInts;
  1068   std::vector<int> fRuns;
  1072     fPedestalStrings.resize(0);
  1073     fPedestalInts.resize(0);
  1081     int version_index=-1;
  1082     for(
size_t i=0;i<fPedestalStrings.size();i++){
  1083       if(version == fPedestalStrings.at(i)) version_index = i;
  1085     if(version_index == -1){
  1086       version_index = fPedestalStrings.size();
  1087       fPedestalStrings.push_back(version);
  1090     fPedestalInts.push_back(version_index);
  1091     fRuns.push_back(run);    
  1092     std::cerr << 
"INFO : " << 
"run " << run << 
" version " << version << 
std::endl;
  1097     fGr = 
new TGraph(fRuns.size());
  1098     for(
size_t i=0;i<fRuns.size();i++) fGr->SetPoint(i, fRuns.at(i), fPedestalInts.at(i));
  1103   TCanvas* 
GetPedestalCanvas(TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800){
  1104     TCanvas* can = 
new TCanvas(
"can_processing_version", 
"can_processing_version", width, height);
  1105     can->SetRightMargin(0.20);
  1106     TGraph* gr = GetGraph();
  1109     gr->SetTitle(
"Nearline Processing Pedestal");   
  1110     gr->GetXaxis()->SetTitle(
"Run Number");   
  1113     gr->GetYaxis()->Set(fPedestalStrings.size(),-0.5,fPedestalStrings.size()-0.5);
  1114     gr->GetYaxis()->SetRangeUser(-0.5, fPedestalStrings.size()-0.5);
  1115     for(
size_t i=0;i<fPedestalStrings.size();i++){
  1116       gr->GetYaxis()->SetBinLabel(i+1, fPedestalStrings.at(i).c_str());
  1130     sprintf(name, 
"ProcessingPedestal_%.3i_days.png", Ndays);
  1136     TCanvas *can = GetPedestalCanvas(updateText, time_ago, XNow, width, height);
  1137     can->Print((plot_dir + 
"/" + GetPlotName(Ndays)).c_str());
  1140     for(
size_t i=0;i<fPedestalStrings.size();i++){
  1141       std::cerr << 
"INFO : Pedestals Used: " << fPedestalStrings.at(i) << 
std::endl;
  1149     output+=
"<h3>Nearline Processing Pedestal as a function of Run.</h3>\n";
  1150     output+=
"<figure>\n";
  1151     output+=
"<img src=\"" + relative_plot_dir + 
"/" + GetPlotName(Ndays) + 
"\" width=\"800\">\n";
  1152     output+=
"</figure>\n";
  1153     output+=
"<BR><BR><BR>\n";
  1162   TDatime fEndNearlineAnaDate;
  1163   TDatime fEndNearlineMuonDate;
  1167   static TDatime GetDateTime(
std::string date, 
int Ndays);
  1170   static TDatime 
const InvalidDateTime;
  1177   fStartDate=InvalidDateTime;
  1178   fEndNearlineAnaDate=InvalidDateTime;
  1179   fEndNearlineMuonDate=InvalidDateTime;
  1180   fEndDate=InvalidDateTime;
  1182   std::ifstream in_file(
file_name.c_str());
  1190   while(std::getline(in_file, line)){   
  1191     if(line.find(
"START_DATE ") != std::string::npos)  start = line.substr(
std::string(
"START_DATE ").size());
  1192     if(line.find(
"END_NEARLINE_ANA ") != std::string::npos)  end_nearline_ana = line.substr(
std::string(
"END_NEARLINE_ANA ").size());
  1193     if(line.find(
"END_NEARLINE_MUON ") != std::string::npos)  end_nearline_muon = line.substr(
std::string(
"END_NEARLINE_MUON ").size());
  1194     if(line.find(
"END_DATE ") != std::string::npos)  end = line.substr(
std::string(
"END_DATE ").size());
  1199   if(start != 
"") fStartDate = GetDateTime(start, Ndays);
  1200   if(end_nearline_ana != 
"") fEndNearlineAnaDate = GetDateTime(end_nearline_ana, Ndays);
  1201   if(end_nearline_muon != 
"") fEndNearlineMuonDate = GetDateTime(end_nearline_muon, Ndays);
  1202   if(end != 
"") fEndDate = GetDateTime(end, Ndays);
  1209   std::string command = 
"date -d \"" + date + 
"\" +\"%Y-%m-%d %T\" > " + temp_file_name;
  1210   int retval = system(command.c_str());
  1211   std::ifstream temp_file(temp_file_name.c_str());
  1213   std::getline(temp_file, new_date);
  1215   TDatime date_time(new_date.c_str());
  1224   std::string file_name_done = file_name.substr(0, file_name.find(
"_nearline")) + 
".root.DONE";
  1225   return file_name_done;
  1235   std::string prefix_dir = file_name.substr(0, file_name.find(
"/nearline/")); 
  1236   std::string suffix_dir = file_name.substr(file_name.find(
"/v"), 
std::string(
"/v04_36_01/011/011425").size());
  1237   std::string short_file_name = file_name.substr(file_name.find(suffix_dir)+suffix_dir.size()+1);
  1238   std::string file_name_done = prefix_dir + 
"/nearline_evd" + suffix_dir + 
"_01/" + short_file_name;
  1239   file_name_done = file_name_done.substr(0, file_name_done.find(
"_nearline")) + 
".rootEVD.DONE";
  1241   return file_name_done;
  1246   std::vector<int> fVecRunTotal;
  1247   std::vector<int> fVecRunNearlineAna;
  1248   std::vector<int> fVecRunNearlineMuon;
  1249   std::vector<int> fVecTotalTime;       
  1250   std::vector<int> fVecNearlineAnaTime; 
  1251   std::vector<int> fVecNearlineMuonTime;
  1257     fVecRunTotal.resize(0);             
  1258     fVecRunNearlineAna.resize(0);               
  1259     fVecRunNearlineMuon.resize(0);              
  1260     fVecTotalTime.resize(0);      
  1261     fVecNearlineAnaTime.resize(0);        
  1262     fVecNearlineMuonTime.resize(0);
  1268     std::cerr << 
"INFO : " << 
"run " << run << 
" StartDate: " << this_processing_time.
fStartDate.AsString() << 
std::endl;
  1269     std::cerr << 
"INFO : " << 
"run " << run << 
" EndDate: " << this_processing_time.
fEndDate.AsString() << 
std::endl;
  1274     int total_time = this_processing_time.
fEndDate.Get() - this_processing_time.
fStartDate.Get();
  1275     fVecRunTotal.push_back(run);
  1276     fVecTotalTime.push_back(total_time);
  1284       nearline_ana_time = 0;
  1285       nearline_muon_time = 0;
  1288       nearline_muon_time = 0;
  1290     if(nearline_ana_time!=0){
  1291       fVecNearlineAnaTime.push_back(nearline_ana_time);
  1292       fVecRunNearlineAna.push_back(run);
  1294     if(nearline_muon_time!=0){
  1295       fVecNearlineMuonTime.push_back(nearline_ana_time);
  1296       fVecRunNearlineMuon.push_back(run);
  1301     TGraph* gr = 
new TGraph(fVecRunTotal.size());
  1302     for(
unsigned int i=0;i<fVecRunTotal.size();i++) gr->SetPoint(i, fVecRunTotal.at(i), fVecTotalTime.at(i));
  1303     if(fIsEVD) gr->SetTitle(
"Nearline Event Display Processing Time");
  1304     else gr->SetTitle(
"Nearline Processing Time");
  1305     gr->SetMarkerColor(kBlue);
  1306     gr->SetMarkerStyle(20);
  1307     gr->SetMarkerSize(1.5);
  1308     gr->GetXaxis()->SetTitle(
"Run Number");
  1309     gr->GetYaxis()->SetTitle(
"Processing Time in Seconds");
  1313     TGraph* gr = 
new TGraph(fVecRunNearlineAna.size());
  1314     for(
unsigned int i=0;i<fVecRunNearlineAna.size();i++) gr->SetPoint(i, fVecRunNearlineAna.at(i), fVecNearlineAnaTime.at(i));
  1315     gr->SetTitle(
"Nearline Ana Processing Time");
  1316     gr->SetMarkerColor(kRed);
  1317     gr->SetMarkerStyle(21);
  1318     gr->SetMarkerSize(1.5);
  1319     gr->GetXaxis()->SetTitle(
"Run Number");
  1320     gr->GetYaxis()->SetTitle(
"Processing Time in Seconds");
  1324     TGraph* gr = 
new TGraph(fVecRunNearlineMuon.size());
  1325     for(
unsigned int i=0;i<fVecRunNearlineMuon.size();i++) gr->SetPoint(i, fVecRunNearlineMuon.at(i), fVecNearlineMuonTime.at(i));
  1326     gr->SetTitle(
"Nearline Muon Processing Time");
  1327     gr->SetMarkerColor(kBlack);
  1328     gr->SetMarkerStyle(22);
  1329     gr->SetMarkerSize(1.5);
  1330     gr->GetXaxis()->SetTitle(
"Run Number");
  1331     gr->GetYaxis()->SetTitle(
"Processing Time in Seconds");
  1336     TMultiGraph* mgr = 
new TMultiGraph();
  1338     if(fIsEVD) fLegend = TLegend(0.75,0.85,0.95,0.95);
  1339     else fLegend = TLegend(0.75,0.75,0.95,0.95);
  1341     gr = GetTotalTimeGraph();
  1343     fLegend.AddEntry(gr, gr->GetTitle(), 
"p");
  1345     gr = GetNearlineAnaTimeGraph();
  1348       fLegend.AddEntry(gr, gr->GetTitle(), 
"p");
  1350     gr = GetNearlineMuonTimeGraph();
  1353       fLegend.AddEntry(gr, gr->GetTitle(), 
"p");
  1358   TCanvas* 
GetTimeCanvas(TPaveText* updateText, 
int time_ago, 
int XNow, 
int width=1200, 
int height=800){
  1359     TCanvas* can = 
new TCanvas(
"can_processing_time", 
"can_processing_time", width, height);
  1360     can->SetRightMargin(0.20);
  1361     TMultiGraph* gr = GetTimeMultiGraph();
  1362     can->cd()->SetLogy();
  1364     if(fIsEVD) gr->SetTitle(
"Nearline Event Display Processing Time");   
  1365     else gr->SetTitle(
"Nearline Processing Time");   
  1366     gr->GetXaxis()->SetTitle(
"Run Number");   
  1367     gr->GetYaxis()->SetTitle(
"Processing Time in Seconds");   
  1380     if(fIsEVD) sprintf(name, 
"ProcessingTimeEvd_%.3i_days.png", Ndays);
  1381     else sprintf(name, 
"ProcessingTime_%.3i_days.png", Ndays);
  1386     TCanvas *can = GetTimeCanvas(updateText, time_ago, XNow, width, height);
  1387     can->Print((plot_dir + 
"/" + GetPlotName(Ndays)).c_str());
  1396     if(fIsEVD) output+=
"<h3>Nearline Event Display Processing Time as a function of Run.</h3>\n";
  1397     else output+=
"<h3>Nearline Processing Time as a function of Run.</h3>\n";
  1398     output+=
"<figure>\n";
  1399     output+=
"<img src=\"" + relative_plot_dir + 
"/" + GetPlotName(Ndays) + 
"\" width=\"800\">\n";
  1400     output+=
"</figure>\n";
  1402     if(fIsEVD)       output+=
"<b>Nearline Event Display Processing Time</b> - Total time taken to run this Nearline Processing Job<BR>\n";
  1404       output+=
"<b>Nearline Processing Time</b> - Total time taken to run this Nearline Processing Job<BR>\n";
  1405       output+=
"<b>Nearline Ana Processing Time</b> - Time taken to run the NearlineAna part of the Job<BR>\n";
  1406       output+=
"<b>Nearline Muon Processing Time</b> - Time taken to run the Nearline Muon Counter part of the Job<BR>\n";
  1409     output+=
"<BR><BR><BR>\n";
 
void setPlotInfo(NearlinePlotInfo this_plot_info)
void PrintPedestalPlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
def line(rflist, normalization=13700 *units.eplus)
bool AddHistogram2D(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
std::vector< std::vector< float > > fBinByBinMetricVec
TCanvas * makeHistoCanvas(TPaveText *updateText, int width=1200, int height=800)
static std::string MakeHistogram2D(std::string plot_location, NearlinePlot *plot)
TGraph * GetNearlineMuonTimeGraph()
static std::string GetEVDDoneFileName(std::string file_name)
void setHistTitle(std::string hist_title)
std::string GetMetricMeanTimeGraphName(bool zoom=false)
void PrintVersionPlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static std::string MakePedestalPlotsHTML(std::string relative_plot_dir, int Ndays)
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
TCanvas * GetTimeCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
TMultiGraph * GetTimeMultiGraph()
static std::string MakeHistogramPair(std::string plot_location, NearlinePlot *plot)
TCanvas * makeGraphMetricTimeCanvas(TPaveText *updateText, int time_ago, int XNow, bool rms=false, bool zoom=false, int width=1200, int height=800, std::string taxis_labels="")
static std::string MakeHistogram(std::string plot_location, NearlinePlot *plot)
std::string GetNearlineVersionFromFileName(std::string fileName)
static TDatime GetDateTime(std::string date, int Ndays)
std::string GetMetricRmsTimeGraphName(bool zoom=false)
TCanvas * makeBinByBinGraphTime(unsigned int bin, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
bool AddHistogram1D(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
void setMetricDetails(std::string metric_details)
void AddMetricDetails(std::string metric_details)
NearlinePlotInfo(std::string metric_name, int channel, int num_days, std::string file_extension, std::string metric_details="")
void AddFile(std::string filename, int run, int Ndays)
void printBinByBinGraphs(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
NearlineProcessingTimePlot()
NearlinePlotLogScale(bool metric_time_graph_log=true, bool histo_1d_log=true, bool histo_2d_log=true, bool bin_by_bin_log=true)
TGraph * GetNearlineAnaTimeGraph()
static TDatime const InvalidDateTime
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end. 
void printHistogram1D(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
TCanvas * GetVersionCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static std::string MakeGraphPair(std::string plot_location, NearlinePlot *plot, bool rms)
std::string GetPlotName(int Ndays)
void printPlots(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
NearlineProcessingPedestal()
NearlineProcessingVersion()
static std::string GetPlotName(int Ndays)
void AddFile(std::string fileName, int run)
TCanvas * GetPedestalCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
std::string GetBinByBinTimeGraphName(unsigned int bin)
static int max(int a, int b)
static std::string GetDoneFileName(std::string file_name)
static std::string GetPedestalFileName(std::string done_file_name)
std::string fMetricDetails
NearlineProcessingTime(std::string file_name, int Ndays)
static std::string MakePlotSet(std::string plot_location, NearlinePlot *plot)
void printHistogram2D(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
auto norm(Vector const &v)
Return norm of the specified vector. 
static std::string MakeBinByBinGraphs(std::string plot_location, NearlinePlot *plot)
static std::string MakeVersionPlotsHTML(std::string relative_plot_dir, int Ndays)
static std::string GetPlotName(int Ndays)
std::vector< std::string > fBinByBinLabels
TDatime fEndNearlineMuonDate
void printGraphs(std::string plot_dir, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
NearlinePlotEnables(bool normalise_histo_1d=false, bool make_metric_time_graph=true, bool make_2d_histo=true, bool make_bin_by_bin_plots=false)
std::string GetHistOutputName()
void PrintTimePlots(std::string plot_dir, int Ndays, TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800)
static std::string MakeStartYearPlot(std::string relative_plot_path)
QTextStream & bin(QTextStream &s)
NearlinePlot(std::string this_hist_name, NearlinePlotInfo this_plot_info, NearlinePlotEnables this_plot_enable=NearlinePlotEnables(), NearlinePlotLogScale this_plot_log_scale=NearlinePlotLogScale())
bool AddHistogram(TFile const &file, TTree *header, int Xsrtime, int XNow, int GMToffset, int time_ago)
bool fMakeMetricTimeGraph
std::string MakeTimePlotsHTML(std::string relative_plot_dir, int Ndays)
std::string GetHist2DOutputName()
TGraph * GetTotalTimeGraph()
TCanvas * makeHisto2DCanvas(TPaveText *updateText, int time_ago, int XNow, int width=1200, int height=800, std::string taxis_labels="")
void histogramZoom(TH1 *hist, double n_sigma)
std::string to_string(ModuleType const mt)
static std::string MakePageHeader(int Ndays)
QTextStream & endl(QTextStream &s)
TDatime fEndNearlineAnaDate
void graphZoom(TGraph *gr, double n_sigma)
NearlinePlotEnables fPlotEnables
NearlinePlotInfo fPlotInfo
void AddFile(std::string fileName, int run)