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> 66 TStyle*
novaStyle =
new TStyle(
"novaStyle",
"NOvA Style");
69 novaStyle->SetTitleAlign(22);
70 novaStyle->SetTitleX(.5);
71 novaStyle->SetTitleY(.95);
72 novaStyle->SetTitleBorderSize(0);
75 novaStyle->SetOptStat(0);
78 novaStyle->SetFillColor(10);
79 novaStyle->SetFrameFillColor(10);
80 novaStyle->SetCanvasColor(10);
81 novaStyle->SetPadColor(10);
82 novaStyle->SetTitleFillColor(0);
83 novaStyle->SetStatColor(10);
86 novaStyle->SetFrameBorderMode(0);
87 novaStyle->SetCanvasBorderMode(0);
88 novaStyle->SetPadBorderMode(0);
91 novaStyle->SetFuncColor(
kRed);
97 novaStyle->SetLegendBorderSize(0);
100 novaStyle->SetTitleSize(.095,
"xyz");
101 novaStyle->SetTitleOffset(.8,
"xyz");
103 novaStyle->SetTitleOffset(.9,
"y");
105 novaStyle->SetTitleSize(.055,
"");
106 novaStyle->SetTitleOffset(.8,
"");
108 novaStyle->SetLabelSize(.095,
"xyz");
109 novaStyle->SetLabelOffset(.005,
"xyz");
112 novaStyle->SetHistMinimumZero();
115 novaStyle->SetHistLineWidth(2);
116 novaStyle->SetFrameLineWidth(2);
117 novaStyle->SetFuncWidth(2);
120 novaStyle->SetNdivisions(506,
"xyz");
123 novaStyle->SetPadTickX(1);
124 novaStyle->SetPadTickY(1);
128 novaStyle->SetStatFont(kNovaFont);
129 novaStyle->SetLabelFont(kNovaFont,
"xyz");
130 novaStyle->SetTitleFont(kNovaFont,
"xyz");
131 novaStyle->SetTitleFont(kNovaFont,
"");
132 novaStyle->SetTextFont(kNovaFont);
133 novaStyle->SetLegendFont(kNovaFont);
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);
145 gROOT->SetStyle(
"novaStyle");
164 std::vector<double>
findCluster(
unsigned int tofIndex);
166 std::vector<TLine*>&
lines,
167 std::vector<TText*>&
texts);
169 void findTime(
unsigned int subrunNo,
int& srH,
int& srM);
171 struct tm& outputUnixTime);
173 struct timeval& outputUnixTime);
175 void decimal2binary(
unsigned int decimalNumber,
unsigned int* binaryNumber);
187 "WC1IGNOREME",
"WC2IGNOREME",
"WC3IGNOREME",
"WCCOINC",
188 "PAD1",
"PAD2",
"PAD3",
"PAD4",
189 "TOFUS",
"SWYDGATE",
"MWPCOFF",
"DIGBUSY",
190 "WCHDWR",
"TOFDS",
"TOFPrompt",
"TOFSlow"};
239 unsigned int* binaryNumber) {
241 unsigned int reference = TMath::Power(2, (
int)
index);
242 if (decimalNumber >= reference) {
243 *(binaryNumber +
index) = 1;
244 decimalNumber = decimalNumber - reference;
246 *(binaryNumber +
index) = 0;
304 new TH1D(
"hGoodTriggerRatio",
";Subrun Number;Ratio of Good Trigger (%)",
307 new TH1D(
"hDecentTriggerRatio",
";Subrun Number;Ratio of Good Triggers (%)",
309 hTotalTrigger =
new TH1D(
"hTotalTrigger",
";Subrun Number;Trigger Counts",
311 hGoodTrigger =
new TH1D(
"hGoodTrigger",
";Subrun Number;Good Triggers",
313 hDecentTrigger =
new TH1D(
"hGoodTrigger",
";Subrun Number;Good Triggers",
339 std::vector<art::Ptr<brb::BeamlineDigit> > ToFs;
344 std::vector<art::Ptr<brb::WCTrack> > WCs;
348 std::vector<art::Ptr<rawdata::RawBeamlineTrigger> > Triggers;
353 std::vector<art::Ptr<rawdata::RawBeamlineWC> > RawWCs;
357 for (
auto trigItr = Triggers.begin(); trigItr != Triggers.end(); trigItr++) {
358 unsigned int pattern = (*trigItr)->Pattern();
359 unsigned int binaryNumber[32];
373 struct tm outputTime;
374 if (Triggers.size() >= 1) {
375 auto TriggerItr = Triggers.begin();
376 uint64_t inputNovaTime = (*TriggerItr)->TDUTime();
379 bool hourBack =
false;
380 if (outputTime.tm_min < (
int)(e.
subRun() - 1)) {
387 _RunStartH = outputTime.tm_hour - 6 > 0 ? outputTime.tm_hour - 6
388 : outputTime.tm_hour - 6 + 24;
390 _RunStartH = outputTime.tm_hour - 5 > 0 ? outputTime.tm_hour - 5
391 : outputTime.tm_hour - 5 + 24;
397 for (
unsigned int iCh = 0; iCh < 12; iCh++) {
401 for (
auto TOFitr = ToFs.begin(); TOFitr != ToFs.end(); TOFitr++) {
403 startTimeOfHits[channel - 4].push_back((*TOFitr)->StartTimeInNanoSec());
406 std::vector<double> hitStartTOFUS =
findCluster(0);
407 std::vector<double> hitStartTOFDS =
findCluster(1);
408 int nHitsTOFUS = hitStartTOFUS.size();
409 int nHitsTOFDS = hitStartTOFDS.size();
411 bool passSelectionGoodTrack =
false;
412 if (nHitsTOFUS >= 1 && nHitsTOFDS >= 1) passSelectionGoodTrack =
true;
413 if (passSelectionGoodTrack) {
415 if (WCs.size() >= 1) {
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;
433 unsigned int numberOfWCsHit = foundWC[0] + foundWC[1] + foundWC[2] + foundWC[3];
435 bool passSelection3WCs =
false;
436 if (nHitsTOFUS >= 1 && nHitsTOFDS >= 1) passSelection3WCs =
true;
437 if (passSelection3WCs) {
439 if (numberOfWCsHit >= 3) {
452 std::vector<double> hitStartTOF;
454 std::vector<double> TOFGroup[4];
456 for (
unsigned int iCh = 8; iCh < 12; iCh++) {
462 }
else if (tofIndex == 1) {
463 for (
unsigned int iCh = 12; iCh < 16; iCh++) {
471 for (
unsigned int iNS = 0; iNS < 400; iNS++) {
472 double coincWindowStart = (double)iNS;
473 double coincWindowEnd = (double)iNS + 5.;
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.;
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);
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];
502 bool tof_conic_4in4 =
true;
503 for (
unsigned int iChCoinc = 0; iChCoinc < 4; iChCoinc++) {
505 tof_conic_4in4 && coincidence_individual_channel[iChCoinc];
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];
515 for (
unsigned int iCh = 0; iCh < 4; iCh++) {
516 sum += coincidence_time_individual_channel[iCh];
518 if (tof_conic_4in4) {
519 hitStartTOF.push_back(sum / 4.);
521 hitStartTOF.push_back(sum / 3.);
523 iNS = (
unsigned int)coincWindowEnd;
534 int hourAdded = (
int)srM / 60;
547 (
unsigned int)sr.
subRun(),
550 (
unsigned int)sr.
subRun(),
553 (double)totalTriggersInSubrun);
574 uint64_t
const& inputNovaTime,
struct tm& outputUnixTime) {
575 timeval outputTimeval;
577 outputUnixTime = *gmtime(&(outputTimeval.tv_sec));
583 uint64_t
const& inputNovaTime,
struct timeval& outputUnixTime) {
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);
590 if (outputUnixTime.tv_sec > 1341100799)
592 --outputUnixTime.tv_sec;
594 if (outputUnixTime.tv_sec > 1435708799)
596 --outputUnixTime.tv_sec;
599 if (outputUnixTime.tv_sec > 1483228799)
601 --outputUnixTime.tv_sec;
608 std::vector<TLine*>&
lines,
609 std::vector<TText*>&
texts) {
610 for (
int i = 2;
i < histogram->GetSize() - 2;
i++) {
617 int subrunno = (
int)(histogram->GetBinCenter(
i) - 0.4);
621 std::stringstream
ss;
623 leadingZeroSr = ss.str();
625 leadingZeroSr =
"00" + leadingZeroSr;
626 }
else if (subrunno < 100) {
627 leadingZeroSr =
"0" + leadingZeroSr;
630 std::stringstream ssh;
632 leadingZeroSrH = ssh.str();
634 leadingZeroSrH =
"0" + leadingZeroSrH;
637 std::stringstream ssm;
639 leadingZeroSrM = ssm.str();
641 leadingZeroSrM =
"0" + leadingZeroSrM;
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);
656 gStyle->SetOptStat(0);
658 TCanvas*
c =
new TCanvas(
"c",
"c", 3600, 2400);
690 TLegend* leg_ratio =
new TLegend(0.75, 0.75, 0.95, 0.95);
696 std::vector<TLine*> ratiolines;
697 std::vector<TText*> ratiotexts;
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();
709 TLegend*
leg =
new TLegend(0.75, 0.70, 0.95, 0.95);
717 std::vector<TLine*> totallines;
718 std::vector<TText*> totaltexts;
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();
729 c->SaveAs(Form(
"tune_run_%i.pdf", (
int)
runNumber));
std::ofstream TriggerBitCountFile
std::vector< double > startTimeOfHits[12]
SubRunNumber_t subRun() const
unsigned int countTriggerBit_PAD2
SubRunNumber_t subRun() const
void beginSubRun(art::SubRun const &sr) override
const uint64_t NOVA_TIME_FACTOR
art::InputTag _WCInputTag
const uint32_t NOVA_EPOCH
BeamTuning(fhicl::ParameterSet const &p)
DEFINE_ART_MODULE(TestTMapFile)
void reconfigure(const fhicl::ParameterSet &p)
std::vector< double > momentum
unsigned int OnlineDigitChannel(ChannelID channel) const
Online digiziter channel number for this offline ChannelID.
unsigned int _TimeInterval
std::vector< bool > isElectron
art::InputTag _RawWCInputTag
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 'hits'. Used for ToF PMTs and SiPMs, and Cherenkov and Muon ...
std::string TriggerBitName[16]
void findTime(unsigned int subrunNo, int &srH, int &srM)
art::InputTag _TriggerInputTag
T get(std::string const &key) const
Encapsulation of reconstructed Time-of-Flight (ToF) information. Part of beamline reconstruction for ...
std::vector< double > tof_p1_p4
unsigned int countTriggerBit_TOFSlow
TH1D * hDecentTriggerRatio
Encapsulation of reconstructed Wire Chamber track. Part of beamline reconstruction for NOvA test beam...
void decimal2binary(unsigned int decimalNumber, unsigned int *binaryNumber)
EDAnalyzer(Table< Config > const &config)
unsigned int decentTriggersInSubrun
std::vector< double > findCluster(unsigned int tofIndex)
bool convertNovaTimeToUnixTime(uint64_t const &inputNovaTime, struct tm &outputUnixTime)
unsigned int countTriggerBit_PAD4
unsigned int totalTriggersInSubrun
unsigned int countTriggerBit_WCHDWR
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
Raw data definitions for beamline data used in NOvA test beam experiment.
void endSubRun(art::SubRun const &sr) override
SubRunNumber_t subRun() const
unsigned int countTriggerBit_TOFUS
void endRun(art::Run const &r) override
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Encapsulation of reconstructed PID information from detectors in the beamline (ToF, WCs, Cherenkov). Part of beamline reconstruction for NOvA test beam.
unsigned int countTriggerBit_PAD3
Channel mapping service which may be used to interpret the channels which are read out by the various...
Encapsulation of reconstructed track in the muon stack downstream of test beam detector. Part of beamline reconstruction for NOvA test beam.
art::InputTag _ToFInputTag