BOSS 7.1.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([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 "CLHEP/Alist/AList.h"
19#include "MdcData/MdcHit.h"
20#include "MdcGeom/MdcDetector.h"
28#include "MdcTrkRecon/MdcSeg.h"
29#include "MdcTrkRecon/GmsList.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++) {
68 isValid[j] = 0;
69 }
70}
71
72//------------------------------------------------------------------------
74//------------------------------------------------------------------------
75 if(3==_debug) std::cout<<std::endl<< "=====MdcSegGrouperAx::fillWithSegs====="<<std::endl;
76 // Prepare for axial finding
77 // Store the segments (pointers, actually), sorting by phi0
78 for (int isuper = 0; isuper < _gm->nSuper(); isuper++) {
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 // Create an info object within the seg to store info
88 inSeg->setInfo(info);
89 info->calcFromOrigin(inSeg); // calc. origin-dependent info
90
91 // Loop over the segs already stored, looking for the right place
92 // to stick the new one
93 int isInserted = 0;
94 for (int iseg = 0; iseg < (int) segList[isuper].length(); iseg++) {
95 MdcSeg *aSeg = segList[isuper][iseg];
96 if ( ((MdcSegInfoAxialO *)aSeg->info())->phi0() < info->phi0()) {
97 continue; }
98 segList[isuper].insert(inSeg, iseg);
99 isInserted = 1;
100 break;
101 } // end of loop over existing segs
102 if (isInserted == 0) segList[isuper].append(inSeg);
103 inSeg = (MdcSeg *) inSeg->next();
104 } // end loop over new segs
105// cout<<"segList["<<isuper<<"].length"<< segList[isuper].length()<<endl;//yzhang debug
106 } // end loop over superlayers
107
108/////////////////////
109/* for(int isuper = 0; isuper < _gm->nSuper(); isuper++) {
110 std::cout<<"-------super layer "<<isuper<<std::endl;
111 for (int iseg = 0; iseg < (int) segList[isuper].length(); iseg++) {
112 MdcSeg *aSeg = segList[isuper][iseg];
113 std::cout << " seg phi "<<iseg<< " "<<((MdcSegInfoAxialO*)aSeg->info())->phi0()<<std::endl;
114 } // end of loop over existing segs
115 }
116
117*/
118
119}
120
121//-------------------------------------------------------------------------
123 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 //std::cout<< "test seg:";
131 testSeg->plotSegAll();
132 }
133 // Test phi0 match
134 MdcSegInfoAxialO *refInfo = (MdcSegInfoAxialO *) refSeg->info();
135 MdcSegInfoAxialO *testInfo = (MdcSegInfoAxialO *) testSeg->info();
136
137
138 double sigPhi0 = (refInfo->sigPhi0() > testInfo->sigPhi0() ?
139 refInfo->sigPhi0() : testInfo->sigPhi0());
140 double refPhi0 = refInfo->phi0();
141 double testPhi0 = testInfo->phi0();
142 double corrPhi0 = mdcWrapAng(refPhi0, testPhi0);
143
144 double sigCurv = (refInfo->sigCurv() > testInfo->sigCurv() ?
145 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 << std::endl;
153 //std::cout << "test Curv "<<testCurv<<" ref "<<refCurv<<" sig "<< nSigmaCurv * sigCurv << std::endl;
154
155 if (g_tupleCombAx) {
156 g_combAxdPhi0 = refPhi0 - corrPhi0;
157 g_combAxdCurv = refCurv - testCurv;
158 g_combAxQualitySeed = refSeg->quality()+refSeg->nHit()*10+refSeg->superlayer()->slayNum()*1000;
159 g_combAxQualityTest = testSeg->quality()+testSeg->nHit()*10+testSeg->superlayer()->slayNum()*1000;
162 g_combAxMc = refSeg->testCombSeg(testSeg);
163 g_combAxMcPt = refSeg->testCombSegPt();
165 //g_combAxSigPhi0 = sigPhi0;
166 //g_combAxSigCurv = sigCurv;
167 //g_combAxSlSeed = refSeg->superlayer()->slayNum();
168 //g_combAxSlTest = testSeg->superlayer()->slayNum();
169 //g_combAxPatSeed = refSeg->segPattern();
170 //g_combAxPatTest = testSeg->segPattern();
171 //g_combAxNhitSeed = refSeg->nHit();
172 //g_combAxNhitTest = testSeg->nHit();
173 //test if the combined segments in the same track
174 // return -1:seed false
175 // return value = n hits on the seed track/ n hits of test seg
176 //g_combAxMcPhi = refSeg->testCombSegPhi();
177 //std::cout<< "mc seg "<< refSeg->testCombSeg(testSeg) << std::endl;//yzhang debug
178 g_tupleCombAx->write();
179 }
180
181 //yzhang add 2009-10-16
182 //if (refPhi0 - corrPhi0 > nSigmaPhi0 * sigPhi0)
183 //if(3 == _debug){
184 // std::cout << " phi0 ref"<<refPhi0
185 // <<" corr "<<corrPhi0
186 // << " diff "<<fabs(corrPhi0-refPhi0)
187 // <<" >? "<<phi0Cut<<std::endl;
188 // std::cout << " curv ref"<<refCurv
189 // <<" test "<<testCurv<< " diff "<<refCurv-testCurv
190 // <<" >? "<<curvCut<< std::endl;
191 //}
192 if(refSeg->testCombSegPt()>0.4 && fabs(corrPhi0 - refPhi0)>0.4 &&(refSeg->testCombSeg(testSeg)>0.5)){
193 if(3==_debug){
194 std::cout<< endl<<" test " << std::endl;
195 std::cout<<"seed seg: "; refSeg->plotSegAll(); std::cout<< std::endl;
196 std::cout<<"test seg: "; testSeg->plotSegAll(); std::cout<< std::endl;
197 std::cout<< " dPhi0 abnormal "<<corrPhi0 - refPhi0<<std::endl;
198 }
199 }else{
200 if(3== _debug){
201 std::cout<< endl<<" test " << std::endl;
202 std::cout<<"seed seg: "; refSeg->plotSegAll(); std::cout<< std::endl;
203 std::cout<<"test seg: "; testSeg->plotSegAll(); std::cout<< std::endl;
204 std::cout<< " dPhi0 ok " <<setprecision(3)<< corrPhi0 - refPhi0<<std::endl;
205 }
206 }
207
208 //std::cout<< __FILE__ << " " << __LINE__ << " dphi0= "<<fabs(corrPhi0 - refPhi0)<<" mc "<<refSeg->testCombSeg(testSeg)<<std::endl;
209
210 cout<<setiosflags(ios::fixed);
211 //FIXME 2011-05-31 yzhang cut vs pt
212 if (fabs(corrPhi0 - refPhi0) > phi0Cut) {
213 if(3 == _debug) std::cout << " SKIP by dPhi0 "
214 <<fabs(corrPhi0-refPhi0)<<">"<<phi0Cut<<std::endl;
215 //yzhang delete
216 //if (testPhi0 > refPhi0) return 1;
217 //else
218 return -1; // => testPhi0>2pi & refPhi0<2pi
219 }else{
220 if(3 == _debug)std::cout<< " dphi " <<setprecision(3)<< fabs(corrPhi0 - refPhi0);
221 }
222
223 // Test curvature match
224 // use larger error of the two
225 //if (fabs(refCurv - testCurv) > nSigmaCurv * sigCurv)
226 if (fabs(refCurv - testCurv) > curvCut){
227 if(3 == _debug) std::cout << " SKIP by dCurv"
228 <<fabs(refCurv-testCurv)<<">"<<curvCut<<std::endl;
229 return -2;
230 }else{
231 if(3 == _debug)std::cout<< " dCurv " <<setprecision(3)<< fabs(refCurv - testCurv);
232 }
233 if(3 == _debug) std::cout << " KEEP "<<std::endl;
234
235 cout<<setprecision(6);
236 cout<<setiosflags(ios::scientific);
237 //std::cout<< "ok! " << std::endl;//yzhang debug
238 return 0;
239}
240
241//-------------------------------------------------------------------------
242int MdcSegGrouperAx::incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg,
243 int iply) {
244 //-------------------------------------------------------------------------
245
246 return 0;
247}
248
249//-------------------------------------------------------------------------
251 //-------------------------------------------------------------------------
252
253 // Delete existing list of valid/invalid segs
254 if (isValid != 0) {
255 int i;
256 for (i = 0; i < nDeep; i++) {
257 delete [] isValid[i];
258 isValid[i] = 0;
259 }
260 }
261
262 _seed = seed;
263 //Grab the seglist for each non-seed slayer
264 int islay = 0;
265 int iply = 0;
266 nPlyFilled = 0;
267 nNull = 0;
268 const MdcSuperLayer *seedSlay = 0;
269 if (seed != 0) seedSlay = seed->superlayer();
270
271
272 // Set up all sorts of stuff for fast grouping of segs in nextGroup()
273 for (const MdcSuperLayer *thisSlay = _gm->firstSlay(); thisSlay != 0;
274 thisSlay = thisSlay->next()) {
275 bool noGoodYet = true;
276 islay++;
277
278 if (thisSlay == seedSlay) continue;
279 if (thisSlay->whichView() != 0) continue;//Axial slayer
280 firstGood[iply] = 0;
281
282 // Loop over the segs, marking start & end of valid region for this seed
283 firstBad[iply] = 0;
284 if (segList[islay-1].length() != 0) {
285 isValid[iply] = new bool[segList[islay-1].length()];
286 }
287
288 if(3 == _debug && segList[islay-1].length()>0) {
289 std::cout<<std::endl<< "--match axial seg by phi in slayer "
290 <<thisSlay->slayNum()<<"--"<<std::endl;
291 //std::cout<< "reference seg: "; seed->plotSeg();
292 //std::cout<< std::endl;
293 }
294
295 for (int i = 0; i < (int) segList[islay-1].length(); i++) {
296 MdcSeg *aSeg = segList[islay-1][i];
297 int invalid = incompWithSeg(seed, aSeg);
298 isValid[iply][i] = true;
299 if (invalid < 0) {
300 firstBad[iply] = i;
301 isValid[iply][i] = false;
302 if (noGoodYet) firstGood[iply] = i+1;
303 } else if (invalid > 0) {
304 // No more valid segs in this slayer
305 firstBad[iply] = i;
306 for (int j = i; j < (int) segList[islay-1].length(); j++)
307 isValid[iply][j] = false;
308 break;
309 } else {
310 firstBad[iply] = i+1;
311 noGoodYet = false;
312 }
313 }
314
315 //if(3 == _debug) std::cout<<iply<<" islay "<<islay<<" firstGood "<<firstGood[iply]<<" "<<firstBad[iply]<< std::endl;
316 if (firstGood[iply] > firstBad[iply]) firstGood[iply] = firstBad[iply];
317 if (firstGood[iply] == firstBad[iply]) {
318 // If there are no valid segs for this ply, drop it
319 delete [] isValid[iply];
320 isValid[iply] = 0;
321 continue;
322 }
323 // Associate correct seglist with this ply
324 combList[iply] = &segList[islay-1];
325 leaveGap[iply] = false;
326 iply++;
327 }
328 nPlyFilled = iply;
330 maxNull = nPlyFilled - 2;
331 maxNull++;
332}
333//---------------------------------------------------------------------
335 double chisq, TrkContext& context,
336 double t0) {
337 //---------------------------------------------------------------------
338 // cout << "storePar in MdcSegGrouperAx" <<endl;//yzhang debug
339 assert(trk == 0);
340 BesAngle foundPhi0(parms[0]);
341 // factor of two to convert to BaBar def of curvature (omega)
342 //std::cout<< "stored par " << parms[0]<< " "<<parms[1]
343 //<<" store: "<<foundPhi0.rad()<<" "<<2.*parms[1]<<std::endl;
344 TrkExchangePar par(0.0, foundPhi0.rad(), 2.*parms[1], 0.0, 0.0);
345 return new MdcTrack(_gm->nSuper(), par, chisq, context, t0);
346}
347
348/*
349 double MdcSegGrouperAx::calcParByHits(MdcSeg **segGroup, int nToUse, const TrkExchangePar &par, double param[2]) {
350 return 0.;
351 }
352 */
NTuple::Item< double > g_combAxMcPt
Definition: MdcHistItem.h:163
NTuple::Item< double > g_combAxQualitySeed
Definition: MdcHistItem.h:156
NTuple::Item< double > g_combAxMcAmbigTest
Definition: MdcHistItem.h:167
NTuple::Item< double > g_combAxMcTheta
Definition: MdcHistItem.h:164
NTuple::Item< double > g_combAxQualityTest
Definition: MdcHistItem.h:157
NTuple::Item< double > g_combAxdCurv
Definition: MdcHistItem.h:151
NTuple::Item< double > g_combAxdPhi0
Definition: MdcHistItem.h:150
NTuple::Item< double > g_combAxMc
Definition: MdcHistItem.h:162
NTuple::Tuple * g_tupleCombAx
Definition: MdcHistItem.h:149
NTuple::Item< double > g_combAxMcAmbigSeed
Definition: MdcHistItem.h:166
NTuple::Item< double > g_combAxMcPt
Definition: MdcHistItem.h:163
double MdcTrkReconCut_combAxCurv
NTuple::Item< double > g_combAxSlTest
Definition: MdcHistItem.h:155
NTuple::Item< double > g_combAxQualitySeed
Definition: MdcHistItem.h:156
NTuple::Item< double > g_combAxPatSeed
Definition: MdcHistItem.h:158
double MdcTrkReconCut_combAxPhi0
NTuple::Item< double > g_combAxMcAmbigTest
Definition: MdcHistItem.h:167
double MdcTrkReconCut_combAxPhi0Cut
NTuple::Item< double > g_combAxMcTheta
Definition: MdcHistItem.h:164
NTuple::Item< double > g_combAxQualityTest
Definition: MdcHistItem.h:157
NTuple::Item< double > g_combAxNhitTest
Definition: MdcHistItem.h:161
NTuple::Item< double > g_combAxSigPhi0
Definition: MdcHistItem.h:152
NTuple::Item< double > g_combAxdCurv
Definition: MdcHistItem.h:151
NTuple::Item< double > g_combAxSigCurv
Definition: MdcHistItem.h:153
NTuple::Item< double > g_combAxdPhi0
Definition: MdcHistItem.h:150
double MdcTrkReconCut_combAxCurvCut
NTuple::Item< double > g_combAxPatTest
Definition: MdcHistItem.h:159
NTuple::Item< double > g_combAxNhitSeed
Definition: MdcHistItem.h:160
NTuple::Item< double > g_combAxMc
Definition: MdcHistItem.h:162
NTuple::Item< double > g_combAxSlSeed
Definition: MdcHistItem.h:154
NTuple::Tuple * g_tupleCombAx
Definition: MdcHistItem.h:149
NTuple::Item< double > g_combAxMcAmbigSeed
Definition: MdcHistItem.h:166
NTuple::Item< double > g_combAxMcPhi
Definition: MdcHistItem.h:165
double MdcTrkReconCut_combAxPhi0Cut
double MdcTrkReconCut_combAxCurvCut
double rad() const
Definition: BesAngle.h:118
GmsListLink * first() const
Definition: GmsList.h:42
unsigned int count() const
Definition: GmsList.h:43
const MdcSuperLayer * firstSlay(void) const
Definition: MdcDetector.h:46
int nSuper() const
Definition: MdcDetector.h:53
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)
int nPly() const
Definition: MdcSegGrouper.h:54
void resetSegCounters()
HepAList< MdcSeg > * segList
Definition: MdcSegGrouper.h:80
bool ** isValid
Definition: MdcSegGrouper.h:74
const MdcDetector * _gm
Definition: MdcSegGrouper.h:79
HepAList< MdcSeg > ** combList
Definition: MdcSegGrouper.h:78
void calcFromOrigin(const MdcSeg *parentSeg)
double curv() const
double phi0() const
double sigPhi0() const
double sigCurv() const
const GmsList * oneList(int slayIndex) const
Definition: MdcSegList.cxx:412
Definition: MdcSeg.h:42
const MdcSuperLayer * superlayer() const
Definition: MdcSeg.h:51
double testCombSegTheta() const
Definition: MdcSeg.cxx:424
int nHit() const
Definition: MdcSeg.cxx:368
double testCombSegAmbig() const
Definition: MdcSeg.cxx:458
double testCombSeg(const MdcSeg *) const
Definition: MdcSeg.cxx:376
MdcSegInfo * info() const
Definition: MdcSeg.h:52
void plotSegAll() const
Definition: MdcSeg.cxx:159
unsigned int quality() const
Definition: MdcSeg.h:49
double testCombSegPt() const
Definition: MdcSeg.cxx:407
void setInfo(MdcSegInfo *ptr)
Definition: MdcSeg.cxx:96
const MdcSuperLayer * next(void) const
Definition: MdcSuperLayer.h:39
int whichView(void) const
Definition: MdcSuperLayer.h:21
int slayNum(void) const
Definition: MdcSuperLayer.h:43
double mdcWrapAng(double phi1, double phi2)
Definition: mdcWrapAng.h:12