BOSS 7.1.2
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.11 2022/07/04 21:28:34 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
30//DECLARE_COMPONENT(MdcxMergeDups)
32 m_debug = (debug == 10);
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 for (int i = 0; i < ntracks-1; i++) {
42 MdcxFittedHel* iptr = trkl[i];
43 int already_merged = 0;
44 if (iptr->GetUsedOnHel()) {
45 already_merged = trkl[i]->GetUsedOnHel();
46 iptr = NewTrklist[already_merged-1];
47 }
48 for (int j = i+1; j < ntracks; j++) {
49 if (trkl[j]->GetUsedOnHel()) continue;
50 double omega1 = iptr->Omega();
51 double omega2 = trkl[j]->Omega();
52 double phi01 = iptr->Phi0();
53 double phi02 = trkl[j]->Phi0();
54 double d01 = iptr->D0();
55 double d02 = trkl[j]->D0();
56 double prodo = omega1*omega2;
57 if (m_debug) cout << "Try track [" << i << "] and [" << j << "], prodo = " << prodo << endl;
58 // Try to merge pair that looks like duplicates (same charge)
59 if (prodo > 0.0) {
60 if(m_debug) std::cout << " fabs(d01 - d02) " << fabs(d01 - d02) << std::endl;
61 if (fabs(d01 - d02) < MdcxParameters::maxDd0InMerge) {
62 if(m_debug) std::cout << " fabs(phi01-phi02) " << fabs(phi01-phi02) << std::endl;
63 if (fabs(phi01-phi02) < MdcxParameters::maxDphi0InMerge) {
64 double r1=100000.;
65 if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
66 double r2=100000.;
67 if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2); //FIXME
68 double pdrad = fabs((r1-r2)/(r1+r2)) ;
69 if (m_debug) {
70 std::cout << "omega1,r1 " << omega1 << " " << r1
71 << " omega2,r2 " << omega2 << " " << r2
72 << " pdrad " << pdrad << std::endl;
73 }
75 if (iprt)
76 cout << "MdcxMD i j dif " << i << " " << j << " " << d01-d02 << " "
77 << phi01-phi02 << " " << r1 << " " << r2 << " " << pdrad << endl;
78 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
79 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
80 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
81 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
82 dcxhlist.append(dcxh2);
83 dcxhlist.purge();
84 if (iprt) cout << " " << dcxhlist.length() << endl;
85 MdcxFittedHel fit1(dcxhlist, *iptr); // fit1.FitPrint(); fit1.print();
86 MdcxFittedHel fit2(dcxhlist, *trkl[j]); // fit2.FitPrint(); fit2.print();
87 int uf = 0;
88 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1;
89 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
90 if (m_debug) {
91 std::cout << "fit1.Fail() " << fit1.Fail() << " fit1.Rcs " << fit1.Rcs()
92 << " fit2.Fail() " << fit2.Fail() << " fit2.Rcs " << fit2.Rcs()
93 << std::endl;
94 }
95 if (uf) {
96 MdcxHel fitme = (uf == 1) ? fit1 : fit2;
97 MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
98 if (!finehel->Fail()) {
99 if (already_merged) {
100 NewTrklist.replace(iptr, finehel);
101 delete iptr;
102 iptr = finehel;
103 trkl[j]->SetUsedOnHel(already_merged);
104 } else {
105 NewTrklist.append(finehel);
106 already_merged = NewTrklist.length();
107 iptr->SetUsedOnHel(already_merged);
108 iptr = finehel;
109 trkl[j]->SetUsedOnHel(already_merged);
110 }
111 } else {
112 delete finehel;
113 }
114 }
115 }
116 }
117 }
118 }
119
120 // Try to merge pair that looks like albedo (opp charge, large d0)
121 if (prodo < 0.0) {
122 if ((fabs(d01+d02) < 4.0) && (fabs(d01-d02) > 47.0)) { /// FIXME
123 double deltap = fabs( fabs(phi01-phi02) - M_PI );
124 if (deltap < MdcxParameters::maxDphi0InMerge) {
125 double r1=100000.;
126 if (fabs(omega1) > 0.00001) r1 = 1.0/fabs(omega1);
127 double r2=100000.;
128 if (fabs(omega2) > 0.00001) r2 = 1.0/fabs(omega2);
129 double pdrad = fabs((r1-r2)/(r1+r2)) ;
131 if (iprt)
132 cout << "MdcxMD i j sum " << i << " " << j << " " << d01+d02 << " "
133 << deltap << " " << r1 << " " << r2 << " " << pdrad << endl;
134 MdcxHel temp1 = *iptr;
135 //zoujh?: temp1.SetTurnFlag(1);
136 MdcxHel temp2 = *trkl[j];
137 temp2.SetTurnFlag(1);
138 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
139 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
140 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
141 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
142 dcxhlist.append(dcxh2);
143 dcxhlist.purge();
144 if (iprt) cout << " " << dcxhlist.length() << endl;
145 MdcxFittedHel fit1(dcxhlist, temp1); // fit1.FitPrint(); fit1.print();
146 MdcxFittedHel fit2(dcxhlist, temp2); // fit2.FitPrint(); fit2.print();
147 int uf = 0;
148 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1;
149 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
150 if (uf) {
151 MdcxHel fitme = (1 == uf) ? fit1 : fit2;
152 MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
153 if (!finehel->Fail()) {
154 if (already_merged) {
155 NewTrklist.replace(iptr, finehel);
156 delete iptr;
157 iptr = finehel;
158 trkl[j]->SetUsedOnHel(already_merged);
159 } else {
160 NewTrklist.append(finehel);
161 already_merged = NewTrklist.length();
162 iptr->SetUsedOnHel(already_merged);
163 iptr = finehel;
164 trkl[j]->SetUsedOnHel(already_merged);
165 }
166 } else {
167 delete finehel;
168 }
169 }
170 }
171 }
172 }
173 }
174 }//end j loop
175 }//end i loop
176 }
177
178 k = 0;
179 while (trkl[k]) {
180 if (iprt)cout << "In MdcxMD, trk is used on " << k << " " << trkl[k]->GetUsedOnHel() << endl;
181 if (!trkl[k]->GetUsedOnHel()) CleanTrklist.append(trkl[k]);
182 k++;
183 }
184
185 k=0;
186 while (NewTrklist[k]) {
187 if (iprt && m_debug) {
188 NewTrklist[k]->FitPrint();
189 NewTrklist[k]->print();
190 }
191
192 CleanTrklist.append(NewTrklist[k++]);
193 }
194
195 if (iprt) cout << "MdcxMD leaves with " << CleanTrklist.length() << " tracks" << endl;
196}
197
201
#define M_PI
Definition TConstant.h:4
float Rcs() const
void SetUsedOnHel(const int &i)
const HepAList< MdcxHit > & XHitList() const
int GetUsedOnHel() const
float Chisq() const
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
virtual ~MdcxMergeDups()
MdcxMergeDups(HepAList< MdcxFittedHel > &f, int debug)
HepAList< MdcxFittedHel > CleanTrklist
static const double maxDd0InMerge
static const double maxPdradInMerge
static const double maxRcsInMerge
static const double maxDphi0InMerge