CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
HoughHit.cxx
Go to the documentation of this file.
2#include "Identifier/MdcID.h"
4#include "MdcGeom/Constants.h"
5#include "TrkBase/TrkPoca.h"
6#include "TrkBase/HelixTraj.h"
9
10#include <iomanip>
11#include <string>
12
13using namespace std;
14
15MdcGeomSvc* HoughHit::m_mdcGeomSvc = NULL;
16MdcCalibFunSvc* HoughHit::m_mdcCalibFunSvc = NULL;
17CgemGeomSvc* HoughHit::m_cgemGeomSvc = NULL;
18CgemCalibFunSvc* HoughHit::m_cgemCalibFunSvc = NULL;
19const MdcDetector* HoughHit::m_mdcDetector = NULL;
21 //m_det=Global::m_gm;
22 m_cgemCluster=NULL;
23 m_mdcDigi=NULL;
24 m_cgemMcHit=NULL;
25 m_mdcMcHit=NULL;
26 //m_hitMap = NULL;
27}
28
29HoughHit::HoughHit(const MdcDigi* mdcDigi, double bunchTime, int hitID)
30{
31 m_hitID = hitID;
32 m_hitType = MDCHIT;
33 m_cgemCluster = NULL;
34 m_mdcDigi = mdcDigi;
35 m_cgemMcHit=NULL;
36 m_mdcMcHit=NULL;
37 m_layer = MdcID::layer(mdcDigi->identify());
38 m_wire = MdcID::wire(mdcDigi->identify());
39 m_flag = flag();
40 m_use = 0;
41 m_bunchTime = bunchTime;
42 m_rawTime = RawDataUtil::MdcTime(mdcDigi->getTimeChannel());
43 m_depositEnergy = mdcDigi->getChargeChannel();
44 const MdcGeoWire* wire = m_mdcGeomSvc->Wire(m_layer,m_wire);
45 m_hitPosition = (wire->Forward() + wire->Backward())/10/2;
46 m_westPoint = wire->Forward();
47 m_eastPoint = wire->Backward();
48 m_driftDist = driftDistance();
49 m_residual = 9999;
50 //m_hitMap = NULL;
51 //m_sLeft = 0;
52 //m_zLeft = 0;
53 //m_sRight = 0;
54 //m_zRight = 0;
55 m_trkID.clear();
56 m_sz.clear();
57 m_pairHit = NULL;
58 m_halfCircle = 0;
59 m_position.clear();
60 m_mdcHit = NULL;
61 //MdcHit mdcHit = *(new MdcHit(m_mdcDigi,m_mdcDetector));
62 //mdcHit.setCalibSvc(m_mdcCalibFunSvc);
63 //mdcHit.setCountPropTime(true);
64}
65
66HoughHit::HoughHit(const RecCgemCluster* cgemCluster, double bunchTime, int hitID)
67{
68 m_hitID = hitID;
69 m_hitType = CGEMHIT;
70 m_cgemCluster = cgemCluster;
71 m_mdcDigi=NULL;
72 m_cgemMcHit=NULL;
73 m_mdcMcHit=NULL;
74 m_layer = cgemCluster->getlayerid();
75 m_wire = cgemCluster->getsheetid();
76 //m_wire = cgemCluster->getclusterid();
77 //m_wire = -1;
78 m_flag = cgemCluster->getflag();
79 m_use = 0;
80 m_bunchTime = bunchTime;
81 m_rawTime = 0; //FIXME
82 m_depositEnergy = cgemCluster->getenergydeposit(); //FIXME
83 m_hitPosition.setX((m_cgemGeomSvc->getCgemLayer(m_layer)->getMiddleROfGapD()/10.)*cos(cgemCluster->getrecphi()));
84 m_hitPosition.setY((m_cgemGeomSvc->getCgemLayer(m_layer)->getMiddleROfGapD()/10.)*sin(cgemCluster->getrecphi()));
85 m_hitPosition.setZ(cgemCluster->getRecZ()/10.);
86 m_westPoint = HepPoint3D(0,0,0);
87 m_eastPoint = HepPoint3D(0,0,0);
88 m_driftDist = 0;
89 m_residual = 9999;
90 //m_hitMap = NULL;
91 //m_sLeft = 0;
92 //m_zLeft = 0;
93 //m_sRight = 0;
94 //m_zRight = 0;
95 m_trkID.clear();
96 m_sz.clear();
97 m_pairHit = NULL;
98 m_halfCircle = 0;
99 m_position.clear();
100 m_mdcHit = NULL;
101}
102
103HoughHit::HoughHit(const MdcMcHit* mdcMcHit, double bunchTime, int hitID)
104{
105 m_hitID = hitID;
106 m_hitType = MDCMCHIT;
107 m_cgemCluster = NULL;
108 m_mdcDigi = NULL;
109 m_cgemMcHit = NULL;
110 m_mdcMcHit = mdcMcHit;
111 m_layer = MdcID::layer(mdcMcHit->identify());
112 m_wire = MdcID::wire(mdcMcHit->identify());
113 m_flag = flag();
114 m_use = mdcMcHit->getPositionFlag();
115 m_bunchTime = bunchTime;
116 m_rawTime = 0;
117 m_depositEnergy = mdcMcHit->getDepositEnergy();
118 m_hitPosition.setX(mdcMcHit->getPositionX()/10.);
119 m_hitPosition.setY(mdcMcHit->getPositionY()/10.);
120 m_hitPosition.setZ(mdcMcHit->getPositionZ()/10.);
121 m_westPoint = HepPoint3D(0,0,0);
122 m_eastPoint = HepPoint3D(0,0,0);
123 m_driftDist = mdcMcHit->getDriftDistance()/10.;
124 m_residual = 9999;
125 //m_hitMap = NULL;
126 //m_sLeft = 0;
127 //m_zLeft = 0;
128 //m_sRight = 0;
129 //m_zRight = 0;
130 m_trkID.push_back(mdcMcHit->getTrackIndex());
131 //cout<<m_layer<<" "<<mdcMcHit->getTrackIndex()<<endl;
132 m_sz.clear();
133 m_pairHit = NULL;
134 m_halfCircle = 0;
135 m_position.clear();
136 m_mdcHit = NULL;
137}
138
139HoughHit::HoughHit(const CgemMcHit* cgemMcHit, double bunchTime, int hitID)
140{
141 m_hitID = hitID;
142 m_hitType = CGEMMCHIT;
143 m_cgemCluster = NULL;
144 m_mdcDigi = NULL;
145 m_cgemMcHit = cgemMcHit;
146 m_mdcMcHit = NULL;
147 m_layer = cgemMcHit->GetLayerID();
148 //m_wire = cgemMcHit->GetParentID();
149 //m_flag = cgemMcHit->GetPDGCode();
150 m_wire = -1;
151 m_flag = 2;
152 m_use = 0;
153 m_bunchTime = bunchTime;
154 m_rawTime = 0;
155 m_depositEnergy = 0;
156 m_hitPosition.setX((cgemMcHit->GetPositionXOfPrePoint()+cgemMcHit->GetPositionXOfPostPoint())/2/10.);
157 m_hitPosition.setY((cgemMcHit->GetPositionYOfPrePoint()+cgemMcHit->GetPositionYOfPostPoint())/2/10.);
158 m_hitPosition.setZ((cgemMcHit->GetPositionZOfPrePoint()+cgemMcHit->GetPositionZOfPostPoint())/2/10.);
159 m_westPoint = HepPoint3D(0,0,0);
160 m_eastPoint = HepPoint3D(0,0,0);
161 m_driftDist = 0;
162 m_residual = 9999;
163 //m_hitMap = NULL;
164 //m_sLeft = 0;
165 //m_zLeft = 0;
166 //m_sRight = 0;
167 //m_zRight = 0;
168 m_trkID.push_back(cgemMcHit->GetTrackID());
169 //cout<<m_layer<<" "<<cgemMcHit->GetTrackID()<<endl;
170 m_sz.clear();
171 m_pairHit = NULL;
172 m_halfCircle = 0;
173 m_position.clear();
174 m_mdcHit = NULL;
175}
176
178 m_hitID(other.m_hitID),
179 m_hitType(other.m_hitType),
180 m_cgemCluster(other.m_cgemCluster),
181 m_mdcDigi(other.m_mdcDigi),
182 m_cgemMcHit(other.m_cgemMcHit),
183 m_mdcMcHit(other.m_mdcMcHit),
184 m_layer(other.m_layer),
185 m_wire(other.m_wire),
186 m_flag(other.m_flag),
187 m_use(other.m_use),
188 m_bunchTime(other.m_bunchTime),
189 m_rawTime(other.m_rawTime),
190 m_depositEnergy(other.m_depositEnergy),
191 m_hitPosition(other.m_hitPosition),
192 m_westPoint(other.m_westPoint),
193 m_eastPoint(other.m_eastPoint),
194 m_driftDist(other.m_driftDist),
195 m_residual(other.m_residual),
196 //m_hitMap(other.m_hitMap),
197 //m_sLeft(other.m_sLeft),
198 //m_zLeft(other.m_zLeft),
199 //m_sRight(other.m_sRight),
200 //m_zRight(other.m_zRight),
201 m_trkID(other.m_trkID),
202 m_sz(other.m_sz),
203 m_pairHit(other.m_pairHit),
204 m_halfCircle(other.m_halfCircle),
205 m_position(other.m_position),
206 m_mdcHit(other.m_mdcHit)
207{}
208
210{
211 m_hitID = other.m_hitID;
212 m_hitType = other.m_hitType;
213 m_cgemCluster = other.m_cgemCluster;
214 m_mdcDigi = other.m_mdcDigi;
215 m_cgemMcHit = other.m_cgemMcHit;
216 m_mdcMcHit = other.m_mdcMcHit;
217 m_layer = other.m_layer;
218 m_wire = other.m_wire;
219 m_flag = other.m_flag;
220 m_use = other.m_use;
221 m_bunchTime = other.m_bunchTime;
222 m_rawTime = other.m_rawTime;
223 m_depositEnergy = other.m_depositEnergy;
224 m_hitPosition = other.m_hitPosition;
225 m_westPoint = other.m_westPoint;
226 m_eastPoint = other.m_eastPoint;
227 m_driftDist = other.m_driftDist;
228 m_residual = other.m_residual;
229 //m_hitMap = other.m_hitMap;
230 //m_sLeft = other.m_sLeft;
231 //m_zLeft = other.m_zLeft;
232 //m_sRight = other.m_sRight;
233 //m_zRight = other.m_zRight;
234 m_trkID = other.m_trkID;
235 m_sz = other.m_sz;
236 m_pairHit = other.m_pairHit;
237 m_halfCircle = other.m_halfCircle;
238 m_position = other.m_position;
239 m_mdcHit =other.m_mdcHit;
240}
241
242/*
243void HoughHit::buildMap(int x_bin, double x_min, double x_max, int y_bin, double y_min, double y_max, int nPoint, int charge)
244{
245 if(m_hitMap!=NULL)delete m_hitMap;
246 stringstream ssname;
247 ssname<<"id"<<m_hitID<<",layer"<<m_layer<<",wire(sheet)"<<m_wire;
248 string sname = ssname.str();
249 const char * name = sname.c_str();
250 m_hitMap = new TH2D(name,name, x_bin, x_min, x_max, y_bin, y_min, y_max);
251 int N = x_bin*nPoint;
252 double delta_alpha = (x_max - x_min )/N;
253 double alpha = x_min-delta_alpha/2;
254 double u = 2*m_hitPosition.x()/(m_hitPosition.x()*m_hitPosition.x()+m_hitPosition.y()*m_hitPosition.y()-m_driftDist*m_driftDist);
255 double v = 2*m_hitPosition.y()/(m_hitPosition.x()*m_hitPosition.x()+m_hitPosition.y()*m_hitPosition.y()-m_driftDist*m_driftDist);
256 double w = 2*m_driftDist/(m_hitPosition.x()*m_hitPosition.x()+m_hitPosition.y()*m_hitPosition.y()-m_driftDist*m_driftDist);
257 for(int i=0;i<N;i++){
258 alpha += delta_alpha;
259 if(alpha>M_PI)alpha -= M_PI;
260 double rho1 = u*cos(alpha) + v*sin(alpha) + w;
261 double rho2 = u*cos(alpha) + v*sin(alpha) - w;
262 //cout<<alpha<<" "<<rho1<<" "<<rho2<<endl;
263 double slantOfLine = v*cos(alpha) - u*sin(alpha);
264 int chargeOfHitOnCir1 = (slantOfLine/fabs(slantOfLine))*(rho1/fabs(rho1));
265 if(chargeOfHitOnCir1 != charge && y_min<(rho1) && (rho1)<y_max){
266 //if( y_min<(rho1) && (rho1)<y_max){
267 m_hitMap->Fill(alpha,rho1);
268 }
269 int chargeOfHitOnCir2 = (slantOfLine/fabs(slantOfLine))*(rho2/fabs(rho2));
270 if(chargeOfHitOnCir2 != charge && y_min<(rho2) && (rho2)<y_max){
271 //if( y_min<(rho2) && (rho2)<y_max){
272 if(m_hitType == CGEMHIT)continue;
273 //int bin = m_hitMap->FindBin(alpha,rho2);
274 //int bin = m_hitMap->FindFixBin(alpha,rho2);
275 //if(m_hitMap->GetBinContent(bin)>0)continue;
276 m_hitMap->Fill(alpha,rho2);
277 }
278 }
279}
280
281void HoughHit::clearMap()
282{
283 if(m_hitMap!=NULL)delete m_hitMap;
284 m_hitMap = NULL;
285}
286*/
287
288int HoughHit::flag()
289{
290 double nomShift = m_mdcGeomSvc->Layer(m_layer)->nomShift();
291 if(nomShift>0) return 1;
292 else if(nomShift<0) return -1;
293 else return 0;
294}
295
297{
298 double ToF = 1.e9*sqrt(m_hitPosition.x()*m_hitPosition.x()+m_hitPosition.y()*m_hitPosition.y())/Constants::c;
299 double Tprop = m_mdcCalibFunSvc->getTprop(m_layer,m_hitPosition.z()*10.);
300 double Twalk = m_mdcCalibFunSvc->getTimeWalk(m_layer, m_depositEnergy);
301 double T0 = m_mdcCalibFunSvc->getT0(m_layer,m_wire);
302 double driftTime = m_rawTime - 1.e9*m_bunchTime - ToF - Tprop - Twalk -T0;
303 //cout<<m_rawTime - Twalk - T0 - ToF - Tprop<<endl;
304 //cout<<"("<<m_layer<<", "<<m_wire<<"): ";
305 //cout<<"bunchT = "<<1.e9*m_bunchTime<<" , rawT "<<m_rawTime<<" , Tof "<<ToF<<" , Tprop "<<Tprop<<" , T0walk "<<Twalk+T0<<" , driftT "<<driftTime<<" , rmid "<<sqrt(m_hitPosition.x()*m_hitPosition.x()+m_hitPosition.y()*m_hitPosition.y())<<" , z "<<m_hitPosition.z()*10.0<<endl;
306 //cout<<endl;
307 return driftTime;
308}
309
310double HoughHit::driftDistance()
311{
312 //if(fabs(m_hitPosition.z())>150. || driftTime>1500.)return -1;
313 double driftT = driftTime();
314 if(fabs(driftT)>1500.||fabs(m_hitPosition.z()>150.)){
315 m_use = -1;
316 return 9999.;
317 }
318 double driftDist(-1);
319 int lrCalib=2;
320 //if (m_flag==1) lrCalib = 0;
321 //else if (m_flag==-1) lrCalib = 1;
322 double entranceAngle = 0;
323 driftDist = 0.1 * m_mdcCalibFunSvc->driftTimeToDist(driftT,m_layer,m_wire,lrCalib,entranceAngle);
324 return driftDist;
325}
326
328{
329 string hitType;
330 switch(m_hitType){
331 case CGEMHIT : hitType = "CGEMHIT"; break;
332 case MDCHIT : hitType = "MDCHIT"; break;
333 case CGEMMCHIT : hitType = "CGEMMCHIT"; break;
334 case MDCMCHIT : hitType = "MDCMCHIT"; break;
335 default : hitType = "";
336 }
337 cout<<"ID:" <<setw(6)<<m_hitID;
338 cout<<"(" <<setw(2)<<m_layer;
339 cout<<"," <<setw(3)<<m_wire<<") ";
340 cout<<" flag:" <<setw(3)<<m_flag;
341 if(m_hitType==CGEMHIT) {cout<<" clusterId "<<m_cgemCluster->getclusterid()<<" pos: "<<m_hitPosition;}
342 if(m_hitType==CGEMHIT||m_hitType==MDCHIT){
343 if(m_pairHit!=NULL){
344 cout<<" half:"<<setw(2)<<m_pairHit->getHalfCircle();
345 cout<<" trkID:"<<setw(3)<<(m_pairHit->getTrkID())[0];
346 cout<<" McHit:("<<setw(10)<<m_pairHit->getHitPosition().x()<<", "<<setw(10)<<m_pairHit->getHitPosition().y()<<", "<<setw(10)<<m_pairHit->getHitPosition().z()<<") ";
347 if(m_hitType==MDCHIT){
348 cout<<" McLR:"<<setw(3)<<m_pairHit->getMdcMcHit()->getPositionFlag();
349 cout<<" drift:"<<setw(10)<<m_pairHit->getMdcMcHit()->getDriftDistance();
350 }
351 //if(m_hitType==MDCHIT)
352 //cout<<" trkID:"<<setw(3)<<m_pairHit->getMdcMcHit()->getTrackIndex();
353 }
354 }
355 if(m_hitType==CGEMMCHIT||m_hitType==MDCMCHIT){
356 cout<<" half:"<<setw(2)<<getHalfCircle();
357 cout<<" trkID:"<<setw(3)<<m_trkID[0];
358 cout<<" McHit:("<<setw(10)<<m_hitPosition.x()<<", "<<setw(10)<<m_hitPosition.y()<<", "<<setw(10)<<m_hitPosition.z()<<") ";
359 //if(m_hitType==MDCMCHIT)
360 //cout<<" trkID:"<<setw(3)<<m_mdcMcHit->getTrackIndex();
361 if(m_hitType==MDCMCHIT){
362 cout<<" McLR:"<<setw(3)<<m_mdcMcHit->getPositionFlag();
363 cout<<" drift:"<<setw(10)<<m_mdcMcHit->getDriftDistance();
364 }
365 }
366
367 //cout<<setw(7)<<"hitID:" <<setw(6)<<m_hitID
368 //<<setw(10)<<"hitType:" <<setw(10)<<hitType
369 //<<setw(8)<<"layer:" <<setw(4)<<m_layer
370 //<<setw(6)<<"wire:" <<setw(6)<<m_wire
371 //<<setw(10)<<"flag:" <<setw(10)<<m_flag
372 //<<setw(5)<<"use:" <<setw(3)<<m_use
373 //<<endl
374 //<<setw(12)<<"bunchTime:"<<setw(12)<<m_bunchTime
375 //<<setw(12)<<"rawTime:" <<setw(12)<<m_rawTime
376 //<<setw(12)<<"charge:" <<setw(12)<<m_depositEnergy
377 //<<setw(12)<<"driftTime:"<<setw(12)<<driftTime()
378 //<<setw(11)<<"driftDist:"<<setw(12)<<m_driftDist
379 //<<setw(12)<<"residual:" <<setw(12)<<m_residual
380 //<<endl
381 //<<setw(10)<<"sLeft:" <<setw(10)<<m_sLeft
382 //<<setw(10)<<"zLeft:" <<setw(10)<<m_zLeft
383 //<<setw(10)<<"sRight:" <<setw(10)<<m_sRight
384 //<<setw(10)<<"zRight:" <<setw(10)<<m_zRight
385 //<<endl
386 //<<endl
387 //cout<<m_trkID.size()<<" trkID:";
388 //for(int i=0;i<m_trkID.size();i++)cout<<setw(4)<<m_trkID[i]<<endl;
389 //;
390 //if(m_layer>3)cout<<"TrkID:"<<setw(4)<<getDigi()->getTrackIndex();
391 //cout<<endl;
392 //;
393 cout<<endl;
394}
395
396
397// erase trk id and residual from the Hough hit
398void HoughHit::dropTrkID(int trkID)
399{
400 vector<int>::iterator it0 = m_trkID.begin();
401 vector<int>::iterator result = find(m_trkID.begin(),m_trkID.end(),trkID);
402 if(result!=m_trkID.end()) {
403 m_trkID.erase(result);
404 vector<double>::iterator itRes = m_vecResid.begin()+(result-it0);
405 if(itRes!=m_vecResid.end()) m_vecResid.erase(itRes);
406 }
407}
408
409vector<HepPoint3D>& HoughHit::VHitPosition(HoughTrack* track)
410{
411 if(getFlag()==0)return m_position;
412 m_position.clear();
413 //if(getPairHit()==NULL)return m_position;
414 //if(getPairHit()->getHalfCircle()!=1)return m_position;
415 double z(0);
416 double xc = track->center().x();
417 double yc = track->center().y();
418 double rTrack = track->radius();// signed FIXME
420 resetSZ();
421 double drift = getDriftDist();
422 const MdcGeoWire* wire = getMdcGeomSvc()->Wire(getLayer(),getWire());
423 HepPoint3D westPoint = wire->Forward();
424 HepPoint3D eastPoint = wire->Backward();
425 double xEast = eastPoint.x()/10.0;
426 double xWest = westPoint.x()/10.0;
427 double yEast = eastPoint.y()/10.0;
428 double yWest = westPoint.y()/10.0;
429 double zEast = eastPoint.z()/10.0;
430 double zWest = westPoint.z()/10.0;
431 //cout<<"wast:x,y,z: "<<xWest<<", "<<yWest<<", "<<zWest<<endl;
432 //cout<<"east:x,y,z: "<<xEast<<", "<<yEast<<", "<<zEast<<endl;
433 //cout<<"Xc, Yc, Rc: "<<xc<<", "<<yc<<", "<<rTrack<<endl;
434 double west2east = sqrt((xEast-xWest)*(xEast-xWest)+(yEast-yWest)*(yEast-yWest));
435
436 double slope = (yEast-yWest)/(xEast-xWest);
437 double intercept = (yWest-slope*xWest+yEast-slope*xEast)/2;
438 double a = 1+slope*slope;
439 double b = -2*(xc+slope*yc-slope*intercept);
440 double c1 = xc*xc+(yc-intercept)*(yc-intercept)-(rTrack+drift)*(rTrack+drift);
441 double c2 = xc*xc+(yc-intercept)*(yc-intercept)-(rTrack-drift)*(rTrack-drift);
442 //double c1 = intercept*(2*yc-intercept)+drift*(drift+rTrack);
443 //double c2 = intercept*(2*yc-intercept)+drift*(drift-rTrack);
444 double delta1 = (b*b-4*a*c1);
445 double delta2 = (b*b-4*a*c2);
446 //cout<<"a,b,c1,c2: "<<a<<", "<<b<<", "<<c1<<", "<<c2<<endl;
447 //cout<<"delta: "<<delta1<<", "<<delta2<<endl;
448 if(delta1>=0){
449 double x1 = (-b+sqrt(delta1))/(2*a);
450 double x2 = (-b-sqrt(delta1))/(2*a);
451 double y1 = slope*x1+intercept;
452 double y2 = slope*x2+intercept;
453 if((x1-xWest)*(x1-xEast)<0){
454 double l = sqrt((x1-xWest)*(x1-xWest)+(y1-yWest)*(y1-yWest));
455 z = zWest + l/west2east*fabs((zEast-zWest));
456 HepPoint3D position(x1,y1,z);
457 m_position.push_back(position);
458 }
459 if((x2-xWest)*(x2-xEast)<0){
460 double l = sqrt((x2-xWest)*(x2-xWest)+(y2-yWest)*(y2-yWest));
461 z = zWest + l/west2east*fabs((zEast-zWest));
462 HepPoint3D position(x2,y2,z);
463 m_position.push_back(position);
464 }
465 }
466
467 if( delta2>=0){
468 double x1 = (-b+sqrt(delta2))/(2*a);
469 double x2 = (-b-sqrt(delta2))/(2*a);
470 double y1 = slope*x1+intercept;
471 double y2 = slope*x2+intercept;
472 if((x1-xWest)*(x1-xEast)<0){
473 double l = sqrt((x1-xWest)*(x1-xWest)+(y1-yWest)*(y1-yWest));
474 z = zWest + l/west2east*fabs((zEast-zWest));
475 HepPoint3D position(x1,y1,z);
476 m_position.push_back(position);
477 }
478 if((x2-xWest)*(x2-xEast)<0){
479 //double l = zWest + sqrt((x2-xWest)*(x2-xWest)+(y2-yWest)*(y2-yWest));
480 //z = l/west2east*fabs((zEast-zWest));
481 double l = sqrt((x2-xWest)*(x2-xWest)+(y2-yWest)*(y2-yWest));
482 z = zWest + l/west2east*fabs((zEast-zWest));
483 HepPoint3D position(x2,y2,z);
484 m_position.push_back(position);
485 }
486 }
487 }
488 return m_position;
489}
490///*
492{
493 double residual(9999.);
494 if(m_flag==0){
495 HepPoint3D hitPoint = getHitPosition();
497 //HepPoint3D circleCenter = m_helix.center();
498 HepPoint3D circleCenter = track->center();
499 //double distance = circleCenter.perp(hitPoint);
500 double distance = (circleCenter-hitPoint).perp();
501 //double Rc = m_helix.radius();
502 double Rc = fabs(track->radius());
503 double driftDist(0);
504 //if(getHitType() == HoughHit::MDCMCHIT)driftDist = 0;
505 if(getHitType() == HoughHit::MDCHIT)driftDist = getDriftDist();
506 //residual = fabs(distance - Rc) - driftDist;
507 residual = driftDist-fabs(distance - Rc);
508 //cout<<"driftDist, distance, Rc = "<<driftDist<<", "<<distance<<", "<<Rc<<endl;
509 //double distance = (m_helix.center()).perp(hit.getHitPosition());
510 //res = fabs(distance - m_helix.radius()) - hit.getDriftDist();
512 double rCgem = hitPoint.perp();
513 //double phiTrkFlt = m_helix.IntersectCylinder(rCgem);
514 double phiTrkFlt = track->IntersectCylinder(rCgem);
515 phiTrkFlt = track->judgeHalf(this)*phiTrkFlt;
516 //HepPoint3D crossPoint = m_helix.x(phiTrkFlt);
517 HepPoint3D crossPoint = track->x(phiTrkFlt);
518 double phiCrossPoint = crossPoint.phi();
519 double phiMeasure = hitPoint.phi();
520 residual = phiMeasure - phiCrossPoint;
521 while(residual<-M_PI)residual += 2*M_PI;
522 while(residual> M_PI)residual -= 2*M_PI;
523 residual = rCgem*residual;
524 }
525 }else{
526 double zTruth = getPairHit()->getHitPosition().z();
527 double minRes(9999);
529 vector<HepPoint3D> position = VHitPosition(track);
530 for(vector<HepPoint3D>::iterator posIt = position.begin();posIt!=position.end();posIt++){
531 HepPoint3D point = *posIt;
532 double s = track->flightArc(point);
533 double zTrk = track->dz()+s*track->tanl();
534 double res = point.z() - zTrk;
535 //res = point.z() - zTruth;
536 if(fabs(res)<minRes){
537 minRes=fabs(res);
538 residual = res;
539 }
540 }
542 double s = track->flightArc(m_hitPosition);
543 double zTrk = track->dz()+s*track->tanl();
544 residual = m_hitPosition.z() - zTrk;
545 //residual = m_hitPosition.z() - zTruth;
546 }
547 }
548 return residual;
549}
550
552{
553 if(m_flag!=0&&m_hitType==HoughHit::MDCHIT){
554 double minRes(9999);
555 HepPoint3D hitPoint(m_hitPosition);
556 vector<HepPoint3D> position = VHitPosition(track);
557 for(vector<HepPoint3D>::iterator posIt = position.begin();posIt!=position.end();posIt++){
558 HepPoint3D point = *posIt;
559 double s = track->flightArc(point);
560 double zTrk = track->dz()+s*track->tanl();
561 double res = point.z() - zTrk;
562 if(fabs(res)<minRes){
563 minRes=fabs(res);
564 hitPoint = point;
565 }
566 }
567 m_hitPosition = hitPoint;
568 m_driftDist = driftDistance();
569 }
570}
571//*/
572double HoughHit::residual(HoughTrack* track, HepPoint3D& positionOntrack, HepPoint3D& positionOnDetector)
573{
574 double residual(9999.);
575 HepPoint3D pivot(0,0,0);
576 track->pivot(pivot);
577 if(m_hitType==MDCHIT){
578 const MdcDetector* mdcDetector(m_mdcDetector);
579 MdcHit mdcHit(m_mdcDigi,mdcDetector);
580 const Trajectory* wire(mdcHit.hitTraj());
581
582 double d0 = -track->dr();
583 double phi0 = track->phi0()+M_PI/2;
584 double omega = track->kappa()/fabs(track->alpha());
585 double z0 = track->dz();
586 double tanl = track->tanl();
587
588 //HepVector a(5,0);
589 //a(1) = d0;
590 //a(2) = phi0;
591 //a(3) = omega;
592 //a(4) = z0;
593 //a(5) = tanl;
594 //HepSymMatrix Ea(5,0);
595 //const HepVector pvec(a);
596 //const HepSymMatrix pcov(Ea);
597 //const HepPoint3D refpoint(track->pivot());
598 //const HelixTraj trk(pvec, pcov, -99999., 99999., refpoint);
599
600 double hitWireLength = m_hitPosition.z()-m_westPoint.z();
601 const TrkExchangePar trkExchangePar(d0,phi0,omega,z0,tanl);
602 double trkFlightLength = track->flightLength(m_hitPosition);
603 const HelixTraj helixTraj(trkExchangePar);
604 TrkPoca trkPoca(helixTraj,trkFlightLength,*wire,hitWireLength);
605 trkFlightLength = trkPoca.flt1();
606 hitWireLength = trkPoca.flt2();
607 double doca = trkPoca.doca();
608 //double trkFlightArc = track->flightArc(m_hitPosition);
609 //const TrkCircleTraj circleTraj(trkExchangePar);
610 //TrkPoca trkPoca(circleTraj,trkFlightArc,*wire,hitWireLength);
611 //trkFlightArc = trkPoca.flt1();
612 //hitWireLength = trkPoca.flt2();
613 //double doca = trkPoca.doca();
614
615 Hep3Vector wireDirection, trackDirection;
616 //HepPoint3D hitOnWire, hitOntrack;
617 wire->getInfo(hitWireLength, positionOnDetector, wireDirection);
618 helixTraj.getInfo(trkFlightLength, positionOntrack, trackDirection);
619 residual = m_driftDist - fabs(doca);
620 //cout<<"("<<m_layer<<","<<m_wire<<") ";
621 //cout<<setw(12)<<m_driftDist
622 //<<setw(12)<<doca
623 //<<setw(12)<<residual
624 //<<endl;
625
626 //cout<<"("<<m_layer<<","<<m_wire<<") "
627 //<<setw(12)<<getPairHit()->getHitPosition().z()
628 //<<setw(12)<<positionOntrack.z()
629 //<<setw(12)<<positionOnDetector.z()
630 //<<setw(12)<<tanl/sqrt(1+tanl*tanl)*trkFlightLength+z0
631 //<<setw(12)<<tanl*(track->flightArc(m_hitPosition))+z0
632 //<<endl;
633 }
634 else if(m_hitType==CGEMHIT){
635 double rCgem = m_hitPosition.perp();
636 //double phiTrkFlt = m_helix.IntersectCylinder(rCgem);
637 double phiTrkFlt = track->IntersectCylinder(rCgem);
638 phiTrkFlt = track->judgeHalf(this)*phiTrkFlt;
639 //HepPoint3D crossPoint = m_helix.x(phiTrkFlt);
640 positionOntrack = track->x(phiTrkFlt);
641 positionOnDetector = track->x(phiTrkFlt);
642 if(m_flag==0){
643 double phiCrossPoint = positionOntrack.phi();
644 double phiMeasure = m_hitPosition.phi();
645 double dphi = phiMeasure - phiCrossPoint;
646 while(dphi<-M_PI)dphi += 2*M_PI;
647 while(dphi> M_PI)dphi -= 2*M_PI;
648 residual = rCgem*dphi;
649 }
650 else{
651 residual = (m_cgemCluster->getrecv() - m_cgemGeomSvc->getReadoutPlane(m_layer,m_wire)->getVFromPhiZ(positionOntrack.phi(),positionOntrack.z()*10.))/10.;
652 }
653 }
654 return residual;
655}
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
HepGeom::Point3D< double > HepPoint3D
Definition Gam4pikp.cxx:37
XmlRpcServer s
NTuple::Array< double > m_wire
NTuple::Array< double > m_layer
#define M_PI
Definition TConstant.h:4
double getMiddleROfGapD() const
double getVFromPhiZ(double phi, double z, bool checkRange=true) const
CgemGeoLayer * getCgemLayer(int i) const
Definition CgemGeomSvc.h:48
CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const
static const double c
Definition Constants.h:43
double GetPositionXOfPostPoint() const
Definition CgemMcHit.h:107
double GetPositionYOfPrePoint() const
Definition CgemMcHit.h:105
double GetPositionZOfPrePoint() const
Definition CgemMcHit.h:106
int GetTrackID() const
Definition CgemMcHit.h:97
int GetLayerID() const
Definition CgemMcHit.h:100
double GetPositionXOfPrePoint() const
Definition CgemMcHit.h:104
double GetPositionZOfPostPoint() const
Definition CgemMcHit.h:109
double GetPositionYOfPostPoint() const
Definition CgemMcHit.h:108
double getPositionZ() const
Definition MdcMcHit.cxx:44
int getPositionFlag() const
Definition MdcMcHit.cxx:59
double getDepositEnergy() const
Definition MdcMcHit.cxx:54
unsigned int getTrackIndex() const
Definition MdcMcHit.cxx:29
double getDriftDistance() const
Definition MdcMcHit.cxx:49
double getPositionX() const
Definition MdcMcHit.cxx:34
Identifier identify() const
Definition MdcMcHit.cxx:24
double getPositionY() const
Definition MdcMcHit.cxx:39
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &dir) const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
int getHalfCircle()
Definition HoughHit.h:70
MdcGeomSvc * getMdcGeomSvc() const
Definition HoughHit.h:65
double residual(HoughTrack *track)
Definition HoughHit.cxx:491
void dropTrkID(int trkID)
Definition HoughHit.cxx:398
HoughHit * getPairHit()
Definition HoughHit.h:71
double getDriftDist() const
Definition HoughHit.h:54
vector< int > getTrkID() const
Definition HoughHit.h:56
const MdcMcHit * getMdcMcHit() const
Definition HoughHit.h:44
HepPoint3D getHitPosition() const
Definition HoughHit.h:51
HitType getHitType() const
Definition HoughHit.h:40
int getFlag() const
Definition HoughHit.h:47
void print()
Definition HoughHit.cxx:327
double driftTime()
Definition HoughHit.cxx:296
void updateVHit(HoughTrack *track)
Definition HoughHit.cxx:551
vector< HepPoint3D > & VHitPosition(HoughTrack *track)
Definition HoughHit.cxx:409
int getLayer() const
Definition HoughHit.h:45
int getWire() const
Definition HoughHit.h:46
void resetSZ()
Definition HoughHit.h:97
@ CGEMMCHIT
Definition HoughHit.h:27
@ CGEMHIT
Definition HoughHit.h:27
@ MDCMCHIT
Definition HoughHit.h:27
HoughHit & operator=(const HoughHit &other)
Definition HoughHit.cxx:209
int judgeHalf(HoughHit *hit)
double getT0(int layid, int cellid) const
double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const
double getTprop(int lay, double z) const
double getTimeWalk(int layid, double Q) const
const MdcGeoWire *const Wire(unsigned id)
const MdcGeoLayer *const Layer(unsigned id)
const Trajectory * hitTraj() const
Definition MdcHit.cxx:231
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 double MdcTime(int timeChannel)
Definition RawDataUtil.h:8
virtual Identifier identify() const
Definition RawData.cxx:15
unsigned int getChargeChannel() const
Definition RawData.cxx:45
unsigned int getTimeChannel() const
Definition RawData.cxx:40
double getenergydeposit(void) const
double getRecZ(void) const
int getclusterid(void) const
int getlayerid(void) const
int getflag(void) const
double getrecphi(void) const
double getrecv(void) const
int getsheetid(void) const
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
double flt2() const
Definition TrkPocaBase.h:68
double flt1() const
Definition TrkPocaBase.h:65
double doca() const
Definition TrkPoca.h:56
TCanvas * c1
Definition tau_mode.c:75