BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
MucRec2DRoad.cxx
Go to the documentation of this file.
1//$id$
2//
3//$log$
4
5/*
6 * 2003/12/22 Zhengyun You Peking University
7 *
8 * 2005/02/24 Zhengyun You Peking University
9 * transplanted to Gaudi framework
10 */
11
12using namespace std;
13
14#include <iostream>
15#include <vector>
16#include <CLHEP/Vector/ThreeVector.h>
17#include <CLHEP/Geometry/Point3D.h>
18
19#include "Identifier/MucID.h"
25
26const double muckInfinity = 1e30;
27// Constructor.
29 const int& seg,
30 const int& orient,
31 const float& xVertex,
32 const float& yVertex,
33 const float& zVertex,
34 const int& fittingMethod)
35 : m_VertexPos(xVertex, yVertex, zVertex),
36 m_VertexSigma(0.0, 0.0, 0.0),
37 m_Part(part), m_Seg(seg), m_Orient(orient),
38 m_Chi2(0.0), m_DOF(0),
39 m_MaxHitsPerGap(0), m_LastGap(0), m_TotalHits(0),
40 m_FitOK(false), m_QuadFitOK(false),
41 m_HitDistance(5, float(muckInfinity)),
42 m_pHits(0), m_fittingMethod(fittingMethod)
43{ }
44
45// Assignment constructor.
48{
49 // Assignment operator.
50 if ( this != &orig ) { // Watch out for self-assignment!
51 m_VertexPos = orig.m_VertexPos;
52 m_VertexSigma = orig.m_VertexSigma;
53 m_Index = orig.m_Index;
54 m_Part = orig.m_Part;
55 m_Seg = orig.m_Seg;
56 m_Orient = orig.m_Orient;
57 m_Chi2 = orig.m_Chi2;
58 m_DOF = orig.m_DOF;
59 m_FitOK = orig.m_FitOK;
60 m_MaxHitsPerGap = orig.m_MaxHitsPerGap;
61 m_LastGap = orig.m_LastGap;
62 m_TotalHits = orig.m_TotalHits;
63 m_HitDistance = orig.m_HitDistance;
64 m_pHits = orig.m_pHits;
65 m_fittingMethod = orig.m_fittingMethod;
66 }
67
68 return *this;
69}
70
71// Copy constructor.
73 : m_VertexPos(source.m_VertexPos),
74 m_VertexSigma(source.m_VertexSigma),
75 m_Index(source.m_Index),
76 m_Part(source.m_Part), m_Seg(source.m_Seg), m_Orient(source.m_Orient),
77 m_Chi2(source.m_Chi2), m_DOF(source.m_DOF),
78 m_MaxHitsPerGap(source.m_MaxHitsPerGap),
79 m_LastGap(source.m_LastGap), m_TotalHits(source.m_TotalHits),
80 m_FitOK(source.m_FitOK),
81 m_HitDistance(source.m_HitDistance),
82 m_pHits(source.m_pHits),
83 m_fittingMethod(source.m_fittingMethod)
84{ }
85
86// Destructor.
88{ }
89
90// Set the index for this road.
91void
92MucRec2DRoad::SetIndex(const int& index)
93{
94 if (index >= 0) m_Index = index;
95}
96
97// Attach the given hit this road.
98// Assume that this hit has been verified to be consistent with the road.
99void
101{
102 // cout << "MucRec2DRoad::AttachHit-I0 hit = " << hit << endl;
103 if (!hit) {
104 cout << "MucRec2DRoad::AttachHit-E1 null hit pointer!" << endl;
105 return ;
106 }
107
108 int gap = hit->Gap();
109 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
110 // The gap number of the hit is out of range.
111 cout << "MucRec2DRoad::AttachHit-W3 bad gap number = " << gap
112 << endl;
113 return;
114 }
115
116 // Attach the hit to the road.
117 //bool hitExist = false;
118 for (int i = 0; i < (int)m_pHits.size(); i++) {
119 if (m_pHits[i] == hit) return;
120 }
121 m_pHits.push_back(hit);
122 //cout << "before Count " << m_pHits.size() << endl;
123 // m_HitDistance[gap] = dX;
124
125 // Now recalculate the total number of hits and the max. number of
126 // hits per gap.
127 CountHits();
128 //cout << "after Count " << m_pHits.size() << endl;
129
130 // Redo the "simple" least-squares fit to the positions ...
131 float a, sa, b, sb, chi;
132 int n;
133 int status = SimpleFit(a, b, sa, sb, chi, n);
134 if (status < 0) {
135 //cout << "MucRec2DRoad::AttachHit-E5 simple fit fail status = " << status << endl;
136 }
137
138 //cout << "Hit center = " << hit->GetCenterPos() << endl;
139 //cout << "After attach hit, slope = " << a << " intercept = " << b << endl;
140}
141
142// Attach the given hit this road.
143// Assume that this hit has been verified to be consistent with the road.
144void
146{
147 // cout << "MucRec2DRoad::AttachHit-I0 hit = " << hit << endl;
148 if (!hit) {
149 cout << "MucRec2DRoad::AttachHit-E1 null hit pointer!" << endl;
150 return ;
151 }
152
153 int gap = hit->Gap();
154 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
155 // The gap number of the hit is out of range.
156 cout << "MucRec2DRoad::AttachHit-W3 bad gap number = " << gap
157 << endl;
158 return;
159 }
160
161 // Attach the hit to the road.
162 //bool hitExist = false;
163 for (int i = 0; i < (int)m_pHits.size(); i++) {
164 if (m_pHits[i] == hit) return;
165 }
166 m_pHits.push_back(hit);
167 //cout << "before Count " << m_pHits.size() << endl;
168 // m_HitDistance[gap] = dX;
169
170 // Now recalculate the total number of hits and the max. number of
171 // hits per gap.
172 CountHits();
173 //cout << "after Count " << m_pHits.size() << endl;
174
175}
176
177// Max number of consecutive gaps allowed with no hits attached.
178// This parameter affects the calculation of the last gap.
179void
181{
182 m_MaxNSkippedGaps = numGaps;
183 CountHits(); // recalculate the last gap and the hit counts.
184}
185
186// Calculate the best-fit straight line with "simple" weights.
187int
189 float& intercept,
190 float& sigmaSlope,
191 float& sigmaIntercept,
192 float& chisq,
193 int& ndof)
194{
195 // Assign to temporary arrays to be used in fit.
196 float px[100];
197 float py[100];
198 float pw[100];
199 int npoints = 0;
200
201 vector<MucRecHit*>::const_iterator iHit;
202
203 float weight[100];
204
205// for (int i = 0; i < m_pHits.size(); i++) {
206// cout<<"info: "<<m_pHits[i]->Seg()<<" "<<m_pHits[i]->Gap()<<" "<< m_pHits[i]->Strip()<<endl;
207// }
208 for (int i = 0; i < m_pHits.size(); i++) {
209 weight[i] = 1;
210
211 for(int j = 0; j < m_pHits.size(); j++){
212
213 if(j == i) continue;
214 if(m_pHits[i]->Part() == m_pHits[j]->Part() &&
215 m_pHits[i]->Seg() == m_pHits[j]->Seg() &&
216 m_pHits[i]->Gap() == m_pHits[j]->Gap() )
217 {
218 int deltaStrip = fabs(m_pHits[i]->Strip()- m_pHits[j]->Strip());
219
220 //cout<<i<<" "<<m_pHits[i]->Seg()<<" "<<m_pHits[i]->Gap()<<" "<<m_pHits[i]->Strip()<<" - "<<m_pHits[j]->Strip()<<endl;
221 if(deltaStrip == 0){
222 cout<<"deltaStrip == 0 ? check it"<<endl;
223 }
224 else{
225 weight[i] *= (deltaStrip+1) * (deltaStrip+1);
226 }
227
228 }
229 }
230 }
231
232 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
233 if (*iHit) { // Check for a null pointer.
234
235 /*
236 float localx, localy, localz;
237 (*iHit)->GetStrip()->GetCenterPos(localx, localy, localz);
238 if ( m_Orient == 0) {
239 px[npoints] = localy;
240 py[npoints] = localz;
241 }
242 else {
243 px[npoints] = localx;
244 py[npoints] = localz;
245 }
246 npoints++;
247 }
248 }
249 */
250
251
252 Hep3Vector center = (*iHit)->GetCenterPos();
253 Hep3Vector sigma = (*iHit)->GetCenterSigma();
254 //Hep3Vector sigma(1.0, 1.0, 1.0);
255
256 if (m_Part == 1) {
257 if ( m_Orient == 0) {
258 px[npoints] = center.z();
259 py[npoints] = sqrt(center.x()*center.x()
260 + center.y()*center.y());
261 if(m_Seg==2) py[npoints] = center.y(); //deal with seg2 seperately! because there is a hole here. 2006.11.9
262
263 pw[npoints] = 4.0 * 1.0/(sigma.y()*sigma.y()) / weight[npoints];
264 }
265 else {
266 px[npoints] = center.x();
267 py[npoints] = center.y();
268 pw[npoints] = 4.0 * 1.0/(sigma.x()*sigma.x()) / weight[npoints];
269 }
270 }
271 else {
272 if ( m_Orient == 0) {
273 px[npoints] = center.z();
274 py[npoints] = center.y();
275 pw[npoints] = 4.0 * 1.0/(sigma.y()*sigma.y()) / weight[npoints];
276 }
277 else {
278 px[npoints] = center.z();
279 py[npoints] = center.x();
280 pw[npoints] = 4.0 * 1.0/(sigma.x()*sigma.x()) / weight[npoints];
281 }
282 }
283
284 //cout << " in MucRec2DRoad ID: " <<(*iHit)->Part()<<" "<<(*iHit)->Seg()<<" "<<(*iHit)->Gap()<<" "<< (*iHit)->Strip()<<" "<<px[npoints] << " " << py[npoints] << " " << pw[npoints] << endl;
285 npoints++;
286
287 if(npoints > 99)
288 { cout<<"MucRec2DRoad: to many hits in this track, ignore it!"<<endl;
289 return -1;
290 }
291 }
292}
293/*
294float px2[100];
295float py2[100];
296for (int i = 0; i < m_pHits.size(); i++) {
297 int hitsInGap = 1;
298 px2[i] = -999; py2[i] = -999;
299 for(int j = 0; j < m_pHits.size(); j++){
300
301 if(j == i) continue;
302 if(m_pHits[i]->Part() == m_pHits[j]->Part() &&
303 m_pHits[i]->Seg() == m_pHits[j]->Seg() &&
304 m_pHits[i]->Gap() == m_pHits[j]->Gap() )
305 {
306 hitsInGap++;
307 px2[i] = (px[i]*(hitsInGap-1) + px[j])/hitsInGap;
308 py2[i] = (py[i]*(hitsInGap-1) + py[j])/hitsInGap;
309 cout<<hitsInGap<<" "<<px[i]<<" "<<px[j]<<" "<<px2[i]<<endl;
310 }
311 }
312}
313
314for(int i = 0; i < m_pHits.size(); i++){
315 if(px2[i] != -999&&py2[i] != -999){
316 px[i] = px2[i]; py[i] = py2[i];
317 }
318}
319*/
320
321ndof = npoints - 2;
322if (ndof < 0) return -1;
323
324if (npoints == 1) {
325 if (m_Part == 1) {
326 if ( m_Orient == 0) {
327 px[npoints] = m_VertexPos.z();
328 py[npoints] = sqrt(m_VertexPos.x()*m_VertexPos.x()
329 + m_VertexPos.y()*m_VertexPos.y());
330 if(m_Seg==2) py[npoints] = m_VertexPos.y();
331 }
332 else {
333 px[npoints] = m_VertexPos.x();
334 py[npoints] = m_VertexPos.y();
335 }
336 }
337 else {
338 if ( m_Orient == 0) {
339 px[npoints] = m_VertexPos.z();
340 py[npoints] = m_VertexPos.y();
341 }
342 else {
343 px[npoints] = m_VertexPos.z();
344 py[npoints] = m_VertexPos.x();
345 }
346 }
347 pw[npoints] = 1.0;
348 npoints++;
349}
350else {
351 if (npoints == 0 ) {
352 return -1;
353 }
354}
355
356// Do the fits here.
357MucRecLineFit fit;
358 int status = fit.LineFit(px, py, pw, npoints,
359 &slope, &intercept, &chisq,
360 &sigmaSlope, &sigmaIntercept);
361
362
363 float tempslope, tempintercept,tempchisq, tempsigmaslope, sigmaPos;
364 int status4 = fit.LineFit(px, py, pw,m_Part,m_Seg,m_Orient, npoints,
365 &tempslope, &tempintercept, &tempchisq,
366 &tempsigmaslope, &sigmaPos);
367
368 MucRecQuadFit quadfit;
369 float quad_a, quad_b, quad_c, sigmaquad_a, sigmaquad_b, sigmaquad_c, chisq_quad;
370 int whichhalf, status2;
371
372 if(m_fittingMethod == 2){
373 status2 = quadfit.QuadFit(px, py, pw, npoints,
374 &quad_a, &quad_b, &quad_c, &whichhalf, &chisq_quad,
375 &sigmaquad_a, &sigmaquad_b, &sigmaquad_c);
376
377 }
378 //cout << " in MucRec2DRoad slope " << slope << " "<<intercept<<endl;
379
380 if (slope > 1.0e10 || slope < -1.0e10) {
381 if (m_Seg > 4) slope *= -1.0; // to avoid wrong direction
382 }
383
384 m_SimpleSlope = slope;
385 m_SimpleSlopeSigma = sigmaSlope;
386 m_SimpleIntercept = intercept;
387 m_SimpleInterceptSigma = sigmaIntercept;
388 m_SimplePosSigma = sigmaPos; //new 20071227
389 m_SimpleChi2 = chisq;
390 m_SimpleDOF = ndof;
391 m_SimpleFitOK = (status == 0) && (chisq < 1000.0);
392 m_QuadFitOK = (status2 == 1);
393
394 m_SimpleQuad_a = quad_a;
395 m_SimpleQuad_b = quad_b;
396 m_SimpleQuad_c = quad_c;
397 m_SimpleQuad_whichhalf = whichhalf;
398 m_SimpleQuad_aSigma = sigmaquad_a;
399 m_SimpleQuad_bSigma = sigmaquad_b;
400 m_SimpleQuad_cSigma = sigmaquad_c;
401
402 return status;
403}
404
405
406/////////////////////////////////////////////////
407// Calculate the best-fit straight line with "simple" weights. add not use current gap!!!
408int
410 int currentgap,
411 float& slope,
412 float& intercept,
413 float& sigmaSlope,
414 float& sigmaIntercept,
415 float& chisq,
416 int& ndof)
417{
418 // Assign to temporary arrays to be used in fit.
419 float px[100];
420 float py[100];
421 float pw[100];
422 int npoints = 0;
423
424 int notused = 0;
425
426 vector<MucRecHit*>::const_iterator iHit;
427
428 float pw2[100];
429 for(int i = 0; i< m_pHits.size(); i++) {
430 pw2[i] = 1;
431 //----if( m_pHits[i]->Gap()==currentgap ) pw2[i] = 9999;
432 }
433
434 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
435 if (*iHit) { // Check for a null pointer.
436 if( (*iHit)->Gap()==currentgap ) continue;
437
438 Hep3Vector center = (*iHit)->GetCenterPos();
439 Hep3Vector sigma = (*iHit)->GetCenterSigma();
440 //Hep3Vector sigma(1.0, 1.0, 1.0);
441
442 if (m_Part == 1) {
443 if ( m_Orient == 0) {
444 px[npoints] = center.z();
445 py[npoints] = sqrt(center.x()*center.x()
446 + center.y()*center.y());
447 if(m_Seg==2) py[npoints] = center.y(); //deal with seg2 seperately! because there is a hole here. 2006.11.9
448
449 pw[npoints] = 1.0/(sigma.y()*sigma.y())/pw2[npoints]/pw2[npoints];
450 }
451 else {
452 px[npoints] = center.x();
453 py[npoints] = center.y();
454 pw[npoints] = 1.0/(sigma.x()*sigma.x())/pw2[npoints]/pw2[npoints];
455 }
456 }
457 else {
458 if ( m_Orient == 0) {
459 px[npoints] = center.z();
460 py[npoints] = center.y();
461 pw[npoints] = 1.0/(sigma.y()*sigma.y())/pw2[npoints]/pw2[npoints];
462 }
463 else {
464 px[npoints] = center.z();
465 py[npoints] = center.x();
466 pw[npoints] = 1.0/(sigma.x()*sigma.x())/pw2[npoints]/pw2[npoints];
467 }
468 }
469
470 //cout << " in MucRec2DRoad ID: " <<(*iHit)->Part()<<" "<<(*iHit)->Seg()<<" "<<(*iHit)->Gap()<<" "<< (*iHit)->Strip()<<" "<<px[npoints] << " " << py[npoints] << " " << pw[npoints] << endl;
471 //cout<<"process ngap: "<<currentgap<<" current: "<<(*iHit)->Gap()<<" x: "<<px[npoints]<<" y: "<<py[npoints]<<" weight: "<<pw[npoints]<<endl;
472 npoints++;
473
474 if(npoints > 99)
475 { cout<<"MucRec2DRoad: to many hits in this track, ignore it!"<<endl;
476 return -1;
477 }
478 }
479 }
480
481 ndof = npoints - 2;
482 if (ndof < 0) return -1;
483
484 if (npoints == 1) {
485 if (m_Part == 1) {
486 if ( m_Orient == 0) {
487 px[npoints] = m_VertexPos.z();
488 py[npoints] = sqrt(m_VertexPos.x()*m_VertexPos.x()
489 + m_VertexPos.y()*m_VertexPos.y());
490 if(m_Seg==2) py[npoints] = m_VertexPos.y();
491 }
492 else {
493 px[npoints] = m_VertexPos.x();
494 py[npoints] = m_VertexPos.y();
495 }
496 }
497 else {
498 if ( m_Orient == 0) {
499 px[npoints] = m_VertexPos.z();
500 py[npoints] = m_VertexPos.y();
501 }
502 else {
503 px[npoints] = m_VertexPos.z();
504 py[npoints] = m_VertexPos.x();
505 }
506 }
507 pw[npoints] = 1.0;
508 npoints++;
509 }
510else {
511 if (npoints == 0 ) {
512 return -1;
513 }
514
515}
516
517// Do the fits here.
518MucRecLineFit fit;
519int status = fit.LineFit(px, py, pw, npoints,
520 &slope, &intercept, &chisq,
521 &sigmaSlope, &sigmaIntercept);
522
523MucRecQuadFit quadfit;
524float quad_a, quad_b, quad_c, sigmaquad_a, sigmaquad_b, sigmaquad_c, chisq_quad;
525int whichhalf, status2;
526
527if(m_fittingMethod == 2){
528 status2 = quadfit.QuadFit(px, py, pw, npoints,
529 &quad_a, &quad_b, &quad_c, &whichhalf, &chisq_quad,
530 &sigmaquad_a, &sigmaquad_b, &sigmaquad_c);
531
532}
533//cout << " in MucRec2DRoad slope " << slope << " "<<intercept<<endl;
534
535if (slope > 1.0e10 || slope < -1.0e10) {
536 if (m_Seg > 4) slope *= -1.0; // to avoid wrong direction
537}
538
539////////2009-03-12
540 m_SimpleSlope = slope;
541 m_SimpleSlopeSigma = sigmaSlope;
542 m_SimpleIntercept = intercept;
543 m_SimpleInterceptSigma = sigmaIntercept;
544 //m_SimplePosSigma = sigmaPos; //new 20071227
545 m_SimpleChi2 = chisq;
546 m_SimpleDOF = ndof;
547 m_SimpleFitOK = (status == 0) && (chisq < 1000.0);
548 m_QuadFitOK = (status2 == 1);
549
550 m_SimpleQuad_a = quad_a;
551 m_SimpleQuad_b = quad_b;
552 m_SimpleQuad_c = quad_c;
553 m_SimpleQuad_whichhalf = whichhalf;
554 m_SimpleQuad_aSigma = sigmaquad_a;
555 m_SimpleQuad_bSigma = sigmaquad_b;
556 m_SimpleQuad_cSigma = sigmaquad_c;
557
558
559return status;
560}
561
562
563
564
565// Fit (with weights) the hit centers to a straight line.
566// This is a helper function for the Project methods.
567// Give an estimated position (x,y,z) of the point to which we will
568// project.
569 int
570MucRec2DRoad::Fit(const float& x,
571 const float& y,
572 const float& z,
573 float& slope, float& intercept,
574 float& sigmaSlope, float& sigmaIntercept,
575 float& chisq, int& ndof)
576{
577 int status;
578
579 // If the "simple" fit has not been done yet, do it now.
580 if (!m_SimpleFitOK) {
581 // Least-squares fit to the positions ...
582 float a, sa, b, sb, chi;
583 int n;
584 status = SimpleFit(a, b, sa, sb, chi, n);
585 if (status < 0) {
586 //cout << "MucRec2DRoad::Fit-E2 simple fit fail status = "
587 // << status << endl;
588 return status;
589 }
590 }
591
592 // Assign to temporary arrays to be used in fit.
593 float px[100];
594 float py[100];
595 float pw[100];
596 int npoints = 0;
597 float dx, dy, dr;
598
599
600 // include vertex point when do the fancy fitting
601 //if (m_Orient == kHORIZ) {
602 // px[npoints] = m_VertexPos.y();
603 // dx = px[npoints] - y;
604 //} else {
605 // px[npoints] = m_VertexPos.x();
606 // dx = px[npoints] - x;
607 //}
608 //pz[npoints] = m_VertexPos.z();
609 //dz = pz[npoints] - z;
610 //dr = sqrt(dx*dx + dz*dz);
611 //pw[npoints] = WeightFunc(m_SimpleChi2,dr);
612 //npoints++;
613
614 vector<MucRecHit*>::const_iterator iHit;
615
616 // Determine the weights based on the chi-square of the fit
617 // (the scatter of the points should be roughly related to the
618 // momentum) and the distance from the center to the estimated
619 // location.
620
621 //cout << m_pHits.size() << endl;
622 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
623 if (*iHit) { // Check for a null pointer.
624
625 Hep3Vector center = (*iHit)->GetCenterPos();
626 Hep3Vector sigma = (*iHit)->GetCenterSigma();
627
628 if (m_Part == 1) { // change from 0 to 1 at 2006.11.30
629 if ( m_Orient == 0) {
630 px[npoints] = center.z();
631 dx = px[npoints] - z;
632 py[npoints] = sqrt(center.x()*center.x()
633 + center.y()*center.y());
634 if(m_Seg==2) py[npoints] = center.y(); //deal with seg2 seperately! because there is a hole here. 2006.11.9
635 dy = py[npoints] - sqrt(x*x + y*y);
636 }
637 else {
638 px[npoints] = center.x();
639 dx = px[npoints] - x;
640 py[npoints] = center.y();
641 dy = py[npoints] - y;
642 }
643 }
644 else {
645 if ( m_Orient == 0) {
646 px[npoints] = center.z();
647 dx = px[npoints] - z;
648 py[npoints] = center.y();
649 dy = py[npoints] - y;
650 }
651 else {
652 px[npoints] = center.z();
653 dx = px[npoints] - z;
654 py[npoints] = center.x();
655 dy = py[npoints] - x;
656 }
657 }
658
659 dr = sqrt(dx*dx + dy*dy);
660 pw[npoints] = WeightFunc(m_SimpleChi2, dr);
661 //pw[npoints] = WeightFunc(m_SimpleChi2,dr);
662
663 // cout << " " << npoints << " "
664 // << px[npoints] << " " << py[npoints] << " " << pw[npoints]
665 // << " " << dx << " " << dy << " " << dr
666 // << endl;
667
668 npoints++;
669
670 if(npoints > 99)
671 { cout<<"MucRec2DRoad: to many hits in this track, ignore it!"<<endl;
672 return -1;
673 }
674
675 }
676 }
677
678 // Refit ...
679 ndof = npoints - 2;
680 if (npoints == 1) {
681 if (m_Part == 1) { // change from 0 to 1 at 2006.11.30
682 if ( m_Orient == 0) {
683 px[npoints] = m_VertexPos.z();
684 py[npoints] = sqrt(m_VertexPos.x()*m_VertexPos.x()
685 + m_VertexPos.y()*m_VertexPos.y());
686 if(m_Seg==2) py[npoints] = m_VertexPos.y();
687 }
688 else {
689 px[npoints] = m_VertexPos.x();
690 py[npoints] = m_VertexPos.y();
691 }
692 }
693 else {
694 if ( m_Orient == 0) {
695 px[npoints] = m_VertexPos.z();
696 py[npoints] = m_VertexPos.y();
697 }
698 else {
699 px[npoints] = m_VertexPos.z();
700 py[npoints] = m_VertexPos.x();
701 }
702 }
703 pw[npoints] = 1.0;
704 npoints++;
705 }
706 else {
707 if (npoints == 0) {
708 return -1;
709 }
710 }
711
712 MucRecLineFit fit;
713 //cout << "npoints " << npoints << endl;
714 status = fit.LineFit(px, py, pw, npoints,
715 &slope, &intercept, &chisq,
716 &sigmaSlope, &sigmaIntercept);
717 m_DOF = ndof;
718 m_Chi2 = chisq;
719
720 if (status < 0) {
721 //cout << "MucRec2DRoad::Fit-E3 fit fail status = " << status << endl;
722 }
723
724 return status;
725}
726
727// Where does the trajectory of this road intersect a specific gap?
728void
729MucRec2DRoad::Project(const int& gap,
730 float& x, float& y, float& z, float& x2, float& y2, float& z2)
731{
732 float sigmaX, sigmaY, sigmaZ;
733
734 x = 0.0; sigmaX = 0.0; x2 = 0.0;
735 y = 0.0; sigmaY = 0.0; y2 = 0.0;
736 z = 0.0; sigmaZ = 0.0; z2 = 0.0;
737
738 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
739 cout << "MucRec2DRoad::Project-E1 invalid gap = " << gap << endl;
740 return;
741 }
742
743 // Determine the projection point of the "simple" fit to the desired gap.
744 float x0, y0, z0, sigmaX0, sigmaY0, sigmaZ0;
745 float phi = m_Seg*0.25*kPi;
747
748 if (m_Part == 1) {
749 if (m_Orient == 0) {
750 geom->FindIntersection(m_Part, m_Seg, gap,
751 m_SimpleSlope*cos(phi), m_SimpleSlope*sin(phi), 1.0,
752 m_SimpleIntercept*cos(phi),m_SimpleIntercept*sin(phi), 0.0,
753 m_SimpleSlopeSigma, 0.0, 0.0,
754 m_SimpleInterceptSigma, 0.0, 0.0,
755 x0, y0, z0,
756 sigmaX0, sigmaY0, sigmaZ0);
757
758 if(m_SimpleSlope>10000){ //the line is in right center of this segment, we can not get intersection in y coordinate, in this case, m_SimpleIntercept is in z coordinate.
759 geom->FindIntersection(m_Part, m_Seg, gap,
760 m_SimpleSlope*cos(phi), m_SimpleSlope*sin(phi), 1.0,
761 0.0, 0.0, m_SimpleIntercept,
762 m_SimpleSlopeSigma, 0.0, 0.0,
763 m_SimpleInterceptSigma, 0.0, 0.0,
764 x0, y0, z0,
765 sigmaX0, sigmaY0, sigmaZ0);
766
767 }
768
769 }
770 else {
771 geom->FindIntersection(m_Part, m_Seg, gap,
772 1.0, m_SimpleSlope, 0.0,
773 0.0, m_SimpleIntercept, 0.0,
774 0.0, m_SimpleSlopeSigma, 0.0,
775 0.0, m_SimpleInterceptSigma, 0.0,
776 x0, y0, z0,
777 sigmaX0, sigmaY0, sigmaZ0);
778 //cout<<"in MucRec2DRoad line Project xyz0 = "<<x0<<" "<<y0<<" "<<z0<<endl;
779
780 }
781 }
782 else {
783 if (m_Orient == 0) {
784 geom->FindIntersection(m_Part, m_Seg, gap,
785 m_SimpleSlope, m_SimpleSlope, 1.0,
786 0.0, m_SimpleIntercept, 0.0,
787 0.0, m_SimpleSlopeSigma, 0.0,
788 0.0, m_SimpleInterceptSigma, 0.0,
789 x0, y0, z0,
790 sigmaX0, sigmaY0, sigmaZ0);
791 }
792 else {
793 geom->FindIntersection(m_Part, m_Seg, gap,
794 m_SimpleSlope, m_SimpleSlope, 1.0,
795 m_SimpleIntercept, 0.0, 0.0,
796 m_SimpleSlopeSigma, 0.0, 0.0,
797 m_SimpleInterceptSigma, 0.0, 0.0,
798 x0, y0, z0,
799 sigmaX0, sigmaY0, sigmaZ0);
800 }
801 //cout << " part " << m_Part
802 // << " seg " << m_Seg
803 // << " gap " << gap
804 // << " orient " << m_Orient
805 // << " slope = " << m_SimpleSlope
806 // << endl;
807 }
808
809 //cout << "In find intersection x0 = " << x0 << " y0 = " << y0 << " z0 = " << z0 << endl;
810
811 float a,b,sa,sb,chi2;
812 int ndof;
813
814 int status = Fit(x0, y0, z0, a, b, sa, sb, chi2, ndof);
815
816// m_FitOK = (status == 0) && (chi2<1000.0);
817// if (!fFitOK) {
818// cout << "MucRec2DRoad::Project-E2 fit fail status = "
819// << status << " npoints = " << npoints << " chi-sq = "
820// << chi2 << endl;
821// }
822
823// // Assign to fields of TMuiRoad object.
824// m_DOF = npoints - 2;
825// m_Chi2 = chi2;
826
827 if (m_Part == 1) { //change from 0 to 1 at 2006.11.30
828 if (m_Orient == 0) {
829 geom->FindIntersection(m_Part, m_Seg, gap,
830 a*cos(phi), a*sin(phi), 1.0,
831 //a, 0.0, 1.0,
832 b*cos(phi), b*sin(phi), 0.0,
833 sa, 0.0, 0.0,
834 sb, 0.0, 0.0,
835 x, y, z,
836 sigmaX, sigmaY, sigmaZ);
837
838 if(fabs(a)>10000){ ///
839 geom->FindIntersection(m_Part, m_Seg, gap,
840 a*cos(phi), a*sin(phi), 1.0,
841 0.0, 0.0, b,
842 //a, 0.0, 1.0,
843 //b, 0.0, 0.0,
844 sa, 0.0, 0.0,
845 sb, 0.0, 0.0,
846 x, y, z,
847 sigmaX, sigmaY, sigmaZ);
848
849 }
850 }
851 else {
852 geom->FindIntersection(m_Part, m_Seg, gap,
853 1.0, a, 0.0,
854 0.0, b, 0.0,
855 0.0, sa, 0.0,
856 0.0, sb, 0.0,
857 x, y, z,
858 sigmaX, sigmaY, sigmaZ);
859
860 if(m_fittingMethod == 2 && m_QuadFitOK ){
861 float a, b, c;
862 float sa, sb, sc, chi2x; int ydof; int whichhalf;
863
864 GetSimpleFitParams(a, b, c, whichhalf, sa, sb, sc, chi2x, ydof);
865 geom->FindIntersection(m_Part, m_Seg, gap,
866 10E30, 0.0, m_SimpleIntercept, 0.0, //vy = infinite
867 a, b, c, //y = a*x*x + b*x +c
868 whichhalf,
869 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
870 x, y, z, x2, y2, z2,
871 sigmaX, sigmaY, sigmaZ);
872
873
874 }
875
876 }
877 }
878 else {
879 if (m_Orient == 0) {
880 geom->FindIntersection(m_Part, m_Seg, gap,
881 a, a, 1.0,
882 0.0, b, 0.0,
883 0.0, sa, 0.0,
884 0.0, sb, 0.0,
885 x, y, z,
886 sigmaX, sigmaY, sigmaZ);
887 }
888 else {
889 geom->FindIntersection(m_Part, m_Seg, gap,
890 a, a, 1.0,
891 b, 0.0, 0.0,
892 sa, 0.0, 0.0,
893 sb, 0.0, 0.0,
894 x, y, z,
895 sigmaX, sigmaY, sigmaZ);
896 }
897 }
898
899 return;
900}
901
902// A unique identifier for this road in the current event.
903int
905{
906 return m_Index;
907}
908
909// In which part was this road found?
910int
911MucRec2DRoad::GetPart() const { return m_Part; }
912
913// In which seg was this road found?
914int
915MucRec2DRoad::GetSeg() const { return m_Seg; }
916
917// In which orientation was this road found?
918int
919MucRec2DRoad::GetOrient() const { return m_Orient; }
920
921// Position of the vertex point.
922void
923MucRec2DRoad::GetVertexPos(float& x, float& y, float& z) const
924{
925 x = m_VertexPos.x();
926 y = m_VertexPos.y();
927 z = m_VertexPos.z();
928
929 return;
930}
931
932// Which gap is the last one with hits attached to this road?
933int
934MucRec2DRoad::GetLastGap() const { return m_LastGap; }
935
936// Return the number of hits in the gap with the most attached hits.
937int
938MucRec2DRoad::GetMaxHitsPerGap() const { return m_MaxHitsPerGap; }
939
940// Return the total number of hits attached to this road.
941int
942MucRec2DRoad::GetTotalHits() const { return m_TotalHits; }
943
944// How many gaps provide hits attached to this road?
945int
947{
948 const int ngap = (int)MucID::getGapMax();
949 int gap, count = 0;
950 vector<int> firedGap;
951 for ( gap = 0; gap < ngap; gap++) {
952 firedGap.push_back(0);
953 }
954
955 vector<MucRecHit*>::const_iterator iHit;
956 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
957 if (*iHit) { // Check for a null pointer.
958 gap = (*iHit)->Gap();
959 firedGap[gap] = 1;
960 }
961 }
962
963 for ( gap = 0; gap < ngap; gap++) {
964 count += firedGap[gap];
965 }
966
967 return count;
968}
969
970// How many hits per gap does this road contain?
971int
972MucRec2DRoad::GetHitsPerGap(const int& gap) const
973{
974 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
975 cout << "MucRec2DRoad::GetHitsPerGap-E1 invalid gap = " << gap << endl;
976 return 0;
977 }
978
979 vector<MucRecHit*>::const_iterator iHit;
980 int hitsInGap = 0;
981
982 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
983
984 if ( !(*iHit) ) {
985 cout << "MucRec2DRoad::GetHitsPerGap()-E2 null hit pointer !" << endl;
986 return 0;
987 }
988 else {
989 if( gap == (*iHit)->Gap() ) hitsInGap += 1;
990 }
991 }
992
993 return hitsInGap;
994}
995
996// Does this road contain any hits in the given seg in a gap?
997bool
998MucRec2DRoad::HasHitInGap(const int& gap) const
999{
1000 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
1001 cout << "MucRec2DRoad::HasHitInGap-E2 invalid gap = " << gap << endl;
1002 return false;
1003 }
1004
1005 bool found = false;
1006 vector<MucRecHit*>::const_iterator iHit;
1007
1008 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
1009 if (*iHit) { // Check for a null pointer.
1010 if ( (*iHit)->Gap() == gap ) {
1011 found = true;
1012 }
1013 }
1014 }
1015
1016 return found;
1017}
1018
1019// How many hits do two roads share?
1020int
1022{
1023 if (!road2) {
1024 return 0;
1025 }
1026
1027 int count = 0;
1028 vector<MucRecHit*>::const_iterator iHit1;
1029 vector<MucRecHit*>::const_iterator iHit2;
1030 MucRecHit *hit1, *hit2;
1031
1032 for( iHit1 = m_pHits.begin(); iHit1 != m_pHits.end(); iHit1++){
1033 for( iHit2 = road2->m_pHits.begin();
1034 iHit2 != road2->m_pHits.end(); iHit2++){
1035 hit1 = (*iHit1);
1036 hit2 = (*iHit2);
1037
1038 if ( (hit1 != 0) && (hit2 != 0) ) {
1039 if (hit1->GetID() == hit2->GetID()) {
1040 count++;
1041 }
1042 }
1043 }
1044 }
1045
1046 return count;
1047}
1048
1049// Slope of trajectory.
1050float
1051MucRec2DRoad::GetSlope() const { return m_SimpleSlope; }
1052
1053// Intercept of trajectory.
1054float
1055MucRec2DRoad::GetIntercept() const { return m_SimpleIntercept; }
1056
1057// Degrees of freedom of trajectory fit.
1058int
1059MucRec2DRoad::GetDegreesOfFreedom() const { return m_SimpleDOF; }
1060
1061// Chi-square parameters (per degree of freedom) of trajectory fit.
1062float
1064{
1065 if ( (!m_SimpleFitOK) || (m_SimpleDOF < 0) ) {
1066 return -1.0;
1067 }
1068 else if (m_SimpleDOF == 0) {
1069 return 0.0;
1070 }
1071 else {
1072 return (m_SimpleChi2 / m_SimpleDOF);
1073 }
1074}
1075
1076// Get the parameters from the simple fit.
1077void
1078MucRec2DRoad::GetSimpleFitParams(float& slope, float& intercept,
1079 float& sigmaSlope, float& sigmaIntercept,
1080 float& chisq, int& ndof) const
1081{
1082 slope = m_SimpleSlope;
1083 intercept = m_SimpleIntercept;
1084 sigmaSlope = m_SimpleSlopeSigma;
1085 sigmaIntercept = m_SimpleInterceptSigma;
1086 chisq = m_SimpleChi2;
1087 ndof = m_SimpleDOF;
1088
1089 return;
1090}
1091
1092
1093void
1094MucRec2DRoad::GetPosSigma(float &possigma)const
1095{
1096 possigma = m_SimplePosSigma;
1097
1098}
1099
1100
1101// Get the parameters from the simple quad fit.
1102void
1103MucRec2DRoad::GetSimpleFitParams(float& a, float& b, float& c, int& whichhalf,
1104 float& sigmaa, float& sigmab, float& sigmac,
1105 float& chisq, int& ndof) const
1106{
1107 a = m_SimpleQuad_a;
1108 b = m_SimpleQuad_b;
1109 c = m_SimpleQuad_c;
1110 whichhalf = m_SimpleQuad_whichhalf;
1111
1112 sigmaa = m_SimpleQuad_aSigma;
1113 sigmab = m_SimpleQuad_bSigma;
1114 sigmac = m_SimpleQuad_cSigma;
1115
1116 chisq = m_SimpleChi2;
1117 ndof = m_SimpleDOF;
1118
1119 return;
1120}
1121
1122
1123
1124// Get a pointer to the first found hit attached in a particular gap.
1125MucRecHit*
1126MucRec2DRoad::GetHit(const int& gap) const
1127{
1128 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
1129 cout << "MucRec2DRoad::Hit-E1 invalid gap = " << gap << endl;
1130 return 0;
1131 }
1132
1133 vector<MucRecHit*>::const_iterator iHit;
1134
1135 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
1136 if (*iHit) { // Check for a null pointer.
1137 if ( (*iHit)->Gap() == gap) {
1138 return (*iHit);
1139 }
1140 }
1141 }
1142
1143 return 0L;
1144}
1145
1146// Distance from a hit to the projection of the road to the gap
1147// containing the hit.
1148float
1150{
1151 // Use straight-line projection?
1152 if (!hit) {
1153 cout << "MucRec2DRoad::GetHitDistance-E1 null hit pointer!" << endl;
1154 return muckInfinity;
1155 }
1156
1157 int gap = hit->Gap();
1158 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
1159 cout << "MucRec2DRoad::HitDistance-W2 bad gap number = " << gap << endl;
1160 return muckInfinity;
1161 }
1162
1163 if ( hit->GetGap()->Orient() != m_Orient) {
1164 // The orientation of the hit is different from that of the road.
1165 cout << "MucRec2DRoad::GetHitDistance-W3 "
1166 << " hit has wrong orientation = "
1167 << hit->GetGap()->Orient()
1168 << endl;
1169 return muckInfinity;
1170 }
1171
1172 HepPoint3D r = hit->GetCenterPos();
1173 HepPoint3D rl = hit->GetGap()->TransformToGap(r);
1174 // cout << "hit center " << r << endl;
1175 // cout << "hit center local " << rl << endl;
1176
1177 // Determine the projection point of the "simple" fit to the desired gap.
1178 // FIXME(?): need to use fit with fancy weights instead?
1179 float delta, delta1,delta2;
1180 float x0, y0, z0;
1181 float x2, y2, z2;
1182 //float sigmaX0, sigmaY0, sigmaZ0;
1183
1184 //cout << "y:x = " << m_SimpleSlope << endl;
1185
1186 Project(gap, x0, y0, z0, x2, y2, z2);
1187 // cout << " gap = " << gap << " x0 = " << x0
1188 // << " y0 = " << y0 << " z0 = " << z0
1189 // << endl;
1190
1191 if(x0==y0&&x0==z0&&x0==0) {x0+=-9999;y0+=-9999;z0+=-9999;}//cout<<"wrong intersection"<<endl;}
1192 if(x2==y2&&x2==z2&&x2==0) {x2+=-9999;y2+=-9999;z2+=-9999;}//cout<<"wrong intersection"<<endl;} //wrong intersection!!!
1193 HepPoint3D s = HepPoint3D(x0, y0, z0);
1194 HepPoint3D s_2 = HepPoint3D(x2, y2, z2);
1195 HepPoint3D sl = hit->GetGap()->TransformToGap(s);
1196 HepPoint3D s_2l = hit->GetGap()->TransformToGap(s_2);
1197 //cout << "project center " << s << endl;
1198
1199// cout << "project center local sl= " << sl << endl;
1200// cout << "project center local sl= " << s_2l << endl;
1201// cout << "project center local rl= " << rl << endl;
1202 if ( m_Part == 0 ) {
1203 if ( m_Orient == 0 ) {
1204 delta1 = fabs( sl.y() - rl.y() );
1205 delta2= fabs( s_2l.y() - rl.y() );
1206 }
1207 else {
1208 delta1 = fabs( sl.x() - rl.x() );
1209 delta2= fabs( s_2l.x() - rl.x() );
1210 }
1211 }
1212 else {
1213 if ( m_Orient == 0 ) {
1214 delta1 = fabs( sl.y() - rl.y() );
1215 delta2= fabs( s_2l.y() - rl.y() );
1216 }
1217 else {
1218 delta1 = fabs( sl.x() - rl.x() );
1219 delta2= fabs( s_2l.x() - rl.x() );
1220 }
1221 }
1222// if(which==0) {
1223// if(delta1<delta2)delta = delta1;
1224// else delta = delta2;
1225// }
1226 //cout<<"which = "<<which<<" distance = "<<delta1<<" "<<delta2<<endl;
1227
1228 if(delta1 < delta2) return delta1;
1229 else return delta2;
1230}
1231
1232// Determine the size of the search window in the given gap.
1233float
1235{
1236 if ( (gap < 0) || (gap >= (int)MucID::getGapMax()) ) {
1237 cout << "MucRec2DRoad::GetSearchWindowSize-E1 invalid gap = " << gap << endl;
1238 return 0.0;
1239 }
1240
1241 // Determine the projection point of the "simple" fit to the last
1242 // gap and the desired gap.
1243 // FIXME? the "delta-x" variable is calculated as the scalar
1244 // difference between the positions obtained by projecting to the
1245 // last gap and to the desired gap.
1246
1248 float x1, y1, z1, x2, y2, z2, dx, dy, dr;
1249 float sigmaX, sigmaY, sigmaZ;
1250
1251 if (m_Part == 0) {
1252 if (m_Orient == 0) {
1253 geom->FindIntersection(m_Part, 0, m_LastGap,
1254 1.0, m_SimpleSlope, 0.0,
1255 0.0, m_SimpleIntercept, 0.0,
1256 0.0, m_SimpleSlopeSigma, 0.0,
1257 0.0, m_SimpleInterceptSigma, 0.0,
1258 x1, y1, z1,
1259 sigmaX, sigmaY, sigmaZ);
1260 geom->FindIntersection(m_Part, 0, gap,
1261 1.0, m_SimpleSlope, 0.0,
1262 0.0, m_SimpleIntercept, 0.0,
1263 0.0, m_SimpleSlopeSigma, 0.0,
1264 0.0, m_SimpleInterceptSigma, 0.0,
1265 x2, y2, z2,
1266 sigmaX, sigmaY, sigmaZ);
1267 dx = z2 - z1;
1268 dy = sqrt(x2*x2 + y2*y2) - sqrt(x1*x1 + y1*y1);
1269 }
1270 else {
1271 geom->FindIntersection(m_Part, m_Seg, m_LastGap,
1272 m_SimpleSlope, 0.0, 1.0,
1273 m_SimpleIntercept, 0.0, 0.0,
1274 m_SimpleSlopeSigma, 0.0, 0.0,
1275 m_SimpleInterceptSigma, 0.0, 0.0,
1276 x1, y1, z1,
1277 sigmaX, sigmaY, sigmaZ);
1278 geom->FindIntersection(m_Part, m_Seg, gap,
1279 m_SimpleSlope, 0.0, 1.0,
1280 m_SimpleIntercept, 0.0, 0.0,
1281 m_SimpleSlopeSigma, 0.0, 0.0,
1282 m_SimpleInterceptSigma, 0.0, 0.0,
1283 x2, y2, z2,
1284 sigmaX, sigmaY, sigmaZ);
1285 dx = x2 - x1;
1286 dy = y2 - y1;
1287 }
1288 }
1289 else {
1290 if (m_Orient == 0) {
1291 geom->FindIntersection(m_Part, m_Seg, m_LastGap,
1292 0.0, m_SimpleSlope, 1.0,
1293 0.0, m_SimpleIntercept, 0.0,
1294 0.0, m_SimpleSlopeSigma, 0.0,
1295 0.0, m_SimpleInterceptSigma, 0.0,
1296 x1, y1, z1,
1297 sigmaX, sigmaY, sigmaZ);
1298 geom->FindIntersection(m_Part, m_Seg, gap,
1299 0.0, m_SimpleSlope, 1.0,
1300 0.0, m_SimpleIntercept, 0.0,
1301 0.0, m_SimpleSlopeSigma, 0.0,
1302 0.0, m_SimpleInterceptSigma, 0.0,
1303 x2, y2, z2,
1304 sigmaX, sigmaY, sigmaZ);
1305 dx = z2 - z1;
1306 dy = y2 - y1;
1307 }
1308 else {
1309 geom->FindIntersection(m_Part, m_Seg, m_LastGap,
1310 m_SimpleSlope, 0.0, 1.0,
1311 m_SimpleIntercept, 0.0, 0.0,
1312 m_SimpleSlopeSigma, 0.0, 0.0,
1313 m_SimpleInterceptSigma, 0.0, 0.0,
1314 x1, y1, z1,
1315 sigmaX, sigmaY, sigmaZ);
1316 geom->FindIntersection(m_Part, m_Seg, gap,
1317 m_SimpleSlope, 0.0, 1.0,
1318 m_SimpleIntercept, 0.0, 0.0,
1319 m_SimpleSlopeSigma, 0.0, 0.0,
1320 m_SimpleInterceptSigma, 0.0, 0.0,
1321 x2, y2, z2,
1322 sigmaX, sigmaY, sigmaZ);
1323 dx = z2 - z1;
1324 dy = x2 - x1;
1325 }
1326 }
1327
1328 dr = sqrt(dx*dx + dy*dy);
1329
1330 return WindowFunc(m_SimpleChi2,dr);
1331}
1332
1333// Calculate the hit counts and last gap quantities.
1334void
1335MucRec2DRoad::CountHits()
1336{
1337 m_MaxHitsPerGap = 0;
1338 m_TotalHits = 0;
1339 m_LastGap = 0;
1340
1341 vector<MucRecHit*>::const_iterator iHit;
1342 const int ngap = (int)MucID::getGapNum(m_Part);
1343 vector<int> HitsPerGap;
1344 for (int gap = 0; gap < ngap; gap++) {
1345 HitsPerGap.push_back(0);
1346 }
1347
1348 // Fill HitsPerGap
1349 for (iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
1350 if ( !(*iHit) ) {
1351 cout << "MucRec2DRoad::CountHits()-E1 null hit pointer !" << endl;
1352 return;
1353 }
1354 else {
1355 int gap = (*iHit)->Gap();
1356 HitsPerGap[gap]++;
1357 //cout << "gap " << gap << endl;
1358 }
1359 }
1360
1361 // Find the gap from where we should stop count,
1362 // namely in front of the gap there are more than
1363 // m_MaxNSkippedGaps gaps containing no hit.
1364
1365 int StopGap = ngap;
1366 /*
1367 for (int gap = m_MaxNSkippedGaps; gap < ngap; gap++) {
1368 int SubTotalHits = 0;
1369 for (int igap = gap-m_MaxNSkippedGaps; igap <= gap; igap++) {
1370 SubTotalHits += HitsPerGap[igap];
1371 }
1372 if (SubTotalHits == 0 ) {
1373 StopGap = gap - m_MaxNSkippedGaps;
1374 break;
1375 }
1376 }
1377 */
1378
1379 //cout << "StopGap " << StopGap << endl;
1380 // Now we might get correct counting on hits, last gap and MaxHitsPerGap
1381 for (int gap = 0; gap < StopGap; gap++) {
1382 m_TotalHits += HitsPerGap[gap];
1383 if(m_MaxHitsPerGap < HitsPerGap[gap]) m_MaxHitsPerGap = HitsPerGap[gap];
1384 if(HitsPerGap[gap] > 0) m_LastGap = gap;
1385 }
1386}
1387
1388// Does the Hit exist in the road .
1389bool
1391{
1392
1393 vector<MucRecHit*>::const_iterator iHit;
1394 bool HitExist = false;
1395
1396 // Also, if a track hits overlap region of two panels, we avoid
1397 // to double count hits in two panels
1398
1399 Identifier id = hit->GetID();
1400
1401 for ( iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++ ) {
1402 if ( *iHit ) { // Check for a null pointer.
1403 if ( (*iHit)->GetID() == id ) HitExist = true;
1404 }
1405 if (HitExist) break;
1406 }
1407
1408 return HitExist;
1409}
1410
1411// Get indices of all hits in the road.
1412vector<Identifier>
1414{
1415 vector<Identifier> idCon;
1416
1417 vector<MucRecHit*>::const_iterator iHit;
1418 for ( iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
1419 if (*iHit) { // Check for a null pointer.
1420 Identifier id = (*iHit)->GetID();
1421 idCon.push_back(id);
1422 /*
1423 cout << " MucRec2DRoad::HitIndices gap orientation twopack= "
1424 << (*iHit)->ChannelID().Plane() << " "
1425 << (*iHit)->ChannelID().Orient() << " "
1426 << (*iHit)->ChannelID().TwoPack() << endl;
1427 */
1428 }
1429 }
1430 return idCon;
1431}
1432
1433vector<MucRecHit*>
1435{
1436return m_pHits;
1437
1438}
1439
1440
1441
1442// Print Hits Infomation.
1443void
1445{
1446 vector<MucRecHit*>::const_iterator iHit;
1447 for ( iHit = m_pHits.begin(); iHit != m_pHits.end(); iHit++) {
1448 if (*iHit) { // Check for a null pointer.
1449 float xl, yl, zl;
1450 (*iHit)->GetStrip()->GetCenterPos(xl, yl, zl);
1451 HepPoint3D vl(xl, yl, zl);
1452 HepPoint3D vg = (*iHit)->GetGap()->TransformToGlobal(vl);
1453
1454 cout << " orient " << m_Orient
1455 << " part " << (*iHit)->Part()
1456 << " seg " << (*iHit)->Seg()
1457 << " gap " << (*iHit)->Gap()
1458 << " strip " << (*iHit)->Strip()
1459 << " pos (" << vg.x() << ", " << vg.y() << ", " << vg.z() << ")"
1460 << endl;
1461 }
1462 }
1463
1464}
1465
1466// Function used to determine the search weight size
1467float
1468MucRec2DRoad::WeightFunc(const float& chisq, const float& distance) const
1469{
1470 return 1.0;
1471}
1472
1473// Function used to determine the search window size
1474float
1475MucRec2DRoad::WindowFunc(const float& chisq, const float& distance) const
1476{
1477 return 1.0;
1478}
1479
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
const Int_t n
Double_t x[10]
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
XmlRpcServer s
Definition: HelloServer.cpp:11
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
Definition: KarFin.h:34
const double kPi
Definition: MucConstant.h:6
const double muckInfinity
HepPoint3D TransformToGap(const HepPoint3D gPoint) const
Transform a point from global coordinate to gap coordinate.
Definition: MucGeoGap.cxx:627
int Orient() const
Definition: MucGeoGap.h:108
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
void FindIntersection(const int part, const int seg, const int gap, const float vx, const float vy, const float vz, const float x0, const float y0, const float z0, const float sigmaVx, const float sigmaVy, const float sigmaVz, const float sigmaX0, const float sigmaY0, const float sigmaZ0, float &x, float &y, float &z, float &sigmaX, float &sigmaY, float &sigmaZ)
static value_type getGapMax()
Definition: MucID.cxx:195
static value_type getGapNum(int part)
Definition: MucID.cxx:171
~MucRec2DRoad()
Destructor.
int Fit(const float &x, const float &y, const float &z, float &slope, float &intercept, float &sigmaSlope, float &sigmaIntercept, float &chisq, int &ndof)
Fit (with weights) the hit center to a straight line.
vector< Identifier > GetHitsID() const
Get indices of all hits in the road.
int GetNGapsWithHits() const
How many gaps provide hits attached to this road?
bool HasHitInGap(const int &gap) const
Does this road contain any hits in the given gap?
void PrintHitsInfo() const
Print Hits Infomation.
int GetTotalHits() const
How many hits in all does this road contain?
int GetHitsPerGap(const int &gap) const
How many hits per gap does this road contain?
float GetReducedChiSquare() const
Chi-square parameter (per degree of freedom) of the trajectory fit.
void SetIndex(const int &index)
Set the index for this road.
void Project(const int &gap, float &x, float &y, float &z, float &x2, float &y2, float &z2)
Where does the trajectory of this road intersect a specific gap?
void GetVertexPos(float &x, float &y, float &z) const
Position of the vertex point.
void GetPosSigma(float &possigma) const
float WindowFunc(const float &chisq, const float &distance) const
MucRec2DRoad & operator=(const MucRec2DRoad &orig)
Assignment constructor.
float GetSearchWindowSize(const int &gap) const
Determine the size of the search window in the given gap.
float GetIntercept() const
Intercept of trajectory.
void AttachHit(MucRecHit *hit)
Attach the given hit to this road.
MucRec2DRoad(const int &part=0, const int &seg=0, const int &orient=0, const float &xVertex=0.0, const float &yVertex=0.0, const float &zVertex=0.0, const int &fittingMethod=0)
Constructor.
int GetMaxHitsPerGap() const
How many hits were attached in the gap with the most attached hits?
int GetLastGap() const
Which gap is the last one with hits attached to this road?
void AttachHitNoFit(MucRecHit *hit)
Attach the given hit to this road, but not fit this road.
float GetSlope() const
Slope of trajectory.
bool HasHit(MucRecHit *hit) const
Does the hit exist in the road .
int GetNSharedHits(const MucRec2DRoad *road) const
How many hits do two roads share?
void SetMaxNSkippedGaps(const int &nGaps)
int GetPart() const
In which part was this road found?
int SimpleFit(float &slope, float &intercept, float &sigmaSlope, float &sigmaIntercept, float &chisq, int &ndof)
Calculate the best-fit straight line with "simple" weights.
float GetHitDistance(const MucRecHit *hit)
Distance to a hit.
int GetDegreesOfFreedom() const
How many degrees of freedom in the trajectory fit?
int GetIndex() const
A unique identifier for this road in the current event.
void GetSimpleFitParams(float &slope, float &intercept, float &sigmaSlope, float &sigmaIntercept, float &chisq, int &ndof) const
Get the parameters from the simple fit.
vector< MucRecHit * > GetHits() const
float WeightFunc(const float &chisq, const float &distance) const
int GetSeg() const
In which segment was this road found?
int GetOrient() const
In which orientation was this road found?
MucRecHit * GetHit(const int &gap) const
Get a pointer to the first found hit attached in a particular gap.
int SimpleFitNoCurrentGap(int currentgap, float &slope, float &intercept, float &sigmaSlope, float &sigmaIntercept, float &chisq, int &ndof)
Calculate the best-fit straight line with "simple" weights. not use current gap!!!
MucGeoGap * GetGap() const
Get geometry data for the gap containing this hit.
Definition: MucRecHit.h:83
Hep3Vector GetCenterPos() const
Get Center position of the strip (global coords).
Definition: MucRecHit.cxx:104
int Gap() const
Get Gap.
Definition: MucRecHit.h:77
Identifier GetID() const
Get soft identifier of this hit.
Definition: MucRecHit.h:68
int LineFit(float x[], float y[], float w[], int n, float *a, float *b, float *chisq, float *siga, float *sigb)
int QuadFit(float x[], float y[], float w[], int n, float *a, float *b, float *c, int *half, float *chisq, float *siga, float *sigb, float *sigc)