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.1, 0.0, 0.5, 0.05, "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.05);
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 
1105  // Make conditional standard time axis labels depending on period (Day, Week, Month)
1106  string taxis_labels;
1107  if(period == "Day"){
1108  taxis_labels = "%H:%M";
1109  }
1110  else{
1111  taxis_labels = "%m/%d";
1112  }
1113 
1114  // make the OnMon hardware label drawer
1115  om::HwDetLabel *hwdetlbl = new om::HwDetLabel();
1116 
1117  // loop over all partitions to make 24 hour plots
1118  for(unsigned int p = 0; p < Npar; ++p) {
1119  char filename[128];
1120  char title[128];
1121 
1122  for(unsigned int e = 0; e < Nerr; ++e) {
1123  TCanvas *cErr = new TCanvas("cErr","Errors",2000,800);
1124  cErr->cd();
1125 
1126  hErrorHistos[p][e]->SetLineWidth(2);
1127  hErrorHistos[p][e]->SetLineColor(kBlue);
1128  hErrorHistos[p][e]->Draw("hist");
1129  UpdateText->Draw();
1130  hErrorHistos[p][e]->GetXaxis()->SetTimeDisplay(1);
1131  hErrorHistos[p][e]->GetXaxis()->SetLabelSize(0.03);
1132  hErrorHistos[p][e]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1133  hErrorHistos[p][e]->SetStats(kFALSE);
1134 
1135  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());
1136  cErr->Print(filename);
1137 
1138  delete cErr;
1139  cErr = 0;
1140  }
1141 
1142  for(unsigned int a = 0; a < Nalert; ++a) {
1143  TCanvas *cAlert = new TCanvas("cAlert","Alerts",2000,800);
1144  cAlert->cd();
1145 
1146  hAlertHistos[p][a]->SetLineWidth(2);
1147  hAlertHistos[p][a]->SetLineColor(kBlue);
1148  hAlertHistos[p][a]->Draw("hist");
1149  UpdateText->Draw();
1150  hAlertHistos[p][a]->GetXaxis()->SetTimeDisplay(1);
1151  hAlertHistos[p][a]->GetXaxis()->SetLabelSize(0.03);
1152  hAlertHistos[p][a]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1153  hAlertHistos[p][a]->SetStats(kFALSE);
1154 
1155  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());
1156  cAlert->Print(filename);
1157 
1158  delete cAlert;
1159  cAlert = 0;
1160  }
1161 
1162 
1163  TCanvas *cQday = new TCanvas("cQday","Qplot Day",1200,800);
1164  cQday->cd();
1165  gPad->SetLogx();
1166  gPad->SetLogy();
1167  gStyle->SetOptStat(111111);
1168  hQDay[p]->SetAxisRange(5.0,5000.0,"X");
1169  hQDay[p]->SetLineWidth(2);
1170  hQDay[p]->SetLineColor(kRed);
1171  hQDay[p]->Draw();
1172  UpdateText->Draw();
1173  // Change this to normal directory but different plot name
1174  sprintf(filename,"%s/%s-%s-P%.1uQPlot%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1175  cQday->Print(filename);
1176  delete cQday;
1177  cQday = 0;
1178 
1179  TCanvas *cHMRday = new TCanvas("cHMRday","FEB HitMap Rates Day",1200,800);
1180  cHMRday->cd();
1181  cHMRday->SetLogz();
1182  gStyle->SetPalette(1); //kRainbow
1183  hFEBRateHitMapDay[p]->SetAxisRange(100.0,40000.0,"Z");
1184  hFEBRateHitMapDay[p]->GetXaxis()->SetTickLength(0);
1185  hFEBRateHitMapDay[p]->GetXaxis()->SetLabelColor(0);
1186  hFEBRateHitMapDay[p]->GetYaxis()->SetTickLength(0);
1187  hFEBRateHitMapDay[p]->GetYaxis()->SetLabelColor(0);
1188  hFEBRateHitMapDay[p]->SetStats(kFALSE);
1189  hwdetlbl->Config(hFEBRateHitMapDay[p]);
1190  hFEBRateHitMapDay[p]->Draw("colz");
1191  hwdetlbl->Draw();
1192  UpdateText->Draw();
1193  sprintf(filename,"%s/%s-%s-P%.1uFEBRateHitMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1194  cHMRday->Print(filename);
1195  delete cHMRday;
1196  cHMRday = 0;
1197 
1198  TCanvas *cHMdropday = new TCanvas("cHMdropday", "FEB Dropouts Day",1200,800);
1199  cHMdropday->cd();
1200  cHMdropday->SetLogz();
1201  hFEBDropOutMapDay[p]->SetAxisRange(1,100.0,"Z");
1202  hFEBDropOutMapDay[p]->GetXaxis()->SetTickLength(0);
1203  hFEBDropOutMapDay[p]->GetXaxis()->SetLabelColor(0);
1204  hFEBDropOutMapDay[p]->GetYaxis()->SetTickLength(0);
1205  hFEBDropOutMapDay[p]->GetYaxis()->SetLabelColor(0);
1206  hFEBDropOutMapDay[p]->SetStats(kFALSE);
1207  hwdetlbl->Config(hFEBDropOutMapDay[p]);
1208  hFEBDropOutMapDay[p]->Draw("colz");
1209  hwdetlbl->Draw();
1210  UpdateText->Draw();
1211  sprintf(filename,"%s/%s-%s-P%.1uFEBDropOutMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1212  cHMdropday->Print(filename);
1213  delete cHMdropday;
1214  cHMdropday = 0;
1215 
1216  TCanvas *cHMadcday = new TCanvas("cHMadcday","FEB ave ADC HitMap Day",1200,800);
1217  cHMadcday->cd();
1218  cHMadcday->SetLogz();
1219  hFEBaveADCHitMapDay[p]->SetAxisRange(0.5,1000,"Z");
1220  hFEBaveADCHitMapDay[p]->GetXaxis()->SetTickLength(0);
1221  hFEBaveADCHitMapDay[p]->GetXaxis()->SetLabelColor(0);
1222  hFEBaveADCHitMapDay[p]->GetYaxis()->SetTickLength(0);
1223  hFEBaveADCHitMapDay[p]->GetYaxis()->SetLabelColor(0);
1224  hFEBaveADCHitMapDay[p]->SetStats(kFALSE);
1225  hwdetlbl->Config(hFEBaveADCHitMapDay[p]);
1226  hFEBaveADCHitMapDay[p]->Draw("colz");
1227  hwdetlbl->Draw();
1228  UpdateText->Draw();
1229  sprintf(filename,"%s/%s-%s-P%.1uFEBaveADCHitMap%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1230  cHMadcday->Print(filename);
1231  delete cHMadcday;
1232  cHMadcday = 0;
1233 
1234  TCanvas *cFRday = new TCanvas("cFRday","FEB Rate Day",1200,800);
1235  cFRday->cd();
1236  gPad->SetLogy();
1237  gStyle->SetOptStat(111111);
1238  hFEBRateSpectrumDay[p]->SetLineWidth(2);
1239  hFEBRateSpectrumDay[p]->SetLineColor(kGreen+2);
1240  hFEBRateSpectrumDay[p]->Draw();
1241  UpdateText->Draw();
1242  sprintf(filename,"%s/%s-%s-P%.1uFEBRateSpectrum%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1243  cFRday->Print(filename);
1244  delete cFRday;
1245  cFRday = 0;
1246 
1247  TCanvas *cFEBRTday = new TCanvas("cFEBRTday","FEB Rate vs Time day",1200,800);
1248  cFEBRTday->cd();
1249  gPad->SetGridx();
1250  gPad->SetLogz();
1251  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1252  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1253  hFEBRateSpectrumVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1254  hFEBRateSpectrumVsTimeDay[p]->SetStats(kFALSE);
1255  hFEBRateSpectrumVsTimeDay[p]->Draw("colz");
1256  UpdateText->Draw();
1257  sprintf(filename,"%s/%s-%s-P%.1uFEBRateSpectrumVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1258  cFEBRTday->Print(filename);
1259  delete cFEBRTday;
1260  cFEBRTday = 0;
1261 
1262  TCanvas *cTPAday = new TCanvas("cTPAday","TPlotALL Day",1200,800);
1263  cTPAday->cd();
1264  gStyle->SetOptStat(111111);
1265  hTPlotALLDay[p]->SetLineWidth(2);
1266  hTPlotALLDay[p]->SetLineColor(kBlue);
1267  hTPlotALLDay[p]->Draw();
1268  hTPlotALLDay[p]->GetYaxis()->UnZoom();
1269  UpdateText->Draw();
1270  sprintf(filename,"%s/%s-%s-P%.1uTPlotALL%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1271  cTPAday->Print(filename);
1272  delete cTPAday;
1273  cTPAday = 0;
1274 
1275  TCanvas *cTPATday = new TCanvas("cTPATday","TPlotALL vs Time day",1200,800);
1276  cTPATday->cd();
1277  gPad->SetGridx();
1278  hTPlotALLVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1279  hTPlotALLVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1280  hTPlotALLVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1281  hTPlotALLVsTimeDay[p]->SetStats(kFALSE);
1282  hTPlotALLVsTimeDay[p]->Draw("colz");
1283  UpdateText->Draw();
1284  sprintf(filename,"%s/%s-%s-P%.1uTPlotALLVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1285  cTPATday->Print(filename);
1286  delete cTPATday;
1287  cTPATday = 0;
1288 
1289  TCanvas *cTPZday = new TCanvas("cTPZday","TPlotZOOM Day",1200,800);
1290  cTPZday->cd();
1291  gStyle->SetOptStat(111111);
1292  hTPlotZOOMDay[p]->SetLineWidth(2);
1293  hTPlotZOOMDay[p]->SetLineColor(kBlue);
1294  hTPlotZOOMDay[p]->Draw();
1295  hTPlotZOOMDay[p]->GetYaxis()->UnZoom();
1296  UpdateText->Draw();
1297  sprintf(filename,"%s/%s-%s-P%.1uTPloZOOM%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1298  cTPZday->Print(filename);
1299  delete cTPZday;
1300  cTPZday = 0;
1301 
1302  TCanvas *cTPZTday = new TCanvas("cTPZTday","TPlotZOOM vs Time day",1200,800);
1303  cTPZTday->cd();
1304  gPad->SetGridx();
1305  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetTimeDisplay(1);
1306  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetLabelSize(0.03);
1307  hTPlotZOOMVsTimeDay[p]->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1308  hTPlotZOOMVsTimeDay[p]->SetStats(kFALSE);
1309  hTPlotZOOMVsTimeDay[p]->Draw("colz");
1310  UpdateText->Draw();
1311  sprintf(filename,"%s/%s-%s-P%.1uTPlotZOOMVsTime%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1312  cTPZTday->Print(filename);
1313  delete cTPZTday;
1314  cTPZTday = 0;
1315 
1316 
1317  // ........................................................................
1318  // Number of Active DCMs per Subrun
1319  currentTime = 0;
1320  current = 0.0;
1321  ave = 0.0;
1322  for(int i = 0; i < NDCMDayCount[p]; ++i) {
1323  ave += (double)NDCMDay[p][i];
1324  if(NDCMtimeDay[p][i] > currentTime) {
1325  currentTime = NDCMtimeDay[p][i];
1326  current = NDCMDay[p][i];
1327  }
1328  }
1329  if(NDCMDayCount[p] > 0) ave = ave/(double)NDCMDayCount[p];
1330  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1331  LastPoint->Clear();
1332  LastPoint->AddText(lptext);
1333  TCanvas *cNDCMday = new TCanvas("cNDCMday","# of DCMs day",1200,800);
1334  cNDCMday->cd();
1335  gPad->SetGridx();
1336  TGraph *gNDCMday = new TGraph(NDCMDayCount[p],NDCMtimeDay[p],NDCMDay[p]);
1337  sprintf(title,"Number of Active DCMs per Subrun - partition %.1u",p);
1338  gNDCMday->SetTitle(title);
1339  gNDCMday->SetMarkerColor(kBlue);
1340  gNDCMday->GetXaxis()->SetTimeDisplay(1);
1341  gNDCMday->GetXaxis()->SetLabelSize(0.03);
1342  gNDCMday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1343  gNDCMday->GetXaxis()->SetLimits(time_ago,XNow);
1344  gNDCMday->GetXaxis()->SetTitle("(central time)");
1345  gNDCMday->Draw("A*");
1346  UpdateText->Draw();
1347  LastPoint->Draw();
1348  sprintf(filename,"%s/%s-%s-P%.1uNDCMperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1349  cNDCMday->Print(filename);
1350  delete cNDCMday;
1351  cNDCMday = 0;
1352 
1353 
1354  // ........................................................................
1355  // Number of Active FEBs per Subrun
1356  currentTime = 0;
1357  current = 0.0;
1358  ave = 0.0;
1359  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1360  ave += (double)NFEBDay[p][i];
1361  if(NFEBtimeDay[p][i] > currentTime) {
1362  currentTime = NFEBtimeDay[p][i];
1363  current = NFEBDay[p][i];
1364  }
1365  }
1366  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1367  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1368  LastPoint->Clear();
1369  LastPoint->AddText(lptext);
1370  TCanvas *cNFEBday = new TCanvas("cNFEBday","# of FEBs day",1200,800);
1371  cNFEBday->cd();
1372  gPad->SetGridx();
1373  TGraph *gNFEBday = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1374  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1375  gNFEBday->SetTitle(title);
1376 
1377  // Change plot color to red if latest point drops below threshold
1378  gNFEBday->SetMarkerColor(kBlue);
1379  gNFEBday->GetXaxis()->SetTimeDisplay(1);
1380  gNFEBday->GetXaxis()->SetLabelSize(0.03);
1381  gNFEBday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1382  gNFEBday->GetXaxis()->SetLimits(time_ago,XNow);
1383  gNFEBday->GetXaxis()->SetTitle("(central time)");
1384  if(det_type == "FarDet"){
1385  gNFEBday->SetMinimum(0);
1386  gNFEBday->SetMaximum(11700);
1387  }
1388  double lmax=gPad->GetUymax();
1389  int FEBmax = 0;
1390  if(det_type == "FarDet"){
1391  FEBmax = 10749;
1392  }
1393  if(det_type == "NearDet"){
1394  FEBmax = 631;
1395  }
1396  if(det_type =="TestBeam"){
1397  FEBmax = 126;
1398  }
1399  double range = FEBmax - 620;
1400  double rangeBuffer = 0.10 * range;
1401  double thisMax = ((rangeBuffer > 1) ? FEBmax + rangeBuffer : FEBmax + 6);
1402  gNFEBday->SetMaximum(thisMax);
1403  gNFEBday->Draw("A*");
1404  gPad->Update();
1405  TLine* lMaxFEBs = new TLine(gPad->GetUxmin(),FEBmax,gPad->GetUxmax(),FEBmax);
1406  lMaxFEBs->SetLineColor(kGreen+2);
1407  lMaxFEBs->SetLineWidth(3);
1408  lMaxFEBs->SetLineStyle(9);
1409  lMaxFEBs->Draw();
1410  UpdateText->Draw();
1411  LastPoint->Draw();
1412  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1413  cNFEBday->Print(filename);
1414  //delete cNFEBday;
1415  //cNFEBday = 0;
1416 
1417  // Number of Drop Outs v. Time Plot
1418  currentTime = 0;
1419  current = 0.0;
1420  ave = 0.0;
1421  for(int i = 0; i < NFEBDDayCount[p]; ++i) {
1422  ave += (double)NFEBDDay[p][i];
1423  if(NFEBtimeDDay[p][i] > currentTime) {
1424  currentTime = NFEBtimeDDay[p][i];
1425  current = NFEBDDay[p][i];
1426  }
1427  }
1428  if(NFEBDDayCount[p] > 0) ave = ave/(double)NFEBDDayCount[p];
1429  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1430  LastPoint->Clear();
1431  LastPoint->AddText(lptext);
1432  TCanvas *cNFEBDday = new TCanvas("cNFEBDday","# of FEB Drop Outs day",1200,800);
1433  cNFEBDday->cd();
1434  gPad->SetGridx();
1435  TGraph *gNFEBDday = new TGraph(NFEBDDayCount[p],NFEBtimeDDay[p],NFEBDDay[p]);
1436  sprintf(title,"%s Number of FEB Drop Outs per Subrun - partition %.1u",trigname.c_str(), p);
1437  gNFEBDday->SetTitle(title);
1438 
1439  gNFEBDday->SetMarkerColor(kBlue);
1440  gNFEBDday->GetXaxis()->SetTimeDisplay(1);
1441  gNFEBDday->GetXaxis()->SetLabelSize(0.03);
1442  gNFEBDday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1443  gNFEBDday->GetXaxis()->SetLimits(time_ago,XNow);
1444  gNFEBDday->GetXaxis()->SetTitle("(central time)");
1445  gNFEBDday->Draw("A*");
1446  UpdateText->Draw();
1447  LastPoint->Draw();
1448  sprintf(filename,"%s/%s-%s-P%.1uNDropOutFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1449  cNFEBDday->Print(filename);
1450  //delete cNFEBDday;
1451  //cNFEBDday = 0;
1452  // ........................................................................
1453  // TODO: Number of Active FEBs per Subrun TEST TEST TEST TEST
1454  currentTime = 0;
1455  current = 0.0;
1456  ave = 0.0;
1457  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1458  ave += (double)NFEBDay[p][i];
1459  if(NFEBtimeDay[p][i] > currentTime) {
1460  currentTime = NFEBtimeDay[p][i];
1461  current = NFEBDay[p][i];
1462  }
1463  }
1464  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1465  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1466  LastPoint->Clear();
1467  LastPoint->AddText(lptext);
1468  TCanvas *cNFEBdayTest = new TCanvas("cNFEBdayTest","# of FEBs day",1200,800);
1469  cNFEBdayTest->SetFillColor(kRed - 4);
1470  cNFEBdayTest->cd();
1471  gPad->SetGridx();
1472  TGraph *gNFEBdayTest = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1473  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1474  gNFEBdayTest->SetTitle(title);
1475 
1476  // Change plot color to red if latest point drops below threshold
1477  if((det_type == "FarDet") && (current < 10690)) {
1478  // gNFEBdayTest->SetMarkerColor(kRed);
1479  // gPad->SetFrameFillColor(kWhite);
1480  // cNFEBdayTest->SetFillColor(kRed);
1481  gNFEBdayTest->SetMarkerColor(kBlue);
1482  }
1483  else {
1484  // gNFEBdayTest->SetMarkerColor(kWhite);
1485  }
1486  gNFEBdayTest->GetXaxis()->SetTimeDisplay(1);
1487  gNFEBdayTest->GetXaxis()->SetLabelSize(0.03);
1488  gNFEBdayTest->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1489  gNFEBdayTest->GetXaxis()->SetLimits(time_ago,XNow);
1490  gNFEBdayTest->GetXaxis()->SetTitle("(central time)");
1491  if(det_type == "FarDet"){
1492  gNFEBdayTest->SetMinimum(10650);
1493  gNFEBdayTest->SetMaximum(10720);
1494  }
1495  gNFEBdayTest->Draw("A*");
1496  UpdateText->Draw();
1497  LastPoint->Draw();
1498  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSR%s-TEST.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1499  cNFEBdayTest->Print(filename);
1500  delete cNFEBdayTest;
1501  cNFEBdayTest = 0;
1502  //////////////////////////////////////////////////////////////////////////////////
1503 
1504 
1505 
1506  // ........................................................................
1507  // Number of Active FEBs per Subrun (ZOOM)
1508  if(det_type != "NearDet"){
1509  timeVariable = 0;
1510  currentTime = 0;
1511  current = 0.0;
1512  ave = 0.0;
1513  max = 0.0;
1514  max2 = 0.0;
1515  min1 = 99999;
1516  min2 = 99998;
1517  for(int i = 0; i < NFEBDayCount[p]; ++i) {
1518  ave += (double)NFEBDay[p][i];
1519  if(i==0)
1520  timeVariable = NFEBtimeDay[p][i];
1521  if(NFEBtimeDay[p][i] > currentTime) {
1522  currentTime = NFEBtimeDay[p][i];
1523  current = NFEBDay[p][i];
1524  }
1525  //std::cout << "i, Time: " << i << ", " << NFEBtimeDay[p][i] << std::endl;
1526  //find min 2 points
1527  if(NFEBDay[p][i] <= min1){
1528  //if zero data points are over x seconds old, ignore them (to avoid always zooming out)
1529  if((NFEBDay[p][i] == 0 ) && ((timeVariable - NFEBtimeDay[p][i]) > 7400))
1530  continue;
1531  min2 = min1;
1532  min1 = NFEBDay[p][i];
1533  }
1534  if(NFEBDay[p][i] > min1){
1535  if(NFEBDay[p][i] < min2)
1536  min2 = NFEBDay[p][i];
1537  }
1538 
1539  //find max 2 points
1540  if(NFEBDay[p][i] >= max){
1541  max2 = max;
1542  max = NFEBDay[p][i];
1543  }
1544  if(NFEBDay[p][i] < max){
1545  if(NFEBDay[p][i] > max2)
1546  max2 = NFEBDay[p][i];
1547  }
1548  //std::cout << "Current, Max, max2, min, min2: " << NFEBDay[p][i] << ", " << max << ", " << max2 << ", " << min1 << ", " << min2 << std::endl;
1549  }
1550  //threshold for showing warning error for NFEB plot
1551  threshold = max2 - 45;
1552  //max2 += (max2-min2)*0.1;
1553  //min2 -= (max2-min2)*0.1;
1554  if(NFEBDayCount[p] > 0) ave = ave/(double)NFEBDayCount[p];
1555  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1556  LastPoint->Clear();
1557  LastPoint->AddText(lptext);
1558  TCanvas *cNFEBday_zoom = new TCanvas("cNFEBday_zoom","# of FEBs day",1200,800);
1559  cNFEBday_zoom->cd();
1560  gPad->SetGridx();
1561  TGraph *gNFEBday_zoom = new TGraph(NFEBDayCount[p],NFEBtimeDay[p],NFEBDay[p]);
1562  sprintf(title,"%s Number of Active FEBs per Subrun - partition %.1u",trigname.c_str(), p);
1563  gNFEBday_zoom->SetTitle(title);
1564  //std::cout << "Current threshold: " << threshold << std::endl;
1565  // Change plot color to red if latest point drops below threshold
1566  int FEBmax = 0;
1567  if(det_type == "FarDet"){
1568  FEBmax = 10749;
1569  }
1570  if(det_type == "NearDet"){
1571  FEBmax = 631;
1572  }
1573  if(det_type == "TestBeam"){
1574  FEBmax = 126;
1575  }
1576  if((det_type == "FarDet") && (current < threshold) && (period == "Day")) {
1577  gNFEBday_zoom->SetMarkerColor(kWhite);
1578  cNFEBday_zoom->SetFillColor(kRed);
1579  sprintf(warntext,"WARNING! :o Low Number of FEBs! (%.f)",current);
1580  WarningText->Clear();
1581  WarningText->AddText(warntext);
1582  }
1583  else if((det_type == "FarDet") && (current < 10500)){
1584  gNFEBday_zoom->SetMarkerColor(kWhite);
1585  cNFEBday_zoom->SetFillColor(kRed);
1586  sprintf(warntext,"WARNING! Low Number of FEBs! (%.f)",current);
1587  WarningText->Clear();
1588  WarningText->AddText(warntext);
1589  }
1590  else {
1591  gNFEBday_zoom->SetMarkerColor(kBlue);
1592  }
1593  gNFEBday_zoom->GetXaxis()->SetTimeDisplay(1);
1594  gNFEBday_zoom->GetXaxis()->SetLabelSize(0.03);
1595  gNFEBday_zoom->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1596  gNFEBday_zoom->GetXaxis()->SetLimits(time_ago,XNow);
1597  gNFEBday_zoom->GetXaxis()->SetTitle("(central time)");
1598  if(period == "Month" || period == "Week"){
1599  gNFEBday_zoom->SetMinimum(ave-105);
1600  }
1601  else{
1602  gNFEBday_zoom->SetMinimum(min2-(max2-min2)*0.1);
1603  }
1604  double range = FEBmax - gNFEBday_zoom->GetMinimum();
1605  double rangeBuffer = 0.10 * range;
1606  double thisMax = ((rangeBuffer > 1) ? FEBmax + rangeBuffer : FEBmax + 1);
1607  gNFEBday_zoom->SetMaximum(thisMax);
1608  gNFEBday_zoom->Draw("A*");
1609  cNFEBday_zoom->Update();
1610  TLine* lMaxFEBs = new TLine(gPad->GetUxmin(),FEBmax,gPad->GetUxmax(),FEBmax);
1611  lMaxFEBs->SetLineColor(kGreen+2);
1612  lMaxFEBs->SetLineWidth(3);
1613  lMaxFEBs->SetLineStyle(9);
1614  lMaxFEBs->Draw();
1615  UpdateText->Draw();
1616  LastPoint->Draw();
1617  if(((det_type == "FarDet") && (current < threshold) && (period == "Day")) || ((det_type == "FarDet") && (current < 10500) && (period == "Day") )){
1618  WarningText->Draw();
1619  }
1620  sprintf(filename,"%s/%s-%s-P%.1uNFEBperSRzoom%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1621  cNFEBday_zoom->Print(filename);
1622  delete cNFEBday_zoom;
1623  cNFEBday_zoom = 0;
1624  }
1625 
1626 
1627  // ........................................................................
1628  // Number of Active Channels per Subrun
1629  currentTime = 0;
1630  current = 0.0;
1631  ave = 0.0;
1632  for(int i = 0; i < NPIXperSRDayCount[p]; ++i) {
1633  ave += (double)NPIXperSRDay[p][i];
1634  if(NPIXperSRtimeDay[p][i] > currentTime) {
1635  currentTime = NPIXperSRtimeDay[p][i];
1636  current = NPIXperSRDay[p][i];
1637  }
1638  }
1639  if(NPIXperSRDayCount[p] > 0) ave = ave/(double)NPIXperSRDayCount[p];
1640  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1641  LastPoint->Clear();
1642  LastPoint->AddText(lptext);
1643  TCanvas *cNPIXperSRday = new TCanvas("cNPIXperSRday","# of channels per subrun day",1200,800);
1644  cNPIXperSRday->cd();
1645  gPad->SetGridx();
1646  TGraph *gNPIXperSRday = new TGraph(NPIXperSRDayCount[p],NPIXperSRtimeDay[p],NPIXperSRDay[p]);
1647  sprintf(title,"%s Number of Active Channels per Subrun - partition %.1u",trigname.c_str(), p);
1648  gNPIXperSRday->SetTitle(title);
1649  gNPIXperSRday->SetMarkerColor(kBlue);
1650  gNPIXperSRday->GetXaxis()->SetTimeDisplay(1);
1651  gNPIXperSRday->GetXaxis()->SetLabelSize(0.03);
1652  gNPIXperSRday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1653  gNPIXperSRday->GetXaxis()->SetLimits(time_ago,XNow);
1654  gNPIXperSRday->GetXaxis()->SetTitle("(central time)");
1655  gNPIXperSRday->Draw("A*");
1656  UpdateText->Draw();
1657  LastPoint->Draw();
1658  sprintf(filename,"%s/%s-%s-P%.1uNPIXperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1659  cNPIXperSRday->Print(filename);
1660  delete cNPIXperSRday;
1661  cNPIXperSRday = 0;
1662 
1663 
1664  // ........................................................................
1665  // Average Number of Hits per Spill
1666  currentTime = 0;
1667  current = 0.0;
1668  ave = 0.0;
1669  for(int i = 0; i < NPIXperEVTDayCount[p]; ++i) {
1670  ave += (double)NPIXperEVTDay[p][i];
1671  if(NPIXperEVTtimeDay[p][i] > currentTime) {
1672  currentTime = NPIXperEVTtimeDay[p][i];
1673  current = NPIXperEVTDay[p][i];
1674  }
1675  }
1676  if(NPIXperEVTDayCount[p] > 0) ave = ave/(double)NPIXperEVTDayCount[p];
1677  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1678  LastPoint->Clear();
1679  LastPoint->AddText(lptext);
1680  TCanvas *cNPIXperEVTday = new TCanvas("cNPIXperEVTday","# of hits per spill day",1200,800);
1681  cNPIXperEVTday->cd();
1682  gPad->SetGridx();
1683  TGraph *gNPIXperEVTday = new TGraph(NPIXperEVTDayCount[p],NPIXperEVTtimeDay[p],NPIXperEVTDay[p]);
1684  sprintf(title,"%s Average Number of Hits per Spill - partition %.1u",trigname.c_str(),p);
1685  gNPIXperEVTday->SetTitle(title);
1686  gNPIXperEVTday->SetMarkerColor(kBlue);
1687  gNPIXperEVTday->GetXaxis()->SetTimeDisplay(1);
1688  gNPIXperEVTday->GetXaxis()->SetLabelSize(0.03);
1689  gNPIXperEVTday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1690  gNPIXperEVTday->GetXaxis()->SetLimits(time_ago,XNow);
1691  gNPIXperEVTday->GetXaxis()->SetTitle("(central time)");
1692  gNPIXperEVTday->Draw("A*");
1693  UpdateText->Draw();
1694  LastPoint->Draw();
1695  sprintf(filename,"%s/%s-%s-P%.1uNPIXperEVT%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1696  cNPIXperEVTday->Print(filename);
1697  delete cNPIXperEVTday;
1698  cNPIXperEVTday = 0;
1699 
1700 
1701  // ........................................................................
1702  // Percentage of Empty Spills
1703  currentTime = 0;
1704  current = 0.0;
1705  ave = 0.0;
1706  for(int i = 0; i < Ndcm0DayCount[p]; ++i) {
1707  ave += (double)Ndcm0Day[p][i];
1708  if(dcm0timeDay[p][i] > currentTime) {
1709  currentTime = dcm0timeDay[p][i];
1710  current = Ndcm0Day[p][i];
1711  }
1712  }
1713  if(Ndcm0DayCount[p] > 0) ave = ave/(double)Ndcm0DayCount[p];
1714  sprintf(lptext,"Last Point = %.f / Average = %f",current,ave);
1715  LastPoint->Clear();
1716  LastPoint->AddText(lptext);
1717  TCanvas *cNdcm0day = new TCanvas("cNdcm0day","# of zero DCM spills day",1200,800);
1718  cNdcm0day->cd();
1719  gPad->SetGridx();
1720  TGraph *gNdcm0day = new TGraph(Ndcm0DayCount[p],dcm0timeDay[p],Ndcm0Day[p]);
1721  sprintf(title,"%s Percentage of Empty Spills (zero DCMs reporting) - partition %.1u",trigname.c_str(),p);
1722  gNdcm0day->SetTitle(title);
1723  gNdcm0day->SetMarkerColor(kBlue);
1724  gNdcm0day->GetXaxis()->SetTimeDisplay(1);
1725  gNdcm0day->GetXaxis()->SetLabelSize(0.03);
1726  gNdcm0day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1727  gNdcm0day->GetXaxis()->SetLimits(time_ago,XNow);
1728  gNdcm0day->GetYaxis()->SetTitle("percent");
1729  gNdcm0day->GetXaxis()->SetTitle("(central time)");
1730  gNdcm0day->Draw("A*");
1731  UpdateText->Draw();
1732  LastPoint->Draw();
1733  sprintf(filename,"%s/%s-%s-P%.1uNdcm0%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1734  cNdcm0day->Print(filename);
1735  delete cNdcm0day;
1736  cNdcm0day = 0;
1737 
1738 
1739  // ........................................................................
1740  // Average NuMI Trigger Rate Seen by OnMon per Subrun
1741  currentTime = 0;
1742  current = 0.0;
1743  ave = 0.0;
1744  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1745  ave += (double)Trig00Day[p][i];
1746  if(Trig00timeDay[p][i] > currentTime) {
1747  currentTime = Trig00timeDay[p][i];
1748  current = Trig00Day[p][i];
1749  }
1750  }
1751  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1752  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1753  LastPoint->Clear();
1754  LastPoint->AddText(lptext);
1755  TCanvas *cTrig00day = new TCanvas("cTrig00day","trig00 rate day",1200,800);
1756  cTrig00day->cd();
1757  gPad->SetGridx();
1758  TGraph *gTrig00day = new TGraph(NTrigDayCount[p],Trig00timeDay[p],Trig00Day[p]);
1759  sprintf(title,"Average NuMI Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1760  gTrig00day->SetTitle(title);
1761  gTrig00day->SetMarkerColor(kBlue);
1762  gTrig00day->GetXaxis()->SetTimeDisplay(1);
1763  gTrig00day->GetXaxis()->SetLabelSize(0.03);
1764  gTrig00day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1765  gTrig00day->GetXaxis()->SetLimits(time_ago,XNow);
1766  gTrig00day->GetYaxis()->SetLimits(0,11);
1767  gTrig00day->GetXaxis()->SetTitle("(central time)");
1768  gTrig00day->Draw("A*");
1769  UpdateText->Draw();
1770  LastPoint->Draw();
1771  sprintf(filename,"%s/%s-%s-P%.1uNuMITriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1772  cTrig00day->Print(filename);
1773 
1774 
1775  // ........................................................................
1776  // Average BNB/Beamline(TB) Trigger Rate Seen by OnMon per Subrun
1777  currentTime = 0;
1778  current = 0.0;
1779  ave = 0.0;
1780  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1781  ave += (double)Trig01Day[p][i];
1782  if(Trig01timeDay[p][i] > currentTime) {
1783  currentTime = Trig01timeDay[p][i];
1784  current = Trig01Day[p][i];
1785  }
1786  }
1787  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1788  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1789  LastPoint->Clear();
1790  LastPoint->AddText(lptext);
1791  TCanvas *cTrig01day = new TCanvas("cTrig01day","trig01 rate day",1200,800);
1792  cTrig01day->cd();
1793  gPad->SetGridx();
1794  TGraph *gTrig01day = new TGraph(NTrigDayCount[p],Trig01timeDay[p],Trig01Day[p]);
1795  sprintf(title,"Average Beamline Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1796  gTrig01day->SetTitle(title);
1797  gTrig01day->SetMarkerColor(kBlue);
1798  gTrig01day->GetXaxis()->SetTimeDisplay(1);
1799  gTrig01day->GetXaxis()->SetLabelSize(0.03);
1800  gTrig01day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1801  gTrig01day->GetXaxis()->SetLimits(time_ago,XNow);
1802  gTrig01day->GetYaxis()->SetLimits(0,11);
1803  gTrig01day->GetXaxis()->SetTitle("(central time)");
1804  gTrig01day->Draw("A*");
1805  UpdateText->Draw();
1806  LastPoint->Draw();
1807  sprintf(filename,"%s/%s-%s-P%.1uBeamlineTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1808  cTrig01day->Print(filename);
1809 
1810 
1811  // ........................................................................
1812  // Average Cosmic Trigger Rate Seen by OnMon per Subrun
1813  currentTime = 0;
1814  current = 0.0;
1815  ave = 0.0;
1816  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1817  ave += (double)Trig02Day[p][i];
1818  if(Trig02timeDay[p][i] > currentTime) {
1819  currentTime = Trig02timeDay[p][i];
1820  current = Trig02Day[p][i];
1821  }
1822  }
1823  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1824  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1825  LastPoint->Clear();
1826  LastPoint->AddText(lptext);
1827  TCanvas *cTrig02day = new TCanvas("cTrig02day","trig02 rate day",1200,800);
1828  cTrig02day->cd();
1829  gPad->SetGridx();
1830  TGraph *gTrig02day = new TGraph(NTrigDayCount[p],Trig02timeDay[p],Trig02Day[p]);
1831  sprintf(title,"Average Cosmic Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1832  gTrig02day->SetTitle(title);
1833  gTrig02day->SetMarkerColor(kBlue);
1834  gTrig02day->SetMarkerStyle(21);
1835  gTrig02day->GetXaxis()->SetTimeDisplay(1);
1836  gTrig02day->GetXaxis()->SetLabelSize(0.03);
1837  gTrig02day->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1838  gTrig02day->GetXaxis()->SetLimits(time_ago,XNow);
1839  gTrig02day->GetYaxis()->SetLimits(0,1.1);
1840  gTrig02day->GetXaxis()->SetTitle("(central time)");
1841  gTrig02day->Draw("A*");
1842  UpdateText->Draw();
1843  LastPoint->Draw();
1844  sprintf(filename,"%s/%s-%s-P%.1uCosmicTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1845  cTrig02day->Print(filename);
1846 
1847 
1848  // ........................................................................
1849  // Average DDActivity Trigger Rate Seen by OnMon per Subrun
1850  currentTime = 0;
1851  current = 0.0;
1852  ave = 0.0;
1853  for(int i = 0; i < NTrigDayCount[p]; ++i) {
1854  ave += (double)TrigActDay[p][i];
1855  if(TrigActtimeDay[p][i] > currentTime) {
1856  currentTime = TrigActtimeDay[p][i];
1857  current = TrigActDay[p][i];
1858  }
1859  }
1860  if(NTrigDayCount[p] > 0) ave = ave/(double)NTrigDayCount[p];
1861  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1862  LastPoint->Clear();
1863  LastPoint->AddText(lptext);
1864  TCanvas *cTrigActday = new TCanvas("cTrigActday","trigact rate day",1200,800);
1865  cTrigActday->cd();
1866  gPad->SetGridx();
1867  TGraph *gTrigActday = new TGraph(NTrigDayCount[p],TrigActtimeDay[p],TrigActDay[p]);
1868  sprintf(title,"Average DDActivity Trigger Rate (Hz) Seen by OnMon per Subrun - partition %.1u",p);
1869  gTrigActday->SetTitle(title);
1870  gTrigActday->SetMarkerColor(kBlue);
1871  gTrigActday->GetXaxis()->SetTimeDisplay(1);
1872  gTrigActday->GetXaxis()->SetLabelSize(0.03);
1873  gTrigActday->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1874  gTrigActday->GetXaxis()->SetLimits(time_ago,XNow);
1875  gTrigActday->GetYaxis()->SetLimits(0,11);
1876  gTrigActday->GetXaxis()->SetTitle("(central time)");
1877  gTrigActday->Draw("A*");
1878  UpdateText->Draw();
1879  LastPoint->Draw();
1880  sprintf(filename,"%s/%s-%s-P%.1uActTriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1881  cTrigActday->Print(filename);
1882 
1883 
1884  // ........................................................................
1885  // Spill Count per bin interval
1886  std::cout<<NSpillEntryCount[0]<<"......"<<std::endl;
1887  std::cout<<NSpills<<"......"<<std::endl;
1888 
1889  TGraph *gSpillCount = new TGraph(NSpillEntryCount[0],SpillCountTime[0],SpillCountValue[0]);
1890 
1891  currentTime = 0;
1892  current = 0.0;
1893  ave = 0.0;
1894  for(int i = 0; i < NSpillEntryCount[0]; ++i) {
1895  ave += (double)SpillCountValue[0][i];
1896  if(SpillCountTime[0][i] > currentTime) {
1897  currentTime = SpillCountTime[0][i];
1898  current = SpillCountValue[0][i];
1899  }
1900  }
1901  if(NSpillEntryCount[0] > 0) ave = ave/(double)NSpillEntryCount[0];
1902  sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1903  LastPoint->Clear();
1904  LastPoint->AddText(lptext);
1905  TCanvas *cSpill = new TCanvas("cSpill","Spill Count day",1200,800);
1906  cSpill->cd();
1907  gPad->SetGridx();
1908  // TGraph *gTrig00day = new TGraph(NTrigDayCount[p],Trig00timeDay[p],Trig00Day[p]);
1909  sprintf(title,"Spill count per bin interval");
1910  gSpillCount->SetTitle(title);
1911  gSpillCount->SetMarkerColor(kMagenta);
1912  gSpillCount->SetMarkerStyle(22);
1913  gSpillCount->GetXaxis()->SetTimeDisplay(1);
1914  gSpillCount->GetXaxis()->SetLabelSize(0.03);
1915  gSpillCount->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1916  gSpillCount->GetXaxis()->SetLimits(time_ago,XNow);
1917  gSpillCount->GetXaxis()->SetTitle("(central time)");
1918  gSpillCount->Draw("A*");
1919  UpdateText->Draw();
1920  LastPoint->Draw();
1921  sprintf(filename,"%s/%s-%s-P%.1uSpillCount%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1922  cSpill->Print(filename);
1923 
1924  // ........................................................................
1925  // BNB Spill Count per bin interval
1926  //std::cout<<BNBNSpillEntryCount[0]<<"......"<<std::endl;
1927  //std::cout<<BNBNSpills<<"......"<<std::endl;
1928 
1929  // TGraph *gBNBSpillCount = new TGraph(BNBNSpillEntryCount[0],BNBSpillCountTime[0],BNBSpillCountValue[0]);
1930 
1931  currentTime = 0;
1932  current = 0.0;
1933  ave = 0.0;
1934  //for(int i = 0; i < BNBNSpillEntryCount[0]; ++i) {
1935  //ave += (double)BNBSpillCountValue[0][i];
1936  //if(BNBSpillCountTime[0][i] > currentTime) {
1937  // currentTime = BNBSpillCountTime[0][i];
1938  // current = BNBSpillCountValue[0][i];
1939  //}
1940  //}
1941  //if(BNBNSpillEntryCount[0] > 0) ave = ave/(double)BNBNSpillEntryCount[0];
1942  //sprintf(lptext,"Last Point = %f / Average = %f",current,ave);
1943  //LastPoint->Clear();
1944  //LastPoint->AddText(lptext);
1945  //TCanvas *cBNBSpill = new TCanvas("cBNBSpill","BNB Spill Count day",1200,800);
1946  //cBNBSpill->cd();
1947  //gPad->SetGridx();
1948  sprintf(title,"Spill count per bin interval");
1949  //gBNBSpillCount->SetTitle(title);
1950  //gBNBSpillCount->SetMarkerColor(kMagenta);
1951  //gBNBSpillCount->SetMarkerStyle(22);
1952  //gBNBSpillCount->GetXaxis()->SetTimeDisplay(1);
1953  //gBNBSpillCount->GetXaxis()->SetLabelSize(0.03);
1954  //gBNBSpillCount->GetXaxis()->SetTimeFormat(taxis_labels.c_str());
1955  //gBNBSpillCount->GetXaxis()->SetLimits(time_ago,XNow);
1956  //gBNBSpillCount->GetXaxis()->SetTitle("(central time)");
1957  //gBNBSpillCount->Draw("A*");
1958  //UpdateText->Draw();
1959  //LastPoint->Draw();
1960  //sprintf(filename,"%s/%s-%s-P%.1uBNBSpillCount%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
1961  // cBNBSpill->Print(filename);
1962 
1963  // Combined Active FEBs and FEB Drop Outs
1964 
1965  TCanvas *cCombo = new TCanvas("cCombo", "feb active/dropout day", 1200, 800);
1966  TPad *activepad = new TPad("activepad","",0,0,1,1);
1967  TPad *dropoutpad = new TPad("dropoutpad","",0,0,1,1);
1968 
1969  dropoutpad->SetFillStyle(4000); //transparent
1970  dropoutpad->SetFillColor(0);
1971  dropoutpad->SetFrameFillStyle(4000);
1972  activepad->Draw();
1973  activepad->cd();
1974  activepad->SetGridx();
1975 
1976  sprintf(title,"Number of Active and Drop Out FEBs - partition %.1u",p);
1977  gNFEBday->SetTitle(title);
1978  gNFEBday->SetMarkerStyle(22);
1979  gNFEBday->SetMarkerColor(kBlue);
1980  gNFEBday->SetFillColor(kBlue);
1981  //gNFEBday->GetYaxis()->SetLabelOffset(1);
1982  gNFEBday->GetYaxis()->SetLabelColor(kBlue);
1983  //gNFEBday->GetYaxis()->SetNdivisions(0, kFALSE);
1984  if( det == "FarDet")
1985  gNFEBday->GetYaxis()->SetRangeUser(10740,10750);
1986  if( det == "NearDet")
1987  gNFEBday->GetYaxis()->SetRangeUser(625,635);
1988  gNFEBday->Draw("AP");
1989 
1990  activepad->Modified();
1991  activepad->Update();
1992 
1993  dropoutpad->Draw();
1994  dropoutpad->cd();
1995  dropoutpad->SetGridx();
1996 
1997  gNFEBDday->SetTitle("");
1998  gNFEBDday->SetMarkerStyle(23);
1999  gNFEBDday->SetMarkerColor(kOrange+7);
2000  gNFEBDday->SetFillColor(kOrange+7);
2001  gNFEBDday->GetYaxis()->SetLabelColor(kOrange+7);
2002  gNFEBDday->GetYaxis()->SetRangeUser(0,10);
2003  gNFEBDday->Draw("APY+");
2004 
2005  UpdateText->Draw();
2006 
2007  dropoutpad->Modified();
2008  dropoutpad->Update();
2009 
2010  TLegend *legc = new TLegend(0.62,0.69,0.87,0.78);
2011  legc->SetFillColor(0);
2012  TLegendEntry *af = legc->AddEntry(gNFEBday,"#bf{Active FEBs}","F");
2013  af->SetTextColor(kBlue);
2014  TLegendEntry *df = legc->AddEntry(gNFEBDday,"#bf{FEB Drop Outs}","F");
2015  df->SetTextColor(kOrange+7);
2016  legc->SetFillStyle(4000);
2017  legc->SetLineColor(0);
2018  legc->Draw();
2019 
2020  sprintf(filename,"%s/%s-%s-P%.1uNDropOutActiveFEBperSR%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
2021  cCombo->Print(filename);
2022  delete cCombo;
2023  delete cNFEBDday;
2024  delete cNFEBday;
2025  cCombo = 0;
2026  cNFEBDday = 0;
2027  cNFEBday = 0;
2028 
2029  // ........................................................................
2030  // Average Trigger and Spill Rates
2031  gTrig00day->SetMarkerColor(kRed);
2032  TCanvas *cTrig = new TCanvas("cTrig", "trig rate day",1200, 800);
2033 
2034  float currentNuMITrigRate = Trig00Day[1][NTrigDayCount[1] - 1];
2035  float currentSpillRate = SpillCountValue[0][NSpillEntryCount[0] - 1];
2036 
2037  //float spillRateThreshold = 0.8;
2038  float triggerRateThreshold = 0.9;
2039  float spillNumiDiffThreshold = 0.05;
2040 
2041  TPad *pad1 = new TPad("pad1","",0,0,1,1);
2042  TPad *pad2 = new TPad("pad2","",0,0,1,1);
2043  TPad *pad3 = new TPad("pad3","",0,0,1,1);
2044  TPad *pad4 = new TPad("pad4","",0,0,1,1);
2045  // Warning: spill rate too high
2046  // NOTE: This is not working right now, so commenting it out.
2047  // Hopefully someone will come back and fix this someday.
2048  //std::cout << "CHECKING FOR HIGH SPILL RATE......";
2049  //if (currentSpillRate > spillRateThreshold){
2050  // std::cout << "BAD" << std::endl;
2051  // pad1->SetFillColor(kRed - 4);
2052  //
2053  // // Email experts
2054  // char cmd[1000];
2055  // char to[1000] = "nova_watchdogs@fnal.gov nova_nearlineonmon_support@fnal.gov jvasel@indiana.edu";
2056  // char subject[1000] = "Nearline--Current spill rate exceeds alarm thresholds";
2057  // char body[1000] = "There may be an issue with the timing system.";
2058  //
2059  // sprintf(cmd, "echo %s | mail -s %s %s", body, subject, to);
2060  // system(cmd);
2061  //}
2062  //else {
2063  // std::cout << "OK" << std::endl;
2064  //}
2065 
2066  // Warning: spill and trigger rate differ
2067  //std::cout << "CHECKING FOR SPILL/TRIGGER RATE MISMATCH......";
2068  //if (std::abs(currentSpillRate - currentNuMITrigRate) > spillNumiDiffThreshold){
2069  // std::cout << "BAD";
2070  // pad1->SetFillColor(kRed - 4);
2071  //
2072  // // Email experts
2073  // char cmd[1000];
2074  // char to[1000] = "nova_watchdogs@fnal.gov nova_nearlineonmon_support@fnal.gov jvasel@indiana.edu";
2075  // char subject[1000] = "Nearline--Current spill rate differs from NuMI trigger rate";
2076  // char body[1000] = "There may be an issue with the spill server.";
2077  //
2078  // sprintf(cmd, "echo %s | mail -s %s %s", body, subject, to);
2079  // system(cmd);
2080  //}
2081  //else {
2082  // std::cout << "OK";
2083  //}
2084  //std::cout << " (SpillRate=" << currentSpillRate << " TrigRate=" << currentNuMITrigRate
2085  // << " Diff=" << std::abs(currentSpillRate - currentNuMITrigRate) << ")" << std::endl;
2086  pad2->SetFillStyle(4000); // pad2 will be transparent
2087  pad2->SetFillColor(0);
2088  pad2->SetFrameFillStyle(4000);
2089  pad3->SetFillStyle(4000); // pad2 will be transparent
2090  pad3->SetFillColor(0);
2091  pad3->SetFrameFillStyle(4000);
2092  pad4->SetFillStyle(4000); // pad2 will be transparent
2093  pad4->SetFillColor(0);
2094  pad4->SetFrameFillStyle(4000);
2095  pad1->Draw();
2096  pad1->cd();
2097  pad1->SetGridx();
2098 
2099  sprintf(title,"Average Trigger and Spill Rates (Hz) - partition %.1u",p);
2100  gTrig00day->SetTitle(title);
2101  gTrig00day->SetMarkerStyle(21);
2102  gTrig00day->SetMarkerColor(kRed+3);
2103  gTrig00day->SetFillColor(kRed+3);
2104  if (t_prd != "Day") gTrig00day->SetMarkerStyle(7);
2105  gTrig00day->GetYaxis()->SetLabelOffset(1);
2106  gTrig00day->GetYaxis()->SetLabelColor(kRed+3);
2107  gTrig00day->GetYaxis()->SetNdivisions(0, kFALSE); // Disable tick marks
2108  gTrig00day->GetYaxis()->SetRangeUser(0,1.1);
2109 
2110  WarningText->Clear();
2111  std::cout << "CHECKING FOR HIGH NUMI TRIGGER RATE......";
2112  std::cout<<"Current NuMI trigger rate = "<<currentNuMITrigRate<<std::endl;
2113  if (currentNuMITrigRate > triggerRateThreshold){
2114  std::cout << "NUMI TRIGGER RATE TOO HIGH" << std::endl;
2115  pad1->SetFillColor(kRed);
2116  sprintf(warntext,"WARNING! NuMI trigger rate too high! Call DAQ expert!");
2117  WarningText->AddText(warntext);
2118  send_spill_email=true;
2119  }
2120  else {
2121  std::cout << "OK" << std::endl;
2122  }
2123  std::cout << " (SpillRate=" << currentSpillRate << " TrigRate=" << currentNuMITrigRate
2124  << " Diff=" << std::abs(currentSpillRate - currentNuMITrigRate) << ")" << std::endl;
2125 
2126  gTrig00day->Draw("AP");
2127  WarningText->Draw();
2128 
2129  pad1->Modified();
2130  pad1->Update();
2131 
2132  pad4->Draw();
2133  pad4->cd();
2134  pad4->SetGridx();
2135 
2136  //pad2->Draw();
2137  //pad2->cd();
2138  //pad2->SetGridx();
2139 
2140  //gBNBSpillCount->SetTitle("");
2141  //gBNBSpillCount->GetYaxis()->SetRangeUser(0,30);
2142  //gBNBSpillCount->GetYaxis()->SetLabelColor(kBlue+3);
2143  //gBNBSpillCount->SetMarkerStyle(34);
2144  //gBNBSpillCount->SetFillColor(kBlue+3);
2145  //gBNBSpillCount->SetMarkerColor(kBlue+3);
2146  //gBNBSpillCount->Draw("AP");
2147 
2148  if(det_type != "NearDet"){
2149  gTrig02day->SetTitle("");
2150  gTrig02day->SetMarkerStyle(21);
2151  if (t_prd != "Day") gTrig02day->SetMarkerStyle(7);
2152  gTrig02day->SetFillColor(kBlue);
2153  gTrig02day->GetYaxis()->SetLabelColor(kBlue);
2154  gTrig02day->GetYaxis()->SetRangeUser(0,30);
2155  gTrig02day->Draw("AP");
2156  }
2157  pad4->Modified();
2158  pad4->Update();
2159 
2160  pad3->Draw();
2161  pad3->cd();
2162  pad3->SetGridx();
2163 
2164  gSpillCount->SetTitle("");
2165  gSpillCount->GetYaxis()->SetRangeUser(0,1.1);
2166  gSpillCount->GetYaxis()->SetLabelColor(kRed);
2167  gSpillCount->SetMarkerStyle(34);
2168  gSpillCount->SetFillColor(kRed);
2169  gSpillCount->SetMarkerColor(kRed);
2170  gSpillCount->Draw("APY+");
2171  UpdateText->Draw();
2172 
2173  pad3->Modified();
2174  pad3->Update();
2175 
2176  TLegend *leg = new TLegend(0.62,0.69,0.87,0.78);
2177  leg->SetFillColor(0);
2178  if(det_type != "NearDet"){
2179  TLegendEntry *l2 = leg->AddEntry(gTrig02day,"#bf{Cosmic Trigger Rate}","F");
2180  l2->SetTextColor(kBlue);
2181  }
2182  // TLegendEntry *l4 = leg->AddEntry(gBNBSpillCount,"#bf{Delivered BNB Spill Rate}","F");
2183  //l4->SetTextColor(kBlue+3);
2184  TLegendEntry *l1 = leg->AddEntry(gTrig00day,"#bf{NuMI Trigger Rate}","F");
2185  l1->SetTextColor(kRed+3);
2186  TLegendEntry *l3 = leg->AddEntry(gSpillCount,"#bf{Delivered NuMI Spill Rate}","F");
2187  l3->SetTextColor(kRed);
2188  leg->SetFillStyle(4000);
2189  leg->SetLineColor(0);
2190  leg->Draw();
2191 
2192  sprintf(filename,"%s/%s-%s-P%.1uCosmicNuMITriggerRate%s.png",PLOT_DIR.c_str(),det.c_str(),trig.c_str(),p,period.c_str());
2193  cTrig->Print(filename);
2194  delete cTrig;
2195  delete cTrig00day;
2196  delete cTrig02day;
2197  delete cSpill;
2198  cSpill=0;
2199  cTrig02day = 0;
2200  cTrig00day = 0;
2201  cTrig = 0;
2202  }
2203 
2204  // If NuMI trigger rate is too high for any partition, send email.
2205  if (send_spill_email) {
2206  char cmd[1000];
2207  char to[1000] = "tlackey@indiana.edu nova_runcoordinator@fnal.gov mcgroh@iu.edu jvasel@iu.edu nova_daq_support@fnal.gov";
2208  char subject[1000] = "NuMI Trigger rate too high.";
2209  char body[1000] = "NuMI Trigger rate is too high. There may be an issue with the spill server.";
2210 
2211  sprintf(cmd, "echo -e \"%s\" | mail -s \"%s\" %s",body,subject,to);
2212  system(cmd);
2213  }
2214 
2215 
2216 }
UInt_t LastSR
Definition: AnaPlotMaker.h:50
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:501
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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
TPad * pad1
Definition: analysis.C:13
static constexpr Double_t year
Definition: Munits.h:185