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