124{
125
126
127 MsgStream log(
msgSvc(), name());
128 log << MSG::INFO << "In CgemMdcFitAlg execute()" << endreq;
129
130 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
131 if (!eventHeader) {
132 log << MSG::FATAL << "Could not find Event Header" << endreq;
133 return StatusCode::FAILURE;
134 }
135 int run = eventHeader->runNumber();
136 int evt = eventHeader->eventNumber();
137 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(), "/Event/Recon/RecMdcTrackCol");
138 if (!recMdcTrackCol){
139 log << MSG::WARNING << "Could not find RecMdcTrackCol" << endreq;
140 return StatusCode::SUCCESS;
141 }
142
143 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
144 if (!evTimeCol) {
145 log << MSG::WARNING<< "Could not retrieve RecEsTimeCol" << endreq;
146 return StatusCode::SUCCESS;
147 }else{
148 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
149 if (iter_evt != evTimeCol->end()){
150 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
151 }
152 }
153
154 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc(),"/Event/Digi/MdcDigiCol");
155 if (!mdcDigiCol) {
156 log << MSG::FATAL << "Could not find MdcDigiCol!" << endreq;
157 return StatusCode::SUCCESS;
158 }
159
160 if(m_filter){
162 lowPt_Evt.open(m_evtFile.c_str());
163 vector<int> evtlist;
164 int evtNum;
165 while( lowPt_Evt >> evtNum) {
166 evtlist.push_back(evtNum);
167 }
168 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),evt);
169 if( iter_evt == evtlist.end() ) { setFilterPassed(false); return StatusCode::SUCCESS; }
170 else setFilterPassed(true);
171 }
172
173 if(m_debug)cout<<endl;
174 if(m_debug)cout<<"run:"<<run<<" event:"<<evt<<endl;
175 if(m_tuple)getMcTruth();
176 if(m_debug)cout<<"tracks before fitting: "<<recMdcTrackCol->size()<<endl;
177
178 if(m_tuple){
179 m_run = run;
180 m_event = evt;
181 m_nTrkRec = recMdcTrackCol->size();
182 }
183
184 for(RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();itTrk != recMdcTrackCol->end();itTrk++)
185 {
186 HitRefVec vechits = (*itTrk)->getVecHits();
187 HitRefVec::iterator itHit = vechits.begin();
188 for( ; itHit != vechits.end(); itHit++)
189 {
190 double tdc = (*itHit)->getTdc();
191 double adc = (*itHit)->getAdc();
192 const Identifier mdcid = (*itHit)->getMdcId();
195
196 MdcDigiCol::iterator iterDigi = mdcDigiCol->begin();
197 for(; iterDigi != mdcDigiCol->end(); iterDigi++ ) {
198 if((*iterDigi)->identify() == mdcid) break;
199 }
200 if(tdc==0)tdc = (*iterDigi)->getTimeChannel();
201
202
203 bool used = false;
204 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
205 for(;imdcHit != mdcHitCol.end();imdcHit++){
206 if((*imdcHit)->mdcId() == mdcid){
207 used = true;
208
209 break;
210 }
211 }
212 if(used)continue;
213
216 mdcHitCol.push_back(mdcHit);
217 }
218 }
219
221 if(m_debugArbHit>0 ) m_par.
lPrint=8;
223
224
225
226
228
231
232 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
233 for(int itrk=0;itTrk != recMdcTrackCol->end(); itrk++,itTrk++)
234 {
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289 if(m_tuple){
290 m_trkidRec[itrk] = (*itTrk)->trackId();
291 m_drRec[itrk] = (*itTrk)->helix(0);
292 m_phi0Rec[itrk] = (*itTrk)->helix(1);
293 m_kappaRec[itrk] = (*itTrk)->helix(2);
294 m_dzRec[itrk] = (*itTrk)->helix(3);
295 m_tanlRec[itrk] = (*itTrk)->helix(4);
296 m_chargeRec[itrk] = (*itTrk)->charge() ;
297 m_statRec[itrk] = (*itTrk)->stat() ;
298 m_nhitsRec[itrk] = (*itTrk)->getNhits() ;
299 m_nclusterRec[itrk]= (*itTrk)->getNcluster() ;
300 m_nsterRec[itrk] = (*itTrk)->nster() ;
301 m_ndofRec[itrk] = (*itTrk)->ndof() ;
302 m_chi2Rec[itrk] = (*itTrk)->chi2() ;
303 m_pxRec[itrk] = (*itTrk)->px() ;
304 m_pyRec[itrk] = (*itTrk)->py() ;
305 m_pzRec[itrk] = (*itTrk)->pz() ;
306 m_pxyRec[itrk] = (*itTrk)->pxy() ;
307 m_pRec[itrk] = (*itTrk)->p() ;
308 m_xRec[itrk] = (*itTrk)->x() ;
309 m_yRec[itrk] = (*itTrk)->y() ;
310 m_zRec[itrk] = (*itTrk)->z() ;
311 m_rRec[itrk] = (*itTrk)->r() ;
312 m_thetaRec[itrk] = (*itTrk)->theta() ;
313 m_phiRec[itrk] = (*itTrk)->phi() ;
314 m_fiTermRec[itrk] = (*itTrk)->getFiTerm() ;
315 }
316
317 if(m_debug)cout<<"fitting track: "<<itrk<<endl;
318
319
320 float chisum =0.;
321 bool permitFlips = true;
322 bool lPickHits = true;
323 int trkId = (*itTrk)->trackId();
324 double dr = (*itTrk)->helix(0);
325 double phi0 = (*itTrk)->helix(1);
326 double kappa = (*itTrk)->helix(2);
327 double dz = (*itTrk)->helix(3);
328 double tanl = (*itTrk)->helix(4);
329 if(m_debug)cout<<"helix parameters before fitting: "<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl;
330
331
332
333 if(m_fit2D){
335
342 if (m_debug && fit_circle.
failure()){cout<<
"fit: "<<fit_circle<<endl;}
343 if (m_debug && check_circle.
failure()){cout<<
"check: "<<check_circle<<endl;}
345
346
350 if(phi0<0)phi0+=2*
M_PI;
351 kappa = par.
omega()*333.567;
352 if(m_debug)cout<<"helix parameters after 2D fitting: "<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl;
353 }
354
355
357
361
362
366 if (m_debug && fit_helix.
failure()){cout<<
"fit: "<<fit_helix<<endl;}
367 if (m_debug && check_helix.
failure()){cout<<
"check: "<<check_helix<<endl;}
369
373 if(phi0<0)phi0+=2*
M_PI;
374 kappa = par.
omega()*333.567;
377 if(m_debug)cout<<"helix parameters after fitting: "<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl<<endl;
378
379
380 int trkStat = 5;
381 if(m_changeTDS ==1)
updateTracks(trkId,helixTrk,(*itTrk),trkStat);
382
383
384
385
386 if(m_changeTDS ==2){
388
389 mdcTrackList.append(mdcTrack);
390 }
391
392 }
393
394 if(m_changeTDS ==2){
395 mdcTrackList.setNoInner(true);
396 if(m_removeBadTrack){
397 int nDeleted=mdcTrackList.arbitrateHits();
398 if(m_debug>0 && nDeleted>0)cout<<nDeleted<<" tracks have been deleted by MdcTrackList..arbitrateHits()"<<endl;
399 }
401 storeTracks(trackList_tds, hitList_tds,mdcTrackList);
402 }
403
404 if(m_tuple){
405 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(), "/Event/Recon/RecMdcTrackCol");
406 if (!recMdcTrackCol){
407 log << MSG::WARNING << "Could not find RecMdcTrackCol" << endreq;
408 return StatusCode::SUCCESS;
409 }
410 m_nTrkFit = recMdcTrackCol->size();
411 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
412 for(int itrk=0;itTrk != recMdcTrackCol->end(); itrk++,itTrk++)
413 {
414
415 m_trkidFit[itrk] = (*itTrk)->trackId();
416 m_drFit[itrk] = (*itTrk)->helix(0);
417 m_phi0Fit[itrk] = (*itTrk)->helix(1);
418 m_kappaFit[itrk] = (*itTrk)->helix(2);
419 m_dzFit[itrk] = (*itTrk)->helix(3);
420 m_tanlFit[itrk] = (*itTrk)->helix(4);
421 m_chargeFit[itrk] = (*itTrk)->charge() ;
422 m_statFit[itrk] = (*itTrk)->stat() ;
423 m_nhitsFit[itrk] = (*itTrk)->getNhits() ;
424 m_nclusterFit[itrk]= (*itTrk)->getNcluster() ;
425 m_nsterFit[itrk] = (*itTrk)->nster() ;
426 m_ndofFit[itrk] = (*itTrk)->ndof() ;
427 m_chi2Fit[itrk] = (*itTrk)->chi2() ;
428 m_pxFit[itrk] = (*itTrk)->px() ;
429 m_pyFit[itrk] = (*itTrk)->py() ;
430 m_pzFit[itrk] = (*itTrk)->pz() ;
431 m_pxyFit[itrk] = (*itTrk)->pxy() ;
432 m_pFit[itrk] = (*itTrk)->p() ;
433 m_xFit[itrk] = (*itTrk)->x() ;
434 m_yFit[itrk] = (*itTrk)->y() ;
435 m_zFit[itrk] = (*itTrk)->z() ;
436 m_rFit[itrk] = (*itTrk)->r() ;
437 m_thetaFit[itrk] = (*itTrk)->theta() ;
438 m_phiFit[itrk] = (*itTrk)->phi() ;
439 m_fiTermFit[itrk] = (*itTrk)->getFiTerm() ;
440 }
441 }
442
443
444 if(m_tuple)ntuple_evt->write();
445
446 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
447 for(;imdcHit != mdcHitCol.end();imdcHit++){
448 delete (*imdcHit);
449 }
450 mdcHitCol.clear();
451 return StatusCode::SUCCESS;
452}
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
void updateTracks(int trackId, TrkRecoTrk *trkRecoTrk, RecMdcTrack *recMdcTrack, int trkStat)
void compareTracks(MdcTrackList &mdcTrackList, double dzCut)
TrkErrCode check(TrkRecoTrk *trkRecoTrk, TrackType trackType)
TrkErrCode fit(RecMdcTrack *recMdcTrack, TrkRecoTrk *trkRecoTrk, TrackType trackType)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const