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