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