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