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