BOSS 7.0.8
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 }
50 return;
51}
52
53StatusCode EmcRawDataProvider::initialize(bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg){
54
56 // test cut value
57 MsgStream log(m_msgSvc, m_name);
58 if(log.level()<=MSG::INFO){
59 std::cout << "EmcRawDataProvider:: " << "elow=" << m_adcLowThreshold << ", tlow=" << m_tLowThreshold
60 << ", thigh=" << m_tHighThreshold << std::endl;
61 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
62 std::cout << " hot crystals ";
63 for(;it!=m_hotCrystals.end();it++){
64 std::cout << *it << " ";
65 }
66 std::cout << std::endl << " dead crystals ";
67 for(it=m_deadCrystals.begin();it!=m_deadCrystals.end();it++){
68 std::cout << *it << " ";
69 }
70 std::cout << std::endl;
71 }
72
73 // get point of EMC calibration service
74 StatusCode sc = m_svcLocator->service("EmcCalibConstSvc", m_emcCalibConstSvc);
75 if(sc != StatusCode::SUCCESS) {
76 log << MSG::ERROR << "Can't get EmcCalibConstSvc." << endreq;
77 m_emcCalibConstSvc=0;
78 }
79 else if(mode) m_emcCalibConstSvc->getDigiCalibConst(0);
80
81 return StatusCode::SUCCESS;
82}
83
84bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, uint32_t id, uint32_t measure,
85 uint32_t adc, uint32_t tdc){
86 if(control&DropLow) {
87 if(measure==0&&adc<m_adcLowThreshold) return false;
88 }
89 if(control&DropFull) {
90 if(measure==3) return false;
91 }
92 if(control&CutTime) {
93 if(tdc<m_tLowThreshold||tdc>m_tHighThreshold) return false;
94 }
95 if(control&DropHot) {
96 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
97 for(;it!=m_hotCrystals.end();it++){
98 if((*it)==id) return false;
99 }
100 }
101 if(control&DropDead) {
102 std::vector<uint32_t>::iterator it=m_deadCrystals.begin();
103 for(;it!=m_deadCrystals.end();it++){
104 if((*it)==id) return false;
105 }
106 }
107 return true;
108}
109
110bool EmcRawDataProvider::isGoodEmcDigi(uint32_t control, EmcDigi* emcDigi){
111 uint32_t adc=emcDigi->getChargeChannel();
112 uint32_t measure=emcDigi->getMeasure();
113 uint32_t tdc=emcDigi->getTimeChannel();
114 Identifier id=emcDigi->identify();
115 return isGoodEmcDigi(control,id.get_value(),measure,adc,tdc);
116}
117
118void EmcRawDataProvider::doCalib(Identifier& id, uint32_t& measure, uint32_t& adc){
119
120 uint32_t part = EmcID::barrel_ec(id);
121 uint32_t itheta = EmcID::theta_module(id);
122 uint32_t iphi = EmcID::phi_module(id);
123 int index = m_emcCalibConstSvc->getIndex(part,itheta,iphi);
124 double adc2e = m_emcCalibConstSvc->getDigiCalibConst(index);
125 double e = RawDataUtil::EmcCharge(measure, adc)*adc2e;
126
129}
130
132 Identifier id=emcDigi->identify();
133 uint32_t adc=emcDigi->getChargeChannel();
134 uint32_t measure=emcDigi->getMeasure();
135 doCalib(id,measure,adc);
136 emcDigi->setChargeChannel(adc);
137 emcDigi->setMeasure(measure);
138}
139
141 MsgStream log(m_msgSvc, m_name);
142 log << MSG::INFO << "EmcRawDataProvider::getEmcDigiVec..." << endreq;
143 log << MSG::DEBUG << "vector size=" << m_emcDigiVec.size() << endreq;
144
145 if(m_emcDigiVec.size()>0){
146 if(control&Redo) m_emcDigiVec=EmcDigiCol();
147 else return m_emcDigiVec;
148 }
149 // Retrieve Hits Collection
150 // tianhl for mt
151 std::string evtDataSvc_name("EventDataSvc");
152 if(isGaudiThreaded(m_name)){
153 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
154 }
155 // tianhl for mt
156 IDataProviderSvc* evtSvc;
157 StatusCode sc = m_svcLocator->service(evtDataSvc_name.c_str(),evtSvc,true);
158 if (!sc.isSuccess()){
159 log << MSG::FATAL << "EmcRawDataProvider: ERROR Could not load EventDataSvc" << endreq;
160 }
161
162 SmartDataPtr<EmcDigiCol> emcDigiCol(evtSvc,"/Event/Digi/EmcDigiCol");
163 if (!emcDigiCol) {
164 log << MSG::FATAL << "Could not find Emc digi!!" << endreq;
165 return m_emcDigiVec;
166 }
167 log << MSG::DEBUG << "start dealing with EmcRawCol " << emcDigiCol->size() << endreq;
168 EmcDigiCol::iterator iterEMC=emcDigiCol->begin();
169 for(;iterEMC!= emcDigiCol->end();iterEMC++) {
170 log << MSG::NIL << "vector size=" << m_emcDigiVec.size() << endreq;
171 if(isGoodEmcDigi(control,*iterEMC)) m_emcDigiVec.insert(m_emcDigiVec.end(),*iterEMC);
172 if(control&DoCalib) {
173 if(m_emcCalibConstSvc!=0) doCalib(*iterEMC);
174 else {
175 log << MSG::WARNING << "require EMC calibration, but none service, ignore." << endreq;
176 }
177 }
178 if(control&DoOther) { }
179 }
180 log << MSG::VERBOSE << "ready for return" << endreq;
181 return m_emcDigiVec;
182}
183
185 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
186 for(;it!=m_hotCrystals.end();it++){
187 if((*it)==teid) {
188 m_hotCrystals.erase(it);
189 break;
190 }
191 }
192 if(it==m_hotCrystals.end()) return false;
193
194 return true;
195}
196
198 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
199 for(;it!=m_deadCrystals.end();it++){
200 if((*it)==teid) {
201 m_deadCrystals.erase(it);
202 break;
203 }
204 }
205 if(it==m_deadCrystals.end()) return false;
206
207 return true;
208}
209
211 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
212 for(;it!=m_hotCrystals.end();it++){
213 if((*it)==teid) break;
214 }
215 if(it==m_hotCrystals.end()) m_hotCrystals.push_back(teid);
216
217 return;
218}
219
221 std::vector<uint32_t>::iterator it=m_hotCrystals.begin();
222 for(;it!=m_deadCrystals.end();it++){
223 if((*it)==teid) break;
224 }
225 if(it==m_deadCrystals.end()) m_deadCrystals.push_back(teid);
226
227 return;
228}
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)
ISvcLocator * m_svcLocator
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