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