BeamTuning_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: BeamTuning
3 // Plugin Type: analyzer (art v2_12_01)
4 // File: BeamTuning_module.cc
5 //
6 // Generated at Tue Jun 18 11:16:43 2019 by Dung Phan using cetskelgen
7 // from cetlib version v3_06_00.
8 ////////////////////////////////////////////////////////////////////////
9 
20 #include "fhiclcpp/ParameterSet.h"
21 
22 // nova
27 #include "BeamlineRecoBase/ToF.h"
29 #include "RawData/RawBeamline.h"
31 
32 // ROOT
33 #include "TCanvas.h"
34 #include "TFile.h"
35 #include "TGraph.h"
36 #include "TH1D.h"
37 #include "TH2D.h"
38 #include "TLatex.h"
39 #include "TLegend.h"
40 #include "TLine.h"
41 #include "TMath.h"
42 #include "TROOT.h"
43 #include "TStyle.h"
44 #include "TTree.h"
45 
46 // stl
47 #include <cstdio>
48 #include <cstdlib>
49 #include <fstream>
50 #include <iomanip>
51 #include <iostream>
52 #include <sstream>
53 #include <string>
54 #include <vector>
55 
56 // Boost
57 #include <boost/algorithm/string.hpp>
58 #include <boost/date_time/posix_time/posix_time.hpp>
59 #include <boost/date_time/time_zone_base.hpp>
60 #include <boost/lexical_cast.hpp>
61 
62 const uint32_t NOVA_EPOCH = 1262304000;
63 const uint64_t NOVA_TIME_FACTOR = 64000000;
64 
65 void rootlogon() {
66  TStyle* novaStyle = new TStyle("novaStyle", "NOvA Style");
67 
68  // Centre title
69  novaStyle->SetTitleAlign(22);
70  novaStyle->SetTitleX(.5);
71  novaStyle->SetTitleY(.95);
72  novaStyle->SetTitleBorderSize(0);
73 
74  // No info box
75  novaStyle->SetOptStat(0);
76 
77  // set the background color to white
78  novaStyle->SetFillColor(10);
79  novaStyle->SetFrameFillColor(10);
80  novaStyle->SetCanvasColor(10);
81  novaStyle->SetPadColor(10);
82  novaStyle->SetTitleFillColor(0);
83  novaStyle->SetStatColor(10);
84 
85  // Don't put a colored frame around the plots
86  novaStyle->SetFrameBorderMode(0);
87  novaStyle->SetCanvasBorderMode(0);
88  novaStyle->SetPadBorderMode(0);
89 
90  // Set the default line color for a fit function to be red
91  novaStyle->SetFuncColor(kRed);
92 
93  // Marker settings
94  // novaStyle->SetMarkerStyle(kFullCircle);
95 
96  // No border on legends
97  novaStyle->SetLegendBorderSize(0);
98 
99  // Axis titles
100  novaStyle->SetTitleSize(.095, "xyz");
101  novaStyle->SetTitleOffset(.8, "xyz");
102  // More space for y-axis to avoid clashing with big numbers
103  novaStyle->SetTitleOffset(.9, "y");
104  // This applies the same settings to the overall plot title
105  novaStyle->SetTitleSize(.055, "");
106  novaStyle->SetTitleOffset(.8, "");
107  // Axis labels (numbering)
108  novaStyle->SetLabelSize(.095, "xyz");
109  novaStyle->SetLabelOffset(.005, "xyz");
110 
111  // Prevent ROOT from occasionally automatically zero-suppressing
112  novaStyle->SetHistMinimumZero();
113 
114  // Thicker lines
115  novaStyle->SetHistLineWidth(2);
116  novaStyle->SetFrameLineWidth(2);
117  novaStyle->SetFuncWidth(2);
118 
119  // Set the number of tick marks to show
120  novaStyle->SetNdivisions(506, "xyz");
121 
122  // Set the tick mark style
123  novaStyle->SetPadTickX(1);
124  novaStyle->SetPadTickY(1);
125 
126  // Fonts
127  const int kNovaFont = 42;
128  novaStyle->SetStatFont(kNovaFont);
129  novaStyle->SetLabelFont(kNovaFont, "xyz");
130  novaStyle->SetTitleFont(kNovaFont, "xyz");
131  novaStyle->SetTitleFont(kNovaFont, ""); // Apply same setting to plot titles
132  novaStyle->SetTextFont(kNovaFont);
133  novaStyle->SetLegendFont(kNovaFont);
134 
135  // Get moodier colours for colz
136  const Int_t NRGBs = 5;
137  const Int_t NCont = 255;
138  Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
139  Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
140  Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
141  Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
142  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
143  novaStyle->SetNumberContours(NCont);
144 
145  gROOT->SetStyle("novaStyle");
146  gROOT->ForceStyle();
147 }
148 
149 namespace novatb {
150 class BeamTuning;
151 }
152 
154  public:
155  explicit BeamTuning(fhicl::ParameterSet const& p);
156  void reconfigure(const fhicl::ParameterSet& p);
157  void analyze(art::Event const& e) override;
158  void beginJob() override;
159  void beginRun(art::Run const& r) override;
160  void beginSubRun(art::SubRun const& sr) override;
161  void endJob() override;
162  void endRun(art::Run const& r) override;
163  void endSubRun(art::SubRun const& sr) override;
164  std::vector<double> findCluster(unsigned int tofIndex);
165  void makeLinesAndTexts(TH1D* histogram, double ymin, double ymax,
166  std::vector<TLine*>& lines,
167  std::vector<TText*>& texts);
168 
169  void findTime(unsigned int subrunNo, int& srH, int& srM);
170  bool convertNovaTimeToUnixTime(uint64_t const& inputNovaTime,
171  struct tm& outputUnixTime);
172  bool convertNovaTimeToUnixTime(uint64_t const& inputNovaTime,
173  struct timeval& outputUnixTime);
174 
175  void decimal2binary(unsigned int decimalNumber, unsigned int* binaryNumber);
176 
177  private:
183 
184  unsigned int runNumber;
185 
187  "WC1IGNOREME", "WC2IGNOREME", "WC3IGNOREME", "WCCOINC",
188  "PAD1", "PAD2", "PAD3", "PAD4",
189  "TOFUS", "SWYDGATE", "MWPCOFF", "DIGBUSY",
190  "WCHDWR", "TOFDS", "TOFPrompt", "TOFSlow"};
191 
192  std::vector<double> startTimeOfHits[12];
193 
194  std::vector<double> tof_p1_p4;
195  std::vector<double> momentum;
196  std::vector<bool> isElectron;
197 
198  unsigned int totalTriggersInSubrun;
199  unsigned int goodTriggersInSubrun;
201 
207 
210  unsigned int _TimeRange;
211  unsigned int _TimeInterval;
212  double _RangeRatio;
213  double _RangeTotal;
214  double _RangeGood;
218 
219  unsigned int countTriggerBit_TOFDS;
220  unsigned int countTriggerBit_TOFUS;
224  unsigned int countTriggerBit_PAD1;
225  unsigned int countTriggerBit_PAD2;
226  unsigned int countTriggerBit_PAD3;
227  unsigned int countTriggerBit_PAD4;
228 
229  std::ofstream TriggerBitCountFile;
230 
232 };
233 
235  reconfigure(p);
236 }
237 
238 void novatb::BeamTuning::decimal2binary(unsigned int decimalNumber,
239  unsigned int* binaryNumber) {
240  for (int index = 31; index >= 0; index--) {
241  unsigned int reference = TMath::Power(2, (int)index);
242  if (decimalNumber >= reference) {
243  *(binaryNumber + index) = 1;
244  decimalNumber = decimalNumber - reference;
245  } else {
246  *(binaryNumber + index) = 0;
247  }
248  }
249 }
250 
252  _ToFInputTag = "cfdhitreco";
253  _WCInputTag = "wctrackreco";
254  _TriggerInputTag = "daq:Trigger";
255  _RawWCInputTag = "daq:WC";
256 
257  _TimeRange = p.get<unsigned int>("time_range");
258  _RangeTotal = p.get<double>("range_total");
259  _RangeGood = p.get<double>("range_good");
260  _RangeRatio = p.get<double>("range_ratio");
261  _TimeInterval = p.get<unsigned int>("time_interval");
262  _DrawLinesAndTimes = p.get<bool>("drawlines");
263  _RequireWCTrack = p.get<bool>("requiretrack");
264  _Require3WCs = p.get<bool>("require3wcs");
265 }
266 
268  _RunStartH = -9999;
269  _RunStartM = -9999;
270 
271  TriggerBitCountFile.open(Form("TriggerBitCountFile.txt"));
273 
274  TriggerBitCountFile << std::setw(15) << "SUBRUN"
275  << " ";
276  ;
277  TriggerBitCountFile << std::setw(15) << "TOFDS"
278  << " ";
279  ;
280  TriggerBitCountFile << std::setw(15) << "TOFUS"
281  << " ";
282  ;
283  TriggerBitCountFile << std::setw(15) << "TOFPrompt"
284  << " ";
285  ;
286  TriggerBitCountFile << std::setw(15) << "TOFSlow"
287  << " ";
288  ;
289  TriggerBitCountFile << std::setw(15) << "WCHDWR"
290  << " ";
291  ;
292  TriggerBitCountFile << std::setw(15) << "PAD1"
293  << " ";
294  ;
295  TriggerBitCountFile << std::setw(15) << "PAD2"
296  << " ";
297  ;
298  TriggerBitCountFile << std::setw(15) << "PAD3"
299  << " ";
300  ;
301  TriggerBitCountFile << std::setw(15) << "PAD4" << std::endl;
302 
304  new TH1D("hGoodTriggerRatio", ";Subrun Number;Ratio of Good Trigger (%)",
305  _TimeRange - 1, 1, _TimeRange);
307  new TH1D("hDecentTriggerRatio", ";Subrun Number;Ratio of Good Triggers (%)",
308  _TimeRange - 1, 1, _TimeRange);
309  hTotalTrigger = new TH1D("hTotalTrigger", ";Subrun Number;Trigger Counts",
310  _TimeRange - 1, 1, _TimeRange);
311  hGoodTrigger = new TH1D("hGoodTrigger", ";Subrun Number;Good Triggers",
312  _TimeRange - 1, 1, _TimeRange);
313  hDecentTrigger = new TH1D("hGoodTrigger", ";Subrun Number;Good Triggers",
314  _TimeRange - 1, 1, _TimeRange);
315 }
316 
318  runNumber = r.id().run();
319 }
320 
325 
335 }
336 
339  std::vector<art::Ptr<brb::BeamlineDigit> > ToFs;
340  if (e.getByLabel(_ToFInputTag, ToFHandle))
341  art::fill_ptr_vector(ToFs, ToFHandle);
342 
344  std::vector<art::Ptr<brb::WCTrack> > WCs;
345  if (e.getByLabel(_WCInputTag, WCHandle)) art::fill_ptr_vector(WCs, WCHandle);
346 
348  std::vector<art::Ptr<rawdata::RawBeamlineTrigger> > Triggers;
349  if (e.getByLabel(_TriggerInputTag, TriggerHandle))
350  art::fill_ptr_vector(Triggers, TriggerHandle);
351 
353  std::vector<art::Ptr<rawdata::RawBeamlineWC> > RawWCs;
354  if (e.getByLabel(_RawWCInputTag, RawWCHandle))
355  art::fill_ptr_vector(RawWCs, RawWCHandle);
356 
357  for (auto trigItr = Triggers.begin(); trigItr != Triggers.end(); trigItr++) {
358  unsigned int pattern = (*trigItr)->Pattern();
359  unsigned int binaryNumber[32];
360  decimal2binary(pattern, &binaryNumber[0]);
361  if (binaryNumber[13] == 1) countTriggerBit_TOFDS++;
362  if (binaryNumber[8] == 1) countTriggerBit_TOFUS++;
363  if (binaryNumber[14] == 1) countTriggerBit_TOFPrompt++;
364  if (binaryNumber[15] == 1) countTriggerBit_TOFSlow++;
365  if (binaryNumber[12] == 1) countTriggerBit_WCHDWR++;
366  if (binaryNumber[4] == 1) countTriggerBit_PAD1++;
367  if (binaryNumber[5] == 1) countTriggerBit_PAD2++;
368  if (binaryNumber[6] == 1) countTriggerBit_PAD3++;
369  if (binaryNumber[7] == 1) countTriggerBit_PAD4++;
370  }
371 
372  if (e.subRun() < 20 && _RunStartH == -9999 && _RunStartM == -9999) {
373  struct tm outputTime;
374  if (Triggers.size() >= 1) {
375  auto TriggerItr = Triggers.begin();
376  uint64_t inputNovaTime = (*TriggerItr)->TDUTime();
377  convertNovaTimeToUnixTime(inputNovaTime, outputTime);
378  }
379  bool hourBack = false;
380  if (outputTime.tm_min < (int)(e.subRun() - 1)) {
381  _RunStartM = outputTime.tm_min - (e.subRun() - 1) + 60;
382  hourBack = true;
383  } else {
384  _RunStartM = outputTime.tm_min - (e.subRun() - 1);
385  }
386  if (hourBack) {
387  _RunStartH = outputTime.tm_hour - 6 > 0 ? outputTime.tm_hour - 6
388  : outputTime.tm_hour - 6 + 24;
389  } else {
390  _RunStartH = outputTime.tm_hour - 5 > 0 ? outputTime.tm_hour - 5
391  : outputTime.tm_hour - 5 + 24;
392  }
393  std::cout << "_RunStartH: " << _RunStartH << std::endl;
394  std::cout << "_RunStartM: " << _RunStartM << std::endl;
395  }
396 
397  for (unsigned int iCh = 0; iCh < 12; iCh++) {
398  startTimeOfHits[iCh].clear();
399  }
400 
401  for (auto TOFitr = ToFs.begin(); TOFitr != ToFs.end(); TOFitr++) {
402  unsigned int channel = fChannelMap->OnlineDigitChannel((*TOFitr)->ChannelID());
403  startTimeOfHits[channel - 4].push_back((*TOFitr)->StartTimeInNanoSec());
404  }
405 
406  std::vector<double> hitStartTOFUS = findCluster(0);
407  std::vector<double> hitStartTOFDS = findCluster(1);
408  int nHitsTOFUS = hitStartTOFUS.size();
409  int nHitsTOFDS = hitStartTOFDS.size();
410 
411  bool passSelectionGoodTrack = false;
412  if (nHitsTOFUS >= 1 && nHitsTOFDS >= 1) passSelectionGoodTrack = true;
413  if (passSelectionGoodTrack) {
414  if (_RequireWCTrack) {
415  if (WCs.size() >= 1) {
417  } // make sure only one and only one track is associated with this
418  // trigger
419  } else {
421  }
422  }
423 
424  unsigned int foundWC[4] = {1, 1, 1, 1} ;
425  for (auto RawWCitr = RawWCs.begin(); RawWCitr != RawWCs.end(); RawWCitr++) {
426  unsigned int wcnumber = (*RawWCitr)->DetectorID().Detector;
427  unsigned int nhitX = ((*RawWCitr)->XPulses()).size();
428  unsigned int nhitY = ((*RawWCitr)->YPulses()).size();
429  if (nhitX == 0 || nhitY == 0) {
430  foundWC[wcnumber] = 0;
431  }
432  }
433  unsigned int numberOfWCsHit = foundWC[0] + foundWC[1] + foundWC[2] + foundWC[3];
434 
435  bool passSelection3WCs = false;
436  if (nHitsTOFUS >= 1 && nHitsTOFDS >= 1) passSelection3WCs = true;
437  if (passSelection3WCs) {
438  if (_Require3WCs) {
439  if (numberOfWCsHit >= 3) {
441  } // make sure only one and only one track is associated with this
442  // trigger
443  } else {
445  }
446  }
447 
449 }
450 
451 std::vector<double> novatb::BeamTuning::findCluster(unsigned int tofIndex) {
452  std::vector<double> hitStartTOF;
453 
454  std::vector<double> TOFGroup[4];
455  if (tofIndex == 0) {
456  for (unsigned int iCh = 8; iCh < 12; iCh++) {
457  for (unsigned int iElem = 0; iElem < startTimeOfHits[iCh - 4].size();
458  iElem++) {
459  TOFGroup[iCh - 8].push_back(startTimeOfHits[iCh - 4].at(iElem));
460  }
461  }
462  } else if (tofIndex == 1) {
463  for (unsigned int iCh = 12; iCh < 16; iCh++) {
464  for (unsigned int iElem = 0; iElem < startTimeOfHits[iCh - 4].size();
465  iElem++) {
466  TOFGroup[iCh - 12].push_back(startTimeOfHits[iCh - 4].at(iElem));
467  }
468  }
469  }
470 
471  for (unsigned int iNS = 0; iNS < 400; iNS++) {
472  double coincWindowStart = (double)iNS;
473  double coincWindowEnd = (double)iNS + 5.;
474 
475  bool coincidence_individual_channel[4];
476  double coincidence_time_individual_channel[4];
477  for (unsigned int iCh = 0; iCh < 4; iCh++) {
478  coincidence_individual_channel[iCh] = false;
479  coincidence_time_individual_channel[iCh] = 0.;
480  }
481 
482  for (unsigned int iCh = 0; iCh < 4; iCh++) {
483  for (unsigned int iElem = 0; iElem < TOFGroup[iCh].size(); iElem++) {
484  if (coincWindowStart < TOFGroup[iCh].at(iElem) &&
485  TOFGroup[iCh].at(iElem) < coincWindowEnd) {
486  coincidence_individual_channel[iCh] = true;
487  coincidence_time_individual_channel[iCh] = TOFGroup[iCh].at(iElem);
488  }
489  }
490  }
491 
492  // check coinciden 3 out of 4 or 4 out of 4
493  bool tof_conic_3in4[4];
494  for (unsigned int iChNegate = 0; iChNegate < 4; iChNegate++) {
495  tof_conic_3in4[iChNegate] = true;
496  for (unsigned int iChCoinc = 0; iChCoinc < 4; iChCoinc++) {
497  if (iChCoinc != iChNegate)
498  tof_conic_3in4[iChNegate] = tof_conic_3in4[iChNegate] &&
499  coincidence_individual_channel[iChCoinc];
500  }
501  }
502  bool tof_conic_4in4 = true;
503  for (unsigned int iChCoinc = 0; iChCoinc < 4; iChCoinc++) {
504  tof_conic_4in4 =
505  tof_conic_4in4 && coincidence_individual_channel[iChCoinc];
506  }
507 
508  bool tof_conic = tof_conic_4in4;
509  for (unsigned int iChNegate = 0; iChNegate < 4; iChNegate++) {
510  tof_conic = tof_conic || tof_conic_3in4[iChNegate];
511  }
512 
513  if (tof_conic) {
514  double sum = 0;
515  for (unsigned int iCh = 0; iCh < 4; iCh++) {
516  sum += coincidence_time_individual_channel[iCh];
517  }
518  if (tof_conic_4in4) {
519  hitStartTOF.push_back(sum / 4.);
520  } else {
521  hitStartTOF.push_back(sum / 3.);
522  }
523  iNS = (unsigned int)coincWindowEnd;
524  } else
525  continue;
526  } // loop over 400ns step of 1ns
527 
528  return hitStartTOF;
529 }
530 
531 void novatb::BeamTuning::findTime(unsigned int subrunNo, int& srH, int& srM) {
532  srM = _RunStartM + subrunNo - 1;
533  // std::cout << "srM: " << srM << std::endl;
534  int hourAdded = (int)srM / 60;
535  // std::cout << "hourAdded: " << hourAdded << std::endl;
536  srM = srM % 60;
537  // std::cout << "srM: " << srM << std::endl;
538  srH = _RunStartH + hourAdded;
539  // std::cout << "srH: " << srH << std::endl;
540 }
541 
543  // std::cout << "totalTriggersInSubrun: " << totalTriggersInSubrun << std::endl;
544  // std::cout << "goodTriggersInSubrun: " << goodTriggersInSubrun << std::endl;
545  // std::cout << "sr.subRun(): " << sr.subRun() << std::endl;
546  hGoodTriggerRatio->SetBinContent(
547  (unsigned int)sr.subRun(),
548  100. * ((double)goodTriggersInSubrun) / ((double)totalTriggersInSubrun));
549  hDecentTriggerRatio->SetBinContent(
550  (unsigned int)sr.subRun(),
551  100. * ((double)decentTriggersInSubrun) / ((double)totalTriggersInSubrun));
552  hTotalTrigger->SetBinContent((unsigned int)sr.subRun(),
553  (double)totalTriggersInSubrun);
554  hGoodTrigger->SetBinContent((unsigned int)sr.subRun(),
555  (double)goodTriggersInSubrun);
556  hDecentTrigger->SetBinContent((unsigned int)sr.subRun(),
557  (double)decentTriggersInSubrun);
558 
559  TriggerBitCountFile << std::setw(15) << sr.id().subRun() << " ";
560  TriggerBitCountFile << std::setw(15) << countTriggerBit_TOFDS << " ";
561  TriggerBitCountFile << std::setw(15) << countTriggerBit_TOFUS << " ";
562  TriggerBitCountFile << std::setw(15) << countTriggerBit_TOFPrompt << " ";
563  TriggerBitCountFile << std::setw(15) << countTriggerBit_TOFSlow << " ";
564  TriggerBitCountFile << std::setw(15) << countTriggerBit_WCHDWR << " ";
565  TriggerBitCountFile << std::setw(15) << countTriggerBit_PAD1 << " ";
566  TriggerBitCountFile << std::setw(15) << countTriggerBit_PAD2 << " ";
567  TriggerBitCountFile << std::setw(15) << countTriggerBit_PAD3 << " ";
568  TriggerBitCountFile << std::setw(15) << countTriggerBit_PAD4 << std::endl;
569 }
570 
572 
574  uint64_t const& inputNovaTime, struct tm& outputUnixTime) {
575  timeval outputTimeval;
576  if (!convertNovaTimeToUnixTime(inputNovaTime, outputTimeval)) return false;
577  outputUnixTime = *gmtime(&(outputTimeval.tv_sec));
578 
579  return true;
580 }
581 
583  uint64_t const& inputNovaTime, struct timeval& outputUnixTime) {
584  double doubleTime = (double)inputNovaTime / (double)NOVA_TIME_FACTOR;
585  time_t time_sec = (time_t)doubleTime;
586  outputUnixTime.tv_sec = NOVA_EPOCH + time_sec;
587  outputUnixTime.tv_usec =
588  (suseconds_t)((doubleTime - (double)time_sec) * 1000000);
589  // test in chrono order
590  if (outputUnixTime.tv_sec > 1341100799) // Jun 30 23:59:59 2012 UTC
591  {
592  --outputUnixTime.tv_sec;
593  }
594  if (outputUnixTime.tv_sec > 1435708799) // Jun 30 23:59:59 2015 UTC
595  {
596  --outputUnixTime.tv_sec;
597  }
598 
599  if (outputUnixTime.tv_sec > 1483228799) // Dec 31 23:59:59 2016 UTC
600  {
601  --outputUnixTime.tv_sec;
602  }
603  return true;
604 }
605 
607  double ymax,
608  std::vector<TLine*>& lines,
609  std::vector<TText*>& texts) {
610  for (int i = 2; i < histogram->GetSize() - 2; i++) {
611  std::string leadingZeroSr;
612  std::string leadingZeroSrH;
613  std::string leadingZeroSrM;
614 
615  int srH;
616  int srM;
617  int subrunno = (int)(histogram->GetBinCenter(i) - 0.4);
618  if (subrunno % _TimeInterval == 0) {
619  findTime(subrunno, srH, srM);
620 
621  std::stringstream ss;
622  ss << subrunno;
623  leadingZeroSr = ss.str();
624  if (subrunno < 10) {
625  leadingZeroSr = "00" + leadingZeroSr;
626  } else if (subrunno < 100) {
627  leadingZeroSr = "0" + leadingZeroSr;
628  }
629 
630  std::stringstream ssh;
631  ssh << srH;
632  leadingZeroSrH = ssh.str();
633  if (srH < 10) {
634  leadingZeroSrH = "0" + leadingZeroSrH;
635  }
636 
637  std::stringstream ssm;
638  ssm << srM;
639  leadingZeroSrM = ssm.str();
640  if (srM < 10) {
641  leadingZeroSrM = "0" + leadingZeroSrM;
642  }
643 
644  TLine* newLine = new TLine((double)i, ymin, (double)i, ymax);
645  lines.push_back(newLine);
646  TText* newText = new TText(
647  (double)subrunno - 0.8, ymin + 0.6 * (ymax - ymin),
648  Form("%s:%s", leadingZeroSrH.c_str(), leadingZeroSrM.c_str()));
649  texts.push_back(newText);
650  }
651  }
652 }
653 
655  // rootlogon();
656  gStyle->SetOptStat(0);
657 
658  TCanvas* c = new TCanvas("c", "c", 3600, 2400);
659  c->Divide(1, 2);
660  hGoodTriggerRatio->SetLineWidth(1);
661  hGoodTriggerRatio->SetLineColor(kRed);
662  hDecentTriggerRatio->SetLineWidth(1);
663  hDecentTriggerRatio->SetLineColor(kBlue);
664  hTotalTrigger->SetLineWidth(1);
665  hTotalTrigger->SetLineColor(kBlack);
666  hGoodTrigger->SetLineWidth(1);
667  hGoodTrigger->SetLineColor(kRed);
668  hDecentTrigger->SetLineWidth(1);
669  hDecentTrigger->SetLineColor(kBlue);
670 
671  _RangeRatio = hDecentTriggerRatio->GetBinContent(hDecentTriggerRatio->GetMaximumBin());
672  _RangeTotal = hTotalTrigger->GetBinContent(hTotalTrigger->GetMaximumBin());
673  _RangeGood = hDecentTrigger->GetBinContent(hDecentTrigger->GetMaximumBin());
674 
675  _RangeRatio = _RangeRatio * 1.2;
676  _RangeTotal = _RangeTotal * 1.2;
677  _RangeGood = _RangeGood * 1.2;
678 
679  hDecentTriggerRatio->GetYaxis()->SetRangeUser(0, _RangeRatio);
680  hTotalTrigger->GetYaxis()->SetRangeUser(0, _RangeTotal);
681  hDecentTrigger->GetYaxis()->SetRangeUser(0, _RangeGood);
682 
683  hGoodTriggerRatio->GetXaxis()->CenterTitle();
684  hDecentTriggerRatio->GetXaxis()->CenterTitle();
685  hTotalTrigger->GetXaxis()->CenterTitle();
686  hGoodTrigger->GetXaxis()->CenterTitle();
687  hDecentTrigger->GetXaxis()->CenterTitle();
688 
689  c->cd(1);
690  TLegend* leg_ratio = new TLegend(0.75, 0.75, 0.95, 0.95);
691  leg_ratio->AddEntry(hDecentTriggerRatio, "TOF & atleast 3WCs", "l");
692  leg_ratio->AddEntry(hGoodTriggerRatio, "TOF & Track (4WCs)", "l");
693  hDecentTriggerRatio->Draw();
694  hGoodTriggerRatio->Draw("SAME");
695  leg_ratio->Draw();
696  std::vector<TLine*> ratiolines;
697  std::vector<TText*> ratiotexts;
698  makeLinesAndTexts(hDecentTriggerRatio, 0, _RangeRatio, ratiolines, ratiotexts);
699  if (_DrawLinesAndTimes) {
700  for (unsigned int k = 0; k < ratiolines.size(); k++) {
701  ratiolines.at(k)->SetLineStyle(kDashed);
702  ratiolines.at(k)->Draw();
703  ratiotexts.at(k)->SetTextAngle(90);
704  ratiotexts.at(k)->Draw();
705  }
706  }
707 
708  c->cd(2);
709  TLegend* leg = new TLegend(0.75, 0.70, 0.95, 0.95);
710  leg->AddEntry(hTotalTrigger, "All triggers", "l");
711  leg->AddEntry(hDecentTrigger, "TOF & atleast 3WCs", "l");
712  leg->AddEntry(hGoodTrigger, "TOF & Track (4WCs)", "l");
713  hTotalTrigger->Draw();
714  hGoodTrigger->Draw("SAME");
715  hDecentTrigger->Draw("SAME");
716  leg->Draw();
717  std::vector<TLine*> totallines;
718  std::vector<TText*> totaltexts;
719  makeLinesAndTexts(hTotalTrigger, 0, _RangeTotal, totallines, totaltexts);
720  if (_DrawLinesAndTimes) {
721  for (unsigned int k = 0; k < totallines.size(); k++) {
722  totallines.at(k)->SetLineStyle(kDashed);
723  totallines.at(k)->Draw();
724  totaltexts.at(k)->SetTextAngle(90);
725  totaltexts.at(k)->Draw();
726  }
727  }
728 
729  c->SaveAs(Form("tune_run_%i.pdf", (int)runNumber));
730 
731  TriggerBitCountFile.close();
732 }
733 
std::ofstream TriggerBitCountFile
std::vector< double > startTimeOfHits[12]
SubRunNumber_t subRun() const
Definition: Event.h:72
enum BeamMode kRed
unsigned int countTriggerBit_PAD2
SubRunNumber_t subRun() const
Definition: SubRun.h:44
void beginSubRun(art::SubRun const &sr) override
const uint64_t NOVA_TIME_FACTOR
art::InputTag _WCInputTag
const char * p
Definition: xmltok.h:285
const uint32_t NOVA_EPOCH
Float_t ss
Definition: plot.C:24
BeamTuning(fhicl::ParameterSet const &p)
DEFINE_ART_MODULE(TestTMapFile)
void reconfigure(const fhicl::ParameterSet &p)
RunNumber_t run() const
Definition: RunID.h:62
std::vector< double > momentum
unsigned int OnlineDigitChannel(ChannelID channel) const
Online digiziter channel number for this offline ChannelID.
unsigned int _TimeInterval
Definition: Run.h:31
std::vector< bool > isElectron
art::InputTag _RawWCInputTag
Double_t ymax
Definition: plot.C:25
unsigned int countTriggerBit_TOFDS
void analyze(art::Event const &e) override
art::InputTag _CherenkovInputTag
unsigned int countTriggerBit_PAD1
unsigned int goodTriggersInSubrun
Encapsulation of reconstructed digitizer &#39;hits&#39;. Used for ToF PMTs and SiPMs, and Cherenkov and Muon ...
std::string TriggerBitName[16]
void findTime(unsigned int subrunNo, int &srH, int &srM)
tuple blue
Definition: rootlogon.py:65
int NRGBs
Definition: rootlogon.py:77
art::InputTag _TriggerInputTag
RunID const & id() const
Definition: Run.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
Encapsulation of reconstructed Time-of-Flight (ToF) information. Part of beamline reconstruction for ...
std::vector< double > tof_p1_p4
unsigned int countTriggerBit_TOFSlow
int NCont
Definition: rootlogon.py:78
Encapsulation of reconstructed Wire Chamber track. Part of beamline reconstruction for NOvA test beam...
caf::StandardRecord * sr
void decimal2binary(unsigned int decimalNumber, unsigned int *binaryNumber)
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
unsigned int decentTriggersInSubrun
std::vector< double > findCluster(unsigned int tofIndex)
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct tm &outputUnixTime)
OStream cout
Definition: OStream.cxx:6
unsigned int countTriggerBit_PAD4
unsigned int totalTriggersInSubrun
unsigned int countTriggerBit_WCHDWR
void endJob() override
void makeLinesAndTexts(TH1D *histogram, double ymin, double ymax, std::vector< TLine * > &lines, std::vector< TText * > &texts)
void beginRun(art::Run const &r) override
unsigned int countTriggerBit_TOFPrompt
art::ServiceHandle< beamlineutil::BeamlineChannelMap > fChannelMap
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void rootlogon()
void beginJob() override
SubRunID id() const
Definition: SubRun.h:54
TRandom3 r(0)
Double_t ymin
Definition: plot.C:24
Raw data definitions for beamline data used in NOvA test beam experiment.
void endSubRun(art::SubRun const &sr) override
SubRunNumber_t subRun() const
Definition: SubRunID.h:89
unsigned int countTriggerBit_TOFUS
void endRun(art::Run const &r) override
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Double_t sum
Definition: plot.C:31
Encapsulation of reconstructed PID information from detectors in the beamline (ToF, WCs, Cherenkov). Part of beamline reconstruction for NOvA test beam.
Float_t e
Definition: plot.C:35
enum BeamMode kBlue
unsigned int countTriggerBit_PAD3
Channel mapping service which may be used to interpret the channels which are read out by the various...
int kNovaFont
Definition: rootlogon.py:68
Encapsulation of reconstructed track in the muon stack downstream of test beam detector. Part of beamline reconstruction for NOvA test beam.
art::InputTag _ToFInputTag
enum BeamMode string