OnMonPlotMaker.C
Go to the documentation of this file.
1 #include <fstream>
2 #include <TH1F.h>
3 #include <TH2F.h>
4 #include <TGraph.h>
5 #include <TTree.h>
6 #include <TCanvas.h>
7 #include <TFile.h>
8 #include <TPaveText.h>
9 #include <TStyle.h>
10 #include <TSystem.h>
11 #include <TDatime.h>
12 #include <TLegend.h>
13 #include <TLegendEntry.h>
14 // Can't remember if I still need these includes...
15 #include <iostream>
16 #include <iomanip>
17 #include <sstream>
18 #include <string>
19 #include <cstring>
20 
21 // This lets me draw the fancy OnMon-style plot labels.
23 
25 
26 void OnMonPlotMaker(TString det_type, TString t_prd, TString trigger) {
27 
28  const std::string DATA_DIR = "/nusoft/app/web/htdoc/nova/datacheck/nearline/data";
29  const std::string PLOT_DIR = "/nusoft/app/web/htdoc/nova/datacheck/nearline/plots";
30  //const std::string PLOT_DIR = "/nusoft/app/web/htdoc/nova/datacheck/nearline/test_plots";
31 
32  // TODO:
33  // * make the histograms smart enough to get their binnings from the onmon-histos file
34  // (or make them smart enough to figure out how big they should be...???) In fact,
35  // make nothing hardcoded about the histos (get all info from onmon-histos.csv)
36  //
37  // * make hitmap style plot of DCM duty cycle (using the empty DCM histo)
38  //
39  // * fix this so that if one of the text files is empty, it doesn't crash
40  //
41  // * document the heck out of this code...
42  //
43  // * should I normalize the NFEBperSR histos so that each bin is the average of each subrun that contributed?
44  //
45  // * I think that I am doing the GMT to CST conversion correctly, but I also think that I'm doing it in a convoluted way. Maybe I should make this better...
46  //
47  // * I don't think that I need to count all of the things for the TGraphs every time. Maybe I only need to count them during the month loop and then
48  // just zoom each plot appropriately?
49  //
50  // * normalize Nhits per spill plot to be percentage???
51  //
52  // * figure out a better way to do the arrays (other than to have fixed sizes...)
53  //
54  // * make the rasta plot have 1 hour bins (since subruns are now ~20 minutes)???
55  //
56  // * keep track of last run/subrun (for the text boxes) by partition
57 
58 
59 
60 
61  TDatime *TNowGMT = new TDatime; // current GMT time
62  TDatime *TNow = new TDatime; // current local time
63  TDatime *SRtime = new TDatime;
64  TDatime *SRtime_fine = new TDatime;
65 
66  int XNowGMT = TNowGMT->Convert(kTRUE);
67  int XNow = TNow ->Convert(kFALSE);
68 
69  int GMToffset = XNowGMT - XNow;
70  XNow = XNow - GMToffset;
71 
72  int XDayAgo = XNow - 60*60*24;
73  int XWeekAgo = XNow - 60*60*24*7;
74  int XMonthAgo = XNow - 60*60*24*30;
75  int XSixMonthsAgo = XNow - 60*60*24*26*7;
76  int XYearAgo = XNow - 60*60*24*52*7;
77 
78  int Xsrtime = 0;
79  int Xsrtime_fine = 0;
80  int time_ago = 0;
81 
82  string det;
83  string period;
84  string trig;
85  string trigname;
86 
87  if(det_type == "FarDet"){
88  det = "FarDet";
89  trig = "t02";
90  trigname = " ";
91 
92  if(t_prd == "Day"){
93  period = "Day";
94  time_ago = XDayAgo;
95  }
96  else if(t_prd == "Week"){
97  period = "Week";
98  time_ago = XWeekAgo;
99  }
100  else if(t_prd == "Month"){
101  period = "Month";
102  time_ago = XMonthAgo;
103  }
104  else if(t_prd == "6Months"){
105  period = "6Months";
106  time_ago = XSixMonthsAgo;
107  }
108  else if(t_prd == "Year"){
109  period = "Year";
110  time_ago = XYearAgo;
111  }
112  }
113 
114  if(det_type == "NearDet"){
115  det = "NearDet";
116 
117  if (trigger == "t00"){
118  trig = "t00";
119  trigname = "NuMI";
120  }
121  else if(trigger == "DDActivity1"){
122  trig = "DDActivity1";
123  trigname = "DDActivity";
124  }
125  else if(trigger == "t02"){
126  trig = "t02";
127  trigname = "Cosmic";
128  }
129  if(t_prd == "Day"){
130  period = "Day";
131  time_ago = XDayAgo;
132  }
133  else if(t_prd == "Week"){
134  period = "Week";
135  time_ago = XWeekAgo;
136  }
137  else if(t_prd == "Month"){
138  period = "Month";
139  time_ago = XMonthAgo;
140  }
141  else if(t_prd == "6Months"){
142  period = "6Months";
143  time_ago = XSixMonthsAgo;
144  }
145  else if(t_prd == "Year"){
146  period = "Year";
147  time_ago = XYearAgo;
148  }
149  }
150 
151  if(det_type == "TestBeam"){
152  det = "TestBeam";
153 
154  if (trigger == "Beamline"){
155  trig = "Beamline";
156  trigname = "Beamline";
157  }
158  else if(trigger == "DDActivity1"){
159  trig = "DDActivity1";
160  trigname = "DDActivity";
161  }
162  else if(trigger == "t02"){
163  trig = "t02";
164  trigname = "Cosmic";
165  }
166  else if(trigger == "Spill"){
167  trig = "Spill";
168  trigname = "Full Spill";
169  }
170  if(t_prd == "Day"){
171  period = "Day";
172  time_ago = XDayAgo;
173  }
174  else if(t_prd == "Week"){
175  period = "Week";
176  time_ago = XWeekAgo;
177  }
178  else if(t_prd == "Month"){
179  period = "Month";
180  time_ago = XMonthAgo;
181  }
182  else if(t_prd == "6Months"){
183  period = "6Months";
184  time_ago = XSixMonthsAgo;
185  }
186  else if(t_prd == "Year"){
187  period = "Year";
188  time_ago = XYearAgo;
189  }
190  }
191 
192  unsigned int year = 0;
193  unsigned short int month = 0;
194  unsigned short int day = 0;
195  double Hour = 0.0;
196  double Min = 0.0;
197  int hour = 0;
198  int min = 0;
199  int sec = 0;
200 
201  unsigned int run = 0;
202  unsigned int subrun = 0;
203  UInt_t par = 0;
204 
205  unsigned int LastRun = 0;
206  unsigned int LastSR = 0;
207 
208  unsigned int yearEnd = 0;
209  unsigned short int monthEnd = 0;
210  unsigned short int dayEnd = 0;
211  double HourEnd = 0.0;
212  double SRdur = 0;
213 
214  // Root is stupid and you have to make it think that it is in a different time zone so that it will draw any
215  // plots with time on the X-axis correctly.
216  gSystem->Setenv("TZ","UTC");
217  gStyle->SetTimeOffset(0);
218 
219 
220 
221  // Define the number of partitions in the data. Make this number one more
222  // than the actual number so that there can be a default unassigned value.
223  // Define the maximum number of points to go into a TGraph (assuming a max
224  // of one subrun every minute.)
225  const unsigned int Npar = 5;
226  double livetime = 0.0;
227 
228  // Define the number of errors in the AE plot and alerts in the AA plot.
229  const unsigned int Nerr = 10;
230  const unsigned int Nalert = 5;
231 
232  int t_n = 1;
233  if(t_prd == "Day") t_n = 1;
234  if(t_prd == "Week") t_n = 7;
235  if(t_prd == "Month") t_n = 30;
236  if(t_prd == "6Months") t_n = 7*26;
237  if(t_prd == "Year") t_n = 7*52;
238  const unsigned int Npoint = 1440 * t_n;
239 
240 
241 
242  //
243  // Make plots
244  //
245  // make titles for lists [in testing for automatic trigger naming of list files]
246  // char filelist_title[128];
247 
248  // Spill files only exist for ND/FD
249  char SpillInfoFile[128]="";
250  //char BNBSpillInfoFile[128]="";
251  if (det_type == "NearDet" || det_type == "FarDet"){
252 
253  if(t_prd == "Day")
254  sprintf(SpillInfoFile, "%s/POTSpillRateDay.root",DATA_DIR.c_str());
255  if(t_prd == "Week")
256  sprintf(SpillInfoFile, "%s/POTSpillRateWeek.root",DATA_DIR.c_str());
257  if(t_prd == "Month")
258  sprintf(SpillInfoFile, "%s/POTSpillRateMonth.root",DATA_DIR.c_str());
259  if(t_prd == "6Months")
260  sprintf(SpillInfoFile, "%s/POTSpillRate6Months.root",DATA_DIR.c_str());
261  if(t_prd == "Year")
262  sprintf(SpillInfoFile, "%s/POTSpillRateYear.root",DATA_DIR.c_str());
263 
264 
265  // if(t_prd == "Day")
266  //sprintf(BNBSpillInfoFile, "%s/BNBPOTSpillRateDay.root",DATA_DIR.c_str());
267  //if(t_prd == "Week")
268  //sprintf(BNBSpillInfoFile, "%s/BNBPOTSpillRateWeek.root",DATA_DIR.c_str());
269  //if(t_prd == "Month")
270  //sprintf(BNBSpillInfoFile, "%s/BNBPOTSpillRateMonth.root",DATA_DIR.c_str());
271  //if(t_prd == "6Months")
272  //sprintf(BNBSpillInfoFile, "%s/BNBPOTSpillRate6Months.root",DATA_DIR.c_str());
273  //if(t_prd == "Year")
274  //sprintf(BNBSpillInfoFile, "%s/BNBPOTSpillRateYear.root",DATA_DIR.c_str());
275  }
276 
277  std::ifstream inFile;
278  if(det_type == "FarDet"){
279  if(t_prd == "Day"){
280  // sprintf(filelist_title,"FDOnMonWeekFileList_t02-t00.txt");
281  inFile.open("FDOnMonDayFileList_t02-t00.txt");
282  }
283  else if(t_prd == "Week"){
284  //sprintf(filelist_title,"FDOnMonWeekFileList_%s.txt",trig.c_str());
285  inFile.open("FDOnMonWeekFileList_t02-t00.txt");
286  }
287  else if(t_prd == "Month"){
288  //sprintf(filelist_title,"FDOnMonMonthFileList_%s.txt",trig.c_str());
289  inFile.open("FDOnMonMonthFileList_t02-t00.txt");
290  }
291  else if(t_prd == "6Months"){
292  inFile.open("FDOnMon6MonthsFileList_t02-t00.txt");
293  }
294  else if(t_prd == "Year"){
295  inFile.open("FDOnMonYearFileList_t02-t00.txt");
296  }
297  }
298  if(det_type == "NearDet"){
299 
300  if(t_prd == "Day"){
301  // sprintf(filelist_title,"NDOnMonDayFileList_%s.txt",trig.c_str());
302  if(trig == "t00")
303  inFile.open("NDOnMonDayFileList_t00.txt");
304  if(trig == "t02")
305  inFile.open("NDOnMonDayFileList_t02.txt");
306  else if(trig == "DDActivity1")
307  inFile.open("NDOnMonDayFileList_DDActivity1.txt");
308  }
309  else if(t_prd == "Week"){
310  // sprintf(filelist_title,"NDOnMonWeekFileList_%s.txt",trig.c_str());
311  if(trig == "t00")
312  inFile.open("NDOnMonWeekFileList_t00.txt");
313  if(trig == "t02")
314  inFile.open("NDOnMonWeekFileList_t02.txt");
315  else if(trig == "DDActivity1")
316  inFile.open("NDOnMonWeekFileList_DDActivity1.txt");
317  }
318  else if(t_prd == "Month"){
319  // sprintf(filelist_title,"NDOnMonMonthFileList_%s.txt",trig.c_str());
320  if(trig == "t00")
321  inFile.open("NDOnMonMonthFileList_t00.txt");
322  if(trig == "t02")
323  inFile.open("NDOnMonMonthFileList_t02.txt");
324  else if(trig == "DDActivity1")
325  inFile.open("NDOnMonMonthFileList_DDActivity1.txt");
326  }
327  else if(t_prd == "6Months"){
328  if(trig== "t00")
329  inFile.open("NDOnMon6MonthsFileList_t00.txt");
330  if(trig == "t02")
331  inFile.open("NDOnMon6MonthsFileList_t02.txt");
332  else if(trig == "DDActivity1")
333  inFile.open("NDOnMon6MonthsFileList_DDActivity1.txt");
334  }
335  else if(t_prd == "Year"){
336  if(trig== "t00")
337  inFile.open("NDOnMonYearFileList_t00.txt");
338  if(trig== "t02")
339  inFile.open("NDOnMonYearFileList_t02.txt");
340  else if(trig == "DDActivity1")
341  inFile.open("NDOnMonYearFileList_DDActivity1.txt");
342  }
343  }
344 
345  if(det_type == "TestBeam"){
346 
347  if(t_prd == "Day"){
348  if(trig == "Beamline")
349  inFile.open("TBOnMonDayFileList_Beamline.txt");
350  else if(trig == "t02")
351  inFile.open("TBOnMonDayFileList_t02.txt");
352  else if(trig == "DDActivity1")
353  inFile.open("TBOnMonDayFileList_DDActivity1.txt");
354  else if(trig == "Spill")
355  inFile.open("TBOnMonDayFileList_Spill.txt");
356  }
357  else if(t_prd == "Week"){
358  if(trig == "Beamline")
359  inFile.open("TBOnMonWeekFileList_Beamline.txt");
360  else if(trig == "t02")
361  inFile.open("TBOnMonWeekFileList_t02.txt");
362  else if(trig == "DDActivity1")
363  inFile.open("TBOnMonWeekFileList_DDActivity1.txt");
364  else if(trig == "Spill")
365  inFile.open("TBOnMonWeekFileList_Spill.txt");
366  }
367  else if(t_prd == "Month"){
368  if(trig == "Beamline")
369  inFile.open("TBOnMonMonthFileList_Beamline.txt");
370  else if(trig == "t02")
371  inFile.open("TBOnMonMonthFileList_t02.txt");
372  else if(trig == "DDActivity1")
373  inFile.open("TBOnMonMonthFileList_DDActivity1.txt");
374  else if(trig == "Spill")
375  inFile.open("TBOnMonMonthFileList_Spill.txt");
376  }
377  else if(t_prd == "6Months"){
378  if(trig== "Beamline")
379  inFile.open("TBOnMon6MonthsFileList_Beamline.txt");
380  if(trig == "t02")
381  inFile.open("TBOnMon6MonthsFileList_t02.txt");
382  else if(trig == "DDActivity1")
383  inFile.open("TBOnMon6MonthsFileList_DDActivity1.txt");
384  else if(trig == "Spill")
385  inFile.open("TBOnMon6MonthsFileList_Spill.txt");
386  }
387  else if(t_prd == "Year"){
388  if(trig== "Beamline")
389  inFile.open("TBOnMonYearFileList_Beamline.txt");
390  else if(trig== "t02")
391  inFile.open("TBOnMonYearFileList_t02.txt");
392  else if(trig == "DDActivity1")
393  inFile.open("TBOnMonYearFileList_DDActivity1.txt");
394  else if(trig == "Spill")
395  inFile.open("TBOnMonYearFileList_Spill.txt");
396  }
397  }
398 
399  // fix trig string
400  if(trigger == "DDActivity1")
401  trig = "Act";
402 
403  // Make array of histo names and titles for the all errors plots.
404  // Histo titles taken from OnlineMonitoring/viewer/PlotOptions.cxx. If they ever change there (which they never will) they need to change here as well.
405  // 19 July 2018: They changed. We were mislabelling 5 errors/alerts. This has now been fixed in OnMon.
406  std::string errorHistoNames[Nerr];
407 
408  errorHistoNames[0] = "ErrorEventIncomplete";
409  errorHistoNames[1] = "ErrorDataMissing";
410  errorHistoNames[2] = "ErrorMilliSliceIncomplete"; // This is never actually filled in OnMon. Plot will always be blank.
411  errorHistoNames[3] = "ErrorDCMDataPresent";
412  errorHistoNames[4] = "ErrorComm";
413  errorHistoNames[5] = "ErrorADC";
414  errorHistoNames[6] = "ErrorTECC";
415  errorHistoNames[7] = "ErrorDataDrop";
416  errorHistoNames[8] = "ErrorLinkStatus";
417  errorHistoNames[9] = "ErrorFEBDataPresent";
418 
419  std::string errorHistoTitles[Nerr];
420 
421  errorHistoTitles[0] = "Event Incomplete Error";
422  errorHistoTitles[1] = "Data Missing Error";
423  errorHistoTitles[2] = "Millislice Incomplete Error";
424  errorHistoTitles[3] = "DCM Data Present Error";
425  errorHistoTitles[4] = "Comm. Error";
426  errorHistoTitles[5] = "ADC Error";
427  errorHistoTitles[6] = "TECC Error";
428  errorHistoTitles[7] = "Data Drop Error";
429  errorHistoTitles[8] = "Link Status Error";
430  errorHistoTitles[9] = "FEB Data Present Error";
431 
432  // Make array of histo names and titles for all alert plots.
433  std::string alertHistoNames[Nalert];
434 
435  alertHistoNames[0] = "AlertSimulationsFlag";
436  alertHistoNames[1] = "AlertDAQEnabled";
437  alertHistoNames[2] = "AlertTECCEnable";
438  alertHistoNames[3] = "AlertFIFOFull";
439  alertHistoNames[4] = "AlertDebugMode";
440 
441  std::string alertHistoTitles[Nalert];
442 
443  alertHistoTitles[0] = "Simulations Flag";
444  alertHistoTitles[1] = "DAQ Enabled";
445  alertHistoTitles[2] = "TECC Enabled";
446  alertHistoTitles[3] = "Event FIFO Full";
447  alertHistoTitles[4] = "Debug Mode";
448 
449 
450  // book histos, arrays for TGraphs, etc.
451  TH1F *hErrorHistos[Npar][Nerr];
452  TH1F *hAlertHistos[Npar][Nalert];
453 
454  TH1F *hQDay[Npar];
455  TH2F *hFEBRateHitMapDay[Npar];
456  TH2F *hFEBDropOutMapDay[Npar];
457  TH2F *hFEBTimeHitMapDay[Npar];
458  TH2F *hFEBaveADCHitMapDay[Npar];
459  TH2F *hFEBhitsHitMapDay[Npar];
460 
461  TH1F *hFEBRateSpectrumDay[Npar];
462  TH2F *hFEBRateSpectrumVsTimeDay[Npar];
463 
464  TH1F *hTPlotALLDay[Npar];
465  TH2F *hTPlotALLVsTimeDay[Npar];
466 
467  TH1F *hTPlotZOOMDay[Npar];
468  TH2F *hTPlotZOOMVsTimeDay[Npar];
469 
470  TH1F *hNormalizationVsTimeDay[Npar];
471  TH1F *hTimingNormVsTimeDay[Npar];
472 
473  int *NDCMtimeDay[Npar];
474  int *NDCMDay[Npar];
475  int NDCMDayCount[Npar];
476  int *NFEBtimeDay[Npar];
477  int *NFEBDay[Npar];
478  int NFEBDayCount[Npar];
479  int *NFEBtimeDDay[Npar];
480  int *NFEBDDay[Npar];
481  int NFEBDDayCount[Npar];
482  int *NPIXperSRtimeDay[Npar];
483  int *NPIXperSRDay[Npar];
484  int NPIXperSRDayCount[Npar];
485  int *NPIXperEVTtimeDay[Npar];
486  int *NPIXperEVTDay[Npar];
487  int NPIXperEVTDayCount[Npar];
488 
489  double *Trig00timeDay[Npar];
490  double *Trig00Day[Npar];
491  double *Trig01timeDay[Npar];
492  double *Trig01Day[Npar];
493  double *Trig02timeDay[Npar];
494  double *Trig02Day[Npar];
495  double *TrigActtimeDay[Npar];
496  double *TrigActDay[Npar];
497  int NTrigDayCount[Npar];
498 
499  int NSpillEntryCount[Npar];
500  double *SpillCountValue[Npar];
501  double *SpillCountTime[Npar];
502 
503  // int BNBNSpillEntryCount[Npar];
504  //double *BNBSpillCountValue[Npar];
505  //double *BNBSpillCountTime[Npar];
506 
507  double *dcm0timeDay[Npar];
508  double *Ndcm0Day[Npar];
509  int Ndcm0DayCount[Npar];
510 
511 
512 
513  // assigning for every partition an array of dimension Npoint.
514  for(unsigned int i = 0; i < Npar; i++){
515  NDCMtimeDay[i] = new int[Npoint];
516  NDCMDay[i] = new int[Npoint];
517  NFEBtimeDay[i] = new int[Npoint];
518  NFEBtimeDDay[i] = new int[Npoint];
519  NFEBDay[i] = new int[Npoint];
520  NFEBDDay[i] = new int[Npoint];
521  NPIXperSRtimeDay[i] = new int[Npoint];
522  NPIXperSRDay[i] = new int[Npoint];
523  NPIXperEVTtimeDay[i] = new int[Npoint];
524  NPIXperEVTDay[i] = new int[Npoint];
525 
526  Trig00timeDay[i] = new double[Npoint];
527  Trig00Day[i] = new double[Npoint];
528  Trig01timeDay[i] = new double[Npoint];
529  Trig01Day[i] = new double[Npoint];
530  Trig02timeDay[i] = new double[Npoint];
531  Trig02Day[i] = new double[Npoint];
532  TrigActtimeDay[i] = new double[Npoint];
533  TrigActDay[i] = new double[Npoint];
534 
535  SpillCountValue[i] = new double[Npoint];
536  SpillCountTime[i] = new double[Npoint];
537 
538  //BNBSpillCountValue[i] = new double[Npoint];
539  //BNBSpillCountTime[i] = new double[Npoint];
540 
541  dcm0timeDay[i] = new double[Npoint];
542  Ndcm0Day[i] = new double[Npoint];
543  }
544 
545  string time;
546  if(period == "Day") time = "past 24 hrs.";
547  if(period == "Week") time = "past 7 days";
548  if(period == "Month") time = "past 30 days";
549  if(period == "6Months") time = "past 26 week";
550  if(period == "Year") time = "past 52 weeks";
551 
552  int FEBxbin_n = 0;
553  int FEBxbin_min = 0;
554  int FEBxbin_max = 0;
555 
556  int FEBybin_n = 0;
557  int FEBybin_min = 0;
558  int FEBybin_max = 0;
559 
560  int Timebin_n = 72;
561  // Since NearDet (and TestBeam) subruns are longer than 20 minutes, we will use fewer than 72 bins
562  // for the 24 hour NearDet (and TestBeam) plots to avoid creating vertical white stripes.
563  if( (det_type == "NearDet" || det_type == "TestBeam") && period == "Day") Timebin_n = 18;
564 
565  if(det_type == "FarDet"){
566  FEBxbin_n = 224;
567  FEBxbin_min = 0;
568  FEBxbin_max = 896;
569  FEBybin_n = 48;
570  FEBybin_min = 0;
571  FEBybin_max = 384;
572  }
573  if(det_type == "NearDet"){
574  FEBxbin_n = 64;
575  FEBxbin_min = 0;
576  FEBxbin_max = 256;
577  FEBybin_n = 16;
578  FEBybin_min = 0;
579  FEBybin_max = 128;
580  }
581  if(det_type == "TestBeam"){
582  FEBxbin_n = 16;
583  FEBxbin_min = 0;
584  FEBxbin_max = 64;
585  FEBybin_n = 12;
586  FEBybin_min = 0;
587  FEBybin_max = 96;
588  }
589 
590  // initalize histos
591  for(unsigned int p = 0; p < Npar; ++p) {
592  char histoname[56];
593  char histotitle[128];
594 
595  for(unsigned int e = 0; e < Nerr; ++e) {
596  sprintf(histoname,"h%sP%.1u",errorHistoNames[e].c_str(),p);
597  sprintf(histotitle,"%s %s (%s) - partition %.1u;(central time);",trigname.c_str(),errorHistoTitles[e].c_str(),time.c_str(),p);
598  hErrorHistos[p][e] = new TH1F(histoname,histotitle,1440,time_ago,XNow);
599  // NOTE: Using 1440 bins since that will line up with the original AE histo X-axis bin size. This allows for easier comparisons to the original histogram.
600  }
601 
602  for(unsigned int a = 0; a < Nalert; ++a) {
603  sprintf(histoname,"h%sP%.1u",alertHistoNames[a].c_str(),p);
604  sprintf(histotitle,"%s %s (%s) - partition %.1u;(central time);",trigname.c_str(),alertHistoTitles[a].c_str(),time.c_str(),p);
605  hAlertHistos[p][a] = new TH1F(histoname,histotitle,1440,time_ago,XNow);
606  // NOTE: Using 1440 bins since that will line up with the original AA histo X-axis bin size. This allows for easier comparisons to the original histogram.
607  }
608 
609  sprintf(histoname,"hQDayP%.1u",p);
610  sprintf(histotitle,"%s ADC Spectra (%s) - partition %.1u;ADC;",trigname.c_str(),time.c_str(),p);
611  hQDay[p] = new TH1F(histoname,histotitle,4100,0,4100);
612 
613  sprintf(histoname,"hFEBRateHitMapDayP%.1u",p);
614  sprintf(histotitle,"%s FEB Hit Rates (%s) - partition %.1u",trigname.c_str(),time.c_str(),p);
615  hFEBRateHitMapDay[p] = new TH2F(histoname,histotitle,FEBxbin_n,FEBxbin_min,FEBxbin_max,FEBybin_n,FEBybin_min,FEBybin_max);
616 
617  sprintf(histoname, "hFEBDropOutMapDayP%.1u", p);
618  sprintf(histotitle,"%s FEB Number of Drop Outs (%s) - partition %.1u",trigname.c_str(),time.c_str(),p);
619  hFEBDropOutMapDay[p] = new TH2F(histoname,histotitle,FEBxbin_n,FEBxbin_min,FEBxbin_max,FEBybin_n,FEBybin_min,FEBybin_max);
620 
621  sprintf(histoname,"hFEBTimeHitMapDayP%.1u",p);
622  sprintf(histotitle,"%s FEB Live Time (%s) - partition %.1u",trigname.c_str(),time.c_str(),p);
623  hFEBTimeHitMapDay[p] = new TH2F(histoname,histotitle,FEBxbin_n,FEBxbin_min,FEBxbin_max,FEBybin_n,FEBybin_min,FEBybin_max);
624 
625  sprintf(histoname,"hFEBaveADCHitMapDayP%.1u",p);
626  sprintf(histotitle,"%s Average ADC per FEB (%s) - partition %.1u",trigname.c_str(),time.c_str(),p);
627  hFEBaveADCHitMapDay[p] = new TH2F(histoname,histotitle,FEBxbin_n,FEBxbin_min,FEBxbin_max,FEBybin_n,FEBybin_min,FEBybin_max);
628 
629  sprintf(histoname,"hFEBhitsHitMapDayP%.1u",p);
630  sprintf(histotitle,"%s FEB Number of Hits (%s) - partition %.1u",trigname.c_str(),time.c_str(),p);
631  hFEBhitsHitMapDay[p] = new TH2F(histoname,histotitle,FEBxbin_n,FEBxbin_min,FEBxbin_max,FEBybin_n,FEBybin_min,FEBybin_max);
632 
633  sprintf(histoname,"hFEBRateSpectrumDayP%.1u",p);
634  sprintf(histotitle,"%s FEB Hit Rate Spectrum (%s) - partition %.1u;Log_{10}(rate);",trigname.c_str(),time.c_str(),p);
635  hFEBRateSpectrumDay[p] = new TH1F(histoname,histotitle,200,1,6);
636 
637  sprintf(histoname,"hFEBRateSpectrumVsTimeDayP%.1u",p);
638  sprintf(histotitle,"%s FEB Hit Rate Spectra vs. Time - partition %.1u;(central time);Log_{10}(rate)",trigname.c_str(),p);
639  hFEBRateSpectrumVsTimeDay[p] = new TH2F(histoname,histotitle,Timebin_n,time_ago,XNow,200,1,6);
640 
641  sprintf(histoname,"hTPlotALLDayP%.1u",p);
642  sprintf(histotitle,"%s Time Distribution for All Hits (%s) - partition %.1u;Hit Time [#musec];",trigname.c_str(),time.c_str(),p);
643  hTPlotALLDay[p] = new TH1F(histoname,histotitle,350,-100,600);
644  sprintf(histoname,"hTPlotALLVsTimeDayP%.1u",p);
645  sprintf(histotitle,"%s Time Distribution for All Hits vs. Time - partition %.1u;(central time);Hit Time [#musec]",trigname.c_str(),p);
646  hTPlotALLVsTimeDay[p] = new TH2F(histoname,histotitle,Timebin_n,time_ago,XNow,350,-100,600);
647  sprintf(histoname,"hTPlotZOOMDayP%.1u",p);
648  sprintf(histotitle,"%s Time Distribution for All Hits (%s) - partition %.1u;Hit Time [#musec];",trigname.c_str(),time.c_str(),p);
649  hTPlotZOOMDay[p] = new TH1F(histoname,histotitle,200,212,237);
650  sprintf(histoname,"hTPlotZOOMVsTimeDayP%.1u",p);
651  sprintf(histotitle,"%s Time Distribution for All Hits vs. Time - partition %.1u;(central time);Hit Time [#musec]",trigname.c_str(),p);
652  hTPlotZOOMVsTimeDay[p] = new TH2F(histoname,histotitle,Timebin_n,time_ago,XNow,200,212,237);
653  sprintf(histoname,"hNormalizationVsTimeDayP%.1u",p);
654  sprintf(histotitle,"%s Day Normalization - partition %.1u",trigname.c_str(),p);
655  hNormalizationVsTimeDay[p] = new TH1F(histoname,histotitle,Timebin_n,time_ago,XNow);
656  sprintf(histoname,"hTimingNormVsTimeDayP%.1u",p);
657  sprintf(histotitle,"%s Day Timing Normalization - partition %.1u",trigname.c_str(),p);
658  hTimingNormVsTimeDay[p] = new TH1F(histoname,histotitle,Timebin_n,time_ago,XNow);
659  NDCMDayCount[p] = 0;
660  NFEBDayCount[p] = 0;
661  NFEBDDayCount[p] = 0;
662  NPIXperSRDayCount[p] = 0;
663  NPIXperEVTDayCount[p] = 0;
664  NTrigDayCount[p] = 0;
665  NSpillEntryCount[0] = 0;
666  //BNBNSpillEntryCount[0]= 0;
667  Ndcm0DayCount[p] = 0;
668  }
669 
670  int NSpills = 0;
671  //int BNBNSpills = 0;
672  // Only get Beam files for FD/ND.
673  if(det_type == "FarDet" || det_type == "NearDet"){
674  //Get Spill Summary
675  std::cout << "\n\nChecking for Beam Summary File...\n\n";
676  // TFile* fileBeam = TFile::Open("/home/novanearline/Nearline-test-releases/S15-02-05/Commissioning/Nearline/POTBeamDay.root");
677  TFile* fileBeam = TFile::Open(SpillInfoFile);
678  TTree* BeamTree = dynamic_cast<TTree*>(fileBeam->Get("BeamMetrics"));
679  double timestamp;
680  double spills;
681  BeamTree->SetBranchAddress("Time", &timestamp);
682  BeamTree->SetBranchAddress("SpillRate", &spills);
683 
684  int n_entries = BeamTree->GetEntries();
685 
686  std::cout<<n_entries<<std::endl;
687  //loop over all entries
688  NSpillEntryCount[0] =0;
689  for (int entryid = 0; entryid < n_entries; entryid++){
690  BeamTree->GetEntry(entryid);
691  std::cout<<entryid<<" t="<<timestamp<<" S= "<<spills<<std::endl;
692 
693  timestamp = timestamp -GMToffset;
694  if ( timestamp > time_ago && timestamp < XNow ){
695  SpillCountTime[0][entryid]=timestamp;
696  SpillCountValue[0][entryid]=spills;
697  NSpillEntryCount[0] ++;
698  NSpills++;
699  }
700  }
701 
702  //TFile* BNBfileBeam = TFile::Open(BNBSpillInfoFile);
703  //TTree* BNBBeamTree = dynamic_cast<TTree*>(BNBfileBeam->Get("BeamMetrics"));
704  //double BNBtimestamp;
705  //double BNBspills;
706  //BNBBeamTree->SetBranchAddress("Time", &BNBtimestamp);
707  //BNBBeamTree->SetBranchAddress("SpillRate", &BNBspills);
708 
709  //int BNB_n_entries = BNBBeamTree->GetEntries();
710 
711  //std::cout<<BNB_n_entries<<std::endl;
712  //loop over all entries
713  //BNBNSpillEntryCount[0] =0;
714  //for (int entryid = 0; entryid < BNB_n_entries; entryid++){
715  //BNBBeamTree->GetEntry(entryid);
716  //std::cout<<entryid<<" t="<<BNBtimestamp<<" S= "<<BNBspills<<std::endl;
717 
718  //BNBtimestamp = BNBtimestamp - GMToffset;
719  //if ( BNBtimestamp > time_ago && BNBtimestamp < XNow ){
720  // BNBSpillCountTime[0][entryid]=BNBtimestamp;
721  // BNBSpillCountValue[0][entryid]=BNBspills;
722  // BNBNSpillEntryCount[0] ++;
723  // BNBNSpills++;
724  // }
725  //}
726 
727  } // end Beam Summary Files
728 
729 
730  unsigned int nFilesProcessed = 0;
731 
732  std::cout << "\n\nChecking for file...\n\n";
733  while(inFile.good()) {
734  if ((++nFilesProcessed % 100) == 0) std::cout << "\nProcessed " << nFilesProcessed << " files.";
735 
736  char filenameD[256];
737  inFile >> filenameD;
738  TFile fileD(filenameD);
739 
740  // Get subrun info out of the header.
741  TTree *header = (TTree*)fileD.Get("Header");
742  if(header != 0) {
743  header->SetBranchAddress("StartYear", &year);
744  header->SetBranchAddress("StartMonth", &month);
745  header->SetBranchAddress("StartDay", &day);
746  header->SetBranchAddress("StartHour", &Hour);
747  header->SetBranchAddress("EndYear", &yearEnd);
748  header->SetBranchAddress("EndMonth", &monthEnd);
749  header->SetBranchAddress("EndDay", &dayEnd);
750  header->SetBranchAddress("EndHour", &HourEnd);
751  header->SetBranchAddress("Run", &run);
752  header->SetBranchAddress("Subrun", &subrun);
753  header->SetBranchAddress("Partition", &par);
754  header->GetEntry(0);
755 
756  hour = Hour;
757  Min = (Hour-hour)*60.0;
758  min = (Hour-hour)*60.0;
759  sec = (Min-min)*60.0;
760 
761  // OnMon/DAQ keeps track of GMT time, so convert to local time
762  SRtime->Set(year,month,day,hour,min,sec);
763  Xsrtime = SRtime->Convert() - GMToffset;
764 
765  hour = HourEnd;
766  Min = (HourEnd-hour)*60.0;
767  min = (HourEnd-hour)*60.0;
768  sec = (Min-min)*60.0;
769 
770  // Get the end time and compute subrun duration.
771  SRtime->Set(yearEnd,monthEnd,dayEnd,hour,min,sec);
772  if(dayEnd == day)
773  SRdur = 3600.0*(HourEnd-Hour);
774  else
775  SRdur = 3600.0*(HourEnd+24.0-Hour);
776 
777  if(Xsrtime < time_ago) continue;
778 
779  if(run >= LastRun) {
780  if(run > LastRun) {
781  LastRun = run;
782  LastSR = subrun;
783  }
784  else if(subrun > LastSR) {
785  LastRun = run;
786  LastSR = subrun;
787  }
788  }
789 
790  }
791 
792 
793  // Protection against subruns with only one event in them (yes, this did happen once...)
794  if(SRdur == 0.0) continue;
795 
796  std::cout << "\nLOOP: adding run " << run << ", subrun " << subrun;
797 
798  // Get the all error plot
799  TH2F *hAEtemp = (TH2F*)fileD.FindObjectAny("AEVsHour");
800 
801  // loop over the errors and fill the error vs. time plots:
802  if(hAEtemp != 0 && header != 0) {
803  // loop over errors (Y-axis)
804  for(unsigned int e = 0; e < Nerr; ++e) {
805  // loop over time bins (X-axis)
806  for(unsigned int xb = 61; xb < 1500; ++xb) {
807  // Histo bins start at 1 AND in this histo, I put a spacer bin between each of the error bins (to make it look better.)
808  // Therefore, the bins I am interested are actually enumerated by 2*e+1
809  double content = hAEtemp->GetBinContent(hAEtemp->GetBin(xb,2*e+1));
810 
811  double eventTime = hAEtemp->GetXaxis()->GetBinCenter(xb);
812 
813  int hour_fine = (int)eventTime;
814  int min_fine = (int) ((eventTime - (double)hour_fine)*60.0);
815  int sec_fine = (int) ((eventTime - (double)hour_fine - (double)min_fine/60.0)*3600.0);
816 
817  SRtime_fine->Set(year,month,day,hour_fine,min_fine,sec_fine);
818  Xsrtime_fine = SRtime_fine->Convert() - GMToffset;
819 
820  hErrorHistos[par][e]->Fill(Xsrtime_fine,content);
821  } // end loop over Xbins
822  } // end loop over number of errors
823  } // end check if histo and header are okay
824 
825  // Get the all alerts plot
826  TH2F *hAAtemp = (TH2F*)fileD.FindObjectAny("AAVsHour");
827 
828  // loop over the alerts and fill the alert vs. time plots:
829  if(hAAtemp != 0 && header != 0) {
830  // loop over alerts (Y-axis)
831  for(unsigned int a = 0; a < Nalert; ++a) {
832  // loop over time bins (X-axis)
833  for(unsigned int xb = 61; xb < 1500; ++xb) {
834  // Histo bins start at 1 AND in this histo, I put a spacer bin between each of the alert bins (to make it look better.)
835  // Therefore, the bins I am interested are actually enumerated by 2*a+1
836  double content = hAAtemp->GetBinContent(hAAtemp->GetBin(xb,2*a+1));
837 
838  double eventTime = hAAtemp->GetXaxis()->GetBinCenter(xb);
839 
840  int hour_fine = (int)eventTime;
841  int min_fine = (int) ((eventTime - (double)hour_fine)*60.0);
842  int sec_fine = (int) ((eventTime - (double)hour_fine - (double)min_fine/60.0)*3600.0);
843 
844  SRtime_fine->Set(year,month,day,hour_fine,min_fine,sec_fine);
845  Xsrtime_fine = SRtime_fine->Convert() - GMToffset;
846 
847  hAlertHistos[par][a]->Fill(Xsrtime_fine,content);
848  } // end loop over Xbins
849  } // end loop over number of alerts
850  } // end check if histo and header are okay
851 
852  TH1F *hQtemp = (TH1F*)fileD.FindObjectAny("QPlotALL");
853  if(hQtemp != 0)
854  hQDay[par]->Add(hQtemp,1.0);
855 
856  livetime = 0.0;
857  TH2F *hFEBRateTemp = (TH2F*)fileD.FindObjectAny("FEBHitMap");
858  TH1F *hTime = (TH1F*)fileD.FindObjectAny("RecordedTime");
859  if(hFEBRateTemp != 0 && hTime != 0) {
860  livetime = (hTime->Integral())*(5.0E-7); // recorded time is in units of 500 ns
861  hFEBRateHitMapDay[par]->Add(hFEBRateTemp,1.0);
862  for(int i = 1; i <= hFEBRateTemp->GetNbinsX(); ++i) {
863  for(int j = 1; j <= hFEBRateTemp->GetNbinsY(); ++j) {
864  double bin1 = hFEBRateTemp->GetBinContent(hFEBRateTemp->GetBin(i,j));
865  double bin2 = hFEBTimeHitMapDay[par]->GetBinContent(hFEBTimeHitMapDay[par]->GetBin(i,j));
866  if(bin1 > 0.0) hFEBTimeHitMapDay[par]->SetBinContent(hFEBTimeHitMapDay[par]->GetBin(i,j),bin2+livetime);
867  }
868  }
869  }
870 
871  TH2F *hFEBDropOut = (TH2F*)fileD.FindObjectAny("FEBShutOff");
872  if(hFEBDropOut != 0 && header !=0){
873  hFEBDropOutMapDay[par]->Add(hFEBDropOut,1.0);
874  }
875 
876  TH2F *hFEBtotADCTemp = (TH2F*)fileD.FindObjectAny("TotADCFEBHitMap");
877  if(hFEBtotADCTemp != 0 && hFEBRateTemp != 0) {
878  hFEBaveADCHitMapDay[par]->Add(hFEBtotADCTemp,1.0);
879  hFEBhitsHitMapDay[par]->Add(hFEBRateTemp,1.0);
880  }
881 
882  TH2F *hDCMHit = (TH2F*)fileD.FindObjectAny("DCMHitMap");
883  if(hDCMHit != 0 && header !=0) {
884  int DCMhitcount = 0;
885  for(int i = 1; i <= hDCMHit->GetNbinsX(); i++){
886  for(int j = 1; j <= hDCMHit->GetNbinsY(); j++){
887  if(hDCMHit->GetBinContent(hDCMHit->GetBin(i,j)) > 0)
888  DCMhitcount++;
889  }
890  }
891  NDCMtimeDay[par][NDCMDayCount[par]] = Xsrtime;
892  NDCMDay [par][NDCMDayCount[par]] = DCMhitcount;
893  NDCMDayCount[par]++;
894  }
895 
896  TH2F *hFEBHit = (TH2F*)fileD.FindObjectAny("FEBHitMap");
897  TH2F *hFEBRate = (TH2F*)fileD.FindObjectAny("FEBHitRateMap");
898  TH2F *hFEBRateSpec = (TH2F*)fileD.FindObjectAny("FEBHitRateSpectrum");
899  if(hFEBRate != 0 && header != 0) {
900  hNormalizationVsTimeDay[par]->Fill(Xsrtime);
901  hTimingNormVsTimeDay[par]->Fill(Xsrtime, SRdur);
902  int FEBcount = 0;
903  for(int i = 1; i <= hFEBRate->GetNbinsX(); ++i) {
904  for(int j = 1; j <= hFEBRate->GetNbinsY(); ++j) {
905  double rate = hFEBRate->GetBinContent(hFEBRate->GetBin(i,j));
906  if(rate > 0.0) {
907  rate = log10(rate);
908  FEBcount++;
909  }
910  else
911  rate = -100.0;
912  hFEBRateSpectrumVsTimeDay[par]->Fill(Xsrtime,rate);
913  }
914  }
915  }
916  if(hFEBHit != 0 && header != 0){
917  int FEBhitcount = 0;
918  for(int i = 1; i <= hFEBHit->GetNbinsX(); i++){
919  for(int j = 1; j <= hFEBHit->GetNbinsY(); j++){
920  if(hFEBHit->GetBinContent(hFEBHit->GetBin(i,j)) > 0)
921  FEBhitcount++;
922  }
923  }
924  NFEBDay [par][NFEBDayCount[par]] = FEBhitcount;
925  NFEBDayCount[par]++;
926  NFEBtimeDay[par][NFEBDayCount[par]] = Xsrtime;
927  }
928  if(hFEBDropOut != 0 && header != 0){
929  int FEBdropoutcount = 0;
930  for(int i = 1; i <= hFEBDropOut->GetNbinsX(); i++){
931  for(int j = 1; j <= hFEBDropOut->GetNbinsY(); j++){
932  FEBdropoutcount += hFEBDropOut->GetBinContent(hFEBDropOut->GetBin(i,j));
933  }
934  }
935  NFEBDDay[par][NFEBDDayCount[par]] = FEBdropoutcount;
936  NFEBDDayCount[par]++;
937  NFEBtimeDDay[par][NFEBDDayCount[par]] = Xsrtime;
938  }
939  TH1F *hTPlotALLTemp = (TH1F*)fileD.FindObjectAny("TPlotALL");
940  if(hTPlotALLTemp != 0 && header != 0) {
941  hTPlotALLDay[par]->Add(hTPlotALLTemp);
942 
943  for(int i = 1; i <= hTPlotALLTemp->GetNbinsX(); ++i) {
944  double content = hTPlotALLTemp->GetBinContent(hTPlotALLTemp->GetBin(i));
945  hTPlotALLVsTimeDay[par]->Fill(Xsrtime,hTPlotALLTemp->GetBinCenter(i),content);
946  }
947  }
948 
949  TH1F *hTPlotZOOMTemp = (TH1F*)fileD.FindObjectAny("TPlotZOOM");
950  if(hTPlotZOOMTemp != 0 && header != 0) {
951  hTPlotZOOMDay[par]->Add(hTPlotZOOMTemp);
952 
953  for(int i = 1; i <= hTPlotZOOMTemp->GetNbinsX(); ++i) {
954  double content = hTPlotZOOMTemp->GetBinContent(hTPlotZOOMTemp->GetBin(i));
955  hTPlotZOOMVsTimeDay[par]->Fill(Xsrtime,hTPlotZOOMTemp->GetBinCenter(i),content);
956  }
957  }
958 
959  TH2F *hPixelRateSpec = (TH2F*)fileD.FindObjectAny("PixelHitRateSpectrum");
960  if(hPixelRateSpec != 0 && header !=0) {
961  NPIXperSRtimeDay[par][NPIXperSRDayCount[par]] = Xsrtime;
962  NPIXperSRDay [par][NPIXperSRDayCount[par]] = hPixelRateSpec->Integral();
963  NPIXperSRDayCount[par]++;
964  }
965 
966  TH2F *hNPIXvsTime = (TH2F*)fileD.FindObjectAny("NhitVsHour");
967  if(hNPIXvsTime != 0 && header != 0) {
968  NPIXperEVTtimeDay[par][NPIXperEVTDayCount[par]] = Xsrtime;
969  NPIXperEVTDay [par][NPIXperEVTDayCount[par]] = hNPIXvsTime->GetMean(2);
970  NPIXperEVTDayCount[par]++;
971  }
972 
973  TH2F *hTrig = (TH2F*)fileD.FindObjectAny("TriggerVsHourGeneral");
974  if(hTrig != 0 && header != 0) {
975  double Trig00 = hTrig->Integral(61,1500,1,1);
976  double Trig01 = hTrig->Integral(61,1500,2,2); //BNB @ ND, Beamline @ TB
977  double Trig02 = hTrig->Integral(61,1500,3,3);
978  double TrigAct= hTrig->Integral(61,1500,22,22); //DDActivity
979  Trig00timeDay[par][NTrigDayCount[par]] = Xsrtime;
980  Trig01timeDay[par][NTrigDayCount[par]] = Xsrtime;
981  Trig02timeDay[par][NTrigDayCount[par]] = Xsrtime;
982  TrigActtimeDay[par][NTrigDayCount[par]]= Xsrtime;
983  Trig00Day[par][NTrigDayCount[par]] = Trig00/SRdur;
984  Trig01Day[par][NTrigDayCount[par]] = Trig01/SRdur;
985  Trig02Day[par][NTrigDayCount[par]] = Trig02/SRdur;
986  TrigActDay[par][NTrigDayCount[par]] = TrigAct/SRdur;
987  NTrigDayCount[par]++;
988  }
989 
990  TH2F *hNdcm = (TH2F*)fileD.FindObjectAny("NdcmsVsHour");
991  double Zerodcm = 0.0;
992  if(hNdcm != 0 && header != 0) {
993  int NbinsY = hNdcm->GetNbinsY();
994  double total = hNdcm->Integral(61,1500,1,NbinsY);
995  if(total > 0.0)
996  Zerodcm = ((double)(hNdcm->Integral(61,1500,1,1)))/(total)*100.0;
997  dcm0timeDay[par][Ndcm0DayCount[par]] = Xsrtime;
998  Ndcm0Day[par][Ndcm0DayCount[par]] = Zerodcm;
999  Ndcm0DayCount[par]++;
1000  }
1001 
1002  fileD.Close();
1003  }
1004 
1005  for(unsigned int p = 0; p < Npar; ++p) {
1006  hFEBaveADCHitMapDay[p]->Divide(hFEBhitsHitMapDay[p]);
1007  hFEBRateHitMapDay[p]->Divide(hFEBTimeHitMapDay[p]);
1008 
1009  for(int i = 1; i <= hFEBRateHitMapDay[p]->GetNbinsX(); ++i) {
1010  for(int j = 1; j <= hFEBRateHitMapDay[p]->GetNbinsY(); ++j) {
1011  double rate = hFEBRateHitMapDay[p]->GetBinContent(hFEBRateHitMapDay[p]->GetBin(i,j));
1012  if(rate > 0.0)
1013  rate = log10(rate);
1014  else
1015  rate = -100.0;
1016  hFEBRateSpectrumDay[p]->Fill(rate);
1017  }
1018  }
1019 
1020  // DIVIDE BY NORM HISTO
1021  for(int i = 1; i <= hFEBRateSpectrumVsTimeDay[p]->GetNbinsX(); ++i) {
1022  double norm = hNormalizationVsTimeDay[p]->GetBinContent(hNormalizationVsTimeDay[p]->GetBin(i));
1023  for(int j = 1; j <= hFEBRateSpectrumVsTimeDay[p]->GetNbinsY(); ++j) {
1024  double content = 0.0;
1025  if(norm > 0.0) content = (hFEBRateSpectrumVsTimeDay[p]->GetBinContent(hFEBRateSpectrumVsTimeDay[p]->GetBin(i,j)))/norm;
1026  hFEBRateSpectrumVsTimeDay[p]->SetBinContent(hFEBRateSpectrumVsTimeDay[p]->GetBin(i,j),content);
1027  }
1028  }
1029 
1030  // Different norm histo for timing peak. Normalize by subrun length instead of # subruns
1031  // This way shorter subruns don't cause weird features in the plot
1032  for(int i = 1; i <= hTPlotALLVsTimeDay[p]->GetNbinsX(); ++i) {
1033  double norm = hTimingNormVsTimeDay[p]->GetBinContent(hTimingNormVsTimeDay[p]->GetBin(i));
1034  for(int j = 1; j <= hTPlotALLVsTimeDay[p]->GetNbinsY(); ++j) {
1035  double content = 0.0;
1036  if(norm > 0.0) content = (hTPlotALLVsTimeDay[p]->GetBinContent(hTPlotALLVsTimeDay[p]->GetBin(i,j)))/norm;
1037  hTPlotALLVsTimeDay[p]->SetBinContent(hTPlotALLVsTimeDay[p]->GetBin(i,j),content);
1038  }
1039  }
1040 
1041  for(int i = 1; i <= hTPlotZOOMVsTimeDay[p]->GetNbinsX(); ++i) {
1042  double norm = hTimingNormVsTimeDay[p]->GetBinContent(hTimingNormVsTimeDay[p]->GetBin(i));
1043  for(int j = 1; j <= hTPlotZOOMVsTimeDay[p]->GetNbinsY(); ++j) {
1044  double content = 0.0;
1045  if(norm > 0.0) content = (hTPlotZOOMVsTimeDay[p]->GetBinContent(hTPlotZOOMVsTimeDay[p]->GetBin(i,j)))/norm;
1046  hTPlotZOOMVsTimeDay[p]->SetBinContent(hTPlotZOOMVsTimeDay[p]->GetBin(i,j),content);
1047  }
1048  }
1049 
1050  }
1051 
1052 
1053 
1054 
1055 
1056  //
1057  // Make time/date stamp for each plot
1058  //
1059  TDatime *Ttemp = new TDatime; // finish time
1060  int Xfin = Ttemp->Convert() - GMToffset;
1061  TDatime *Tfinish = new TDatime(Xfin); // finish time
1062  TPaveText *UpdateText = new TPaveText(0.05, 0.0, 0.5, 0.06, "NDC");
1063  UpdateText->SetLineColor(0);
1064  UpdateText->SetFillColor(0);
1065  UpdateText->SetBorderSize(1);
1066  UpdateText->SetMargin(0.0);
1067  UpdateText->SetTextAlign(11);
1068  char buff1[256];
1069  sprintf(buff1, "Last updated on: %s (central time)", Tfinish->AsString());
1070  UpdateText->AddText(buff1);
1071  char buff2[256];
1072  sprintf(buff2, "Last run / subrun: %d / %d", LastRun, LastSR);
1073  UpdateText->AddText(buff2);
1074 
1075  TPaveText *StatusText = new TPaveText(0.1, 0.1, 0.9, 0.9, "NDC");
1076  StatusText->SetLineColor(1);
1077  StatusText->SetFillColor(0);
1078  StatusText->SetBorderSize(1);
1079  // StatusText->SetMargin(0.0);
1080  StatusText->AddText(buff1);
1081  StatusText->AddText(buff2);
1082 
1083 
1084  //
1085  // Draw pretty canvases...
1086  //
1087  int currentTime = 0;
1088  int threshold = 0;
1089  int timeVariable = 0;
1090  double current = 0.0, ave = 0.0, max = 0.0, max2 = 0.0, min1 = 99999, min2 = 99998;
1091  TPaveText *LastPoint = new TPaveText(0.3,0.88,0.93,0.93,"NDC");
1092  TPaveText *WarningText = new TPaveText(0,0,1,1,"NBNDC");
1093  //WarningText->SetHighLightColor(kRed);
1094  //WarningText->SetLineColor(kRed);
1095  WarningText->SetTextColor(kWhite);
1096  WarningText->SetFillColorAlpha(kRed,0);
1097  WarningText->SetTextSize(0.07);
1098  LastPoint->SetLineColor(1);
1099  LastPoint->SetFillColor(0);
1100  LastPoint->SetBorderSize(1);
1101  char lptext[128];
1102  char warntext[128];
1103  bool send_spill_email=false;
1104  bool send_feb_email=false;
1105  bool send_ddactrate_email=false;
1106  int nfeb=0;
1107  float ddactrate=0;
1108 
1109  // Make conditional standard time axis labels depending on period (Day, Week, Month)
1110  string taxis_labels;
1111  if(period == "Day"){
1112  taxis_labels = "%H:%M";
1113  }
1114  else{
1115  taxis_labels = "%m/%d";
1116  }
1117 
1118  // make the OnMon hardware label drawer
1119  om::HwDetLabel *hwdetlbl = new om::HwDetLabel();
1120 
1121  // loop over all partitions to make 24 hour plots
1122  for(unsigned int p = 0; p < Npar; ++p) {
1123  char filename[128];
1124  char title[128];
1125 
1126  for(unsigned int e = 0; e < Nerr; ++e) {
1127  TCanvas *cErr = new TCanvas("cErr","Errors",2000,800);
1128  cErr->cd();
1129 
1130  hErrorHistos[p][e]->SetLineWidth(2);
1131  hErrorHistos[p][e]->SetLineColor(kBlue);
1132  hErrorHistos[p][e]->Draw("hist");
1133  UpdateText->Draw();
1134  hErrorHistos[p][e]->GetXaxis()->SetTimeDisplay(1);
1135  hErrorHistos[p][e]->GetXaxis()->SetLabelSize(0.03);
1136  hErrorHistos[p][e]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1137  hErrorHistos[p][e]->SetStats(kFALSE);
1138 
1139  sprintf(filename,"%s/%s-%s-P%.1u%s%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,errorHistoNames[e].c_str(),period.c_str());
1140  cErr->Print(filename);
1141 
1142  delete cErr;
1143  cErr = 0;
1144  }
1145 
1146  for(unsigned int a = 0; a < Nalert; ++a) {
1147  TCanvas *cAlert = new TCanvas("cAlert","Alerts",2000,800);
1148  cAlert->cd();
1149 
1150  hAlertHistos[p][a]->SetLineWidth(2);
1151  hAlertHistos[p][a]->SetLineColor(kBlue);
1152  hAlertHistos[p][a]->Draw("hist");
1153  UpdateText->Draw();
1154  hAlertHistos[p][a]->GetXaxis()->SetTimeDisplay(1);
1155  hAlertHistos[p][a]->GetXaxis()->SetLabelSize(0.03);
1156  hAlertHistos[p][a]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1157  hAlertHistos[p][a]->SetStats(kFALSE);
1158 
1159  sprintf(filename,"%s/%s-%s-P%.1u%s%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,alertHistoNames[a].c_str(),period.c_str());
1160  cAlert->Print(filename);
1161 
1162  delete cAlert;
1163  cAlert = 0;
1164  }
1165 
1166 
1167  TCanvas *cQday = new TCanvas("cQday","Qplot Day",1200,800);
1168  cQday->cd();
1169  gPad->SetLogx();
1170  gPad->SetLogy();
1171  gStyle->SetOptStat(111111);
1172  hQDay[p]->SetAxisRange(5.0,5000.0,"X");
1173  hQDay[p]->SetLineWidth(2);
1174  hQDay[p]->SetLineColor(kRed);
1175  hQDay[p]->Draw();
1176  UpdateText->Draw();
1177  // Change this to normal directory but different plot name
1178  sprintf(filename,"%s/%s-%s-P%.1uQPlot%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1179  cQday->Print(filename);
1180  delete cQday;
1181  cQday = 0;
1182 
1183  TCanvas *cHMRday = new TCanvas("cHMRday","FEB HitMap Rates Day",1200,800);
1184  cHMRday->cd();
1185  cHMRday->SetLogz();
1186  gStyle->SetPalette(1); //kRainbow
1187  hFEBRateHitMapDay[p]->SetAxisRange(100.0,40000.0,"Z");
1188  hFEBRateHitMapDay[p]->GetXaxis()->SetTickLength(0);
1189  hFEBRateHitMapDay[p]->GetXaxis()->SetLabelColor(0);
1190  hFEBRateHitMapDay[p]->GetYaxis()->SetTickLength(0);
1191  hFEBRateHitMapDay[p]->GetYaxis()->SetLabelColor(0);
1192  hFEBRateHitMapDay[p]->SetStats(kFALSE);
1193  hwdetlbl->Config(hFEBRateHitMapDay[p]);
1194  hFEBRateHitMapDay[p]->Draw("colz");
1195  hwdetlbl->Draw();
1196  UpdateText->Draw();
1197  sprintf(filename,"%s/%s-%s-P%.1uFEBRateHitMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1198  cHMRday->Print(filename);
1199  delete cHMRday;
1200  cHMRday = 0;
1201 
1202  TCanvas *cHMdropday = new TCanvas("cHMdropday", "FEB Dropouts Day",1200,800);
1203  cHMdropday->cd();
1204  cHMdropday->SetLogz();
1205  hFEBDropOutMapDay[p]->SetAxisRange(1,100.0,"Z");
1206  hFEBDropOutMapDay[p]->GetXaxis()->SetTickLength(0);
1207  hFEBDropOutMapDay[p]->GetXaxis()->SetLabelColor(0);
1208  hFEBDropOutMapDay[p]->GetYaxis()->SetTickLength(0);
1209  hFEBDropOutMapDay[p]->GetYaxis()->SetLabelColor(0);
1210  hFEBDropOutMapDay[p]->SetStats(kFALSE);
1211  hwdetlbl->Config(hFEBDropOutMapDay[p]);
1212  hFEBDropOutMapDay[p]->Draw("colz");
1213  hwdetlbl->Draw();
1214  UpdateText->Draw();
1215  sprintf(filename,"%s/%s-%s-P%.1uFEBDropOutMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1216  cHMdropday->Print(filename);
1217  delete cHMdropday;
1218  cHMdropday = 0;
1219 
1220  TCanvas *cHMadcday = new TCanvas("cHMadcday","FEB ave ADC HitMap Day",1200,800);
1221  cHMadcday->cd();
1222  cHMadcday->SetLogz();
1223  hFEBaveADCHitMapDay[p]->SetAxisRange(0.5,1000,"Z");
1224  hFEBaveADCHitMapDay[p]->GetXaxis()->SetTickLength(0);
1225  hFEBaveADCHitMapDay[p]->GetXaxis()->SetLabelColor(0);
1226  hFEBaveADCHitMapDay[p]->GetYaxis()->SetTickLength(0);
1227  hFEBaveADCHitMapDay[p]->GetYaxis()->SetLabelColor(0);
1228  hFEBaveADCHitMapDay[p]->SetStats(kFALSE);
1229  hwdetlbl->Config(hFEBaveADCHitMapDay[p]);
1230  hFEBaveADCHitMapDay[p]->Draw("colz");
1231  hwdetlbl->Draw();
1232  UpdateText->Draw();
1233  sprintf(filename,"%s/%s-%s-P%.1uFEBaveADCHitMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1234  cHMadcday->Print(filename);
1235  delete cHMadcday;
1236  cHMadcday = 0;
1237 
1238  TCanvas *cFRday = new TCanvas("cFRday","FEB Rate Day",1200,800);
1239  cFRday->cd();
1240  gPad->SetLogy();
1241  gStyle->SetOptStat(111111);
1242  hFEBRateSpectrumDay[p]->SetLineWidth(2);
1243  hFEBRateSpectrumDay[p]->SetLineColor(kGreen+2);
1244  hFEBRateSpectrumDay[p]->Draw();
1245  UpdateText->Draw();
1246  sprintf(filename,"%s/%s-%s-P%.1uFEBRateSpectrum%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1247  cFRday->Print(filename);
1248  delete cFRday;
1249  cFRday = 0;
1250 
1251  TCanvas *cFEBRTday = new TCanvas("cFEBRTday","FEB Rate vs Time day",1200,800);
1252  cFEBRTday->cd();
1253  gPad->SetGridx();
1254  gPad->SetLogz();
1255  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1256  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1257  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1258  hFEBRateSpectrumVsTimeDay[p]->SetStats(kFALSE);
1259  hFEBRateSpectrumVsTimeDay[p]->Draw("colz");
1260  UpdateText->Draw();
1261  sprintf(filename,"%s/%s-%s-P%.1uFEBRateSpectrumVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1262  cFEBRTday->Print(filename);
1263  delete cFEBRTday;
1264  cFEBRTday = 0;
1265 
1266  TCanvas *cTPAday = new TCanvas("cTPAday","TPlotALL Day",1200,800);
1267  cTPAday->cd();
1268  gStyle->SetOptStat(111111);
1269  hTPlotALLDay[p]->SetLineWidth(2);
1270  hTPlotALLDay[p]->SetLineColor(kBlue);
1271  hTPlotALLDay[p]->Draw();
1272  hTPlotALLDay[p]->GetYaxis()->UnZoom();
1273  UpdateText->Draw();
1274  sprintf(filename,"%s/%s-%s-P%.1uTPlotALL%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1275  cTPAday->Print(filename);
1276  delete cTPAday;
1277  cTPAday = 0;
1278 
1279  TCanvas *cTPATday = new TCanvas("cTPATday","TPlotALL vs Time day",1200,800);
1280  cTPATday->cd();
1281  gPad->SetGridx();
1282  hTPlotALLVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1283  hTPlotALLVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1284  hTPlotALLVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1285  hTPlotALLVsTimeDay[p]->SetStats(kFALSE);
1286  hTPlotALLVsTimeDay[p]->Draw("colz");
1287  UpdateText->Draw();
1288  sprintf(filename,"%s/%s-%s-P%.1uTPlotALLVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1289  cTPATday->Print(filename);
1290  delete cTPATday;
1291  cTPATday = 0;
1292 
1293  TCanvas *cTPZday = new TCanvas("cTPZday","TPlotZOOM Day",1200,800);
1294  cTPZday->cd();
1295  gStyle->SetOptStat(111111);
1296  hTPlotZOOMDay[p]->SetLineWidth(2);
1297  hTPlotZOOMDay[p]->SetLineColor(kBlue);
1298  hTPlotZOOMDay[p]->Draw();
1299  hTPlotZOOMDay[p]->GetYaxis()->UnZoom();
1300  UpdateText->Draw();
1301  sprintf(filename,"%s/%s-%s-P%.1uTPloZOOM%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1302  cTPZday->Print(filename);
1303  delete cTPZday;
1304  cTPZday = 0;
1305 
1306  TCanvas *cTPZTday = new TCanvas("cTPZTday","TPlotZOOM vs Time day",1200,800);
1307  cTPZTday->cd();
1308  gPad->SetGridx();
1309  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1310  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1311  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1312  hTPlotZOOMVsTimeDay[p]->SetStats(kFALSE);
1313  hTPlotZOOMVsTimeDay[p]->Draw("colz");
1314  UpdateText->Draw();
1315  sprintf(filename,"%s/%s-%s-P%.1uTPlotZOOMVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1316  cTPZTday->Print(filename);
1317  delete cTPZTday;
1318  cTPZTday = 0;
1319 
1320 
1321  // ........................................................................
1322  // Number of Active DCMs per Subrun
1323  currentTime = 0;
1324  current = 0.0;
1325  ave = 0.0;
1326  for(int i = 0; i < NDCMDayCount[p]; ++i) {
1327  ave += (double)NDCMDay[p][i];
1328  if(NDCMtimeDay[p][i] > currentTime) {
1329  currentTime = NDCMtimeDay[p][i];
1330  current = NDCMDay[p][i];
1331  }
1332  }
1333  if(NDCMDayCount[p] > 0) ave = ave/(double)NDCMDayCount[p];
1334  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1335  LastPoint->Clear();
1336  LastPoint->AddText(lptext);
1337  TCanvas *cNDCMday = new TCanvas("cNDCMday","# of DCMs day",1200,800);
1338  cNDCMday->cd();
1339  gPad->SetGridx();
1340  TGraph *gNDCMday = new TGraph(NDCMDayCount[p],NDCMtimeDay[p],NDCMDay[p]);
1341  sprintf(title,"Number of Active DCMs per Subrun - partition %.1u",p);
1342  gNDCMday->SetTitle(title);
1343  gNDCMday->SetMarkerColor(kBlue);
1344  gNDCMday->GetXaxis()->SetTimeDisplay(1);
1345  gNDCMday->GetXaxis()->SetLabelSize(0.03);
1346  gNDCMday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1347  gNDCMday->GetXaxis()->SetLimits(time_ago,XNow);
1348  gNDCMday->GetXaxis()->SetTitle("(central time)");
1349  gNDCMday->Draw("A*");
1350  UpdateText->Draw();
1351  LastPoint->Draw();
1352  sprintf(filename,"%s/%s-%s-P%.1uNDCMperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1353  cNDCMday->Print(filename);
1354  delete cNDCMday;
1355  cNDCMday = 0;
1356 
1357 
1358  // ........................................................................
1359  // Number of Active FEBs per Subrun
1360  currentTime = 0;
1361  current = 0.0;
1362  ave = 0.0;
1363  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1364  ave += (double)NFEBDay[p][i];
1365  if(NFEBtimeDay[p][i] > currentTime) {
1366  currentTime = NFEBtimeDay[p][i];
1367  current = NFEBDay[p][i];
1368  }
1369  }
1370  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1371  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1372  LastPoint->Clear();
1373  LastPoint->AddText(lptext);
1374  TCanvas *cNFEBday = new TCanvas("cNFEBday","# of FEBs day",1200,800);
1375  cNFEBday->cd();
1376  gPad->SetGridx();
1377  TGraph *gNFEBday = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1378  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1379  gNFEBday->SetTitle(title);
1380 
1381  // Change plot color to red if latest point drops below threshold
1382  gNFEBday->SetMarkerColor(kBlue);
1383  gNFEBday->GetXaxis()->SetTimeDisplay(1);
1384  gNFEBday->GetXaxis()->SetLabelSize(0.03);
1385  gNFEBday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1386  gNFEBday->GetXaxis()->SetLimits(time_ago,XNow);
1387  gNFEBday->GetXaxis()->SetTitle("(central time)");
1388  if(det_type == "FarDet"){
1389  gNFEBday->SetMinimum(0);
1390  gNFEBday->SetMaximum(11700);
1391  }
1392  double lmax=gPad->GetUymax();
1393  int FEBmax = 0;
1394  if(det_type == "FarDet"){
1395  FEBmax = 10749;
1396  }
1397  if(det_type == "NearDet"){
1398  FEBmax = 631;
1399  }
1400  if(det_type =="TestBeam"){
1401  FEBmax = 126;
1402  }
1403  double range = FEBmax - 620;
1404  double rangeBuffer = 0.10 * range;
1405  double thisMax = ((rangeBuffer > 1) ? FEBmax + rangeBuffer : FEBmax + 6);
1406  gNFEBday->SetMaximum(thisMax);
1407  gNFEBday->Draw("A*");
1408  gPad->Update();
1409  TLine* lMaxFEBs = new TLine(gPad->GetUxmin(),FEBmax,gPad->GetUxmax(),FEBmax);
1410  lMaxFEBs->SetLineColor(kGreen+2);
1411  lMaxFEBs->SetLineWidth(3);
1412  lMaxFEBs->SetLineStyle(9);
1413  lMaxFEBs->Draw();
1414  UpdateText->Draw();
1415  LastPoint->Draw();
1416  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1417  cNFEBday->Print(filename);
1418  //delete cNFEBday;
1419  //cNFEBday = 0;
1420 
1421  // Number of Drop Outs v. Time Plot
1422  currentTime = 0;
1423  current = 0.0;
1424  ave = 0.0;
1425  for(int i = 0; i < NFEBDDayCount[p]; ++i) {
1426  ave += (double)NFEBDDay[p][i];
1427  if(NFEBtimeDDay[p][i] > currentTime) {
1428  currentTime = NFEBtimeDDay[p][i];
1429  current = NFEBDDay[p][i];
1430  }
1431  }
1432  if(NFEBDDayCount[p] > 0) ave = ave/(double)NFEBDDayCount[p];
1433  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1434  LastPoint->Clear();
1435  LastPoint->AddText(lptext);
1436  TCanvas *cNFEBDday = new TCanvas("cNFEBDday","# of FEB Drop Outs day",1200,800);
1437  cNFEBDday->cd();
1438  gPad->SetGridx();
1439  TGraph *gNFEBDday = new TGraph(NFEBDDayCount[p],NFEBtimeDDay[p],NFEBDDay[p]);
1440  sprintf(title,"%s Number of FEB Drop Outs per Subrun - partition %.1u",trigname.c_str(), p);
1441  gNFEBDday->SetTitle(title);
1442 
1443  gNFEBDday->SetMarkerColor(kBlue);
1444  gNFEBDday->GetXaxis()->SetTimeDisplay(1);
1445  gNFEBDday->GetXaxis()->SetLabelSize(0.03);
1446  gNFEBDday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1447  gNFEBDday->GetXaxis()->SetLimits(time_ago,XNow);
1448  gNFEBDday->GetXaxis()->SetTitle("(central time)");
1449  gNFEBDday->Draw("A*");
1450  UpdateText->Draw();
1451  LastPoint->Draw();
1452  sprintf(filename,"%s/%s-%s-P%.1uNDropOutFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1453  cNFEBDday->Print(filename);
1454  //delete cNFEBDday;
1455  //cNFEBDday = 0;
1456  // ........................................................................
1457  // TODO: Number of Active FEBs per Subrun TEST TEST TEST TEST
1458  currentTime = 0;
1459  current = 0.0;
1460  ave = 0.0;
1461  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1462  ave += (double)NFEBDay[p][i];
1463  if(NFEBtimeDay[p][i] > currentTime) {
1464  currentTime = NFEBtimeDay[p][i];
1465  current = NFEBDay[p][i];
1466  }
1467  }
1468  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1469  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1470  LastPoint->Clear();
1471  LastPoint->AddText(lptext);
1472  TCanvas *cNFEBdayTest = new TCanvas("cNFEBdayTest","# of FEBs day",1200,800);
1473  cNFEBdayTest->SetFillColor(kRed - 4);
1474  cNFEBdayTest->cd();
1475  gPad->SetGridx();
1476  TGraph *gNFEBdayTest = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1477  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1478  gNFEBdayTest->SetTitle(title);
1479 
1480  // Change plot color to red if latest point drops below threshold
1481  if((det_type == "FarDet") && (current < 10690)) {
1482  // gNFEBdayTest->SetMarkerColor(kRed);
1483  // gPad->SetFrameFillColor(kWhite);
1484  // cNFEBdayTest->SetFillColor(kRed);
1485  gNFEBdayTest->SetMarkerColor(kBlue);
1486  }
1487  else {
1488  // gNFEBdayTest->SetMarkerColor(kWhite);
1489  }
1490  gNFEBdayTest->GetXaxis()->SetTimeDisplay(1);
1491  gNFEBdayTest->GetXaxis()->SetLabelSize(0.03);
1492  gNFEBdayTest->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1493  gNFEBdayTest->GetXaxis()->SetLimits(time_ago,XNow);
1494  gNFEBdayTest->GetXaxis()->SetTitle("(central time)");
1495  if(det_type == "FarDet"){
1496  gNFEBdayTest->SetMinimum(10650);
1497  gNFEBdayTest->SetMaximum(10720);
1498  }
1499  gNFEBdayTest->Draw("A*");
1500  UpdateText->Draw();
1501  LastPoint->Draw();
1502  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSR%s-TEST.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1503  cNFEBdayTest->Print(filename);
1504  delete cNFEBdayTest;
1505  cNFEBdayTest = 0;
1506  //////////////////////////////////////////////////////////////////////////////////
1507 
1508 
1509 
1510  // ........................................................................
1511  // Number of Active FEBs per Subrun (ZOOM)
1512  if(det_type != "NearDet"){
1513  timeVariable = 0;
1514  currentTime = 0;
1515  current = 0.0;
1516  ave = 0.0;
1517  max = 0.0;
1518  max2 = 0.0;
1519  min1 = 99999;
1520  min2 = 99998;
1521  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1522  ave += (double)NFEBDay[p][i];
1523  if(i==0)
1524  timeVariable = NFEBtimeDay[p][i];
1525  if(NFEBtimeDay[p][i] > currentTime) {
1526  currentTime = NFEBtimeDay[p][i];
1527  current = NFEBDay[p][i];
1528  }
1529  //std::cout << "i, Time: " << i << ", " << NFEBtimeDay[p][i] << std::endl;
1530  //find min 2 points
1531  if(NFEBDay[p][i] <= min1){
1532  //if zero data points are over x seconds old, ignore them (to avoid always zooming out)
1533  if((NFEBDay[p][i] == 0 ) && ((timeVariable - NFEBtimeDay[p][i]) > 7400))
1534  continue;
1535  min2 = min1;
1536  min1 = NFEBDay[p][i];
1537  }
1538  if(NFEBDay[p][i] > min1){
1539  if(NFEBDay[p][i] < min2)
1540  min2 = NFEBDay[p][i];
1541  }
1542 
1543  //find max 2 points
1544  if(NFEBDay[p][i] >= max){
1545  max2 = max;
1546  max = NFEBDay[p][i];
1547  }
1548  if(NFEBDay[p][i] < max){
1549  if(NFEBDay[p][i] > max2)
1550  max2 = NFEBDay[p][i];
1551  }
1552  //std::cout << "Current, Max, max2, min, min2: " << NFEBDay[p][i] << ", " << max << ", " << max2 << ", " << min1 << ", " << min2 << std::endl;
1553  }
1554  //threshold for showing warning error for NFEB plot
1555  threshold = max2 - 45;
1556  //max2 += (max2-min2)*0.1;
1557  //min2 -= (max2-min2)*0.1;
1558  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1559  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1560  LastPoint->Clear();
1561  LastPoint->AddText(lptext);
1562  TCanvas *cNFEBday_zoom = new TCanvas("cNFEBday_zoom","# of FEBs day",1200,800);
1563  cNFEBday_zoom->cd();
1564  gPad->SetGridx();
1565  TGraph *gNFEBday_zoom = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1566  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1567  gNFEBday_zoom->SetTitle(title);
1568  //std::cout << "Current threshold: " << threshold << std::endl;
1569  // Change plot color to red if latest point drops below threshold
1570  int FEBmax = 0;
1571  if(det_type == "FarDet"){
1572  FEBmax = 10749;
1573  }
1574  if(det_type == "NearDet"){
1575  FEBmax = 631;
1576  }
1577  if(det_type == "TestBeam"){
1578  FEBmax = 126;
1579  threshold = 122;
1580  }
1581  if((det_type == "FarDet" || det_type == "TestBeam") && (current < threshold) && (period == "Day")) {
1582  cNFEBday_zoom->SetFillColor(kRed);
1583  sprintf(warntext,"WARNING! Low Number of FEBs! (%.f)",current);
1584  WarningText->Clear();
1585  WarningText->SetFillColorAlpha(kRed,0.5);
1586  WarningText->AddText(warntext);
1587  if (p==1 && det_type == "TestBeam") {
1588  send_feb_email=true;
1589  nfeb = current;
1590  }
1591  }
1592  else if((det_type == "FarDet") && (current < 10500)){
1593  gNFEBday_zoom->SetMarkerColor(kWhite);
1594  cNFEBday_zoom->SetFillColor(kRed);
1595  sprintf(warntext,"WARNING! Low Number of FEBs! (%.f)",current);
1596  WarningText->Clear();
1597  WarningText->AddText(warntext);
1598  }
1599  else {
1600  gNFEBday_zoom->SetMarkerColor(kBlue);
1601  }
1602  gNFEBday_zoom->GetXaxis()->SetTimeDisplay(1);
1603  gNFEBday_zoom->GetXaxis()->SetLabelSize(0.03);
1604  gNFEBday_zoom->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1605  gNFEBday_zoom->GetXaxis()->SetLimits(time_ago,XNow);
1606  gNFEBday_zoom->GetXaxis()->SetTitle("(central time)");
1607  if(period == "Month" || period == "Week"){
1608  gNFEBday_zoom->SetMinimum(ave-105);
1609  }
1610  else{
1611  gNFEBday_zoom->SetMinimum(min2-(max2-min2)*0.1);
1612  }
1613  double range = FEBmax - gNFEBday_zoom->GetMinimum();
1614  double rangeBuffer = 0.10 * range;
1615  double thisMax = ((rangeBuffer > 1) ? FEBmax + rangeBuffer : FEBmax + 1);
1616  gNFEBday_zoom->SetMaximum(thisMax);
1617  gNFEBday_zoom->Draw("A*");
1618  cNFEBday_zoom->Update();
1619  TLine* lMaxFEBs = new TLine(gPad->GetUxmin(),FEBmax,gPad->GetUxmax(),FEBmax);
1620  lMaxFEBs->SetLineColor(kGreen+2);
1621  lMaxFEBs->SetLineWidth(3);
1622  lMaxFEBs->SetLineStyle(9);
1623  lMaxFEBs->Draw();
1624  UpdateText->Draw();
1625  LastPoint->Draw();
1626  if(((det_type == "FarDet" || det_type == "TestBeam") && (current < threshold) && (period == "Day")) || ((det_type == "FarDet") && (current < 10500) && (period == "Day") )){
1627  WarningText->Draw();
1628  }
1629  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSRzoom%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1630  cNFEBday_zoom->Print(filename);
1631  delete cNFEBday_zoom;
1632  cNFEBday_zoom = 0;
1633  }
1634 
1635 
1636  // ........................................................................
1637  // Number of Active Channels per Subrun
1638  currentTime = 0;
1639  current = 0.0;
1640  ave = 0.0;
1641  for(int i = 0; i < NPIXperSRDayCount[p]; ++i) {
1642  ave += (double)NPIXperSRDay[p][i];
1643  if(NPIXperSRtimeDay[p][i] > currentTime) {
1644  currentTime = NPIXperSRtimeDay[p][i];
1645  current = NPIXperSRDay[p][i];
1646  }
1647  }
1648  if(NPIXperSRDayCount[p] > 0) ave = ave/(double)NPIXperSRDayCount[p];
1649  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1650  LastPoint->Clear();
1651  LastPoint->AddText(lptext);
1652  TCanvas *cNPIXperSRday = new TCanvas("cNPIXperSRday","# of channels per subrun day",1200,800);
1653  cNPIXperSRday->cd();
1654  gPad->SetGridx();
1655  TGraph *gNPIXperSRday = new TGraph(NPIXperSRDayCount[p],NPIXperSRtimeDay[p],NPIXperSRDay[p]);
1656  sprintf(title,"%s Number of Active Channels per Subrun - partition %.1u",trigname.c_str(), p);
1657  gNPIXperSRday->SetTitle(title);
1658  gNPIXperSRday->SetMarkerColor(kBlue);
1659  gNPIXperSRday->GetXaxis()->SetTimeDisplay(1);
1660  gNPIXperSRday->GetXaxis()->SetLabelSize(0.03);
1661  gNPIXperSRday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1662  gNPIXperSRday->GetXaxis()->SetLimits(time_ago,XNow);
1663  gNPIXperSRday->GetXaxis()->SetTitle("(central time)");
1664  gNPIXperSRday->Draw("A*");
1665  UpdateText->Draw();
1666  LastPoint->Draw();
1667  sprintf(filename,"%s/%s-%s-P%.1uNPIXperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1668  cNPIXperSRday->Print(filename);
1669  delete cNPIXperSRday;
1670  cNPIXperSRday = 0;
1671 
1672 
1673  // ........................................................................
1674  // Average Number of Hits per Spill
1675  currentTime = 0;
1676  current = 0.0;
1677  ave = 0.0;
1678  for(int i = 0; i < NPIXperEVTDayCount[p]; ++i) {
1679  ave += (double)NPIXperEVTDay[p][i];
1680  if(NPIXperEVTtimeDay[p][i] > currentTime) {
1681  currentTime = NPIXperEVTtimeDay[p][i];
1682  current = NPIXperEVTDay[p][i];
1683  }
1684  }
1685  if(NPIXperEVTDayCount[p] > 0) ave = ave/(double)NPIXperEVTDayCount[p];
1686  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1687  LastPoint->Clear();
1688  LastPoint->AddText(lptext);
1689  TCanvas *cNPIXperEVTday = new TCanvas("cNPIXperEVTday","# of hits per spill day",1200,800);
1690  cNPIXperEVTday->cd();
1691  gPad->SetGridx();
1692  TGraph *gNPIXperEVTday = new TGraph(NPIXperEVTDayCount[p],NPIXperEVTtimeDay[p],NPIXperEVTDay[p]);
1693  sprintf(title,"%s Average Number of Hits per Spill - partition %.1u",trigname.c_str(),p);
1694  gNPIXperEVTday->SetTitle(title);
1695  gNPIXperEVTday->SetMarkerColor(kBlue);
1696  gNPIXperEVTday->GetXaxis()->SetTimeDisplay(1);
1697  gNPIXperEVTday->GetXaxis()->SetLabelSize(0.03);
1698  gNPIXperEVTday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1699  gNPIXperEVTday->GetXaxis()->SetLimits(time_ago,XNow);
1700  gNPIXperEVTday->GetXaxis()->SetTitle("(central time)");
1701  gNPIXperEVTday->Draw("A*");
1702  UpdateText->Draw();
1703  LastPoint->Draw();
1704  sprintf(filename,"%s/%s-%s-P%.1uNPIXperEVT%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1705  cNPIXperEVTday->Print(filename);
1706  delete cNPIXperEVTday;
1707  cNPIXperEVTday = 0;
1708 
1709 
1710  // ........................................................................
1711  // Percentage of Empty Spills
1712  currentTime = 0;
1713  current = 0.0;
1714  ave = 0.0;
1715  for(int i = 0; i < Ndcm0DayCount[p]; ++i) {
1716  ave += (double)Ndcm0Day[p][i];
1717  if(dcm0timeDay[p][i] > currentTime) {
1718  currentTime = dcm0timeDay[p][i];
1719  current = Ndcm0Day[p][i];
1720  }
1721  }
1722  if(Ndcm0DayCount[p] > 0) ave = ave/(double)Ndcm0DayCount[p];
1723  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1724  LastPoint->Clear();
1725  LastPoint->AddText(lptext);
1726  TCanvas *cNdcm0day = new TCanvas("cNdcm0day","# of zero DCM spills day",1200,800);
1727  cNdcm0day->cd();
1728  gPad->SetGridx();
1729  TGraph *gNdcm0day = new TGraph(Ndcm0DayCount[p],dcm0timeDay[p],Ndcm0Day[p]);
1730  sprintf(title,"%s Percentage of Empty Spills (zero DCMs reporting) - partition %.1u",trigname.c_str(),p);
1731  gNdcm0day->SetTitle(title);
1732  gNdcm0day->SetMarkerColor(kBlue);
1733  gNdcm0day->GetXaxis()->SetTimeDisplay(1);
1734  gNdcm0day->GetXaxis()->SetLabelSize(0.03);
1735  gNdcm0day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1736  gNdcm0day->GetXaxis()->SetLimits(time_ago,XNow);
1737  gNdcm0day->GetYaxis()->SetTitle("percent");
1738  gNdcm0day->GetXaxis()->SetTitle("(central time)");
1739  gNdcm0day->Draw("A*");
1740  UpdateText->Draw();
1741  LastPoint->Draw();
1742  sprintf(filename,"%s/%s-%s-P%.1uNdcm0%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1743  cNdcm0day->Print(filename);
1744  delete cNdcm0day;
1745  cNdcm0day = 0;
1746 
1747 
1748  // ........................................................................
1749  // Average NuMI Trigger Rate Seen by OnMon per Subrun
1750  currentTime = 0;
1751  current = 0.0;
1752  ave = 0.0;
1753  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1754  ave += (double)Trig00Day[p][i];
1755  if(Trig00timeDay[p][i] > currentTime) {
1756  currentTime = Trig00timeDay[p][i];
1757  current = Trig00Day[p][i];
1758  }
1759  }
1760  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1761  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1762  LastPoint->Clear();
1763  LastPoint->AddText(lptext);
1764  TCanvas *cTrig00day = new TCanvas("cTrig00day","trig00 rate day",1200,800);
1765  cTrig00day->cd();
1766  gPad->SetGridx();
1767  TGraph *gTrig00day = new TGraph(NTrigDayCount[p],Trig00timeDay[p],Trig00Day[p]);
1768  sprintf(title,"Average NuMI Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1769  gTrig00day->SetTitle(title);
1770  gTrig00day->SetMarkerColor(kBlue);
1771  gTrig00day->GetXaxis()->SetTimeDisplay(1);
1772  gTrig00day->GetXaxis()->SetLabelSize(0.03);
1773  gTrig00day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1774  gTrig00day->GetXaxis()->SetLimits(time_ago,XNow);
1775  gTrig00day->GetYaxis()->SetLimits(0,11);
1776  gTrig00day->GetXaxis()->SetTitle("(central time)");
1777  gTrig00day->Draw("A*");
1778  UpdateText->Draw();
1779  LastPoint->Draw();
1780  sprintf(filename,"%s/%s-%s-P%.1uNuMITriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1781  cTrig00day->Print(filename);
1782 
1783 
1784  // ........................................................................
1785  // Average BNB/Beamline(TB) Trigger Rate Seen by OnMon per Subrun
1786  currentTime = 0;
1787  current = 0.0;
1788  ave = 0.0;
1789  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1790  ave += (double)Trig01Day[p][i];
1791  if(Trig01timeDay[p][i] > currentTime) {
1792  currentTime = Trig01timeDay[p][i];
1793  current = Trig01Day[p][i];
1794  }
1795  }
1796  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1797  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1798  LastPoint->Clear();
1799  LastPoint->AddText(lptext);
1800  TCanvas *cTrig01day = new TCanvas("cTrig01day","trig01 rate day",1200,800);
1801  cTrig01day->cd();
1802  gPad->SetGridx();
1803  TGraph *gTrig01day = new TGraph(NTrigDayCount[p],Trig01timeDay[p],Trig01Day[p]);
1804  sprintf(title,"Average Beamline Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1805  gTrig01day->SetTitle(title);
1806  gTrig01day->SetMarkerColor(kBlue);
1807  gTrig01day->GetXaxis()->SetTimeDisplay(1);
1808  gTrig01day->GetXaxis()->SetLabelSize(0.03);
1809  gTrig01day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1810  gTrig01day->GetXaxis()->SetLimits(time_ago,XNow);
1811  gTrig01day->GetYaxis()->SetLimits(0,11);
1812  gTrig01day->GetXaxis()->SetTitle("(central time)");
1813  gTrig01day->Draw("A*");
1814  UpdateText->Draw();
1815  LastPoint->Draw();
1816  sprintf(filename,"%s/%s-%s-P%.1uBeamlineTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1817  cTrig01day->Print(filename);
1818 
1819 
1820  // ........................................................................
1821  // Average Cosmic Trigger Rate Seen by OnMon per Subrun
1822  currentTime = 0;
1823  current = 0.0;
1824  ave = 0.0;
1825  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1826  ave += (double)Trig02Day[p][i];
1827  if(Trig02timeDay[p][i] > currentTime) {
1828  currentTime = Trig02timeDay[p][i];
1829  current = Trig02Day[p][i];
1830  }
1831  }
1832  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1833  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1834  LastPoint->Clear();
1835  LastPoint->AddText(lptext);
1836  TCanvas *cTrig02day = new TCanvas("cTrig02day","trig02 rate day",1200,800);
1837  cTrig02day->cd();
1838  gPad->SetGridx();
1839  TGraph *gTrig02day = new TGraph(NTrigDayCount[p],Trig02timeDay[p],Trig02Day[p]);
1840  sprintf(title,"Average Cosmic Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1841  gTrig02day->SetTitle(title);
1842  gTrig02day->SetMarkerColor(kBlue);
1843  gTrig02day->SetMarkerStyle(21);
1844  gTrig02day->GetXaxis()->SetTimeDisplay(1);
1845  gTrig02day->GetXaxis()->SetLabelSize(0.03);
1846  gTrig02day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1847  gTrig02day->GetXaxis()->SetLimits(time_ago,XNow);
1848  gTrig02day->GetYaxis()->SetLimits(0,1.1);
1849  gTrig02day->GetXaxis()->SetTitle("(central time)");
1850  gTrig02day->Draw("A*");
1851  UpdateText->Draw();
1852  LastPoint->Draw();
1853  sprintf(filename,"%s/%s-%s-P%.1uCosmicTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1854  cTrig02day->Print(filename);
1855 
1856 
1857  // ........................................................................
1858  // Average DDActivity Trigger Rate Seen by OnMon per Subrun
1859  currentTime = 0;
1860  current = 0.0;
1861  ave = 0.0;
1862  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1863  ave += (double)TrigActDay[p][i];
1864  if(TrigActtimeDay[p][i] > currentTime) {
1865  currentTime = TrigActtimeDay[p][i];
1866  current = TrigActDay[p][i];
1867  }
1868  }
1869  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1870  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1871  LastPoint->Clear();
1872  LastPoint->AddText(lptext);
1873  TCanvas *cTrigActday = new TCanvas("cTrigActday","trigact rate day",1200,800);
1874  cTrigActday->cd();
1875  gPad->SetGridx();
1876  TGraph *gTrigActday = new TGraph(NTrigDayCount[p],TrigActtimeDay[p],TrigActDay[p]);
1877  sprintf(title,"Average DDActivity Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1878  gTrigActday->SetTitle(title);
1879 
1880  // Change plot color to red if latest point drops below threshold
1881  if((det_type == "TestBeam") && (current < 10) && (period == "Day")) {
1882  cTrigActday->SetFillColor(kRed);
1883  sprintf(warntext,"WARNING! Trigger rate low! (%.2f Hz)",current);
1884  WarningText->Clear();
1885  WarningText->SetFillColorAlpha(kRed,0.5);
1886  WarningText->AddText(warntext);
1887  if (p==1) {
1888  send_ddactrate_email=true;
1889  ddactrate=current;
1890  }
1891  }
1892  gTrigActday->SetMarkerColor(kBlue);
1893  gTrigActday->GetXaxis()->SetTimeDisplay(1);
1894  gTrigActday->GetXaxis()->SetLabelSize(0.03);
1895  gTrigActday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1896  gTrigActday->GetXaxis()->SetLimits(time_ago,XNow);
1897  gTrigActday->GetYaxis()->SetLimits(0,11);
1898  gTrigActday->GetXaxis()->SetTitle("(central time)");
1899  gTrigActday->Draw("A*");
1900  gPad->Update();
1901  UpdateText->Draw();
1902  LastPoint->Draw();
1903  if((det_type == "TestBeam") && (current < 10) && (period == "Day")) {
1904  WarningText->Draw();
1905  }
1906  sprintf(filename,"%s/%s-%s-P%.1uActTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1907  cTrigActday->Print(filename);
1908 
1909 
1910  // ........................................................................
1911  // Spill Count per bin interval
1912  std::cout<<NSpillEntryCount[0]<<"......"<<std::endl;
1913  std::cout<<NSpills<<"......"<<std::endl;
1914 
1915  TGraph *gSpillCount = new TGraph(NSpillEntryCount[0],SpillCountTime[0],SpillCountValue[0]);
1916 
1917  currentTime = 0;
1918  current = 0.0;
1919  ave = 0.0;
1920  for(int i = 0; i < NSpillEntryCount[0]; ++i) {
1921  ave += (double)SpillCountValue[0][i];
1922  if(SpillCountTime[0][i] > currentTime) {
1923  currentTime = SpillCountTime[0][i];
1924  current = SpillCountValue[0][i];
1925  }
1926  }
1927  if(NSpillEntryCount[0] > 0) ave = ave/(double)NSpillEntryCount[0];
1928  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1929  LastPoint->Clear();
1930  LastPoint->AddText(lptext);
1931  TCanvas *cSpill = new TCanvas("cSpill","Spill Count day",1200,800);
1932  cSpill->cd();
1933  gPad->SetGridx();
1934  // TGraph *gTrig00day = new TGraph(NTrigDayCount[p],Trig00timeDay[p],Trig00Day[p]);
1935  sprintf(title,"Spill count per bin interval");
1936  gSpillCount->SetTitle(title);
1937  gSpillCount->SetMarkerColor(kMagenta);
1938  gSpillCount->SetMarkerStyle(22);
1939  gSpillCount->GetXaxis()->SetTimeDisplay(1);
1940  gSpillCount->GetXaxis()->SetLabelSize(0.03);
1941  gSpillCount->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1942  gSpillCount->GetXaxis()->SetLimits(time_ago,XNow);
1943  gSpillCount->GetXaxis()->SetTitle("(central time)");
1944  gSpillCount->Draw("A*");
1945  UpdateText->Draw();
1946  LastPoint->Draw();
1947  sprintf(filename,"%s/%s-%s-P%.1uSpillCount%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1948  cSpill->Print(filename);
1949 
1950  // ........................................................................
1951  // BNB Spill Count per bin interval
1952  //std::cout<<BNBNSpillEntryCount[0]<<"......"<<std::endl;
1953  //std::cout<<BNBNSpills<<"......"<<std::endl;
1954 
1955  // TGraph *gBNBSpillCount = new TGraph(BNBNSpillEntryCount[0],BNBSpillCountTime[0],BNBSpillCountValue[0]);
1956 
1957  currentTime = 0;
1958  current = 0.0;
1959  ave = 0.0;
1960  //for(int i = 0; i < BNBNSpillEntryCount[0]; ++i) {
1961  //ave += (double)BNBSpillCountValue[0][i];
1962  //if(BNBSpillCountTime[0][i] > currentTime) {
1963  // currentTime = BNBSpillCountTime[0][i];
1964  // current = BNBSpillCountValue[0][i];
1965  //}
1966  //}
1967  //if(BNBNSpillEntryCount[0] > 0) ave = ave/(double)BNBNSpillEntryCount[0];
1968  //sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1969  //LastPoint->Clear();
1970  //LastPoint->AddText(lptext);
1971  //TCanvas *cBNBSpill = new TCanvas("cBNBSpill","BNB Spill Count day",1200,800);
1972  //cBNBSpill->cd();
1973  //gPad->SetGridx();
1974  sprintf(title,"Spill count per bin interval");
1975  //gBNBSpillCount->SetTitle(title);
1976  //gBNBSpillCount->SetMarkerColor(kMagenta);
1977  //gBNBSpillCount->SetMarkerStyle(22);
1978  //gBNBSpillCount->GetXaxis()->SetTimeDisplay(1);
1979  //gBNBSpillCount->GetXaxis()->SetLabelSize(0.03);
1980  //gBNBSpillCount->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1981  //gBNBSpillCount->GetXaxis()->SetLimits(time_ago,XNow);
1982  //gBNBSpillCount->GetXaxis()->SetTitle("(central time)");
1983  //gBNBSpillCount->Draw("A*");
1984  //UpdateText->Draw();
1985  //LastPoint->Draw();
1986  //sprintf(filename,"%s/%s-%s-P%.1uBNBSpillCount%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1987  // cBNBSpill->Print(filename);
1988 
1989  // Combined Active FEBs and FEB Drop Outs
1990 
1991  TCanvas *cCombo = new TCanvas("cCombo", "feb active/dropout day", 1200, 800);
1992  TPad *activepad = new TPad("activepad","",0,0,1,1);
1993  TPad *dropoutpad = new TPad("dropoutpad","",0,0,1,1);
1994 
1995  dropoutpad->SetFillStyle(4000); //transparent
1996  dropoutpad->SetFillColor(0);
1997  dropoutpad->SetFrameFillStyle(4000);
1998  activepad->Draw();
1999  activepad->cd();
2000  activepad->SetGridx();
2001 
2002  sprintf(title,"Number of Active and Drop Out FEBs - partition %.1u",p);
2003  gNFEBday->SetTitle(title);
2004  gNFEBday->SetMarkerStyle(22);
2005  gNFEBday->SetMarkerColor(kBlue);
2006  gNFEBday->SetFillColor(kBlue);
2007  //gNFEBday->GetYaxis()->SetLabelOffset(1);
2008  gNFEBday->GetYaxis()->SetLabelColor(kBlue);
2009  //gNFEBday->GetYaxis()->SetNdivisions(0, kFALSE);
2010  if( det == "FarDet")
2011  gNFEBday->GetYaxis()->SetRangeUser(10740,10750);
2012  if( det == "NearDet")
2013  gNFEBday->GetYaxis()->SetRangeUser(625,635);
2014  gNFEBday->Draw("AP");
2015 
2016  activepad->Modified();
2017  activepad->Update();
2018 
2019  dropoutpad->Draw();
2020  dropoutpad->cd();
2021  dropoutpad->SetGridx();
2022 
2023  gNFEBDday->SetTitle("");
2024  gNFEBDday->SetMarkerStyle(23);
2025  gNFEBDday->SetMarkerColor(kOrange+7);
2026  gNFEBDday->SetFillColor(kOrange+7);
2027  gNFEBDday->GetYaxis()->SetLabelColor(kOrange+7);
2028  gNFEBDday->GetYaxis()->SetRangeUser(0,10);
2029  gNFEBDday->Draw("APY+");
2030 
2031  UpdateText->Draw();
2032 
2033  dropoutpad->Modified();
2034  dropoutpad->Update();
2035 
2036  TLegend *legc = new TLegend(0.62,0.69,0.87,0.78);
2037  legc->SetFillColor(0);
2038  TLegendEntry *af = legc->AddEntry(gNFEBday,"#bf{Active FEBs}","F");
2039  af->SetTextColor(kBlue);
2040  TLegendEntry *df = legc->AddEntry(gNFEBDday,"#bf{FEB Drop Outs}","F");
2041  df->SetTextColor(kOrange+7);
2042  legc->SetFillStyle(4000);
2043  legc->SetLineColor(0);
2044  legc->Draw();
2045 
2046  sprintf(filename,"%s/%s-%s-P%.1uNDropOutActiveFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
2047  cCombo->Print(filename);
2048  delete cCombo;
2049  delete cNFEBDday;
2050  delete cNFEBday;
2051  cCombo = 0;
2052  cNFEBDday = 0;
2053  cNFEBday = 0;
2054 
2055  // ........................................................................
2056  // Average Trigger and Spill Rates
2057  gTrig00day->SetMarkerColor(kRed);
2058  TCanvas *cTrig = new TCanvas("cTrig", "trig rate day",1200, 800);
2059 
2060  float currentNuMITrigRate = Trig00Day[1][NTrigDayCount[1] - 1];
2061  float currentSpillRate = SpillCountValue[0][NSpillEntryCount[0] - 1];
2062 
2063  //float spillRateThreshold = 0.8;
2064  float triggerRateThreshold = 0.9;
2065  float spillNumiDiffThreshold = 0.05;
2066 
2067  TPad *pad1 = new TPad("pad1","",0,0,1,1);
2068  TPad *pad2 = new TPad("pad2","",0,0,1,1);
2069  TPad *pad3 = new TPad("pad3","",0,0,1,1);
2070  TPad *pad4 = new TPad("pad4","",0,0,1,1);
2071  // Warning: spill rate too high
2072  // NOTE: This is not working right now, so commenting it out.
2073  // Hopefully someone will come back and fix this someday.
2074  //std::cout << "CHECKING FOR HIGH SPILL RATE......";
2075  //if (currentSpillRate > spillRateThreshold){
2076  // std::cout << "BAD" << std::endl;
2077  // pad1->SetFillColor(kRed - 4);
2078  //
2079  // // Email experts
2080  // char cmd[1000];
2081  // char to[1000] = "nova_watchdogs@fnal.gov nova_nearlineonmon_support@fnal.gov jvasel@indiana.edu";
2082  // char subject[1000] = "Nearline--Current spill rate exceeds alarm thresholds";
2083  // char body[1000] = "There may be an issue with the timing system.";
2084  //
2085  // sprintf(cmd, "echo %s | mail -s %s %s", body, subject, to);
2086  // system(cmd);
2087  //}
2088  //else {
2089  // std::cout << "OK" << std::endl;
2090  //}
2091 
2092  // Warning: spill and trigger rate differ
2093  //std::cout << "CHECKING FOR SPILL/TRIGGER RATE MISMATCH......";
2094  //if (std::abs(currentSpillRate - currentNuMITrigRate) > spillNumiDiffThreshold){
2095  // std::cout << "BAD";
2096  // pad1->SetFillColor(kRed - 4);
2097  //
2098  // // Email experts
2099  // char cmd[1000];
2100  // char to[1000] = "nova_watchdogs@fnal.gov nova_nearlineonmon_support@fnal.gov jvasel@indiana.edu";
2101  // char subject[1000] = "Nearline--Current spill rate differs from NuMI trigger rate";
2102  // char body[1000] = "There may be an issue with the spill server.";
2103  //
2104  // sprintf(cmd, "echo %s | mail -s %s %s", body, subject, to);
2105  // system(cmd);
2106  //}
2107  //else {
2108  // std::cout << "OK";
2109  //}
2110  //std::cout << " (SpillRate=" << currentSpillRate << " TrigRate=" << currentNuMITrigRate
2111  // << " Diff=" << std::abs(currentSpillRate - currentNuMITrigRate) << ")" << std::endl;
2112  pad2->SetFillStyle(4000); // pad2 will be transparent
2113  pad2->SetFillColor(0);
2114  pad2->SetFrameFillStyle(4000);
2115  pad3->SetFillStyle(4000); // pad2 will be transparent
2116  pad3->SetFillColor(0);
2117  pad3->SetFrameFillStyle(4000);
2118  pad4->SetFillStyle(4000); // pad2 will be transparent
2119  pad4->SetFillColor(0);
2120  pad4->SetFrameFillStyle(4000);
2121  pad1->Draw();
2122  pad1->cd();
2123  pad1->SetGridx();
2124 
2125  sprintf(title,"Average Trigger and Spill Rates (Hz) - partition %.1u",p);
2126  gTrig00day->SetTitle(title);
2127  gTrig00day->SetMarkerStyle(21);
2128  gTrig00day->SetMarkerColor(kRed+3);
2129  gTrig00day->SetFillColor(kRed+3);
2130  if (t_prd != "Day") gTrig00day->SetMarkerStyle(7);
2131  gTrig00day->GetYaxis()->SetLabelOffset(1);
2132  gTrig00day->GetYaxis()->SetLabelColor(kRed+3);
2133  gTrig00day->GetYaxis()->SetNdivisions(0, kFALSE); // Disable tick marks
2134  gTrig00day->GetYaxis()->SetRangeUser(0,1.1);
2135 
2136  WarningText->Clear();
2137  std::cout << "CHECKING FOR HIGH NUMI TRIGGER RATE......";
2138  std::cout<<"Current NuMI trigger rate = "<<currentNuMITrigRate<<std::endl;
2139  if (currentNuMITrigRate > triggerRateThreshold){
2140  std::cout << "NUMI TRIGGER RATE TOO HIGH" << std::endl;
2141  pad1->SetFillColor(kRed);
2142  sprintf(warntext,"WARNING! NuMI trigger rate too high! Call DAQ expert!");
2143  WarningText->AddText(warntext);
2144  send_spill_email=true;
2145  }
2146  else {
2147  std::cout << "OK" << std::endl;
2148  }
2149  std::cout << " (SpillRate=" << currentSpillRate << " TrigRate=" << currentNuMITrigRate
2150  << " Diff=" << std::abs(currentSpillRate - currentNuMITrigRate) << ")" << std::endl;
2151 
2152  gTrig00day->Draw("AP");
2153  WarningText->Draw();
2154 
2155  pad1->Modified();
2156  pad1->Update();
2157 
2158  pad4->Draw();
2159  pad4->cd();
2160  pad4->SetGridx();
2161 
2162  //pad2->Draw();
2163  //pad2->cd();
2164  //pad2->SetGridx();
2165 
2166  //gBNBSpillCount->SetTitle("");
2167  //gBNBSpillCount->GetYaxis()->SetRangeUser(0,30);
2168  //gBNBSpillCount->GetYaxis()->SetLabelColor(kBlue+3);
2169  //gBNBSpillCount->SetMarkerStyle(34);
2170  //gBNBSpillCount->SetFillColor(kBlue+3);
2171  //gBNBSpillCount->SetMarkerColor(kBlue+3);
2172  //gBNBSpillCount->Draw("AP");
2173 
2174  if(det_type != "NearDet"){
2175  gTrig02day->SetTitle("");
2176  gTrig02day->SetMarkerStyle(21);
2177  if (t_prd != "Day") gTrig02day->SetMarkerStyle(7);
2178  gTrig02day->SetFillColor(kBlue);
2179  gTrig02day->GetYaxis()->SetLabelColor(kBlue);
2180  gTrig02day->GetYaxis()->SetRangeUser(0,30);
2181  gTrig02day->Draw("AP");
2182  }
2183  pad4->Modified();
2184  pad4->Update();
2185 
2186  pad3->Draw();
2187  pad3->cd();
2188  pad3->SetGridx();
2189 
2190  gSpillCount->SetTitle("");
2191  gSpillCount->GetYaxis()->SetRangeUser(0,1.1);
2192  gSpillCount->GetYaxis()->SetLabelColor(kRed);
2193  gSpillCount->SetMarkerStyle(34);
2194  gSpillCount->SetFillColor(kRed);
2195  gSpillCount->SetMarkerColor(kRed);
2196  gSpillCount->Draw("APY+");
2197  UpdateText->Draw();
2198 
2199  pad3->Modified();
2200  pad3->Update();
2201 
2202  TLegend *leg = new TLegend(0.62,0.69,0.87,0.78);
2203  leg->SetFillColor(0);
2204  if(det_type != "NearDet"){
2205  TLegendEntry *l2 = leg->AddEntry(gTrig02day,"#bf{Cosmic Trigger Rate}","F");
2206  l2->SetTextColor(kBlue);
2207  }
2208  // TLegendEntry *l4 = leg->AddEntry(gBNBSpillCount,"#bf{Delivered BNB Spill Rate}","F");
2209  //l4->SetTextColor(kBlue+3);
2210  TLegendEntry *l1 = leg->AddEntry(gTrig00day,"#bf{NuMI Trigger Rate}","F");
2211  l1->SetTextColor(kRed+3);
2212  TLegendEntry *l3 = leg->AddEntry(gSpillCount,"#bf{Delivered NuMI Spill Rate}","F");
2213  l3->SetTextColor(kRed);
2214  leg->SetFillStyle(4000);
2215  leg->SetLineColor(0);
2216  leg->Draw();
2217 
2218  sprintf(filename,"%s/%s-%s-P%.1uCosmicNuMITriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
2219  cTrig->Print(filename);
2220  delete cTrig;
2221  delete cTrig00day;
2222  delete cTrig02day;
2223  delete cSpill;
2224  cSpill=0;
2225  cTrig02day = 0;
2226  cTrig00day = 0;
2227  cTrig = 0;
2228  }
2229 
2230  // If NuMI trigger rate is too high for any partition, send email.
2231  if (send_spill_email) {
2232  char cmd[1000];
2233  char to[1000] = "tlackey@indiana.edu nova_runcoordinator@fnal.gov mcgroh@iu.edu jvasel@iu.edu nova_daq_support@fnal.gov";
2234  char subject[1000] = "NuMI Trigger rate too high.";
2235  char body[1000] = "NuMI Trigger rate is too high. There may be an issue with the spill server.";
2236 
2237  sprintf(cmd, "echo -e \"%s\" | mail -s \"%s\" %s",body,subject,to);
2238  system(cmd);
2239  }
2240 
2241  // If Number of active FEBs too low, send email.
2242  if (send_feb_email) {
2243  char cmd[1000];
2244  char to[1000] = "tlackey@indiana.edu";
2245  char subject[1000] = "NFEBs too low.";
2246  char body[1000];// = "Number of Active FEBs is too low. The TDU may be disconnected.";
2247  sprintf(body,"Number of Active FEBs (%d) is too low. The TDU may be disconnected.",nfeb);
2248 
2249  sprintf(cmd, "echo -e \"%s\" | mail -s \"%s\" %s",body,subject,to);
2250  system(cmd);
2251  }
2252  // If DDActivity rate is too low, send email.
2253  if (send_ddactrate_email) {
2254  char cmd[1000];
2255  char to[1000] = "tlackey@indiana.edu";
2256  char subject[1000] = "DDActivity rate too low.";
2257  char body[1000];// = "DDActivity rate is too low. The run may need restarting.";
2258  sprintf(body,"DDActivity rate is too low: %f Hz. The run may need restarting.",ddactrate);
2259 
2260  sprintf(cmd, "echo -e \"%s\" | mail -s \"%s\" %s",body,subject,to);
2261  system(cmd);
2262  }
2263 }
enum BeamMode kOrange
UInt_t LastSR
Definition: AnaPlotMaker.h:50
enum BeamMode kRed
system("rm -rf microbeam.root")
TPaveText * UpdateText
Definition: DCSPlotMaker.C:18
TDatime * TNow
Definition: AnaPlotMaker.h:41
string body
Definition: readPickles.py:54
const char * p
Definition: xmltok.h:285
Int_t par
Definition: SimpleIterate.C:24
string filename
Definition: shutoffs.py:106
TDatime * SRtime
Definition: AnaPlotMaker.h:42
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
float abs(float number)
Definition: d0nt_math.hpp:39
ifstream inFile
Definition: AnaPlotMaker.h:34
string cmd
Definition: run_hadd.py:52
TPaveText * WarningText
Definition: DCSPlotMaker.C:19
Float_t E
Definition: plot.C:20
const unsigned int Npar
Definition: AnaPlotMaker.h:38
const double a
UInt_t LastRun
Definition: AnaPlotMaker.h:49
const double j
Definition: BetheBloch.cxx:29
void OnMonPlotMaker()
const std::string PLOT_DIR
Definition: AnaPlotMaker.C:8
Definition: run.py:1
TDatime * TNowGMT
Definition: AnaPlotMaker.h:40
OStream cout
Definition: OStream.cxx:6
det_type
Definition: Constants.h:584
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
Float_t norm
T log10(T number)
Definition: d0nt_math.hpp:120
Int_t GMToffset
Definition: AnaPlotMaker.h:43
double livetime
Definition: saveFDMCHists.C:21
TPad * pad3
Definition: analysis.C:13
void Config(const TH1 *h)
Definition: HwDetLabel.cxx:21
TPad * pad2
Definition: analysis.C:13
Float_t e
Definition: plot.C:35
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
enum BeamMode kGreen
enum BeamMode kBlue
TPad * pad1
Definition: analysis.C:13
static constexpr Double_t year
Definition: Munits.h:185
enum BeamMode string