BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
TofSimSvc.cxx
Go to the documentation of this file.
1//********************************************************
2//
3// BESIII Tof Simulation Service
4// Class: TofSimSvc
5// Sun Shengsen <[email protected]>
6//
7// Description:
8// This service is used to get Tof Simulation Constants
9// from DataBase and do the Tof simulation.
10//
11//*********************************************************
12
13#include "GaudiKernel/StatusCode.h"
14#include "GaudiKernel/SvcFactory.h"
15#include "GaudiKernel/MsgStream.h"
16#include "GaudiKernel/IIncidentSvc.h"
17#include "GaudiKernel/Incident.h"
18#include "GaudiKernel/IIncidentListener.h"
19#include "GaudiKernel/IDataProviderSvc.h"
20#include "GaudiKernel/DataSvc.h"
21#include "GaudiKernel/SmartDataPtr.h"
22#include "GaudiKernel/Service.h"
24#include "TofSimSvc/TofSimSvc.h"
25
26using namespace std;
27
28TofSimSvc::TofSimSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
29 declareProperty("Run",m_run=1);
30}
31
32StatusCode TofSimSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
33
34 if ( IID_ITofSimSvc.versionMatch(riid) ) {
35 *ppvInterface = static_cast<ITofSimSvc*> (this);
36 } else {
37 return Service::queryInterface(riid, ppvInterface) ;
38 }
39 return StatusCode::SUCCESS;
40}
41
42StatusCode TofSimSvc::initialize ( ) {
43 m_hasbeeninitialized=false;
44
45 MsgStream log(msgSvc(), name());
46 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
47
48 StatusCode sc = Service::initialize();
49 if ( sc.isFailure() ) return sc;
50
51 IIncidentSvc* incsvc;
52 sc = service("IncidentSvc", incsvc);
53 int priority = 100;
54 if( sc.isSuccess() ){
55 incsvc -> addListener(this, "NewRun", priority);
56 }
57
58 StatusCode scc;
59
60 log<<MSG::INFO << "setProperties()" << endreq;
61 scc = service("CalibDataSvc", m_pSimDataSvc, true);
62 if ( !scc.isSuccess() ) {
63 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of SimXmlCnvSvc"<<endreq;
64 return scc;
65 } else {
66 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of SimXmlCnvSvc"<<endreq;
67 }
68 // Get properties from the JobOptionsSvc
69 scc = setProperties();
70
71 return sc;
72}
73
74StatusCode TofSimSvc::finalize ( ) {
75 MsgStream log(msgSvc(), name());
76 log << MSG::INFO << name() << ": End of Run" << endreq;
77 return StatusCode::SUCCESS;
78}
79
81 MsgStream log(msgSvc(), name());
82 log << MSG::INFO << name() << ": Destructor function of TofSimSvc" << endreq;
83
84 for(vector<TofConst*>::iterator it1 = fTofConst.begin(); it1 != fTofConst.end(); it1++) { delete (*it1); }
85 fTofConst.clear();
86 for(vector<BTofSim*>::iterator it2 = fBTofSim.begin(); it2 != fBTofSim.end(); it2++) { delete (*it2); }
87 fBTofSim.clear();
88 for(vector<ETofSim*>::iterator it3 = fETofSim.begin(); it3 != fETofSim.end(); it3++) { delete (*it3); }
89 fETofSim.clear();
90
91 return;
92}
93
94StatusCode TofSimSvc::FillfromDatabase(){
95
96 MsgStream log(msgSvc(), name());
97 std::string fullPath = "/Calib/TofSim";
98 log << MSG::INFO<<" Tof simulation fullPath = "<<fullPath<< endreq;
99 SmartDataPtr<CalibData::TofSimData> test(m_pSimDataSvc, fullPath);
100 if(!test){
101 log << MSG::FATAL << "TofSimSvc could not find TofSimData in TDS!!" << endreq;
102 return StatusCode::FAILURE;
103 }
104
105 for(vector<TofConst*>::iterator it1 = fTofConst.begin(); it1 != fTofConst.end(); it1++) { delete (*it1); }
106 fTofConst.clear();
107 for(vector<BTofSim*>::iterator it2 = fBTofSim.begin(); it2 != fBTofSim.end(); it2++) { delete (*it2); }
108 fBTofSim.clear();
109 for(vector<ETofSim*>::iterator it3 = fETofSim.begin(); it3 != fETofSim.end(); it3++) { delete (*it3); }
110 fETofSim.clear();
111
112 TofConst* tofConst = new TofConst;
113 tofConst->setBarLowThres( test->getBarLowThres() );
114 tofConst->setBarHighThres( test->getBarHighThres() );
115 tofConst->setEndLowThres( test->getEndLowThres() );
116 tofConst->setEndHighThres( test->getEndHighThres() );
117 tofConst->setBarPMTGain( test->getBarPMTGain() );
118 tofConst->setEndPMTGain( test->getEndPMTGain() );
119 tofConst->setBarConstant( test->getBarConstant() );
120 tofConst->setEndConstant( test->getEndConstant() );
121 tofConst->setEndNoiseSwitch( test->getEndNoiseSwitch() );
122 fTofConst.push_back(tofConst);
123
124 for( unsigned int id=0; id<176; id++ ) {
125// std::cout<<test->getBarAttenLength(id)<<std::endl;
126 BTofSim* btof = new BTofSim;
127 btof->setGain( test->getBarGain(id) );
128 btof->setRatio( test->getBarRatio(id) );
129 btof->setAttenLength( test->getBarAttenLength(id) );
130 fBTofSim.push_back(btof);
131 }
132
133 for( unsigned int id=0; id<96; id++ ) {
134 ETofSim* etof = new ETofSim;
135 etof->setGain( test->getEndGain(id) );
136 etof->setAttenLength( test->getEndAttenLength(id) );
137 etof->setNoiseSmear( test->getEndNoiseSmear(id) );
138 fETofSim.push_back(etof);
139 }
140
141 return StatusCode::SUCCESS;
142}
143
145 std::cout<<"Now We can get the TOF Simulation Service"<<std::endl;
146 return;
147}
148
149void TofSimSvc::handle(const Incident& inc){
150 MsgStream log( messageService(), name() );
151 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
152
153 if ( inc.type() == "NewRun" ){
154 log << MSG::DEBUG << "New Run" << endreq;
155 StatusCode sc= FillfromDatabase();
156 if(sc.isSuccess()){
157 m_hasbeeninitialized=true;
158 }
159 }
160 return;
161}
162
164 return fTofConst[0]->getBarLowThres();
165}
166
168 return fTofConst[0]->getBarHighThres();
169}
170
172 return fTofConst[0]->getEndLowThres();
173}
174
176 return fTofConst[0]->getEndHighThres();
177}
178
179const double TofSimSvc::BarPMTGain() {
180 return fTofConst[0]->getBarPMTGain();
181}
182
183const double TofSimSvc::EndPMTGain() {
184 return fTofConst[0]->getEndPMTGain();
185}
186
188 return fTofConst[0]->getBarConstant();
189}
190
192 return fTofConst[0]->getEndConstant();
193}
194
196 return fTofConst[0]->getEndNoiseSwitch();
197}
198
199const double TofSimSvc::BarGain1(unsigned int id) {
200 if( id < 176 ) {
201 return fBTofSim[id]->getGain1();
202 }
203 else {
204 std::cout<<"TofSimSvc::BarGain1: bad id="<<id<<std::endl;
205 return 0.0;
206 }
207}
208
209const double TofSimSvc::BarGain2(unsigned int id) {
210 if( id < 176 ) {
211 return fBTofSim[id]->getGain2();
212 }
213 else {
214 std::cout<<"TofSimSvc::BarGain2: bad id="<<id<<std::endl;
215 return 0.0;
216 }
217}
218
219const double TofSimSvc::EndGain(unsigned int id) {
220 if( id < 96 ) {
221 return fETofSim[id]->getGain();
222 }
223 else {
224 std::cout<<"TofSimSvc::EndGain: bad id="<<id<<std::endl;
225 return 0.0;
226 }
227}
228
229const double TofSimSvc::BarAttenLength(unsigned int id) {
230 if( id < 176 ) {
231 return fBTofSim[id]->getAttenLength();
232 }
233 else {
234 std::cout<<"TofSimSvc::BarAttenLength: bad id="<<id<<std::endl;
235 return 0.0;
236 }
237}
238
239const double TofSimSvc::EndAttenLength(unsigned int id) {
240 if( id < 96 ) {
241 return fETofSim[id]->getAttenLength();
242 }
243 else {
244 std::cout<<"TofSimSvc::EndAttenLength: bad id="<<id<<std::endl;
245 return 0.0;
246 }
247}
248
249const double TofSimSvc::EndNoiseSmear(unsigned int id) {
250 if( id < 96 ) {
251 return fETofSim[id]->getNoiseSmear();
252 }
253 else {
254 std::cout<<"TofSimSvc::EndNoiseSmear: bad id="<<id<<std::endl;
255 return 0.0;
256 }
257}
std::string test
Definition: CalibModel.cxx:43
IMessageSvc * msgSvc()
Definition: BTofSim.h:6
void setAttenLength(double length)
Definition: BTofSim.h:18
void setGain(double gain)
Definition: BTofSim.h:16
void setRatio(double ratio)
Definition: BTofSim.h:17
Definition: ETofSim.h:4
void setGain(double gain)
Definition: ETofSim.h:14
void setNoiseSmear(double noisesmear)
Definition: ETofSim.h:16
void setAttenLength(double length)
Definition: ETofSim.h:15
void setBarPMTGain(double bg)
Definition: TofConst.h:24
void setBarConstant(double bc)
Definition: TofConst.h:26
void setEndConstant(double ec)
Definition: TofConst.h:27
void setBarLowThres(double blth)
Definition: TofConst.h:20
void setEndHighThres(double ehth)
Definition: TofConst.h:23
void setEndNoiseSwitch(double eswitch)
Definition: TofConst.h:28
void setEndPMTGain(double eg)
Definition: TofConst.h:25
void setEndLowThres(double elth)
Definition: TofConst.h:22
void setBarHighThres(double bhth)
Definition: TofConst.h:21
const double EndNoiseSwitch()
Definition: TofSimSvc.cxx:195
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Definition: TofSimSvc.cxx:32
const double BarLowThres()
Definition: TofSimSvc.cxx:163
const double BarGain1(unsigned int id)
Definition: TofSimSvc.cxx:199
const double BarConstant()
Definition: TofSimSvc.cxx:187
virtual StatusCode initialize()
Definition: TofSimSvc.cxx:42
void Dump()
Definition: TofSimSvc.cxx:144
const double EndAttenLength(unsigned int id)
Definition: TofSimSvc.cxx:239
const double BarPMTGain()
Definition: TofSimSvc.cxx:179
const double EndGain(unsigned int id)
Definition: TofSimSvc.cxx:219
const double EndNoiseSmear(unsigned int id)
Definition: TofSimSvc.cxx:249
void handle(const Incident &)
Definition: TofSimSvc.cxx:149
TofSimSvc(const std::string &name, ISvcLocator *svcloc)
Definition: TofSimSvc.cxx:28
const double EndConstant()
Definition: TofSimSvc.cxx:191
const double BarAttenLength(unsigned int id)
Definition: TofSimSvc.cxx:229
const double EndPMTGain()
Definition: TofSimSvc.cxx:183
const double EndHighThres()
Definition: TofSimSvc.cxx:175
virtual StatusCode finalize()
Definition: TofSimSvc.cxx:74
const double EndLowThres()
Definition: TofSimSvc.cxx:171
const double BarHighThres()
Definition: TofSimSvc.cxx:167
const double BarGain2(unsigned int id)
Definition: TofSimSvc.cxx:209