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