31 {
33 int iprt = 0;
34 int ntracks = trkl.length();
35 if ( iprt ) cout << "MdcxMergeDups called with " << ntracks << " tracks" << endl;
36 double m_2pi = 2.0 *
M_PI;
37 int k = 0;
38 while ( trkl[k] ) trkl[k++]->SetUsedOnHel( 0 );
39
40 if ( ntracks > 1 )
41 {
42 for ( int i = 0; i < ntracks - 1; i++ )
43 {
44 MdcxFittedHel* iptr = trkl[i];
45 int already_merged = 0;
47 {
48 already_merged = trkl[i]->GetUsedOnHel();
50 }
51 for ( int j = i + 1; j < ntracks; j++ )
52 {
53 if ( trkl[j]->GetUsedOnHel() ) continue;
54 double omega1 = iptr->
Omega();
55 double omega2 = trkl[j]->Omega();
56 double phi01 = iptr->
Phi0();
57 double phi02 = trkl[j]->Phi0();
58 double d01 = iptr->
D0();
59 double d02 = trkl[j]->D0();
60 double prodo = omega1 * omega2;
62 cout << "Try track [" << i << "] and [" << j << "], prodo = " << prodo << endl;
63
64 if ( prodo > 0.0 )
65 {
66 if (
m_debug ) std::cout <<
" fabs(d01 - d02) " << fabs( d01 - d02 ) << std::endl;
68 {
70 std::cout << " fabs(phi01-phi02) " << fabs( phi01 - phi02 ) << std::endl;
72 {
73 double r1 = 100000.;
74 if ( fabs( omega1 ) > 0.00001 ) r1 = 1.0 / fabs( omega1 );
75 double r2 = 100000.;
76 if ( fabs( omega2 ) > 0.00001 ) r2 = 1.0 / fabs( omega2 );
77 double pdrad = fabs( ( r1 - r2 ) / ( r1 + r2 ) );
79 {
80 std::cout << "omega1,r1 " << omega1 << " " << r1 << " omega2,r2 " << omega2
81 << " " << r2 << " pdrad " << pdrad << std::endl;
82 }
84 {
85 if ( iprt )
86 cout << "MdcxMD i j dif " << i << " " << j << " " << d01 - d02 << " "
87 << phi01 - phi02 << " " << r1 << " " << r2 << " " << pdrad << endl;
88 HepAList<MdcxHit> dcxhlist = iptr->
XHitList();
89 if ( iprt ) cout <<
"MdcxMD " << dcxhlist.length() <<
" " << iptr->
Chisq();
90 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
91 if ( iprt ) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
92 dcxhlist.append( dcxh2 );
93 dcxhlist.purge();
94 if ( iprt ) cout << " " << dcxhlist.length() << endl;
95 MdcxFittedHel fit1( dcxhlist, *iptr );
96 MdcxFittedHel fit2( dcxhlist, *trkl[j] );
97 int uf = 0;
99 if ( !fit2.Fail() && ( fit2.Rcs() < fit1.Rcs() ) ) uf = 2;
101 {
102 std::cout << "fit1.Fail() " << fit1.Fail() << " fit1.Rcs " << fit1.Rcs()
103 << " fit2.Fail() " << fit2.Fail() << " fit2.Rcs " << fit2.Rcs()
104 << std::endl;
105 }
106 if ( uf )
107 {
108 MdcxHel fitme = ( uf == 1 ) ? fit1 : fit2;
109 MdcxFittedHel* finehel = new MdcxFittedHel( dcxhlist, fitme );
110 if ( !finehel->
Fail() )
111 {
112 if ( already_merged )
113 {
115 delete iptr;
116 iptr = finehel;
118 }
119 else
120 {
124 iptr = finehel;
126 }
127 }
128 else { delete finehel; }
129 }
130 }
131 }
132 }
133 }
134
135
136 if ( prodo < 0.0 )
137 {
138 if ( ( fabs( d01 + d02 ) < 4.0 ) && ( fabs( d01 - d02 ) > 47.0 ) )
139 {
140 double deltap = fabs( fabs( phi01 - phi02 ) -
M_PI );
142 {
143 double r1 = 100000.;
144 if ( fabs( omega1 ) > 0.00001 ) r1 = 1.0 / fabs( omega1 );
145 double r2 = 100000.;
146 if ( fabs( omega2 ) > 0.00001 ) r2 = 1.0 / fabs( omega2 );
147 double pdrad = fabs( ( r1 - r2 ) / ( r1 + r2 ) );
149 {
150 if ( iprt )
151 cout << "MdcxMD i j sum " << i << " " << j << " " << d01 + d02 << " "
152 << deltap << " " << r1 << " " << r2 << " " << pdrad << endl;
153 MdcxHel temp1 = *iptr;
154
155 MdcxHel temp2 = *trkl[j];
157 HepAList<MdcxHit> dcxhlist = iptr->
XHitList();
158 if ( iprt ) cout <<
"MdcxMD " << dcxhlist.length() <<
" " << iptr->
Chisq();
159 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
160 if ( iprt ) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
161 dcxhlist.append( dcxh2 );
162 dcxhlist.purge();
163 if ( iprt ) cout << " " << dcxhlist.length() << endl;
164 MdcxFittedHel fit1( dcxhlist, temp1 );
165 MdcxFittedHel fit2( dcxhlist, temp2 );
166 int uf = 0;
168 if ( !fit2.Fail() && ( fit2.Rcs() < fit1.Rcs() ) ) uf = 2;
169 if ( uf )
170 {
171 MdcxHel fitme = ( 1 == uf ) ? fit1 : fit2;
172 MdcxFittedHel* finehel = new MdcxFittedHel( dcxhlist, fitme );
173 if ( !finehel->
Fail() )
174 {
175 if ( already_merged )
176 {
178 delete iptr;
179 iptr = finehel;
181 }
182 else
183 {
187 iptr = finehel;
189 }
190 }
191 else { delete finehel; }
192 }
193 }
194 }
195 }
196 }
197 }
198 }
199 }
200
201 k = 0;
202 while ( trkl[k] )
203 {
204 if ( iprt )
205 cout << "In MdcxMD, trk is used on " << k << " " << trkl[k]->GetUsedOnHel() << endl;
206 if ( !trkl[k]->GetUsedOnHel() )
CleanTrklist.append( trkl[k] );
207 k++;
208 }
209
210 k = 0;
212 {
214 {
217 }
218
220 }
221
222 if ( iprt ) cout <<
"MdcxMD leaves with " <<
CleanTrklist.length() <<
" tracks" << endl;
223}
void SetUsedOnHel(const int &i)
const HepAList< MdcxHit > & XHitList() const
int Fail(float Probmin=0.0) const
void SetTurnFlag(const int &i)
HepAList< MdcxFittedHel > CleanTrklist
HepAList< MdcxFittedHel > NewTrklist
static const double maxDd0InMerge
static const double maxPdradInMerge
static const double maxRcsInMerge
static const double maxDphi0InMerge