BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcCalibConstSvc.cxx
Go to the documentation of this file.
2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/StatusCode.h"
5#include "GaudiKernel/SvcFactory.h"
6#include "GaudiKernel/MsgStream.h"
7
8#include "GaudiKernel/ISvcLocator.h"
9#include "GaudiKernel/Bootstrap.h"
10
11#include "GaudiKernel/IDataProviderSvc.h"
12#include "GaudiKernel/SmartDataPtr.h"
13#include "GaudiKernel/DataSvc.h"
14#include "GaudiKernel/PropertyMgr.h"
15
19
20#include <vector>
21#include <math.h>
22#include <fstream>
23#include "GaudiKernel/IIncidentSvc.h"
24#include "GaudiKernel/Incident.h"
25#include "GaudiKernel/IIncidentListener.h"
26
27
29#include "EventModel/Event.h"
31
32
33
34EmcCalibConstSvc::EmcCalibConstSvc( const std::string& name, ISvcLocator* svcloc) :
35 Service (name, svcloc) {
36
37 m_EmaxVersion1=false;
38 m_EmaxVersion2=false;
40
41 for(int i=0;i<6240;i++){
47 }
48
49 int ixtal;
50 double emaxData;
51 int Nixt=0;
52
53 ///for version 1/////////
54 string paraPath = getenv("EMCCALIBCONSTSVCROOT");
55 paraPath += "/share/emax_data.dat"; // version=1
56 ifstream in;
57 in.open(paraPath.c_str());
58 assert(in);
59
60 while (in.peek() != EOF)
61 {
62
63 in >> ixtal>>emaxData;
64
65 m_CrystalEmaxData_1[ixtal]=emaxData;
66 Nixt++;
67 // cout<<"readFile==============="<<emaxData<<endl;
68 }
69
70 in.close();
71
72
73 ////version 2///////////
74 string paraPath2 = getenv("EMCCALIBCONSTSVCROOT");
75 paraPath2 += "/share/emax_data_2.dat"; // version=2
76
77 ifstream in2;
78 in2.open(paraPath2.c_str());
79 assert(in2);
80
81 Nixt=0;
82 while (in2.peek() != EOF)
83 {
84
85 in2 >> ixtal>>emaxData;
86
87 m_CrystalEmaxData_2[ixtal]=emaxData;
88
89 Nixt++;
90 // cout<<"readFile2==============="<<emaxData<<endl;
91 }
92
93 in2.close();
94
95 ////read dead channel energy threshould Ecut///////////
96 string paraPath3 = getenv("EMCCALIBCONSTSVCROOT");
97 paraPath3 += "/share/DeadThresholdEcut_2020.conf";
98
99 ifstream in3;
100 in3.open(paraPath3.c_str());
101 assert(in3);
102
103 Nixt=0;
104 double satuEn,Ecut;
105 double DeltaEcut=0.0;
106
107 while (in3.peek() != EOF)
108 {
109
110 in3 >> ixtal>>satuEn>>Ecut;
111 if ((Ecut-satuEn)>DeltaEcut) {
112 m_CrystalDeadEcut_2020[ixtal]=Ecut-DeltaEcut;
113 } else {
114 m_CrystalDeadEcut_2020[ixtal]=Ecut;
115 }
116 Nixt++;
117
118 }
119
120 in3.close();
121
122}
123
125
126}
127
128StatusCode EmcCalibConstSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
129 if( IID_IEmcCalibConstSvc.versionMatch(riid) ){
130 *ppvInterface = static_cast<IEmcCalibConstSvc*> (this);
131 } else{
132 return Service::queryInterface(riid, ppvInterface);
133 }
134 return StatusCode::SUCCESS;
135}
136
138 MsgStream log(messageService(), name());
139 log << MSG::INFO << "EmcCalibConstSvc::initialize()" << endreq;
140
141 StatusCode sc = Service::initialize();
142 if( sc.isFailure() ) return sc;
143
144
145 IIncidentSvc* incsvc;
146 sc = service("IncidentSvc", incsvc);
147 int priority = 100;
148 if( sc.isSuccess() ){
149 incsvc -> addListener(this, "NewRun", priority);
150 }
151
152 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
153 if (sc .isFailure() ) {
154 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
155 return sc;
156 }
157
158 sc = service("CalibDataSvc", m_calDataSvc, true);
159 if( sc == StatusCode::SUCCESS ){
160 log << MSG::INFO << "Retrieve IDataProviderSvc" << endreq;
161 }else{
162 log << MSG::FATAL << "can not get IDataProviderSvc" << endreq;
163 }
164
165 // sc = service("EmcRecGeoSvc", m_emcGeomSvc);
166 // if( sc != StatusCode::SUCCESS ){
167 // log << MSG::ERROR << "can not use EmcRecGeoSvc" << endreq;
168 // }
169
172
173 //Dump();
174 //cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EmcCalibConstSvc initialize"<<endl;
175 return StatusCode::SUCCESS;
176}
177
179
180 delete m_theEmcStruc;
181
182 MsgStream log(messageService(), name());
183 log << MSG::INFO << "EmcCalibConstSvc::finalize()" << endreq;
184 return StatusCode::SUCCESS;
185
186}
187
188void EmcCalibConstSvc::handle(const Incident& inc){
189 MsgStream log( messageService(), name() );
190 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
191
192
193
194 if ( inc.type() == "NewRun" ){
195 log << MSG::DEBUG << "NewRun" << endreq;
196
197
198 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
199 int run = eventHeader->runNumber();
200 //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcCalibConstSvc handle,run="<<run<<endl;
201 if (run<0) run = -run;
202
203
204 log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<< endreq;
205 //run <63075: EmaxVersion=1; run>=63075: EmaxVersion=2;
206 cout<< "handle: " <<"Run in handle is: "<<run<<endl;
207 if (run<63075&& !m_EmaxVersion1) {
209 m_EmaxVersion1=true;
210 m_EmaxVersion2=false;
211
212
213 cout<< "handle: " <<"EmaxVersion="<<"111111111111111"<<endl;
214 }
215
216
217 if (run>=63075&& !m_EmaxVersion2) {
219 m_EmaxVersion2=true;
220 m_EmaxVersion1=false;
221 cout<< "handle: " <<"EmaxVersion="<<"222222222222"<<endl;
222 }
223
224 if (run>=63075&&run<=65092&&!m_DeadEcutVersion2020){
227 cout<< "handle: " <<"DeadEcutVersion="<<"2020"<<endl;
228 }
229
230 //if(!getCrystalEmaxDataFileInfo()){
231 // log << MSG::ERROR << "can not find the crystal EmaxData file" << endreq;
232 //}
233
234 // Dump();
235 }
236
237
238}
239
240
241
243 {
244 double digiCalibConst = 0.0;
245 MsgStream log(messageService(), name());
246
247 std::string fullPath = "/Calib/EmcCal";
248 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
249 if( ! calConst ){
250 log << MSG::ERROR << "can not access to EmcDigi CalibData via SmartPtr"
251 << endreq;
252 }else {
253 digiCalibConst = calConst->getDigiCalibConst(No);
254 }
255
256 return digiCalibConst;
257}
258
260 {
261 int IxtalNumber = 999999;
262 MsgStream log(messageService(), name());
263
264 std::string fullPath = "/Calib/EmcCal";
265 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
266 if( ! calConst ){
267 log << MSG::ERROR << "can not access to EmcDigi CalibData via SmartPtr"
268 << endreq;
269 }else {
270 IxtalNumber = calConst->getIxtalNumber(No);
271 }
272
273 return IxtalNumber;
274}
275
277 {
278 int digiCalibConstNo = 0;
279 MsgStream log(messageService(), name());
280
281 std::string fullPath = "/Calib/EmcCal";
282 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
283 if( ! calConst ){
284 log << MSG::ERROR << "can not access to EmcDigiNo CalibData via SmartPtr"
285 << endreq;
286 }else {
287 digiCalibConstNo = calConst->getDigiCalibConstNo();
288 }
289
290 return digiCalibConstNo;
291}
292
294 {
295 int IxtalNumberNo = 0;
296 MsgStream log(messageService(), name());
297
298 std::string fullPath = "/Calib/EmcCal";
299 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
300 if( ! calConst ){
301 log << MSG::ERROR << "can not access to EmcDigiNo CalibData via SmartPtr"
302 << endreq;
303 }else {
304 IxtalNumberNo = calConst->getIxtalNumberNo();
305 }
306
307 return IxtalNumberNo;
308}
309
310
311
312int EmcCalibConstSvc::getIndex( unsigned int PartId,
313 unsigned int ThetaIndex,
314 unsigned int PhiIndex) const
315{
316 return m_theEmcStruc->getGeomIndex(PartId, ThetaIndex, PhiIndex);
317}
318
319
320unsigned int EmcCalibConstSvc::getPartID(int Index) const
321{
322 return m_theEmcStruc->getPartId(Index);
323}
324
325unsigned int EmcCalibConstSvc::getThetaIndex( int Index) const
326{
327 return m_theEmcStruc->getTheta(Index);
328}
329
330unsigned int EmcCalibConstSvc::getPhiIndex( int Index) const
331{
332 return m_theEmcStruc->getPhi(Index);
333}
334
335
336
338{
339 return m_CrystalEmaxData[Index];
340}
341
343{
344 return m_CrystalDeadEcut[Index];
345}
346
347
349{
350 /*
351 for(int iNo=0;iNo<6;iNo++){
352 cout<<"getDigiCalibConst "<<getDigiCalibConst(iNo)<<endl;
353 }
354
355 cout<<"getDigiCalibConstNo "<<getDigiCalibConstNo()<<endl;
356
357
358 cout<<"ind"<<" "<<"getThetaIndex(ind)"<<" "
359 <<"getPhiIndex(ind)"<<"getPartID"<<endl;
360
361 for(int ind=0; ind<6240;ind++){
362
363 cout<<ind<<" "<<getThetaIndex(ind)<<" "
364 <<getPhiIndex(ind)<<" "<<getPartID(ind)<<endl;
365
366 }
367
368 cout<<"getIndex(0,5,95)="<<getIndex(0,5,95)<<endl;
369 cout<<"getIndex(1,43,119)="<<getIndex(1,43,119)<<endl;
370 cout<<"getIndex(2,5,95)="<<getIndex(2,5,95)<<endl;
371 cout<<"getIndex(0,5,96)="<<getIndex(0,5,96)<<endl;
372 cout<<"getIndex(1,43,120)="<<getIndex(1,43,120)<<endl;
373 cout<<"getIndex(2,5,96)="<<getIndex(2,5,96)<<endl;
374 */
375 for(int i=0;i<6240;i++){
376 cout<<i<<"\t"<<getCrystalEmaxData(i) <<endl;
377 }
378
379
380}
381
382
EmcCalibConstSvc(const std::string &name, ISvcLocator *svcloc)
double m_CrystalDeadEcut_2020[6240]
void handle(const Incident &)
double m_CrystalEmaxData_2[6240]
virtual StatusCode finalize()
double m_CrystalEmaxData[6240]
void setCrystalDeadEcut(double CrystalDeadEcut[6240])
int getIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const
virtual StatusCode initialize()
double m_CrystalEmaxData_1[6240]
int getIxtalNumberNo() const
unsigned int getPartID(int Index) const
double m_CrystalDeadEcut[6240]
void setCrystalEmaxData(double CrystalEmaxData[6240])
int getDigiCalibConstNo() const
int getIxtalNumber(int No) const
double getCrystalEmaxData(int Index) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
EmcStructure * m_theEmcStruc
unsigned int getPhiIndex(int Index) const
IDataProviderSvc * m_calDataSvc
unsigned int getThetaIndex(int Index) const
double getDigiCalibConst(int No) const
double getCrystalDeadEcut(int Index) const
int getGeomIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const
void setEmcStruc()
unsigned int getPartId(long Index) const
Definition: EmcStructure.h:35
unsigned int getPhi(long Index) const
Definition: EmcStructure.h:37
unsigned int getTheta(long Index) const
Definition: EmcStructure.h:36