BOSS 7.0.9
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;
45
46
47
49
50 for(int i=0;i<6240;i++){
60
63 }
64
65 int ixtal;
66 double emaxData;
67 int Nixt=0;
68
69 ///for version 1/////////
70 string paraPath = getenv("EMCCALIBCONSTSVCROOT");
71 paraPath += "/share/emax_data.dat"; // version=1
72 ifstream in;
73 in.open(paraPath.c_str());
74 assert(in);
75
76 while (in.peek() != EOF)
77 {
78
79 in >> ixtal>>emaxData;
80
81 m_CrystalEmaxData_1[ixtal]=emaxData;
82 Nixt++;
83 // cout<<"readFile==============="<<emaxData<<endl;
84 }
85
86 in.close();
87 //at the end of version 1/////
88
89 ////version 2-4680data@2020///////////
90 string paraPath2 = getenv("EMCCALIBCONSTSVCROOT");
91 paraPath2 += "/share/emax_data_2.dat"; // version=2
92
93 ifstream in2;
94 in2.open(paraPath2.c_str());
95 assert(in2);
96
97 Nixt=0;
98 while (in2.peek() != EOF)
99 {
100
101 in2 >> ixtal>>emaxData;
102
103 m_CrystalEmaxData_2[ixtal]=emaxData;
104
105 Nixt++;
106 // cout<<"readFile2==============="<<emaxData<<endl;
107 }
108
109 in2.close();
110 //at the end of version 2/////
111
112 ////version 4740data@2021///////////
113 string paraPath4740 = getenv("EMCCALIBCONSTSVCROOT");
114 paraPath4740 += "/share/emax_data_4740.dat"; // version=4740
115
116 ifstream in4740;
117 in4740.open(paraPath4740.c_str());
118 assert(in4740);
119
120 Nixt=0;
121 while (in4740.peek() != EOF)
122 {
123
124 in4740 >> ixtal>>emaxData;
125
126 m_CrystalEmaxData_4740[ixtal]=emaxData;
127
128 Nixt++;
129 // cout<<"readFile4740==============="<<emaxData<<endl;
130 }
131
132 in4740.close();
133 //at the end of version 4740/////
134
135 ////version 4750data@2021///////////
136 string paraPath4750 = getenv("EMCCALIBCONSTSVCROOT");
137 paraPath4750 += "/share/emax_data_4750.dat"; // version=4750
138
139 ifstream in4750;
140 in4750.open(paraPath4750.c_str());
141 assert(in4750);
142
143 Nixt=0;
144 while (in4750.peek() != EOF)
145 {
146
147 in4750 >> ixtal>>emaxData;
148
149 m_CrystalEmaxData_4750[ixtal]=emaxData;
150
151 Nixt++;
152 // cout<<"readFile4750==============="<<emaxData<<endl;
153 }
154
155 in4750.close();
156 //at the end of version 4750/////
157
158 ////version 4780data@2021///////////
159 string paraPath4780 = getenv("EMCCALIBCONSTSVCROOT");
160 paraPath4780 += "/share/emax_data_4780.dat"; // version=4780
161
162 ifstream in4780;
163 in4780.open(paraPath4780.c_str());
164 assert(in4780);
165
166 Nixt=0;
167 while (in4780.peek() != EOF)
168 {
169
170 in4780 >> ixtal>>emaxData;
171
172 m_CrystalEmaxData_4780[ixtal]=emaxData;
173
174 Nixt++;
175 // cout<<"readFile4780==============="<<emaxData<<endl;
176 }
177
178 in4780.close();
179 //at the end of version 4780/////
180
181 ////version 4840data@2021///////////
182 string paraPath4840 = getenv("EMCCALIBCONSTSVCROOT");
183 paraPath4840 += "/share/emax_data_4840.dat"; // version=4840
184
185 ifstream in4840;
186 in4840.open(paraPath4840.c_str());
187 assert(in4840);
188
189 Nixt=0;
190 while (in4840.peek() != EOF)
191 {
192
193 in4840 >> ixtal>>emaxData;
194
195 m_CrystalEmaxData_4840[ixtal]=emaxData;
196
197 Nixt++;
198 // cout<<"readFile4840==============="<<emaxData<<endl;
199 }
200
201 in4840.close();
202 //at the end of version 4840/////
203
204
205 ////version 4914data@2021///////////
206 string paraPath4914 = getenv("EMCCALIBCONSTSVCROOT");
207 paraPath4914 += "/share/emax_data_4914.dat"; // version=4914
208
209 ifstream in4914;
210 in4914.open(paraPath4914.c_str());
211 assert(in4914);
212
213 Nixt=0;
214 while (in4914.peek() != EOF)
215 {
216
217 in4914 >> ixtal>>emaxData;
218
219 m_CrystalEmaxData_4914[ixtal]=emaxData;
220
221 Nixt++;
222 // cout<<"readFile4914==============="<<emaxData<<endl;
223 }
224
225 in4914.close();
226 //at the end of version 4914/////
227
228 ////version 4946data@2021///////////
229 string paraPath4946 = getenv("EMCCALIBCONSTSVCROOT");
230 paraPath4946 += "/share/emax_data_4946.dat"; // version=4946
231
232 ifstream in4946;
233 in4946.open(paraPath4946.c_str());
234 assert(in4946);
235
236 Nixt=0;
237 while (in4946.peek() != EOF)
238 {
239
240 in4946 >> ixtal>>emaxData;
241
242 m_CrystalEmaxData_4946[ixtal]=emaxData;
243
244 Nixt++;
245 // cout<<"readFile4946==============="<<emaxData<<endl;
246 }
247
248 in4946.close();
249 //at the end of version 4946/////
250
251
252 ////read dead channel energy threshould Ecut///////////
253 string paraPath3 = getenv("EMCCALIBCONSTSVCROOT");
254 paraPath3 += "/share/DeadThresholdEcut_2020.conf";
255
256 ifstream in3;
257 in3.open(paraPath3.c_str());
258 assert(in3);
259
260 Nixt=0;
261 double satuEn,Ecut;
262 double DeltaEcut=0.0;
263
264 while (in3.peek() != EOF)
265 {
266
267 in3 >> ixtal>>satuEn>>Ecut;
268 if ((Ecut-satuEn)>DeltaEcut) {
269 m_CrystalDeadEcut_2020[ixtal]=Ecut-DeltaEcut;
270 } else {
271 m_CrystalDeadEcut_2020[ixtal]=Ecut;
272 }
273 Nixt++;
274
275 }
276
277 in3.close();
278
279}
280
282
283}
284
285StatusCode EmcCalibConstSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
286 if( IID_IEmcCalibConstSvc.versionMatch(riid) ){
287 *ppvInterface = static_cast<IEmcCalibConstSvc*> (this);
288 } else{
289 return Service::queryInterface(riid, ppvInterface);
290 }
291 return StatusCode::SUCCESS;
292}
293
295 MsgStream log(messageService(), name());
296 log << MSG::INFO << "EmcCalibConstSvc::initialize()" << endreq;
297
298 StatusCode sc = Service::initialize();
299 if( sc.isFailure() ) return sc;
300
301
302 IIncidentSvc* incsvc;
303 sc = service("IncidentSvc", incsvc);
304 int priority = 100;
305 if( sc.isSuccess() ){
306 incsvc -> addListener(this, "NewRun", priority);
307 }
308
309 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
310 if (sc .isFailure() ) {
311 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
312 return sc;
313 }
314
315 sc = service("CalibDataSvc", m_calDataSvc, true);
316 if( sc == StatusCode::SUCCESS ){
317 log << MSG::INFO << "Retrieve IDataProviderSvc" << endreq;
318 }else{
319 log << MSG::FATAL << "can not get IDataProviderSvc" << endreq;
320 }
321
322 // sc = service("EmcRecGeoSvc", m_emcGeomSvc);
323 // if( sc != StatusCode::SUCCESS ){
324 // log << MSG::ERROR << "can not use EmcRecGeoSvc" << endreq;
325 // }
326
329
330 //Dump();
331 //cout<<"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EmcCalibConstSvc initialize"<<endl;
332 return StatusCode::SUCCESS;
333}
334
336
337 delete m_theEmcStruc;
338
339 MsgStream log(messageService(), name());
340 log << MSG::INFO << "EmcCalibConstSvc::finalize()" << endreq;
341 return StatusCode::SUCCESS;
342
343}
344
345void EmcCalibConstSvc::handle(const Incident& inc){
346 MsgStream log( messageService(), name() );
347 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
348
349
350
351 if ( inc.type() == "NewRun" ){
352 log << MSG::DEBUG << "NewRun" << endreq;
353
354
355 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
356 int run = eventHeader->runNumber();
357 //cout<<"&&&&&&&&&&&&&&:&&&&&&&&&&&&&&&&&&&& EmcCalibConstSvc handle,run="<<run<<endl;
358 if (run<0) run = -run;
359
360
361 log << MSG::DEBUG << "handle: " <<"Run in handle is: "<<run<< endreq;
362 //run <63075: EmaxVersion=1; run>=63075: EmaxVersion=2;
363 cout<< "handle: " <<"Run in handle is: "<<run<<endl;
364 if (run<63075&& !m_EmaxVersion1) {
366
367 m_EmaxVersion1=true;
368 m_EmaxVersion2=false;
369 m_EmaxVersion4740=false;
370 m_EmaxVersion4750=false;
371 m_EmaxVersion4780=false;
372 m_EmaxVersion4840=false;
373 m_EmaxVersion4914=false;
374 m_EmaxVersion4946=false;
375
376 cout<< "handle: " <<"EmaxVersion="<<"111111111111111"<<endl;
377 }
378
379
380 if (run>=63075&&run<=65207&& !m_EmaxVersion2) { // 2020 topup data~4680
382
383 m_EmaxVersion1=false;
384 m_EmaxVersion2=true;
385 m_EmaxVersion4740=false;
386 m_EmaxVersion4750=false;
387 m_EmaxVersion4780=false;
388 m_EmaxVersion4840=false;
389 m_EmaxVersion4914=false;
390 m_EmaxVersion4946=false;
391 cout<< "handle: " <<"EmaxVersion="<<"emax data from topup data 4680@2020"<<endl;
392 }
393
394
395 if (run>=65208&&run<=65321&& !m_EmaxVersion4740) { // 2021 data~4740
397
398 m_EmaxVersion1=false;
399 m_EmaxVersion2=false;
401 m_EmaxVersion4750=false;
402 m_EmaxVersion4780=false;
403 m_EmaxVersion4840=false;
404 m_EmaxVersion4914=false;
405 m_EmaxVersion4946=false;
406
407 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4740data@2021"<<endl;
408 }
409
410 if (run>=65322&&run<=65494&& !m_EmaxVersion4750) { // 2021 data~4750
412
413 m_EmaxVersion1=false;
414 m_EmaxVersion2=false;
415 m_EmaxVersion4740=false;
417 m_EmaxVersion4780=false;
418 m_EmaxVersion4840=false;
419 m_EmaxVersion4914=false;
420 m_EmaxVersion4946=false;
421
422 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4750data@2021"<<endl;
423 }
424
425 if (run>=65495&&run<=65646&& !m_EmaxVersion4780) { // 2021 data~4780
427
428 m_EmaxVersion1=false;
429 m_EmaxVersion2=false;
430 m_EmaxVersion4740=false;
431 m_EmaxVersion4750=false;
433 m_EmaxVersion4840=false;
434 m_EmaxVersion4914=false;
435 m_EmaxVersion4946=false;
436
437 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4780data@2021"<<endl;
438 }
439
440
441 if (run>=65647&&run<=65866&& !m_EmaxVersion4840) { // 2021 data~4840
443
444 m_EmaxVersion1=false;
445 m_EmaxVersion2=false;
446 m_EmaxVersion4740=false;
447 m_EmaxVersion4750=false;
448 m_EmaxVersion4780=false;
450 m_EmaxVersion4914=false;
451 m_EmaxVersion4946=false;
452
453 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4840data@2021"<<endl;
454 }
455
456 if (run>=65867&&run<=65937&& !m_EmaxVersion4914) { // 2021 data~4914
458
459 m_EmaxVersion1=false;
460 m_EmaxVersion2=false;
461 m_EmaxVersion4740=false;
462 m_EmaxVersion4750=false;
463 m_EmaxVersion4780=false;
464 m_EmaxVersion4840=false;
466 m_EmaxVersion4946=false;
467
468 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4914data@2021"<<endl;
469 }
470
471 if (run>=65938&& !m_EmaxVersion4946) { // 2021 data~4946
473
474 m_EmaxVersion1=false;
475 m_EmaxVersion2=false;
476 m_EmaxVersion4740=false;
477 m_EmaxVersion4750=false;
478 m_EmaxVersion4780=false;
479 m_EmaxVersion4840=false;
480 m_EmaxVersion4914=false;
482
483 cout<< "handle: " <<"EmaxVersion="<<"emax data from 4946data@2021"<<endl;
484 }
485
486 //if (run>=63075&&run<=65092&&!m_DeadEcutVersion2020){
490 cout<< "handle: " <<"DeadEcutVersion="<<"2020"<<endl;
491 }
492
493 //if(!getCrystalEmaxDataFileInfo()){
494 // log << MSG::ERROR << "can not find the crystal EmaxData file" << endreq;
495 //}
496
497 // Dump();
498 }
499
500
501}
502
503
504
506 {
507 double digiCalibConst = 0.0;
508 MsgStream log(messageService(), name());
509
510 std::string fullPath = "/Calib/EmcCal";
511 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
512 if( ! calConst ){
513 log << MSG::ERROR << "can not access to EmcDigi CalibData via SmartPtr"
514 << endreq;
515 }else {
516 digiCalibConst = calConst->getDigiCalibConst(No);
517 }
518
519 return digiCalibConst;
520}
521
523 {
524 int IxtalNumber = 999999;
525 MsgStream log(messageService(), name());
526
527 std::string fullPath = "/Calib/EmcCal";
528 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
529 if( ! calConst ){
530 log << MSG::ERROR << "can not access to EmcDigi CalibData via SmartPtr"
531 << endreq;
532 }else {
533 IxtalNumber = calConst->getIxtalNumber(No);
534 }
535
536 return IxtalNumber;
537}
538
540 {
541 int digiCalibConstNo = 0;
542 MsgStream log(messageService(), name());
543
544 std::string fullPath = "/Calib/EmcCal";
545 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
546 if( ! calConst ){
547 log << MSG::ERROR << "can not access to EmcDigiNo CalibData via SmartPtr"
548 << endreq;
549 }else {
550 digiCalibConstNo = calConst->getDigiCalibConstNo();
551 }
552
553 return digiCalibConstNo;
554}
555
557 {
558 int IxtalNumberNo = 0;
559 MsgStream log(messageService(), name());
560
561 std::string fullPath = "/Calib/EmcCal";
562 SmartDataPtr<CalibData::EmcCalibData> calConst(m_calDataSvc, fullPath);
563 if( ! calConst ){
564 log << MSG::ERROR << "can not access to EmcDigiNo CalibData via SmartPtr"
565 << endreq;
566 }else {
567 IxtalNumberNo = calConst->getIxtalNumberNo();
568 }
569
570 return IxtalNumberNo;
571}
572
573
574
575int EmcCalibConstSvc::getIndex( unsigned int PartId,
576 unsigned int ThetaIndex,
577 unsigned int PhiIndex) const
578{
579 return m_theEmcStruc->getGeomIndex(PartId, ThetaIndex, PhiIndex);
580}
581
582
583unsigned int EmcCalibConstSvc::getPartID(int Index) const
584{
585 return m_theEmcStruc->getPartId(Index);
586}
587
588unsigned int EmcCalibConstSvc::getThetaIndex( int Index) const
589{
590 return m_theEmcStruc->getTheta(Index);
591}
592
593unsigned int EmcCalibConstSvc::getPhiIndex( int Index) const
594{
595 return m_theEmcStruc->getPhi(Index);
596}
597
598
599
601{
602 return m_CrystalEmaxData[Index];
603}
604
606{
607 return m_CrystalDeadEcut[Index];
608}
609
610
612{
613 /*
614 for(int iNo=0;iNo<6;iNo++){
615 cout<<"getDigiCalibConst "<<getDigiCalibConst(iNo)<<endl;
616 }
617
618 cout<<"getDigiCalibConstNo "<<getDigiCalibConstNo()<<endl;
619
620
621 cout<<"ind"<<" "<<"getThetaIndex(ind)"<<" "
622 <<"getPhiIndex(ind)"<<"getPartID"<<endl;
623
624 for(int ind=0; ind<6240;ind++){
625
626 cout<<ind<<" "<<getThetaIndex(ind)<<" "
627 <<getPhiIndex(ind)<<" "<<getPartID(ind)<<endl;
628
629 }
630
631 cout<<"getIndex(0,5,95)="<<getIndex(0,5,95)<<endl;
632 cout<<"getIndex(1,43,119)="<<getIndex(1,43,119)<<endl;
633 cout<<"getIndex(2,5,95)="<<getIndex(2,5,95)<<endl;
634 cout<<"getIndex(0,5,96)="<<getIndex(0,5,96)<<endl;
635 cout<<"getIndex(1,43,120)="<<getIndex(1,43,120)<<endl;
636 cout<<"getIndex(2,5,96)="<<getIndex(2,5,96)<<endl;
637 */
638 for(int i=0;i<6240;i++){
639 cout<<i<<"\t"<<getCrystalEmaxData(i) <<endl;
640 }
641
642
643}
644
645
double m_CrystalEmaxData_4740[6240]
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])
double m_CrystalEmaxData_4946[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
double m_CrystalEmaxData_4840[6240]
double m_CrystalEmaxData_4750[6240]
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 m_CrystalEmaxData_4914[6240]
double m_CrystalEmaxData_4780[6240]
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