BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
TofQElecSvc.cxx
Go to the documentation of this file.
1// TofQElecSvc
2// Sun Shengsen 2009-9-17
3//
4#include "GaudiKernel/Kernel.h"
5#include "GaudiKernel/IInterface.h"
6#include "GaudiKernel/StatusCode.h"
7//#include "GaudiKernel/ISvcFactory.h"
8#include "GaudiKernel/SvcFactory.h"
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/IIncidentSvc.h"
11#include "GaudiKernel/Incident.h"
12#include "GaudiKernel/IIncidentListener.h"
13#include "GaudiKernel/IDataProviderSvc.h"
14#include "GaudiKernel/Service.h"
15#include "GaudiKernel/DataSvc.h"
16#include "GaudiKernel/SmartDataPtr.h"
17#include "TofQElecSvc/TofQElecSvc.h"
18#include "TMath.h"
19
20using namespace std;
21
22TofQElecSvc::TofQElecSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
23 declareProperty("Run",m_run=1);
24}
25
26
27StatusCode TofQElecSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
28
29 if ( IID_ITofQElecSvc.versionMatch(riid) ) {
30 *ppvInterface = static_cast<ITofQElecSvc*> (this);
31 } else {
32 return Service::queryInterface(riid, ppvInterface) ;
33 }
34 return StatusCode::SUCCESS;
35}
36
38 m_hasbeeninitialized=false;
39
40 MsgStream log(msgSvc(), name());
41 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
42
43 StatusCode sc = Service::initialize();
44 if ( sc.isFailure() ) return sc;
45
46 IIncidentSvc* incsvc;
47 sc = service("IncidentSvc", incsvc);
48 int priority = 100;
49 if( sc.isSuccess() ){
50 incsvc -> addListener(this, "NewRun", priority);
51 }
52
53 StatusCode scc;
54
55 log<<MSG::INFO << "setProperties()" << endreq;
56 scc = service("CalibDataSvc", m_pCalibDataSvc, true);
57 if ( !scc.isSuccess() ) {
58 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of QElecXmlCnvSvc"<<endreq;
59 return scc;
60 } else {
61 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of QElecXmlCnvSvc"<<endreq;
62 }
63 // Get properties from the JobOptionsSvc
64 scc = setProperties();
65 m_data=0;
66 return sc;
67}
68
69StatusCode TofQElecSvc::finalize ( ) {
70 MsgStream log(msgSvc(), name());
71 log << MSG::INFO << name() << ": End of Run" << endreq;
72 return StatusCode::SUCCESS;
73}
74
75
77 delete m_data;
78 return;
79}
80
81
82StatusCode TofQElecSvc::FillfromDatabase(){
83
84 MsgStream log(msgSvc(), name());
85 std::string fullPath = "/Calib/TofQElec";
86 log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
87 SmartDataPtr<CalibData::TofElecData> test(m_pCalibDataSvc, fullPath);
88 if(!test){
89 log << MSG::FATAL << "TofQElecSvc could not find TofQElecData in TCDS!!" << endreq;
90 return StatusCode::FAILURE;
91 }
92
93 if(m_data) delete m_data;
94 m_data = new CalibData::TofElecData;
95 m_data->sim(test);
96
97 /*
98 for( vector<CalibData::BarrelElec*>::iterator iter1 = fBarrelElec.begin(); iter1 != fBarrelElec.end(); iter1++ ) {
99 delete *iter1;
100 }
101 fBarrelElec.clear();
102 for( vector<CalibData::EndcapElec*>::iterator iter2 = fEndcapElec.begin(); iter2 != fEndcapElec.end(); iter2++ ) {
103 delete *iter2;
104 }
105 fEndcapElec.clear();
106
107 for( unsigned ib=0; ib<176; ib++ ) {
108 BarrelElec* bElec = new BarrelElec;
109 for( unsigned int j=0; j<4; j++ ) {
110 bElec->setNumEast( j, ib );
111 bElec->setNumWest( j, ib );
112 }
113 for( unsigned int k=0; k<11; k++ ) {
114 bElec->setP1( k, ib );
115 bElec->setP2( k, ib );
116 bElec->setSimP1( k, ib );
117 bElec->setSimP2( k, ib );
118 }
119 fBarrelElec.push_back( bElec );
120 }
121
122 for( unsigned ie=0; ie<96; ie++ ) {
123 EndcapElec* eElec = new EndcapElec;
124 for( unsigned int j=0; j<4; j++ ) {
125 eElec->setNum( j, ie );
126 }
127 for( unsigned int k=0; k<11; k++ ) {
128 eElec->setP( k, ie );
129 eElec->setSimP( k, ie );
130 }
131 fEndcapElec.push_back( eElec );
132 }
133 */
134
135 return StatusCode::SUCCESS;
136}
137
138
139void TofQElecSvc::handle(const Incident& inc){
140 MsgStream log( messageService(), name() );
141 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
142
143 if ( inc.type() == "NewRun" ){
144 log << MSG::DEBUG << "New Run" << endreq;
145 StatusCode sc= FillfromDatabase();
146 }
147 return;
148}
149
150
151const unsigned int TofQElecSvc::Board( bool barrel, int id, bool eastEnd ) {
152 MsgStream log(msgSvc(), name());
153
154 if( barrel ) {
155 if( id<0 || id>175 ) {
156 log << MSG::WARNING <<"Board : TofId is out of Range, tofid=" << id << endreq;
157 return 1000;
158 }
159 }
160 else {
161 if( id<0 || id>95 ) {
162 log << MSG::WARNING <<"Board : TofId is out of Range, tofid=" << id << endreq;
163 return 1000;
164 }
165 }
166
167 unsigned int board;
168 if( barrel ) {
169 if( eastEnd ) {
170 board = (m_data->getBTof(id)).getNumEast(0);
171 }
172 else {
173 board = (m_data->getBTof(id)).getNumWest(0);
174 }
175 }
176 else {
177 board = (m_data->getETof(id)).getNum(0);
178 }
179
180 return board;
181}
182
183
184const unsigned int TofQElecSvc::Crate( bool barrel, int id, bool eastEnd ) {
185 MsgStream log(msgSvc(), name());
186
187 if( barrel ) {
188 if( id<0 || id>175 ) {
189 log << MSG::WARNING <<"Crate : TofId is out of Range, tofid=" << id << endreq;
190 return 1000;
191 }
192 }
193 else {
194 if( id<0 || id>95 ) {
195 log << MSG::WARNING <<"Crate : TofId is out of Range, tofid=" << id << endreq;
196 return 1000;
197 }
198 }
199
200 unsigned int crate;
201 if( barrel ) {
202 if( eastEnd ) {
203 crate = (m_data->getBTof(id)).getNumEast(2);
204 }
205 else {
206 crate = (m_data->getBTof(id)).getNumWest(2);
207 }
208 }
209 else {
210 crate = (m_data->getETof(id)).getNum(2);
211 }
212
213 return crate;
214}
215
216
217const unsigned int TofQElecSvc::Fee( bool barrel, int id, bool eastEnd ) {
218 MsgStream log(msgSvc(), name());
219
220 if( barrel ) {
221 if( id<0 || id>175 ) {
222 log << MSG::WARNING <<"Fee : TofId is out of Range, tofid=" << id << endreq;
223 return 1000;
224 }
225 }
226 else {
227 if( id<0 || id>95 ) {
228 log << MSG::WARNING <<"Fee : TofId is out of Range, tofid=" << id << endreq;
229 return 1000;
230 }
231 }
232
233 unsigned int crate;
234 if( barrel ) {
235 if( eastEnd ) {
236 crate = (m_data->getBTof(id)).getNumEast(3);
237 }
238 else {
239 crate = (m_data->getBTof(id)).getNumWest(3);
240 }
241 }
242 else {
243 crate = (m_data->getETof(id)).getNum(3);
244 }
245
246 return crate;
247}
248
249
250const unsigned int TofQElecSvc::Channel( bool barrel, int id, bool eastEnd ) {
251 MsgStream log(msgSvc(), name());
252
253 if( barrel ) {
254 if( id<0 || id>175 ) {
255 log << MSG::WARNING <<"Channel : TofId is out of Range, tofid=" << id << endreq;
256 return 1000;
257 }
258 }
259 else {
260 if( id<0 || id>95 ) {
261 log << MSG::WARNING <<"Channel : TofId is out of Range, tofid=" << id << endreq;
262 return 1000;
263 }
264 }
265
266 unsigned int channel;
267 if( barrel ) {
268 if( eastEnd ) {
269 channel = (m_data->getBTof(id)).getNumEast(1);
270 }
271 else {
272 channel = (m_data->getBTof(id)).getNumWest(1);
273 }
274 }
275 else {
276 channel = (m_data->getETof(id)).getNum(1);
277 }
278
279 return channel;
280}
281
282
283const double TofQElecSvc::BQTC1(int id, double q) {
284 double qtcNew = -999.0;
285 MsgStream log(msgSvc(), name());
286 if( id<0 || id>175 ) {
287 log << MSG::WARNING <<"BQTC1 : TofId is out of Range, tofid=" << id << endreq;
288 return qtcNew;
289 }
290 if( fabs(q-10000.0)<1.0e-6 ) { return 10000.0; }
291 else if( fabs(q+999.0)<1.0e-6 ) { return -999.0; }
292
293 double ratio = (m_data->getBTof(id)).getP1(0);
294 double p[10];
295 for(unsigned int i=0; i<10; i++ ) {
296 p[i] = (m_data->getBTof(id)).getP1(i+1);
297 }
298 q = q*ratio;
299 qtcNew = p[0] + p[1]*q + p[2]*q*q + p[3]*q*q*q + p[4]*q*q*q*q + p[7]*exp(p[5]*(q-p[6]));
300
301 // cout << "East tofid=" << id << " ratio=" << ratio;
302 // for( unsigned int i=0; i<8; i++ ) { cout << " P" << i << "= " << p[i]; }
303 // cout << endl;
304
305 return qtcNew;
306}
307
308
309const double TofQElecSvc::BQTC2(int id, double q) {
310 double qtcNew = -999.0;
311 MsgStream log(msgSvc(), name());
312 if( id<0 || id>175 ) {
313 log << MSG::WARNING <<"BQTC2 : TofId is out of Range, tofid=" << id << endreq;
314 return qtcNew;
315 }
316 if( fabs(q-10000.0)<1.0e-6 ) { return 10000.0; }
317 else if( fabs(q+999.0)<1.0e-6 ) { return -999.0; }
318
319 double ratio = (m_data->getBTof(id)).getP2(0);
320 double p[10];
321 for(unsigned int i=0; i<10; i++ ) {
322 p[i] = (m_data->getBTof(id)).getP2(i+1);
323 }
324 q = q*ratio;
325 qtcNew = p[0] + p[1]*q + p[2]*q*q + p[3]*q*q*q + p[4]*q*q*q*q + p[7]*exp(p[5]*(q-p[6]));
326
327 // cout << "West tofid=" << id << " ratio=" << ratio;
328 // for( unsigned int i=0; i<8; i++ ) { cout << " P" << i << "= " << p[i]; }
329 // cout << endl;
330
331 return qtcNew;
332}
333
334
335const double TofQElecSvc::EQTC(int id, double q) {
336 double qtcNew = -999.0;
337 MsgStream log(msgSvc(), name());
338 if( id<0 || id>95 ) {
339 log << MSG::WARNING <<"EQTC : TofId is out of Range, tofid=" << id << endreq;
340 return qtcNew;
341 }
342 if( fabs(q-10000.0)<1.0e-6 ) { return 10000.0; }
343 else if( fabs(q+999.0)<1.0e-6 ) { return -999.0; }
344
345 double ratio = (m_data->getETof(id)).getP(0);
346 double p[10];
347 for(unsigned int i=0; i<10; i++ ) {
348 p[i] = (m_data->getETof(id)).getP(i+1);
349 }
350 q = q*ratio;
351 qtcNew = p[0] + p[1]*q + p[2]*q*q + p[3]*q*q*q + p[4]*q*q*q*q + p[7]*exp(p[5]*(q-p[6]));
352
353 // cout << "Endcap tofid=" << id << " ratio=" << ratio;
354 // for( unsigned int i=0; i<8; i++ ) { cout << " P" << i << "= " << p[i]; }
355 // cout << endl;
356
357 return qtcNew;
358}
359
360
361const double TofQElecSvc::BQChannel1(int id, double qtc) {
362 double qChannel = -999.0;
363 MsgStream log(msgSvc(), name());
364 if( id<0 || id>175 ) {
365 log << MSG::ERROR <<"BChannel1 : TofId is out of Range, tofid=" << id << endreq;
366 return qChannel;
367 }
368
369 double ratio = (m_data->getBTof(id)).getSimP1(0);
370 double p[10];
371 for(unsigned int i=0; i<10; i++ ) {
372 p[i] = (m_data->getBTof(id)).getSimP1(i+1);
373 }
374 qChannel = ( p[0] + p[1]*qtc + p[2]*qtc*qtc + p[3]*qtc*qtc*qtc )*( 1.0 - TMath::Erf((qtc-p[4])/p[5]) ) + ( p[6] + p[7]*qtc )*( 1.0 + TMath::Erf((qtc-p[8])/p[9]) );
375 qChannel = ratio*qChannel;
376
377 // cout << "Sim East tofid=" << id << " ratio=" << ratio;
378 // for( unsigned int i=0; i<11; i++ ) { cout << " P" << i << "= " << p[i]; }
379 // cout << endl;
380
381 return qChannel;
382}
383
384
385const double TofQElecSvc::BQChannel2(int id, double qtc) {
386 double qChannel = -999.0;
387 MsgStream log(msgSvc(), name());
388 if( id<0 || id>175 ) {
389 log << MSG::ERROR <<"BChannel2 : TofId is out of Range, tofid=" << id << endreq;
390 return qChannel;
391 }
392
393 double ratio = (m_data->getBTof(id)).getSimP2(0);
394 double p[10];
395 for(unsigned int i=0; i<10; i++ ) {
396 p[i] = (m_data->getBTof(id)).getSimP2(i+1);
397 }
398 qChannel = ( p[0] + p[1]*qtc + p[2]*qtc*qtc + p[3]*qtc*qtc*qtc )*( 1.0 - TMath::Erf((qtc-p[4])/p[5]) ) + ( p[6] + p[7]*qtc )*( 1.0 + TMath::Erf((qtc-p[8])/p[9]) );
399 qChannel = ratio*qChannel;
400
401 // cout << "Sim West tofid=" << id << " ratio=" << ratio;
402 // for( unsigned int i=0; i<11; i++ ) { cout << " P" << i << "= " << p[i]; }
403 // cout << endl;
404
405 return qChannel;
406}
407
408
409const double TofQElecSvc::EQChannel(int id, double qtc) {
410 double qChannel = -999.0;
411 MsgStream log(msgSvc(), name());
412 if( id<0 || id>95 ) {
413 log << MSG::ERROR <<"EQTC : TofId is out of Range, tofid=" << id << endreq;
414 return qChannel;
415 }
416
417 double ratio = (m_data->getETof(id)).getSimP(0);
418 double p[10];
419 for(unsigned int i=0; i<10; i++ ) {
420 p[i] = (m_data->getETof(id)).getSimP(i+1);
421 }
422 qChannel = ( p[0] + p[1]*qtc + p[2]*qtc*qtc + p[3]*qtc*qtc*qtc )*( 1.0 - TMath::Erf((qtc-p[4])/p[5]) ) + ( p[6] + p[7]*qtc )*( 1.0 + TMath::Erf((qtc-p[8])/p[9]) );
423 qChannel = ratio*qChannel;
424
425 // cout << "Endcap tofid=" << id << " ratio=" << ratio;
426 // for( unsigned int i=0; i<11; i++ ) { cout << " P" << i << "= " << p[i]; }
427 // cout << endl;
428
429 return qChannel;
430}
std::string test
Definition: CalibModel.cxx:43
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition: KKsem.h:33
void sim(TofElecData *other1)
Definition: TofElecData.cxx:33
EndcapElec getETof(int cnt) const
Definition: TofElecData.cxx:52
BarrelElec getBTof(int cnt) const
Definition: TofElecData.cxx:43
const double EQTC(int id, double q)
const double BQChannel2(int id, double qtc)
const double BQChannel1(int id, double qtc)
const unsigned int Channel(bool barrel, int id, bool eastEnd)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Definition: TofQElecSvc.cxx:27
TofQElecSvc(const std::string &name, ISvcLocator *svcloc)
Definition: TofQElecSvc.cxx:22
virtual StatusCode finalize()
Definition: TofQElecSvc.cxx:69
void handle(const Incident &)
const double BQTC1(int id, double q)
const unsigned int Fee(bool barrel, int id, bool eastEnd)
virtual StatusCode initialize()
Definition: TofQElecSvc.cxx:37
const double EQChannel(int id, double qtc)
const unsigned int Crate(bool barrel, int id, bool eastEnd)
const unsigned int Board(bool barrel, int id, bool eastEnd)
const double BQTC2(int id, double q)