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