BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcRawDataProvider.cxx
Go to the documentation of this file.
1//*******************************
2#include "GaudiKernel/MsgStream.h"
3//#include "GaudiKernel/Bootstrap.h"
4#include "GaudiKernel/SmartDataPtr.h"
5//#include "GaudiKernel/Service.h"
6//#include "GaudiKernel/DataSvc.h"
8#include "Identifier/EmcID.h"
10#include "EmcRawEvent/EmcDigi.h"
11//#include <exception>
12// tianhl for mt
13#include "GaudiKernel/ThreadGaudi.h"
14// tianhl for mt
15
17
20 m_adcLowThreshold(0), m_tLowThreshold(0), m_tHighThreshold(60),
21 m_hotCrystals(0), m_deadCrystals(0),
22 m_emcDigiVec(){
23 m_emcCalibConstSvc=0;
24}
25
26EmcRawDataProvider::EmcRawDataProvider(const char* name, uint32_t elow, uint32_t tlow, uint32_t thigh):
28 m_adcLowThreshold(elow), m_tLowThreshold(tlow), m_tHighThreshold(thigh),
29 m_hotCrystals(0), m_deadCrystals(0),
30 m_emcDigiVec(){
31 m_emcCalibConstSvc=0;
32}
33
34EmcRawDataProvider::EmcRawDataProvider(const char* name,std::vector<uint32_t>& hot, std::vector<uint32_t>& dead,
35 uint32_t elow, uint32_t tlow, uint32_t thigh):
37 m_adcLowThreshold(elow), m_tLowThreshold(tlow), m_tHighThreshold(thigh),
38 m_hotCrystals(hot), m_deadCrystals(dead),
39 m_emcDigiVec(){
40 m_emcCalibConstSvc=0;
41}
42
43void EmcRawDataProvider::handle(const Incident& inc){
44 MsgStream log(m_msgSvc, m_name);
45 log << MSG::DEBUG << "inc.type=" << inc.type() << endreq;
46 if ( inc.type() == "BeginEvent" ){
47 //EmcDigiCol empty;
48 //m_emcDigiVec=empty;
49 m_emcDigiVec.clear();
50 }
51 return;
52}
53
54StatusCode EmcRawDataProvider::initialize(bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg){
55
57 // test cut value
58 MsgStream log(m_msgSvc, m_name);
59 if(log.level()<=MSG::INFO){
60 std::cout << "EmcRawDataProvider:: " << "elow=" << m_adcLowThreshold << ", tlow=" << m_tLowThreshold
61 << ", thigh=" << m_tHighThreshold << std::endl;
62 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
63 std::cout << " hot crystals ";
64 for(;it!=m_hotCrystals.end();it++){
65 std::cout << *it << " ";
66 }
67 std::cout << std::endl << " dead crystals ";
68 for(it=m_deadCrystals.begin();it!=m_deadCrystals.end();it++){
69 std::cout << *it << " ";
70 }
71 std::cout << std::endl;
72 }
73
74 // get point of EMC calibration service
75 StatusCode sc = m_svcLocator->service("EmcCalibConstSvc", m_emcCalibConstSvc);
76 if(sc != StatusCode::SUCCESS) {
77 log << MSG::ERROR << "Can't get EmcCalibConstSvc." << endreq;
78 m_emcCalibConstSvc=0;
79 }
80 else if(mode) m_emcCalibConstSvc->getDigiCalibConst(0);
81
82 return StatusCode::SUCCESS;
83}
84
85bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, uint32_t id, uint32_t measure,
86 uint32_t adc, uint32_t tdc){
87 if(control&DropLow) {
88 if(measure==0&&adc<m_adcLowThreshold) return false;
89 }
90 if(control&DropFull) {
91 if(measure==3) return false;
92 }
93 if(control&CutTime) {
94 if(tdc<m_tLowThreshold||tdc>m_tHighThreshold) return false;
95 }
96 if(control&DropHot) {
97 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
98 for(;it!=m_hotCrystals.end();it++){
99 if((*it)==id) return false;
100 }
101 }
102 if(control&DropDead) {
103 std::vector<uint32_t>::iterator it=m_deadCrystals.begin();
104 for(;it!=m_deadCrystals.end();it++){
105 if((*it)==id) return false;
106 }
107 }
108 return true;
109}
110
111bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, EmcDigi* emcDigi){
112 uint32_t adc=emcDigi->getChargeChannel();
113 uint32_t measure=emcDigi->getMeasure();
114 uint32_t tdc=emcDigi->getTimeChannel();
115 Identifier id=emcDigi->identify();
116 return isGoodEmcDigi(control,id.get_value(),measure,adc,tdc);
117}
118
119void EmcRawDataProvider::doCalib(Identifier& id, uint32_t& measure, uint32_t& adc){
120
121 uint32_t part = EmcID::barrel_ec(id);
122 uint32_t itheta = EmcID::theta_module(id);
123 uint32_t iphi = EmcID::phi_module(id);
124 int index = m_emcCalibConstSvc->getIndex(part,itheta,iphi);
125 double adc2e = m_emcCalibConstSvc->getDigiCalibConst(index);
126 double e = RawDataUtil::EmcCharge(measure, adc)*adc2e;
127
130}
131
133 Identifier id=emcDigi->identify();
134 uint32_t adc=emcDigi->getChargeChannel();
135 uint32_t measure=emcDigi->getMeasure();
136 doCalib(id,measure,adc);
137 emcDigi->setChargeChannel(adc);
138 emcDigi->setMeasure(measure);
139}
140
142 MsgStream log(m_msgSvc, m_name);
143 log << MSG::INFO << "EmcRawDataProvider::getEmcDigiVec..." << endreq;
144 log << MSG::DEBUG << "vector size=" << m_emcDigiVec.size() << endreq;
145
146 if(m_emcDigiVec.size()>0){
147 if(control&Redo) m_emcDigiVec.clear();
148 else return m_emcDigiVec;
149 }
150 // Retrieve Hits Collection
151 // tianhl for mt
152 std::string evtDataSvc_name("EventDataSvc");
153 if(isGaudiThreaded(m_name)){
154 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
155 }
156 // tianhl for mt
157 IDataProviderSvc* evtSvc;
158 StatusCode sc = m_svcLocator->service(evtDataSvc_name.c_str(),evtSvc,true);
159 if (!sc.isSuccess()){
160 log << MSG::FATAL << "EmcRawDataProvider: ERROR Could not load EventDataSvc" << endreq;
161 }
162
163 SmartDataPtr<EmcDigiCol> emcDigiCol(evtSvc,"/Event/Digi/EmcDigiCol");
164 if (!emcDigiCol) {
165 log << MSG::FATAL << "Could not find Emc digi!!" << endreq;
166 return m_emcDigiVec;
167 }
168 log << MSG::DEBUG << "start dealing with EmcRawCol " << emcDigiCol->size() << endreq;
169 EmcDigiCol::iterator iterEMC=emcDigiCol->begin();
170 for(;iterEMC!= emcDigiCol->end();iterEMC++) {
171 log << MSG::NIL << "vector size=" << m_emcDigiVec.size() << endreq;
172 if(isGoodEmcDigi(control,*iterEMC)) m_emcDigiVec.insert(m_emcDigiVec.end(),*iterEMC);
173 if(control&DoCalib) {
174 if(m_emcCalibConstSvc!=0) doCalib(*iterEMC);
175 else {
176 log << MSG::WARNING << "require EMC calibration, but none service, ignore." << endreq;
177 }
178 }
179 if(control&DoOther) { }
180 }
181 log << MSG::VERBOSE << "ready for return" << endreq;
182 return m_emcDigiVec;
183}
184
186 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
187 for(;it!=m_hotCrystals.end();it++){
188 if((*it)==teid) {
189 m_hotCrystals.erase(it);
190 break;
191 }
192 }
193 if(it==m_hotCrystals.end()) return false;
194
195 return true;
196}
197
199 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
200 for(;it!=m_deadCrystals.end();it++){
201 if((*it)==teid) {
202 m_deadCrystals.erase(it);
203 break;
204 }
205 }
206 if(it==m_deadCrystals.end()) return false;
207
208 return true;
209}
210
212 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
213 for(;it!=m_hotCrystals.end();it++){
214 if((*it)==teid) break;
215 }
216 if(it==m_hotCrystals.end()) m_hotCrystals.push_back(teid);
217
218 return;
219}
220
222 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
223 for(;it!=m_deadCrystals.end();it++){
224 if((*it)==teid) break;
225 }
226 if(it==m_deadCrystals.end()) m_deadCrystals.push_back(teid);
227
228 return;
229}
ObjectVector< EmcDigi > EmcDigiCol
Definition EmcDigi.h:43
unsigned int getMeasure() const
Definition EmcDigi.h:27
void setMeasure(const unsigned int measure)
Definition EmcDigi.h:24
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition EmcID.cxx:48
bool removeDeadCrystal(const uint32_t id)
bool isGoodEmcDigi(uint32_t control, uint32_t id, uint32_t measure, uint32_t adc, uint32_t tdc)
bool removeHotCrystal(const uint32_t id)
void doCalib(Identifier &id, uint32_t &measure, uint32_t &adc)
EmcDigiCol & getEmcDigiVec(uint32_t control)
void addDeadCrystal(const uint32_t id)
void addHotCrystal(const uint32_t id)
void handle(const Incident &)
virtual StatusCode initialize(bool mode=0, ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
virtual double getDigiCalibConst(int No) const =0
virtual int getIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const =0
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
static int EmcChargeChannel(double charge)
Definition RawDataUtil.h:37
static int EmcChargeMeasure(double charge)
Definition RawDataUtil.h:50
static double EmcCharge(int measure, int chargeChannel)
Definition RawDataUtil.h:17
virtual Identifier identify() const
Definition RawData.cxx:15
void setChargeChannel(const unsigned int chargeChannel)
Definition RawData.cxx:30
unsigned int getChargeChannel() const
Definition RawData.cxx:45
unsigned int getTimeChannel() const
Definition RawData.cxx:40