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