BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcxMergeDups.cxx
Go to the documentation of this file.
1//-------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcxMergeDups.cxx,v 1.9 2011/12/08 06:52:29 zhangy Exp $
4//
5// Description:
6// Class Implementation for K0s finding
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// S. Wagner
13//
14// Copyright Information:
15// Copyright (C) 1997 BEPCII
16//
17// History:
18// Migration for BESIII MDC
19//
20//------------------------------------------------------------------------
21#include <math.h>
23#include "MdcxReco/MdcxHel.h"
24#include "CLHEP/Alist/AIterator.h"
25#include "MdcxReco/MdcxHit.h"
27using std::cout;
28using std::endl;
29
31 m_debug = (debug == 10);
32 int iprt = 0;
33 int ntracks = trkl.length();
34 if (iprt) cout << "MdcxMergeDups called with " << ntracks << " tracks" << endl;
35 double m_2pi = 2.0*M_PI;
36 int k = 0;
37 while(trkl[k]) trkl[k++]->SetUsedOnHel(0);
38
39 if (ntracks > 1) {
40 for (int i = 0; i < ntracks-1; i++) {
41 MdcxFittedHel* iptr = trkl[i];
42 int already_merged = 0;
43 if (iptr->GetUsedOnHel()) {
44 already_merged = trkl[i]->GetUsedOnHel();
45 iptr = NewTrklist[already_merged-1];
46 }
47 for (int j = i+1; j < ntracks; j++) {
48 if (trkl[j]->GetUsedOnHel()) continue;
49 double omega1 = iptr->Omega();
50 double omega2 = trkl[j]->Omega();
51 double phi01 = iptr->Phi0();
52 double phi02 = trkl[j]->Phi0();
53 double d01 = iptr->D0();
54 double d02 = trkl[j]->D0();
55 double prodo = omega1*omega2;
56 if (m_debug) cout << "Try track [" << i << "] and [" << j << "], prodo = " << prodo << endl;
57 // Try to merge pair that looks like duplicates (same charge)
58 if (prodo > 0.0) {
59 if(m_debug) std::cout << " fabs(d01 - d02) " << fabs(d01 - d02) << std::endl;
60 if (fabs(d01 - d02) < MdcxParameters::maxDd0InMerge) {
61 if(m_debug) std::cout << " fabs(phi01-phi02) " << fabs(phi01-phi02) << std::endl;
62 if (fabs(phi01-phi02) < MdcxParameters::maxDphi0InMerge) {
63 double r1=100000.;
64 if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
65 double r2=100000.;
66 if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2); //FIXME
67 double pdrad = fabs((r1-r2)/(r1+r2)) ;
68 if (m_debug) {
69 std::cout << "omega1,r1 " << omega1 << " " << r1
70 << " omega2,r2 " << omega2 << " " << r2
71 << " pdrad " << pdrad << std::endl;
72 }
74 if (iprt)
75 cout << "MdcxMD i j dif " << i << " " << j << " " << d01-d02 << " "
76 << phi01-phi02 << " " << r1 << " " << r2 << " " << pdrad << endl;
77 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
78 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
79 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
80 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
81 dcxhlist.append(dcxh2);
82 dcxhlist.purge();
83 if (iprt) cout << " " << dcxhlist.length() << endl;
84 MdcxFittedHel fit1(dcxhlist, *iptr); // fit1.FitPrint(); fit1.print();
85 MdcxFittedHel fit2(dcxhlist, *trkl[j]); // fit2.FitPrint(); fit2.print();
86 int uf = 0;
87 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1;
88 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
89 if (m_debug) {
90 std::cout << "fit1.Fail() " << fit1.Fail() << " fit1.Rcs " << fit1.Rcs()
91 << " fit2.Fail() " << fit2.Fail() << " fit2.Rcs " << fit2.Rcs()
92 << std::endl;
93 }
94 if (uf) {
95 MdcxHel fitme = (uf == 1) ? fit1 : fit2;
96 MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
97 if (!finehel->Fail()) {
98 if (already_merged) {
99 NewTrklist.replace(iptr, finehel);
100 delete iptr;
101 iptr = finehel;
102 trkl[j]->SetUsedOnHel(already_merged);
103 } else {
104 NewTrklist.append(finehel);
105 already_merged = NewTrklist.length();
106 iptr->SetUsedOnHel(already_merged);
107 iptr = finehel;
108 trkl[j]->SetUsedOnHel(already_merged);
109 }
110 } else {
111 delete finehel;
112 }
113 }
114 }
115 }
116 }
117 }
118
119 // Try to merge pair that looks like albedo (opp charge, large d0)
120 if (prodo < 0.0) {
121 if ((fabs(d01+d02) < 4.0) && (fabs(d01-d02) > 47.0)) { /// FIXME
122 double deltap = fabs( fabs(phi01-phi02) - M_PI );
123 if (deltap < MdcxParameters::maxDphi0InMerge) {
124 double r1=100000.;
125 if (fabs(omega1) > 0.00001) r1 = 1.0/fabs(omega1);
126 double r2=100000.;
127 if (fabs(omega2) > 0.00001) r2 = 1.0/fabs(omega2);
128 double pdrad = fabs((r1-r2)/(r1+r2)) ;
130 if (iprt)
131 cout << "MdcxMD i j sum " << i << " " << j << " " << d01+d02 << " "
132 << deltap << " " << r1 << " " << r2 << " " << pdrad << endl;
133 MdcxHel temp1 = *iptr;
134 //zoujh?: temp1.SetTurnFlag(1);
135 MdcxHel temp2 = *trkl[j];
136 temp2.SetTurnFlag(1);
137 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
138 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
139 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
140 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
141 dcxhlist.append(dcxh2);
142 dcxhlist.purge();
143 if (iprt) cout << " " << dcxhlist.length() << endl;
144 MdcxFittedHel fit1(dcxhlist, temp1); // fit1.FitPrint(); fit1.print();
145 MdcxFittedHel fit2(dcxhlist, temp2); // fit2.FitPrint(); fit2.print();
146 int uf = 0;
147 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1;
148 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
149 if (uf) {
150 MdcxHel fitme = (1 == uf) ? fit1 : fit2;
151 MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
152 if (!finehel->Fail()) {
153 if (already_merged) {
154 NewTrklist.replace(iptr, finehel);
155 delete iptr;
156 iptr = finehel;
157 trkl[j]->SetUsedOnHel(already_merged);
158 } else {
159 NewTrklist.append(finehel);
160 already_merged = NewTrklist.length();
161 iptr->SetUsedOnHel(already_merged);
162 iptr = finehel;
163 trkl[j]->SetUsedOnHel(already_merged);
164 }
165 } else {
166 delete finehel;
167 }
168 }
169 }
170 }
171 }
172 }
173 }//end j loop
174 }//end i loop
175 }
176
177 k = 0;
178 while (trkl[k]) {
179 if (iprt)cout << "In MdcxMD, trk is used on " << k << " " << trkl[k]->GetUsedOnHel() << endl;
180 if (!trkl[k]->GetUsedOnHel()) CleanTrklist.append(trkl[k]);
181 k++;
182 }
183
184 k=0;
185 while (NewTrklist[k]) {
186 if (iprt && m_debug) {
187 NewTrklist[k]->FitPrint();
188 NewTrklist[k]->print();
189 }
190
191 CleanTrklist.append(NewTrklist[k++]);
192 }
193
194 if (iprt) cout << "MdcxMD leaves with " << CleanTrklist.length() << " tracks" << endl;
195}
196
198 KillList();
199}
200
#define M_PI
Definition: TConstant.h:4
float Rcs() const
Definition: MdcxFittedHel.h:46
void SetUsedOnHel(const int &i)
Definition: MdcxFittedHel.h:55
const HepAList< MdcxHit > & XHitList() const
Definition: MdcxFittedHel.h:59
int GetUsedOnHel() const
Definition: MdcxFittedHel.h:56
float Chisq() const
Definition: MdcxFittedHel.h:45
int Fail(float Probmin=0.0) const
double Phi0() const
Definition: MdcxHel.h:54
double D0() const
Definition: MdcxHel.h:53
double Omega() const
Definition: MdcxHel.h:55
void SetTurnFlag(const int &i)
Definition: MdcxHel.h:115
HepAList< MdcxFittedHel > NewTrklist
Definition: MdcxMergeDups.h:36
virtual ~MdcxMergeDups()
MdcxMergeDups(HepAList< MdcxFittedHel > &f, int debug)
HepAList< MdcxFittedHel > CleanTrklist
Definition: MdcxMergeDups.h:37
static const double maxDd0InMerge
static const double maxPdradInMerge
static const double maxRcsInMerge
static const double maxDphi0InMerge