170 {
171 if ( !m_beginRun )
172 {
174 if ( sc.isFailure() )
175 {
176 error() <<
"beginRun failed" << endmsg;
177 return StatusCode::FAILURE;
178 }
179 m_beginRun = true;
180 }
181
182 MsgStream log(
msgSvc(), name() );
183 log << MSG::INFO << "in execute()" << endmsg;
184
185 setFilterPassed( false );
186
187 SmartDataPtr<Event::EventHeader> evtHead( eventSvc(), "/Event/EventHeader" );
188 if ( !evtHead )
189 {
190 log << MSG::FATAL << "Could not retrieve event header" << endmsg;
191 return StatusCode::FAILURE;
192 }
193 long t_runNo = evtHead->runNumber();
194 long t_evtNo = evtHead->eventNumber();
195 if ( m_debug )
196 std::cout << "sew " << ++i_evt << " run " << t_runNo << " evt " << t_evtNo << std::endl;
197
198
199 m_bunchT0 = -999.;
200 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
201 if ( !aevtimeCol || aevtimeCol->size() == 0 )
202 {
203 log << MSG::WARNING << "Could not find RecEsTimeCol" << endmsg;
204 return StatusCode::SUCCESS;
205 }
206 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
207 for ( ; iter_evt != aevtimeCol->end(); iter_evt++ ) { m_bunchT0 = ( *iter_evt )->getTest(); }
208
209
212 if ( !recMdcTrackCol || !recMdcHitCol ) return StatusCode::SUCCESS;
213 if ( 2 != recMdcTrackCol->size() )
214 {
216 return StatusCode::SUCCESS;
217 }
218 if ( m_debug ) std::cout << name() << " nTk==2 begin sewing" << std::endl;
219
220
221 double dParam[5] = { 0., 0., 0., 0., 0. };
222 float bprob = 0.;
223 float chisum = 0.;
224 RecMdcTrackCol::iterator besthel;
225
226 int besthelId = -999;
227 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
228 for ( int iTk = 0; it != recMdcTrackCol->end(); it++, iTk++ )
229 {
230 RecMdcTrack* tk = *it;
231 double Bz = m_bfield->bFieldNominal();
232 double d0 = -tk->
helix( 0 );
233 double phi0 = tk->
helix( 1 ) + CLHEP::halfpi;
234 double omega = Bz * tk->
helix( 2 ) / -333.567;
235 double z0 = tk->
helix( 3 );
236 double tanl = tk->
helix( 4 );
237
240
241 if ( m_debug )
242 std::cout << __FILE__ << " " << __LINE__ << "tk" << iTk << "(" << d0 << "," << phi0
243 << ","
244 << "," << omega << "," << z0 << "," << tanl << ")" << std::endl;
245
246 if ( iTk == 0 )
247 {
248 dParam[0] = d0;
249 dParam[1] = phi0;
250 dParam[2] = omega;
251 dParam[3] = z0;
252 dParam[4] = tanl;
253 }
254 else
255 {
256 dParam[0] += d0;
258 dParam[2] -= omega;
259 dParam[3] -= z0;
260 dParam[4] += tanl;
261 }
262
263 if ( phi0 < 0 )
264 {
265 besthelId = iTk;
266 besthel = it;
267 }
268 float bchisq = tk->
chi2();
269 int bndof = tk->
ndof();
271 chisum += bchisq;
272
273
274
275
276 }
277
278 if ( besthelId == -999 ) return StatusCode::SUCCESS;
279
280 TrkHelixMaker helixfactory;
282
283 if ( m_debug )
284 {
285 std::cout << __FILE__ << " param diff: "
286 << "\n D0 " << dParam[0] << "\n Phi0 " << dParam[1] << "\n Omega " << dParam[2]
287 << "\n Z0 " << dParam[3] << "\n Tanl " << dParam[4] << std::endl;
288 }
289
290 if ( m_hist )
291 {
292 m_csmcD0 = dParam[0];
293 m_csmcPhi0 = dParam[1];
294 m_csmcOmega = dParam[2];
295 m_csmcZ0 = dParam[3];
296 m_csmcTanl = dParam[4];
297 m_xtupleCsmcSew->write();
298 }
299
300
301 if ( ( fabs( dParam[0] ) > m_cosmicSewPar[0] ) ||
302 ( fabs( dParam[1] ) > m_cosmicSewPar[1] ) ||
303 ( fabs( dParam[2] ) > m_cosmicSewPar[2] ) ||
304 ( fabs( dParam[3] ) > m_cosmicSewPar[3] ) || ( fabs( dParam[4] ) > m_cosmicSewPar[4] ) )
305 {
306 if ( m_debug ) std::cout << __FILE__ << " 2 trk param not satisfied skip!" << std::endl;
307 if ( m_debug )
308 {
309 if ( fabs( dParam[0] ) > m_cosmicSewPar[0] ) std::cout << " cut by d0 " << std::endl;
310 if ( fabs( dParam[1] ) > m_cosmicSewPar[1] ) std::cout << " cut by phi0 " << std::endl;
311 if ( fabs( dParam[2] ) > m_cosmicSewPar[2] ) std::cout << " cut by omega " << std::endl;
312 if ( fabs( dParam[3] ) > m_cosmicSewPar[3] ) std::cout << " cut by z0" << std::endl;
313 if ( fabs( dParam[4] ) > m_cosmicSewPar[4] ) std::cout << " cut by tanl" << std::endl;
314 }
316 return StatusCode::SUCCESS;
317 }
318
319
320 RecMdcTrack* tk = *besthel;
321 double Bz = m_bfield->bFieldNominal();
322 double d0 = -tk->
helix( 0 );
323 double phi0 = tk->
helix( 1 ) + CLHEP::halfpi;
324 double omega = Bz * tk->
helix( 2 ) / -333.567;
325 double z0 = tk->
helix( 3 );
326 double tanl = tk->
helix( 4 );
327
328 TrkExchangePar tt( d0, phi0, omega, z0, tanl );
329 if ( m_debug )
330 std::cout << __FILE__ <<
" best helix: No." << tk->
trackId() <<
" Pat param=(" << d0 <<
" "
331 << phi0 << " " << omega << " " << z0 << " " << tanl << ")" << std::endl;
332
333
334 TrkRecoTrk* newTrack;
335 if ( m_lineFit )
336 {
337 newTrack = linefactory.
makeTrack( tt, chisum, *m_context, m_bunchT0 * 1.e-9 );
339 }
340 else
341 {
342 newTrack = helixfactory.
makeTrack( tt, chisum, *m_context, m_bunchT0 * 1.e-9 );
344 }
345
346
348 it = recMdcTrackCol->begin();
349 for ( int iTk = 0; it != recMdcTrackCol->end(); it++, iTk++ )
350 {
351 RecMdcTrack* tk = *it;
353 HepVector helixPatPar = m_mdcUtilitySvc->besPar2PatPar( tk->
helix() );
355 }
356
357
358
359
360 TrkErrCode err = newTrack->
hits()->
fit();
361 const TrkFit* newFit = newTrack->
fitResult();
362
363 if ( !newFit )
364 {
365
366 if ( m_debug ) std::cout << __FILE__ << " sew fit failed!!!" << std::endl;
367 HitRefVec::iterator it = skippedHits.begin();
368 for ( ; it != skippedHits.end(); ++it ) { delete it->data(); }
369 delete newTrack;
371 }
372 else
373 {
374
375
376
377 if ( m_lineFit ) { linefactory.
setFlipAndDrop( *newTrack,
false,
false ); }
379 if ( m_debug )
380 {
381 std::cout << __FILE__ << " sew cosmic fit good " << std::endl;
382 newTrack->
print( std::cout );
383 }
384
385 SmartDataPtr<MdcHitCol> m_hitCol( eventSvc(), "/Event/Hit/MdcHitCol" );
386 if ( !m_hitCol )
387 {
389 StatusCode sc = eventSvc()->registerObject( "/Event/Hit/MdcHitCol", m_hitCol );
390 if ( !sc.isSuccess() )
391 {
392 std::cout << " Could not register MdcHitCol" << endmsg;
393 return StatusCode::FAILURE;
394 }
395 }
396 uint32_t getDigiFlag = 0;
397 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
398 const MdcDigi* m_digiMap[43][288];
399 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
400 for ( ;
iter != mdcDigiVec.end();
iter++ )
401 {
402 const MdcDigi* aDigi = *
iter;
403 const Identifier
id = aDigi->
identify();
406 m_digiMap[layer][wire] = aDigi;
407 }
408
409
410 HitRefVec::iterator itHitSkipped = skippedHits.begin();
411 for ( ; itHitSkipped != skippedHits.end(); ++itHitSkipped )
412 {
413 RecMdcHit* h = *itHitSkipped;
417 double fltLen = 0.;
418 HepVector helix = newFit->
helix( fltLen ).
params();
421
422
423 double doca = m_mdcUtilitySvc->docaPatPar( layer, wire, helix, err );
424 double newDoca = fabs( doca );
426 if ( flagLR == 0 ) { newDoca = -fabs( doca ); }
428 if ( m_debug >= 3 )
429 std::cout << "(" << layer << "," << wire << ") new doca " << newDoca << " resid "
431 if ( m_debug >= 3 && fabs( fabs( newDoca ) - fabs( h->
getDriftDistLeft() ) ) > 0.02 )
432 std::cout <<
" bad resid " << fabs( fabs( newDoca ) - fabs( h->
getDriftDistLeft() ) )
434
435
436 MdcHit* thehit = new MdcHit( m_digiMap[layer][wire], m_gm );
440 m_hitCol->push_back( thehit );
441
443 Hep3Vector tempDir;
444 getInfo( helix, 0, poca, tempDir );
445 if ( m_debug > 3 ) std::cout << "track poca " << poca << std::endl;
447 Hep3Vector dir;
448 getInfo( helix, docaFltLen, pos, dir );
449
450 if ( pos.y() > poca.y() )
451 {
452 int wireAmb = patAmbig( flagLR );
453
454 double tof = docaFltLen /
Constants::c + ( m_bunchT0 ) * 1.e-9;
455
456
457
458 double eAngle = EntranceAngle( dir.phi() - thehit->
phi( pos.z() ) );
460 double z = pos.z();
461 double dist = thehit->
driftDist( tof, wireAmb, eAngle, dAngle, z );
462 double sigma = thehit->
sigma( dist, wireAmb, eAngle, dAngle, z );
463
464 if ( m_debug > 3 && fabs( fabs( h->
getDoca() ) - fabs( dist ) ) > 0.02 )
465 std::cout <<
"(" << layer <<
"," << wire <<
") old doca " << h->
getDoca()
467 << " newAmbig "
468 << wireAmb
469
470
472 << " " << std::endl;
477 }
478 }
479
480
481
482
483 store( newTrack, skippedHits );
484
485 setFilterPassed( true );
486 m_nSewed++;
487 }
488
489 if ( m_debug ) { m_mdcPrintSvc->printRecMdcTrackCol(); }
490
491 return StatusCode::SUCCESS;
492}
HepGeom::Point3D< double > HepPoint3D
std::vector< MdcDigi * > MdcDigiVec
ObjectVector< MdcHit > MdcHitCol
SmartRefVector< RecMdcHit > HitRefVec
float Mdcxprobab(int &ndof, float &chisq)
TrkSimpleMaker< TrkLineRep > TrkLineMaker
static const double twoPi
const double chi2() const
const int trackId() const
const HepVector helix() const
......
void setCosmicFit(const bool cosmicfit)
double sigma(double, int, double, double, double) const
void setCountPropTime(const bool count)
double driftDist(double, int, double, double, double) const
void setCalibSvc(const IMdcCalibFunSvc *calibSvc)
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
static int wire(const Identifier &id)
void clearRecMdcTrackHit()
void MdcxHitsToHots(HepVector &helix, TrkRecoTrk *trk, HitRefVec &hits, HitRefVec &skiped)
void store(TrkRecoTrk *tk, HitRefVec &skip)
virtual Identifier identify() const
const int getFlagLR(void) const
void setErrDriftDistRight(double erddr)
void setErrDriftDistLeft(double erddl)
void setDriftDistLeft(double ddl)
const Identifier getMdcId(void) const
void setDoca(double doca)
const double getDriftDistRight(void) const
const double getDriftDistLeft(void) const
const double getFltLen(void) const
const double getDoca(void) const
void setDriftDistRight(double ddr)
const double getErrDriftDistLeft(void) const
const HitRefVec getVecHits(void) const
const HepVector & params() const
const HepSymMatrix & covariance() const
virtual TrkExchangePar helix(double fltL) const =0
virtual void print(std::ostream &) const
const TrkFit * fitResult() const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const