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