33{
34 MsgStream log(
msgSvc(), name());
35 log << MSG::INFO << "in execute()" << endreq;
36
37
38 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
39 if (!eventHeader) {
40 log << MSG::FATAL << "Could not find Event Header" << endreq;
41 return StatusCode::FAILURE;
42 }
43 log << MSG::DEBUG << "Retrieved event: " << eventHeader->eventNumber()
44 << " run: " << eventHeader->runNumber() << endreq;
45
46
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;
55 }
56 }
57
60 if ( sc.isFailure() ) {
61 log << MSG::FATAL << "Could not register RecZddChannelCol" << endreq;
62 return StatusCode::FAILURE;
63 }
64
65
66
67 if ( m_errStat ) return StatusCode::SUCCESS;
68
69
70 SmartDataPtr<Event::ZddEvent> zddEvt(eventSvc(),"/Event/ZddEvent");
71 int zddCheck = zddDataStat(zddEvt.ptr(), eventHeader->eventNumber()+1);
72
73 if ( zddCheck != 0 ) {
74 if ( zddCheck < 0 ) {
75
76 m_errStat = true;
77
78 if ( m_errQuit ) {
79 return StatusCode::FAILURE;
80 }
81 }
82
83
84 return StatusCode::SUCCESS;
85 }
86
87
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;
92
93 }
94 else {
95 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
96 if (iter_evt != evTimeCol->end()) {
97 bes3_t0 = (*iter_evt)->getTest();
98
99 bes3_t0 = 6400 - bes3_t0;
100 }
101 }
102
103
105
106
107 Event::ZddEvent::Channels::const_iterator end_ch = chs.end();
108 for ( Event::ZddEvent::Channels::const_iterator it = chs.begin(); it != end_ch; ++it ) {
111
112
116 double e_K = getEK(pch->
getChId());
117
118
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;
124 int start = 0;
125 for ( ZddChannel::Fragments::const_iterator jt = frags.begin(); jt != end_fg; ++jt) {
127
128
129
130
131
133
134
135 if ( start+frag.
length > maxSamples ) {
137 MsgStream log(
msgSvc(), name());
138 log << MSG::ERROR << "ZDD BAD DATA: CAEN corruption problem" << endreq;
139 quit_event = true;
140 break;
141 }
142
143 for (
int i = 0; i < frag.
length; ++i ) waveform[start++] = frag.
sample[i];
144 }
145
146
147 unsigned char threshold = 20;
148 unsigned char rephaseThreshold = 40;
149 unsigned char minSample = 255, maxSample = -1;
150 int maxTime = -1;
151 bool closed = true;
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 ) {
158 if ( closed ) {
159 closed = false;
160 maxSample = waveform[pt];
161 maxTime = pt;
162 } else {
163 if ( waveform[pt] > maxSample ) {
164 maxSample = waveform[pt];
165 maxTime = pt;
166 }
167 }
168 } else {
169 if ( ! closed ) {
170 closed = true;
171 double tNsec = 2.*maxTime;
173
174 if ( maxSample > rephaseThreshold ) {
175 int phase = maxTime%4;
176 phases[phase]++;
177 }
178 }
179 }
180 }
181 if ( ! closed ) {
182 closed = true;
183 double tNsec = 2.*maxTime;
185
186 if ( maxSample > rephaseThreshold ) {
187 int phase = maxTime%4;
188 phases[phase]++;
189 }
190 }
191
192
193 int mostProb = -1;
194 int chPhase = -1;
195 for (int ph=0; ph<4; ph++) {
196 if ( phases[ph] > mostProb ) {
197 mostProb = phases[ph];
198 chPhase = ph;
199 }
200 }
201
202 if ( chPhase==-1 ) {
204 chPhase = -2;
205 }
206
209 recZddCol->push_back(recZddCh);
210
211
212
213
214
215
216
217
218
219
220
221
222 if ( quit_event ) break;
223
224 }
225 return StatusCode::SUCCESS;
226}
ObjectVector< RecZddChannel > RecZddChannelCol
std::vector< ZddChannel * > Channels
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
_EXTERN_ std::string RecZddChannelCol