CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
TTrackManager.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TTrackManager.cxx,v 1.68.14.1 2013/03/04 07:22:52 xuqn Exp $
3//-----------------------------------------------------------------------------
4// Filename : TTrackManager.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A manager of TTrack information to make outputs as Reccdc_trk.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13/* for isnan */
14#if defined(__sparc)
15# if defined(__EXTENSIONS__)
16# include <cmath>
17# else
18# define __EXTENSIONS__
19# include <cmath>
20# undef __EXTENSIONS__
21# endif
22#elif defined(__GNUC__)
23# if defined(_XOPEN_SOURCE)
24# include <cmath>
25# else
26# define _XOPEN_SOURCE
27# include <cmath>
28# undef _XOPEN_SOURCE
29# endif
30#endif
31
32#define TTRACKMANAGER_INLINE_DEFINE_HERE
33#include <values.h>
34#include <cstring>
35#include <cstdlib>
36
37//#include "belle.h"
38#include "CLHEP/String/Strings.h"
39//#include "basf/basfshm.h"
40#include "TrkReco/TrkReco.h"
41#include "TrkReco/TMDCWireHit.h"
43#include "TrkReco/TTrack.h"
44#include "TrkReco/TTrackMC.h"
45#include "TrkReco/TTrackHEP.h"
47#include "MdcTables/MdcTables.h"
48#include "MdcTables/TrkTables.h"
49
50#include "GaudiKernel/MsgStream.h"
51#include "GaudiKernel/AlgFactory.h"
52#include "GaudiKernel/ISvcLocator.h"
53#include "GaudiKernel/IMessageSvc.h"
54#include "GaudiKernel/IDataProviderSvc.h"
55#include "GaudiKernel/IDataManagerSvc.h"
56#include "GaudiKernel/SmartDataPtr.h"
57#include "GaudiKernel/IDataProviderSvc.h"
58#include "GaudiKernel/PropertyMgr.h"
59#include "GaudiKernel/IJobOptionsSvc.h"
60#include "GaudiKernel/Bootstrap.h"
61#include "GaudiKernel/StatusCode.h"
62
63#include "GaudiKernel/ContainedObject.h"
64#include "GaudiKernel/SmartRef.h"
65#include "GaudiKernel/SmartRefVector.h"
66#include "GaudiKernel/ObjectVector.h"
68
70
71
73#include "Identifier/MdcID.h"
74
75//#include "TrkReco/TSvdAssociator.h" // jtanaka 000925
76
77//extern BasfSharedMem * BASF_Sharedmem;
78
80: _maxMomentum(10.),
81 _sigmaCurlerMergeTest(sqrt(100.)),
82 _nCurlerMergeTest(4),
83 _debugLevel(0),
84 _fitter("TTrackManager Fitter"),
85 _cFitter("TTrackManager 2D Fitter"),
86 _s(0) {
87// BASF_Sharedmem->allocate("TrkMgrSum", sizeof(struct summary));
88
89 StatusCode scmgn = Gaudi::svcLocator()->service("MagneticFieldSvc",m_pmgnIMF);
90 if(scmgn!=StatusCode::SUCCESS) {
91 std::cout<< "ERROR: Unable to open Magnetic field service"<<std::endl;
92 }
93 // Get RawDataProviderSvc
94 IRawDataProviderSvc* irawDataProviderSvc;
95 StatusCode sc = Gaudi::svcLocator()->service("RawDataProviderSvc",irawDataProviderSvc);
96 m_rawDataProviderSvc = dynamic_cast<RawDataProviderSvc*> (irawDataProviderSvc);
97 if(sc!=StatusCode::SUCCESS) {
98 std::cout<< "ERROR: Unable to load RawDataProviderSvc"<<std::endl;
99 }
100}
101
103}
104
105std::string
107 return std::string("2.27");
108}
109
110void
111TTrackManager::dump(const std::string & msg, const std::string & pre) const {
112 bool def = (msg == "") ? true : false;
113/*
114 if (msg.find("summary") != std::string::npos || msg.find("detail") != std::string::npos) {
115 struct summary s;
116 // bzero((char*)& s, sizeof(struct summary));
117 memset((char*)& s, 0, sizeof(struct summary));
118 for (int i = 0; i < BASF_Sharedmem->nprocess(); i++) {
119 int size;
120 struct summary & r = * (struct summary *)
121 BASF_Sharedmem->get_pointer(i, "TrkMgrSum", & size);
122 s._nEvents += r._nEvents;
123 s._nTracks += r._nTracks;
124 s._nTracksAll += r._nTracksAll;
125 s._nTracks2D += r._nTracks2D;
126 s._nTracksFinal += r._nTracksFinal;
127 s._nSuperMoms += r._nSuperMoms;
128 s._nToBeMerged += r._nToBeMerged;
129 s._nToBeMergedMoreThanTwo += r._nToBeMergedMoreThanTwo;
130 }
131
132 std::cout << pre;
133 std::cout << "all events : " << s._nEvents << std::endl;
134 std::cout << pre;
135 std::cout << "all tracks : " << s._nTracksAll << std::endl;
136 std::cout << pre;
137 std::cout << " good tracks : " << s._nTracks << std::endl;
138 std::cout << pre;
139 std::cout << " 2D tracks : " << s._nTracks2D << std::endl;
140 std::cout << pre;
141 std::cout << " final tracks : " << s._nTracksFinal << std::endl;
142 std::cout << pre;
143 std::cout << " super mom. : " << s._nSuperMoms << std::endl;
144 std::cout << pre;
145 std::cout << " to be mreged : " << s._nToBeMerged << std::endl;
146 std::cout << pre;
147 std::cout << " to be mreged2: " << s._nToBeMergedMoreThanTwo
148 << std::endl;
149 }
150*/
151 if (def || msg.find("eventSummary") != std::string::npos || msg.find("detail") != std::string::npos) {
152 std::cout << pre
153 << "tracks reconstructed : " << _tracksAll.length()
154 << std::endl;
155 std::cout << pre
156 << "good tracks : " << _tracks.length()
157 << std::endl;
158 std::cout << pre
159 << "2D tracks : " << _tracks2D.length()
160 << std::endl;
161 std::cout << pre
162 << "Track list:" << std::endl;
163
164 std::string tab = pre;
165 std::string spc = " ";
166 for (unsigned i = 0; i < _tracksAll.length(); i++) {
167 std::cout << tab << TrackDump(* _tracksAll[i]) << std::endl;
168 if (msg.find("hits") != std::string::npos || msg.find("detail") != std::string::npos)
169 Dump(_tracksAll[i]->links(), "hits sort flag");
170 }
171 }
172}
173
174void
176 const AList<TMDCWireHit> &stereo,
177 const AList<TTrack> &tracks) const {
178//...Coded by jtanaka...
179
180 int i = 0;
181 while(const TTrack *t = tracks[i++]){
182 int j = 0;
183 while(TMDCWireHit *a = axial[j++]){
184 double x = t->helix().center().x() - a->xyPosition().x();
185 double y = t->helix().center().y() - a->xyPosition().y();
186 double r = sqrt(x*x+y*y);
187 double R = fabs(t->helix().radius());
188 double q = t->helix().center().x()*a->xyPosition().y() -
189 t->helix().center().y()*a->xyPosition().x();
190 double qq = q*t->charge();
191 if(R-2. < r && r < R+2. && qq > 0.){
192 a->state(a->state() | WireHitUsed);
193 }
194 }
195 j = 0;
196 while(TMDCWireHit *s = stereo[j++]){
197 double x = t->helix().center().x() - s->xyPosition().x();
198 double y = t->helix().center().y() - s->xyPosition().y();
199 double r = sqrt(x*x+y*y);
200 double R = fabs(t->helix().radius());
201 double q = t->helix().center().x()*s->xyPosition().y() -
202 t->helix().center().y()*s->xyPosition().x();
203 double qq = q*t->charge();
204 if(R-2.5 < r && r < R+2.5 && qq > 0.){
205 s->state(s->state() | WireHitUsed);
206 }
207 }
208 }
209}
210
211void
213
214#ifdef TRKRECO_DEBUG_DETAIL
215 std::cout << name() << " ... salvaging" << std::endl;
216 std::cout << " # of given hits=" << hits.length() << std::endl;
217#endif
218
219 //...Check arguments...
220 unsigned nTracks = _tracks.length();
221 if (nTracks == 0) return;
222 unsigned nHits = hits.length();
223 if (nHits == 0) return;
224
225 //...Hit loop...
226 for (unsigned i = 0; i < nHits; i++) {
227 TMDCWireHit & h = * hits[i];
228
229 //...Already used?...
230 if (h.state() & WireHitUsed) continue;
231#ifdef TRKRECO_DEBUG_DETAIL
232 std::cout << " checking " << h.wire()->name() << std::endl;
233#endif
234
235 //...Select the closest track to a hit...
236 TTrack * best = closest(_tracks, h);
237#ifdef TRKRECO_DEBUG_DETAIL
238 if (! best) {
239 std::cout << " no track candidate returned";
240 std::cout << "by TTrackManager::closest" << std::endl;
241 }
242#endif
243 if (! best) continue;
244
245 //...Try to append this hit...
246 AList<TMLink> link;
247 link.append(new TMLink(0, & h));
248 best->appendByApproach(link, 30.);
249 // best->assign(WireHitConformalFinder);
251 }
252}
253
254TTrack *
256 const TMDCWireHit & hit) const {
257
258 TMLink t;
259 t.hit(& hit);
260 unsigned n = tracks.length();
261 double minDistance = MAXDOUBLE;
262 TTrack * minTrk = NULL;
263
264 //...Loop over all tracks...
265 for (unsigned i = 0; i < n; i++) {
266 TTrack & trk = * tracks[i];
267 int err = trk.approach(t);
268 if (err < 0) continue;
269 if (minDistance > t.distance()) {
270 minDistance = t.distance();
271 minTrk = & trk;
272 }
273 }
274
275 return minTrk;
276}
277
278
279StatusCode
280//TTrackManager::makeTds(bool doClear, int tkStat) { //yzhang change interface
281TTrackManager::makeTds(RecMdcTrackCol* trkcol, RecMdcHitCol* hitcol, int tkStat, int brunge , int cal) { //yzhang change interface 2010-05-14
282 IMessageSvc *msgSvc;
283 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
284
285 MsgStream log(msgSvc, "TrkReco");
286
287 IDataProviderSvc* eventSvc = NULL;
288 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
289
290#ifdef TRKRECO_DEBUG
291 if (eventSvc) {
292 log << MSG::INFO << "makeTds:event Svc has been found" << endreq;
293 } else {
294 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endreq;
295 return StatusCode::FAILURE ;
296 }
297#endif
298//check whether Recon already registered
299// DataObject *aReconEvent;
300// eventSvc->findObject("/Event/Recon",aReconEvent);
301// if(!aReconEvent) {
302// ReconEvent* recevt = new ReconEvent;
303// StatusCode sc = eventSvc->registerObject("/Event/Recon",recevt );
304// if(sc!=StatusCode::SUCCESS) {
305// log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
306// return( StatusCode::FAILURE);
307// }
308// }
309//
310// /// Unregister Tracks
311// IDataManagerSvc *dataManSvc;
312// if(doClear){//yzhang add, do NOT clear Tds when associate rec
313// dataManSvc= dynamic_cast<IDataManagerSvc*>(eventSvc);
314// DataObject *aTrackCol;
315// eventSvc->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
316// if(aTrackCol != NULL) {
317// dataManSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
318// eventSvc->unregisterObject("/Event/Recon/RecMdcTrackCol");
319// }
320// DataObject *aRecHitCol;
321// eventSvc->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
322// if(aRecHitCol != NULL) {
323// dataManSvc->clearSubTree("/Event/Recon/RecMdcHitCol");
324// eventSvc->unregisterObject("/Event/Recon/RecMdcHitCol");
325// }
326// }
327// /// Writing
328// RecMdcTrackCol* trkcol = new RecMdcTrackCol;
329// RecMdcHitCol* hitcol = new RecMdcHitCol;
330
331 unsigned n = _tracks.length();
332 int nTdsTk = trkcol->size();
333 for (int i =0; i < n; i++) {
334 RecMdcTrack* trk = new RecMdcTrack;
335 TTrack* t = _tracks[i];
336 int trackindex = i + nTdsTk;//for combination
337
338 HitRefVec hitrefvec;
339 AList<TMLink> hits = t->links();
340 float chisq=0;
341
342 HepPoint3D pos = t->helix().pivot();
343 int charge = -1;
344 HepVector m_a(5,0);
345 m_a = t->helix().a();
346 int statfinder=t->getFinderType();
347 if(abs(statfinder)>1000&&brunge)statfinder=103;
348 if(abs(statfinder)>1000&&!brunge)statfinder=3;
349 //be cautious
350 if(!brunge)m_a[2] = -m_a[2];
351 if(abs(m_a[1])>999)m_a[1]=0;
352 while(m_a[1]<0){m_a[1]+=2*pi;}
353 while(m_a[1]>2*pi){m_a[1]-=2*pi;}
354 /// added by Jike Wang
355 const double x0 = t->helix().pivot().x();
356 const double y0 = t->helix().pivot().y();
357
358 const double dr = m_a[0];
359 const double phi0 = m_a[1];
360 const double kappa = m_a[2];
361 const double dz = m_a[3];
362 const double tanl = m_a[4];
363
364 const double Bz = -1000*(m_pmgnIMF->getReferField());
365 const double alpha = 333.564095 / Bz;
366
367 const double cox = x0 + dr*cos(phi0) - alpha*cos(phi0)/kappa;
368 const double coy = y0 + dr*sin(phi0) - alpha*sin(phi0)/kappa;
369
370
371 unsigned nHits = t->links().length();
372 unsigned nStereos = 0;
373 unsigned firstLyr = 44;
374 unsigned lastLyr = 0;
375 for (unsigned j=0; j<nHits; j++){
376
377 TMLink * l = hits[j];
378
379 HepPoint3D ontrack = l->positionOnTrack();
380 HepPoint3D onwire = l->positionOnWire();
381 HepPoint3D dir(ontrack.y()-coy,cox-ontrack.x(),0);
382 double pos_phi=onwire.phi();
383 double dir_phi=dir.phi();
384 while(pos_phi>pi){pos_phi-=pi;}
385 while(pos_phi<0){pos_phi+=pi;}
386 while(dir_phi>pi){dir_phi-=pi;}
387 while(dir_phi<0){dir_phi+=pi;}
388 double entrangle=dir_phi-pos_phi;
389 while(entrangle>pi/2)entrangle-=pi;
390 while(entrangle<(-1)*pi/2)entrangle+=pi;
391
392 //jialk setFltLen to tds
393 int imass = 3;
394 float tl = t->helix().a()[4];
395 float f = sqrt(1. + tl * tl);
396 float s = fabs(t->helix().curv()) * fabs(l->dPhi()) * f;
397 float p = f / fabs(t->helix().a()[2]);
398 float Mass[5] = {0.000511,0.105,0.140,0.493677,0.98327};
399 double tof = s/29.98*sqrt(1.0+(Mass[imass-1]/p)*(Mass[imass-1]/p));
400
401 RecMdcHit* hit = new RecMdcHit;
402 hit->setId(l->hit()->reccdc()->id);
403// hit->setTrkId(i);
404 hit->setTrkId(trackindex); //for combination
405 hit->setDriftDistLeft(l->drift(0));
406 hit->setDriftDistRight(l->drift(1));
407 hit->setErrDriftDistLeft(l->dDrift(0));
408 hit->setErrDriftDistRight(l->dDrift(1));
409 hit->setChisqAdd(l->pull());
410 hit->setFlagLR(l->leftRight());
411 // hit->setStat(l->hit()->state());
412 hit->setStat(1);
413 // std::cout<<"state :"<< l->hit()->state() << std::endl;
414 hit->setAdc(l->hit()->reccdc()->adc);
415// hit->setTdc((l->hit()->reccdc()->tdc + t0bes)/0.09375); //jialk
416 hit->setTdc(l->hit()->reccdc()->timechannel);
417 hit->setFltLen(tof * 30);//jialk
418 // std::cout<<"tdc :"<< l->hit()->reccdc()->tdc <<" "<<"t0bes : "<< t0bes <<std::endl;
419 if(cal){hit->setDoca(l->distancenew());}
420 else{hit->setDoca(l->distance());}
421 hit->setZhit(l->positionOnTrack().z());
422
423 ///add by jialk: returns driftTime prop time correction & entra angle
424 hit->setEntra(entrangle);
425 hit->setDriftT(l->getDriftTime());
426
427
428 Identifier hitIdf = MdcID:: wire_id(l->wire()->layerId(),l->wire()->localId());
429 hit->setMdcId(hitIdf);
430 hitcol->push_back(hit);
431
432 SmartRef<RecMdcHit> refhit(hit);
433 hitrefvec.push_back(refhit);
434 chisq += l->pull();
435 if(l->wire()->stereo()) ++nStereos;
436 if(firstLyr > l->wire()->layerId()) firstLyr = l->wire()->layerId();
437 if(lastLyr < l->wire()->layerId()) lastLyr = l->wire()->layerId();
438 }
439
440
441 HepSymMatrix m_ea = t->helix().Ea();
442 double errorMat[15];
443 int k = 0;
444 for (int ie = 0 ; ie < 5 ; ie ++){
445 for (int je = ie ; je < 5 ; je ++) {
446 errorMat[k] = m_ea[ie][je];
447 k++;
448 }
449 }
450
451 trk->setTrackId(trackindex);
452 trk->setHelix(m_a);
453 trk->setPxy(t->pt());
454 trk->setPx(t->pt() * (-sin(t->helix().phi0())));
455 trk->setPy(t->pt() * cos(t->helix().phi0()));
456 trk->setPz(t->pz());
457 trk->setP(t->ptot());
458
459 //jialk
460 double theta = acos((t->pz())/t->ptot());
461 trk->setTheta(theta);
462
463 double poca_dr = t->helix().dr();
464 double poca_phi0 = t->helix().phi0();
465 trk->setPhi(poca_phi0);
466 HepPoint3D poca(pos.x()+poca_dr*cos(poca_phi0),
467 pos.y()+poca_dr*sin(poca_phi0),
468 pos.z()+t->helix().dz());
469 trk->setPoca(poca);
470 trk->setX(poca.x());
471 trk->setY(poca.y());
472 trk->setZ(poca.z());
473 trk->setR(sqrt(poca.x()*poca.x() + poca.y()*poca.y()));
474 trk->setPivot(pos);
475 trk->setVX0(pos.x());
476 trk->setVY0(pos.y());
477 trk->setVZ0(pos.z());
478
479 trk->setError(m_ea);
480// trk->setError(errorMat); //...............2
481
482// double poca_dr = t->helix().dr();
483// double poca_phi0 = t->helix().phi0();
484// HepPoint3D poca(poca_dr*cos(poca_phi0),poca_dr*sin(poca_phi0),t->helix().dz());
485// trk->setVX0(pos.x()+poca_dr*cos(poca_phi0));
486// trk->setVY0(pos.y()+poca_dr*sin(poca_phi0));
487// trk->setVZ0(pos.z()+t->helix().dz());
488// cout<<"pivot:("<<pos.x()<<","<<pos.y()<<","<<pos.z()<<")"<<endl;
489// cout<<"poca:("<<trk->getVX0()<<","<<trk->getVY0()<<","<<trk->getVZ0()<<")"<<endl;
490
491 trk->setChi2(chisq);
492 trk->setNdof(nHits-5);
493 if (t->quality() & TrackQuality2D) trk->setNdof(nHits-3);
494
495 TMLink * last = OuterMost(hits);
496 t->approach(*last);
497 trk->setFiTerm(last->dPhi());
498
499 trk->setNhits(nHits);
500 trk->setNster(nStereos);
501 trk->setStat(statfinder);//yzhang add stat: ConformalFinder=2, CurlFiner=3
502 //xuqn 2013-02-26
503 //trk->setCharge(int(t->charge())*(-1));
504 if(!brunge) trk->setCharge(int(t->charge())*(-1));
505 else trk->setCharge(t->charge());
506 trk->setVecHits(hitrefvec);
507 trk->setFirstLayer(firstLyr);
508 trk->setLastLayer(lastLyr);
509 //cout<<"first: "<<firstLyr<<" last: "<<lastLyr<<endl;
510 trkcol->push_back(trk);
511 }
512
513// StatusCode trksc;
514// trksc = eventSvc->registerObject("/Event/Recon/RecMdcTrackCol", trkcol);
515// if( trksc.isFailure() ) {
516// log << MSG::FATAL << "Could not register MdcTrack" << endreq;
517// return trksc;
518// }
519//
520// StatusCode hitsc = eventSvc->registerObject("/Event/Recon/RecMdcHitCol", hitcol);
521// if ( hitsc.isFailure() ) {
522// log << MSG::FATAL << "Could not register MdcRecHit" << endreq;
523// return hitsc;
524// }
525//log << MSG::INFO << "MdcTrackCol registered successfully!" <<endreq;
526
527 ///check the result:MdcTrackCol
528#ifdef TRKRECO_DEBUG
529 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc,"/Event/Recon/RecMdcTrackCol");
530 if (!newtrkCol) {
531 log << MSG::FATAL << "Could not find RecMdcTrackCol" << endreq;
532 return( StatusCode::FAILURE);
533 }
534 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
535 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
536 for( ; iter_trk != newtrkCol->end(); iter_trk++){
537 const RecMdcTrack* tk = *iter_trk;
538 std::cout<< "//==== "<<name()<<" print RecMdcTrack No."<<tk->trackId()<<" :"<< std::endl;
539 cout <<" dr "<<tk->helix(0)
540 <<" phi0 "<<tk->helix(1)
541 <<" cpa "<<tk->helix(2)
542 <<" z0 "<<tk->helix(3)
543 <<" tanl "<<tk->helix(4)
544 <<endl;
545 bool printTrackDetail = true;
546 if(printTrackDetail){
547 std::cout<<" q "<<tk->charge()
548 <<" theta "<<tk->theta()
549 <<" phi "<<tk->phi()
550 <<" x0 "<<tk->x()
551 <<" y0 "<<tk->y()
552 <<" z0 "<<tk->z()
553 <<" r0 "<<tk->r()
554 <<endl;
555 std::cout <<" p "<<tk->p()
556 <<" pt "<<tk->pxy()
557 <<" pxyz("<<tk->px()
558 <<","<<tk->py()
559 <<","<<tk->pz()
560 <<")"<<endl;
561 std::cout<<" tkStat "<<tk->stat()
562 <<" chi2 "<<tk->chi2()
563 <<" ndof "<<tk->ndof()
564 <<" nhit "<<tk->getNhits()
565 <<" nst "<<tk->nster()
566 <<endl;
567 bool printErrMat = true;
568 if(printErrMat){
569 std::cout<< "errmat " << std::endl;
570 for (int i=0; i<15; i++){ std::cout<< " "<<tk->err(i); }
571 std::cout<< " " << std::endl;
572 }
573 }
574
575 bool printHit = true;
576 if(printHit){
577 int haveDigi[43][288];
578 bool printMcTk = true;
579 if(printMcTk) {
580 for(int ii=0;ii<43;ii++){
581 for(int jj=0;jj<43;jj++){
582 haveDigi[ii][jj]=-9999;
583 }
584 }
585 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec();
586 MdcDigiCol::iterator iter = mdcDigiVec.begin();
587 std::cout<<name()<<"//==== "<<name()<<" print MdcDigiVec, nDigi="<<mdcDigiVec.size()<<" :"<<std::endl;
588 for (int iDigi=0;iter!= mdcDigiVec.end(); iter++,iDigi++ ) {
589 long l = MdcID::layer((*iter)->identify());
590 long w = MdcID::wire((*iter)->identify());
591 haveDigi[l][w]=(*iter)->getTrackIndex();
592 }
593 }
594
595 int nhits = tk->getVecHits().size();
596 std::cout<<"nHits=" <<nhits<< std::endl;
597 cout<<"No. ";
598 if(printMcTk) cout<<"mcTkId ";
599 cout<<"(layer,wire,lr) stat z"<<endl;
600 for(int ii=0; ii <nhits ; ii++){
601 Identifier id(tk->getVecHits()[ii]->getMdcId());
602 int layer = MdcID::layer(id);
603 int wire = MdcID::wire(id);
604 cout<<ii<<":";
605 if(printMcTk) { cout<<haveDigi[layer][wire]; }
606 cout<<" ("<<layer<<","<<wire
607 <<","<<tk->getVecHits()[ii]->getFlagLR()
608 <<") "<<tk->getVecHits()[ii]->getStat()
609 <<" "<<tk->getVecHits()[ii]->getZhit()<< " "<<std::endl;
610 }//end of hit list
611 std::cout << " "<< std::endl;
612 }
613 /*
614 std::cout << "retrieved MDC track:"
615 << "Track Id: " << (*iter_trk)->getTrkId()
616 << " Pivot: " << (*iter_trk)->getVX0() << " "
617 << (*iter_trk)->getVY0() << " " << (*iter_trk)->getVZ0()
618 << endl
619 << "Phi0: " << (*iter_trk)->getFi0() << " Error of Phi0 "
620 << (*iter_trk)->getError()(2,2) << endreq
621 << "kappa: " << (*iter_trk)->getCpa() << " Error of kappa "
622 << (*iter_trk)->getError()(3,3) << endreq
623 << "Tanl: " << (*iter_trk)->getTanl() << " Error of Tanl "
624 << (*iter_trk)->getError()(5,5) << endreq
625 << "Chisq of fit: "<< (*iter_trk)->getChisq()
626 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
627 << endl
628 << "Number of hits: "<< (*iter_trk)->getNhits()
629 << " Number of stereo hits " << (*iter_trk)->getNster()
630 << endreq;
631
632 log << MSG::DEBUG << "hitList of this track:" << endreq;
633 std::vector<MdcRecHit*> gothits = (*iter_trk)->getVecHits();
634 std::vector<MdcRecHit*>::iterator it_gothit = gothits.begin();
635 for( ; it_gothit != gothits.end(); it_gothit++){
636 log << MSG::DEBUG << "hits Id: "<<(*it_gothit)->getId()
637 << " hits DDL&DDR " <<(*it_gothit)->getDriftDistLeft()
638 << " hits MDC IDentifier " <<(*it_gothit)->getMdcId()
639 << endreq
640 << " hits TDC " <<(*it_gothit)->getTdc()
641 << " hits ADC " <<(*it_gothit)->getAdc() << endreq;
642 }
643 */
644 }
645#endif
646 return StatusCode::SUCCESS;
647}
648
649
650
651void
653#ifdef TRKRECO_DEBUG
654 std::cout << "TTrackManager::saveTables ... # 3D tracks=" << _tracks.length()
655 << ", # 2D tracks=" << _tracks2D.length()
656 << ", all tracks=" << _tracksAll.length() << std::endl;
657#endif
658
659 //...For 3D tracks...
660 AList<TTrack> badTracks;
661 unsigned n = _tracks.length();
662 unsigned * id = (unsigned *) malloc(n * sizeof(unsigned));
663 // bzero((char *) id, n * sizeof(unsigned));
664 memset((char *) id, 0, n * sizeof(unsigned));
665 for (unsigned i = 0; i < n; i++) {
666 TTrack & t = * _tracks[i];
667 if (! t.nLinks()) {
668 badTracks.append((TTrack &) t);
669 continue;
670 }
671
672 //...Copy track parameters...
673 MdcRec_trk * r = 0;
674 MdcRec_trk_add * a = 0;
675 int err = copyTrack(t, & r, & a);
676 if (err) {
677 badTracks.append(t);
678 continue;
679 }
680 _tracksFinal.append(t);
681
682 //...Type and quality...
683 id[i] = r->id;
684 r->stat = t.state();
685 a->kind = t.type();
686 a->decision = t.finder();
687 a->stat = t.fitting();
688 // if (a->m_kind == TrackTypeCosmic) {
689 // a->m_quality = TrackQualityCosmic;
690 // }
691 // if (t.daughter() && (_tracks.index(t.daughter()) >= 0))
692 // a->m_daughter = _tracks.index(t.daughter()) + 1;
693
694 }
695
696 //...Daughter treatment...
697 for (unsigned i = 0; i < n; i++) {
698
699#ifdef TRKRECO_DEBUG_DETAIL
700 std::cout << "id[" << i << "]=" << id[i] << std::endl;
701#endif
702 if (! (id[i])) continue;
703 if (! (_tracks[i]->daughter())) continue;
704
705 int dId = _tracks.index(_tracks[i]->daughter());
706
707#ifdef TRKRECO_DEBUG_DETAIL
708 std::cout << " dId=" << dId;
709 if (dId >= 0) std::cout << ", id[dId]=" << id[dId];
710 std::cout << std::endl;
711#endif
712
713 if (dId >= 0) {
714 if (id[dId]) {
715 // reccdc_trk_add * a = (reccdc_trk_add *)
716 // BsGetEnt(RECMDC_TRK_ADD, id[i], BBS_No_Index);
717 // a->m_daughter = id[dId];
719 }
720 }
721 }
722 free(id);
723
724 //...Remove bad tracks...
725 _tracks.remove(badTracks);
726 badTracks.removeAll();
727
728 //...For 2D tracks...
729 n = _tracks2D.length();
730 for (unsigned i = 0; i < n; i++) {
731 TTrack & t = * _tracks2D[i];
732
733 //...Copy track parameters...
734 MdcRec_trk * r = 0;
735 MdcRec_trk_add * a = 0;
736 int err = copyTrack(t, & r, & a);
737 if (err) {
738#ifdef TRKRECO_DEBUG
739 std::cout << "TTrackManager::saveTables !!! bad 2D tracks found"
740 << " : err=" << err << std::endl
741 << TrackDump(t) << std::endl;
742#endif
743 badTracks.append(t);
744 continue;
745 }
746 _tracksFinal.append(t);
747
748 //...Reset helix parameter...
749 // r->m_helix[3] = 0.;
750 // r->m_helix[4] = 0.;
751 // r->m_nhits -= r->m_nster;
752 // r->m_nster = 0;
753
754 //...Table filling...
755 r->stat = t.state();
756 a->kind = t.type();
757 a->decision = t.finder();
758 // a->m_quality = t.quality();
760 a->stat = t.fitting();
761
762#ifdef TRKRECO_DEBUG
763 if ((r->ndf == 0) && (r->chiSq > 0.)) {
764 std::cout << "TTrackManager::saveTables !!! chisq>0 with ndf=0."
765 << std::endl
766 << " Here is a track dump"
767 << " " << TrackDump(t) << std::endl;
768 t.dump("detail");
769 }
770 if ((r->ndf > 0) && (r->chiSq == 0.)) {
771 std::cout << "TTrackManager::saveTables !!! chisq=0 with ndf>0."
772 << std::endl
773 << " Here is a track dump"
774 << " " << TrackDump(t) << std::endl;
775 t.dump("detail");
776 }
777
778 if (r->ndf == 0)
779 std::cout << "TTrackManager::saveTables ... ndf = 0" << std::endl
780 << " " << TrackDump(t) << std::endl;
781 if (r->chiSq == 0.)
782 std::cout << "TTrackManager::saveTables ... chisq = 0" << std::endl
783 << " " << TrackDump(t) << std::endl;
784#endif
785 }
786 _tracks2D.remove(badTracks);
787
788 //...Statistics...
789 ++_s->_nEvents;
790 _s->_nTracks += _tracks.length();
791 _s->_nTracksAll += _tracksAll.length();
792 _s->_nTracks2D += _tracks2D.length();
793 _s->_nTracksFinal += _tracksFinal.length();
794}
795
796void
798 unsigned n = _tracksFinal.length();
799 for (unsigned i = 0; i < n; i++) {
800 const TTrack & t = * _tracksFinal[i];
801
802 // struct reccdc_trk * r;
803 // r = (struct reccdc_trk *) BsGetEnt(RECMDC_TRK, i + 1, BBS_No_Index);
805
806 //...Set type...
807
808 //...Hit loop...
809 const AList<TMLink> & hits = t.finalHits();
810 unsigned nHits = hits.length();
811 for (unsigned j = 0; j < nHits; j++) {
812 TMLink * l = hits[j];
813 MdcRec_wirhit * h = l->hit()->reccdc();
814 MdcDat_mcwirhit * m = l->hit()->mc()->datcdc();
815 m->trk = r;
816 // struct reccdc_mctrk2hep * c;
817 // c = (struct reccdc_mctrk2hep *) BsNewEnt(RECMDC_MCTRK2HEP);
820 c->wir = h;
821 c->trk = r;
822 c->hep = l->hit()->mc()->hep()->gen();
823 }
824
825 const TTrackMC * const mc = t.mc();
826 // struct reccdc_mctrk * m;
827 // m = (struct reccdc_mctrk *) BsNewEnt(RECMDC_MCTRK);
828 // // MdcRec_mctrk* m = &(*MdcRecMctrkCol::getMdcRecMctrkCol())[0];
829 MdcRec_mctrk* m = new MdcRec_mctrk;
830 MdcRecMctrkCol::getMdcRecMctrkCol()->push_back(*m);
831 m->wirFrac = mc->wireFraction();
832 m->wirFracHep = mc->wireFractionHEP();
833 m->charge = mc->charge();
834 m->ptFrac = mc->ptFraction();
835 m->pzFrac = mc->pzFraction();
836 m->quality = mc->quality();
837 if (mc->hep()) m->hep = mc->hep()->gen();
838 else m->hep = 0;
839 }
840}
841
842void
844 unsigned n = _tracksAll.length();
845 // unsigned n = _tracks.length();
846 for (unsigned i = 0; i < n; i++) {
847 if (_tracksAll[i]->nLinks()) _tracksAll[i]->movePivot();
848 // if (_tracks[i]->nLinks()) _tracks[i]->movePivot();
849 }
850 nameTracks();
851}
852
853void
855 HepAListDeleteAll(_tracksAll);
856 _tracks.removeAll();
857 _tracks2D.removeAll();
858 _tracksFinal.removeAll();
859 HepAListDeleteAll(_associateHits);
860 static bool first = true;
861 if (first) {
862 first = false;
863 int size;
864 // _s = (struct summary *)
865 // BASF_Sharedmem->get_pointer(BASF_Sharedmem->get_id(),
866 // "TrkMgrSum",
867 // & size);
868 }
869}
870
871void
873 refit();
874 movePivot();
875 if (_debugLevel > 1) {
876 std::cout << name() << " ... finishing" << std::endl;
877 // unsigned n = _tracksAll.length();
878 unsigned n = _tracks.length();
879 for (unsigned i = 0; i < n; i++) {
880 // TTrack & t = * _tracksAll[i];
881 TTrack & t = * _tracks[i];
882 std::cout << " " << t.name() << std::endl;
883 t.dump("hits mc track flag sort", " ");
884 }
885 }
886}
887
888void
890 _tracksAll.append(list);
891 _tracks.append(selectGoodTracks(list));
892 list.removeAll();
893}
894
895void
897 _tracksAll.append(list);
898 _tracks2D.append(selectGoodTracks(list, true));
899 _tracks2D.sort(SortByPt);
900 list.removeAll();
901}
902
903void
905#ifdef TRKRECO_DEBUG_DETAIL
906 std::cout << name() << " ... refitting" << std::endl;
907#endif
908 unsigned n = _tracks.length();
909 AList<TTrack> bads;
910 for (unsigned i = 0; i < n; i++) {
911 TTrack & t = * _tracks[i];
912 int err;
913 err = _fitter.fit(t);
914 if (err < 0) {
915 bads.append(t);
916#ifdef TRKRECO_DEBUG_DETAIL
917 std::cout << " " << t.name();
918 std::cout << " rejected because of fitting failure" << std::endl;
919#endif
920 continue;
921 }
922 t.refine(30. * 10.);
923 err = _fitter.fit(t);
924 if (err < 0) {
925 bads.append(t);
926#ifdef TRKRECO_DEBUG_DETAIL
927 std::cout << " " << t.name();
928 std::cout << " rejected because of fitting failure" << std::endl;
929#endif
930 continue;
931 }
932 t.refine(30. * 1.);
933 err = _fitter.fit(t);
934 if (err < 0) {
935 bads.append(t);
936#ifdef TRKRECO_DEBUG_DETAIL
937 std::cout << " " << t.name();
938 std::cout << " rejected because of fitting failure" << std::endl;
939#endif
940 continue;
941 }
942 }
943 _tracks.remove(bads);
944}
945
946void
948#ifdef TRKRECO_DEBUG_DETAIL
949 std::cout << name() << " ... masking" << std::endl;
950#endif
951
952 unsigned n = _tracks.length();
953 for (unsigned i = 0; i < n; i++) {
954 TTrack & t = * _tracks[i];
955
956 //...Skip if no core...
957 // This should not be happend...
958 if (! t.cores().length()) continue;
959
960 //...Counts # of hits per layer...
961 unsigned nHits[43];
962 NHits(t.cores(), nHits);
963
964 //...Check each layer...
965 bool needMask = false;
966 for (unsigned j = 0; j < 43; j++) {
967 if (nHits[j] > 1) {
968 AList<TMLink> linksInLayer = SameLayer(t.links(), j);
969 if (Width(linksInLayer) > 2) {
970 needMask = true;
971
972#ifdef TRKRECO_DEBUG_DETAIL
973 Dump(linksInLayer, "sort", " -->");
974#endif
975 break;
976 }
977 }
978 }
979 if (! needMask) continue;
980
981#ifdef TRKRECO_DEBUG_DETAIL
982 std::cout << " trk" << i << "(id is tmp) needs mask" << std::endl;
983 std::cout << " type = " << t.type() << std::endl;
984#endif
985
986 //...Switch by track type...
987 switch (t.type()) {
988 case TrackTypeNormal:
989 maskNormal(t);
991 break;
992 case TrackTypeCurl:
993 maskCurl(t);
995 break;
996 default:
997 break;
998 }
999
1000 //...Refit...
1001 // refit() ???
1002 _fitter.fit(t);
1003
1004#ifdef TRKRECO_DEBUG_DETAIL
1005 std::cout << " masking result : ";
1006 t.dump("detail sort", " ");
1007#endif
1008 }
1009}
1010
1011void
1012TTrackManager::nameTracks(void) {
1013 unsigned n = _tracks.length();
1014 for (unsigned i = 0; i < n; i++) {
1015 TTrack & t = * _tracks[i];
1016 t._name = "trk" + itostring(i) + "(" + t._name + ")";
1017 }
1018 AList<TTrack> tmp = _tracksAll;
1019 tmp.remove(_tracks);
1020 unsigned n1 = tmp.length();
1021 for (unsigned i = 0; i < n1; i++) {
1022 TTrack & t = * tmp[i];
1023 t._name = "trk" + itostring(i + n) + "(" + t._name + ")";
1024 }
1025}
1026
1027TMLink &
1029 TMLink & start = * OuterMost(t.links());
1030 const HepPoint3D & center = t.helix().center();
1031 const HepVector3D a = start.positionOnTrack() - center;
1032 for (unsigned j = 0; j < t.nLinks(); j++) {
1033 if (t[j] == & start) continue;
1034 TMLink & k = * t[j];
1035 const HepVector3D b = k.positionOnTrack() - center;
1036 if (a.cross(b).z() >= 0.) l[0].append(k);
1037 else l[1].append(k);
1038 }
1039
1040#ifdef TRKRECO_DEBUG_DETAIL
1041 std::cout << " outer link = " << start.hit()->wire()->name() << std::endl;
1042 std::cout << " nLinks of 0 = " << l[0].length() << std::endl;
1043 std::cout << " nLinks of 1 = " << l[1].length() << std::endl;
1044#endif
1045
1046 if (l[0].length() == 0 || l[1].length() == 0)
1047 return divideByIp(t, l);
1048
1049 return start;
1050}
1051
1052TMLink &
1054 l[0].removeAll();
1055 l[1].removeAll();
1056
1057 const HepPoint3D & center = t.helix().center();
1058 const HepVector3D a = ORIGIN - center;
1059 for (unsigned j = 0; j < t.nLinks(); j++) {
1060 TMLink & k = * t[j];
1061 const HepVector3D b = k.positionOnTrack() - center;
1062 if (a.cross(b).z() >= 0.) l[0].append(k);
1063 else l[1].append(k);
1064 }
1065
1066 //...This is a dummy...
1067 TMLink & start = * OuterMost(t.links());
1068 return start;
1069}
1070
1071void
1073
1074 //...Calculate average phi...
1075 unsigned n = l.length();
1076 float phiSum = 0.;
1077 for (unsigned i = 0; i < n; i++) {
1078 const TMDCWire & w = * l[i]->hit()->wire();
1079 unsigned j = w.localId();
1080 unsigned nWire = w.layer()->nWires();
1081
1082 float phi = (float) j / (float) nWire;
1083 phiSum += phi;
1084 }
1085 float average = phiSum / (float) n;
1086
1088 for (unsigned i = 0; i < n; i++) {
1089 const TMDCWire & w = * l[i]->hit()->wire();
1090 unsigned j = w.localId();
1091 unsigned nWire = w.layer()->nWires();
1092
1093 float phi = (float) j / (float) nWire;
1094 float dif = fabs(phi - average);
1095 if (dif > 0.5) dif = 1. - dif;
1096
1097 if (dif > 0.3) cross.append(l[i]);
1098 }
1099 l.remove(cross);
1100
1101#ifdef TRKRECO_DEBUG_DETAIL
1102 std::cout << " Cross over IP reduction : ";
1103 for (unsigned i = 0; i < cross.length(); i++) {
1104 std::cout << cross[i]->wire()->name() << ",";
1105 }
1106 std::cout << std::endl;
1107#endif
1108}
1109
1110
1111void
1113 unsigned n = links.length();
1114 if (! n) return;
1115 for (unsigned i = 0; i < n; i++) {
1116 const TMDCWireHit & hit = * links[i]->hit();
1117 hit.state(hit.state() | WireHitInvalidForFit);
1118 }
1119 t._fitted = false;
1120
1121#ifdef TRKRECO_DEBUG_DETAIL
1122 Dump(links, "detail", " TTrackManager::maskOut ... masking ");
1123#endif
1124}
1125
1126void
1128#ifdef TRKRECO_DEBUG_DETAIL
1129 std::cout << "... masking multi-hits" << std::endl;
1130#endif
1131
1132 if (! t.cores().length()) return;
1133 AList<TMLink> cores = t.cores();
1134 unsigned n = cores.length();
1135 bool layerLimited = false;
1136 AList<TMLink> bads;
1137
1138 cores.sort(SortByWireId);
1139 for (unsigned i = 0; i < n; i++) {
1140 if (layerLimited) {
1141 bads.append(cores[i]);
1142 continue;
1143 }
1144 AList<TMLink> linksInLayer =
1145 SameLayer(cores, cores[i]->wire()->layerId());
1146 if (linksInLayer.length() > 3) {
1147 bads.append(cores[i]);
1148 layerLimited = true;
1149 }
1150 }
1151 maskOut(t, bads);
1152}
1153
1154void
1156
1157 //...Divide into two tracks...
1158 AList<TMLink> l[2];
1159 TMLink & start = divideByIp(t, l);
1160
1161#ifdef TRKRECO_DEBUG_DETAIL
1162 std::cout << " normal : divided by IP" << std::endl;
1163 std::cout << " 0=";
1164 for (unsigned j = 0; j < l[0].length(); j++) {
1165 std::cout << "," << l[0][j]->wire()->name();
1166 }
1167 std::cout << std::endl;
1168 std::cout << " 1=";
1169 for (unsigned j = 0; j < l[1].length(); j++) {
1170 std::cout << "," << l[1][j]->wire()->name();
1171 }
1172 std::cout << std::endl;
1173#endif
1174
1175 //...Which should be masked out ?...
1176 unsigned maskSide = 2;
1177
1178 //...1. Check by # of super layers...
1179 if (NSuperLayers(l[0]) < NSuperLayers(l[1])) maskSide = 0;
1180 else if (NSuperLayers(l[0]) > NSuperLayers(l[1])) maskSide = 1;
1181#ifdef TRKRECO_DEBUG_DETAIL
1182 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers(l[0]) << ", ";
1183 std::cout << NSuperLayers(l[1]) << std::endl;
1184#endif
1185 if (maskSide != 2) {
1186 maskOut(t, l[maskSide]);
1187 return;
1188 }
1189
1190 //...2. Check by the inner-most layer...
1191 unsigned i0 = InnerMost(l[0])->wire()->layerId();
1192 unsigned i1 = InnerMost(l[1])->wire()->layerId();
1193 if (i0 < i1) maskSide = 1;
1194 else if (i0 > i1) maskSide = 0;
1195#ifdef TRKRECO_DEBUG_DETAIL
1196 std::cout << " i0, i1 = " << i0 << ", " << i1 << std::endl;
1197#endif
1198 if (maskSide != 2) {
1199 maskOut(t, l[maskSide]);
1200 return;
1201 }
1202
1203 //...3. Check by # of layers...
1204 if (NLayers(l[0]) < NLayers(l[1])) maskSide = 0;
1205 else if (NLayers(l[0]) > NLayers(l[1])) maskSide = 1;
1206#ifdef TRKRECO_DEBUG_DETAIL
1207 std::cout << " NLayers 0, 1 = " << NLayers(l[0]) << ", ";
1208 std::cout << NLayers(l[1]) << std::endl;
1209#endif
1210 if (maskSide != 2) {
1211 maskOut(t, l[maskSide]);
1212 return;
1213 }
1214
1215 //...4. Check by pt...
1216 if (maskSide == 2) {
1217 TTrack * tt[2];
1218 for (unsigned j = 0; j < 2; j++) {
1219 tt[j] = new TTrack(t);
1220 tt[j]->remove(l[j]);
1221 _fitter.fit(* tt[j]);
1222 }
1223 if (tt[1]->pt() > tt[0]->pt()) maskSide = 1;
1224 else maskSide = 0;
1225#ifdef TRKRECO_DEBUG_DETAIL
1226 std::cout << " pt 0 = " << tt[1]->pt() << std::endl;
1227 std::cout << " pt 1 = " << tt[0]->pt() << std::endl;
1228#endif
1229 delete tt[0];
1230 delete tt[1];
1231 }
1232 maskOut(t, l[maskSide]);
1233 return;
1234}
1235
1236void
1238
1239 //...Divide into two tracks...
1240 AList<TMLink> l[2];
1241 TMLink & start = divideByIp(t, l);
1242 if (l[0].length() == 0) return;
1243 if (l[1].length() == 0) return;
1244
1245#ifdef TRKRECO_DEBUG_DETAIL
1246 std::cout << " curl : divided by IP" << std::endl;
1247 std::cout << " 0:";
1248 Dump(l[0], "flag sort");
1249 std::cout << " 1:";
1250 Dump(l[1], "flag sort");
1251 std::cout << std::endl;
1252#endif
1253
1254 //...Which should be masked out ?...
1255 unsigned maskSide = 2;
1256
1257 //...1. Check by # of super layers...
1258 if (NSuperLayers(l[0]) < NSuperLayers(l[1])) maskSide = 0;
1259 else if (NSuperLayers(l[0]) > NSuperLayers(l[1])) maskSide = 1;
1260#ifdef TRKRECO_DEBUG_DETAIL
1261 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers(l[0]) << ", ";
1262 std::cout << NSuperLayers(l[1]) << std::endl;
1263#endif
1264 if (maskSide != 2) {
1265 maskOut(t, l[maskSide]);
1266 return;
1267 }
1268
1269 //...Make two tracks...
1270 TTrack * tt[2];
1271 tt[0] = new TTrack(t);
1272 tt[1] = new TTrack(t);
1273 tt[0]->remove(l[1]);
1274 tt[1]->remove(l[0]);
1275 _fitter.fit(* tt[0]);
1276 _fitter.fit(* tt[1]);
1277 Helix h0 = Helix(tt[0]->helix());
1278 Helix h1 = Helix(tt[1]->helix());
1279
1280 //...Check by z...
1281 h0.pivot(ORIGIN);
1282 h1.pivot(ORIGIN);
1283 if (fabs(h0.dz()) < fabs(h1.dz())) maskSide = 1;
1284 else maskSide = 0;
1285
1286 delete tt[0];
1287 delete tt[1];
1288 maskOut(t, l[maskSide]);
1289 return;
1290}
1291
1292StatusCode
1293TTrackManager::determineT0(unsigned level, unsigned nMax) {
1294#ifdef TRKRECO_DEBUG_DETAIL
1295 if (level == 0) {
1296 std::cout << "TTrackManager::determineT0 !!! called with level = 0";
1297 std::cout << std::endl;
1298 }
1299#endif
1300
1301 IMessageSvc *msgSvc;
1302 Gaudi::svcLocator()->service("MessageSvc", msgSvc);
1303 MsgStream log(msgSvc, "TTrackManager");
1304
1305 IDataProviderSvc* eventSvc = NULL;
1306 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
1307
1308 static bool first = true;
1309 static unsigned methode = 0;
1310 if (first) {
1311 first = false;
1312
1313 if (level == 1) {
1314 _cFitter.fit2D(true);
1315 }
1316 else if (level == 2) {
1317 // default setting
1318 }
1319 else if (level == 3) {
1320 // _cFitter.sag(true); //Liuqg
1321 }
1322 else if (level == 4) {
1323 // _cFitter.sag(true); //Liuqg
1324 _cFitter.propagation(true);
1325 }
1326 else if (level == 5) {
1327 // _cFitter.sag(true); //Liuqg
1328 _cFitter.propagation(true);
1329 _cFitter.tof(true);
1330 }
1331 else if (level == 6) {
1332 methode = 1;
1333 // _cFitter.sag(true); //Liuqg
1334 _cFitter.propagation(true);
1335 _cFitter.tof(true);
1336 }
1337 else if (level == 7) {
1338 methode = 2;
1339 // _cFitter.sag(true); //Liuqg
1340 _cFitter.propagation(true);
1341 _cFitter.tof(true);
1342 }
1343 }
1344
1345 unsigned n = _tracks.length();
1346 if (! n) return StatusCode::SUCCESS;
1347
1348 if (nMax == 0) nMax = n;
1349 if (n > nMax) n = nMax;
1350
1351 // float t0 = 0.;
1352 _t0 = 999.;
1353
1354 //read t0 from TDS
1355 float t0_sta = -1;
1356 float tev = 0;
1357 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,"/Event/Recon/RecEsTimeCol");
1358 if (aevtimeCol) {
1359 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
1360 t0_sta = (*iter_evt)->getStat();
1361 tev = (*iter_evt)->getTest();
1362 // cout<<"t0_sta: "<<t0_sta<<" tev: "<<tev<<endl;
1363 }else{
1364 log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
1365 }
1366
1367 if (methode == 0) _t0 = T0(n);
1368
1369 else if (methode == 1) _t0 = T0Fit(n);
1370
1371 else if (methode ==2) { //revise method == 2 to BESIII environment. Liuqg
1372 if (t0_sta != 1) { //1: tof 11:tof after reco //no tof
1373 _t0 = T0Fit(n);
1374 //cout<<"t0: "<<_t0<<endl;
1375 }
1376 }
1377
1378 // std::cout << "reccdc_timing=" << BsCouTab(RECMDC_TIMING) << std::endl;
1379 /* else if (methode == 2 && BsCouTab(RECMDC_TIMING) != 0) {
1380 struct reccdc_timing * r0 = (struct reccdc_timing *)
1381 BsGetEnt(RECMDC_TIMING, BsCouTab(RECMDC_TIMING), BBS_No_Index);
1382 if (r0->m_quality == 102) {
1383 if (BsCouTab(BELLE_EVENT)) {
1384 struct belle_event * b0 = (struct belle_event *)
1385 BsGetEnt(BELLE_EVENT, 1, BBS_No_Index);
1386 if(1==b0->m_ExpMC) t0 = T0Fit(n);
1387 if(2==b0->m_ExpMC && r0->m_time !=0.) t0 = T0Fit(n);
1388 }
1389 }
1390 else if (r0->m_quality == 100) t0 = T0Fit(n);
1391 // std::cout << "quality=" << r0->m_quality << std::endl;
1392 }
1393 */
1394
1395 //...For debug...
1396 if (_debugLevel) {
1397 std::cout << "TTrackManager::determineT0 ... methode=" << methode;
1398 std::cout << ", T0 offset=" << - _t0;
1399 std::cout << ", # of tracks used=" << n << std::endl;
1400 }
1401
1402 //...store them... Liuqg
1403 float t0_rec = 999.;
1404 int t0_recSta = 8;
1405 if(fabs(_t0 + tev) < 4) t0_rec = 0;
1406 if(fabs(_t0 + tev - 8) < 4) t0_rec = 8;
1407 if(fabs(_t0 + tev - 16) < 4) t0_rec = 16;
1408 log << MSG::INFO << "beginning to make RecEsTimeCol" <<endreq;
1409 IDataManagerSvc *dataManSvc = dynamic_cast<IDataManagerSvc*> (eventSvc);
1410 DataObject *aEvTime;
1411 eventSvc->findObject("/Event/Recon/RecEsTimeCol",aEvTime);
1412 if(aEvTime!=NULL && t0_rec<25){
1413 dataManSvc->clearSubTree("/Event/Recon/RecEsTimeCol");
1414 eventSvc->unregisterObject("/Event/Recon/RecEsTimeCol");
1415 }
1416 if(t0_rec<25){
1417
1418 RecEsTimeCol *aEvTimeCol = new RecEsTimeCol;
1419 RecEsTime *aevtime = new RecEsTime;
1420 aevtime -> setTest(t0_rec);
1421 aevtime -> setStat(t0_recSta);
1422 aEvTimeCol->push_back(aevtime);
1423
1424 // register event time to TDS
1425 //check whether the t0 has been already registered
1426 StatusCode evtime = eventSvc->registerObject("/Event/Recon/RecEsTimeCol", aEvTimeCol);
1427
1428 if(evtime!=StatusCode::SUCCESS) {
1429 log << MSG::FATAL << "Could not register Event Start Time" << endreq;
1430 return( StatusCode::FAILURE);
1431 }
1432 }
1433 return( StatusCode::SUCCESS );
1434}
1435
1436float
1437TTrackManager::T0(unsigned n) {
1438
1439#define X0 -10.
1440#define X1 0.
1441#define X2 10.
1442#define STEP 10.
1443
1444 //...Determine T0 for each track...
1445 float t0Sum = 0.;
1446 for (unsigned i = 0; i < n; i++) {
1447 TTrack & t = * _tracks[i];
1448 float y[3];
1449 for (unsigned j = 0; j < 3; j++) {
1450 float offset = X0 + j * STEP;
1451 _cFitter.fit(t, offset);
1452 y[j] = t.chi2();
1453 }
1454 t0Sum += minimum(y[0], y[1], y[2]);
1455 }
1456 float t0 = t0Sum / (float) n;
1457 if (isnan(t0)) t0 = 0.;
1458
1459 //...Fit with T0 correction...
1460 n = _tracks.length();
1461 for (unsigned i = 0; i < n; i++) {
1462 TTrack & t = * _tracks[i];
1463 _cFitter.fit(t, t0);
1464 }
1465
1466 //...Store it...
1467 // reccdc_timing * t = (reccdc_timing *) BsNewEnt(RECMDC_TIMING);
1468 /* MdcRec_timing* t = new MdcRec_timing;
1469 MdcRecTimingCol::getMdcRecTimingCol()->push_back(*t);
1470 t->time = - t0;
1471 t->quality = 11;
1472 */
1473 return - t0;
1474}
1475
1476float
1477TTrackManager::T0Fit(unsigned n) {
1478
1479 float tev_err;
1480 float tev_sum0= 0.;
1481 float tev_sum = 0.;
1482 float tev_sum2= 0.;
1483 float w_sum = 0.;
1484
1485 //sort in order of pt
1486 // std::cout << "length=" << _tracks.length() << std::endl;
1487 const int cn=_tracks.length();
1488 float* sort = new float[cn];
1489 float ptmax_pre=1.e10;
1490 for (unsigned i = 0; i < cn; i++) {
1491 float ptmax=-999.;
1492 int jmax;
1493 for (unsigned j = 0; j < cn; j++) {
1494 TTrack & tj = * _tracks[j];
1495 float pt = fabs(1./tj.helix().a()[2]);
1496 if( pt < ptmax_pre && pt > ptmax) {
1497 ptmax = pt;
1498 jmax = j;
1499 }
1500 sort[i]=jmax;
1501 }
1502 ptmax_pre=ptmax;
1503 }
1504
1505 for (unsigned i = 0; i < n; i++) {
1506 //srtbypt TTrack & t = * _tracks[i];
1507 TTrack & t = * _tracks[sort[i]];
1508 //float pt = fabs(1./t.helix().a()[2]);
1509 //std::cout << "pt=" << pt << endl;
1510 float tev = 0.;
1511 _cFitter.fit(t, tev, tev_err);
1512 // std::cout << "tev,tev_err=" <<tev<< " "<<tev_err<<endl;
1513 float w = 1. / tev_err / tev_err;
1514 tev_sum += w * tev;
1515 w_sum += w;
1516 // tev_sum0 += tev;
1517 // tev_sum2 += tev * tev;
1518 }
1519
1520 delete [] sort;
1521
1522 float tev_mean = tev_sum / w_sum;
1523 // float tev_err_a = 1. / sqrt(w_sum);
1524 // float tev_err_b = (tev_sum2 - tev_sum0 * tev_sum0 / (n + 1)) / n;
1525 // tev_err_b = sqrt(tev_err_b);
1526 // std::cout << "comp,t0,mean tev,err ="<<t0<<" "<<tev_mean<<" "<<tev_err_a<<" "<<tev_err_b<<std::endl;
1527 if (isnan(tev_mean)) tev_mean = 0.;
1528
1529 //...Store it...
1530 // reccdc_timing * tt = (reccdc_timing *) BsNewEnt(RECMDC_TIMING);
1531 // MdcRec_timing* tt = new MdcRec_timing;
1532 // MdcRecTimingCol::getMdcRecTimingCol()->push_back(*tt);
1533 // tt->time = tev_mean;
1534 // tt->quality = 151;
1535
1536 return - tev_mean;
1537}
1538
1539float
1540TTrackManager::minimum(float y0, float y1, float y2) const {
1541 float xMin = X1 + 0.5 * STEP * (y0 - y2) / (y0 + y2 - 2. * y1);
1542 return xMin;
1543}
1544
1545// added by matsu ( 1999/05/24 )
1546void
1548
1549 //...Merging...
1550 unsigned n = _tracks.length();
1551 //cout<<"tracks: "<<n<<endl;
1552 AList<TTrack> bads;
1553 unsigned * flagTrk = (unsigned *) malloc(n * sizeof(unsigned));
1554 for (unsigned i = 0; i < n; i++) flagTrk[i] = 0;
1555
1556 //...Search a track to be merged...
1557 for (unsigned i0 = 0; i0 < n; i0++) {
1558
1559 if (flagTrk[i0] != 0) continue;
1560 TTrack & t0 = * _tracks[i0];
1561 if (! (t0.pt() < 0.13)) continue;
1562
1563 unsigned Noverlap(0), Nall(0);
1564 float OverlapRatioMax(-999.);
1565 unsigned MaxID(0);
1566
1567 for (unsigned i1= 0 ; i1 < n; i1++) {
1568
1569 if (i0 == i1 || flagTrk[i1] != 0) continue;
1570 TTrack & t1 = * _tracks[i1];
1571 if (! (t1.pt() < 0.13)) continue;
1572 Nall = t1.links().length();
1573 if (! Nall) continue;
1574
1575 Noverlap = 0;
1576 for (unsigned j = 0; j < Nall; j++) {
1577 TMLink & l = * t1.links()[j];
1578 const TMDCWireHit & whit = * l.hit();
1579 double load(3.);//jialk original is 2
1580 if (whit.state() & WireHitStereo) load = 4.;//jialk original is 3
1581
1582 double x = t0.helix().center().x() - l.positionOnTrack().x();
1583 double y = t0.helix().center().y() - l.positionOnTrack().y();
1584 double r = sqrt(x * x + y * y);
1585 double R = fabs(t0.helix().radius());
1586
1587 if ((R - load) < r && r < (R + load)) Noverlap++;
1588 }
1589
1590 if (! Noverlap) continue;
1591 float tmpRatio = float(Noverlap) / float(Nall);
1592
1593 if (tmpRatio > OverlapRatioMax) {
1594 OverlapRatioMax = tmpRatio;
1595 MaxID = i1;
1596 }
1597 }
1598 //jialk caution original is 0.8
1599 if (OverlapRatioMax < 0.7) continue;
1600
1601 //...Mask should be done...
1602 unsigned MaskID[2] = {MaxID , i0};
1603 AList<TMLink> l[2];
1604
1605 for( unsigned j0=0;j0<2;j0++){
1606 for( unsigned j1=0;j1< _tracks[MaskID[j0]]->nLinks();j1++){
1607 TMLink &k = * _tracks[MaskID[j0]]->links()[j1];
1608 l[j0].append( k );
1609 }
1610 }
1611 // _tracks[i0]->links().append( _tracks[MaxID]->links() );
1612 // _tracks[MaxID]->links().append( _tracks[i0]->links ());
1613 _tracks[i0]->append(_tracks[MaxID]->links());
1614 _tracks[MaxID]->append(_tracks[i0]->links());
1615
1616#ifdef TRKRECO_DEBUG_DETAIL
1617 std::cout << " mask & merge " << std::endl;
1618 std::cout << " 0:";
1619 Dump(l[0], "flag sort");
1620 std::cout << " 1:";
1621 Dump(l[1], "flag sort");
1622 std::cout << std::endl;
1623#endif
1624
1625 //...Which should be masked out ?...
1626 unsigned maskSide = 2;
1627
1628#if 0
1629 //...0. Check by # of super layers... ( not applied now )
1630 unsigned super0 = NSuperLayers(l[0]);
1631 unsigned super1 = NSuperLayers(l[1]);
1632
1633 if( super0 < super1 ) maskSide = 0;
1634 else if ( super0 > super1 ) maskSide = 1;
1635
1636#ifdef TRKRECO_DEBUG_DETAIL
1637 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers(l[0]) << ", ";
1638 std::cout << NSuperLayers(l[1]) << std::endl;
1639#endif
1640
1641 if (maskSide == 2) {
1642#endif
1643
1644 //...1. Check by the inner-most layer...
1645 unsigned inner0 = InnerMost(l[0])->wire()->layerId();
1646 unsigned inner1 = InnerMost(l[1])->wire()->layerId();
1647 if (inner0 < inner1 ) maskSide = 1;
1648 else if (inner0 > inner1) maskSide = 0;
1649
1650 if( maskSide == 2 ){
1651
1652 //...2. Check by dz
1653
1654 //...Make two tracks...
1655 TTrack * tt[2];
1656 tt[0] = new TTrack( *(_tracks[MaskID[0]]));
1657 tt[1] = new TTrack( *(_tracks[MaskID[1]]));
1658 _fitter.fit(* tt[0]);
1659 _fitter.fit(* tt[1]);
1660 Helix h0 = Helix(tt[0]->helix());
1661 Helix h1 = Helix(tt[1]->helix());
1662
1663 //...Check dz...
1664 h0.pivot(ORIGIN);
1665 h1.pivot(ORIGIN);
1666 if (fabs(h0.dz()) < fabs(h1.dz())) maskSide = 1;
1667 else maskSide = 0;
1668
1669 delete tt[0];
1670 delete tt[1];
1671 }
1672#if 0
1673 }
1674#endif
1675 bads.append(_tracks[MaskID[maskSide]]);
1676 flagTrk[MaskID[maskSide]] = 1;
1677 }
1678
1679 //cout<<"bads: "<<bads.length()<<endl;
1680 _tracks.remove(bads);
1681
1682 //***** Masking *****
1683 n = _tracks.length();
1684
1685 for( unsigned i=0;i<n;i++){
1686 TTrack & t = * _tracks[i];
1687 for( unsigned j=0;j<t.links().length();j++){
1688 TMLink & l = * t.links()[j];
1689 const TMDCWireHit & whit = * l.hit();
1690
1691 if( !(whit.state() & WireHitFittingValid) ) continue;
1692
1693 // within half circle or not?
1694 double q = t.helix().center().x() * l.positionOnTrack().y() -
1695 t.helix().center().y() * l.positionOnTrack().x();
1696 double qq = q *t.charge();
1697
1698 if( qq > 0 ) whit.state(whit.state() & ~WireHitInvalidForFit);
1699 else whit.state(whit.state() | WireHitInvalidForFit);
1700 }
1701 }
1702
1703 free(flagTrk);
1704}
1705// end of addition
1706
1707int
1708TTrackManager::copyTrack(TTrack & t,
1709 MdcRec_trk ** pr,
1710 MdcRec_trk_add ** pra) const {
1711
1712 static const unsigned GoodHitMask = (WireHitTimeValid |
1716 int err = 0;
1717
1718 //...Hit loop...
1719#ifdef TRKRECO_DEBUG_DETAIL
1720 std::cout << " checking hits ... " << t.name()
1721 << " quality = " << t.quality();
1722 std::cout << " : " << t.cores().length() << ", " << t.ndf() << " : ";
1723 unsigned nnn = 0;
1724#endif
1725 unsigned j = 0;
1726 unsigned nClst = 0;
1727 unsigned nStereos = 0;
1728 unsigned nOccupied = 0;
1729 AList<TMLink> hits;
1730 AList<TMLink> badHits;
1731 unsigned n = t.links().length();
1732 for (unsigned i = 0; i < n; i++) {
1733 TMLink * l = t.links()[i];
1734 MdcRec_wirhit * h = l->hit()->reccdc();
1735
1736#ifdef TRKRECO_DEBUG_DETAIL
1737 if (h->trk) std::cout << l->wire()->name() << "(n/a),";
1738#endif
1739
1740 if (h->trk) {
1741 ++nOccupied;
1742 if (! (h->stat & WireHitInvalidForFit))
1743 continue;
1744 }
1745 if ((l->hit()->state() & GoodHitMask) == GoodHitMask) {
1746 if (l->hit()->state() & WireHitInvalidForFit) {
1747 if (! (h->stat & WireHitInvalidForFit))
1748 badHits.append(l);
1749 }
1750 else {
1751 hits.append(l);
1752 if (l->wire()->stereo()) ++nStereos;
1753 }
1754 }
1755 }
1756 t.finalHits(hits);
1757#ifdef TRKRECO_DEBUG_DETAIL
1758 std::cout << std::endl;
1759#endif
1760
1761 //...Check # of hits...
1762 if (t.quality() & TrackQuality2D) {
1763 if (hits.length() < 3) err = 3;
1764 if (nOccupied > 2) err = 4;
1765 }
1766 else {
1767 if (hits.length() < 5) err = 1;
1768 if (nStereos < 2) err = 2;
1769 }
1770 if (err) return err;
1771
1772 //...Create new tables...
1773 // * pr = (reccdc_trk *) BsNewEnt(RECMDC_TRK);
1774 // * pra = (reccdc_trk_add *) BsNewEnt(RECMDC_TRK_ADD);
1775 // reccdc_trk * r = * pr;
1776 // reccdc_trk_add * ra = * pra;
1777 * pr = new MdcRec_trk;
1778 * pra = new MdcRec_trk_add;
1779 MdcRec_trk* r = * pr;
1780 MdcRec_trk_add* ra = * pra;
1781
1782 //...Copy hit information...
1783 // const AList<TMLink> & cores = t.cores();
1784 // const AList<TMLink> & links = t.links();
1785 // unsigned allHits = cores.length();
1786 // unsigned stereoHits = NStereoHits(cores);
1787 // r.m_chiSq = t.chi2();
1788 // r.m_confl = t.confidenceLevel();
1789 // r.m_ndf = t.ndf();
1790 // r.m_nhits = allHits;
1791 // r.m_nster = stereoHits;
1792 float chisq = 0.;
1793 unsigned nHits = hits.length();
1794 for (unsigned i = 0; i < nHits; i++) {
1795 TMLink * l = hits[i];
1796 MdcRec_wirhit * h = hits[i]->hit()->reccdc();
1797 h->trk = r;
1798 h->pChiSq = l->pull();
1799 h->lr = l->leftRight();
1800 //zsl if (l->usecathode() == 4) ++nClst;
1801 chisq += h->pChiSq;
1802 }
1803 r->chiSq = chisq;
1804 r->nhits = nHits;
1805 r->nster = nStereos;
1806 r->ndf = nHits - 5;
1807 if (t.quality() & TrackQuality2D)
1808 r->ndf = nHits - 3;
1809
1810 //...Bad hits...
1811 n = badHits.length();
1812 for (unsigned i = 0; i < n; i++) {
1813 MdcRec_wirhit * h = badHits[i]->hit()->reccdc();
1814 h->trk = r;
1816 }
1817
1818 //...Cathode...
1819 r->nclus = nClst;
1820
1821 //...Helix parameter...
1822 const Vector & a = t.helix().a();
1823 const SymMatrix & ea = t.helix().Ea();
1824 const HepPoint3D & x = t.helix().pivot();
1825 r->helix[0] = a[0];
1826 r->helix[1] = a[1];
1827 r->helix[2] = a[2];
1828 r->helix[3] = a[3];
1829 r->helix[4] = a[4];
1830
1831 r->pivot[0] = x.x();
1832 r->pivot[1] = x.y();
1833 r->pivot[2] = x.z();
1834
1835 r->error[0] = ea[0][0];
1836 r->error[1] = ea[1][0];
1837 r->error[2] = ea[1][1];
1838 r->error[3] = ea[2][0];
1839 r->error[4] = ea[2][1];
1840 r->error[5] = ea[2][2];
1841 r->error[6] = ea[3][0];
1842 r->error[7] = ea[3][1];
1843 r->error[8] = ea[3][2];
1844 r->error[9] = ea[3][3];
1845 r->error[10] = ea[4][0];
1846 r->error[11] = ea[4][1];
1847 r->error[12] = ea[4][2];
1848 r->error[13] = ea[4][3];
1849 r->error[14] = ea[4][4];
1850
1851 //...Get outer most hit(=termination point)...
1852 TMLink * last = OuterMost(hits);
1853
1854 //...Calculate phi of the termination point...
1855 t.approach(* last);
1856 r->fiTerm = last->dPhi();
1857
1858 return err;
1859}
1860
1861void
1863 unsigned n = _tracks.length();
1864 if (n < 2) return;
1865
1866 for (unsigned i = 0; i < n - 1; i++) {
1867 TTrack & t0 = * _tracks[i];
1868 float bestRChisq = HUGE_VAL;
1869 if (t0.ndf() > 0) bestRChisq = t0.chi2() / t0.ndf();
1870 for (unsigned j = i + 1; j < n; j++) {
1871 TTrack & t1 = * _tracks[j];
1872 float rChisq = HUGE_VAL;
1873 if (t1.ndf() > 0) rChisq = t1.chi2() / t1.ndf();
1874 if (rChisq < bestRChisq) {
1875 bestRChisq = rChisq;
1876 _tracks.swap(i, j);
1877 }
1878 }
1879 }
1880}
1881
1882void
1884#ifdef TRKRECO_DEBUG_DETAIL
1885 std::cout << "trkmgr::sortTracksByPt : # of tracks="
1886 << _tracks.length() << std::endl;
1887#endif
1888
1889 unsigned n = _tracks.length();
1890 if (n < 2) return;
1891
1892 for (unsigned i = 0; i < n - 1; i++) {
1893 TTrack & t0 = * _tracks[i];
1894 float bestPt = t0.pt();
1895 for (unsigned j = i + 1; j < n; j++) {
1896 TTrack & t1 = * _tracks[j];
1897 float pt = t1.pt();
1898#ifdef TRKRECO_DEBUG_DETAIL
1899 std::cout << "i,j=" << i << "," << j
1900 << " : pt i,j=" << bestPt << "," << pt << std::endl;
1901#endif
1902 if (pt > bestPt) {
1903 bestPt = pt;
1904 _tracks.swap(i, j);
1905 }
1906 }
1907 }
1908}
1909
1910void
1912 MdcRec_trk_add & cdc1,
1913 unsigned flag) const {
1914 //...Originally coded by j.tanaka...
1915
1916 //...Check inputs...
1917 if (trk1.zero[2] == 0) return;
1918 if (cdc1.daughter == 0) return;
1919
1920 //...The other side...
1921 // reccdc_trk_add & cdc2 = * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
1922 // cdc1.m_daughter,
1923 // BBS_No_Index);
1924 // MdcRec_trk_add & cdc2 = (*MdcRecTrkAddCol::getMdcRecTrkAddCol())[cdc1.daughter.id];
1925 MdcRec_trk_add & cdc2 = * cdc1.daughter->add;
1926
1927 if (cdc2.daughter == 0) return;
1928 if (cdc2.rectrk == 0) return;
1929 // rectrk & trk2 = * (rectrk *) BsGetEnt(RECTRK, cdc2.m_rectrk, BBS_No_Index);
1930 MdcTrk & trk2 = * cdc2.rectrk;
1931
1932 if (trk2.zero[2] == 0) return;
1933
1934 //...Obtain RECTRK_LOCALZ...
1935 // rectrk_localz & z1 = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
1936 // trk1.m_zero[2],
1937 // BBS_No_Index);
1938 // rectrk_localz & z2 = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
1939 // trk2.m_zero[2],
1940 // BBS_No_Index);
1941 MdcTrk_localz & z1 = * trk1.zero[2];
1942 MdcTrk_localz & z2 = * trk2.zero[2];
1943
1944 //...Pointer to mother and daughter...
1945 MdcRec_trk_add * mother = & cdc1;
1946 MdcRec_trk_add * daughter = & cdc2;
1947
1948 // //...By dr...
1949 // if (flag == 1) {
1950 // float dr1 = fabs(z1.m_helix[0]);
1951 // float dr2 = fabs(z2.m_helix[0]);
1952 // if (dr1 > dr2) {
1953 // mother = & cdc2;
1954 // daughter = & cdc1;
1955 // }
1956 // }
1957
1958 // //...By dz...
1959 // else {
1960 // float dz1 = fabs(z1.m_helix[3]);
1961 // float dz2 = fabs(z2.m_helix[3]);
1962 // if (dz1 > dz2) {
1963 // mother = & cdc2;
1964 // daughter = & cdc1;
1965 // }
1966 // }
1967
1968 //...By dz + dr...
1969 if(flag == 3){
1970 float dz1 = fabs(z1.helix[3]);
1971 float dz2 = fabs(z2.helix[3]);
1972 if (fabs(dz1 - dz2) < 2.) flag = 1;
1973 else flag = 2;
1974 }
1975
1976 //...By dr...
1977 if(flag == 1){
1978 float dr1 = fabs(z1.helix[0]);
1979 float dr2 = fabs(z2.helix[0]);
1980 if (dr1 > dr2) {
1981 mother = & cdc2;
1982 daughter = & cdc1;
1983 }
1984 }
1985
1986 //...By dz...
1987 else if(flag == 2){
1988 float dz1 = fabs(z1.helix[3]);
1989 float dz2 = fabs(z2.helix[3]);
1990 if (dz1 > dz2) {
1991 mother = & cdc2;
1992 daughter = & cdc1;
1993 }
1994 }
1995
1996 //...Update information...
1997 mother->quality &= (~ TrackQualityOutsideCurler);
1998 mother->likelihood[0] = 1.;
1999 mother->decision |= TrackTrackManager;
2000 //zsl
2001 mother->daughter = daughter->body;
2002 mother->mother = 0;
2003 //zsl end;
2005 daughter->likelihood[0] = 0.;
2006 daughter->mother = mother->body;
2007 daughter->daughter = 0;
2008 daughter->decision |= TrackTrackManager;
2009}
2010
2011void
2013#ifdef TRKRECO_DEBUG_DETAIL
2014 std::cout << "trkmgr::sortBanksByPt : # of tracks="
2015 // << BsCouTab(RECMDC_TRK_ADD) << std::endl;
2016 << MdcRecTrkAddCol::getMdcRecTrkAddCol()->size() << std::endl;
2017#endif
2018
2019 // unsigned n = BsCouTab(RECMDC_TRK_ADD);
2020 unsigned n = MdcRecTrkAddCol::getMdcRecTrkAddCol()->size();
2021 if (n < 2) return;
2022
2023 //...Sort RECMDC...
2024 unsigned * id = (unsigned *) malloc(n * sizeof(unsigned));
2025 for (unsigned i = 0; i < n; i++) id[i] = i;
2026 for (unsigned i = 0; i < n - 1; i++) {
2027 // reccdc_trk & cdc0 =
2028 // * (reccdc_trk *) BsGetEnt(RECMDC_TRK,
2029 // i + 1,
2030 // BBS_No_Index);
2031 // reccdc_trk_add & add0 =
2032 // * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2033 // i + 1,
2034 // BBS_No_Index);
2035 // reccdc_mctrk & mc0 =
2036 // * (reccdc_mctrk *) BsGetEnt(RECMDC_MCTRK,
2037 // i + 1,
2038 // BBS_No_Index);
2039 MdcRec_trk & cdc0 = (* MdcRecTrkCol::getMdcRecTrkCol())[i];
2042
2043 float bestPt = 1. / fabs(cdc0.helix[2]);
2044 unsigned bestQuality = add0.quality;
2045 for (unsigned j = i + 1; j < n; j++) {
2046 // reccdc_trk & cdc1 =
2047 // * (reccdc_trk *) BsGetEnt(RECMDC_TRK,
2048 // j + 1,
2049 // BBS_No_Index);
2050 // reccdc_trk_add & add1 =
2051 // * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2052 // j + 1,
2053 // BBS_No_Index);
2054 // reccdc_mctrk & mc1 =
2055 // * (reccdc_mctrk *) BsGetEnt(RECMDC_MCTRK,
2056 // j + 1,
2057 // BBS_No_Index);
2058 MdcRec_trk & cdc1 = (* MdcRecTrkCol::getMdcRecTrkCol())[j];
2061
2062 float pt = 1. / fabs(cdc1.helix[2]);
2063#ifdef TRKRECO_DEBUG_DETAIL
2064 std::cout << "i,j=" << i << "," << j
2065 << " : quality i,j=" << bestQuality << ","
2066 << add1.quality << std::endl;
2067#endif
2068 unsigned quality = add1.quality;
2069 if (quality > bestQuality) continue;
2070 else if (quality < bestQuality) {
2071 bestQuality = quality;
2072 bestPt = pt;
2073 swapReccdc(cdc0, add0, mc0, cdc1, add1, mc1);
2074 unsigned tmp = id[i];
2075 id[i] = id[j];
2076 id[j] = tmp;
2077#ifdef TRKRECO_DEBUG_DETAIL
2078 std::cout << "swapped" << std::endl;
2079#endif
2080 continue;
2081 }
2082#ifdef TRKRECO_DEBUG_DETAIL
2083 std::cout << "i,j=" << i << "," << j
2084 << " : pt i,j=" << bestPt << "," << pt << std::endl;
2085#endif
2086 if (pt > bestPt) {
2087#ifdef TRKRECO_DEBUG_DETAIL
2088 std::cout << "swapping ... " << & cdc0 << "," << & add0 << ","
2089 << & mc0 << " <-> " << & cdc1 << "," << & add1 << ","
2090 << & mc1 << std::endl;
2091#endif
2092 bestQuality = quality;
2093 bestPt = pt;
2094 swapReccdc(cdc0, add0, mc0, cdc1, add1, mc1);
2095 unsigned tmp = id[i];
2096 id[i] = id[j];
2097 id[j] = tmp;
2098#ifdef TRKRECO_DEBUG_DETAIL
2099 std::cout << "swapped" << std::endl;
2100#endif
2101 }
2102 }
2103 }
2104#ifdef TRKRECO_DEBUG_DETAIL
2105 std::cout << "trkmgr::sortBanksByPt : first phase finished" << std::endl;
2106#endif
2107
2108 tagReccdc(id, n);
2109 free(id);
2110
2111#ifdef TRKRECO_DEBUG_DETAIL
2112 std::cout << "trkmgr::sortBanksByPt : second phase finished" << std::endl;
2113#endif
2114
2115#if 0
2116 //...Sort RECTRK...
2117 n = BsCouTab(RECTRK);
2118 id = (unsigned *) malloc(n * sizeof(unsigned));
2119 for (unsigned i = 0; i < n; i++) id[i] = i;
2120 if (n > 1) {
2121 unsigned i = 0;
2122 while (i < n - 1) {
2123 rectrk & t = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2124 if (t.m_prekal == (i + 1)) {
2125 ++i;
2126 continue;
2127 }
2128
2129 rectrk & s = * (rectrk *) BsGetEnt(RECTRK,
2130 t.m_prekal,
2131 BBS_No_Index);
2132
2133 swapRectrk(t, s);
2134 unsigned tmp = id[i];
2135 id[i] = id[s.m_ID - 1];
2136 id[s.m_ID - 1] = tmp;
2137
2138 //std::cout << "swap " << i + 1 << " and " << s.m_ID << std::endl;
2139
2140 reccdc_trk_add & a =
2141 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2142 t.m_prekal,
2143 BBS_No_Index);
2144 reccdc_trk_add & b =
2145 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2146 s.m_prekal,
2147 BBS_No_Index);
2148 a.m_rectrk = t.m_ID;
2149 b.m_rectrk = s.m_ID;
2150 }
2151 }
2152#else
2153 /*
2154 // jtanaka 000925 -->
2155 n = BsCouTab(RECTRK);
2156 id = (unsigned *) malloc(n * sizeof(unsigned));
2157 for (unsigned i = 0; i < n; i++) id[i] = i;
2158 int foundId = 0;
2159 while(foundId != n){
2160 rectrk & t = * (rectrk *) BsGetEnt(RECTRK, foundId + 1, BBS_No_Index);
2161 int minPrekal = t.m_prekal;
2162 int exchangeId = foundId;
2163 for(int i=foundId+1;i<n;++i){
2164 rectrk & s = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2165 if(s.m_prekal < minPrekal){
2166 minPrekal = s.m_prekal;
2167 exchangeId = i;
2168 }
2169 }
2170 if(exchangeId != foundId){
2171 rectrk & s = * (rectrk *) BsGetEnt(RECTRK,
2172 exchangeId + 1,
2173 BBS_No_Index);
2174
2175 swapRectrk(t, s);
2176 unsigned tmp = id[t.m_ID - 1];
2177 id[t.m_ID - 1] = id[s.m_ID - 1];
2178 id[s.m_ID - 1] = tmp;
2179
2180 reccdc_trk_add & a =
2181 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2182 t.m_prekal,
2183 BBS_No_Index);
2184 reccdc_trk_add & b =
2185 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2186 s.m_prekal,
2187 BBS_No_Index);
2188 a.m_rectrk = t.m_ID;
2189 b.m_rectrk = s.m_ID;
2190 }
2191 ++foundId;
2192 }
2193 // <-- jtanaka 000925
2194 */
2195#endif
2196
2197 tagRectrk(id, n);
2198 free(id);
2199}
2200
2201void
2202TTrackManager::swapReccdc(MdcRec_trk & cdc0,
2203 MdcRec_trk_add & add0,
2204 MdcRec_mctrk & mc0,
2205 MdcRec_trk & cdc1,
2206 MdcRec_trk_add & add1,
2207 MdcRec_mctrk & mc1) const {
2208#define RECMDC_ACTUAL_SIZE 124
2209#define RECMDCADD_ACTUAL_SIZE 40
2210#define RECMDCMC_ACTUAL_SIZE 28
2211
2212 static bool first = true;
2213 static void * swapRegion;
2214 if (first) {
2215 first = false;
2216 swapRegion = malloc(RECMDC_ACTUAL_SIZE);
2217 }
2218
2219 void * s0 = & cdc0.helix[0];
2220 void * s1 = & cdc1.helix[0];
2221 memcpy(swapRegion, s0, RECMDC_ACTUAL_SIZE);
2222 memcpy(s0, s1, RECMDC_ACTUAL_SIZE);
2223 memcpy(s1, swapRegion, RECMDC_ACTUAL_SIZE);
2224
2225 s0 = & add0.quality;
2226 s1 = & add1.quality;
2227 memcpy(swapRegion, s0, RECMDCADD_ACTUAL_SIZE);
2228 memcpy(s0, s1, RECMDCADD_ACTUAL_SIZE);
2229 memcpy(s1, swapRegion, RECMDCADD_ACTUAL_SIZE);
2230
2231 if ((& mc0) && (& mc1)) {
2232 s0 = & mc0.hep;
2233 s1 = & mc1.hep;
2234 memcpy(swapRegion, s0, RECMDCMC_ACTUAL_SIZE);
2235 memcpy(s0, s1, RECMDCMC_ACTUAL_SIZE);
2236 memcpy(s1, swapRegion, RECMDCMC_ACTUAL_SIZE);
2237 }
2238}
2239
2240void
2241TTrackManager::swapRectrk(MdcTrk & rec0,
2242 MdcTrk & rec1) const {
2243#define RECTRK_ACTUAL_SIZE 84
2244
2245 static bool first = true;
2246 static void * swapRegion;
2247 if (first) {
2248 first = false;
2249 swapRegion = malloc(RECTRK_ACTUAL_SIZE);
2250 }
2251
2252 void * s0 = & rec0.glob[0];
2253 void * s1 = & rec1.glob[0];
2254 memcpy(swapRegion, s0, RECTRK_ACTUAL_SIZE);
2255 memcpy(s0, s1, RECTRK_ACTUAL_SIZE);
2256 memcpy(s1, swapRegion, RECTRK_ACTUAL_SIZE);
2257}
2258
2259void
2260TTrackManager::tagReccdc(unsigned * id0, unsigned nTrk) const {
2261 /*
2262 unsigned * id = (unsigned *) malloc(nTrk * sizeof(unsigned));
2263 for (unsigned i = 0; i < nTrk; i++)
2264 id[id0[i]] = i;
2265
2266#ifdef TRKRECO_DEBUG_DETAIL
2267for (unsigned i = 0; i < nTrk; i++)
2268std::cout << "id0 " << i << " ... " << id0[i] << std::endl;
2269for (unsigned i = 0; i < nTrk; i++)
2270std::cout << "id " << i << " ... " << id[i] << std::endl;
2271#endif
2272 // unsigned n = BsCouTab(RECMDC_TRK_ADD);
2273 // unsigned n = MdcRecTrkAddCol::getMdcRecTrkAddCol()->size();
2274
2275 // for (unsigned i = 0; i < n; i++) {
2276 // reccdc_trk_add & w = * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2277 // i + 1,
2278 // BBS_No_Index);
2279 // MdcRec_trk_add & w = (* MdcRecTrkAddCol::getMdcRecTrkAddCol())[i];
2280 // if (w.mother) w.mother = id[w.mother - 1] + 1;
2281 // if (w.daughter) w.daughter = id[w.daughter - 1] + 1;
2282 // }
2283
2284#ifdef TRKRECO_DEBUG_DETAIL
2285std::cout << "TTrackManager::tagReccdc ... RECMDC_TRK_ADD done" << std::endl;
2286#endif
2287
2288n = BsCouTab(RECMDC_WIRHIT);
2289for (unsigned i = 0; i < n; i++) {
2290reccdc_wirhit & w = * (reccdc_wirhit *) BsGetEnt(RECMDC_WIRHIT,
2291i + 1,
2292BBS_No_Index);
2293if (w.m_trk == 0) continue;
2294w.m_trk = id[w.m_trk - 1] + 1;
2295}
2296
2297#ifdef TRKRECO_DEBUG_DETAIL
2298std::cout << "TTrackManager::tagReccdc ... RECMDC_WIRHIT done" << std::endl;
2299#endif
2300
2301n = BsCouTab(DATMDC_MCWIRHIT);
2302for (unsigned i = 0; i < n; i++) {
2303datcdc_mcwirhit & m =
2304 * (datcdc_mcwirhit *) BsGetEnt(DATMDC_MCWIRHIT,i + 1,BBS_No_Index);
2305 if (m.m_trk == 0) continue;
2306 m.m_trk = id[m.m_trk - 1] + 1;
2307 }
2308
2309#ifdef TRKRECO_DEBUG_DETAIL
2310std::cout << "TTrackManager::tagReccdc ... DATMDC_MCWIRHIT done" << std::endl;
2311#endif
2312
2313n = BsCouTab(RECTRK);
2314for (unsigned i = 0; i < n; i++) {
2315rectrk & r = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2316if (r.m_prekal == 0) continue;
2317r.m_prekal = id[r.m_prekal - 1] + 1;
2318}
2319
2320#ifdef TRKRECO_DEBUG_DETAIL
2321std::cout << "TTrackManager::tagReccdc ... RECTRK done" << std::endl;
2322#endif
2323
2324// jtanaka
2325n = BsCouTab(RECMDC_SVD_TRK);
2326for (unsigned i = 0; i < n; i++) {
2327reccdc_svd_trk & r = * (reccdc_svd_trk *) BsGetEnt(RECMDC_SVD_TRK, i + 1, BBS_No_Index);
2328if (r.m_cdc_trk == 0) continue;
2329r.m_cdc_trk = id[r.m_cdc_trk - 1] + 1;
2330}
2331
2332#ifdef TRKRECO_DEBUG_DETAIL
2333std::cout << "TTrackManager::tagReccdc ... RECMDC_SVD_TRK done" << std::endl;
2334#endif
2335
2336free(id);
2337*/
2338}
2339
2340void
2342 unsigned n = _tracks.length();
2343 if (n < 2) return;
2344
2345 for (unsigned i = 0; i < n - 1; i++) {
2346 TTrack & t0 = * _tracks[i];
2347 if (t0.type() != TrackTypeCurl) continue;
2348 float c0 = t0.charge();
2349
2350 for (unsigned j = i + 1; j < n; j++) {
2351 TTrack & t1 = * _tracks[j];
2352 float c1 = t1.charge();
2353 if (c0 * c1 > 0.) continue;
2354 if (t1.type() != TrackTypeCurl) continue;
2355
2356 bool toBeMerged = false;
2357 unsigned n0 = t0.testByApproach(t1.cores(), _sigmaCurlerMergeTest);
2358 if (n0 > _nCurlerMergeTest) toBeMerged = true;
2359 if (! toBeMerged) {
2360 unsigned n1 = t1.testByApproach(t0.cores(),
2361 _sigmaCurlerMergeTest);
2362 if (n1 > _nCurlerMergeTest) toBeMerged = true;
2363 }
2364
2365 if (toBeMerged) {
2366 // ++_s->_nToBeMerged;
2367 if ((t0.daughter()) || (t1.daughter()))
2368 ++_s->_nToBeMergedMoreThanTwo;
2369 t0.daughter(& t1);
2370 t1.daughter(& t0);
2371
2372 }
2373 }
2374 }
2375}
2376
2377void
2379 float maxSigma2) {
2380 //#define TRKRECO_DEBUG
2381 //#define TRKRECO_DEBUG_DETAIL
2382
2383#ifdef TRKRECO_DEBUG
2384 std::cout << "... trkmgr::salvaging associate hits" << std::endl;
2385 std::cout << " # of given hits=" << hits.length() << std::endl;
2386#endif
2387
2388 //...Check arguments...
2389 unsigned nTracks = _tracks.length();
2390 if (nTracks == 0) return;
2391 unsigned nHits = hits.length();
2392 if (nHits == 0) return;
2393
2394 static const TPoint2D o(0., 0.);
2395
2396 //...Hit loop...
2397 for (unsigned i = 0; i < nHits; i++) {
2398 TMDCWireHit & h = * hits[i];
2399
2400 //...Already used?...
2401 if (h.state() & WireHitUsed) continue;
2402#ifdef TRKRECO_DEBUG_DETAIL
2403 std::cout << " checking " << h.wire()->name();
2404#endif
2405
2406 //...Track loop...
2407 AList<TMLink> toBeDeleted;
2408 TMLink * best = NULL;
2409 TTrack * bestTrack = NULL;
2410 for (unsigned j = 0; j < nTracks; j++) {
2411 TTrack & t = * _tracks[j];
2412
2413 //...Pre-selection...
2414 TPoint2D c = t.center();
2415 TPoint2D co = - c;
2416 TPoint2D x = h.wire()->xyPosition();
2417
2418#ifdef TRKRECO_DEBUG_DETAIL
2419 std::cout << " : c= " << co.cross(x - c) * t.charge();
2420 std::cout << ", d=" << fabs((x - c).mag() - fabs(t.radius()));
2421#endif
2422
2423 if (co.cross(x - c) * t.charge() > 0.)
2424 continue;
2425 if (fabs((x - c).mag() - fabs(t.radius())) > 5.)
2426 continue;
2427
2428 //...Try to append this hit...
2429 TMLink & link = * new TMLink(0, & h);
2430 int err = t.approach(link);
2431 if (err < 0) {
2432#ifdef TRKRECO_DEBUG_DETAIL
2433 std::cout << " : " << t.name() << " approach failure";
2434#endif
2435 toBeDeleted.append(link);
2436 continue;
2437 }
2438
2439 //...Calculate sigma...
2440 float distance = link.distance();
2441 float diff = fabs(distance - link.hit()->drift());
2442 float sigma = diff / link.hit()->dDrift();
2443 link.pull(sigma * sigma);
2444
2445#ifdef TRKRECO_DEBUG_DETAIL
2446 std::cout << " : " << t.name() << " pull = " << link.pull();
2447#endif
2448 if (link.pull() > maxSigma2) {
2449 toBeDeleted.append(link);
2450 continue;
2451 }
2452
2453 if (best) {
2454 if (best->pull() > link.pull()) {
2455 toBeDeleted.append(best);
2456 best = & link;
2457 bestTrack = & t;
2458 }
2459 else {
2460 toBeDeleted.append(link);
2461 }
2462 }
2463 else {
2464 best = & link;
2465 bestTrack = & t;
2466 }
2467 }
2468
2469 if (best) {
2470 bestTrack->append(* best);
2471 best->hit()->state(best->hit()->state() | WireHitInvalidForFit);
2472 _associateHits.append(best);
2473#ifdef TRKRECO_DEBUG
2474 std::cout << " " << best->hit()->wire()->name();
2475 std::cout << " -> " << bestTrack->name() << std::endl;
2476#endif
2477 }
2478 HepAListDeleteAll(toBeDeleted);
2479
2480#ifdef TRKRECO_DEBUG_DETAIL
2481 std::cout << std::endl;
2482#endif
2483 }
2484}
2485
2486void
2487TTrackManager::maskBadHits(const AList<TTrack> & tracks, float maxSigma2) {
2488#ifdef TRKRECO_DEBUG
2489 std::cout << "... trkmgr::maskBadHits" << std::endl;
2490#endif
2491
2492 unsigned n = tracks.length();
2493 for (unsigned i = 0; i < n; i++) {
2494 TTrack & t = * tracks[i];
2495 bool toBeUpdated = false;
2496 const AList<TMLink> links = t.links();
2497 unsigned nHits = links.length();
2498 for (unsigned j = 0; j < nHits; j++) {
2499 if (links[j]->pull() > maxSigma2) {
2500 links[j]->hit()->state(links[j]->hit()->state() |
2502 toBeUpdated = true;
2503#ifdef TRKRECO_DEBUG
2504 std::cout << " " << t.name() << " : ";
2505 std::cout << links[j]->wire()->name() << "(pull=";
2506 std::cout << links[j]->pull() << ") is masked" << std::endl;
2507#endif
2508 }
2509 }
2510 if (toBeUpdated) t.update();
2511 }
2512}
2513
2514void
2516 // BsDelEnt(RECMDC_TRK, BBS_ID_ALL);
2517 // BsDelEnt(RECMDC_TRK_ADD, BBS_ID_ALL);
2518 // BsDelEnt(RECMDC_MCTRK, BBS_ID_ALL);
2519 // BsDelEnt(RECMDC_MCTRK2HEP, BBS_ID_ALL);
2520 unsigned n = MdcRecTrkCol::getMdcRecTrkCol()->size();
2521 for (unsigned i = 0; i < n; i++) delete &(*MdcRecTrkCol::getMdcRecTrkCol())[i];
2522
2524 for (unsigned i = 0; i < n; i++) delete &(*MdcRecTrkAddCol::getMdcRecTrkAddCol())[i];
2525
2527 for (unsigned i = 0; i < n; i++) delete &(*MdcRecMctrkCol::getMdcRecMctrkCol())[i];
2528
2530 for (unsigned i = 0; i < n; i++) delete &(*MdcRecMctrk2hepCol::getMdcRecMctrk2hepCol())[i];
2531
2532
2533 //...Clear track association...
2534 // unsigned n = BsCouTab(RECMDC_WIRHIT);
2536 for (unsigned i = 0; i < n; i++) {
2537 // reccdc_wirhit & h = * (reccdc_wirhit *)
2538 // BsGetEnt(RECMDC_WIRHIT, i + 1, BBS_No_Index);
2539 // h.m_trk = 0;
2541 h.trk = 0;
2542 }
2543 // n = BsCouTab(DATMDC_MCWIRHIT);
2545 for (unsigned i = 0; i < n; i++) {
2546 // datcdc_mcwirhit & h = * (datcdc_mcwirhit *)
2547 // BsGetEnt(DATMDC_MCWIRHIT, i + 1, BBS_No_Index);
2548 // h.m_trk = 0;
2550 h.trk = 0;
2551 }
2552}
2553
2555TTrackManager::selectGoodTracks(const AList<TTrack> & list,
2556 bool track2D) const {
2557 AList<TTrack> goodTracks;
2558 unsigned n = list.length();
2559 for (unsigned i = 0; i < n; i++) {
2560 const TTrack & t = * list[i];
2561 if (! goodTrack(t, track2D)) continue;
2562
2563 //...Remove super momentum...
2564 if (_maxMomentum > 0.) {
2565 if (t.ptot() > _maxMomentum) {
2566 // ++_s->_nSuperMoms;
2567 continue;
2568 }
2569 }
2570
2571 goodTracks.append((TTrack &) t);
2572 }
2573
2574 if (_debugLevel) {
2575 if (list.length() != goodTracks.length()) {
2576 std::cout << "TTrackManager::selectGoodTracks ... bad tracks found"
2577 << std::endl
2578 << " # of bad tracks = "
2579 << list.length() - goodTracks.length()
2580 << " : 2D flag = " << track2D << std::endl;
2581 AList<TTrack> tmp;
2582 tmp.append(list);
2583 tmp.remove(goodTracks);
2584 std::cout << " Track dump" << std::endl;
2585 for (unsigned i = 0; i < tmp.length(); i++) {
2586 std::cout << " " << TrackDump(* tmp[i]) << std::endl;
2587 }
2588 }
2589 }
2590
2591 return goodTracks;
2592}
2593
2594bool
2595TTrackManager::checkNumberOfHits(const TTrack & t, bool track2D) {
2596 const AList<TMLink> & cores = t.cores();
2597
2598 if (track2D) {
2599 unsigned axialHits = NAxialHits(cores);
2600 if (axialHits < 3) return false;
2601 }
2602 else {
2603 unsigned allHits = cores.length();
2604 if (allHits < 5) return false;
2605 unsigned stereoHits = NStereoHits(cores);
2606 if (stereoHits < 2) return false;
2607 unsigned axialHits = allHits - stereoHits;
2608 if (axialHits < 3) return false;
2609 }
2610 return true;
2611}
2612
2613void
2615 static const HepVector3D InitialVertex(0., 0., 0.);
2616
2617 //...Track selection...
2618 // unsigned n = BsCouTab(RECTRK);
2619 unsigned n = MdcTrkCol::getMdcTrkCol()->size();
2621 for (unsigned i = 0; i < n; i++) {
2622 // const rectrk & t = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2623 const MdcTrk & t = (* MdcTrkCol::getMdcTrkCol())[i];
2624
2625 if (t.prekal == 0) continue;
2626 // const reccdc_trk_add & c = * (reccdc_trk_add *)
2627 // BsGetEnt(RECMDC_TRK_ADD, t.m_prekal, BBS_No_Index);
2628 const MdcRec_trk_add & c = * t.prekal->add;
2629
2630 //...Only good tracks...
2631 if (c.quality) continue;
2632
2633 //...Require SVD hits...
2634 // const rectrk_global & g = * (rectrk_global *) BsGetEnt(RECTRK_GLOBAL,
2635 // t.m_glob[2],
2636 // BBS_No_Index);
2637 const MdcTrk_global & g = * t.glob[2];
2638
2639 if (! & g) continue;
2640 if (g.nhits[3] < 2) continue;
2641 if (g.nhits[4] < 2) continue;
2642
2643 //...OK...
2644 // const rectrk_localz & z = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
2645 // t.m_zero[2],
2646 // BBS_No_Index);
2647 MdcTrk_localz & z = * t.zero[2];
2648
2649 if (! & z) continue;
2650 // zList.append((rectrk_localz &) z);
2651 zList.append(z);
2652 }
2653 unsigned nZ = zList.length();
2654 if (nZ < 2) return;
2655
2656 //...Fitting...
2657 // kvertexfitter kvf;
2658 // kvf.initialVertex(initialVertex);
2659 // for (unsigned i = 0; i < nZ; i++) {
2660 // kvf.addTrack();
2661 // }
2662
2663}
2664
2665void
2666TTrackManager::tagRectrk(unsigned * id0, unsigned nTrk) const {
2667 /*
2668 unsigned * id = (unsigned *) malloc(nTrk * sizeof(unsigned));
2669 for (unsigned i = 0; i < nTrk; i++)
2670 id[id0[i]] = i;
2671
2672 // for (unsigned i = 0; i < nTrk; i++)
2673 // std::cout << "id0 " << i << " ... " << id0[i] << std::endl;
2674 // for (unsigned i = 0; i < nTrk; i++)
2675 // std::cout << "id " << i << " ... " << id[i] << std::endl;
2676 // BsShwDat(RECTRK_TOF);
2677
2678 unsigned n = BsCouTab(RECTRK_TOF);
2679 for (unsigned i = 0; i < n; i++) {
2680 rectrk_tof & t = * (rectrk_tof *) BsGetEnt(RECTRK_TOF,
2681 i + 1,
2682 BBS_No_Index);
2683 if (t.m_rectrk) t.m_rectrk = id[t.m_rectrk - 1] + 1;
2684 }
2685
2686 // BsShwDat(RECTRK_TOF);
2687
2688 // jtanaka
2689 n = BsCouTab(RECSVD_HIT);
2690 for (unsigned i = 0; i < n; i++) {
2691 recsvd_hit & t = * (recsvd_hit *) BsGetEnt(RECSVD_HIT,
2692 i + 1,
2693 BBS_No_Index);
2694 if (t.m_trk) t.m_trk = id[t.m_trk - 1] + 1;
2695 }
2696
2697 free(id);
2698 */
2699}
2700
2701/*
2702// jtanaka 000925 -->
2703#define TRKRECO_REPLACE_TABLE 1
2704#if !(TRKRECO_REPLACE_TABLE)
2705void
2706copyRecMDC_trk_Table(const Reccdc_trk & org,
2707Reccdc_trk & copied)
2708{
2709copied.helix(0, org.helix(0));
2710copied.helix(1, org.helix(1));
2711copied.helix(2, org.helix(2));
2712copied.helix(3, org.helix(3));
2713copied.helix(4, org.helix(4));
2714copied.pivot(0, org.pivot(0));
2715copied.pivot(1, org.pivot(1));
2716copied.pivot(2, org.pivot(2));
2717copied.error(0, org.error(0));
2718copied.error(1, org.error(1));
2719copied.error(2, org.error(2));
2720copied.error(3, org.error(3));
2721copied.error(4, org.error(4));
2722copied.error(5, org.error(5));
2723copied.error(6, org.error(6));
2724copied.error(7, org.error(7));
2725copied.error(8, org.error(8));
2726copied.error(9, org.error(9));
2727copied.error(10, org.error(10));
2728copied.error(11, org.error(11));
2729copied.error(12, org.error(12));
2730copied.error(13, org.error(13));
2731copied.error(14, org.error(14));
2732copied.chiSq(org.chiSq());
2733copied.ndf(org.ndf());
2734copied.fiTerm(org.fiTerm());
2735copied.nhits(org.nhits());
2736copied.nster(org.nster());
2737copied.nclus(org.nclus());
2738copied.stat(org.stat());
2739copied.mass(org.mass());
2740}
2741
2742void
2743copyRecMDC_trk_add_Table(const Reccdc_trk_add & org,
2744Reccdc_trk_add & copied)
2745{
2746copied.quality(org.quality());
2747copied.kind(org.kind());
2748copied.mother(org.mother());
2749copied.daughter(org.daughter());
2750copied.decision(org.decision());
2751copied.likelihood(0, org.likelihood(0));
2752copied.likelihood(1, org.likelihood(1));
2753copied.likelihood(2, org.likelihood(2));
2754copied.stat(org.stat());
2755copied.rectrk(org.rectrk());
2756}
2757
2758void
2759copyRecMDC_MCtrk_Table(const Reccdc_mctrk & org,
2760Reccdc_mctrk & copied)
2761{
2762copied.hep(org.hep());
2763copied.wirFrac(org.wirFrac());
2764copied.wirFracHep(org.wirFracHep());
2765copied.charge(org.charge());
2766copied.ptFrac(org.ptFrac());
2767copied.pzFrac(org.pzFrac());
2768copied.quality(org.quality());
2769}
2770
2771void
2772copyRecMDC_MCtrk2hep_Table(const Reccdc_mctrk2hep & org,
2773 Reccdc_mctrk2hep & copied)
2774{
2775 copied.wir(org.wir());
2776 copied.clust(org.clust());
2777 copied.trk(org.trk());
2778 copied.hep(org.hep());
2779}
2780#endif
2781
2782void
2783TTrackManager::addSvd(const int mcFlag) const {
2784 TSvdAssociator svdA(-20000.,20000.);
2785 svdA.fillClusters();
2786
2787 //BsShwDat(RECTRK);
2788 //BsShwDat(RECMDC_TRK);
2789 //BsShwDat(RECMDC_MCTRK);
2790
2791 Reccdc_trk_Manager& trkMgr =
2792 Reccdc_trk_Manager::get_manager();
2793 Reccdc_trk_add_Manager& trkMgr2 =
2794 Reccdc_trk_add_Manager::get_manager();
2795 Reccdc_svd_trk_Manager& svdMgr =
2796 Reccdc_svd_trk_Manager::get_manager();
2797
2798#if !(TRKRECO_REPLACE_TABLE)
2799 Reccdc_wirhit_Manager& wirMgr =
2800 Reccdc_wirhit_Manager::get_manager();
2801 Reccdc_mctrk_Manager& mcMgr =
2802 Reccdc_mctrk_Manager::get_manager();
2803 Reccdc_mctrk2hep_Manager& mcMgr2 =
2804 Reccdc_mctrk2hep_Manager::get_manager();
2805 Datcdc_mcwirhit_Manager& mcMgr3 =
2806 Datcdc_mcwirhit_Manager::get_manager();
2807#endif
2808
2809 int nSize = trkMgr.count();
2810 for(int i=0;i<nSize;++i){
2811 //std::cout << "trk " << i << ": " << trkMgr[i].helix(0) << std::endl;
2812#if 1
2813 // Reconstruction Info --> SVD Recon.
2814 if(trkMgr2[i].decision() != TrackPMCurlFinder &&
2815 (trkMgr2[i].quality() & TrackQuality2D) != TrackQuality2D &&
2816 trkMgr[i].helix(2) != 0. && fabs(1./trkMgr[i].helix(2))<0.2){
2817 HepVector a(5);
2818 a[0] = trkMgr[i].helix(0);
2819 a[1] = trkMgr[i].helix(1);
2820 a[2] = trkMgr[i].helix(2);
2821 a[3] = trkMgr[i].helix(3);
2822 a[4] = trkMgr[i].helix(4);
2823 HepPoint3D p(trkMgr[i].pivot(0),
2824 trkMgr[i].pivot(1),
2825 trkMgr[i].pivot(2));
2826 Helix th(p,a);
2827 th.pivot(HepPoint3D(0.,0.,0.)); // pivot = (0,0,0)
2828 AList<TSvdHit> cand;
2829 double tz,tt;
2830 if(svdA.recTrk(th,tz,tt,0.5,50.0,cand,0.5)){
2831 //std::cout << "SVD in " << i << std::endl;
2832#if TRKRECO_REPLACE_TABLE
2833 Reccdc_svd_trk & newSvd = svdMgr.add();
2834#else
2835 Reccdc_trk & newTrk = trkMgr.add();
2836 Reccdc_trk_add & newTrk2 = trkMgr2.add();
2837 Reccdc_svd_trk & newSvd = svdMgr.add();
2838 // copy all information
2839 copyRecMDC_trk_Table(trkMgr[i],newTrk);
2840 copyRecMDC_trk_add_Table(trkMgr2[i],newTrk2);
2841#endif
2842 if(mcFlag){
2843#if TRKRECO_REPLACE_TABLE
2844 ;
2845#else
2846 Reccdc_mctrk & newMcTrk = mcMgr.add();
2847 copyRecMDC_MCtrk_Table(mcMgr[i],mcMgr[mcMgr.count()-1]);
2848 int nMCt2h = mcMgr2.count();
2849 for(int j=0;j<nMCt2h;++j){
2850 if(mcMgr2[j].trk() &&
2851 mcMgr2[j].trk().get_ID() == trkMgr[i].get_ID()){
2852 Reccdc_mctrk2hep & newMcTrk2Hep = mcMgr2.add();
2853 copyRecMDC_MCtrk2hep_Table(mcMgr2[j],newMcTrk2Hep);
2854 newMcTrk2Hep.trk(newTrk);
2855 }
2856 }
2857 int nMCwire = mcMgr3.count();
2858 for(int j=0;j<nMCwire;++j){
2859 if(mcMgr3[j].trk().get_ID() == trkMgr[i].get_ID()){
2860 mcMgr3[j].trk(newTrk);
2861 }
2862 }
2863#endif
2864 }
2865 HepVector ta = th.a(); // pivot = (0,0,0)
2866 ta[3] = tz;
2867 ta[4] = tt;
2868 th.a(ta);
2869 th.pivot(p); // pivot, (0,0,0) --> p
2870#if TRKRECO_REPLACE_TABLE
2871 trkMgr[i].helix(3, th.a()[3]);
2872 trkMgr[i].helix(4, th.a()[4]);
2873#else
2874 newTrk.helix(3, th.a()[3]);
2875 newTrk.helix(4, th.a()[4]);
2876#endif
2877
2878 newSvd.Helix(0, ta[0]);
2879 newSvd.Helix(1, ta[1]);
2880 newSvd.Helix(2, ta[2]);
2881 newSvd.Helix(3, ta[3]);
2882 newSvd.Helix(4, ta[4]);
2883#if TRKRECO_REPLACE_TABLE
2884 newSvd.cdc_trk(trkMgr2[i]);
2885#else
2886 newSvd.cdc_trk(newTrk2);
2887#endif
2888 newSvd.Status(0); // 0 is normal.
2889 int indexSvd = 0;
2890 for(int j=0;j<cand.length();++j){
2891 if(indexSvd >= 16)break;
2892 if((cand[j])->rphi() && (cand[j])->z()){
2893 newSvd.svd_cluster(indexSvd, *(cand[j]->rphi()));
2894 ++indexSvd;
2895 newSvd.svd_cluster(indexSvd, *(cand[j]->z()));
2896 ++indexSvd;
2897 }else{
2898 std::cerr << "[TTrackManager of TrkReco] Why ? no associated SVDhit ?" << std::endl;
2899 }
2900 }
2901#if TRKRECO_REPLACE_TABLE
2902 trkMgr2[i].quality(0); // set to 0 --> GOOD!
2903 trkMgr2[i].decision((trkMgr2[i].decision() | TrackSVDAssociator));
2904#else
2905 newTrk2.quality(1); // temporary
2906 newTrk2.decision((newTrk2.decision() | TrackSVDAssociator));
2907#endif
2908#if !(TRKRECO_REPLACE_TABLE)
2909 // MDC Wire information
2910 for(int j=0;j<wirMgr.count();++j){
2911 if(wirMgr[j].trk() &&
2912 wirMgr[j].trk().get_ID() == trkMgr[i].get_ID()){
2913 wirMgr[j].trk(newTrk);
2914 }
2915 }
2916#endif
2917 }else if(fabs(th.a()[3]) > 30.){
2918 if(svdA.recTrk(th,tz,tt,0.5,-1.0,cand,0.5)){
2919 //std::cout << "SVD in " << i << std::endl;
2920#if TRKRECO_REPLACE_TABLE
2921 Reccdc_svd_trk & newSvd = svdMgr.add();
2922#else
2923 Reccdc_trk & newTrk = trkMgr.add();
2924 Reccdc_trk_add & newTrk2 = trkMgr2.add();
2925 Reccdc_svd_trk & newSvd = svdMgr.add();
2926 // copy all information
2927 copyRecMDC_trk_Table(trkMgr[i],newTrk);
2928 copyRecMDC_trk_add_Table(trkMgr2[i],newTrk2);
2929#endif
2930 if(mcFlag){
2931#if TRKRECO_REPLACE_TABLE
2932 ;
2933#else
2934 Reccdc_mctrk & newMcTrk = mcMgr.add();
2935 copyRecMDC_MCtrk_Table(mcMgr[i],mcMgr[mcMgr.count()-1]);
2936 int nMCt2h = mcMgr2.count();
2937 for(int j=0;j<nMCt2h;++j){
2938 if(mcMgr2[j].trk() &&
2939 mcMgr2[j].trk().get_ID() == trkMgr[i].get_ID()){
2940 Reccdc_mctrk2hep & newMcTrk2Hep = mcMgr2.add();
2941 copyRecMDC_MCtrk2hep_Table(mcMgr2[j],newMcTrk2Hep);
2942 newMcTrk2Hep.trk(newTrk);
2943 }
2944 }
2945 int nMCwire = mcMgr3.count();
2946 for(int j=0;j<nMCwire;++j){
2947 if(mcMgr3[j].trk().get_ID() == trkMgr[i].get_ID()){
2948 mcMgr3[j].trk(newTrk);
2949 }
2950 }
2951#endif
2952 }
2953 HepVector ta = th.a(); // pivot = (0,0,0)
2954 ta[3] = tz;
2955 ta[4] = tt;
2956 th.a(ta);
2957 th.pivot(p); // pivot, (0,0,0) --> p
2958#if TRKRECO_REPLACE_TABLE
2959 trkMgr[i].helix(3, th.a()[3]);
2960 trkMgr[i].helix(4, th.a()[4]);
2961#else
2962 newTrk.helix(3, th.a()[3]);
2963 newTrk.helix(4, th.a()[4]);
2964#endif
2965
2966 newSvd.Helix(0, ta[0]);
2967 newSvd.Helix(1, ta[1]);
2968 newSvd.Helix(2, ta[2]);
2969 newSvd.Helix(3, ta[3]);
2970 newSvd.Helix(4, ta[4]);
2971#if TRKRECO_REPLACE_TABLE
2972 newSvd.cdc_trk(trkMgr2[i]);
2973#else
2974 newSvd.cdc_trk(newTrk2);
2975#endif
2976 newSvd.Status(0); // 0 is normal.
2977 int indexSvd = 0;
2978 for(int j=0;j<cand.length();++j){
2979 if(indexSvd >= 16)break;
2980 if((cand[j])->rphi() && (cand[j])->z()){
2981 newSvd.svd_cluster(indexSvd, *(cand[j]->rphi()));
2982 ++indexSvd;
2983 newSvd.svd_cluster(indexSvd, *(cand[j]->z()));
2984 ++indexSvd;
2985 }else{
2986 std::cerr << "[TTrackManager of TrkReco] Why ? no associated SVDhit ?" << std::endl;
2987 }
2988 }
2989#if TRKRECO_REPLACE_TABLE
2990 trkMgr2[i].quality(0); // set to 0 --> GOOD!
2991 trkMgr2[i].decision((trkMgr2[i].decision() | TrackSVDAssociator));
2992#else
2993 newTrk2.quality(1); // temporary
2994 newTrk2.decision((newTrk2.decision() | TrackSVDAssociator));
2995#endif
2996#if !(TRKRECO_REPLACE_TABLE)
2997 // MDC Wire information
2998 for(int j=0;j<wirMgr.count();++j){
2999 if(wirMgr[j].trk() &&
3000 wirMgr[j].trk().get_ID() == trkMgr[i].get_ID()){
3001 wirMgr[j].trk(newTrk);
3002 }
3003 }
3004#endif
3005 }
3006 }
3007 }
3008 }
3009#endif
3010}
3011// <-- jtanaka 000925
3012*/
3013
3014bool
3015TTrackManager::goodTrack(const TTrack & t, bool track2D) {
3016
3017 //...Check number of hits...
3018 if (! checkNumberOfHits(t, track2D)) return false;
3019
3020 //...Check helix parameter...
3021 if (HelixHasNan(t.helix())) return false;
3022
3023 return true;
3024}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
const int nZ
std::string cal
Definition: CalibModel.cxx:41
double length
const Int_t n
Double_t x[10]
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
Definition: EvtVector3R.cc:84
const double alpha
XmlRpcServer s
Definition: HelloServer.cpp:11
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition: KKsem.h:33
std::vector< MdcDigi * > MdcDigiVec
ObjectVector< RecEsTime > RecEsTimeCol
Definition: RecEsTime.h:53
ObjectVector< RecMdcHit > RecMdcHitCol
Definition: RecMdcHit.h:99
ObjectVector< RecMdcTrack > RecMdcTrackCol
Definition: RecMdcTrack.h:102
SmartRefVector< RecMdcHit > HitRefVec
Definition: RecMdcTrack.h:26
int n1
Definition: SD0Tag.cxx:54
IMessageSvc * msgSvc()
const HepPoint3D ORIGIN
Constants.
Definition: TMDCUtil.cxx:47
#define WireHitChargeValid
Definition: TMDCWireHit.h:27
#define WireHitFindingValid
Definition: TMDCWireHit.h:28
#define WireHitFittingValid
Definition: TMDCWireHit.h:29
#define WireHitTimeValid
Definition: TMDCWireHit.h:26
#define WireHitUsed
Definition: TMDCWireHit.h:47
#define WireHitStereo
Definition: TMDCWireHit.h:31
#define WireHitInvalidForFit
Definition: TMDCWireHit.h:55
#define X1
#define RECMDCADD_ACTUAL_SIZE
#define X0
#define RECMDCMC_ACTUAL_SIZE
#define RECTRK_ACTUAL_SIZE
#define RECMDC_ACTUAL_SIZE
int SortByPt(const void *av, const void *bv)
Utility functions.
Definition: TTrack.cxx:2530
bool HelixHasNan(const Helix &h)
Helix parameter validity.
Definition: TTrack.cxx:3934
#define TrackTypeNormal
Definition: TTrack.h:34
#define TrackQuality2D
Definition: TTrack.h:47
std::string TrackDump(const TTrack &)
to dump a track.
Definition: TTrack.h:697
#define TrackTrackManager
Definition: TTrack.h:27
#define TrackTypeCurl
Definition: TTrack.h:35
#define TrackQualityOutsideCurler
Definition: TTrack.h:44
const double theta() const
Definition: DstMdcTrack.h:59
void setFirstLayer(const int id)
Definition: DstMdcTrack.h:101
void setPxy(const double pxy)
Definition: DstMdcTrack.h:86
const double r() const
Definition: DstMdcTrack.h:64
const double py() const
Definition: DstMdcTrack.h:56
void setTrackId(const int trackId)
Definition: DstMdcTrack.h:84
void setPy(const double py)
Definition: DstMdcTrack.h:88
const HepSymMatrix err() const
void setZ(const double z)
Definition: DstMdcTrack.h:95
void setNster(const int ns)
Definition: DstMdcTrack.h:100
void setX(const double x)
Definition: DstMdcTrack.h:93
void setError(double err[15])
void setNdof(const int ndof)
Definition: DstMdcTrack.h:99
const double chi2() const
Definition: DstMdcTrack.h:66
void setTheta(const double theta)
Definition: DstMdcTrack.h:91
void setStat(const int stat)
Definition: DstMdcTrack.h:97
const int charge() const
Definition: DstMdcTrack.h:53
const int trackId() const
Definition: DstMdcTrack.h:52
const double px() const
Definition: DstMdcTrack.h:55
const double phi() const
Definition: DstMdcTrack.h:60
void setP(const double p)
Definition: DstMdcTrack.h:90
void setHelix(double helix[5])
void setPoca(double poca[3])
const double pz() const
Definition: DstMdcTrack.h:57
void setR(const double r)
Definition: DstMdcTrack.h:96
void setCharge(const int charge)
Definition: DstMdcTrack.h:85
const double pxy() const
Definition: DstMdcTrack.h:54
const int ndof() const
Definition: DstMdcTrack.h:67
void setLastLayer(const int id)
Definition: DstMdcTrack.h:102
const int stat() const
Definition: DstMdcTrack.h:65
const HepVector helix() const
......
const double z() const
Definition: DstMdcTrack.h:63
void setY(const double y)
Definition: DstMdcTrack.h:94
void setChi2(const double chi)
Definition: DstMdcTrack.h:98
void setPhi(const double phi)
Definition: DstMdcTrack.h:92
void setPz(const double pz)
Definition: DstMdcTrack.h:89
const double p() const
Definition: DstMdcTrack.h:58
const int nster() const
Definition: DstMdcTrack.h:68
const double y() const
Definition: DstMdcTrack.h:62
const double x() const
Definition: DstMdcTrack.h:61
void setPx(const double px)
Definition: DstMdcTrack.h:87
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
virtual double getReferField()=0
static vector< MdcDat_mcwirhit > * getMdcDatMcwirhitCol(void)
Definition: MdcTables.cxx:315
MdcRec_trk * trk
Definition: MdcTables.h:662
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
Definition: MdcID.cxx:77
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
static vector< MdcRec_mctrk2hep > * getMdcRecMctrk2hepCol(void)
Definition: MdcTables.cxx:341
static vector< MdcRec_mctrk > * getMdcRecMctrkCol(void)
Definition: MdcTables.cxx:328
static vector< MdcRec_trk_add > * getMdcRecTrkAddCol(void)
Definition: MdcTables.cxx:356
static vector< MdcRec_trk > * getMdcRecTrkCol(void)
Definition: MdcTables.cxx:185
static vector< MdcRec_wirhit > * getMdcRecWirhitCol(void)
Definition: MdcTables.cxx:169
MdcRec_wirhit * wir
Definition: MdcTables.h:710
MdcRec_trk * trk
Definition: MdcTables.h:712
const Gen_hepevt * hep
Definition: MdcTables.h:713
float ptFrac
Definition: MdcTables.h:690
float pzFrac
Definition: MdcTables.h:691
float wirFracHep
Definition: MdcTables.h:688
const Gen_hepevt * hep
Definition: MdcTables.h:686
float wirFrac
Definition: MdcTables.h:687
MdcRec_trk * body
Definition: MdcTables.h:767
MdcTrk * rectrk
Definition: MdcTables.h:773
float likelihood[3]
Definition: MdcTables.h:771
MdcRec_trk * mother
Definition: MdcTables.h:768
MdcRec_trk * daughter
Definition: MdcTables.h:769
float helix[5]
Definition: MdcTables.h:403
float chiSq
Definition: MdcTables.h:406
float fiTerm
Definition: MdcTables.h:408
MdcRec_trk_add * add
Definition: MdcTables.h:415
float pivot[3]
Definition: MdcTables.h:404
float error[15]
Definition: MdcTables.h:405
float ndf
Definition: MdcTables.h:407
float pChiSq
Definition: MdcTables.h:332
unsigned timechannel
Definition: MdcTables.h:341
MdcRec_trk * trk
Definition: MdcTables.h:337
static vector< MdcTrk > * getMdcTrkCol(void)
Definition: TrkTables.cxx:11
int nhits[5]
Definition: TrkTables.h:155
float helix[5]
Definition: TrkTables.h:197
MdcTrk_global * glob[5]
Definition: TrkTables.h:60
MdcTrk_localz * zero[5]
Definition: TrkTables.h:61
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
void setMdcId(Identifier mdcid)
Definition: RecMdcHit.h:67
void setErrDriftDistRight(double erddr)
Definition: RecMdcHit.h:63
void setFltLen(double fltLen)
Definition: RecMdcHit.h:74
void setErrDriftDistLeft(double erddl)
Definition: RecMdcHit.h:62
void setDriftDistLeft(double ddl)
Definition: RecMdcHit.h:60
void setDoca(double doca)
Definition: RecMdcHit.h:71
void setStat(int stat)
Definition: RecMdcHit.h:66
void setTdc(double tdc)
Definition: RecMdcHit.h:68
void setAdc(double adc)
Definition: RecMdcHit.h:69
void setFlagLR(int lr)
Definition: RecMdcHit.h:65
void setChisqAdd(double pChisq)
Definition: RecMdcHit.h:64
void setZhit(double zhit)
Definition: RecMdcHit.h:73
void setDriftT(double driftT)
Definition: RecMdcHit.h:70
void setDriftDistRight(double ddr)
Definition: RecMdcHit.h:61
void setTrkId(int trkid)
Definition: RecMdcHit.h:59
void setId(int id)
Definition: RecMdcHit.h:58
void setEntra(double entra)
Definition: RecMdcHit.h:72
const HitRefVec getVecHits(void) const
Definition: RecMdcTrack.h:67
void setPivot(const HepPoint3D &pivot)
Definition: RecMdcTrack.h:79
void setVZ0(double z0)
Definition: RecMdcTrack.h:76
const int getNhits() const
Definition: RecMdcTrack.h:56
void setVY0(double y0)
Definition: RecMdcTrack.h:75
void setVecHits(HitRefVec vechits)
Definition: RecMdcTrack.cxx:80
void setNhits(int nhits)
Definition: RecMdcTrack.h:78
void setFiTerm(double fiterm)
Definition: RecMdcTrack.h:77
void setVX0(double x0)
Definition: RecMdcTrack.h:74
bool fit2D(void) const
sets/returns 2D flag.
Definition: THelixFitter.h:169
bool tof(void) const
sets/returns propagation-delay correction flag.
Definition: THelixFitter.h:207
int fit(TTrackBase &) const
Definition: THelixFitter.h:231
bool propagation(void) const
sets/returns propagation-delay correction flag.
Definition: THelixFitter.h:193
unsigned nWires(void) const
returns # of wires.
Definition: TMDCLayer.h:139
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
MdcDat_mcwirhit * datcdc(void) const
returns a pointer to DATMDC_MCWIRHIT.
struct MdcRec_wirhit * reccdc(void) const
returns a pointer to RECMDC_WIRHIT.
Definition: TMDCWireHit.h:224
unsigned state(void) const
returns state.
Definition: TMDCWireHit.h:230
float dDrift(unsigned) const
returns drift distance error.
Definition: TMDCWireHit.h:243
float drift(unsigned) const
returns drift distance.
Definition: TMDCWireHit.h:236
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
Definition: TMDCWireHit.h:218
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
Definition: TMDCWireHit.h:298
A class to represent a wire in MDC.
Definition: TMDCWire.h:55
const TMDCLayer *const layer(void) const
returns a pointer to a layer.
Definition: TMDCWire.h:243
unsigned localId(void) const
returns local id in a wire layer.
Definition: TMDCWire.h:213
unsigned layerId(void) const
returns layer id.
Definition: TMDCWire.h:219
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
Definition: TMDCWire.h:327
bool stereo(void) const
returns true if this wire is in a stereo layer.
Definition: TMDCWire.h:354
std::string name(void) const
returns name.
Definition: TMDCWire.h:412
A class to represent a point in 2D.
Definition: TPoint2D.h:37
double cross(const TPoint2D &) const
Definition: TPoint2D.h:139
unsigned testByApproach(const TMLink &list, double sigma) const
returns # of good hits to be appended.
Definition: TTrackBase.cxx:255
void append(TMLink &)
appends a TMLink.
Definition: TTrackBase.cxx:362
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:297
void remove(TMLink &a)
removes a TMLink.
Definition: TTrackBase.h:204
void appendByApproach(AList< TMLink > &list, double maxSigma)
appends TMLinks by approach. 'list' is an input. Unappended TMLinks will be removed from 'list' when ...
Definition: TTrackBase.cxx:101
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:317
const Gen_hepevt * gen(void) const
returns a pointer to Gen_hepevt.
Definition: TTrackHEP.h:184
A class to have MC information of TTrack.
Definition: TTrackMC.h:54
double wireFractionHEP(void) const
returns wire fraction(F2).
Definition: TTrackMC.h:205
const TTrackHEP *const hep(void) const
returns a pointer to TTrackHEP.
Definition: TTrackMC.h:175
unsigned quality(void) const
returns quality.
Definition: TTrackMC.h:217
bool charge(void) const
returns charge matching.
Definition: TTrackMC.h:181
double ptFraction(void) const
returns pt fraction.
Definition: TTrackMC.h:187
double pzFraction(void) const
returns pz fraction.
Definition: TTrackMC.h:193
double wireFraction(void) const
returns wire fraction(F1).
Definition: TTrackMC.h:199
void movePivot(void)
moves pivot of tracks.
void append2D(AList< TTrack > &list)
void maskOut(TTrack &, const AList< TMLink > &) const
void removeHitsAcrossOverIp(AList< TMLink > &) const
static void maskBadHits(const AList< TTrack > &, float maxSigma2)
masks hits with large chisq as associated hits. Pull in TMLink is used.
void clearTables(void) const
clears tables.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
void merge(void)
void maskNormal(TTrack &) const
virtual ~TTrackManager()
Destructor.
void finish(void)
finishes tracks.
TTrack * closest(const AList< TTrack > &, const TMDCWireHit &) const
returns a track which is the closest to a hit.
void append(AList< TTrack > &list)
appends (2D) tracks. 'list' will be cleaned up.
void saveTables(void)
stores track info. into Panther table.
std::string version(void) const
returns version.
void salvageAssociateHits(const AList< TMDCWireHit > &, float maxSigma2)
salvages hits for dE/dx(not for track fitting).
void refit(void)
refits tracks.
TMLink & divide(const TTrack &t, AList< TMLink > *l) const
StatusCode makeTds(RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat=1, int runge=0, int cal=0)
stores track info. into TDS. by Zang Shilei
void setCurlerFlags(void)
tests for curlers.
void maskMultiHits(TTrack &) const
void determineIP(void)
determines IP.
static bool goodTrack(const TTrack &, bool track2D=false)
checks goodness of a track.
const AList< TTrack > & tracks(void) const
returns a list of reconstructed tracks.
std::string name(void) const
returns name.
TTrackManager()
Constructor.
void maskCurl(TTrack &) const
void saveMCTables(void) const
stores MC track info. into Panther table.
void mask(void) const
masks hits out which are in tail of curly tracks.
TMLink & divideByIp(const TTrack &t, AList< TMLink > *l) const
void sortBanksByPt(void) const
sorts RECMDC_TRK tables.
void sortTracksByQuality(void)
sorts tracks.
void treatCurler(MdcTrk &curl, MdcRec_trk_add &cdc, unsigned flag) const
final decision for a curler.
void maskCurlHits(const AList< TMDCWireHit > &axial, const AList< TMDCWireHit > &stereo, const AList< TTrack > &tracks) const
masks hits on found curl tracks.
StatusCode determineT0(unsigned level, unsigned nMaxTracks)
determines T0 and refit all tracks.
void salvage(const AList< TMDCWireHit > &) const
salvages remaining hits.
void clear(void)
clears all internal information.
void sortTracksByPt(void)
A class to represent a track in tracking.
Definition: TTrack.h:129
const Helix & helix(void) const
returns helix parameter.
Definition: TTrack.h:477
unsigned ndf(void) const
returns NDF.
Definition: TTrack.h:486
const std::string & name(void) const
returns/sets name.
Definition: TTrack.h:516
TTrack * daughter(void) const
Definition: TTrack.h:657
unsigned finder(void) const
sets/returns finder.
Definition: TTrack.h:601
unsigned type(void) const
returns type. Definition is depending on an object type.
Definition: TTrack.h:565
double pt(void) const
returns Pt.
Definition: TTrack.h:528
int approach(TMLink &) const
calculates the closest approach to a wire in real space. Results are stored in TMLink....
Definition: TTrack.cxx:296
double chi2(void) const
returns chi2.
Definition: TTrack.h:495
double charge(void) const
returns charge.
Definition: TTrack.h:504
Index first(Pair i)
Definition: EvtCyclic3.cc:195
#define STEP(pi, pj)
Definition: ranlxd.c:376
int t()
Definition: t.c:1
TCanvas * c1
Definition: tau_mode.c:75
const float pi
Definition: vector3.h:133