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