BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcSeg.cxx
Go to the documentation of this file.
1// MdcSeg.cxx
2
3#include "MdcTrkRecon/MdcSeg.h"
4#include "MdcData/MdcHit.h"
5#include "MdcData/MdcHitMap.h"
6#include "MdcData/MdcHitUse.h"
7#include "MdcGeom/BesAngle.h"
8#include "MdcGeom/MdcLayer.h"
9#include "MdcGeom/MdcSuperLayer.h"
10#include "MdcTrkRecon/MdcLine.h"
11#include "MdcTrkRecon/MdcMap.h"
12#include "MdcTrkRecon/MdcSegInfoSterO.h"
13#include "MdcTrkRecon/MdcSegParams.h"
14#include "MdcTrkRecon/MdcSegUsage.h"
15#include "MdcTrkRecon/mdcWrapAng.h"
16#include "MdcTrkRecon/mdcWrapWire.h"
17#include <math.h>
18#include <stdlib.h>
19
20// yzhang hist cut
21#include "AIDA/IHistogram1D.h"
22extern AIDA::IHistogram1D* g_nSigAdd;
23// zhangy hist cut
24
25extern int haveDigiTk[43][288];
26extern double haveDigiPt[43][288];
27extern double haveDigiTheta[43][288];
28extern double haveDigiPhi[43][288];
29extern int haveDigiAmbig[43][288];
30// Initialize static pointer
31MdcSegParams* MdcSeg::segParam = 0;
32const double twoPi = Constants::twoPi;
33//------------------------------------------------------------------------
34MdcSeg::MdcSeg( double bt ) {
35 //------------------------------------------------------------------------
36 _info = 0;
37 _bunchTime = bt;
38}
39
40//------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 if ( _info != 0 ) delete _info;
44 reset(); // delete Hots
45}
46
47//------------------------------------------------------------------------
48MdcSeg::MdcSeg( const MdcSeg& other )
49 : GmsListLink()
50 , _slayer( other._slayer )
51 , _phi( other._phi )
52 , _slope( other._slope )
53 , _chisq( other._chisq )
54 , _qual( other._qual )
55 , _pattern( other._pattern )
56 , _info( other._info )
57 , _bunchTime( other._bunchTime )
58//------------------------------------------------------------------------
59{
60 HepAListDeleteAll( _theList );
61 for ( int i = 0; i < other.nHit(); i++ ) { _theList.append( other.hit( i ) ); }
62 for ( int j = 0; j < 3; j++ )
63 {
64 _errmat[0] = other._errmat[0];
65 _errmat[1] = other._errmat[1];
66 _errmat[2] = other._errmat[2];
67 }
68 segParam = other.segParam;
69}
70
71//------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 if ( &other != this )
75 {
76
77 HepAListDeleteAll( _theList );
78 for ( int i = 0; i < other.nHit(); i++ ) { _theList.append( other.hit( i ) ); }
79 _slayer = other._slayer;
80 _phi = other._phi;
81 _slope = other._slope;
82 _errmat[0] = other._errmat[0];
83 _errmat[1] = other._errmat[1];
84 _errmat[2] = other._errmat[2];
85 _chisq = other._chisq;
86 _qual = other._qual;
87 _pattern = other._pattern;
88 _info = other._info;
89 _bunchTime = other._bunchTime;
90 segParam = other.segParam;
91 }
92
93 return *this;
94}
95
96//------------------------------------------------------------------------
97void MdcSeg::setInfo( MdcSegInfo* newInfo ) {
98 //------------------------------------------------------------------------
99 delete _info; // if any
100 _info = newInfo;
101}
102
103//------------------------------------------------------------------------
104void MdcSeg::setValues( int nInPatt, int nhit, MdcHit* hits[], MdcLine* span,
105 const MdcSuperLayer* slay, int ambig[] ) {
106 //------------------------------------------------------------------------
107 _qual = 0;
108 if ( nInPatt == 4 ) _qual |= segFullFlag;
109 _phi = BesAngle( span->intercept );
110 _slope = span->slope;
111 _chisq = span->chisq;
112 _errmat[0] = span->errmat[0];
113 _errmat[1] = span->errmat[1];
114 _errmat[2] = span->errmat[2];
115 reset();
116 _slayer = slay;
117 for ( int i = 0; i < nhit; i++ )
118 {
119 MdcHitUse* alink = new MdcHitUse( *( hits[i] ), superlayer()->rad0(), ambig[i] );
120 append( alink );
121 }
122
123 return;
124}
125
126//------------------------------------------------------------------------
127void MdcSeg::setValues( int nInPatt, double inPhi, double inSlope, double chi2,
128 double inError[3], const MdcSuperLayer* slay ) {
129 //------------------------------------------------------------------------
130 // Sets segment values with no associated hits
131 _qual = 0;
132 if ( nInPatt == 4 ) _qual |= segFullFlag;
133 _phi = inPhi;
134 _slope = inSlope;
135 _chisq = chi2;
136 _errmat[0] = inError[0];
137 _errmat[1] = inError[1];
138 _errmat[2] = inError[2];
139 _slayer = slay;
140 reset(); // clears hit list
141
142 return;
143}
144
145//------------------------------------------------------------------------
147 //------------------------------------------------------------------------
148 for ( int i = 0; i < nHit(); i++ )
149 {
150 MdcHitUse* alink = _theList[i];
151 MdcSegUsage* x;
152 if ( usedHits.get( alink->mdcHit(), x ) ) x->setUsedAmbig( alink->ambig() );
153 }
154}
155
156//------------------------------------------------------------------------
157void MdcSeg::plotSegAll() const {
158 //------------------------------------------------------------------------
159 // print hit
160 // if(superlayer()!=NULL) std::cout<<"sl"<<superlayer()->slayNum()<<" p"<<segPattern()<<"
161 // st"<<quality();
162 for ( int ihit = 0; ihit < nHit(); ihit++ )
163 {
164 hit( ihit )->mdcHit()->print( std::cout );
165 std::cout << setw( 2 ) << hit( ihit )->ambig() << " ";
166 }
167
168 // cout << setiosflags( ios::fixed );
169 if ( info() != NULL )
170 {
171 std::cout << " phi " << setprecision( 2 ) << phi() << " slope " << std::setw( 2 )
172 << setprecision( 2 ) << slope() << " ";
173 if ( superlayer()->whichView() == 0 )
174 {
175 std::cout << setprecision( 2 ) << "phi0=" << info()->par( 0 );
176 cout << setprecision( 5 ) << " cpa=" << info()->par( 1 );
177 }
178 else
179 {
180 std::cout << setprecision( 2 ) << "z0=" << info()->par( 0 ) << setprecision( 2 )
181 << " ct=" << info()->par( 1 );
182 }
183 if ( fabs( info()->arc() ) > 0.0001 )
184 { std::cout << setprecision( 2 ) << " arc=" << info()->arc(); }
185 std::cout << setprecision( 3 ) << " chi2=" << _chisq;
186 }
187 else
188 {
189 std::cout << " phi " << setprecision( 2 ) << phi() << " slope " << std::setw( 2 )
190 << setprecision( 2 ) << slope() << " chi2 " << setprecision( 3 ) << chisq();
191 }
192
193 std::cout << std::defaultfloat;
194 // cout << setprecision( 6 );
195 // cout << setiosflags( ios::scientific );
196}
197//------------------------------------------------------------------------
198void MdcSeg::plotSeg() const {
199 //------------------------------------------------------------------------
200 std::cout << superlayer()->slayNum() << " pat" << segPattern() << " ";
201 for ( int ihit = 0; ihit < nHit(); ihit++ )
202 {
203 hit( ihit )->mdcHit()->print( std::cout ); // print hit
204 std::cout << hit( ihit )->ambig() << " ";
205 }
206 if ( info() != NULL ) { cout << " . "; }
207 // std::cout << std::endl;
208}
209
210//------------------------------------------------------------------------
211// void
212// MdcSeg::plotZ(int openIt, int color) const {
213//------------------------------------------------------------------------
214/*
215// Plot line to indicate segment
216double start[2], finish[2];
217
218const double length = 0.018 * display->width(windowZ);
219double ct = ((MdcSegInfoSterO *) info())->ct(); // !!! this cast stinks
220double z0 = ((MdcSegInfoSterO *) info())->z0();
221double arc = ((MdcSegInfoSterO *) info())->arc();
222double dels = length / sqrt(1. + ct*ct);
223double z = z0 + ((MdcSegInfoSterO *) info())->arc() * ct;
224start[0] = arc - dels;
225start[1] = z - ct * dels;
226finish[0] = arc + dels;
227finish[1] = z + ct * dels;
228*/
229//}
230
231//------------------------------------------------------------------------
232int MdcSeg::addHits( MdcLine* span, MdcHit** /* hits[]*/, const MdcHitMap* map, double corr ) {
233 //------------------------------------------------------------------------
234
235 /* Pick up hits adjacent to an existing segment. Output final number of
236 hits. Note: input hits are not refound. It picks up hits
237 in cells that the segment should pass through, checking that they
238 have a plausible drift distance. In event of a wraparound (i.e. track that
239 passes through 2pi), all angles are relative to phiseg (i.e. if phiseg is
240 just above 0, some phi's may be negative). */
241 //****
242
243 int cell[2], ambig[2]; // wire # and ambig for cells in current layer
244 double phiwire[2];
245 int cellused[4] = { 0 }; // list of wire #'s of existing hits in span
246 int lAdded = 0;
247 int nhits = nHit();
248 int m_debug = 0;
249
250 // Note the hits already in the fit, so we don't pick them up again.
251 int firstnum = superlayer()->firstLayer()->layNum();
252 for ( int i = 0; i < nHit(); i++ )
253 {
254 const MdcHit* dHit = hit( i )->mdcHit();
255 int laynum = dHit->layernumber();
256 cellused[laynum - firstnum] = dHit->wirenumber();
257 }
258
259 // Loop through the layers, predicting cells that could be hit.
260 // for (int layIndex = 0; layIndex < 4; layIndex++) {
261 for ( int layIndex = 0; layIndex < superlayer()->nLayers(); layIndex++ )
262 {
263 const MdcLayer* layer = superlayer()->layer( layIndex );
264 int laynum = layer->layNum();
265
266 // Calc. projected phi of hit
267 double rinv = 1. / layer->rMid();
268 double ncellinv = 1. / (double)layer->nWires();
269 double phiproj = phi() + ( layer->rMid() - superlayer()->rad0() ) * slope();
270 // Calc. nearest wire.
271 BesAngle tmp( phiproj - layer->phiOffset() );
272 cell[0] = (int)floor( layer->nWires() * tmp.rad() / twoPi + 0.5 );
273 cell[0] = mdcWrapWire( cell[0], layer->nWires() );
274 phiwire[0] = mdcWrapAng( phi(), cell[0] * twoPi * ncellinv + layer->phiOffset() );
275 // Which ambiguity? +1 if phi(wire) < phi(projected).
276 ambig[0] = ( phiwire[0] < phiproj ) ? 1 : -1;
277
278 // Now next nearest wire.
279 ambig[1] = -ambig[0];
280 cell[1] = mdcWrapWire( cell[0] + ambig[0], layer->nWires() );
281 phiwire[1] = mdcWrapAng( phi(), cell[1] * twoPi * ncellinv + layer->phiOffset() );
282
283 if ( m_debug ) std::cout << " loop over the two possible wires " << std::endl;
284 //*** Loop over the two possible wires.
285 for ( int iroad = 0; iroad < 2; iroad++ )
286 {
287 if ( cellused[laynum - firstnum] == cell[iroad] ) continue;
288 if ( m_debug )
289 std::cout << "possible wires " << laynum << " " << cell[iroad] << std::endl;
290 if ( map->hitWire( laynum, cell[iroad] ) != 0 )
291 {
292 MdcHit* ahit = map->hitWire( laynum, cell[iroad] );
293 // if hit is already used, skip it!
294 if ( ahit->usedHit() )
295 {
296 if ( m_debug ) std::cout << "hit used continue " << std::endl;
297 continue;
298 }
299 // drift as delphi
300 // FIXME: flip ambiguity for incoming tracks
301 double phidrift = ahit->driftDist( bunchTime(), ambig[iroad] ) * corr * rinv;
302 double phihit = mdcWrapAng( phi(), phidrift * ambig[iroad] + ahit->phi() );
303
304 // Check the drift distance.
305 double sigphi = corr * ahit->sigma( bunchTime(), 0 ) * rinv;
306 // Skip hit if more than n sigma away from track.
307 if ( g_nSigAdd && fabs( sigphi ) > 0.0001 )
308 { g_nSigAdd->fill( fabs( phihit - phiproj ) / sigphi ); } // yzhang hist cut
309 if ( fabs( phihit - phiproj ) > sigphi * segParam->nsigAddHit )
310 {
311 if ( m_debug )
312 std::cout << fabs( phihit - phiproj ) << "> add hit sigma " << sigphi << "*"
313 << segParam->nsigAddHit << "=" << sigphi * segParam->nsigAddHit
314 << std::endl;
315 continue;
316 }
317
318 // Load hit for refitting
319 lAdded = 1;
320 span->sigma[nhits] = sigphi;
321 span->x[nhits] = layer->rMid() - superlayer()->rad0();
322 span->y[nhits] = mdcWrapAng( span->y[0], phihit );
323
324 // Add this hit to segment
325 MdcHitUse* alink = new MdcHitUse( *ahit, superlayer()->rad0(), ambig[iroad] );
326 append( alink );
327 // std::cout<< __FILE__ << " " << __LINE__ << " addhit "<<std::endl;
328
329 nhits++;
330 } // end if hit wire
331
332 } // end loop over 2 cells
333
334 } // end layer loop
335
336 if ( lAdded )
337 {
338 span->fit( nhits );
339 BesAngle tmpAngle( span->intercept );
340 span->intercept = tmpAngle;
341 _phi = span->intercept;
342 _slope = span->slope;
343 _chisq = span->chisq;
344 _errmat[0] = span->errmat[0];
345 _errmat[1] = span->errmat[1];
346 _errmat[2] = span->errmat[2];
347 }
348
349 return nhits;
350}
351
352//------------------------------------------------------------------------
353void MdcSeg::reset() {
354 //------------------------------------------------------------------------
355 HepAListDeleteAll( _theList );
356}
357
358//------------------------------------------------------------------------
359void MdcSeg::append( MdcHitUse* theHitUse ) {
360 //------------------------------------------------------------------------
361 _theList.append( theHitUse );
362}
363
364//------------------------------------------------------------------------
365void MdcSeg::remove( MdcHitUse* theHitUse ) {
366 //------------------------------------------------------------------------
367 _theList.remove( theHitUse );
368 delete theHitUse;
369}
370
371//------------------------------------------------------------------------
372int MdcSeg::nHit() const {
373 //------------------------------------------------------------------------
374 return _theList.length();
375}
376
377//------------------------------------------------------------------------
378double MdcSeg::testCombSeg( const MdcSeg* testSeg ) const {
379 //------------------------------------------------------------------------
380 int tkId = -1;
381 for ( int i = 0; i < nHit(); i++ )
382 {
383 const MdcHit* h = hit( i )->mdcHit();
384 unsigned int l = h->layernumber();
385 unsigned int w = h->wirenumber();
386 // std::cout<< __FILE__ << " ref " << i << "
387 // haveDigiTk("<<l<<","<<w<<")"<<haveDigiTk[l][w]<<std::endl;
388 if ( haveDigiTk[l][w] < 0 || haveDigiTk[l][w] > 100 ) continue;
389 if ( tkId < 0 ) { tkId = haveDigiTk[l][w]; }
390 else if ( haveDigiTk[l][w] != tkId )
391 {
392 return -1; // hits in this seg not in same mc track
393 }
394 } // end for
395
396 double nSame = 0.;
397 for ( int i = 0; i < testSeg->nHit(); i++ )
398 {
399 const MdcHit* h = testSeg->hit( i )->mdcHit();
400 unsigned int l = h->layernumber();
401 unsigned int w = h->wirenumber();
402 if ( haveDigiTk[l][w] == tkId ) { ++nSame; }
403 }
404
405 return nSame / testSeg->nHit();
406}
407
408//------------------------------------------------------------------------
409double MdcSeg::testCombSegPt() const {
410 //------------------------------------------------------------------------
411 double truthPt = -1.;
412 for ( int i = 0; i < nHit(); i++ )
413 {
414 const MdcHit* h = hit( i )->mdcHit();
415 unsigned int l = h->layernumber();
416 unsigned int w = h->wirenumber();
417 if ( haveDigiPt[l][w] < 0 ) continue;
418 // std::cout<< __FILE__ << " " << __LINE__ << "
419 // haveDigiPt("<<l<<","<<w<<")"<<haveDigiPt[l][w]<<std::endl;
420 if ( truthPt < 0 ) { truthPt = haveDigiPt[l][w]; }
421 } // end for
422
423 return truthPt;
424}
425
426//------------------------------------------------------------------------
428 //------------------------------------------------------------------------
429 double truthTheta = -999.;
430 for ( int i = 0; i < nHit(); i++ )
431 {
432 const MdcHit* h = hit( i )->mdcHit();
433 unsigned int l = h->layernumber();
434 unsigned int w = h->wirenumber();
435 if ( haveDigiTheta[l][w] < -998. ) continue;
436 // std::cout<< __FILE__ << " " << __LINE__ << "
437 // haveDigiTheta("<<l<<","<<w<<")"<<haveDigiTheta[l][w]<<std::endl;
438 if ( truthTheta < -998. ) { truthTheta = haveDigiTheta[l][w]; }
439 } // end for
440
441 return truthTheta;
442}
443
444//------------------------------------------------------------------------
446 //------------------------------------------------------------------------
447 double truthPhi = -999.;
448 for ( int i = 0; i < nHit(); i++ )
449 {
450 const MdcHit* h = hit( i )->mdcHit();
451 unsigned int l = h->layernumber();
452 unsigned int w = h->wirenumber();
453 if ( haveDigiPhi[l][w] < -998. ) continue;
454 // std::cout<< __FILE__ << " " << __LINE__ << "
455 // haveDigiPhi("<<l<<","<<w<<")"<<haveDigiPhi[l][w]<<std::endl;
456 if ( truthPhi < -998. ) { truthPhi = haveDigiPhi[l][w]; }
457 } // end for
458
459 return truthPhi;
460}
461
462//------------------------------------------------------------------------
464 //------------------------------------------------------------------------
465 double ambigOk = 0.;
466 for ( int i = 0; i < nHit(); i++ )
467 {
468 const MdcHit* h = hit( i )->mdcHit();
469 unsigned int l = h->layernumber();
470 unsigned int w = h->wirenumber();
471 if ( hit( i )->ambig() == haveDigiAmbig[l][w] ) ambigOk++;
472 } // end for
473
474 return ambigOk / nHit();
475}
double w
int haveDigiTk[43][288]
int haveDigiAmbig[43][288]
double haveDigiPhi[43][288]
AIDA::IHistogram1D * g_nSigAdd
double haveDigiTheta[43][288]
double haveDigiPt[43][288]
double mdcWrapAng(double phi1, double phi2)
const double twoPi
Definition MdcSeg.cxx:32
const MdcHit * mdcHit() const
Definition MdcHitUse.cxx:62
void print(std::ostream &o) const
double sigma(double, int, double, double, double) const
Definition MdcHit.cxx:183
double driftDist(double, int, double, double, double) const
Definition MdcHit.cxx:157
int fit(int nUse)
Definition MdcLine.cxx:10
bool get(const K &theKey, V &theAnswer) const
double testCombSegTheta() const
Definition MdcSeg.cxx:427
void setValues(int nInPatt, int nhit, MdcHit *hits[], MdcLine *span, const MdcSuperLayer *slay, int ambig[])
Definition MdcSeg.cxx:104
void plotSeg() const
Definition MdcSeg.cxx:198
int nHit() const
Definition MdcSeg.cxx:372
double testCombSegPhi() const
Definition MdcSeg.cxx:445
double testCombSegAmbig() const
Definition MdcSeg.cxx:463
void append(MdcHitUse *)
Definition MdcSeg.cxx:359
double testCombSeg(const MdcSeg *) const
Definition MdcSeg.cxx:378
MdcSeg & operator=(const MdcSeg &)
Definition MdcSeg.cxx:72
int addHits(MdcLine *span, MdcHit *hits[], const MdcHitMap *, double corr)
void plotSegAll() const
Definition MdcSeg.cxx:157
MdcSeg(double bunchT)
Definition MdcSeg.cxx:34
virtual ~MdcSeg()
Definition MdcSeg.cxx:41
void remove(MdcHitUse *)
Definition MdcSeg.cxx:365
double testCombSegPt() const
Definition MdcSeg.cxx:409
void setInfo(MdcSegInfo *ptr)
Definition MdcSeg.cxx:97
void markHits(const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits) const
Definition MdcSeg.cxx:146