BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TofQCorrSvc.cxx
Go to the documentation of this file.
1//********************************************************************
2// TofQCorrSvc package
3// This Service is used for TOF measured pulse height correction.
4// For BESIII, from run 7991 to run 10881,
5// TOF electronics QTC correction are done online.
6// This service is used for convert the corrected Q back to RAW Q
7// Sun Shengsen 2009-9-17
8//********************************************************************
9
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/IIncidentListener.h"
12#include "GaudiKernel/IIncidentSvc.h"
13#include "GaudiKernel/IInterface.h"
14#include "GaudiKernel/Incident.h"
15#include "GaudiKernel/Kernel.h"
16#include "GaudiKernel/MsgStream.h"
17#include "GaudiKernel/Service.h"
18#include "GaudiKernel/SmartDataPtr.h"
19#include "GaudiKernel/StatusCode.h"
20#include <math.h>
21
22#include "CalibData/Tof/TofCalibData.h"
23#include "CalibData/Tof/bTofCalibBase.h"
24#include "EventModel/Event.h"
25#include "EventModel/EventHeader.h"
26#include "EventModel/EventModel.h"
27
28#include "TofQCorrSvc.h"
29
30using namespace std;
32
33TofQCorrSvc::TofQCorrSvc( const std::string& name, ISvcLocator* svcloc )
34 : base_class( name, svcloc ) {}
35
36/*StatusCode TofQCorrSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
37
38 if ( IID_ITofQCorrSvc.versionMatch(riid) ) {
39 *ppvInterface = static_cast<ITofQCorrSvc*> (this);
40 } else {
41 return Service::queryInterface(riid, ppvInterface) ;
42 }
43 return StatusCode::SUCCESS;
44}
45*/
46
48
49 MsgStream log( msgSvc(), name() );
50 log << MSG::INFO << name() << ": Start of run initialisation" << endmsg;
51
52 StatusCode sc = Service::initialize();
53 if ( sc.isFailure() ) return sc;
54
55 IIncidentSvc* incsvc;
56 sc = service( "IncidentSvc", incsvc );
57 int priority = 100;
58 if ( sc.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
59
60 sc = serviceLocator()->service( "DatabaseSvc", m_dbsvc, true );
61 if ( sc.isFailure() )
62 {
63 log << MSG::ERROR << "Unable to find DatabaseSvc " << endmsg;
64 return sc;
65 }
66
67 sc = serviceLocator()->service( "EventDataSvc", m_eventSvc, true );
68 if ( sc.isFailure() )
69 {
70 log << MSG::ERROR << "Unable to find EventDataSvc " << endmsg;
71 return sc;
72 }
73
74 StatusCode scc;
75 log << MSG::INFO << "setProperties()" << endmsg;
76 // scc = setProperties();
77 m_runNo = 0;
78 return sc;
79}
80
82 MsgStream log( msgSvc(), name() );
83 log << MSG::INFO << name() << ": End of Run" << endmsg;
84 return StatusCode::SUCCESS;
85}
86
88
89const double TofQCorrSvc::getBarEast( int layer, int no ) { return m_Bar_East[layer][no]; }
90
91const double TofQCorrSvc::getBarWest( int layer, int no ) { return m_Bar_West[layer][no]; }
92
93const double TofQCorrSvc::getEndcap( int layer, int no ) { return m_Endcap[layer][no]; }
94
95void TofQCorrSvc::handle( const Incident& inc ) {
96 MsgStream log( msgSvc(), name() );
97 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
98
99 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
100 int run = eventHeader->runNumber();
101 if ( run < 0 || run > 11000 ) return;
102
103 if ( inc.type() == "NewRun" )
104 {
105 log << MSG::DEBUG << "New Run:" << run << endmsg;
107 }
108}
109
111 MsgStream log( msgSvc(), name() );
112 SmartDataPtr<Event::EventHeader> eventHeader( m_eventSvc, "/Event/EventHeader" );
113 int run = eventHeader->runNumber();
114 if ( run < 0 )
115 {
116 log << MSG::INFO << "This data is the MC sample with the Run Number: " << run << endmsg;
117 run = -run;
118 }
119 // unsigned long *lengths;
120 char stmt1[200];
121 sprintf( stmt1,
122 "select TOFCalib "
123 "from RunParams where run_number = %d",
124 run );
125
127 int row_no = m_dbsvc->query( "run", stmt1, res );
128 if ( !row_no )
129 {
130 log << MSG::ERROR << "search errror" << endmsg;
131 exit( 1 );
132 }
133 long int runNo;
134 DatabaseRecord* records1 = res[0];
135 sscanf( ( *records1 )["TOFCalib"], "%ld", &runNo );
136
137 char stmt2[200];
138 sprintf( stmt2,
139 "select be,end,counter,a1,a2,a3 "
140 "from TOF_Q where run_number = %ld",
141 runNo );
142
143 res.clear();
144 row_no = m_dbsvc->query( "run", stmt2, res );
145 if ( !row_no )
146 {
147 log << MSG::ERROR << "search errror" << endmsg;
148 exit( 1 );
149 }
150
151 long int be, end, counter;
152 double sql_result[3];
153
154 for ( int jjj = 0; jjj < row_no; jjj++ )
155 {
156 DatabaseRecord* records2 = res[jjj];
157 sscanf( ( *records2 )["be"], "%ld", &be );
158 sscanf( ( *records2 )["end"], "%ld", &end );
159 sscanf( ( *records2 )["counter"], "%ld", &counter );
160 sscanf( ( *records2 )["a1"], "%lf", &sql_result[0] );
161 sscanf( ( *records2 )["a2"], "%lf", &sql_result[1] );
162 sscanf( ( *records2 )["a3"], "%lf", &sql_result[2] );
163 if ( be == 0 && end == 0 )
164 {
165 m_Endcap[counter][0] = sql_result[0];
166 m_Endcap[counter][1] = sql_result[1];
167 m_Endcap[counter][2] = sql_result[2];
168 }
169 if ( be == 1 && end == 0 )
170 {
171 m_Bar_East[counter][0] = sql_result[0];
172 m_Bar_East[counter][1] = sql_result[1];
173 m_Bar_East[counter][2] = sql_result[2];
174 }
175 if ( be == 1 && end == 1 )
176 {
177 m_Bar_West[counter][0] = sql_result[0];
178 m_Bar_West[counter][1] = sql_result[1];
179 m_Bar_West[counter][2] = sql_result[2];
180 }
181 }
182 res.clear();
183}
184
185const double TofQCorrSvc::BQRaw1( int id, double q ) {
186 MsgStream log( msgSvc(), name() );
187 double qraw = -999.0;
188 if ( id < 0 || id > 175 )
189 {
190 log << MSG::WARNING << "BQRaw1 : TofId is out of range, tofid = " << id << endmsg;
191 return qraw;
192 }
193 if ( fabs( q - 10000.0 ) < 1.0e-6 ) { return 10000.0; }
194 else if ( fabs( q + 999.0 ) < 1.0e-6 ) { return -999.0; }
195 double a = m_Bar_East[id][2];
196 double b = m_Bar_East[id][1];
197 double c = m_Bar_East[id][0] - q / 2.5;
198 qraw = ( sqrt( b * b - 4.0 * a * c ) - b ) / ( 2.0 * a );
199
200 return qraw;
201}
202
203const double TofQCorrSvc::BQRaw2( int id, double q ) {
204 MsgStream log( msgSvc(), name() );
205 double qraw = -999.0;
206 if ( id < 0 || id > 175 )
207 {
208 log << MSG::WARNING << "BQRaw2 : TofId is out of range, tofid = " << id << endmsg;
209 return qraw;
210 }
211 if ( fabs( q - 10000.0 ) < 1.0e-6 ) { return 10000.0; }
212 else if ( fabs( q + 999.0 ) < 1.0e-6 ) { return -999.0; }
213 double a = m_Bar_West[id][2];
214 double b = m_Bar_West[id][1];
215 double c = m_Bar_West[id][0] - q / 2.5;
216 qraw = ( sqrt( b * b - 4.0 * a * c ) - b ) / ( 2.0 * a );
217 return qraw;
218}
219
220const double TofQCorrSvc::EQRaw( int id, double q ) {
221 MsgStream log( msgSvc(), name() );
222 double qraw = -999.0;
223 if ( id < 0 || id > 95 )
224 {
225 log << MSG::WARNING << "EQRaw : TofId is out of range, tofid = " << id << endmsg;
226 return qraw;
227 }
228 if ( fabs( q - 10000.0 ) < 1.0e-6 ) { return 10000.0; }
229 else if ( fabs( q + 999.0 ) < 1.0e-6 ) { return -999.0; }
230 double a = m_Endcap[id][2];
231 double b = m_Endcap[id][1];
232 double c = m_Endcap[id][0] - q / 2.5;
233 qraw = ( sqrt( b * b - 4.0 * a * c ) - b ) / ( 2.0 * a );
234 return qraw;
235}
DECLARE_COMPONENT(BesBdkRc)
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
int runNo
Definition DQA_TO_DB.cxx:13
****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 getEndcap(int layer, int no)
virtual StatusCode initialize()
void getTofQCorrInfo()
const double getBarEast(int layer, int no)
const double getBarWest(int layer, int no)
TofQCorrSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
const double BQRaw2(int id, double q)
const double BQRaw1(int id, double q)
void handle(const Incident &)
const double EQRaw(int id, double q)