BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcSegGrouperAx.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcSegGrouperAx.cxx,v 1.13 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/MdcSegGrouperAx.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/MdcSegInfoAxialO.h"
26#include "MdcTrkRecon/MdcSegList.h"
27#include "MdcTrkRecon/MdcSegUsage.h"
28#include "MdcTrkRecon/MdcTrack.h"
29#include "MdcTrkRecon/mdcWrapAng.h"
30#include "TrkBase/TrkExchangePar.h"
31extern double MdcTrkReconCut_combAxPhi0;
32extern double MdcTrkReconCut_combAxCurv;
35
36// tuple item of combine ax segs
37#include "GaudiKernel/NTuple.h"
38extern NTuple::Tuple* g_tupleCombAx;
39extern NTuple::Item<double> g_combAxdPhi0;
40extern NTuple::Item<double> g_combAxdCurv;
41extern NTuple::Item<double> g_combAxSigPhi0;
42extern NTuple::Item<double> g_combAxSigCurv;
43extern NTuple::Item<double> g_combAxSlSeed;
44extern NTuple::Item<double> g_combAxSlTest;
45extern NTuple::Item<double> g_combAxQualitySeed;
46extern NTuple::Item<double> g_combAxQualityTest;
47extern NTuple::Item<double> g_combAxPatSeed;
48extern NTuple::Item<double> g_combAxPatTest;
49extern NTuple::Item<double> g_combAxNhitSeed;
50extern NTuple::Item<double> g_combAxNhitTest;
51extern NTuple::Item<double> g_combAxMc;
52extern NTuple::Item<double> g_combAxMcPt;
53extern NTuple::Item<double> g_combAxMcTheta;
54extern NTuple::Item<double> g_combAxMcPhi;
55extern NTuple::Item<double> g_combAxMcAmbigSeed;
56extern NTuple::Item<double> g_combAxMcAmbigTest;
57
58// Constructor
59//------------------------------------------------------------------------
61 : MdcSegGrouper( gm, gm->nAxialSuper() - 1, debug ) {
62 //------------------------------------------------------------------------
63 lTestGroup = false;
64 lTestSingle = true;
65
66 isValid = new bool*[nPly()];
67 for ( int j = 0; j < nPly(); j++ ) { isValid[j] = 0; }
68}
69
70//------------------------------------------------------------------------
72 //------------------------------------------------------------------------
73 if ( 3 == _debug )
74 std::cout << std::endl << "=====MdcSegGrouperAx::fillWithSegs=====" << std::endl;
75 // Prepare for axial finding
76 // Store the segments (pointers, actually), sorting by phi0
77 for ( int isuper = 0; isuper < _gm->nSuper(); isuper++ )
78 {
79 const GmsList* inList = inSegs->oneList( isuper );
80 if ( inList->count() == 0 ) continue;
81 MdcSeg* inSeg = (MdcSeg*)inList->first();
82 // Only load axial segments
83 if ( inSeg->superlayer()->whichView() != 0 ) continue;
84
85 while ( inSeg != 0 )
86 {
87 // Create an info object within the seg to store info
89 inSeg->setInfo( info );
90 info->calcFromOrigin( inSeg ); // calc. origin-dependent info
91
92 // Loop over the segs already stored, looking for the right place
93 // to stick the new one
94 int isInserted = 0;
95 for ( int iseg = 0; iseg < (int)segList[isuper].length(); iseg++ )
96 {
97 MdcSeg* aSeg = segList[isuper][iseg];
98 if ( ( (MdcSegInfoAxialO*)aSeg->info() )->phi0() < info->phi0() ) { continue; }
99 segList[isuper].insert( inSeg, iseg );
100 isInserted = 1;
101 break;
102 } // end of loop over existing segs
103 if ( isInserted == 0 ) segList[isuper].append( inSeg );
104 inSeg = (MdcSeg*)inSeg->next();
105 } // end loop over new segs
106 // cout<<"segList["<<isuper<<"].length"<< segList[isuper].length()<<endl;//yzhang debug
107 } // end loop over superlayers
108
109 /////////////////////
110 /* for(int isuper = 0; isuper < _gm->nSuper(); isuper++) {
111 std::cout<<"-------super layer "<<isuper<<std::endl;
112 for (int iseg = 0; iseg < (int) segList[isuper].length(); iseg++) {
113 MdcSeg *aSeg = segList[isuper][iseg];
114 std::cout << " seg phi "<<iseg<< "
115 "<<((MdcSegInfoAxialO*)aSeg->info())->phi0()<<std::endl; } // end of loop over existing
116 segs
117 }
118
119 */
120}
121
122//-------------------------------------------------------------------------
123int MdcSegGrouperAx::incompWithSeg( const MdcSeg* refSeg, const MdcSeg* testSeg ) {
124 //-------------------------------------------------------------------------
125
126 // Returns 0 if valid, -1 if invalid, +1 if invalid and no more valid
127 // ones possible in this slayer (assumes they're ordered)
128 if ( testSeg == 0 ) return 0;
129 if ( 3 == _debug )
130 {
131 // std::cout<< "test seg:";
132 testSeg->plotSegAll();
133 }
134 // Test phi0 match
135 MdcSegInfoAxialO* refInfo = (MdcSegInfoAxialO*)refSeg->info();
136 MdcSegInfoAxialO* testInfo = (MdcSegInfoAxialO*)testSeg->info();
137
138 double sigPhi0 =
139 ( refInfo->sigPhi0() > testInfo->sigPhi0() ? refInfo->sigPhi0() : testInfo->sigPhi0() );
140 double refPhi0 = refInfo->phi0();
141 double testPhi0 = testInfo->phi0();
142 double corrPhi0 = mdcWrapAng( refPhi0, testPhi0 );
143
144 double sigCurv =
145 ( refInfo->sigCurv() > testInfo->sigCurv() ? refInfo->sigCurv() : testInfo->sigCurv() );
146 double refCurv = refInfo->curv();
147 double testCurv = testInfo->curv();
148 // double nSigmaPhi0 = MdcTrkReconCut_combAxPhi0;//4. for default
149 // double nSigmaCurv = MdcTrkReconCut_combAxCurv;//4. for default
150 double phi0Cut = MdcTrkReconCut_combAxPhi0Cut;
151 double curvCut = MdcTrkReconCut_combAxCurvCut;
152 // std::cout << "test phi0 "<<corrPhi0<<" ref "<<refPhi0<<" sig "<< nSigmaPhi0 * sigPhi0 <<
153 // std::endl; std::cout << "test Curv "<<testCurv<<" ref "<<refCurv<<" sig "<< nSigmaCurv *
154 // sigCurv << std::endl;
155
156 if ( g_tupleCombAx )
157 {
158 g_combAxdPhi0 = refPhi0 - corrPhi0;
159 g_combAxdCurv = refCurv - testCurv;
161 refSeg->quality() + refSeg->nHit() * 10 + refSeg->superlayer()->slayNum() * 1000;
163 testSeg->quality() + testSeg->nHit() * 10 + testSeg->superlayer()->slayNum() * 1000;
166 g_combAxMc = refSeg->testCombSeg( testSeg );
167 g_combAxMcPt = refSeg->testCombSegPt();
169 // g_combAxSigPhi0 = sigPhi0;
170 // g_combAxSigCurv = sigCurv;
171 // g_combAxSlSeed = refSeg->superlayer()->slayNum();
172 // g_combAxSlTest = testSeg->superlayer()->slayNum();
173 // g_combAxPatSeed = refSeg->segPattern();
174 // g_combAxPatTest = testSeg->segPattern();
175 // g_combAxNhitSeed = refSeg->nHit();
176 // g_combAxNhitTest = testSeg->nHit();
177 // test if the combined segments in the same track
178 // return -1:seed false
179 // return value = n hits on the seed track/ n hits of test seg
180 // g_combAxMcPhi = refSeg->testCombSegPhi();
181 // std::cout<< "mc seg "<< refSeg->testCombSeg(testSeg) << std::endl;//yzhang debug
182 g_tupleCombAx->write();
183 }
184
185 // yzhang add 2009-10-16
186 // if (refPhi0 - corrPhi0 > nSigmaPhi0 * sigPhi0)
187 // if(3 == _debug){
188 // std::cout << " phi0 ref"<<refPhi0
189 // <<" corr "<<corrPhi0
190 // << " diff "<<fabs(corrPhi0-refPhi0)
191 // <<" >? "<<phi0Cut<<std::endl;
192 // std::cout << " curv ref"<<refCurv
193 // <<" test "<<testCurv<< " diff "<<refCurv-testCurv
194 // <<" >? "<<curvCut<< std::endl;
195 // }
196 if ( refSeg->testCombSegPt() > 0.4 && fabs( corrPhi0 - refPhi0 ) > 0.4 &&
197 ( refSeg->testCombSeg( testSeg ) > 0.5 ) )
198 {
199 if ( 3 == _debug )
200 {
201 std::cout << endl << " test " << std::endl;
202 std::cout << "seed seg: ";
203 refSeg->plotSegAll();
204 std::cout << std::endl;
205 std::cout << "test seg: ";
206 testSeg->plotSegAll();
207 std::cout << std::endl;
208 std::cout << " dPhi0 abnormal " << corrPhi0 - refPhi0 << std::endl;
209 }
210 }
211 else
212 {
213 if ( 3 == _debug )
214 {
215 std::cout << endl << " test " << std::endl;
216 std::cout << "seed seg: ";
217 refSeg->plotSegAll();
218 std::cout << std::endl;
219 std::cout << "test seg: ";
220 testSeg->plotSegAll();
221 std::cout << std::endl;
222 std::cout << " dPhi0 ok " << setprecision( 3 ) << corrPhi0 - refPhi0 << std::endl;
223 }
224 }
225
226 // std::cout<< __FILE__ << " " << __LINE__ << " dphi0= "<<fabs(corrPhi0 - refPhi0)<<" mc
227 // "<<refSeg->testCombSeg(testSeg)<<std::endl;
228
229 // cout << setiosflags( ios::fixed );
230 // FIXME 2011-05-31 yzhang cut vs pt
231 if ( fabs( corrPhi0 - refPhi0 ) > phi0Cut )
232 {
233 if ( 3 == _debug )
234 std::cout << " SKIP by dPhi0 " << fabs( corrPhi0 - refPhi0 ) << ">" << phi0Cut
235 << std::endl;
236 // yzhang delete
237 // if (testPhi0 > refPhi0) return 1;
238 // else
239 return -1; // => testPhi0>2pi & refPhi0<2pi
240 }
241 else
242 {
243 if ( 3 == _debug )
244 std::cout << " dphi " << setprecision( 3 ) << fabs( corrPhi0 - refPhi0 );
245 }
246
247 // Test curvature match
248 // use larger error of the two
249 // if (fabs(refCurv - testCurv) > nSigmaCurv * sigCurv)
250 if ( fabs( refCurv - testCurv ) > curvCut )
251 {
252 if ( 3 == _debug )
253 std::cout << " SKIP by dCurv" << fabs( refCurv - testCurv ) << ">" << curvCut
254 << std::endl;
255 return -2;
256 }
257 else
258 {
259 if ( 3 == _debug )
260 std::cout << " dCurv " << setprecision( 3 ) << fabs( refCurv - testCurv );
261 }
262 if ( 3 == _debug ) std::cout << " KEEP " << std::endl;
263
264 cout << resetiosflags( std::ios::floatfield );
265 return 0;
266}
267
268//-------------------------------------------------------------------------
269int MdcSegGrouperAx::incompWithGroup( MdcSeg** segGroup, const MdcSeg* testSeg, int iply ) {
270 //-------------------------------------------------------------------------
271
272 return 0;
273}
274
275//-------------------------------------------------------------------------
277 //-------------------------------------------------------------------------
278
279 // Delete existing list of valid/invalid segs
280 if ( isValid != 0 )
281 {
282 int i;
283 for ( i = 0; i < nDeep; i++ )
284 {
285 delete[] isValid[i];
286 isValid[i] = 0;
287 }
288 }
289
290 _seed = seed;
291 // Grab the seglist for each non-seed slayer
292 int islay = 0;
293 int iply = 0;
294 nPlyFilled = 0;
295 nNull = 0;
296 const MdcSuperLayer* seedSlay = 0;
297 if ( seed != 0 ) seedSlay = seed->superlayer();
298
299 // Set up all sorts of stuff for fast grouping of segs in nextGroup()
300 for ( const MdcSuperLayer* thisSlay = _gm->firstSlay(); thisSlay != 0;
301 thisSlay = thisSlay->next() )
302 {
303 bool noGoodYet = true;
304 islay++;
305
306 if ( thisSlay == seedSlay ) continue;
307 if ( thisSlay->whichView() != 0 ) continue; // Axial slayer
308 firstGood[iply] = 0;
309
310 // Loop over the segs, marking start & end of valid region for this seed
311 firstBad[iply] = 0;
312 if ( segList[islay - 1].length() != 0 )
313 { isValid[iply] = new bool[segList[islay - 1].length()]; }
314
315 if ( 3 == _debug && segList[islay - 1].length() > 0 )
316 {
317 std::cout << std::endl
318 << "--match axial seg by phi in slayer " << thisSlay->slayNum() << "--"
319 << std::endl;
320 // std::cout<< "reference seg: "; seed->plotSeg();
321 // std::cout<< std::endl;
322 }
323
324 for ( int i = 0; i < (int)segList[islay - 1].length(); i++ )
325 {
326 MdcSeg* aSeg = segList[islay - 1][i];
327 int invalid = incompWithSeg( seed, aSeg );
328 isValid[iply][i] = true;
329 if ( invalid < 0 )
330 {
331 firstBad[iply] = i;
332 isValid[iply][i] = false;
333 if ( noGoodYet ) firstGood[iply] = i + 1;
334 }
335 else if ( invalid > 0 )
336 {
337 // No more valid segs in this slayer
338 firstBad[iply] = i;
339 for ( int j = i; j < (int)segList[islay - 1].length(); j++ ) isValid[iply][j] = false;
340 break;
341 }
342 else
343 {
344 firstBad[iply] = i + 1;
345 noGoodYet = false;
346 }
347 }
348
349 // if(3 == _debug) std::cout<<iply<<" islay "<<islay<<" firstGood "<<firstGood[iply]<<"
350 // "<<firstBad[iply]<< std::endl;
351 if ( firstGood[iply] > firstBad[iply] ) firstGood[iply] = firstBad[iply];
352 if ( firstGood[iply] == firstBad[iply] )
353 {
354 // If there are no valid segs for this ply, drop it
355 delete[] isValid[iply];
356 isValid[iply] = 0;
357 continue;
358 }
359 // Associate correct seglist with this ply
360 combList[iply] = &segList[islay - 1];
361 leaveGap[iply] = false;
362 iply++;
363 }
364 nPlyFilled = iply;
366 maxNull = nPlyFilled - 2;
367 maxNull++;
368}
369//---------------------------------------------------------------------
370MdcTrack* MdcSegGrouperAx::storePar( MdcTrack* trk, double parms[2], double chisq,
371 TrkContext& context, double t0 ) {
372 //---------------------------------------------------------------------
373 // cout << "storePar in MdcSegGrouperAx" <<endl;//yzhang debug
374 assert( trk == 0 );
375 BesAngle foundPhi0( parms[0] );
376 // factor of two to convert to BaBar def of curvature (omega)
377 // std::cout<< "stored par " << parms[0]<< " "<<parms[1]
378 //<<" store: "<<foundPhi0.rad()<<" "<<2.*parms[1]<<std::endl;
379 TrkExchangePar par( 0.0, foundPhi0.rad(), 2. * parms[1], 0.0, 0.0 );
380 return new MdcTrack( _gm->nSuper(), par, chisq, context, t0 );
381}
382
383/*
384 double MdcSegGrouperAx::calcParByHits(MdcSeg **segGroup, int nToUse, const TrkExchangePar
385 &par, double param[2]) { return 0.;
386 }
387 */
NTuple::Item< double > g_combAxMcPt
NTuple::Item< double > g_combAxSlTest
NTuple::Item< double > g_combAxQualitySeed
NTuple::Item< double > g_combAxPatSeed
NTuple::Item< double > g_combAxMcAmbigTest
NTuple::Item< double > g_combAxMcTheta
NTuple::Item< double > g_combAxQualityTest
NTuple::Item< double > g_combAxNhitTest
NTuple::Item< double > g_combAxSigPhi0
NTuple::Item< double > g_combAxdCurv
NTuple::Item< double > g_combAxSigCurv
NTuple::Item< double > g_combAxdPhi0
NTuple::Item< double > g_combAxPatTest
NTuple::Item< double > g_combAxNhitSeed
NTuple::Item< double > g_combAxMc
NTuple::Item< double > g_combAxSlSeed
NTuple::Tuple * g_tupleCombAx
NTuple::Item< double > g_combAxMcAmbigSeed
NTuple::Item< double > g_combAxMcPhi
double mdcWrapAng(double phi1, double phi2)
virtual MdcTrack * storePar(MdcTrack *, double parms[2], double chisq, TrkContext &, double trackT0)
void resetComb(const MdcSeg *seed)
virtual int incompWithSeg(const MdcSeg *refSeg, const MdcSeg *testSeg)
void fillWithSegs(const MdcSegList *inSegs)
virtual int incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg, int iply)
MdcSegGrouperAx(const MdcDetector *gm, int debug)
MdcSegGrouper(const MdcDetector *gm, int nDeep, int debug)
void calcFromOrigin(const MdcSeg *parentSeg)
double sigPhi0() const
double sigCurv() const
const GmsList * oneList(int slayIndex) const
double testCombSegTheta() const
Definition MdcSeg.cxx:427
int nHit() const
Definition MdcSeg.cxx:372
double testCombSegAmbig() const
Definition MdcSeg.cxx:463
double testCombSeg(const MdcSeg *) const
Definition MdcSeg.cxx:378
void plotSegAll() const
Definition MdcSeg.cxx:157
double testCombSegPt() const
Definition MdcSeg.cxx:409
void setInfo(MdcSegInfo *ptr)
Definition MdcSeg.cxx:97