BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcRawDataProvider.cxx
Go to the documentation of this file.
1#include "RawDataProviderSvc/MdcRawDataProvider.h"
2#include "EvTimeEvent/RecEsTime.h"
3#include "GaudiKernel/DataSvc.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/IIncidentListener.h"
6#include "GaudiKernel/IIncidentSvc.h"
7#include "GaudiKernel/IInterface.h"
8#include "GaudiKernel/Incident.h"
9#include "GaudiKernel/Kernel.h"
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/SmartDataPtr.h"
12#include "GaudiKernel/StatusCode.h"
13#include "Identifier/MdcID.h"
14#include "MdcCalibFunSvc/IMdcCalibFunSvc.h"
15#include "MdcRecEvent/RecMdcHit.h"
16#include "RawEvent/RawDataUtil.h"
17
18// tianhl for mt
19// #include "GaudiKernel/ThreadGaudi.h"
20// tianhl for mt
21#include <stdint.h>
22#include <vector>
23
24using namespace std;
25
27 : RawDataProviderBase(), digiRef( 0 ), m_mdcCalibFunSvc( 0 ) {}
28
30 : RawDataProviderBase( name ), digiRef( 0 ), m_mdcCalibFunSvc( 0 ) {}
31
33
34StatusCode MdcRawDataProvider::initialize( ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
35 RawDataProviderBase::initialize( pSvcLoc, pMsg );
36 return StatusCode::SUCCESS;
37}
38
39void MdcRawDataProvider::handle( const Incident& inc ) {
40 MsgStream log( m_msgSvc, m_name );
41 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
42 if ( inc.type() == "BeginEvent" ) { digiRef.clear(); }
43 return;
44}
45
47 MsgStream log( m_msgSvc, m_name );
48 StatusCode sc;
49 bool unRedo = ( ( control & b_unRedo ) == b_unRedo );
50 if ( !unRedo ) digiRef.clear();
51 else if ( digiRef.size() > 0 ) return digiRef;
52 //---- get event service
53 IDataProviderSvc* evtSvc;
54 // tianhl for mt
55 std::string evtDataSvc_name( "EventDataSvc" );
56 // if (isGaudiThreaded(m_name)) {
57 // evtDataSvc_name += getGaudiThreadIDfromName(m_name);
58 // }
59 // tianhl for mt
60 sc = m_svcLocator->service( evtDataSvc_name, evtSvc, true );
61 if ( !sc.isSuccess() )
62 {
63 log << MSG::FATAL << "Could not load EventDataSvc" << endmsg;
64 return digiRef;
65 }
66
67 //---- get max MdcDigi
68 int maxMdcDigi = control & i_maxMdcDigi;
69
70 //---- prepare for drop Bad TDC
71 bool keepBadTdc = ( ( control & b_keepBadTdc ) != 0x10000 );
72 double t0 = 0.;
73 if ( keepBadTdc )
74 {
75 // get MdcCalibFunSvc
76 sc = m_svcLocator->service( "MdcCalibFunSvc", m_mdcCalibFunSvc );
77 if ( sc.isFailure() )
78 {
79 log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endmsg;
80 return digiRef;
81 }
82
83 // get event start time t0
84 SmartDataPtr<RecEsTimeCol> esTimeCol( evtSvc, "/Event/Recon/RecEsTimeCol" );
85 if ( !esTimeCol )
86 {
87 log << MSG::INFO << " Could not retrieve RecEsTimeCol" << endmsg;
88 keepBadTdc = false;
89 }
90 else if ( ( esTimeCol->size() == 0 ) )
91 {
92 log << MSG::INFO << " Could not retrieve RecEsTimeCol" << endmsg;
93 keepBadTdc = false;
94 }
95 else
96 {
97 RecEsTimeCol::iterator iter = esTimeCol->begin();
98 for ( ; iter != esTimeCol->end(); iter++ ) { t0 = ( *iter )->getTest(); }
99 } // end esTimeCol
100 }
101
102 //----- mark hit on track
103 bool m_hitInUse[43][288];
104 for ( int i = 0; i < 43; i++ )
105 {
106 for ( int j = 0; j < 288; j++ ) m_hitInUse[i][j] = false;
107 }
108 bool dropHot = ( ( control & b_dropHot ) == 0x4000 );
109 if ( dropHot )
110 {
111 SmartDataPtr<RecMdcHitCol> recHitCol( evtSvc, "/Event/Recon/RecMdcHitCol" );
112 if ( !recHitCol )
113 {
114 log << MSG::INFO << "Could not retrieve RecMdcHitCol" << endmsg;
115 dropHot = false;
116 }
117 else
118 {
119 RecMdcHitCol::iterator iter = recHitCol->begin();
120 for ( ; iter != recHitCol->end(); iter++ )
121 {
122 Identifier id = ( *iter )->getMdcId();
123 m_hitInUse[MdcID::layer( id )][MdcID::wire( id )] = true;
124 }
125 }
126 }
127
128 //----- mark skipped layers
129 bool isSkipLayers = ( ( control & b_keepSkipped ) != 0x8000 ) && ( m_skipLayers.size() > 0 );
130
131 bool skipLayer[43];
132 for ( int i = 0; i < 43; i++ ) { skipLayer[i] = false; }
133 for ( unsigned iSkip = 0; iSkip < m_skipLayers.size(); iSkip++ )
134 { skipLayer[m_skipLayers[iSkip]] = true; }
135
136 //----- loop MdcDigiCol to select------------------
137 int iDigi = 0;
138 int nMatchedDigi = 0;
139
140 SmartDataPtr<MdcDigiCol> mdcDigiCol( evtSvc, "/Event/Digi/MdcDigiCol" );
141 if ( sc != StatusCode::SUCCESS )
142 {
143 log << MSG::FATAL << "Could not find MdcDigiCol!" << endmsg;
144 return digiRef;
145 }
146 MdcDigiCol::iterator iter = mdcDigiCol->begin();
147 for ( ; iter != mdcDigiCol->end(); iter++, iDigi++ )
148 {
149 MdcDigi* aDigi = ( *iter );
150 Identifier id = aDigi->identify();
151 int layer = MdcID::layer( id );
152 int wire = MdcID::wire( id );
153 unsigned tdc = aDigi->getTimeChannel();
154 unsigned adc = aDigi->getChargeChannel();
155 unsigned overflow = aDigi->getOverflow();
156
157 // Give an adc threshold
158 if ( m_adcThresholds.size() > 0 && adc < m_adcThresholds[layer] ) continue;
159
160 //--0. skip dead channel
161 if ( ( ( control & b_keepAllChannel ) != 0x40000 ) && m_mdcCalibFunSvc &&
162 m_mdcCalibFunSvc->getWireEff( layer, wire ) < m_effThreshold )
163 continue;
164
165 //--1. drop Mdc layer hits
166 if ( isSkipLayers && skipLayer[layer] ) continue;
167
168 //--2. drop hit on track
169 if ( dropHot && m_hitInUse[layer][wire] ) continue;
170
171 //--3. drop unmatched, overflow and multi TDC
172 // overflow :
173 // 1, T overflow
174 // 2, Q overflow
175 // 4, multi TDC
176 // 8, multi TDC, earliest
177 if ( ( ( control & b_keepUnmatch ) != 0x2000 ) &&
178 ( ( ( overflow & 1 ) > 0 ) ||
179 ( ( ( overflow & 12 ) != 12 ) && ( ( overflow & 12 ) != 0 ) ) ||
180 ( tdc == 0x7FFFFFFF ) || ( adc == 0x7FFFFFFF ) ) )
181 { continue; }
182
183 //--4. drop bad hit(Tdc - t0 < -10 ns)
184 if ( keepBadTdc )
185 {
186 // Get T0
187 double T0Walk = 0.;
188 if ( m_mdcCalibFunSvc )
189 {
190 T0Walk = m_mdcCalibFunSvc->getT0( layer, wire ) +
191 m_mdcCalibFunSvc->getTimeWalk( layer, adc );
192 }
193 if ( ( RawDataUtil::MdcTime( tdc ) - T0Walk - t0 ) < -10. ) continue;
194 }
195
196 //--5. skip by max limit of digi number
197 nMatchedDigi++;
198 if ( ( maxMdcDigi > 0 ) && ( nMatchedDigi > maxMdcDigi ) )
199 {
200 digiRef.clear();
201 return digiRef;
202 }
203
204 digiRef.push_back( aDigi );
205 } // end loop of MdcDigiCol
206 return digiRef;
207}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< HoughRecHit > recHitCol
Definition Hough2D.h:22
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
Definition MdcID.cxx:47
static int wire(const Identifier &id)
Definition MdcID.cxx:52
void handle(const Incident &)
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
RawDataProviderBase(const char *name)
static double MdcTime(int timeChannel)
virtual Identifier identify() const
Definition RawData.cxx:15
unsigned int getChargeChannel() const
Definition RawData.cxx:35
unsigned int getTimeChannel() const
Definition RawData.cxx:32