34 MsgStream log(
msgSvc(), name());
35 log << MSG::INFO <<
"in execute()" << endreq;
38 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
40 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
41 return StatusCode::FAILURE;
43 log << MSG::DEBUG <<
"Retrieved event: " << eventHeader->eventNumber()
44 <<
" run: " << eventHeader->runNumber() << endreq;
47 DataObject* aRecEvent = 0;
48 eventSvc()->findObject(
"/Event/Recon", aRecEvent);
49 if ( aRecEvent == 0 ) {
51 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon", aRecEvent);
52 if ( sc.isFailure() ) {
53 log << MSG::FATAL <<
"Could not register ReconEvent" << endreq;
54 return StatusCode::FAILURE;
60 if ( sc.isFailure() ) {
61 log << MSG::FATAL <<
"Could not register RecZddChannelCol" << endreq;
62 return StatusCode::FAILURE;
67 if ( m_errStat )
return StatusCode::SUCCESS;
70 SmartDataPtr<Event::ZddEvent> zddEvt(eventSvc(),
"/Event/ZddEvent");
71 int zddCheck = zddDataStat(zddEvt.ptr(), eventHeader->eventNumber()+1);
73 if ( zddCheck != 0 ) {
79 return StatusCode::FAILURE;
84 return StatusCode::SUCCESS;
88 double bes3_t0 = -10000.0;
89 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
90 if ( !evTimeCol || evTimeCol->size() == 0 ) {
91 log << MSG::WARNING <<
" Could not find RecEsTimeCol" << endreq;
95 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
96 if (iter_evt != evTimeCol->end()) {
97 bes3_t0 = (*iter_evt)->getTest();
99 bes3_t0 = 6400 - bes3_t0;
107 Event::ZddEvent::Channels::const_iterator end_ch = chs.end();
108 for ( Event::ZddEvent::Channels::const_iterator it = chs.begin(); it != end_ch; ++it ) {
116 double e_K = getEK(pch->
getChId());
119 int maxSamples = 800;
120 unsigned char waveform[800];
121 memset(waveform, 0, maxSamples);
122 ZddChannel::Fragments::const_iterator end_fg = frags.end();
123 bool quit_event =
false;
125 for ( ZddChannel::Fragments::const_iterator jt = frags.begin(); jt != end_fg; ++jt) {
135 if ( start+frag.
length > maxSamples ) {
137 MsgStream log(
msgSvc(), name());
138 log << MSG::ERROR <<
"ZDD BAD DATA: CAEN corruption problem" << endreq;
143 for (
int i = 0; i < frag.
length; ++i ) waveform[start++] = frag.
sample[i];
147 unsigned char threshold = 20;
148 unsigned char rephaseThreshold = 40;
149 unsigned char minSample = 255, maxSample = -1;
152 int phases[4] = {-1,-1,-1,-1};
153 for (
int pt=0; pt<maxSamples; pt++ ) {
154 bool notZero = waveform[pt]>0;
155 bool smaller = waveform[pt] < minSample;
156 if ( notZero && smaller ) minSample = waveform[pt];
157 if ( waveform[pt] > threshold ) {
160 maxSample = waveform[pt];
163 if ( waveform[pt] > maxSample ) {
164 maxSample = waveform[pt];
171 double tNsec = 2.*maxTime;
174 if ( maxSample > rephaseThreshold ) {
175 int phase = maxTime%4;
183 double tNsec = 2.*maxTime;
186 if ( maxSample > rephaseThreshold ) {
187 int phase = maxTime%4;
195 for (
int ph=0; ph<4; ph++) {
196 if ( phases[ph] > mostProb ) {
197 mostProb = phases[ph];
209 recZddCol->push_back(recZddCh);
222 if ( quit_event )
break;
225 return StatusCode::SUCCESS;