BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcSegGrouperSt.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcSegGrouperSt.cxx,v 1.14 2011/09/26 01:06:37 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Authors:
12// Zhang Yao([email protected]) Migrate to BESIII
13//
14// Copyright (C) 1996 The Board of Trustees of
15// The Leland Stanford Junior University. All Rights Reserved.
16//------------------------------------------------------------------------
17#include "MdcGeom/BesAngle.h"
18#include "MdcData/MdcHit.h"
19#include "CLHEP/Alist/AList.h"
20#include "MdcGeom/MdcDetector.h"
21#include "MdcGeom/MdcSuperLayer.h"
22#include "MdcTrkRecon/MdcSeg.h"
23#include "MdcTrkRecon/MdcSegGrouperSt.h"
24#include "MdcTrkRecon/MdcSegList.h"
25#include "MdcTrkRecon/MdcSegInfoSterO.h"
26#include "MdcTrkRecon/MdcSegWorks.h"
27#include "MdcTrkRecon/MdcSegUsage.h"
28#include "MdcTrkRecon/MdcTrack.h"
29#include "MdcTrkRecon/GmsList.h"
30#include "TrkBase/TrkExchangePar.h"
31#include "TrkBase/TrkRecoTrk.h"
32#include "TrkBase/TrkFit.h"
33#include "TrkFitter/TrkHelixMaker.h"
34
35//yzhang hist cut
36#include "AIDA/IHistogram1D.h"
37extern AIDA::IHistogram1D* g_z0Cut;
38extern AIDA::IHistogram1D* g_ctCut;
39extern AIDA::IHistogram1D* g_delCt;
40extern AIDA::IHistogram1D* g_delZ0;
41//zhangy hist cut
42
43//Constructor
44//------------------------------------------------------------------------
46 MdcSegGrouper(gm, gm->nStereoSuper(-1) + gm->nStereoSuper(1), debug) {
47//------------------------------------------------------------------------
48
49 lTestGroup = true;
50 lTestSingle = false;
51
52 isValid = new bool * [nPly()];
53 for (int j = 0; j < nPly(); j++) {
54 isValid[j] = 0;
55 }
56 }
57
58//------------------------------------------------------------------------
59void MdcSegGrouperSt::resetList() {
60//------------------------------------------------------------------------
61 // Clear existing lists for stereo finding
62 int nsuper = _gm->nSuper();
63 for (int i = 0; i < nsuper; i++) {
64 segList[i].removeAll();
65 }
66}
67
68//------------------------------------------------------------------------
70 const MdcTrack *track) {
71 //------------------------------------------------------------------------
72 // Prepare for stereo finding
73 // Load segments consistent with input track (already in phi order)
74 // Assuming from origin
75 int nsuper = _gm->nSuper();
76 resetList(); // Clear existing lists
77 if(3==_debug) std::cout<<std::endl<< "=====MdcSegGrouperSt::fillWithSegs====="<<std::endl;
78
79 const TrkFit* tkFit = track->track().fitResult();
80 if (tkFit == 0) return;
81 TrkExchangePar par = tkFit->helix(0.0);
82 double kap = 0.5 * par.omega();
83 double phi0 = par.phi0();
84 double d0 = par.d0();
85 MdcSegWorks segStuff; // holds some calculated values to pass to segInfo
86
87 bool lStraight = false;
88 if (fabs(kap) < 1.e-9) { lStraight = true; }
89
90 double rCurl = 99999999.;
91 if (!lStraight) {
92 rCurl = fabs(d0 + 1./kap);
93 }
94
95 // Create an info object to store the info (will be owned by seg)
97
98 // Loop over superlayers
99 for (int isuper = 0; isuper < nsuper; isuper++) {
100 const GmsList *inList = inSegs->oneList(isuper);
101
102 if (inList->count() == 0) continue;
103
104 MdcSeg *inSeg = (MdcSeg *) inList->first();
105 // Only load stereo segments
106 if (inSeg->superlayer()->whichView() == 0) continue;
107
108 // Calculate r & phi (approx) of axial track at slayer
109 double radius = inSeg->superlayer()->rEnd();
110 if (radius >= rCurl) break;
111 double phiArg = kap * radius;
112 if (lStraight) phiArg = d0 / radius;
113 if (phiArg < -1.0) phiArg = -1.0;
114 else if (phiArg > 1.0) phiArg = 1.0;
115 segStuff.phiArg = phiArg;
116 segStuff.phiAx.setRad(phi0 + asin(phiArg)); // Approx??!!!!
117 BesAngle delPhi( fabs(inSeg->superlayer()->delPhi()) );
118 //BesAngle maxPhiA = segStuff.phiAx + delPhi + 0.05; // allow a little slop
119 //BesAngle minPhiA = segStuff.phiAx - delPhi - 0.05;
120 BesAngle maxPhiA = segStuff.phiAx + delPhi + 0.1; // allow a little slop yzhang 2011-06-15
121 BesAngle minPhiA = segStuff.phiAx - delPhi - 0.1;//yzhang TEMP 2011-06-15
122 //yzhang FIXME
123 double maxPhi = maxPhiA;
124 double minPhi = minPhiA;
125 bool phitest = (maxPhi > minPhi);
126 //phitest = false => the valid range straddles phi = 0, so skip
127 //checking against phimin and phimax
128
129 //Calc some things needed in segInfo::calcStereo
130 segStuff.wirLen2inv = 1./ (inSeg->superlayer()->zEnd() *
131 inSeg->superlayer()->zEnd() );
132 // Loop over segs in superlayer
133 if(_debug==3) std::cout<<std::endl<<"Pick segment by phi from " <<minPhi<< " to "<<maxPhi<<" phiAx="<<segStuff.phiAx<<" delPhi="<<delPhi<<std::endl;
134 for ( ; inSeg != 0; inSeg = (MdcSeg *) inSeg->next()) {
135 // Test if within allowed phi range
136 BesAngle phiSeg(inSeg->phi());
137
138 if(_debug==3){ inSeg->plotSeg(); }
139 if (phitest) {
140 if (phiSeg < minPhi){
141 if (_debug ==3){std::cout << " CUT by phi "<<phiSeg
142 << "<min "<<minPhi << std::endl;}//yzhang debug
143 continue; // not up to candidates
144 }
145 else if(phiSeg > maxPhi) {
146 if (_debug ==3){std::cout << " CUT by phi "<<phiSeg
147 <<">max "<<maxPhi<< std::endl;}//yzhang debug
148 break; // past candidates
149 }
150 } else { // !phitest
151 if (phiSeg > maxPhi && phiSeg < minPhi) {
152 if (_debug ==3){std::cout << "!phitest "<<phiSeg
153 <<" max "<<maxPhi<< " min "<<minPhi << std::endl;}//yzhang debug
154 continue;
155 }
156 }
157
158 if(_debug == 3) std::cout<<" **KEEP seg phi="<<phiSeg<< std::endl;
159
160 //std::cout<< __FILE__ << " " << __LINE__ << " MdcSegGrouperSt::fillWithSegs call calcStereo "<<std::endl;
161 int isBad = info->calcStereo(inSeg, track->track(), segStuff);
162
163 if (isBad) {
164 if (_debug ==3){std::cout << " CUT by calcStereo isBad!"<<std::endl;}
165 continue;
166 }
167 // Test for sensible values of ct and z0
168 if (g_z0Cut) {g_z0Cut->fill(info->z0());}
169 if (g_ctCut) {g_ctCut->fill(info->ct());}
170 if (fabs(info->ct()) > inSeg->segPar()->ctcut) {
171 if (_debug ==3){std::cout << " CUT by ctcut! "
172 <<fabs(info->ct())<<" > cut:"<< inSeg->segPar()->ctcut<<" "<<phiSeg<<std::endl; }
173 continue;
174 }
175 if (fabs(info->z0()) > inSeg->segPar()->z0cut){
176 if (_debug ==3){std::cout << " CUT by z0cut! "
177 <<fabs(info->z0())<<" >cut "<< inSeg->segPar()->z0cut<<" "<<phiSeg<<std::endl; }
178 continue;
179 }
180 inSeg->setInfo(info);
181 info = new MdcSegInfoSterO;
182 segList[isuper].append(inSeg);
183 //if(_debug==3)std::cout<<" APPEND this stereo seg"<< std::endl;
184
185 } // end loop over new segs
186 } // end loop over superlayers
187 delete info;
188}
189
190//-------------------------------------------------------------------------
192 //-------------------------------------------------------------------------
193 int nsuper = _gm->nSuper();
194 int isuper;
195 /*
196 for (isuper = 0; isuper < nsuper; isuper++) {
197 if (segList[isuper].length() == 0) continue;
198
199 MdcSeg *inSeg = (MdcSeg *) segList[isuper].first();
200 // Only draw stereo segments
201 if (inSeg->superlayer()->whichView() == 0) continue;
202 for (int j = 0 ; j < (int) segList[isuper].length(); j++) {
203 segList[isuper][j]->plotSeg(0,orange);
204 }
205 }
206 */
207 for (isuper = 0; isuper < nsuper; isuper++) {
208 if (segList[isuper].length() == 0) continue;
209
210 MdcSeg *inSeg = (MdcSeg *) segList[isuper].first();
211 // Only draw stereo segments
212 //if (inSeg->superlayer()->whichView() == 0) continue;
213 for (int j = 0 ; j < (int) segList[isuper].length(); j++) {
214 segList[isuper][j]->plotSeg();
215 }
216 }
217
218}
219//-------------------------------------------------------------------------
221 const MdcSeg *testSeg) {
222 //-------------------------------------------------------------------------
223
224 return 0;
225}
226
227//-------------------------------------------------------------------------
228int MdcSegGrouperSt::incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg,
229 int iply) {
230 //-------------------------------------------------------------------------
231 // Test that the latest seg lies more or less in a line with the others
232 // Currently requiring line to point to IP; also require rough
233 // agreement in ct.
234 // iply = depth index of current seg (not yet in group)
235
236 int i;
237 // Find first segment already in group
238 for (i = iply - 1; i > 0; i--) {
239 if (!leaveGap[i]) break;
240 }
241 const MdcSeg *first = (*combList[i])[currentSeg[i]];
242
243 // Test ct
244 MdcSegInfoSterO* firstInfo = (MdcSegInfoSterO *) first->info();
245 MdcSegInfoSterO* newInfo = (MdcSegInfoSterO *) testSeg->info();
246
247 if (g_delCt) {g_delCt->fill( firstInfo->ct() - newInfo->ct());}//yzhang hist cut
248 if (fabs( firstInfo->ct() - newInfo->ct() ) >
249 testSeg->segPar()->delCtCut) {
250 if(_debug==3){
251 cout << "---MdcSegGrouperSt Ct CUT!" << endl;//yzhang debug
252 std::cout<<"first:"; first->plotSeg(); std::cout<<std::endl;
253 std::cout<<"test:"; testSeg->plotSeg();std::cout<<std::endl;
254 std::cout << "first.ct "<< firstInfo->ct()
255 <<" test.ct "<<newInfo->ct()
256 <<" delta ct "<<firstInfo->ct() - newInfo->ct()
257 <<" Cut "<<testSeg->segPar()->delCtCut << std::endl;//yzhang debug
258
259 std::cout<<"--- "<< std::endl;
260 }
261 return -1;
262 }else{
263 }
264
265 double arcFirst = firstInfo->arc();
266 double arcNew = newInfo->arc();
267 double zFirst = firstInfo->z0() + firstInfo->ct() * arcFirst;
268 double zNew = newInfo->z0() + newInfo->ct() * arcNew;
269 // project line from IP through 1st seg to new seg
270 double zProj = zFirst / arcFirst * arcNew;
271 if (g_delZ0) {g_delZ0->fill( zProj - zNew);}//yzhang hist cut
272
273 if (fabs(zProj - zNew) > testSeg->segPar()->delZ0Cut) {
274 if(3==_debug){
275 cout << "MdcSegGrouperSt delZ0Cut not incompWithGroup CUT!" << endl;//yzhang debug
276 testSeg->plotSeg();
277 std::cout<<" zProj "<< zProj << " zNew "<< zNew<< " CUT! "
278 << testSeg->segPar()->delZ0Cut << std::endl;
279 }
280 return -1;
281 }
282
283 /*
284 double delZ = newInfo->z0() + newInfo->ct() * arcNew - zFirst;
285 double z0 = zFirst - arcFirst * delZ / (arcNew - arcFirst);
286 if (fabs(z0) > testSeg->segPar()->delZ0Cut)return -1;
287
288 for (i = iply - 1; i > 0; i--) {
289 if (segGroup[i] != 0) break;
290 }
291 const MdcSeg *last = segGroup[i];
292 MdcSegInfoSterO* lastInfo = (MdcSegInfoSterO *) last->info();
293
294 // Test that slope from last segment to new one is roughly = slope from
295 // first seg to last
296 double arcLast = lastInfo->arc();
297 double arcFirst = firstInfo->arc();
298 double arcNew = newInfo->arc();
299
300 double delZold = lastInfo->z0() - firstInfo->z0() +
301 lastInfo->ct() * arcLast - firstInfo->ct() * arcFirst;
302 double delArcold = arcLast - arcFirst;
303 double delZnew = newInfo->z0() - lastInfo->z0() +
304 newInfo->ct() * arcNew - lastInfo->ct() * arcLast;
305 double delArcnew = arcNew - arcLast;
306 double p1 = delZold * delArcnew;
307 double p2 = delZnew * delArcold;
308
309 cout << " test: " << p1 << " " << p2 << endl;
310
311 if (fabs(p2 - p1) > 0.02) return -1;
312
313*/
314 return 0;
315}
316
317//**************************************************************************
319 //**************************************************************************
320
321 // Delete existing list of valid/invalid segs
322 if (isValid != 0) {
323 int i;
324 for (i = 0; i < nDeep; i++) {
325 delete [] isValid[i];
326 isValid[i] = 0;
327 }
328 }
329
330 //Grab the seglist for each slayer
331 int islay = 0;
332 int iply = 0;
333 nPlyFilled = 0;
334 nNull = 0;
335
336
337 // Set up all sorts of stuff for fast grouping of segs in nextGroup()
338 for (const MdcSuperLayer *thisSlay = _gm->firstSlay(); thisSlay != 0;
339 thisSlay = thisSlay->next()) {
340 //bool noGoodYet = true;
341 islay++;
342 if (thisSlay->whichView() == 0) continue;
343 firstGood[iply] = 0;
344 firstBad[iply] = segList[islay-1].length();
345 if (firstGood[iply] > firstBad[iply]) firstGood[iply] = firstBad[iply];
346 if (firstGood[iply] == firstBad[iply]) {
347 // If there are no valid segs for this ply, skip it
348 continue;
349 }
350 // Associate correct seglist with this ply
351 combList[iply] = &segList[islay-1];
352 leaveGap[iply] = false;
353 iply++;
354 }
355
356 nPlyFilled = iply;
358 maxNull = nPlyFilled - 2;
359}
360
361//---------------------------------------------------------------------
363 double chisq,
364 TrkContext&, double) {
365 //---------------------------------------------------------------------
366 assert (trk != 0);
367 TrkHelixMaker maker;
368 if(3==_debug) std::cout<< "-----storePar z0 "<<parms[0]<<" ct "<<parms[1]<<std::endl;
369 maker.addZValues(trk->track(), parms[0], parms[1], chisq);
370 return trk;
371}
372
const MdcSuperLayer * firstSlay(void) const
void fillWithSegs(const MdcSegList *inSegs, const MdcTrack *axialTrack)
virtual int incompWithSeg(const MdcSeg *refSeg, const MdcSeg *testSeg)
virtual int incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg, int iply)
void resetComb(const MdcSeg *seed=0)
MdcSegGrouperSt(const MdcDetector *gm, int debug)
virtual MdcTrack * storePar(MdcTrack *trk, double parms[2], double chisq, TrkContext &, double trackT0)
void plotStereo() const
void resetSegCounters()
int calcStereo(MdcSeg *parentSeg, const TrkRecoTrk &track, MdcSegWorks &segStuff)
const GmsList * oneList(int slayIndex) const
Definition: MdcSegList.cxx:412
const MdcSuperLayer * superlayer() const
void plotSeg() const
Definition: MdcSeg.cxx:194
void setInfo(MdcSegInfo *ptr)
Definition: MdcSeg.cxx:96
const MdcSuperLayer * next(void) const
virtual TrkExchangePar helix(double fltL) const =0
void addZValues(TrkRecoTrk &theTrack, double z0, double tanDip, double chi2)
const TrkFit * fitResult() const
Definition: TrkRecoTrk.cxx:387