BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcTrack.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcTrack.cxx,v 1.18 2012/08/13 00:09:19 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author(s):
12// Steve Schaffner
13// Zhang Yao([email protected]) Migrate to BESIII
14//
15//------------------------------------------------------------------------
16#include "MdcTrkRecon/MdcTrack.h"
17#include <math.h>
18#include <stdlib.h>
19#include <assert.h>
20#include "MdcGeom/MdcLayer.h"
21#include "MdcData/MdcHitOnTrack.h"
22#include "MdcGeom/BesAngle.h"
23#include "MdcGeom/Constants.h"
24#include "CLHEP/Alist/AList.h"
25#include "TrkBase/TrkRep.h"
26#include "TrkFitter/TrkHelixRep.h"
27#include "TrkBase/TrkExchangePar.h"
28#include "TrkBase/TrkRecoTrk.h"
29#include "TrkFitter/TrkCircleMaker.h"
30#include "TrkBase/TrkContext.h"
31
32#include "MdcData/MdcRecoHitOnTrack.h"
33#include "BField/BField.h"
34#include "MdcData/MdcHit.h"
35#include "MdcData/MdcHitOnTrack.h"
36#include "MdcRawEvent/MdcDigi.h"
37#include "Identifier/Identifier.h"
38#include "Identifier/MdcID.h"
39//************************************************************************/
41//************************************************************************/
42 _theTrack = aTrack;
43 _firstLayer = _lastLayer = 0;
44 _haveCurled = 0;
45}
46
47//************************************************************************/
48MdcTrack::MdcTrack(int nsupers, const TrkExchangePar& par, double chisq,
49 TrkContext& context, double trackT0) {
50//************************************************************************/
51 TrkCircleMaker maker;
52 _theTrack = maker.makeTrack(par, chisq, context, trackT0);
53 _firstLayer = _lastLayer = 0;
54 _haveCurled = 0;
55}
56
57//************************************************************************/
59//************************************************************************/
60 delete _theTrack;
61}
62//************************************************************************/
63int MdcTrack::projectToR(double radius, BesAngle &phiIntersect, int lCurl)
64 const {
65//************************************************************************/
66 // note that these are currently circle-only routines
67
68 //return -1 if no intersection
69
70 const TrkFit* tkFit = track().fitResult();
71 if (tkFit == 0) return -1;
72 TrkExchangePar par = tkFit->helix(0.0);
73 double d0 = par.d0();
74 double omega = par.omega();
75 double phi0 = par.phi0();
76 double r2d2 = radius * radius - d0 * d0;
77 if (r2d2 < 0) return -1;
78 double rinv = 1./radius;
79 double k2dinv = 1./(1 + omega * d0);
80 if (!lCurl) {
81 double arg = d0 * rinv + 0.5*omega * rinv * r2d2 * k2dinv;
82 if (fabs(arg) > 1.0) return -1;
83 phiIntersect.setRad( phi0 + asin(arg) );
84 }
85 else {
86 double arg = -d0 * rinv - 0.5*omega * rinv * r2d2 * k2dinv;
87 if (fabs(arg) > 1.0) return -1;
88 phiIntersect.setRad( phi0 + Constants::pi + asin(arg) );
89 }
90
91 return 0;
92}
93
94//************************************************************************/
95int MdcTrack::projectToR(double radius, BesAngle &phiIntersect,
96 double &arcLength, int lCurl) const {
97//************************************************************************/
98
99 //return -1 if no intersection
100 // Only valid for projecting track outwards from point of closest approach
101 // Returns arclength from POCA
102
103 const TrkFit* tkFit = track().fitResult();
104 if (tkFit == 0) return -1;
105 TrkExchangePar par = tkFit->helix(0.0);
106 double d0 = par.d0();
107 double omega = par.omega();
108 double phi0 = par.phi0();
109 double r2d2 = radius * radius - d0 * d0;
110 if (r2d2 < 0) return -1;
111 double rinv = 1./radius;
112 double k2dinv = 1./(1 + omega * d0);
113 if (k2dinv < 0.0) return -1;
114 double arg;
115
116 if (!lCurl) {
117 arg = d0 * rinv + 0.5*omega * rinv * r2d2 * k2dinv;
118 if (fabs(arg) > 1.0) return -1;
119 phiIntersect.setRad( phi0 + asin(arg) );
120 }
121 else {
122 arg = -d0 * rinv - 0.5*omega * rinv * r2d2 * k2dinv;
123 if (fabs(arg) > 1.0) return -1;
124 phiIntersect.setRad( phi0 + Constants::pi + asin(arg));
125 }
126
127 arg = 0.5*omega * sqrt(r2d2 * k2dinv);
128 arcLength = 2. * asin(arg) / omega;
129
130 return 0;
131}
132
133//----------------------------------------------------------------
134bool
136//----------------------------------------------------------------
137
138 return (track() == tk.track());
139}
140
141//yzhang for store to TDS
142void
143MdcTrack::storeTrack(int trackId, RecMdcTrackCol* trackList, RecMdcHitCol* hitList,int tkStat){
144 //check the fit succeeded
145 // if (status().failure()) { return; }
146
147 //get the results of the fit to this track
148 const TrkFit* fitresult = track().fitResult();
149 //check the fit worked
150 if (fitresult == 0) return;
151
152 //new a Rec. Track MdcTrack
153 RecMdcTrack* recMdcTrack = new RecMdcTrack();
154 const TrkHitList* aList = track().hits();
155 //some track info
156 const BField& theField = track().bField();
157 double Bz = theField.bFieldZ();
158 //Fit info
159 int hitId = 0;
160 int nHits=0;
161 int nSt=0;
162 //int nAct=0; int nSeg=0;
163 //int maxlay = 0; int minlay = 43; int seg[11];/* 11 slayer */ int segme;
164 //****************************
165 //* active flag open this
166 //****************************
167 //* if (allHit>0){
168 //* nHits = aList->nHit();//add inActive hit also
169 //* }else{
170 //* nHits = fitresult->nMdc();// = nActive()
171 //* }
172 //****************************
173 //for 5.1.0 use all hits
174 nHits = aList->nHit();
175 //****************************
176 // use active only
177 // nHits = fitresult->nMdc();// = nActive()
178 //****************************
179
180 int q = fitresult->charge();
181 double chisq = fitresult->chisq();
182 int nDof = fitresult->nDof();
183 //track parameters at closest approach to beamline
184 double fltLenPoca = 0.0;
185 TrkExchangePar helix = fitresult->helix(fltLenPoca);
186 //std::cout<< __FILE__ << " phi0 " << helix.phi0() << " omega " <<helix.omega()<<std::endl;
187 double phi0 = helix.phi0();
188 double tanDip = helix.tanDip();
189 //double z0 = helix.z0();
190 double d0 = helix.d0();
191 //momenta and position
192 //CLHEP::Hep3Vector mom = fitresult->momentum(fltLenPoca);
193 HepPoint3D poca = fitresult->position(fltLenPoca);
194
195 double helixPar[5];
196 //dro =-d0
197 helixPar[0] = -d0;
198 //phi0 = phi0 - pi/2 [0,2pi)
199 double tphi0 = phi0 - Constants::pi/2.;
200 if (tphi0 < 0. ) tphi0 += Constants::pi * 2.;
201 helixPar[1] = tphi0;
202 //kappa = q/pxy
203 double pxy = fitresult->pt();
204 if (pxy == 0.) helixPar[2] = 9999.;
205 else helixPar[2] = q/fabs(pxy);
206 if(pxy>9999.) helixPar[2] = 0.00001;
207 //dz = z0
208 helixPar[3] = helix.z0();
209 //tanl
210 helixPar[4] = tanDip;
211 //error
212 //V(Y)=S * V(X) * ST , mS = S , mVy = V(Y) , helix.covariance() = V(X)
213 HepSymMatrix mS(helix.params().num_row(),0);
214 mS[0][0]=-1.;//dr0=-d0
215 mS[1][1]=1.;
216 mS[2][2]=-333.567/Bz;//pxy -> cpa
217 mS[3][3]=1.;
218 mS[4][4]=1.;
219 HepSymMatrix mVy = helix.covariance().similarity(mS);
220 double errorMat[15];
221 int k = 0;
222 for (int ie = 0 ; ie < 5 ; ie ++){
223 for (int je = ie ; je < 5 ; je ++) {
224 errorMat[k] = mVy[ie][je];
225 k++;
226 }
227 }
228 double p,px,py,pz;
229 px = pxy * (-sin(helixPar[1]));
230 py = pxy * cos(helixPar[1]);
231 pz = pxy * helixPar[4];
232 p = sqrt(pxy*pxy + pz*pz);
233 //theta, phi
234 double theta = acos(pz/p);
235 double phi = atan2(py,px);
236 recMdcTrack->setTrackId(trackId);
237 recMdcTrack->setHelix(helixPar);
238 recMdcTrack->setCharge(q);
239 recMdcTrack->setPxy(pxy);
240 recMdcTrack->setPx(px);
241 recMdcTrack->setPy(py);
242 recMdcTrack->setPz(pz);
243 recMdcTrack->setP(p);
244 recMdcTrack->setTheta(theta);
245 recMdcTrack->setPhi(phi);
246 recMdcTrack->setPoca(poca);
247 recMdcTrack->setX(poca.x());//poca
248 recMdcTrack->setY(poca.y());
249 recMdcTrack->setZ(poca.z());
250 recMdcTrack->setR(sqrt(poca.x()*poca.x() + poca.y()*poca.y()));
251 HepPoint3D pivot(0.,0.,0.);
252 recMdcTrack->setPivot(pivot);
253 recMdcTrack->setVX0(0.);//pivot
254 recMdcTrack->setVY0(0.);
255 recMdcTrack->setVZ0(0.);
256 recMdcTrack->setError(errorMat);
257 recMdcTrack->setError(mVy);
258 recMdcTrack->setChi2(chisq);
259 recMdcTrack->setNdof(nDof);
260 recMdcTrack->setStat(tkStat);
261 recMdcTrack->setNhits(nHits);
262 //-----------hit list-------------
263 HitRefVec hitRefVec;
264 vector<int> vecHits;
265 //for fiterm
266 int maxLayerId = -1;
267 int minLayerId = 43;
268 double fiTerm = 999.;
269 const MdcRecoHitOnTrack* fiTermHot = NULL;
270 TrkHitList::hot_iterator hot = aList->begin();
271 for (;hot!=aList->end();hot++){
272 const MdcRecoHitOnTrack* recoHot;
273 recoHot = dynamic_cast<const MdcRecoHitOnTrack*> (&(*hot));
274 //if (!recoHot->mdcHit()) return;
275 RecMdcHit* recMdcHit = new RecMdcHit;
276 //id
277 recMdcHit->setId(hitId);
278 //---------BESIII----------
279 //phiWire - phiHit <0 flagLR=0 left driftleft<0 ;
280 //phiWire - phiHit >0 flagLR=1 right driftright>0;
281 //flag = 2 ambig;
282 //-----Babar wireAmbig----
283 //-1 -> right, 0 -> don't know, +1 -> left
284 //+1 phiWire-phiHit<0 Left,
285 //-1 phiWire-phiHit>0 Right,
286 //0 don't know
287 //ambig() w.r.t track direction
288 //wireAmbig() w.r.t. wire location
289 double hotWireAmbig = recoHot->wireAmbig();
290 double driftDist = fabs(recoHot->drift());
291 double sigma = recoHot->hitRms();
292 double doca = fabs(recoHot->dcaToWire());
293 int flagLR=2;
294 if ( hotWireAmbig == 1){
295 flagLR = 0; //left driftDist <0
296 doca *= -1.;//2012-07-19
297 }else if( hotWireAmbig == -1){
298 flagLR = 1; //right driftDist >0
299 }else if( hotWireAmbig == 0){
300 flagLR = 2; //don't know
301 }
302 recMdcHit->setFlagLR(flagLR);
303 recMdcHit->setDriftDistLeft((-1)*driftDist);
304 recMdcHit->setErrDriftDistLeft(sigma);
305 recMdcHit->setDriftDistRight(driftDist);
306 recMdcHit->setErrDriftDistRight(sigma);
307 //Mdc Id
308 Identifier mdcId = recoHot->mdcHit()->digi()->identify();
309 recMdcHit->setMdcId(mdcId);
310 //corrected ADC
311
312 //contribution to chisquare
313 //fill chisq
314 double res=999.,rese=999.;
315 if (recoHot->resid(res,rese,false)){
316 }else{}
317 double deltaChi=0;
318 recoHot->getFitStuff(deltaChi);//yzhang open 2010-09-20
319 recMdcHit->setChisqAdd( deltaChi * deltaChi );
320 //set tracks containing this hit
321 recMdcHit->setTrkId(trackId);
322 //doca
323 recMdcHit->setDoca(doca);//doca sign left<0
324 //entrance angle
325
326 recMdcHit->setEntra(recoHot->entranceAngle());
327 //z of hit
328 HepPoint3D pos; Hep3Vector dir;
329 double fltLen = recoHot->fltLen();
330 recMdcHit->setFltLen(fltLen);
331 recoHot->getParentRep()->traj().getInfo(fltLen,pos,dir);
332 recMdcHit->setZhit(pos.z());
333 double tof = recoHot->getParentRep()->arrivalTime(fltLen);
334 recMdcHit->setTdc(recoHot->mdcHit()->tdcIndex());
335 recMdcHit->setAdc(recoHot->mdcHit()->adcIndex());
336 //drift time
337 recMdcHit->setDriftT(recoHot->mdcHit()->driftTime(tof,pos.z()));
338 //for fiterm
339 int layerId = recoHot->mdcHit()->layernumber();
340 int wireId = recoHot->mdcHit()->wirenumber();
341 //std::cout<<" MdcTrack::store() ("<<layerId<<","<<wireId<<") fltLen "<<fltLen<<" wireAmbig "<<hotWireAmbig<<" y "<<pos.y()<<std::endl;
342 //<<recoHot->entranceAngle()<<std::endl;
343 if (layerId >= maxLayerId){
344 maxLayerId = layerId;
345 fiTermHot = recoHot;
346 }
347 if (layerId < minLayerId){
348 minLayerId = layerId;
349 }
350 // status flag
351 if (recoHot->isActive()) {
352 recMdcHit->setStat(1);
353 }else{
354 recMdcHit->setStat(0);
355 }
356 // for 5.1.0 use all hits
357 if (recoHot->layer()->view()) {
358 ++nSt;
359 }
360 hitList->push_back(recMdcHit);
361 SmartRef<RecMdcHit> refHit(recMdcHit);
362 hitRefVec.push_back(refHit);
363 vecHits.push_back(mdcId.get_value());
364 ++hitId;
365 }
366 //fi terminal angle
367 if (fiTermHot!=NULL){
368 fiTerm=(1./sqrt(1.+tanDip*tanDip))*fiTermHot->fltLen()*helix.omega();
369 }
370 recMdcTrack->setFiTerm(fiTerm);
371 // number of stereo hits contained
372 recMdcTrack->setNster(nSt);
373 recMdcTrack->setFirstLayer(maxLayerId);
374 recMdcTrack->setLastLayer(minLayerId);
375 recMdcTrack->setVecHits(hitRefVec);
376 trackList->push_back(recMdcTrack);
377}//end of storeTrack
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
****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
void setError(double err[15])
void setHelix(double helix[5])
Definition: DstMdcTrack.cxx:98
void setPoca(double poca[3])
int wireAmbig() const
double dcaToWire() const
double entranceAngle() const
const MdcLayer * layer() const
const MdcDigi * digi() const
double driftTime(double tof, double z) const
Definition: MdcHit.cxx:142
const MdcHit * mdcHit() const
int projectToR(double radius, BesAngle &phiIntersect, int lCurl=0) const
Definition: MdcTrack.cxx:63
bool operator==(const MdcTrack &tk) const
Definition: MdcTrack.cxx:135
~MdcTrack()
Definition: MdcTrack.cxx:58
void storeTrack(int trackId, RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat)
Definition: MdcTrack.cxx:143
MdcTrack(TrkRecoTrk *aTrack)
Definition: MdcTrack.cxx:40
virtual Identifier identify() const
Definition: RawData.cxx:15
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual double pt(double fltL=0.) const =0
virtual double chisq() const =0
virtual int charge() const =0
virtual int nDof() const =0
virtual const TrkDifTraj & traj() const =0
virtual HepPoint3D position(double fltL) const =0
virtual TrkExchangePar helix(double fltL) const =0
double resid(bool exclude=false) const
TrkErrCode getFitStuff(HepVector &derivs, double &deltaChi) const
const TrkFit * fitResult() const
Definition: TrkRecoTrk.cxx:387
virtual double arrivalTime(double fltL) const
Definition: TrkRep.cxx:192
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const