BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcSegFinder.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcSegFinder.cxx,v 1.17 2012/10/18 08:35:38 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// Steve Schaffner
13// Zhang Yao([email protected]) Migration for BESIII
14// 2010-04-13
15// Zhang Yao([email protected]) Keep best segment for 4-hit pattern
16//------------------------------------------------------------------------
17
23#include "MdcGeom/Constants.h"
24#include "MdcTrkRecon/MdcLine.h"
25#include "MdcGeom/BesAngle.h"
27#include "MdcTrkRecon/MdcLine.h"
28#include "MdcData/MdcHit.h"
29#include "MdcTrkRecon/MdcSeg.h"
30#include "MdcTrkRecon/GmsList.h"
31#include "MdcTrkRecon/MdcMap.h"
32#include "MdcGeom/MdcDetector.h"
34#include "MdcData/MdcHitUse.h"
35#include "MdcData/MdcHitMap.h"
36//yzhang hist cut
37#include "GaudiKernel/NTuple.h"
38#include <map>
39
40extern NTuple::Tuple* g_tupleFindSeg;
41extern NTuple::Item<double> g_findSegChi2;
42extern NTuple::Item<double> g_findSegIntercept;
43extern NTuple::Item<double> g_findSegSlope;
44extern NTuple::Item<double> g_findSegChi2Refit;
45extern NTuple::Item<double> g_findSegChi2Add;
46extern NTuple::Item<int> g_findSegPat;
47extern NTuple::Item<int> g_findSegNhit;
48extern NTuple::Item<int> g_findSegPat34;
49extern NTuple::Item<int> g_findSegSl;
50extern NTuple::Item<double> g_findSegMc;
51extern NTuple::Item<double> g_findSegAmbig;
52extern int haveDigiTk[43][288];
53extern int haveDigiAmbig[43][288];
54//zhangy hist cut
55
56using std::cout;
57using std::endl;
58
59//-------------------------------------------------------------------------
61 patternList(useAllAmbig) {
62 //-------------------------------------------------------------------------
63
64 }
65//-------------------------------------------------------------------------
66int
68 const MdcMap<const MdcHit*,MdcSegUsage*>& usedHits, const MdcHitMap* map,
69 double bunchTime) {
70 //-------------------------------------------------------------------------
71 // Forms all possible Segs of hits to act as candidate tracks
72 // Construct group of 8 hits; translate hit wires into bit-mapped word
73 // and look up valid patterns (if any) for this group.
74
75 _addHits = segs.segPar()->addHits;
76 int nSegs = 0;
77 int newSegs;
78 unsigned int groupWord;
79 MdcHit *groupHits[8];
80 int lPrevHit = 0; // flags that 2nd layer was hit in last group
81 //which layer/wire to look at for each hit in group
82 static const int layerWire[8][2] =
83 { { 0, -1}, { 0, 0}, { 1, 0}, { 2, -1},
84 { 2, 0}, { 3, -1}, { 3, 0}, { 3, 1} };
85
86 // Loop through the superlayers
87 const MdcSuperLayer *slayer = gm->firstSlay();
88 while (slayer != 0) {
89 const MdcLayer *layArray[4];
90 int wireIndex[4];
91
92
93 // layArray[0] = slayer->firstLayer();
94 // for (int i = 1; i < 4; i++) layArray[i] = gm->nextLayer(layArray[i-1]);
95 int nslay = slayer->nLayers();
96 for (int i = 0; i < nslay; i++) layArray[i] = slayer->layer(i);
97 if(nslay != 4) layArray[3] = 0;
98
99
100 // std::cout<<"-------------super layer----- "<<slayer->Id() << " nlayer "<<nslay<<std::endl;
101 //for (int i = 0; i < nslay; i++) std::cerr<<layArray[i]->Id()<<" "<<layArray[i]->nWires()<<"\n";
102 //slayer = slayer->next();continue;
103
104
105
106 // Loop over cells (index refers to cells in 2nd layer of superlayer)
107 for (int cellIndex = 0; cellIndex < layArray[1]->nWires(); cellIndex++) {
108 //yzhang change FIXME
109 double phi = layArray[1]->getWire(cellIndex)->phiE();
110 for(int i = 0; i < 4; i++ ) {
111 wireIndex[i] = cellIndex;
112 if ( slayer->slayNum() > 4) continue;//nWires over No.4 slayer is uniform
113 if ( (slayer->slayNum() > 9) && (i==3) ) break;//stop when get last layer
114 if ( i == 1 ) continue;
115 if ( i == 3 ) phi = layArray[2]->getWire(wireIndex[2])->phiE();
116 BesAngle tmp(phi - layArray[i]->phiEPOffset());
117 int wlow = (int)floor(layArray[i]->nWires() * tmp.rad() / twopi );
118 int wbig = (int)ceil(layArray[i]->nWires() * tmp.rad() / twopi );
119 if (tmp == 0 ){
120 wlow = -1;
121 wbig = 1;
122 }
123 if ( i!=3 ) {
124 wireIndex[i]=wbig;
125 }else{
126 wireIndex[i]= wlow;
127 }
128 //zhangy change
129 wireIndex[i] = mdcWrapWire(wireIndex[i], layArray[i]->nWires());
130 }
131 // Form group of 8 wires
132 groupWord = 0u;
133 unsigned bitWord = 1u;
134 int nGroup = 0;
135 for (int ii = 0; ii < 8; ii++) {
136 groupHits[ii] = 0;
137 //-----------------------------
138 if(layArray[ layerWire[ii][0] ] == 0) continue;
139 //-----------------------------
140 int laynum = layArray[ layerWire[ii][0] ]->layNum();
141 int wire = wireIndex[ layerWire[ii][0] ] + layerWire[ii][1];
142 wire = mdcWrapWire(wire, layArray[ layerWire[ii][0] ]->nWires()); //handle wrap-around
143 MdcHit* thisHit = map->hitWire(laynum, wire);
144 if (thisHit != 0) {
145 if ( !usedHits.get(thisHit)->deadHit() ) {
146 groupHits[ii] = thisHit;
147 groupWord |= bitWord;
148 nGroup++;
149 } else {
150 // cout << "Skipping hit " << endl;
151 }
152 }
153 // Quit if no hits in 1st 2 layers or 1 hit in 3 layers
154 if ( (ii == 2 && nGroup < 1) || (ii == 4 && nGroup < 2) ) break;
155 bitWord <<= 1;
156 }
157 if (nGroup < 3) continue;
158
159 //int lastWire = mdcWrapWire(cellIndex - 1, layArray[1]->nWires());//2011-08-10
160 int lastWire = mdcWrapWire(cellIndex - 1, layArray[0]->nWires());
161 if (map->hitWire(layArray[1]->layNum(), lastWire) != 0) lPrevHit = 1;
162 // if (layArray[1]->hitWire(lastWire) != 0) lPrevHit = 1;
163 else lPrevHit = 0;
164
165 // Try all allowed 4-hit patterns for this group (if any)
166 int nPatt = patternList.npatt4[groupWord];
167
168 if ((layArray[1]->layNum()==5) && (cellIndex ==46)) {
169 for(int i=0;i<4;i++){
170 //std::cout<<__FILE__<<" "<<__LINE__<<"====("<<layArray[i]->layNum()<<","<< wireIndex[i]<<")" << std::endl;
171 }
172 //std::cout<<__FILE__<<" "<<__LINE__<< " groupWord:"<<groupWord<<" nPatt:"<<nPatt<< std::endl;
173 }
174
175 if (nPatt > 0) {
176 newSegs = tryPatterns(groupHits, groupWord, 4, lPrevHit, nPatt,
177 patternList.allowedPatt4[groupWord], slayer, segs, usedHits, map,
178 bunchTime);
179 nSegs += newSegs;
180 }
181
182
183 // If unsuccessful, try 3-hit patterns ???? may want to try 2nd pass here
184 if (!segs.segPar()->find3[slayer->index()]) continue;
185 int nUnused = 0;
186 for (int i = 0; i < 8; i++) {
187 if (groupHits[i] != 0) {
188 if (usedHits.get(groupHits[i])->usedSeg() == 0) nUnused++;
189 }
190 }
191 if (nUnused > 0) {
192 nPatt = patternList.npatt3[groupWord];
193 if (nPatt > 0) {
194
195 newSegs = tryPatterns(groupHits, groupWord, 3, lPrevHit, nPatt,
196 patternList.allowedPatt3[groupWord], slayer, segs, usedHits, map,
197 bunchTime);
198 nSegs += newSegs;
199 }
200 }
201 } // cellIndex loop
202
203 slayer = slayer->next();
204 } //superlayer loop
205
206 if (nSegs > 0) {
207 segs.massageSegs();
208 segs.resetSeed(gm);
209 }
210
211 nSegs = segs.count();
212
213 if (5 == segs.segPar()->lPrint){
214 cout << "Number of Segs found: " << nSegs << "\n";
215 }
216
217 return nSegs;
218}
219
220//---------------------------------------------------------------------------
221int
222MdcSegFinder::tryPatterns(MdcHit *groupHits[8],
223 unsigned groupWord, int nInPatt,int lPrevHit, int npatt,
224 int *allowedPat, const MdcSuperLayer *slay, MdcSegList &segs,
225 const MdcMap<const MdcHit*,MdcSegUsage*>& usedHits, const MdcHitMap* map, double t0) {
226 //---------------------------------------------------------------------------
227 int nSegs = 0;
228 int nbit = 8;
229
230 unsigned *patterns;
231 int **ambigPatt;
232 if (nInPatt == 3) {
233 patterns = patternList.patt3;
234 ambigPatt = patternList.ambigPatt3;
235 } else {
236 patterns = patternList.patt4;
237 ambigPatt = patternList.ambigPatt4;
238 }
239
240 MdcSeg *trialSeg = new MdcSeg(t0); // start w/ 1 seg active
241
242 // Create temporary array of hit structures for fitting segment
243 MdcLine span(12);
244 int spanAmbig[12];
245 MdcHit *spanHits[12];
246 MdcHit *ahit;
247
248 // *** Loop over the allowed pattern for this group
249 for (int iPatt = 0; iPatt < npatt; iPatt++) {
250 unsigned thisPat = patterns[ allowedPat[iPatt] ];
251 unsigned testWord = thisPat & groupWord;
252
253 if (countbits(testWord) < nInPatt) continue;
254 if (lPrevHit && nInPatt == 3 && (thisPat == 051 || thisPat == 0111))
255 continue;
256
257 // *** Load the hits into hit structure (radius only at this point)
258 // radius is rel. to avg. for superlayer; resolution is converted to delphi
259 unsigned bitadd = 1u;
260 int nhit = 0;
261 for (int ibit = 0; ibit < nbit; ibit++) {
262 // Is this cell in the pattern?
263 if (bitadd & thisPat) {
264 const MdcLayer *layer = groupHits[ibit]->layer();
265 if (layer == 0) cout << "huh?" << endl;
266 span.x[nhit] = layer->rMid() - slay->rad0();
267 spanHits[nhit] = groupHits[ibit];
268 nhit++;
269 if (nhit == nInPatt) break;
270 }
271 bitadd <<= 1;
272 }
273
274 // *** Loop through all ambiguity combinations; the loop counter also
275 // serves as a bit-mapped pattern of ambiguities
276 // Discard combo if all hits have been used w/ this ambig before
277
278 std::map<int, MdcSeg*> bestTrialSegs;//yzhang 2012-09-18
279
280 int namb = 1 << nInPatt;
281 //std::cout<< __FILE__ << " " << __LINE__ << " namb "<<namb<<" nInPatt "<<nInPatt<<std::endl;
282 for (int iamb = 0; iamb < namb; iamb++) {
283
284 // Skip all but allowed ambiguity patterns
285 if (ambigPatt[ allowedPat[iPatt] ][iamb] != 1) continue;
286
287 // Convert loop counter into physical ambiguity (0=> -1; 1=>+1)
288 int nUsed = 0;
289 int ihit;
290 for (ihit = 0; ihit < nInPatt; ihit++) {
291 spanAmbig[ihit] = ( (1u<<ihit) &iamb) ? 1: -1;
292 nUsed += usedHits.get(spanHits[ihit])->usedAmbig( spanAmbig[ihit] );
293 }
294 if (nUsed >= nInPatt) continue;
295
296 // ***Calculate phi for each hit, correcting approx. for angle of track
297 /* First calculate a correction factor for the drift distance (since
298 we're treating hits as being at radius of wire). This may slow
299 things down.*/
300 /* corr = 1/cos(theta), where theta = del(d)/del(r), taken over the
301 span. Use 1/cos = sqrt(1+tan**2) for calculating correction. */
302
303 double rIn = slay->firstLayer()->rMid();
304 double rOut = slay->lastLayer()->rMid();
305 double phiIn = mdcWrapAng(spanHits[nInPatt-1]->phi(),spanHits[0]->phi());
306 double dphidr = ( (spanHits[nInPatt-1]->phi() + spanAmbig[nhit-1] *
307 spanHits[nInPatt-1]->driftDist(t0,spanAmbig[nhit-1]) /
308 rOut) - (phiIn+ spanAmbig[0] * spanHits[0]->driftDist(t0,spanAmbig[0]) / rIn)) / (rOut - rIn);//yzhang temp FIXME
309
310 double corr = sqrt( 1 + slay->rad0() * slay->rad0() * dphidr * dphidr );
311
312 if(5 == segs.segPar()->lPrint) {
313 std::cout<<__FILE__<<" "<<__LINE__<< " corr" <<corr<< " phi_n "
314 <<spanHits[nInPatt-1]->phi()<<" dd_n "<< spanAmbig[nhit-1] *
315 spanHits[nInPatt-1]->driftDist(t0,spanAmbig[nhit-1])
316 <<" phiIn " <<phiIn
317 <<" dd_in "<< spanAmbig[0] * spanHits[0]->driftDist(t0,spanAmbig[0]) << std::endl;
318
319 }
320 //yzhang add fix phi accross -x axis
321 bool crossAxis=false;
322 double yOld = 0;
323 //zhangy add
324 double sigmaSum= 0.;
325 double driftSum= 0.;
326 double driftHit[12];
327 // Actual phi calc
328 for (ihit = 0; ihit < nInPatt; ihit++) {
329 ahit = spanHits[ihit];
330 double rinv = 1. / ahit->layer()->rMid();
331 double drift = ahit->driftDist(t0,spanAmbig[ihit]);
332 span.y[ihit] = ahit->phi() + spanAmbig[ihit] *
333 drift * (corr * rinv);//yzhang temp FIXME
334
335 if (5 == segs.segPar()->lPrint) {
336 std::cout<<" in segment finding ("<<ahit->layernumber()<<","<<ahit->wirenumber()<<")"<<" |driftDist| "<< fabs(drift)<< " ambig "<<spanAmbig[ihit]<< " corr "<<corr<<" rinv "<<rinv<<" sigma "<<ahit->sigma(drift,spanAmbig[ihit])<<std::endl;
337 }
338 //span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]);
339 //yzhang 2010-05-20 , FIXME
340 span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]) * (corr * rinv);
341
342 //yzhang add temp FIXME
343 sigmaSum+= span.sigma[ihit];
344 driftSum+=drift;
345 driftHit[ihit]=drift;
346 //zhangy add temp FIXME
347
348 //yzhang add fix phi accross -x axis,set flag
349 if ( (span.y[ihit]!=0) && (!crossAxis)){
350 if ( (yOld / span.y[ihit]) < 0) crossAxis = true;
351 yOld = span.y[ihit];
352 }
353 //zhangy add
354 }
355
356 //yzhang add temp FIXME
357 //for (ihit = 0; ihit < nInPatt; ihit++) {
358 //span.sigma[ihit] = sigmaSum/nInPatt*
359 //( fabs(driftHit[ihit]-(driftSum/nInPatt))/(driftSum/nInPatt) );
360 //}
361 //zhangy add temp FIXME
362
363 //--yzhang add, fix phi accross -x axis , if cross +twopi
364 if ( crossAxis ){
365 for (int ihit=0 ; ihit < nInPatt; ihit++){
366 //Approx,for max phi of a cell is 2*pi/40, max cross 4 cell=0.628<0.7
367 if (abs(span.y[ihit]) < 0.7) break;
368 if (span.y[ihit] < 0)span.y[ihit]+=twopi;
369 }
370 }
371 //zhangy add
372
373
374 // Fit the segment
375 if (5 == segs.segPar()->lPrint) std::cout<<" first fit("<<nInPatt<<")"<<std::endl;
376 span.fit( nInPatt );
377 BesAngle temp = span.intercept;
378 span.intercept = temp.posRad();
379 double t_segchi2 = span.chisq / (nInPatt - 2) ;
380
381 //yzhang test 2011-06-14
382 if (5 == segs.segPar()->lPrint) {
383 for(int ii=0;ii<nInPatt;ii++){
384 std::cout<<__FILE__<<" "<<__LINE__<<" "<<ii <<" span.x "<<setw(10)<<span.x[ii]<<" y "<<setw(10)<<span.y[ii]<<" sigma "<<setw(10)<<span.sigma[ii]<< std::endl;
385 }
386 }
387 if(g_tupleFindSeg != NULL){
388 g_findSegSlope = span.slope;
389 g_findSegIntercept = span.intercept;
390 g_findSegChi2 = t_segchi2;
391 }
392 //zhangy test
393
394
395 if(5 == segs.segPar()->lPrint) {
396 std::cout<<__FILE__<<" "<<__LINE__<< " pattern "<< thisPat
397 <<" nHit "<<nInPatt <<" chi2/dof " << t_segchi2
398 <<" chisq "<<span.chisq <<" maxChisq="<<segs.segPar()->maxChisq <<std::endl;
399 for(int jj=0; jj<nInPatt; jj++){
400 std::cout << "resid["<<jj<<"] "<<span.resid[jj]<<" sigma "<<span.sigma[jj]<<" chisq add "<<span.resid[jj] * span.resid[jj] / (span.sigma[jj] * span.sigma[jj]) << std::endl;//yzhang debug
401 }
402 }
403 if (span.chisq / (nInPatt - 2) > segs.segPar()->maxChisq) {
404 if (5 == segs.segPar()->lPrint) {
405 std::cout<<__FILE__<<" "<<__LINE__<<"CUT! chi2/(N-2) " <<span.chisq / (nInPatt - 2) <<" > "<< segs.segPar()->maxChisq<< std::endl;
406 for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
407 cout<<" bestTrialSeg nHit="<<iter->first<<endl;
408 }
409 }
410 continue;
411 }
412
413 if (span.slope>Constants::pi || span.slope<(-1.)*Constants::pi ) {
414 if(5 == segs.segPar()->lPrint) std::cout<<" CUT by span.|slope| "<<span.slope<<" > pi"<<std::endl;
415 continue; //yzhang add 2012-08-07
416 }
417
418 int nInSeg = nInPatt;
419
420 // *** Pick up adjacent hits and refit
421 // Recalculate correction factor (optional)
422 if (segs.segPar()->segRefit) {
423 dphidr = span.slope;
424 corr = sqrt( 1 + slay->rad0() * slay->rad0() * dphidr * dphidr );
425 crossAxis = false;
426 for (ihit = 0; ihit < nInSeg; ihit++) {
427 ahit = spanHits[ihit];
428 double rinv = 1. / ahit->layer()->rMid();
429 double drift = ahit->driftDist(t0,spanAmbig[ihit]);
430 span.y[ihit] = ahit->phi() + spanAmbig[ihit] *
431 drift * (corr * rinv);//yzhang temp FIXME
432 //yzhang add
433 //span.y[ihit] = ahit->phi();
434 //zhangy add
435
436 //yzhang 2010-05-20 , FIXME
437 //span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]);
438 span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]) * (corr * rinv);
439 //yzhang add fix phi accross -x axis,set flag
440 if ( (span.y[ihit]!=0) && (!crossAxis)){
441 if ( (yOld / span.y[ihit]) < 0) crossAxis = true;
442 yOld = span.y[ihit];
443 }
444 //zhangy add
445 }
446 //yzhang add, fix phi accross -x axis , if cross +twopi
447 if ( crossAxis ){
448 for (int ihit=0 ; ihit < nInPatt; ihit++){
449 //Approx,for max phi of a cell is 2*pi/40, max cross 4 cell=0.628<0.7
450 if (abs(span.y[ihit]) < 0.7) break;
451 if (span.y[ihit] < 0)span.y[ihit]+=twopi;
452 }
453 }
454 if (5 == segs.segPar()->lPrint) std::cout<<" second fit("<<nInSeg<<")"<<std::endl;
455 //zhangy add
456 span.fit( nInSeg);
457 BesAngle temp = span.intercept;
458 span.intercept = temp.posRad();
459
460 if (span.chisq / (nInPatt - 2) > segs.segPar()->maxChisq) {
461 if (5 == segs.segPar()->lPrint) {
462 std::cout<<__FILE__<<" "<<__LINE__<<"CUT! chi2/(N-2) " <<span.chisq / (nInPatt - 2) <<" > "<< segs.segPar()->maxChisq<< std::endl;
463 for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
464 cout<<" bestTrialSeg nHit="<<iter->first<<endl;
465 }
466 }
467 continue;
468 }
469 }
470
471 if( g_tupleFindSeg!= NULL){
472 g_findSegChi2Refit = span.chisq / (nInSeg - 2);
473 }
474
475 trialSeg->setValues(nInPatt, nInSeg, spanHits, &span, slay, spanAmbig);
476
477 if (5 == segs.segPar()->lPrint) {
478 std::cout<<" try: "<<std::endl;
479 trialSeg->plotSegAll();//yzhang temp 2012-09-18
480 std::cout<<" "<<std::endl;
481 }
482 if (_addHits) {
483 // Look for adjacent hits
484 nInSeg = trialSeg->addHits(&span, spanHits, map, corr);
485 }
486
487
488 if (5 == segs.segPar()->lPrint) {
489 for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
490 cout<<" bestTrialSeg nHit="<<iter->first<<" chi2 "<<iter->second->chisq()<<endl;
491 }
492 std::cout<<"trialSeg chisq "<<trialSeg->chisq()<<std::endl;//<<" best chi2 " <<bestTrialSeg->chisq() << std::endl;
493 cout << "segment phi: " <<
494 trialSeg->phi() << " slope: " << trialSeg->slope() <<
495 " nhit: " << trialSeg->nHit() << " chi2 "<<trialSeg->chisq() << endl;
496 //cout << "layer, wire, ambig, used, drift: " << endl;
497 for (int i = 0; i < trialSeg->nHit(); i++) {
498 int ambi = trialSeg->hit(i)->ambig();
499 const MdcHit* theHit = trialSeg->hit(i)->mdcHit();
500 theHit->print(cout);
501 cout << " ambig " <<ambi;
502 }
503 cout << endl;
504 }
505 trialSeg->setPattern(iPatt);
506 trialSeg->markHits(usedHits);
507 if (nInPatt == 4) trialSeg->setFull();
508
509 if( g_tupleFindSeg!= NULL){
510 double t_mcRadio = -1.;
511 double t_nAmbigRight= 0.;
512 int t_tkId= -1;
513 for(int ii=0;ii<trialSeg->nHit();ii++){
514 unsigned int l = trialSeg->hit(ii)->mdcHit()->layernumber();
515 unsigned int w = trialSeg->hit(ii)->mdcHit()->wirenumber();
516 if ( haveDigiTk[l][w]<0 || haveDigiTk[l][w]>100 ) continue;
517 if (t_tkId==-1){
518 t_tkId = haveDigiTk[l][w];
519 }else if (haveDigiTk[l][w] != t_tkId){
520 t_mcRadio = -999;//hits in this seg not in same mc track
521 }
522
523 // test ambig right ratio
524 if ( haveDigiAmbig[l][w] == trialSeg->hit(ii)->ambig() ) t_nAmbigRight++;
525 }
526
527 double t_nSame = 0.;
528 for(int ii=0;ii<trialSeg->nHit();ii++){
529 unsigned int l = trialSeg->hit(ii)->mdcHit()->layernumber();
530 unsigned int w = trialSeg->hit(ii)->mdcHit()->wirenumber();
531 if (haveDigiTk[l][w] == t_tkId){ ++t_nSame; }
532 if(t_mcRadio>-998.) t_mcRadio = t_nSame/nInSeg;
533 }
534 g_findSegPat = iPatt;
535 if(3==nInPatt) g_findSegPat34 = 3;
536 else g_findSegPat34 = 4;
537 g_findSegSl = slay->slayNum();
538 g_findSegMc = t_mcRadio;
539 g_findSegAmbig = t_nAmbigRight/nInSeg;
540 g_findSegChi2Add = span.chisq / (nInSeg - 2);
541 g_findSegNhit = nInSeg;
542 g_tupleFindSeg->write();
543 }
544
545 //--keep only one segment for ambig
546 if(3 == nInPatt){
547 segs.append(trialSeg); // Add to list of Segs
548 nSegs++;
549 }else{
550 //debug
551 //cout<<" before insert nBest="<<bestTrialSegs.size()<<endl;
552 //for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
553 // cout<<"after insert bestTrialSeg nHit="<<iter->first<<endl;
554 // iter->second->plotSeg();
555 //}
556 std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.find(trialSeg->nHit());
557 if(iter==bestTrialSegs.end()){
558 bestTrialSegs.insert(std::map<int, MdcSeg*>::value_type(trialSeg->nHit(),trialSeg));
559 if(5 == segs.segPar()->lPrint){
560 std::cout<<" ----insert "<<trialSeg->nHit()<<std::endl;
561 trialSeg->plotSegAll(); std::cout<<" \n "<<std::endl;
562 }
563 } else {
564 if(trialSeg->chisq()<iter->second->chisq()){
565 MdcSeg* tempSeg= iter->second;
566 delete tempSeg;
567 iter->second = trialSeg;
568 if(5 == segs.segPar()->lPrint){
569 std::cout<<" ----update "<<iter->first<<std::endl;
570 trialSeg->plotSegAll(); std::cout<<" \n "<<std::endl;
571 }
572 }else{
573 if(5 == segs.segPar()->lPrint){
574 std::cout<< "DROP TrialSeg " <<std::endl;
575 trialSeg->plotSegAll(); std::cout<<" \n "<<std::endl;
576 }
577 delete trialSeg;
578 }
579 }
580 ////debug
581 //cout<<" after insert nBest="<<bestTrialSegs.size()<<endl;
582 //for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
583 // cout<<"after insert bestTrialSeg nHit="<<iter->first<<endl;
584 // iter->second->plotSeg();
585 //}
586 //if((bestTrialSeg->nHit() == trialSeg->nHit()) && (bestTrialSeg->chisq() > trialSeg->chisq())){
587 // if(5 == segs.segPar()->lPrint) std::cout<< "KEEP trial as best. orignal bestTrialSeg "
588 // << bestTrialSeg->chisq()<<"/ndof "<<bestTrialSeg->nHit()-2<< "> trialSeg->chisq() "
589 // <<trialSeg->chisq()<<"/ndof "<<trialSeg->nHit()-2<<std::endl;
590 // delete bestTrialSeg;
591 // bestTrialSeg = trialSeg;
592 // }
593 }
594
595 //--mark best trialSeg
596 //std::cout<< __LINE__<<" best " <<bestTrialSeg->chisq()<< " trial " << trialSeg->chisq() <<std::endl;
597
598 trialSeg = new MdcSeg(t0);
599 }// end ambiguity loop
600
601
602 //--keep only one segment/Hit for ambig
603 for(std::map<int,MdcSeg*>::iterator iter = bestTrialSegs.begin(); iter != bestTrialSegs.end(); iter++) {
604 segs.append(iter->second); // Add to list of Segs
605 if (5 == segs.segPar()->lPrint) {
606 std::cout<<" append bestTrialSeg of nHit " << iter->first <<std::endl;
607 iter->second->plotSeg(); std::cout<<std::endl;
608 }
609 }
610
611 bestTrialSegs.clear();//empty bestTrialSegs
612
613 nSegs++;
614
615
616 }// end pattern loop
617
618 delete trialSeg;
619 return nSegs;
620}
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
NTuple::Item< double > g_findSegMc
Definition: MdcHistItem.h:207
NTuple::Tuple * g_tupleFindSeg
Definition: MdcHistItem.h:197
NTuple::Item< int > g_findSegPat34
Definition: MdcHistItem.h:205
NTuple::Item< double > g_findSegAmbig
Definition: MdcHistItem.h:208
NTuple::Item< int > g_findSegPat
Definition: MdcHistItem.h:203
int haveDigiTk[43][288]
Definition: MdcHistItem.h:254
NTuple::Item< double > g_findSegChi2Refit
Definition: MdcHistItem.h:201
int haveDigiAmbig[43][288]
Definition: MdcHistItem.h:259
NTuple::Item< double > g_findSegIntercept
Definition: MdcHistItem.h:199
NTuple::Item< double > g_findSegChi2
Definition: MdcHistItem.h:198
NTuple::Item< double > g_findSegChi2Add
Definition: MdcHistItem.h:202
NTuple::Item< double > g_findSegSlope
Definition: MdcHistItem.h:200
NTuple::Item< int > g_findSegSl
Definition: MdcHistItem.h:206
NTuple::Item< int > g_findSegNhit
Definition: MdcHistItem.h:204
NTuple::Item< double > g_findSegMc
Definition: MdcHistItem.h:207
NTuple::Tuple * g_tupleFindSeg
Definition: MdcHistItem.h:197
NTuple::Item< int > g_findSegPat34
Definition: MdcHistItem.h:205
NTuple::Item< double > g_findSegAmbig
Definition: MdcHistItem.h:208
NTuple::Item< int > g_findSegPat
Definition: MdcHistItem.h:203
int haveDigiTk[43][288]
Definition: MdcHistItem.h:254
NTuple::Item< double > g_findSegChi2Refit
Definition: MdcHistItem.h:201
int haveDigiAmbig[43][288]
Definition: MdcHistItem.h:259
NTuple::Item< double > g_findSegIntercept
Definition: MdcHistItem.h:199
NTuple::Item< double > g_findSegChi2
Definition: MdcHistItem.h:198
NTuple::Item< double > g_findSegChi2Add
Definition: MdcHistItem.h:202
NTuple::Item< double > g_findSegSlope
Definition: MdcHistItem.h:200
NTuple::Item< int > g_findSegSl
Definition: MdcHistItem.h:206
NTuple::Item< int > g_findSegNhit
Definition: MdcHistItem.h:204
double posRad() const
Definition: BesAngle.h:124
double rad() const
Definition: BesAngle.h:118
static const double pi
Definition: Constants.h:38
const MdcSuperLayer * firstSlay(void) const
Definition: MdcDetector.h:46
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
const MdcLayer * layer() const
Definition: MdcHit.h:56
double rMid(void) const
Definition: MdcLayer.h:36
MdcSWire * getWire(int wire) const
Definition: MdcLayer.h:52
int nWires(void) const
Definition: MdcLayer.h:30
int layNum(void) const
Definition: MdcLayer.h:29
Definition: MdcMap.h:21
bool get(const K &theKey, V &theAnswer) const
double phiE(void) const
Definition: MdcSWire.h:51
MdcSegFinder(int useAllAmbig)
int createSegs(const MdcDetector *gm, MdcSegList &segs, const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits, const MdcHitMap *map, double tbunch)
int count() const
Definition: MdcSegList.cxx:419
void append(MdcSeg *aSeg)
Definition: MdcSegList.cxx:257
void resetSeed(const MdcDetector *gm)
Definition: MdcSegList.cxx:57
MdcSegParams * segPar()
Definition: MdcSegList.h:38
int find3[11]
Definition: MdcSegParams.h:31
double maxChisq
Definition: MdcSegParams.h:17
unsigned patt4[8]
int * allowedPatt3[256]
int * allowedPatt4[256]
unsigned patt3[20]
Definition: MdcSeg.h:42
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
int nHit() const
Definition: MdcSeg.cxx:368
double phi() const
Definition: MdcSeg.h:46
void setFull()
Definition: MdcSeg.h:56
int addHits(MdcLine *span, MdcHit *hits[], const MdcHitMap *, double corr)
Definition: MdcSeg.cxx:230
void plotSegAll() const
Definition: MdcSeg.cxx:159
double slope() const
Definition: MdcSeg.h:47
void setPattern(unsigned thePatt)
Definition: MdcSeg.h:57
MdcHitUse * hit(int i) const
Definition: MdcSeg.h:77
void markHits(const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits) const
Definition: MdcSeg.cxx:148
const MdcSuperLayer * next(void) const
Definition: MdcSuperLayer.h:39
const MdcLayer * lastLayer(void) const
Definition: MdcSuperLayer.h:38
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 index(void) const
Definition: MdcSuperLayer.h:20
int slayNum(void) const
Definition: MdcSuperLayer.h:43
int countbits(unsigned word)
Definition: countBits.h:5
double mdcWrapAng(double phi1, double phi2)
Definition: mdcWrapAng.h:12
int mdcWrapWire(int wireIn, int nCell)
Definition: mdcWrapWire.h:6