BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
ResetEtsAlg.cxx
Go to the documentation of this file.
1#include <iomanip>
2#include <typeinfo>
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/SmartDataPtr.h"
5
9#include <fstream>
10#include <algorithm>
11
12
13using namespace std;
14
15DECLARE_COMPONENT(ResetEtsAlg)
16ResetEtsAlg::ResetEtsAlg(const std::string& name, ISvcLocator* pSvcLocator)
17: Algorithm(name, pSvcLocator),
18 m_run(-1),
19 m_count(0),
20 m_alreadyInDB(false),
21 m_curIndex(0)
22{
23 declareProperty("dump", m_dump = false);
24 declareProperty("ReadInjSigIntervalFromDB", m_readInjSigIntervalFromDB = true);
25 declareProperty("ReadInjSigTimeFromDB", m_readInjSigTimeFromDB = true);
26 declareProperty("InjSigInterval", m_interval=60);
27 declareProperty("RunListFile", m_runListFile);
28 m_printInterval = true;
29}
30
32{
33 MsgStream log(msgSvc(), name());
34
35 StatusCode sc = service("CalibDataSvc", m_calibDataSvc);
36 if ( sc.isFailure() ) {
37 log << MSG::FATAL << "can not get CalibDataSvc" << endreq;
38 return StatusCode::FAILURE;
39 }
40
41 sc = service("InjSigIntervalSvc", m_InjSigIntervalSvc);
42 if( sc != StatusCode::SUCCESS ){
43 log << MSG::FATAL << "can not use InjSigIntervalSvc" << endreq;
44 }
45
46 sc = service("InjSigTimeSvc", m_InjSigTimeSvc);
47 if( sc != StatusCode::SUCCESS ){
48 log << MSG::FATAL << "can not use InjSigTimeSvc" << endreq;
49 }
50
51 if ( ! m_runListFile.empty() ) {
52 int runNo;
53 std::ifstream ifs(m_runListFile.c_str());
54 ifs >> runNo;
55 while ( ifs.good() ) {
56 m_runList.push_back(runNo);
57 ifs >> runNo;
58 }
59 m_fixer = NULL;
60 }
61 else {
62 m_fixer = new EtsFixing();
63 }
64
65 return StatusCode::SUCCESS;
66}
67
69{
70 MsgStream log(msgSvc(), name());
71
72 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
73
74 //the corrected ETS is pre-processed
75 if ( m_fixer == NULL ) {
76 //first event
77 if ( m_run == -1 ) {
78 m_run = eventHeader->runNumber();
79 if ( std::find(m_runList.begin(), m_runList.end(), m_run) != m_runList.end() ) {
80 SmartDataPtr<CalibData::CorrectedETSCal> calConst(m_calibDataSvc, "/Calib/CorrectedETS");
81 if( calConst ) {
82 m_alreadyInDB = true;
83 }
84 else {
85 log << MSG::FATAL << "no result in DB for run " << m_run << endreq;
86 return StatusCode::FAILURE;
87 }
88 }
89 }
90
91 //use corrected ETS in database if available
92 if ( m_alreadyInDB ) {
93 if ( m_run != eventHeader->runNumber() ) {
94 log << MSG::FATAL << "crossed runs are not supported" << endreq;
95 return StatusCode::FAILURE;
96 }
97
98 SmartDataPtr<CalibData::CorrectedETSCal> calConst(m_calibDataSvc, "/Calib/CorrectedETS");
99
100 if ( m_count >= calConst->getNpar() || eventHeader->eventNumber() != calConst->getEvt(m_count) ) {
101 log << MSG::FATAL << "only 1 input file is supported" << endreq;
102 return StatusCode::FAILURE;
103 }
104
105 eventHeader->setRawEtsT1( eventHeader->etsT1() );
106 eventHeader->setEtsT1( calConst->getEts1(m_count) );
107 eventHeader->setEtsT2( calConst->getEts2_pre(m_count) );
108 eventHeader->setEtsFlag( calConst->getFlag_pre(m_count) );
109
110 ++m_count;
111
112 return StatusCode::SUCCESS;
113 }
114 /// else: a good run
115 /// no need to correct ETS, and IST will be reset later
116 }
117 else {
118 /// no pre-processed result is available, and then calculate ETS on the fly ...
119 m_fixer->fixT1(eventHeader);
120 }
121
122
123 /// reset IST and the flag...
124
125 if(m_readInjSigTimeFromDB){
126 int Npar = m_InjSigTimeSvc-> getNpar();
127 for(int i=0; i<Npar; i++){
128 int flag = m_InjSigTimeSvc-> getFlag(i);
129 ULong64_t time = m_InjSigTimeSvc-> getIST(i);
130 m_vecFlag.push_back(flag);
131 m_vecTime.push_back(time);
132 if(m_dump){
133 std::cout<<"flag: "<<flag<< " time: "<<time<<std::endl;
134 }
135 }
136 m_readInjSigTimeFromDB = false;
137 }
138
139 if(m_readInjSigIntervalFromDB){
140 m_interval = double(m_InjSigIntervalSvc->getTInterval());
141 m_readInjSigIntervalFromDB = false;
142 }
143
144 if(m_printInterval){
145 cout << "ResetEts::execute() m_interval = " << m_interval << endl;
146 m_printInterval = false;
147 }
148
149 unsigned long t1 = eventHeader->etsT1(); //500ns
150 unsigned long t2 = eventHeader->etsT2(); //500ns
151
152 if ( m_dump ) {
153
154 std::cout<<"raw data"<<std::endl<< "Event: " << eventHeader->eventNumber()
155 << " run: " << eventHeader->runNumber()
156 << " time: " << eventHeader->time()
157 << " ETS_old: " << t1
158 << " IST_old: " << t2
159 << std::endl;
160 }
161
162 int unit = 2000;
163 double size = m_interval*unit;
164 unsigned long ets2_pre = 0;
165 int flag_pre = 0;
166
167
168 int vec_size = m_vecTime.size();
169 for(int i=m_curIndex;i<vec_size;i++)
170 {
171 if (t1 < m_vecTime[i])
172 {
173 if(i==0){
174 flag_pre = m_vecFlag[i];
175 ets2_pre = m_vecTime[i];
176 m_curIndex = i;
177 break;
178 }
179 else{
180
181 double delta= ((double)m_vecTime[i-1]-(double)t1)/size;
182
183 if(delta>0 && t1!=0)
184 {
185 int num = ceil(delta);
186 i = i-num-1;
187 if(i<0){
188 i=-1; //for protect
189 }
190 continue;
191 }
192 else{
193 ets2_pre = m_vecTime[i-1];
194 flag_pre = m_vecFlag[i-1];
195 m_curIndex = i;
196 break;
197 }
198 }
199 }
200 else if (t1 >= m_vecTime[vec_size-1]){
201 flag_pre = m_vecFlag[vec_size-1];
202 ets2_pre = m_vecTime[vec_size-1];
203 break;
204
205 }
206 }
207
208 //eventHeader->setEtsT1(t1);
209 eventHeader->setEtsT2(ets2_pre);
210 eventHeader->setEtsFlag(flag_pre);
211
212 if ( m_dump ) {
213
214 std::cout<<"ReSetETSAlg"<<std::endl<< "Event: " << eventHeader->eventNumber()
215 << " run: " << eventHeader->runNumber()
216 << " time: " << eventHeader->time()
217 << " ETS_new: " << eventHeader->etsT1()
218 << " IST_new: " << eventHeader->etsT2()
219 << " flag_pre: " << eventHeader->etsFlag()
220 << std::endl;
221 }
222
223
224 return StatusCode::SUCCESS;
225}
226
228{
229 if ( m_fixer != NULL ) {
230 delete m_fixer;
231 }
232
233 return StatusCode::SUCCESS;
234}
const double delta
int runNo
Definition DQA_TO_DB.cxx:12
Double_t time
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
Definition FoamA.h:90
IMessageSvc * msgSvc()
#define NULL
void fixT1(Event::EventHeader *header)
Definition EtsFixing.cxx:91
virtual int getTInterval() const =0
StatusCode initialize()
StatusCode finalize()
StatusCode execute()