BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
CheckOefDbAlg.cxx
Go to the documentation of this file.
1#include "EventModel/Event.h"
2#include "EventModel/EventHeader.h"
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include <iomanip>
6#include <iostream>
7
8#include "CheckOefDbAlg.h"
9
10using namespace std;
12CheckOefDbAlg::CheckOefDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
13 : Algorithm(name, pSvcLocator) {
14 declareProperty("Check_etsT1_hist", m_check_etsT1_time_only = 0); // if it is not 0, we will output a .root file named with this runID, and only check the time and etsT1.
15}
16
18 MsgStream log(msgSvc(), name());
19 log << MSG::INFO << "in initialize()" << endmsg;
20
21 StatusCode sc = service("InjSigIntervalSvc", m_InjSigIntervalSvc);
22 if (sc != StatusCode::SUCCESS) {
23 log << MSG::FATAL << "can not use InjSigIntervalSvc" << endmsg;
24 }
25
26 sc = service("InjSigTimeSvc", m_InjSigTimeSvc);
27 if (sc != StatusCode::SUCCESS) {
28 log << MSG::FATAL << "can not use InjSigTimeSvc" << endmsg;
29 }
30
31 sc = service("OfflineEvtFilterSvc", m_evtFilterSvc);
32 if (sc != StatusCode::SUCCESS) {
33 log << MSG::FATAL << "can not use OfflineEvtFilterSvc" << endmsg;
34 }
35 m_lastRun = -1;
36 m_hist_etsT1 = NULL;
37 if (m_check_etsT1_time_only) {
38
39 const int expected_range = 50000;
40
41 m_hist_etsT1 = new TH1D("hist_etsT1", "hist_etsT1", expected_range * 2 + 1, -expected_range - .5, +expected_range + .5);
42
43 cout << "creating new histograms" << endl;
44 }
45 return StatusCode::SUCCESS;
46}
47
49 MsgStream log(msgSvc(), name());
50 //Get EventHeader
51 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(), "/Event/EventHeader");
52 if (!eventHeader) {
53 log << MSG::FATAL << "Could not find Event Header" << endmsg;
54 return StatusCode::FAILURE;
55 }
56 if (m_hist_etsT1){ // fill in the histogram
57 unsigned long time_etsT1 = eventHeader->etsT1();
58 long time_etsT1_timelike32 = ((time_etsT1 / 2000000) & 0x00000000ffffffffLU);
59 // const int expected_range=50000;
60 m_hist_etsT1->Fill(time_etsT1_timelike32);
61 }
62
63 if (m_lastRun == eventHeader->runNumber()) {
64 return StatusCode::SUCCESS;
65 }
66 m_lastRun = eventHeader->runNumber();
67 cout << "==============CheckOefDbAlg: Run " << m_lastRun << "====================" << endl;
68
69 cout << "shielding window" << endl;
70 cout << "RunFrom: " << setw(15) << m_evtFilterSvc->getRunFrom() << endl
71 << "RunTo: " << setw(15) << m_evtFilterSvc->getRunTo() << endl
72 << "EventFrom: " << setw(15) << m_evtFilterSvc->getEventFrom() << endl
73 << "EventTo: " << setw(15) << m_evtFilterSvc->getEventTo() << endl
74 << "shielding window Npar: " << setw(15) << m_evtFilterSvc->getNpar() << endl;
75 int npar = m_evtFilterSvc->getNpar();
76 for (int i = 0; i < npar; i++) {
77 cout << "Flag:" << setw(15) << m_evtFilterSvc->getFlag(i) << endl
78 << "TBegin: " << setw(15) << m_evtFilterSvc->getTBegin(i) << endl
79 << "TEnd: " << setw(15) << m_evtFilterSvc->getTEnd(i) << endl;
80 }
81
82 cout << "injection interval" << endl;
83 cout << "TInterval: " << setw(15) << m_InjSigIntervalSvc->getTInterval() << endl;
84
85 cout << "IST" << endl;
86 cout << "IST Npar: " << setw(15) << m_InjSigTimeSvc->getNpar() << endl;
87 for (int i = 0; i < m_InjSigTimeSvc->getNpar(); i++) {
88 cout << "IST Flag: " << setw(15) << m_InjSigTimeSvc->getFlag(i) << endl
89 << "IST:" << setw(15) << m_InjSigTimeSvc->getIST(i) << endl;
90 }
91 cout << "CheckOefDbAlg: checking OEF, npar=" << npar << endl;
92 for (int i = 0; i < npar; i++) {
93 cout << "CheckOefDbAlg: OEF: flag:tBegin:tEnd = " << m_evtFilterSvc->getFlag(i)
94 << ":" << setw(13) << m_evtFilterSvc->getTBegin(i)
95 << ":" << setw(13) << m_evtFilterSvc->getTEnd(i) << endl;
96 }
97
98 return StatusCode::SUCCESS;
99}
100static std::pair<int, int> get_range_bin(TH1 *hist) {
101 int nbins = hist->GetNbinsX();
102 int first_nonzero_bin = -1;
103 int last_nonzero_bin = nbins + 1;
104 for (int i = 0; i <= nbins + 1; i++) {
105 if (hist->GetBinContent(i) > 0) {
106 first_nonzero_bin = i;
107 break;
108 }
109 }
110 for (int i = nbins + 1; i >= 0; i--) {
111 if (hist->GetBinContent(i) > 0) {
112 last_nonzero_bin = i;
113 break;
114 }
115 }
116 return std::make_pair(first_nonzero_bin, last_nonzero_bin);
117}
118static std::pair<double, double> get_new_range(TH1 *hist, std::pair<int, int> range_bin) {
119 int nbins = hist->GetNbinsX();
120 int new_bin_first = range_bin.first - 5;
121 if (new_bin_first < 0) new_bin_first = 0;
122 int new_bin_last = range_bin.second + 5;
123 if (new_bin_last > nbins + 1) new_bin_last = nbins + 1;
124 return std::make_pair(hist->GetBinCenter(new_bin_first) - .6, hist->GetBinCenter(new_bin_last) + .6);
125}
127 if (m_hist_etsT1) {
128
129 std::stringstream ss;
130 ss << "hists_" << m_lastRun << ".root";
131 cout << "Printing histogram to "<< ss.str().c_str() << endl;
132 // next we try to find the where in the hist is not 0.
133 // we will use this to find the range of the histogram
134
135 std::pair<double, double> range_etsT1_value = get_new_range(m_hist_etsT1, get_range_bin(m_hist_etsT1));
136 m_hist_etsT1->GetXaxis()->SetRangeUser(range_etsT1_value.first, range_etsT1_value.second);
137
138 TFile *f = new TFile(ss.str().c_str(), "recreate");
139 f->cd();
140 m_hist_etsT1->Write();
141 f->Close();
142
143 delete f;
144 delete m_hist_etsT1;
145 }
146 return StatusCode::SUCCESS;
147}
DECLARE_COMPONENT(BesBdkRc)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const int nbins
IMessageSvc * msgSvc()
StatusCode initialize()
StatusCode execute()
StatusCode finalize()
CheckOefDbAlg(const std::string &name, ISvcLocator *pSvcLocator)