CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
Hough3D.cxx
Go to the documentation of this file.
1#include "MdcHoughFinder/Hough3D.h"
2#include "CgemData/CgemHitOnTrack.h"
4vector<MdcHit*> vec_for_clean;
5vector<TrkRecoTrk*> vectrk_for_clean;
11//double Hough3D::m_dropTrkDrCut=1;
12//double Hough3D::m_dropTrkDzCut=10;
13double Hough3D::m_dropTrkDrCut=1; //no limit of dr dz
16double Hough3D::m_dropTrkChi2Cut=99999;
18//int m_cgemfit = 1;
19
21 //_m_gm = MdcDetector::instance(0);
22}
24 _circleR=other._circleR;
25 _circleX=other._circleX;
26 _circleY=other._circleY;
27 _charge=other._charge;
28 _d0=other._d0;
29 _phi0=other._phi0;
30 _omega=other._omega;
31 _tanl=other._tanl;
32 _z0=other._z0;
33
34 _pt=other._pt;
35 _pz=other._pz;
36 _p=other._p;
37 _nfit=other._nfit;
38 _bunchT0=other._bunchT0;
39 _chi2_aver=other._chi2_aver;
40 _m_gm = other._m_gm;
41 _recHitVec=other._recHitVec;
42 vec_mdcHit=other.vec_mdcHit;
43}
44
45Hough3D::Hough3D(const Hough2D& hough2D,recHitCol hitCol, double bunchtime,double tanl,double z0):_tanl(tanl),_z0(z0){
46 //_m_gm = MdcDetector::instance(0);
47 _circleR=hough2D.getCirR();
48 _circleX=hough2D.getCirX();
49 _circleY=hough2D.getCirY();
50 _d0 = hough2D.getD0();
51 _phi0 = hough2D.getPhi0();
52 _omega= hough2D.getOmega();
53 _charge=hough2D.getCharge();
54 _bunchT0=bunchtime;
55 _recHitVec=hitCol;
56 _pt = 0;
57 _p = 0;
58 _pz = 0;
59 _nfit=0;
60 newTrack=NULL;
61}
62Hough3D::Hough3D(const Hough2D& hough2D,recHitCol hitCol, double bunchtime,double tanl,double z0,const vector<MdcHit*>* mdchit):_tanl(tanl),_z0(z0),vec_mdcHit(mdchit){
63 //_m_gm = MdcDetector::instance(0);
64 _circleR=hough2D.getCirR();
65 _circleX=hough2D.getCirX();
66 _circleY=hough2D.getCirY();
67 _d0 = hough2D.getD0();
68 _phi0 = hough2D.getPhi0();
69 _omega= hough2D.getOmega();
70 _charge=hough2D.getCharge();
71 _bunchT0=bunchtime;
72 _recHitVec=hitCol;
73 _pt = 0;
74 _p = 0;
75 _pz = 0;
76 _nfit=0;
77 newTrack=NULL;
78}
79
81 if(_charge==-1){
82// cout<<" charge -1 "<<endl;
83// _d0=-_d0;
84// _omega=-1.*fabs(_omega);
85 }
86 if(_charge==1){
87// cout<<" charge +1 "<<endl;
88// _d0=_d0;
89// _omega=1.*fabs(_omega);
90 //_phi0=_phi0-M_PI;
91 }
92
93 //outerHit(); // delete 4 hit in a wire for kalman
94
95 TrkExchangePar tt(_d0,_phi0,_omega,_z0,_tanl);
96 //if (m_debug>0) cout<<"q d0 phi0 omega: "<<_charge<<" "<<_d0<<" "<<_phi0<<" "<<_omega<<" "<<_tanl<<" "<<_z0<<endl;
97 double dr = -_d0;
98 double phi0 = _phi0-M_PI/2;
99 double kappa = _omega*333.567;
100 double dz = _z0;
101 double tanl = _tanl;
102 while(phi0>2*M_PI)phi0-=2*M_PI;
103 while(phi0<0)phi0+=2*M_PI;
104 if (m_debug>0)cout<<"rec:"<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl;
105 //cout<<"rec barbar:"<<setw(12)<<_d0<<" "<<setw(12)<<_phi0<<" "<<setw(12)<<_omega<<" "<<setw(12)<<_z0<<" "<<setw(12)<<_tanl<<endl;
106 //cout<<"rec besIII:"<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl;
107 TrkHelixMaker helixfactory;
108 float chisum =0.;
109 newTrack = helixfactory.makeTrack(tt, chisum, *_context, _bunchT0);
110 //vectrk_for_clean.push_back(newTrack);
111 bool permitFlips = true;
112 bool lPickHits = true;
113 helixfactory.setFlipAndDrop(*newTrack, permitFlips, lPickHits);
114 TrkHitList* trkHitList = newTrack->hits();
115 int digiId=0;
116 std::vector<HoughRecHit>::iterator iter = _recHitVec.begin();
117 for (;iter != _recHitVec.end(); iter++, digiId++) {
118//cout<<__FILE__<<" layer: "<<iter->getLayerId()<<" wire: "<<iter->getWireId()<<" flag:"<<iter->getflag()<<endl;
119 if( (*iter).getflag()!=0 ) continue;
120 //if( (*iter)->calDriftDist(_bunchT0,0)>0.8) continue;
121 //if( (*iter)->driftTime(_bunchT0,0)>800) continue;
122 //cout<<"rechit dist time "<<(*iter).calDriftDist(_bunchT0,0)<<" "<<(*iter).driftTime(_bunchT0,0)<<endl;
123 if((*iter).getDetectorType()==MDC) {
124 const MdcDigi* aDigi = (*iter).digi();
125 MdcHit* hit;
126 // compare
127 vector<MdcHit*>::const_iterator iter_digi = (*vec_mdcHit).begin();
128 for (;iter_digi != (*vec_mdcHit).end(); iter_digi++) {
129 if( (*iter_digi)->digi() == (*iter).digi() ) {
130 hit = (*iter_digi);
131 }
132 }
133 Identifier id = aDigi->identify();
134 int layer = MdcID::layer(id);
135 int wire = MdcID::wire(id);
136 if(m_debug>0)cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
137//cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
139 hit->setCountPropTime(true);
140 // new fltLen and ambig
141 int newAmbig = 0;
142 // calc. position of this point
143 MdcRecoHitOnTrack temp( *hit, newAmbig, _bunchT0*1.e9);//m_bunchT0 nano second here
144 MdcHitOnTrack* newhot = &temp;
145 double flight;
146 double z_flight;
147 //if( layer<8 ) flight = sqrt( ((*iter).getsPos())*((*iter).getsPos())+((*iter).getzPos())*((*iter).getzPos())) ;
148 // if( layer<8 ) flight =(*iter).getsPos();
149 flight = (*iter).getRet().second;
150 double distoTrack= (*iter).getDisToTrack();
151 // if( layer<8 ) newhot->setFltLen( (*iter).getsPos()); //caculate by mc
152 // else newhot->setFltLen( (*iter).getRet().second); //caculate by mc
153 newhot->setFltLen( flight );
154 // if(layer==18) continue;
155
156 int use_in3d=1;
157 // if(hit->driftDist(_bunchT0,0)>1.0) use_in3d=0;
158 if(hit->driftTime(_bunchT0,0)>1000) use_in3d=0;
159 //if(m_debug>0) cout<<"flt : "<<(*iter).getsPos()<<endl;
160 //if(m_debug>0) cout<<"flt : "<<flight<<endl;
161 //if(m_debug>0) std::cout<<" ("<<layer<<","<<wire<<",rt "<<hit->rawTime()<<",dt "<<hit->driftTime(_bunchT0,0)<<") T0 " << _mdcCalibFunSvc->getT0(layer,wire) <<" timewalk "<< _mdcCalibFunSvc->getTimeWalk(layer, aDigi->getChargeChannel())<< "dist: "<<hit->driftDist(_bunchT0,0)<<" disToTrk "<< distoTrack<<" use?: "<<use_in3d<<endl;
162 // if(hit->driftTime(_bunchT0,0)>800) continue;
163 if(use_in3d==0) continue;
164 trkHitList->appendHot(newhot);
165 }else if( (*iter).getDetectorType()==CGEM && (*iter).getCluster()->getflag()==2){
166 if(m_debug>0) std::cout<<__FILE__<<" "<<__LINE__<<" add CGEM hit to fit "<<std::endl;
167 CgemHitOnTrack* newhot = new CgemHitOnTrack(*((*iter).getCluster()),_bunchT0*1.e9);
170 trkHitList->appendHot(newhot);
171 //if(m_cgemfit==1 || m_cgemfit==3)trkHitList->appendHot(newhot);
172 }
173 }
174 if( m_debug>0) newTrack->printAll(std::cout);
175 /*
176 TrkHitList* hitList = newTrack->hits();
177 for (TrkHitList::hot_iterator ihit(hitList->begin()); ihit != hitList->end(); ++ihit){
178 if(typeid(*ihit)==typeid(CgemHitOnTrack))continue;
179 int nUsed = ihit->hit()->nUsedHits();
180 std::cout<<"nUsed="<<nUsed<<":"<<endl;
181 //ihit->hit()->printAll(std::cout);
182 ihit->printAll(std::cout);
183 std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator> q = ihit->hit()->getUsedHits();
184 for (TrkFundHit::hot_iterator i = q.first; i != q.second; ++i) {
185 TrkRecoTrk * recoTrk=i->parentTrack();
186 int id = recoTrk->id();
187 cout<<"trkid:"<<id<<endl;
188 }
189 cout<<endl;
190 }
191 */
192 TrkHitList* qhits = newTrack->hits();
193 TrkErrCode err=qhits->fit();
194 const TrkFit* newFit = newTrack->fitResult();
195 int nActiveHit = newTrack->hots()->nActive();
196 //cout<<err<<endl;
197 //if(newFit) cout <<" nAct "<<newFit->nActive()<<" "<<nActiveHit<<endl;
198 int fit_stat=false;
199 double chi2=-999.;
200 if (!newFit || (newFit->nActive()<5)||err.failure()!=0){
201 //if (!newFit )
202 if(m_debug>0){
203 cout << " global 3d fit failed ";
204 if(newFit) cout <<" nAct "<<newFit->nActive()<<endl;
205 cout<<"ERR1 failure ="<<err.failure()<<endl;
206 fit_stat=0;
207 }
208 }else{
209 TrkExchangePar par = newFit->helix(0.);
210 if( abs( 1/(par.omega()) )>0.03) {
211 fit_stat = 1;
212 chi2=newFit->chisq();
213 }
214 else {
215 fit_stat = 0;
216 chi2=-999;
217 }
218
219 bool badQuality = false;
220 if(fabs(chi2)>m_qualityFactor*m_dropTrkChi2Cut ){
221 if(m_debug>0){
222 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by chi2 "<<chi2<<" > "<<m_qualityFactor<<" * "<<m_dropTrkChi2Cut <<std::endl;
223 }
224 badQuality=1;
225 }
226 if( fabs(par.d0())>m_qualityFactor*m_dropTrkDrCut) {
227 if(m_debug>0){
228 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by d0 "<<par.d0()<<" > "<<m_qualityFactor<<" * "<<m_dropTrkDrCut <<std::endl;
229 }
230 badQuality=1;
231 }
232 if( fabs(par.z0())>m_qualityFactor*m_dropTrkDzCut) {
233 if(m_debug>0){
234 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by z0 "<<par.z0()<<" > "<<m_qualityFactor<<" * "<<m_dropTrkDzCut <<std::endl;
235 }
236 badQuality=1;
237 }
238 if( (fabs(chi2)/qhits->nHit()) > m_qualityFactor*m_dropTrkChi2NdfCut) {
239 if(m_debug>0){
240 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by chi2/ndf"<<(fabs(chi2)/qhits->nHit()) <<" > "<<m_qualityFactor<<" * "<<m_dropTrkChi2NdfCut<<std::endl;
241 }
242 badQuality=1;
243 }
244 if( nActiveHit <= m_dropTrkNhitCut) {
245 if(m_debug>0){
246 std::cout<<__FILE__<<" "<<__LINE__<<" drop track by nhit"<<nActiveHit <<" <= "<<m_dropTrkNhitCut<<std::endl;
247 }
248 badQuality=1;
249 }
250 //badQuality = false; //not delete track in this stage
251 if( badQuality) fit_stat=0;
252 }
253 if( fit_stat!=1 ){
254 delete newTrack;
255 //vectrk_for_clean.pop_back();
256 }
257 if( fit_stat==1 ){
258 if(m_debug>0){
259 cout << " global 3d fit success"<<endl;
260 cout<<__FILE__<<__LINE__<<"AFTER fit 3d "<<endl;
261 newTrack->print(std::cout);
262 }
263 TrkExchangePar par = newFit->helix(0.);
264 _d0=par.d0();
265 _phi0=par.phi0();
266 _omega=par.omega();
267 _tanl=par.tanDip();
268 _z0=par.z0();
269
270 double dr = -par.d0();
271 double phi0 = par.phi0()-M_PI/2;
272 if(phi0<0)phi0+=2*M_PI;
273 double kappa = par.omega()*333.567;
274 double dz=par.z0();
275 double tanl=par.tanDip();
276 if(m_debug>0)cout<<"Fit:"<<setw(12)<<dr<<" "<<setw(12)<<phi0<<" "<<setw(12)<<kappa<<" "<<setw(12)<<dz<<" "<<setw(12)<<tanl<<endl<<endl;
277 _circleR=_charge/par.omega();
278 _circleX= sin(par.phi0()) *(par.d0()+1/par.omega()) * -1.; //z axis verse,x_babar = -x_belle
279 _circleY= -1.*cos(par.phi0()) *(par.d0()+1/par.omega()) * -1;//???
280 double pxy=fabs(_circleR/333.567);
281 double pz=pxy*par.tanDip();
282 double pxyz=_charge*sqrt(pxy*pxy+pz*pz);
283 _pt=pxy;
284 _pz=pz;
285 _p=pxyz;
286 if(m_debug>0){
287 cout<<" circle after globle 3d: "<<"("<<_circleX<<","<<_circleY<<","<<_circleR<<")"<<endl;
288 cout<<"pt_rec: "<<_pt<<endl;
289 cout<<"pz_rec: "<<_pz<<endl;
290 cout<<"p_rec: "<<_p<<endl;
291 }
292
293 int nfit3d=0;
294 if(m_debug>0) cout<<" hot list:"<<endl;
295 TrkHotList::hot_iterator hotIter= qhits->hotList().begin();
296 int lay=((MdcHit*)(hotIter->hit()))->layernumber();
297 int wir=((MdcHit*)(hotIter->hit()))->wirenumber();
298 while (hotIter!=qhits->hotList().end()) {
299 if( typeid(*hotIter)==typeid(MdcRecoHitOnTrack) || typeid(*hotIter)==typeid(MdcHitOnTrack)){
300 if(m_debug>0){
301 cout <<"(" <<((MdcHit*)(hotIter->hit()))->layernumber()
302 <<","<<((MdcHit*)(hotIter->hit()))->wirenumber()
303 <<":"<<hotIter->isActive()<<") ";
304 }
305 }else if(typeid(*hotIter)==typeid(CgemHitOnTrack)){
306 if(m_debug>0){
307 const CgemHitOnTrack* recoHot = dynamic_cast<const CgemHitOnTrack*> (&(*hotIter));
308 const RecCgemCluster* recCgemCluster = recoHot->baseHit();
309 cout<<"(" <<recCgemCluster->getlayerid()
310 <<","<<recCgemCluster->getsheetid()
311 <<":"<<hotIter->isActive()<<") ";
312 //<<"clusterID:"<<recCgemCluster->getclusterid()
313 //<<" flag:"<<recCgemCluster->getflag()<<endl;
314 //hotIter++;
315 //continue;
316 }
317 }
318 // cout << "nuse "<<hotIter->hit()->nUsedHits()<<endl;
319 if (hotIter->isActive()==1) nfit3d++;
320 hotIter++;
321 }
322 _nfit=nfit3d;
323 }
324 _chi2_aver=chi2/_nfit;
325 // for(int i=0;i<t_hitCol.size();i++){
326 // delete t_hitCol[i];
327 // }
328 if(m_debug>0) cout<<" in 3D fit number of Active hits : "<<_nfit<<endl;
329 return fit_stat;
330}
331
333 cout<<" print hough3d "<<endl;
334 cout<<"par: "<<_d0<<" "<<_phi0<<" "<<_omega<<" "<<_tanl<<" "<<_z0<<endl;
335}
336
337bool less_layer_3D(const int& a,const int& b){
338 return a < b;
339}
340
342 for(int ihit=0;ihit<_recHitVec.size();ihit++){
343 if( _recHitVec[ihit].calDriftDist(_bunchT0,0)>0.8 || _recHitVec[ihit].driftTime(_bunchT0,0)>800 ) _recHitVec[ihit].setflag(-5); //flag -5 time or drift
344 }
345
346 vector<int> vec_layer_num[43];
347 for(int ilay=0;ilay<43;ilay++){
348 for(int ihit=0;ihit<_recHitVec.size();ihit++){
349 if( _recHitVec[ihit].getLayerId()==ilay && _recHitVec[ihit].getflag()==0 ) {
350 vec_layer_num[ilay].push_back( _recHitVec[ihit].getWireId() );
351 }
352 }
353 std::sort( vec_layer_num[ilay].begin(),vec_layer_num[ilay].end(),less_layer_3D);
354 if( vec_layer_num[ilay].size() < 4 ) continue;
355 for(int j=0;j<vec_layer_num[ilay].size();j++) {
356 // if( (vec_layer_num[ilay][j]+1 == vec_layer_num[ilay][j+1]) && (vec_layer_num[ilay][j+1]+1 == vec_layer_num[ilay][j+2]) && (vec_layer_num[ilay][j+2]+1 == vec_layer_num[ilay][j+3]) ) {
357 for(int jhit=0;jhit<_recHitVec.size();jhit++) {
358 if( (ilay==_recHitVec[jhit].getLayerId()) && (vec_layer_num[ilay][j]==_recHitVec[jhit].getWireId() ) ) {_recHitVec[jhit].setflag(-1);}
359 }
360 //}
361 }
362 }
363}
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
vector< TrkRecoTrk * > vectrk_for_clean
Definition: Hough3D.cxx:5
vector< MdcHit * > vec_for_clean
Definition: Hough3D.cxx:4
bool less_layer_3D(const int &a, const int &b)
Definition: Hough3D.cxx:337
double sin(const BesAngle a)
double cos(const BesAngle a)
#define M_PI
Definition: TConstant.h:4
void print()
Definition: Hough3D.cxx:332
int fit()
Definition: Hough3D.cxx:80
void outerHit()
Definition: Hough3D.cxx:341
Hough3D()
Definition: Hough3D.cxx:20
static const CgemCalibFunSvc * _cgemCalibFunSvc
void setCalibSvc(const MdcCalibFunSvc *calibSvc)
Definition: MdcHit.cxx:136
double driftTime(double tof, double z) const
Definition: MdcHit.cxx:142
void setCountPropTime(const bool count)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
virtual Identifier identify() const
Definition: RawData.cxx:15
virtual double chisq() const =0
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
TrkFundHit::hot_iterator begin() const
TrkErrCode fit()
Definition: TrkHitList.cxx:59
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
Definition: TrkHitList.cxx:91
const TrkHotList & hotList() const
Definition: TrkHitList.cxx:51
virtual int nActive(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual void print(std::ostream &) const
const TrkFit * fitResult() const
Definition: TrkRecoTrk.cxx:387
virtual void printAll(std::ostream &) const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const