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