1#include "ZddReconAlg/ZddReconAlg.h"
2#include "ReconEvent/ReconEvent.h"
3#include "ZddEvent/ZddBoard.h"
4#include "ZddEvent/RecZddChannel.h"
5#include "EvTimeEvent/RecEsTime.h"
6#include "EventModel/EventHeader.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/SmartDataPtr.h"
14 Algorithm(name, pSvcLocator),
17 declareProperty(
"BreakWithError", m_errQuit =
true);
23 MsgStream log(
msgSvc(), name());
24 log << MSG::INFO <<
"in initialize()" << endreq;
26 return StatusCode::SUCCESS;
32 MsgStream log(
msgSvc(), name());
33 log << MSG::INFO <<
"in execute()" << endreq;
36 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
38 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
39 return StatusCode::FAILURE;
41 log << MSG::DEBUG <<
"Retrieved event: " << eventHeader->eventNumber()
42 <<
" run: " << eventHeader->runNumber() << endreq;
45 DataObject* aRecEvent = 0;
46 eventSvc()->findObject(
"/Event/Recon", aRecEvent);
47 if ( aRecEvent == 0 ) {
49 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon", aRecEvent);
50 if ( sc.isFailure() ) {
51 log << MSG::FATAL <<
"Could not register ReconEvent" << endreq;
52 return StatusCode::FAILURE;
58 if ( sc.isFailure() ) {
59 log << MSG::FATAL <<
"Could not register RecZddChannelCol" << endreq;
60 return StatusCode::FAILURE;
65 if ( m_errStat )
return StatusCode::SUCCESS;
68 SmartDataPtr<Event::ZddEvent> zddEvt(eventSvc(),
"/Event/ZddEvent");
69 int zddCheck = zddDataStat(zddEvt.ptr(), eventHeader->eventNumber()+1);
71 if ( zddCheck != 0 ) {
77 return StatusCode::FAILURE;
82 return StatusCode::SUCCESS;
86 double bes3_t0 = -10000.0;
87 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
88 if ( !evTimeCol || evTimeCol->size() == 0 ) {
89 log << MSG::WARNING <<
" Could not find RecEsTimeCol" << endreq;
93 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
94 if (iter_evt != evTimeCol->end()) {
95 bes3_t0 = (*iter_evt)->getTest();
97 bes3_t0 = 6400 - bes3_t0;
105 Event::ZddEvent::Channels::const_iterator end_ch = chs.end();
106 for ( Event::ZddEvent::Channels::const_iterator it = chs.begin(); it != end_ch; ++it ) {
114 double e_K = getEK(pch->
getChId());
117 int maxSamples = 800;
118 unsigned char waveform[800];
119 memset(waveform, 0, maxSamples);
120 ZddChannel::Fragments::const_iterator end_fg = frags.end();
121 bool quit_event =
false;
123 for ( ZddChannel::Fragments::const_iterator jt = frags.begin(); jt != end_fg; ++jt) {
133 if ( start+frag.
length > maxSamples ) {
135 MsgStream log(
msgSvc(), name());
136 log << MSG::ERROR <<
"ZDD BAD DATA: CAEN corruption problem" << endreq;
141 for (
int i = 0; i < frag.
length; ++i ) waveform[start++] = frag.
sample[i];
145 unsigned char threshold = 20;
146 unsigned char rephaseThreshold = 40;
147 unsigned char minSample = 255, maxSample = -1;
150 int phases[4] = {-1,-1,-1,-1};
151 for (
int pt=0; pt<maxSamples; pt++ ) {
152 bool notZero = waveform[pt]>0;
153 bool smaller = waveform[pt] < minSample;
154 if ( notZero && smaller ) minSample = waveform[pt];
155 if ( waveform[pt] > threshold ) {
158 maxSample = waveform[pt];
161 if ( waveform[pt] > maxSample ) {
162 maxSample = waveform[pt];
169 double tNsec = 2.*maxTime;
172 if ( maxSample > rephaseThreshold ) {
173 int phase = maxTime%4;
181 double tNsec = 2.*maxTime;
184 if ( maxSample > rephaseThreshold ) {
185 int phase = maxTime%4;
193 for (
int ph=0; ph<4; ph++) {
194 if ( phases[ph] > mostProb ) {
195 mostProb = phases[ph];
207 recZddCol->push_back(recZddCh);
220 if ( quit_event )
break;
223 return StatusCode::SUCCESS;
229 MsgStream log(
msgSvc(), name());
230 log << MSG::INFO <<
"in finalize()" << endreq;
232 return StatusCode::SUCCESS;
235double ZddReconAlg::getEK(
int chId)
242 MsgStream log(
msgSvc(), name());
245 log << MSG::FATAL <<
"Could not find ZddEvent" << endreq;
250 const std::vector<ZddBoard*>& boards = zddEvt->
boards();
251 if ( boards.size() != 2 ) {
252 log << MSG::FATAL <<
"incomplete ZDD data, no more ZDD data this run!" << endreq;
256 if ( boards[0]->getCounter() != evtId || boards[1]->getCounter() != evtId )
258 log << MSG::FATAL <<
"missaligned ZDD triggers, no more ZDD data this run!" << endreq;
284int ZddReconAlg::calFragEandT(
const ZddFragment& frag,
int& efrag,
int& tfrag)
287 unsigned char min = 255,
max = 0;
288 for (
int i = 0; i < frag.
length; ++i ) {
289 unsigned char& sample = frag.
sample[i];
290 if ( sample <
min ) {
294 if ( sample >
max ) {
ObjectVector< RecZddChannel > RecZddChannelCol
std::vector< ZddChannel * > Channels
const Boards & boards() const
void setBaseLine(int baseLine)
void setScanCode(int scanCode)
void setChannelId(int chId)
void addFragment(int time, float energy)
const Fragments & fragments() const
std::vector< ZddFragment > Fragments
ZddReconAlg(const std::string &name, ISvcLocator *pSvcLocator)
_EXTERN_ std::string RecZddChannelCol