10#include "TrkReco/TCircle.h"
11#include "TrkReco/TCurlFinder.h"
12#include "TrkReco/TMDCWire.h"
13#include "TrkReco/TMDCWireHit.h"
14#include "TrkReco/TMLink.h"
15#include "TrkReco/TSegmentCurl.h"
16#include "TrkReco/TTrack.h"
22#include "MdcTables/MdcTables.h"
26#define DEBUG_CURL_DUMP 0
27#define DEBUG_CURL_SEGMENT 0
28#define DEBUG_CURL_GNUPLOT 0
29#define DEBUG_CURL_MC 0
31#if ( DEBUG_CURL_DUMP + DEBUG_CURL_GNUPLOT + DEBUG_CURL_MC )
32# include "TrkReco/TMDCWireHitMC.h"
33# include "TrkReco/TTrackHEP.h"
37static int debugMcFlag = 1;
44 : m_builder(
"CurlBuilder" )
45 , m_fitter(
"TCurlFinder Fitter" )
46 , m_debugCdcFrame( false )
47 , m_debugPlotFlag( 0 )
48 , m_debugFileNumber( 0 )
49 , m_pmgnIMF( nullptr ) {
56 const unsigned min_segment,
const unsigned min_salvage,
57 const double bad_distance_for_salvage,
const double good_distance_for_salvage,
58 const unsigned min_sequence,
const unsigned min_fullwire,
59 const double range_for_axial_search,
const double range_for_stereo_search,
60 const unsigned superlayer_for_stereo_search,
const double range_for_axial_last2d_search,
61 const double range_for_stereo_last2d_search,
const double trace2d_distance,
62 const double trace2d_first_distance,
const double trace3d_distance,
63 const unsigned determine_one_track,
65 const double selector_max_impact,
const double selector_max_sigma,
66 const double selector_strange_pz,
const double selector_replace_dz,
68 const unsigned stereo_2dfind,
const unsigned merge_exe,
const double merge_ratio,
69 const double merge_z_diff,
const double mask_distance,
const double ratio_used_wire,
70 const double range_for_stereo1,
const double range_for_stereo2,
71 const double range_for_stereo3,
const double range_for_stereo4,
72 const double range_for_stereo5,
const double range_for_stereo6,
74 const double z_cut,
const double z_diff_for_last_attend,
const unsigned svd_reconstruction,
75 const double min_svd_electrons,
const unsigned on_correction,
76 const unsigned output_2dtracks,
const unsigned curl_version,
79 const double minimum_seedLength,
const double minimum_2DTrackLength,
80 const double minimum_3DTrackLength,
const double minimum_closeHitsLength,
81 const double MIN_RADIUS_OF_STRANGE_TRACK,
82 const double ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK )
83 : m_builder(
"CurlBuilder" )
84 , m_fitter(
"TCurlFinder Fitter" )
85 , m_debugCdcFrame( false )
86 , m_debugPlotFlag( 0 )
87 , m_debugFileNumber( 0 )
88 , m_pmgnIMF( nullptr ) {
90 m_param.MIN_SEGMENT = min_segment;
91 m_param.MIN_SALVAGE = min_salvage;
92 m_param.BAD_DISTANCE_FOR_SALVAGE = bad_distance_for_salvage;
93 m_param.GOOD_DISTANCE_FOR_SALVAGE = good_distance_for_salvage;
94 m_param.MIN_SEQUENCE = min_sequence;
95 m_param.MAX_FULLWIRE = min_fullwire;
96 m_param.RANGE_FOR_AXIAL_SEARCH = range_for_axial_search;
97 m_param.RANGE_FOR_STEREO_SEARCH = range_for_stereo_search;
98 m_param.SUPERLAYER_FOR_STEREO_SEARCH = superlayer_for_stereo_search;
99 m_param.RANGE_FOR_AXIAL_LAST2D_SEARCH = range_for_axial_last2d_search;
100 m_param.RANGE_FOR_STEREO_LAST2D_SEARCH = range_for_stereo_last2d_search;
101 m_param.TRACE2D_DISTANCE = trace2d_distance;
102 m_param.TRACE2D_FIRST_SUPERLAYER = trace2d_first_distance;
103 m_param.TRACE3D_DISTANCE = trace3d_distance;
104 m_param.DETERMINE_ONE_TRACK = determine_one_track;
106 m_param.SELECTOR_MAX_IMPACT = selector_max_impact;
107 m_param.SELECTOR_MAX_SIGMA = selector_max_sigma;
108 m_param.SELECTOR_STRANGE_PZ = selector_strange_pz;
109 m_param.SELECTOR_REPLACE_DZ = selector_replace_dz;
111 m_param.STEREO_2DFIND = stereo_2dfind;
112 m_param.MERGE_EXE = merge_exe;
113 m_param.MERGE_RATIO = merge_ratio;
114 m_param.MERGE_Z_DIFF = merge_z_diff;
115 m_param.MASK_DISTANCE = mask_distance;
116 m_param.RATIO_USED_WIRE = ratio_used_wire;
117 m_param.RANGE_FOR_STEREO_FIRST = range_for_stereo1;
118 m_param.RANGE_FOR_STEREO_SECOND = range_for_stereo2;
119 m_param.RANGE_FOR_STEREO_THIRD = range_for_stereo3;
120 m_param.RANGE_FOR_STEREO_FORTH = range_for_stereo4;
121 m_param.RANGE_FOR_STEREO_FIFTH = range_for_stereo5;
122 m_param.RANGE_FOR_STEREO_SIXTH = range_for_stereo6;
124 m_param.Z_CUT = z_cut;
125 m_param.Z_DIFF_FOR_LAST_ATTEND = z_diff_for_last_attend;
126 m_param.SVD_RECONSTRUCTION = svd_reconstruction;
127 m_param.MIN_SVD_ELECTRONS = min_svd_electrons;
128 m_param.ON_CORRECTION = on_correction;
129 m_param.OUTPUT_2DTRACKS = output_2dtracks;
130 m_param.CURL_VERSION = curl_version;
133 m_param.minimum_seedLength = minimum_seedLength;
134 m_param.minimum_2DTrackLength = minimum_2DTrackLength;
135 m_param.minimum_3DTrackLength = minimum_3DTrackLength;
136 m_param.minimum_closeHitsLength = minimum_closeHitsLength;
137 m_param.MIN_RADIUS_OF_STRANGE_TRACK = MIN_RADIUS_OF_STRANGE_TRACK;
138 m_param.ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK = ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK;
141 m_builder.setParam( m_param );
156#if defined( __GNUG__ )
158 if ( ( *a )->maxSeq() < ( *b )->maxSeq() ) {
return 1; }
159 else if ( ( *a )->maxSeq() == ( *b )->maxSeq() ) {
return 0; }
166 if ( ( *a )->maxSeq() < ( *b )->maxSeq() ) {
return 1; }
167 else if ( ( *a )->maxSeq() == ( *b )->maxSeq() ) {
return 0; }
172#if defined( __GNUG__ )
174 if ( ( *a )->position().x() > ( *b )->position().x() ) {
return 1; }
175 else if ( ( *a )->position().x() == ( *b )->position().x() ) {
return 0; }
182 if ( ( *a )->position().x() > ( *b )->position().x() ) {
return 1; }
183 else if ( ( *a )->position().x() == ( *b )->position().x() ) {
return 0; }
190double TCurlFinder::distance(
const double x,
const double y )
const {
191 return sqrt(
x *
x + y * y );
194unsigned TCurlFinder::offset(
const unsigned layerId )
const {
197 if ( layerId == 0 || layerId == 2 || layerId == 4 || layerId == 6 || layerId == 8 ||
198 layerId == 9 || layerId == 11 || layerId == 13 || layerId == 15 || layerId == 17 ||
199 layerId == 18 || layerId == 20 || layerId == 22 || layerId == 24 || layerId == 26 ||
200 layerId == 27 || layerId == 29 || layerId == 31 || layerId == 33 || layerId == 35 ||
201 layerId == 36 || layerId == 38 || layerId == 40 || layerId == 42 || layerId == 44 ||
202 layerId == 45 || layerId == 47 || layerId == 49 )
207unsigned TCurlFinder::layerId(
const double& R )
const {
231 if ( r < 73.0 )
return 0;
232 if ( r <= 85.0 )
return 0;
233 if ( r <= 97.0 )
return 1;
234 if ( r <= 109.0 )
return 2;
235 if ( r <= 121.0 )
return 3;
236 if ( r <= 133.0 )
return 4;
237 if ( r <= 145.0 )
return 5;
238 if ( r <= 157.0 )
return 6;
239 if ( r <= 179.0 )
return 7;
240 if ( r <= 205.2 )
return 8;
241 if ( r <= 221.4 )
return 9;
242 if ( r <= 237.6 )
return 10;
243 if ( r <= 253.8 )
return 11;
244 if ( r <= 270.0 )
return 12;
245 if ( r <= 286.2 )
return 13;
246 if ( r <= 302.4 )
return 14;
247 if ( r <= 318.6 )
return 15;
248 if ( r <= 334.8 )
return 16;
249 if ( r <= 351.0 )
return 17;
250 if ( r <= 367.2 )
return 18;
251 if ( r <= 387.45 )
return 19;
252 if ( r <= 407.7 )
return 20;
253 if ( r <= 423.9 )
return 21;
254 if ( r <= 440.1 )
return 22;
255 if ( r <= 456.3 )
return 23;
256 if ( r <= 472.5 )
return 24;
257 if ( r <= 488.7 )
return 25;
258 if ( r <= 504.9 )
return 26;
259 if ( r <= 521.1 )
return 27;
260 if ( r <= 537.3 )
return 28;
261 if ( r <= 554.5 )
return 29;
262 if ( r <= 569.7 )
return 30;
263 if ( r <= 585.9 )
return 31;
264 if ( r <= 602.1 )
return 32;
265 if ( r <= 618.3 )
return 33;
266 if ( r <= 634.5 )
return 34;
267 if ( r <= 654.75 )
return 35;
268 if ( r <= 675.0 )
return 36;
269 if ( r <= 691.2 )
return 37;
270 if ( r <= 707.4 )
return 38;
271 if ( r <= 723.6 )
return 39;
272 if ( r <= 739.8 )
return 40;
273 if ( r <= 756.0 )
return 41;
274 if ( r <= 772.2 )
return 42;
278unsigned TCurlFinder::maxLocalLayerId(
const unsigned superLayerId )
const {
288 if ( superLayerId == 10 )
return 2;
289 if ( superLayerId >= 0 && superLayerId < 10 )
return 3;
291 std::cerr <<
"Error in the CurlFinder(maxLocalLayerId). superLayerId = " << superLayerId
296int TCurlFinder::nextSuperAxialLayerId(
const unsigned superLayerId,
const int in )
const {
305 if ( superLayerId > 10 || superLayerId < 0 )
307 std::cerr <<
"Error in the CurlFinder(nextSuperAxialLayerId)." << std::endl;
313 if ( superLayerId == 2 || superLayerId == 3 || superLayerId == 4 || superLayerId == 9 ||
315 {
return superLayerId; }
323 if ( ( superLayerId == 3 ) && in == 1 )
return 2;
324 if ( superLayerId == 4 )
326 if ( in == 1 )
return 3;
327 if ( in == 2 )
return 2;
329 if ( superLayerId == 5 || superLayerId == 6 || superLayerId == 7 || superLayerId == 8 ||
332 if ( in == 1 )
return 4;
333 if ( in == 2 )
return 3;
334 if ( in == 3 )
return 2;
336 if ( superLayerId == 10 )
338 if ( in == 1 )
return 9;
339 if ( in == 2 )
return 4;
340 if ( in == 3 )
return 3;
341 if ( in == 4 )
return 2;
344 if ( superLayerId == 0 || superLayerId == 1 )
346 if ( in == -1 )
return 2;
347 if ( in == -2 )
return 3;
348 if ( in == -3 )
return 4;
349 if ( in == -4 )
return 9;
350 if ( in == -5 )
return 10;
352 if ( superLayerId == 2 )
354 if ( in == -1 )
return 3;
355 if ( in == -2 )
return 4;
356 if ( in == -3 )
return 9;
357 if ( in == -4 )
return 10;
359 if ( superLayerId == 3 )
361 if ( in == -1 )
return 4;
362 if ( in == -2 )
return 9;
363 if ( in == -3 )
return 10;
365 if ( superLayerId == 4 )
367 if ( in == -1 )
return 9;
368 if ( in == -2 )
return 10;
370 if ( superLayerId == 5 || superLayerId == 6 || superLayerId == 7 || superLayerId == 8 ||
373 if ( in == -1 )
return 10;
379int TCurlFinder::nextSuperStereoLayerId(
const unsigned superLayerId,
const int in )
const {
388 if ( superLayerId > 10 || superLayerId < 0 )
390 std::cerr <<
"Error in the CurlFinder(nextSuperStereoLayerId)." << std::endl;
396 if ( superLayerId == 0 || superLayerId == 1 || superLayerId == 5 || superLayerId == 6 ||
397 superLayerId == 7 || superLayerId == 8 )
398 {
return superLayerId; }
402 if ( ( superLayerId == 1 || superLayerId == 2 || superLayerId == 3 || superLayerId == 4 ) &&
405 if ( superLayerId == 5 )
407 if ( in == 1 )
return 1;
408 if ( in == 2 )
return 0;
410 if ( superLayerId == 6 )
412 if ( in == 1 )
return 5;
413 if ( in == 2 )
return 1;
414 if ( in == 3 )
return 0;
416 if ( superLayerId == 7 )
418 if ( in == 1 )
return 6;
419 if ( in == 2 )
return 5;
420 if ( in == 3 )
return 1;
421 if ( in == 4 )
return 0;
423 if ( superLayerId == 8 )
425 if ( in == 1 )
return 7;
426 if ( in == 2 )
return 6;
427 if ( in == 3 )
return 5;
428 if ( in == 4 )
return 1;
429 if ( in == 5 )
return 0;
431 if ( superLayerId == 9 || superLayerId == 10 )
433 if ( in == 1 )
return 8;
434 if ( in == 2 )
return 7;
435 if ( in == 3 )
return 6;
436 if ( in == 4 )
return 5;
437 if ( in == 5 )
return 1;
438 if ( in == 6 )
return 0;
441 if ( superLayerId == 0 )
443 if ( in == -1 )
return 1;
444 if ( in == -2 )
return 5;
445 if ( in == -3 )
return 6;
446 if ( in == -4 )
return 7;
447 if ( in == -5 )
return 8;
449 if ( superLayerId == 1 || superLayerId == 2 || superLayerId == 3 || superLayerId == 4 )
451 if ( in == -1 )
return 5;
452 if ( in == -2 )
return 6;
453 if ( in == -3 )
return 7;
454 if ( in == -4 )
return 8;
456 if ( superLayerId == 5 )
458 if ( in == -1 )
return 6;
459 if ( in == -2 )
return 7;
460 if ( in == -3 )
return 8;
462 if ( superLayerId == 6 )
464 if ( in == -1 )
return 7;
465 if ( in == -2 )
return 8;
467 if ( superLayerId == 7 )
469 if ( in == -1 )
return 8;
475unsigned TCurlFinder::nAxialHits(
const double& r )
const {
477 const double eps = 0.2;
513 if ( r < 20.52 -
eps )
return 0;
514 else if ( r < 22.14 -
eps )
return 1;
515 else if ( r < 23.76 -
eps )
return 2;
516 else if ( r < 25.38 -
eps )
return 3;
517 else if ( r < 27.0 -
eps )
return 4;
518 else if ( r < 28.62 -
eps )
return 5;
519 else if ( r < 30.24 -
eps )
return 6;
520 else if ( r < 31.86 -
eps )
return 7;
521 else if ( r < 33.48 -
eps )
return 8;
522 else if ( r < 35.1 -
eps )
return 9;
523 else if ( r < 36.72 -
eps )
return 10;
524 else if ( r < 38.34 -
eps )
return 11;
525 else if ( r < 67.5 -
eps )
return 12;
526 else if ( r < 69.12 -
eps )
return 13;
527 else if ( r < 70.74 -
eps )
return 14;
528 else if ( r < 72.36 -
eps )
return 15;
529 else if ( r < 73.98 -
eps )
return 16;
530 else if ( r < 75.6 -
eps )
return 17;
531 else if ( r < 77.22 -
eps )
return 18;
543 madeList.removeAll();
544 for (
unsigned i = 0, size = originalList.length(); i < size; ++i )
545 madeList.append( originalList[i]->list() );
546 madeList.remove( removeList );
554 madeList.removeAll();
555 madeList.append( originalList );
556 madeList.remove( removeList );
562 HepAListDeleteAll( m_allAxialHitsOriginal );
563 HepAListDeleteAll( m_allStereoHitsOriginal );
564 HepAListDeleteAll( m_segmentList );
565 HepAListDeleteAll( m_allCircles );
566 HepAListDeleteAll( m_allTracks );
568 m_unusedAxialHitsOriginal.removeAll();
569 m_unusedStereoHitsOriginal.removeAll();
570 m_unusedAxialHits.removeAll();
571 m_unusedStereoHits.removeAll();
572 m_removedHits.removeAll();
573 m_circles.removeAll();
574 m_tracks.removeAll();
575 m_2dTracks.removeAll();
577 for (
int i = 0; i < 19; ++i ) m_unusedAxialHitsOnEachLayer[i].removeAll();
578 for (
int i = 0; i < 24; ++i ) m_unusedStereoHitsOnEachLayer[i].removeAll();
579 for (
int i = 0; i < 5; ++i ) m_unusedAxialHitsOnEachSuperLayer[i].removeAll();
580 for (
int i = 0; i < 6; ++i ) m_unusedStereoHitsOnEachSuperLayer[i].removeAll();
581 m_hitsOnInnerSuperLayer.removeAll();
590#if ( DEBUG_CURL_DUMP + DEBUG_CURL_GNUPLOT + DEBUG_CURL_MC )
591 Belle_event_Manager& evtMgr = Belle_event_Manager::get_manager();
593 if ( evtMgr.count() != 0 && evtMgr[0].ExpMC() != 2 ) debugMcFlag = 0;
594 m_debugCdcFrame =
false;
596#if !( DEBUG_CURL_MC )
598 std::cout <<
"(TCurlFinder)Plot Menu : All Off = 0, Interactive = 1, All On = 2"
600 cin >> m_debugPlotFlag;
604 makeWireHitsListsSegments( axialHits, stereoHits );
605# if DEBUG_CURL_SEGMENT
606 std::cout <<
"(TCurlFinder)# of segment = " << m_segmentList.length() << std::endl;
607 debugCheckSegments0();
608 debugCheckSegments1();
609 debugCheckSegments2();
612 if ( checkSortSegments() == 0 )
return 0;
614 if ( m_debugPlotFlag )
617 if ( m_debugPlotFlag == 1 )
619 std::cout <<
"(TCurlFinder) Do you want to see Segment Plot? : yes = 1, no = other #"
625 for (
int i = 0; i < m_segmentList.length(); ++i )
626 plotSegment( m_segmentList[i]->list(), 0 );
631 makeCurlTracks( tracks, tracks2D );
633 makeWithMC( axialHits, stereoHits, tracks );
637 unsigned n = tracks2D.length();
638 for (
unsigned i = 0; i <
n; i++ ) tracks2D[i]->quality(
TrackQuality2D );
656 unsigned size = axialList.length();
657 for (
unsigned i = 0; i < size; ++i )
659 if ( axialList[i]->reccdc()->tdc > 500 )
continue;
662 m_allAxialHitsOriginal.append(
new TMLink( 0, axialList[i] ) );
663 if ( axialList[i]->wire()->superLayerId() <= 3 )
664 m_hitsOnInnerSuperLayer.append( axialList[i] );
667 size = m_allAxialHitsOriginal.length();
668 for (
unsigned i = 0; i < size; ++i )
670 if ( !( m_allAxialHitsOriginal[i]->hit()->state() &
WireHitUsed ) )
675 m_allAxialHitsOriginal[i]->hit()->state() & ( ~WireHitInvalidForFit );
676 m_allAxialHitsOriginal[i]->hit()->state( newState );
678 m_unusedAxialHitsOriginal.append( m_allAxialHitsOriginal[i] );
681 m_unusedAxialHits = m_unusedAxialHitsOriginal;
683 size = stereoList.length();
684 for (
unsigned i = 0; i < size; ++i )
686 if ( stereoList[i]->reccdc()->tdc > 500 )
continue;
689 m_allStereoHitsOriginal.append(
new TMLink( 0, stereoList[i] ) );
690 if ( stereoList[i]->wire()->superLayerId() <= 3 )
691 m_hitsOnInnerSuperLayer.append( stereoList[i] );
694 size = m_allStereoHitsOriginal.length();
695 for (
unsigned i = 0; i < size; ++i )
697 if ( !( m_allStereoHitsOriginal[i]->hit()->state() &
WireHitUsed ) )
702 m_allStereoHitsOriginal[i]->hit()->state() & ( ~WireHitInvalidForFit );
703 m_allStereoHitsOriginal[i]->hit()->state( newState );
705 m_unusedStereoHitsOriginal.append( m_allStereoHitsOriginal[i] );
708 m_unusedStereoHits = m_unusedStereoHitsOriginal;
711 size = m_unusedAxialHitsOriginal.length();
712 for (
unsigned i = 0; i < size; ++i )
714 m_unusedAxialHitsOnEachLayer
715 [m_unusedAxialHitsOriginal[i]->hit()->wire()->axialStereoLayerId()]
716 .append( m_unusedAxialHitsOriginal[i] );
718 size = m_unusedStereoHitsOriginal.length();
719 for (
unsigned i = 0; i < size; ++i )
721 m_unusedStereoHitsOnEachLayer
722 [m_unusedStereoHitsOriginal[i]->hit()->wire()->axialStereoLayerId()]
723 .append( m_unusedStereoHitsOriginal[i] );
727 linkNeighboringWires( m_unusedAxialHitsOnEachLayer, 19 );
728 linkNeighboringWires( m_unusedStereoHitsOnEachLayer, 24 );
733 m_segmentList.removeAll();
734 for (
unsigned i = 0; i < 5; ++i )
735 if ( m_unusedAxialHitsOnEachSuperLayer[i].length() > 0 )
736 createSegments( m_unusedAxialHitsOnEachSuperLayer[i] );
737 for (
unsigned i = 0; i < 6; ++i )
738 if ( m_unusedStereoHitsOnEachSuperLayer[i].length() > 0 )
739 createSegments( m_unusedStereoHitsOnEachSuperLayer[i] );
742void TCurlFinder::linkNeighboringWires(
AList<TMLink>* list,
const unsigned num ) {
747 for (
int i = 0; i <
num; ++i )
749 if ( list[i].length() == 0 )
continue;
750 for (
int j = 0; j < list[i].length(); ++j )
756 if ( i == 0 || i == 4 || i == 8 || i == 12 || i == 16 )
goto outer;
758 else if (
num == 24 )
760 if ( i == 0 || i == 4 || i == 8 || i == 12 || i == 16 || i == 20 )
goto outer;
763 for (
int k = 0; k < list[i - 1].length(); ++k )
765 if ( list[i - 1][k]->hit()->wire()->localId() ==
766 list[i][j]->wire()->neighbor( 1 )->localId() )
767 setNeighboringWires( list[i][j], list[i - 1][k] );
768 else if ( list[i - 1][k]->hit()->wire()->localId() ==
769 list[i][j]->wire()->neighbor( 0 )->localId() )
770 setNeighboringWires( list[i][j], list[i - 1][k] );
776 if ( i == 3 || i == 7 || i == 11 || i == 15 || i == 18 )
goto same;
778 else if (
num == 24 )
780 if ( i == 3 || i == 7 || i == 11 || i == 15 || i == 19 || i == 23 )
goto same;
782 for (
int k = 0; k < list[i + 1].length(); ++k )
784 if ( list[i + 1][k]->hit()->wire()->localId() ==
785 list[i][j]->hit()->wire()->neighbor( 4 )->localId() )
786 setNeighboringWires( list[i][j], list[i + 1][k] );
787 else if ( list[i + 1][k]->wire()->localId() ==
788 list[i][j]->wire()->neighbor( 5 )->localId() )
789 setNeighboringWires( list[i][j], list[i + 1][k] );
793 for (
int k = 0; k < list[i].length(); ++k )
795 if ( list[i][k]->hit()->wire()->localId() ==
796 list[i][j]->hit()->wire()->localIdForPlus() + 1 )
797 { setNeighboringWires( list[i][j], list[i][k] ); }
798 else if ( list[i][k]->hit()->wire()->localId() ==
799 list[i][j]->hit()->wire()->localIdForMinus() - 1 )
800 { setNeighboringWires( list[i][j], list[i][k] ); }
806void TCurlFinder::setNeighboringWires(
TMLink* list,
const TMLink* next ) {
809 for (
int i = 0; i < 6; ++i )
813 list->
neighbor( i,
const_cast<TMLink*
>( next ) );
819void TCurlFinder::createSuperLayer(
void ) {
821 for (
int i = 0; i < 4; ++i )
823 if ( m_unusedAxialHitsOnEachLayer[i].length() > 0 )
824 m_unusedAxialHitsOnEachSuperLayer[0].append( m_unusedAxialHitsOnEachLayer[i] );
825 if ( m_unusedAxialHitsOnEachLayer[i + 4].length() > 0 )
826 m_unusedAxialHitsOnEachSuperLayer[1].append( m_unusedAxialHitsOnEachLayer[i + 4] );
827 if ( m_unusedAxialHitsOnEachLayer[i + 8].length() > 0 )
828 m_unusedAxialHitsOnEachSuperLayer[2].append( m_unusedAxialHitsOnEachLayer[i + 8] );
829 if ( m_unusedAxialHitsOnEachLayer[i + 12].length() > 0 )
830 m_unusedAxialHitsOnEachSuperLayer[3].append( m_unusedAxialHitsOnEachLayer[i + 12] );
831 if ( m_unusedAxialHitsOnEachLayer[i + 16].length() > 0 && i + 16 < 19 )
832 m_unusedAxialHitsOnEachSuperLayer[4].append( m_unusedAxialHitsOnEachLayer[i + 16] );
834 for (
int i = 0; i < 4; ++i )
836 if ( m_unusedStereoHitsOnEachLayer[i].length() > 0 )
837 m_unusedStereoHitsOnEachSuperLayer[0].append( m_unusedStereoHitsOnEachLayer[i] );
838 if ( m_unusedStereoHitsOnEachLayer[i + 4].length() > 0 )
839 m_unusedStereoHitsOnEachSuperLayer[1].append( m_unusedStereoHitsOnEachLayer[i + 4] );
840 if ( m_unusedStereoHitsOnEachLayer[i + 8].length() > 0 )
841 m_unusedStereoHitsOnEachSuperLayer[2].append( m_unusedStereoHitsOnEachLayer[i + 8] );
842 if ( m_unusedStereoHitsOnEachLayer[i + 12].length() > 0 )
843 m_unusedStereoHitsOnEachSuperLayer[3].append( m_unusedStereoHitsOnEachLayer[i + 12] );
844 if ( m_unusedStereoHitsOnEachLayer[i + 16].length() > 0 )
845 m_unusedStereoHitsOnEachSuperLayer[4].append( m_unusedStereoHitsOnEachLayer[i + 16] );
846 if ( m_unusedStereoHitsOnEachLayer[i + 20].length() > 0 )
847 m_unusedStereoHitsOnEachSuperLayer[5].append( m_unusedStereoHitsOnEachLayer[i + 20] );
854 AList<TMLink> seedStock;
856 TSegmentCurl* segment =
857 new TSegmentCurl( list[0]->hit()->wire()->superLayerId(),
858 maxLocalLayerId( list[0]->hit()->wire()->superLayerId() ) );
860 segment->
append( list[0] );
861 TMLink* seed = list[0];
864 searchSegment( seed, list, seedStock, segment );
865 if ( seedStock.length() > 0 )
868 seedStock.remove( seed );
871 else if ( segment->
size() >= m_param.MIN_SEGMENT )
874 m_segmentList.append( segment );
876 std::cout <<
"Segment # = " << m_segmentList.length() << std::endl;
880 else {
delete segment; }
881 }
while ( list.length() > 0 );
886 for (
int i = 0; i < 6; ++i )
890 if ( !findLink( seed->
neighbor( i ), list ) )
continue;
892 seedStock.append( seed->
neighbor( i ) );
903 unsigned size = list.length();
904 if ( size == 0 )
return NULL;
905 for (
unsigned i = 0; i < size; ++i )
907 if ( seed == list[i] )
return list[i];
916int TCurlFinder::checkSortSegments(
void ) {
919 std::cout <<
"(TCurlFinder)checking and sorting segments..." << std::endl;
921 unsigned length = m_segmentList.length();
922 if ( length == 0 )
return 0;
923 checkExceptionalSegmentsType03();
925 checkExceptionalSegmentsType01();
928 std::cout <<
"(TCurlFinder)...done check and sort of segments." << std::endl;
933void TCurlFinder::checkExceptionalSegmentsType03(
void ) {
934 int max = m_param.MAX_FULLWIRE;
936 if (
max == 7 ) nMinWires = 21;
937 else if (
max == 6 ) nMinWires = 19;
938 else if (
max == 5 ) nMinWires = 18;
939 else if (
max == 4 ) nMinWires = 16;
940 else if (
max == 3 ) nMinWires = 14;
941 else if (
max == 2 ) nMinWires = 12;
942 else if (
max == 1 ) nMinWires = 10;
943 else if (
max == 0 ) nMinWires = 7;
945 AList<TSegmentCurl> removeList;
946 for (
unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
948 if ( m_segmentList[i]->size() >= nMinWires )
950 unsigned nWires = m_segmentList[i]->size();
951 unsigned n6Wires = 0;
952 for (
unsigned j = 0; j < nWires; ++j )
954 if ( ( ( m_segmentList[i]->list() )[j] )->neighbor( 5 ) ) ++n6Wires;
955 if ( n6Wires >
max )
break;
957 if ( n6Wires <=
max )
continue;
958 removeList.append( m_segmentList[i] );
959#if DEBUG_CURL_SEGMENT
960 writeSegment( m_segmentList[i]->list(), 3 );
964 if ( removeList.length() >= 1 )
967 std::cout <<
"(TCurlFinder)removing large segments: # = " << removeList.length()
970 m_segmentList.remove( removeList );
971 HepAListDeleteAll( removeList );
975void TCurlFinder::checkExceptionalSegmentsType02(
void ) {
978 AList<TSegmentCurl> removeList;
979 for (
unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
981 int lSize =
max * 3 + hmax * 3;
983 if ( m_segmentList[i]->superLayerId() == 1 || m_segmentList[i]->superLayerId() == 3 )
985 lSize =
max * 2 + hmax;
988 if ( m_segmentList[i]->superLayerId() == 5 || m_segmentList[i]->superLayerId() == 7 ||
989 m_segmentList[i]->superLayerId() == 9 )
991 lSize =
max * 2 + hmax * 2;
994 if ( m_segmentList[i]->superLayerId() == 4 || m_segmentList[i]->superLayerId() == 6 ||
995 m_segmentList[i]->superLayerId() == 8 || m_segmentList[i]->superLayerId() == 10 )
996 lSize =
max * 3 + hmax * 2;
997 if ( m_segmentList[i]->size() < lSize )
continue;
999 for (
unsigned j = 0, size = m_segmentList[i]->maxLocalLayerId(); j < size; ++j )
1001 if ( m_segmentList[i]->sizeOfLayer( j ) >=
max ) ++nL;
1003 if ( nL < lNum )
continue;
1004 removeList.append( m_segmentList[i] );
1006#if DEBUG_CURL_SEGMENT
1010 if ( removeList.length() >= 1 )
1013 std::cout <<
"(TCurlFinder)removing large segments: # = " << removeList.length()
1016 m_segmentList.remove( removeList );
1017 HepAListDeleteAll( removeList );
1021void TCurlFinder::checkExceptionalSegmentsType01(
void ) {
1022 for (
unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
1024 if ( m_segmentList[i]->maxLocalLayerId() != m_segmentList[i]->layerIdOfMaxSeq() &&
1025 m_segmentList[i]->maxSeq() >= m_param.MIN_SEQUENCE )
1027 unsigned innerHits = 0;
1028 if ( m_segmentList[i]->layerIdOfMaxSeq() == 0 )
continue;
1029 TSegmentCurl* outer =
new TSegmentCurl( m_segmentList[i]->superLayerId(),
1030 m_segmentList[i]->maxLocalLayerId() );
1031 for (
unsigned j = 0, size = m_segmentList[i]->size(); j < size; ++j )
1033 if ( m_segmentList[i]->layerIdOfMaxSeq() + 1 <=
1034 ( m_segmentList[i]->list() )[j]->hit()->wire()->localLayerId() &&
1035 ( m_segmentList[i]->list() )[j]->hit()->wire()->localLayerId() <=
1036 m_segmentList[i]->maxLocalLayerId() )
1037 { outer->
append( ( m_segmentList[i]->list() )[j] ); }
1038 else if ( m_segmentList[i]->layerIdOfMaxSeq() - 1 >=
1039 ( m_segmentList[i]->list() )[j]->hit()->wire()->localLayerId() )
1042 if ( innerHits != 0 && outer->
size() != 0 )
1045 std::cout <<
"(TCurlFinder)removing some wires in the segment." << std::endl;
1047#if DEBUG_CURL_SEGMENT
1050 m_segmentList[i]->remove(
const_cast<AList<TMLink>&
>( outer->
list() ) );
1073 AList<TSegmentCurl> segmentList = m_segmentList;
1076 for (
unsigned i = 0, size = m_segmentList.length(); i < size; ++i )
1079 make2DTrack( segmentList[i]->list(), segmentList, 1 );
1082 AList<TMLink> tmp( circle->
links() );
1084 std::cout <<
"(TCurlFinder) 2D:Created Circle!!!" << std::endl;
1085 if ( m_debugPlotFlag )
1088 if ( m_debugPlotFlag == 1 )
1091 <<
"(TCurlFinder) Do you want to see Circle Plot(2D)? : yes = 1, no = other #"
1095 if ( noPlot == 1 ) plotCircle( *circle, 0 );
1108 if ( TCircle* dividedCircle = dividing2DTrack( circle ) )
1111 std::cout <<
"(TCurlFinder) 2D:dividing...good...2 Circles!!!" << std::endl;
1113 TTrack *track1( NULL ), *track2( NULL );
1114 int ok2d[2] = { 0, 0 };
1115 int ok3d[2] = { 0, 0 };
1118 if ( trace2DTrack( circle ) && check2DCircle( circle ) &&
1123 std::cout <<
"(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1125 track1 = make3DTrack( circle, segmentList );
1130 if ( trace2DTrack( dividedCircle ) && check2DCircle( dividedCircle ) &&
1131 dividedCircle->fitForCurl( 1 ) != -1 )
1135 std::cout <<
"(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1137 track2 = make3DTrack( dividedCircle, segmentList );
1139 if ( track1 && track2 )
1142 std::cout <<
"(TCurlFinder) 3D:Create Track!!! in track1 && track2"
1145 salvage3DTrack( track1,
true );
1146 salvage3DTrack( track2,
true );
1148 std::cout <<
"(TCurlFinder) 1:dz = " << track1->helix().dz()
1149 <<
", 2:dz = " << track2->helix().dz() << std::endl;
1151 if ( m_param.DETERMINE_ONE_TRACK )
1153 if ( fabs( track1->helix().dz() ) < fabs( track2->helix().dz() ) )
1155 m_tracks.remove( track2 );
1156 if ( merge3DTrack( track1, tracks ) )
1157 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1161 mask3DTrack( track1, tmp );
1162 tmp.append( track1->links() );
1167 m_tracks.remove( track1 );
1168 if ( merge3DTrack( track2, tracks ) )
1169 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1173 mask3DTrack( track2, tmp );
1174 tmp.append( track2->links() );
1180 int isSaved[2] = { 0, 0 };
1181 if ( merge3DTrack( track1, tracks ) )
1183 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1186 mask3DTrack( track1, tmp );
1187 tmp.append( track1->links() );
1191 if ( merge3DTrack( track2, tracks ) )
1193 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1196 mask3DTrack( track2, tmp );
1197 tmp.append( track2->links() );
1201 if ( isSaved[0] == 1 && isSaved[1] == 1 )
1203 track1->daughter( track2 );
1204 track2->daughter( track1 );
1211 std::cout <<
"(TCurlFinder) 3D:Create Track!!! in track1" << std::endl;
1213 salvage3DTrack( track1,
true );
1214 if ( merge3DTrack( track1, tracks ) )
1215 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1218 mask3DTrack( track1, tmp );
1219 tmp.append( track1->links() );
1225 std::cout <<
"(TCurlFinder) 3D:Create Track!!! in track2" << std::endl;
1227 salvage3DTrack( track2,
true );
1228 if ( merge3DTrack( track2, tracks ) )
1229 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1232 mask3DTrack( track2, tmp );
1233 tmp.append( track2->links() );
1237 if ( m_param.OUTPUT_2DTRACKS )
1240 if ( ok2d[0] == 1 && ok3d[0] == 0 )
1242 removeStereo( *circle );
1245 if ( fitWDD( *circle, chi2_2d, ndf_2d ) )
1247 TTrack* trk2d =
new TTrack( *circle );
1248 trk2d->_ndf = ndf_2d;
1249 trk2d->_chi2 = chi2_2d;
1250 m_2dTracks.append( trk2d );
1251 m_allTracks.append( trk2d );
1255 { std::cout <<
"(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1258 if ( ok2d[1] == 1 && ok3d[1] == 0 )
1260 removeStereo( *dividedCircle );
1263 if ( fitWDD( *dividedCircle, chi2_2d, ndf_2d ) )
1265 TTrack* trk2d =
new TTrack( *dividedCircle );
1266 trk2d->_ndf = ndf_2d;
1267 trk2d->_chi2 = chi2_2d;
1268 m_2dTracks.append( trk2d );
1269 m_allTracks.append( trk2d );
1273 { std::cout <<
"(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1281 std::cout <<
"(TCurlFinder) 2D:dividing...no good...1 Circles!!!" << std::endl;
1287 if ( trace2DTrack( circle ) && check2DCircle( circle ) &&
1291 std::cout <<
"(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1294 TTrack* track3 = make3DTrack( circle, segmentList );
1298 std::cout <<
"(TCurlFinder) 3D:Create Track!!! in track3" << std::endl;
1300 salvage3DTrack( track3,
true );
1301 if ( merge3DTrack( track3, tracks ) )
1302 if ( check3DTrack( track3 ) && trace3DTrack( track3 ) )
1305 mask3DTrack( track3, tmp );
1306 tmp.append( track3->
links() );
1310 if ( m_param.OUTPUT_2DTRACKS )
1313 if ( ok2d == 1 && ok3d == 0 )
1315 removeStereo( *circle );
1318 if ( fitWDD( *circle, chi2_2d, ndf_2d ) )
1320 TTrack* trk2d =
new TTrack( *circle );
1321 trk2d->_ndf = ndf_2d;
1322 trk2d->_chi2 = chi2_2d;
1323 m_2dTracks.append( trk2d );
1324 m_allTracks.append( trk2d );
1328 { std::cout <<
"(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1334 m_unusedAxialHits.remove( tmp );
1335 m_unusedStereoHits.remove( tmp );
1336 for (
unsigned ii = 0, nsize = m_segmentList.length(); ii < nsize; ++ii )
1338 m_segmentList[ii]->remove( tmp );
1339 if ( m_segmentList[ii]->list().length() < m_param.MIN_SEGMENT )
1340 m_segmentList[ii]->removeAll();
1343 segmentList[i]->removeAll();
1353 std::cout <<
"(TCurlFinder)MDC Rec Track # 3D = " << m_tracks.length()
1354 <<
", 2D = " << m_2dTracks.length() << std::endl;
1355 std::cout <<
"3D Track List" << std::endl;
1356 for (
int j = 0; j < m_tracks.length(); ++j )
1358 m_tracks[j]->setFinderType( 3 );
1359 unsigned nA = 0, nS = 0;
1360 unsigned nAOK = 0, nSOK = 0;
1361 for (
unsigned i = 0, size = m_tracks[j]->nLinks(); i < size; ++i )
1363 if ( m_tracks[j]->links()[i]->wire()->stereo() ) ++nS;
1368 if ( m_tracks[j]->links()[i]->wire()->stereo() ) ++nSOK;
1372 std::cout <<
"(TCurlFinder) #" << j <<
": wire info...A+S: " << m_tracks[j]->nLinks()
1373 <<
", A: " << nAOK <<
"/" << nA <<
", S: " << nSOK <<
"/" << nS << std::endl;
1374 if ( m_tracks[j]->daughter() ) std::cout <<
"(TCurlFinder) Relation = EXIST" << std::endl;
1375 else std::cout <<
"(TCurlFinder) Relation = NO EXIST" << std::endl;
1377 std::cout <<
"2D Track List" << std::endl;
1378 for (
int j = 0; j < m_2dTracks.length(); ++j )
1380 unsigned nA = 0, nS = 0;
1381 unsigned nAOK = 0, nSOK = 0;
1382 for (
unsigned i = 0, size = m_2dTracks[j]->nLinks(); i < size; ++i )
1384 if ( m_2dTracks[j]->links()[i]->wire()->stereo() ) ++nS;
1389 if ( m_2dTracks[j]->links()[i]->wire()->stereo() ) ++nSOK;
1393 std::cout <<
"(TCurlFinder) #" << j <<
": wire info...A+S: " << m_2dTracks[j]->nLinks()
1394 <<
", A: " << nAOK <<
"/" << nA <<
", S: " << nSOK <<
"/" << nS
1395 <<
", Chi2: " << m_2dTracks[j]->chi2() <<
", Ndf: " << m_2dTracks[j]->ndf()
1397 if ( m_2dTracks[j]->daughter() )
1398 std::cout <<
"(TCurlFinder) Relation = EXIST" << std::endl;
1399 else std::cout <<
"(TCurlFinder) Relation = NO EXIST" << std::endl;
1404 m_allTracks.remove( m_tracks );
1405 checkRelation( m_tracks );
1406 tracks.append( m_tracks );
1407 if ( m_param.OUTPUT_2DTRACKS )
1410 m_allTracks.remove( m_2dTracks );
1411 tracks2D.append( m_2dTracks );
1415void TCurlFinder::check2DTracks(
void ) {
1416 if ( m_2dTracks.length() == 0 )
return;
1417 AList<TMLink> allWires_3Dtrks;
1418 for (
int i = 0; i < m_tracks.length(); ++i )
1419 { allWires_3Dtrks.append( m_tracks[i]->links() ); }
1422 for (
int i = 0; i < m_2dTracks.length(); ++i )
1424 AList<TMLink> usedWires;
1425 for (
int j = 0; j < m_2dTracks[i]->nLinks(); ++j )
1428 for (
int k = 0; k < allWires_3Dtrks.length(); ++k )
1430 if ( m_2dTracks[i]->links()[j]->wire()->
id() == allWires_3Dtrks[k]->wire()->
id() )
1436 if ( ok == 0 ) { usedWires.append( m_2dTracks[i]->links()[j] ); }
1440 m_2dTracks[i]->remove( usedWires );
1445 unsigned nT = list.length();
1446 if ( nT <= 1 )
return;
1447 for (
unsigned i = 0; i < nT; ++i )
1449 if ( list[i]->daughter() )
1452 for (
unsigned j = 0; j < nT; ++j )
1454 if ( i != j && list[i]->daughter() == list[j] )
1460 if ( isHere == 0 ) { list[i]->daughter( NULL ); }
1466 AList<TMLink> positive, negative;
1467 for (
unsigned i = 0, size = circle->
nLinks(); i < size; ++i )
1469 if ( circle->
center().x() * circle->
links()[i]->hit()->wire()->xyPosition().y() -
1470 circle->
center().y() * circle->
links()[i]->hit()->wire()->xyPosition().x() >
1472 { positive.append( circle->
links()[i] ); }
1473 else { negative.append( circle->
links()[i] ); }
1475 if ( positive.length() > negative.length() )
1477 circle->
remove( negative );
1479 if ( negative.length() >= 3 )
1481 TCircle* new_circle =
new TCircle( negative );
1482 m_allCircles.append( new_circle );
1486 else {
return NULL; }
1490 circle->
remove( positive );
1492 if ( positive.length() >= 3 )
1494 TCircle* new_circle =
new TCircle( positive );
1495 m_allCircles.append( new_circle );
1499 else {
return NULL; }
1503void TCurlFinder::assignTracks(
void ) {
1505 for (
int i = 0, size = m_tracks.length(); i < size; ++i )
1513 for (
int i = 0, size = m_2dTracks.length(); i < size; ++i )
1521 if ( *(
static_cast<const double*
>( i ) ) > *(
static_cast<const double*
>( j ) ) )
return 1;
1522 if ( *(
static_cast<const double*
>( i ) ) < *(
static_cast<const double*
>( j ) ) )
return -1;
1526int TCurlFinder::trace2DTrack(
TCircle* circle ) {
1528 unsigned nSize = circle->
links().length();
1529 if ( nSize == 0 )
return 0;
1530 double r = fabs( circle->
radius() );
1531 if ( r < 0.01 )
return 0;
1532 double cx = circle->
center().x();
1533 double cy = circle->
center().y();
1534 double th = atan2( -cy, -cx );
1535 if ( th < 0. ) th += 2. *
M_PI;
1537 unsigned innerOK = 0;
1538 double* angle =
new double[circle->
links().length()];
1539 for (
unsigned i = 0, size = nSize; i < size; ++i )
1541 double th_r = atan2( circle->
links()[i]->wire()->xyPosition().y() - cy,
1542 circle->
links()[i]->wire()->xyPosition().x() - cx );
1543 if ( th_r < 0. ) th_r += 2. *
M_PI;
1544 double diff = th_r - th + 2. *
M_PI;
1545 if ( th_r > th ) diff = th_r - th;
1546 if ( circle->
links()[i]->wire()->superLayerId() <= 2 ) innerOK = 1;
1550 double maxDiffAngle = 0.;
1551 unsigned maxIndex = 0;
1552 for (
unsigned i = 0, size = nSize; i < size - 1; ++i )
1554 if ( angle[i + 1] - angle[i] > maxDiffAngle )
1556 maxDiffAngle = angle[i + 1] - angle[i];
1566 if ( innerOK == 1 )
return 1;
1568 double q = circle->
radius() > 0. ? 1. : -1;
1569 for (
unsigned i = 0, size = m_hitsOnInnerSuperLayer.length(); i < size; ++i )
1571 double mag = distance( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cx,
1572 m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy );
1573 if ( fabs( mag - r ) < m_param.TRACE2D_FIRST_SUPERLAYER &&
1574 q * ( cx * m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() -
1575 cy * m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() ) >
1582bool TCurlFinder::check2DCircle(
TCircle* circle ) {
1583 unsigned nA( nAxialHits( fabs( circle->
radius() ) * 2.0 ) );
1586 static_cast<unsigned>( floor( m_param.RATIO_USED_WIRE *
static_cast<double>( nA ) ) );
1587 if ( nMA < 3 ) nMA = 3;
1589 unsigned nAhits( 0 ), nShits( 0 );
1590 for (
unsigned i = 0, size = circle->
nLinks(); i < size; ++i )
1592 if ( ( circle->
links()[i] )->wire()->axial() ) ++nAhits;
1598 std::cout <<
"(TCurlFinder) 2D:Fail...checking axial wires # = " << nAhits <<
" < "
1599 << nMA << std::endl;
1602 if ( nAhits >= nMA )
return true;
1606bool TCurlFinder::check3DTrack(
TTrack* track ) {
1607 trace3DTrack( track );
1608 unsigned nA = 0, nS = 0;
1609 for (
unsigned i = 0, size = track->
nLinks(); i < size; ++i )
1612 if ( track->
links()[i]->wire()->stereo() ) ++nS;
1614 if ( nA >= 3 && nS >= 2 )
return true;
1616 m_tracks.remove( track );
1618 std::cout <<
"(TCurlFinder) 3D:Checked...Fail...removing this track. Valid Axial # = "
1619 << nA <<
", Stereo # = " << nS << std::endl;
1624int TCurlFinder::trace3DTrack(
TTrack* track ) {
1626 unsigned nSize = track->
links().length();
1629 m_tracks.remove( track );
1635 m_tracks.remove( track );
1640 double th = atan2( -cy, -cx );
1641 if ( th < 0. ) th += 2. *
M_PI;
1643 double* angle =
new double[track->
links().length()];
1644 for (
unsigned i = 0, size = nSize; i < size; ++i )
1646 double th_r = atan2( track->
links()[i]->positionOnTrack().y() - cy,
1647 track->
links()[i]->positionOnTrack().x() - cx );
1648 if ( th_r < 0. ) th_r += 2. *
M_PI;
1649 double diff = th_r - th + 2. *
M_PI;
1650 if ( th_r > th ) diff = th_r - th;
1654 double maxDiffAngle = 0.;
1655 unsigned maxIndex = 0;
1656 for (
unsigned i = 0, size = nSize; i < size - 1; ++i )
1658 if ( angle[i + 1] - angle[i] > maxDiffAngle )
1660 maxDiffAngle = angle[i + 1] - angle[i];
1667 if ( r * maxDiffAngle > m_param.TRACE3D_DISTANCE )
1669 m_tracks.remove( track );
1680 AList<TMLink> list( m_unusedAxialHits );
1681 list.append( m_unusedStereoHits );
1682 list.remove( track->
links() );
1685 AList<TMLink> removeList;
1686 for (
unsigned i = 0, size = list.length(); i < size; ++i )
1688 double d = distance( *track, *( list[i] ) );
1689 if ( d < m_param.MASK_DISTANCE )
1692 list[i]->position( tmp );
1693 removeList.append( list[i] );
1697 int pLayerId1 =
static_cast<int>( layerId( 2. * r ) );
1698 if ( pLayerId1 != 50 ) pLayerId1 -= 1;
1699 int pLayerId2 = pLayerId1 + 2;
1701 AList<TMLink> preCand, cand;
1702 while ( removeList.length() )
1704 preCand.removeAll();
1705 preCand.append( removeList[0] );
1706 if ( removeList.length() >= 2 )
1708 for (
unsigned j = 1, size = removeList.length(); j < size; ++j )
1710 if ( removeList[0]->wire()->layerId() == removeList[j]->wire()->layerId() )
1712 for (
unsigned k = 0,
num = preCand.length(); k <
num; ++k )
1714 if ( preCand[k]->wire()->localIdForPlus() + 1 == removeList[j]->wire()->localId() )
1716 preCand.append( removeList[j] );
1724 if ( preCand[0]->wire()->layerId() >= pLayerId1 &&
1725 preCand[0]->wire()->layerId() <= pLayerId2 )
1726 { cand.append( preCand ); }
1727 else if ( preCand.length() == 2 )
1729 cand.append( preCand );
1731 else if ( preCand.length() == 1 ) { cand.append( preCand[0] ); }
1733 if ( preCand.length() == 1 )
1735 if ( preCand[0]->position().
x() < MASK_DISTANCE ) cand.append( preCand[0] );
1739 if ( preCand[0]->wire()->layerId() >= pLayerId1 &&
1740 preCand[0]->wire()->layerId() <= pLayerId2 )
1741 { cand.append( preCand ); }
1742 else if ( preCand.length() == 2 )
1744 cand.append( preCand );
1749 else { cand.append( removeList[0] ); }
1750 removeList.remove( removeList[0] );
1751 removeList.remove( cand );
1753 maskList.append( cand );
1757 if ( !m_param.MERGE_EXE )
return track;
1759 AList<TTrack> tracks( confTracks );
1760 tracks.append( m_tracks );
1761 tracks.remove( track );
1762 if ( tracks.length() == 0 )
return track;
1768 unsigned bestIndex = 0;
1769 double bestDiff = 1.0e+20;
1771 for (
unsigned i = 0, size = tracks.length(); i < size; ++i )
1773 R = fabs( tracks[i]->helix().radius() );
1774 cX = tracks[i]->helix().center().x();
1775 cY = tracks[i]->helix().center().y();
1776 if ( fabs( r ) * ( 1. - m_param.MERGE_RATIO ) <= R &&
1777 R <= fabs( r ) * ( 1. + m_param.MERGE_RATIO ) )
1779 if ( fabs( cx - cX ) <= fabs( r ) * m_param.MERGE_RATIO &&
1780 fabs( cy - cY ) <= fabs( r ) * m_param.MERGE_RATIO )
1782 double diff = fabs( ( fabs( r ) - fabs( R ) ) * ( cx - cX ) * ( cy - cY ) );
1783 if ( diff < bestDiff )
1791 if ( bestDiff == 1.0e20 )
return track;
1792 R = tracks[bestIndex]->helix().radius();
1793 cX = tracks[bestIndex]->helix().center().x();
1794 cY = tracks[bestIndex]->helix().center().y();
1797 if ( fabs( track->
helix().
dz() - tracks[bestIndex]->helix().dz() ) < m_param.MERGE_Z_DIFF )
1799 if ( track->
nLinks() > tracks[bestIndex]->nLinks() )
1801 m_tracks.remove( tracks[bestIndex] );
1806 m_tracks.remove( track );
1808 std::cout <<
"(TCurlFinder) 3D:Merged...removing this track.(type1)"
1817 bool newTrack(
false ), oldTrack(
false );
1818 unsigned newCounter( 0 ), oldCounter( 0 );
1819 for (
unsigned i = 0, size = m_hitsOnInnerSuperLayer.length(); i < size; ++i )
1824 cX * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY ) -
1825 cY * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cX ) >
1828 cX * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY ) -
1829 cY * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cX ) <
1832 double dist = distance( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cX,
1833 m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY );
1834 if ( dist < fabs( R ) )
1836 if ( fabs( fabs( R ) - dist - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1839 if ( oldCounter >= 3 ) oldTrack =
true;
1844 if ( fabs( dist - fabs( R ) - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1847 if ( oldCounter >= 3 ) oldTrack =
true;
1855 cx * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy ) -
1856 cy * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cx ) >
1859 cx * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy ) -
1860 cy * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cx ) <
1863 double dist = distance( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().
x() - cx,
1864 m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy );
1865 if ( dist < fabs( r ) )
1867 if ( fabs( fabs( r ) - dist - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1870 if ( newCounter >= 3 ) newTrack =
true;
1875 if ( fabs( dist - fabs( r ) - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1878 if ( newCounter >= 3 ) newTrack =
true;
1883 if ( oldTrack && newTrack )
break;
1885 if ( oldTrack && !newTrack )
1887 m_tracks.remove( track );
1889 std::cout <<
"(TCurlFinder) 3D:Merged...removing this track.(type2)" << std::endl;
1893 else if ( !oldTrack && newTrack )
1895 m_tracks.remove( tracks[bestIndex] );
1898 else if ( !oldTrack && !newTrack )
1900 m_tracks.remove( track );
1901 m_tracks.remove( tracks[bestIndex] );
1903 std::cout <<
"(TCurlFinder) 3D:Merged...removing this track.(type3)" << std::endl;
1907 else if ( oldTrack && newTrack )
1909 if ( fabs( track->
helix().
dz() ) > fabs( tracks[bestIndex]->helix().dz() ) &&
1911 fabs( tracks[bestIndex]->helix().dz() ) + m_param.MERGE_Z_DIFF )
1913 m_tracks.remove( track );
1915 std::cout <<
"(TCurlFinder) 3D:Merged...removing this track.(type4)"
1920 else if ( fabs( tracks[bestIndex]->helix().dz() ) > fabs( track->
helix().
dz() ) &&
1921 fabs( tracks[bestIndex]->helix().dz() ) >
1922 fabs( track->
helix().
dz() ) + m_param.MERGE_Z_DIFF )
1924 m_tracks.remove( tracks[bestIndex] );
1932void TCurlFinder::salvage3DTrack(
TTrack* track,
bool half ) {
1933 if ( track->
nLinks() >= m_param.MIN_SALVAGE )
1935 AList<TMLink> list = m_unusedAxialHits;
1936 list.append( m_unusedStereoHits );
1937 list.remove( track->
links() );
1944 AList<TMLink> removeList;
1945 const double Bz = -1000 * getPmgnIMF()->getReferField();
1946 for (
unsigned i = 0, size = list.length(); i < size; ++i )
1949 (
x * list[i]->wire()->xyPosition().y() -
1950 y * list[i]->wire()->xyPosition().
x() ) <
1954#ifdef TRKRECO_DEBUG_DETAIL
1955 std::cout <<
" " << __FILE__ <<
" " << __LINE__ <<
" removeList append " << i
1958 removeList.append( list[i] );
1961 list.remove( removeList );
1964 AList<TMLink> badCand, goodCand;
1966 for (
unsigned j = 0, nLinks = track->
nLinks(); j < nLinks; ++j )
1968 dist = distance( *track, *( track->
links()[j] ) );
1969#ifdef TRKRECO_DEBUG_DETAIL
1970 std::cout <<
" " << __FILE__ <<
" " << __LINE__ <<
" " << j <<
" distance " << dist
1973 if ( dist > m_param.BAD_DISTANCE_FOR_SALVAGE ) badCand.append( track->
links()[j] );
1975 for (
unsigned j = 0, nList = list.length(); j < nList; ++j )
1977 dist = distance( *track, *( list[j] ) );
1978#ifdef TRKRECO_DEBUG_DETAIL
1979 std::cout <<
" " << __FILE__ <<
" " << __LINE__ <<
" " << j <<
" distance " << dist
1982 if ( dist < m_param.GOOD_DISTANCE_FOR_SALVAGE ) goodCand.append( list[j] );
1984 track->TTrackBase::remove( badCand );
1985 track->TTrackBase::append( goodCand );
1986 if ( m_fitter.fit( *track ) < 0 )
1988 track->TTrackBase::remove( goodCand );
1989 track->TTrackBase::append( badCand );
1990 m_fitter.
fit( *track );
1996double TCurlFinder::distance(
const TTrack& track,
const TMLink& link )
const {
2004 double diff = fabs( d - fabs( track.
helix().
radius() ) );
2005 return fabs( link.
hit()->
drift() - diff );
2012 double vCrs( v0.x() * v1.y() - v0.y() * v1.x() );
2013 double vDot( v0.x() * v1.x() + v0.y() * v1.y() );
2014 double dPhi = atan2( vCrs, vDot );
2016 double kappa = a[2];
2019 const double Bz = -1000 * getPmgnIMF()->getReferField();
2021 double rho = m_param.ALPHA_SAME_WITH_HELIX / kappa / Bz;
2022 double tanLambda = a[4];
2028 HepDiagMatrix e( 3, 1 );
2030 t[0][0] =
v.x() *
v.x();
2031 t[0][1] =
v.x() *
v.y();
2032 t[0][2] =
v.x() *
v.z();
2034 t[1][1] =
v.y() *
v.y();
2035 t[1][2] =
v.y() *
v.z();
2038 t[2][2] =
v.z() *
v.z();
2042 unsigned nTrial = 0;
2049 const double convergence = 1.0e-5;
2050 while ( nTrial < 100 )
2053 double cosPhi =
cos( phi0 + dPhi );
2054 double sinPhi =
sin( phi0 + dPhi );
2055 dXdPhi[0] = rho * sinPhi;
2056 dXdPhi[1] = -rho * cosPhi;
2057 dXdPhi[2] = -rho * tanLambda;
2060 double f = dot( c, dXdPhi ) + dot(
x, (
t * dXdPhi ) );
2062 if ( fabs(
f ) < convergence )
break;
2065 double eval = ( 1. - 0.25 * factor ) * fabs( fOld ) - fabs(
f );
2066 if ( eval <= 0. ) factor *= 0.5;
2069 d2Xd2Phi[0] = rho * cosPhi;
2070 d2Xd2Phi[1] = rho * sinPhi;
2073 dot( c, d2Xd2Phi ) + dot( dXdPhi, (
t * dXdPhi ) ) + dot(
x, (
t * d2Xd2Phi ) );
2074 dPhi -= factor *
f / df;
2091 const unsigned ip ) {
2093 if ( seed.length() < m_param.minimum_seedLength )
return NULL;
2094 TCircle* circle =
new TCircle( seed );
2095 m_allCircles.append( circle );
2099 if ( ( fabs( circle->
radius() ) > m_param.MIN_RADIUS_OF_STRANGE_TRACK ) ||
2100 ( fabs( circle->
radius() ) < m_param.ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK ) )
2102 int searchDirection = 1;
2103 int searchPath( searchDirection );
2104 bool searchZero(
false );
2105 bool changeDirection(
false );
2106 unsigned superLayerId = seed[0]->hit()->wire()->superLayerId();
2108 AList<TMLink> cand, tmpList;
2109 AList<TMLink> preAxialCand, preStereoCand;
2110 makeList( tmpList, segmentList, seed );
2111 for (
unsigned i = 0, size = tmpList.length(); i < size; ++i )
2113 if ( tmpList[i]->wire() )
2115 if ( tmpList[i]->wire()->axial() ) preAxialCand.append( tmpList[i] );
2116 else preStereoCand.append( tmpList[i] );
2120 std::cout <<
"(TCurlFinder) 2D: Superlayer of seed = " << superLayerId << std::endl;
2123 bool appendFlag =
false;
2126 std::cout <<
"(TCurlFinder) 2D: SearchPath = " << searchPath
2127 <<
" Search SelfSuperlayer = " << (int)( searchZero )
2128 <<
" Change Direction of Search = " << (int)( changeDirection ) << std::endl;
2130 if ( preAxialCand.length() == 0 && preStereoCand.length() == 0 )
2132 if ( circle->
links().length() >= 3 )
2134 if ( m_unusedAxialHits.length() == 0 )
2135 if ( errorFlag == -1 )
return NULL;
2141 if ( m_unusedAxialHits.length() == 0 )
return NULL;
2145 searchAxialCand( cand, preAxialCand, circle, searchPath, superLayerId,
2146 m_param.RANGE_FOR_AXIAL_SEARCH );
2147 if ( cand.length() > 0 )
2150 for (
unsigned i = 0, size = cand.length(); i < size; ++i ) circle->
append( *cand[i] );
2152 preAxialCand.remove( circle->
links() );
2153 if ( m_param.STEREO_2DFIND )
2155 searchStereoCand( cand, preStereoCand, circle, searchPath, superLayerId,
2156 m_param.RANGE_FOR_STEREO_SEARCH );
2157 if ( cand.length() > 0 )
2160 for (
unsigned i = 0, size = cand.length(); i < size; ++i ) circle->
append( *cand[i] );
2162 preStereoCand.remove( circle->
links() );
2165 if ( searchDirection == 1 ) ++searchPath;
2171 if ( m_param.STEREO_2DFIND )
2173 searchStereoCand( cand, preStereoCand, circle, searchPath, superLayerId,
2174 m_param.RANGE_FOR_STEREO_SEARCH );
2175 if ( cand.length() > 0 )
2178 for (
unsigned i = 0, size = cand.length(); i < size; ++i ) circle->
append( *cand[i] );
2180 preStereoCand.remove( circle->
links() );
2181 if ( searchDirection == 1 ) ++searchPath;
2185 else if ( ( searchPath == 1 || searchPath == -1 ) && !searchZero )
2191 else if ( ( searchPath == 1 || searchPath == -1 ) && searchZero && !changeDirection )
2194 searchDirection *= -1;
2195 changeDirection =
true;
2200 if ( circle->
links().length() >= 3 )
2202 if ( m_unusedAxialHits.length() == 0 )
2203 if ( errorFlag == -1 )
return NULL;
2209 if ( m_unusedAxialHits.length() == 0 )
return NULL;
2216 if ( ( searchPath == 1 || searchPath == -1 ) && !searchZero )
2222 else if ( ( searchPath == 1 || searchPath == -1 ) && searchZero && !changeDirection )
2225 searchDirection *= -1;
2226 changeDirection =
true;
2231 if ( circle->
links().length() >= 3 )
2233 if ( m_unusedAxialHits.length() == 0 )
2234 if ( errorFlag == -1 )
return NULL;
2240 if ( m_unusedAxialHits.length() == 0 )
return NULL;
2249 searchHits( cand, m_unusedAxialHits, circle, m_param.RANGE_FOR_AXIAL_LAST2D_SEARCH );
2250 if ( m_param.STEREO_2DFIND )
2251 { searchHits( cand, m_unusedStereoHits, circle, m_param.RANGE_FOR_STEREO_LAST2D_SEARCH ); }
2252 if ( checkAppendHits( circle->
links(), cand ) )
2255 if ( circle->
nLinks() >= 3 )
2256 if ( circle->
fitForCurl( ip ) == -1 )
return NULL;
2260 else if ( circle->
nLinks() >= 3 ) {
return circle; }
2267 const TCircle* circle,
const int depth,
2268 const unsigned superLayerID,
const double searchError ) {
2270 int innerSuperLayerId = nextSuperAxialLayerId( superLayerID, depth );
2271 if ( innerSuperLayerId < 0 )
return;
2272 for (
unsigned i = 0, size = preCand.length(); i < size; ++i )
2274 if ( preCand[i]->hit()->wire()->superLayerId() ==
2275 (
static_cast<unsigned>( innerSuperLayerId ) ) )
2278 if(searchHits(preCand[i], circle, searchError))cand.append(preCand[i]);
2280 if ( searchHits( preCand[i], circle, searchError ) )
2282 cand.remove( preCand[i] );
2283 cand.append( preCand[i] );
2287 for (
unsigned j = 0; j < size; ++j )
2289 if ( preCand[j]->wire()->
id() == cand2->
wire()->
id() )
2291 cand.remove( cand2 );
2292 cand.append( cand2 );
2294 std::cout <<
"Axial Appending....";
2295 std::cout <<
" layerID = " << cand2->
wire()->
layerId();
2296 std::cout <<
" localID = " << cand2->
wire()->
localId() << std::endl;
2297 if(searchHits(cand2, circle, searchError)){
2298 std::cout <<
" But this can be added by default!" << std::endl;
2300 std::cout <<
" Good!! this cannot be added by default!" << std::endl;
2314 const TCircle* circle,
const int depth,
2315 const unsigned superLayerID,
const double searchError ) {
2317 int innerSuperLayerId = nextSuperStereoLayerId( superLayerID, depth );
2318 if ( innerSuperLayerId < 0 || innerSuperLayerId > m_param.SUPERLAYER_FOR_STEREO_SEARCH )
2320 for (
unsigned i = 0, size = preCand.length(); i < size; ++i )
2322 if ( preCand[i]->hit()->wire()->superLayerId() ==
2323 (
static_cast<unsigned>( innerSuperLayerId ) ) )
2325 if ( searchHits( preCand[i], circle, searchError ) ) cand.append( preCand[i] );
2330unsigned TCurlFinder::searchHits(
const TMLink* link,
const TCircle* circle,
2331 const double searchError )
const {
2338 double radius = fabs( circle->
radius() );
2341 if ( radius - searchError < dist && radius + searchError > dist )
return 1;
2346 const TCircle* circle,
const double searchError )
const {
2347 unsigned numBefore = cand.length();
2348 for (
unsigned i = 0, size = preCand.length(); i < size; ++i )
2350 if ( searchHits( preCand[i], circle, searchError ) )
2353 cand.append(preCand[i]);
2355 cand.remove( preCand[i] );
2356 cand.append( preCand[i] );
2360 for (
unsigned j = 0; j < size; ++j )
2362 if ( preCand[j]->wire()->
id() == cand2->
wire()->
id() )
2364 cand.remove( cand2 );
2365 cand.append( cand2 );
2373 if ( numBefore == cand.length() )
return 0;
2378 if ( cand.length() == 0 )
return 0;
2380 for (
unsigned i = 0, size1 = cand.length(), size2 = link.length(); i < size1; ++i )
2382 for (
unsigned j = 0; j < size2; ++j )
2384 if ( ( cand[i] )->wire()->
id() == ( link[j] )->wire()->
id() )
2386 tmp.append( cand[i] );
2392 if ( cand.length() > 0 )
return 1;
2396void TCurlFinder::removeStereo(
TCircle& c )
const {
2397 AList<TMLink> stereoList;
2398 for (
int i = 0; i < c.
links().length(); ++i )
2400 if ( c.
links()[i]->wire()->stereo() ) { stereoList.append( c.
links()[i] ); }
2402 if ( stereoList.length() > 0 ) c.
remove( stereoList );
2405bool TCurlFinder::fitWDD(
TCircle& c,
double& chi2,
int& ndf )
const {
2406 if ( c.
links().length() <= 3 )
return false;
2409 for (
int i = 0; i < c.
links().length(); ++i )
2412 ( c.
links()[i] )->wire()->xyPosition().y(), 1.0 );
2415 if ( circle.
fit() < 0.0 || circle.
kappa() == 0.0 )
return false;
2416 double xc = circle.
center()[0];
2417 double yc = circle.
center()[1];
2418 double r = circle.
radius();
2419 const int maxIte = 2;
2420 for (
int ite = 0; ite < maxIte; ++ite )
2425 for (
int i = 0; i < c.
links().length(); ++i )
2428 double R = sqrt( ( ( c.
links()[i] )->wire()->xyPosition().x() - xc ) *
2429 ( ( c.
links()[i] )->wire()->xyPosition().x() - xc ) +
2430 ( ( c.
links()[i] )->wire()->xyPosition().y() - yc ) *
2431 ( ( c.
links()[i] )->wire()->xyPosition().y() - yc ) );
2432 if ( R == 0. )
continue;
2434 double dir =
R > r ? -1. : 1.;
2435 double X = xc + ( ( c.
links()[i] )->wire()->xyPosition().
x() - xc ) * U *
2436 (
R + dir * ( c.
links()[i] )->hit()->drift() );
2437 double Y = yc + ( ( c.
links()[i] )->wire()->xyPosition().y() - yc ) * U *
2438 (
R + dir * ( c.
links()[i] )->hit()->drift() );
2442 if ( circle2.
fit() < 0.0 || circle2.
kappa() == 0.0 )
return false;
2443 xc = circle2.
center()[0];
2444 yc = circle2.
center()[1];
2450 double totalChi2 = 0.;
2452 for (
int i = 0; i < c.
links().length(); ++i )
2455 double xw = ( c.
links()[i] )->wire()->xyPosition().x();
2456 double yw = ( c.
links()[i] )->wire()->xyPosition().y();
2457 double R = sqrt( ( xw - xc ) * ( xw - xc ) + ( yw - yc ) * ( yw - yc ) );
2458 if ( R == 0. )
continue;
2460 double X = xc + ( xw - xc ) * U * r;
2461 double Y = yc + ( yw - yc ) * U * r;
2462 double zlr = xw * Y - yw * X;
2464 double pChi2 = sqrt( ( X - xw ) * ( X - xw ) + ( Y - yw ) * ( Y - yw ) ) -
2465 ( c.
links()[i] )->hit()->drift();
2468 if ( ( c.
links()[i] )->hit()->dDrift() != 0. )
2471 pChi2 / ( ( c.
links()[i] )->hit()->dDrift() * ( c.
links()[i] )->hit()->dDrift() );
2476 else pChi2 = 1.0e+10;
2482 if ( totalNHit <= 3 )
return false;
2483 ndf = totalNHit - 3;
2489 for (
int i = 0; i < c.
links().length(); ++i )
2491 TMLink* l = c.
links()[i];
2492 if ( l == 0 )
continue;
2493 const TMDCWireHit* h = l->
hit();
2494 if ( h == 0 )
continue;
2495 double q = ( center.cross( h->
xyPosition() ) ).z();
2496 if (
q > 0. ) qSum += 1;
2499 if ( qSum >= 0 ) charge = +1.;
2515 unsigned size = segmentList.length();
2516 if ( TTrack* track = make3DTrack( circle ) )
2518 m_tracks.append( track );
2520 std::cout <<
"MDC Helix+Pt: " << track->
helix().
dr() <<
", "
2523 << track->
helix().
dz() <<
", "
2525 <<
": " << 10000./2.9979258/15./track->
helix().
kappa() << std::endl;
2533 TTrack* track =
new TTrack( *circle );
2534 m_allTracks.append( track );
2537 if ( track->
links().length() < m_param.minimum_2DTrackLength )
2540 std::cout <<
"(TCurlFinder) 3D:Fail...inital hit wire # < 3." << std::endl;
2544 AList<TMLink> allStereoHits( m_unusedStereoHits );
2545 allStereoHits.remove( track->
links() );
2546 AList<TMLink> closeHits;
2547 findCloseHits( allStereoHits, *track, closeHits );
2550 if ( closeHits.length() < m_param.minimum_closeHitsLength )
2553 std::cout <<
"(TCurlFinder) 3D:Fail...stereohit wire # < 5." << std::endl;
2558 if ( !m_builder.buildStereo( *track, closeHits, m_allStereoHitsOriginal ) )
2561 std::cout <<
"(TCurlFinder) 3D:Fail...can not build stereo." << std::endl;
2567 if ( ( fabs( circle->
radius() ) > m_param.MIN_RADIUS_OF_STRANGE_TRACK ) ||
2568 ( fabs( circle->
radius() ) < m_param.ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK ) )
2571 std::cout <<
"(TCurlFinder) 3D:Fail...success 3D fit, but large radius > "
2572 << m_param.MIN_RADIUS_OF_STRANGE_TRACK <<
"." << std::endl;
2577 if ( track->
links().length() >= m_param.minimum_3DTrackLength )
2580 std::cout <<
"(TCurlFinder) 3D:Success...can build stereo!!!" << std::endl;
2587 std::cout <<
"(TCurlFinder) 3D:Fail...success 3D fit, but final hit wire # < 3."
2597 TMLink* isolatedLink[2] = { NULL, NULL };
2600 for (
int i = 0; i < 6; ++i )
2609 for (
int j = 0; j < 6; ++j )
2624 if ( isolated == 1 )
2626 if ( nIsolated < 2 ) isolatedLink[nIsolated] = link->
neighbor( i );
2630 if ( testEach == 0 )
2631 { std::cout <<
"Why?? Neighborhood info. dose not exist!!" << std::endl; }
2638 std::cout <<
"isolated/neighbor # = " << nIsolated <<
"/" << nNeighbor << std::endl;
2639 std::cout <<
"layer ID = " << layerID <<
" ";
2640 std::cout <<
"local ID = " << localID <<
" --> ";
2641 if(isolatedLink[0])std::cout << isolatedLink[0]->
wire()->
localId() <<
" ";
2642 if(isolatedLink[1])std::cout << isolatedLink[1]->
wire()->
localId() <<
" ";
2643 std::cout << std::endl;
2645 if ( nIsolated == 1 && nNeighbor == 1 && isolatedLink[0] )
return isolatedLink[0];
2653 double dRcut[11] = { m_param.RANGE_FOR_STEREO_FIRST,
2654 m_param.RANGE_FOR_STEREO_SECOND,
2658 m_param.RANGE_FOR_STEREO_THIRD,
2659 m_param.RANGE_FOR_STEREO_FORTH,
2660 m_param.RANGE_FOR_STEREO_FIFTH,
2661 m_param.RANGE_FOR_STEREO_SIXTH,
2664 double r = fabs( track.
helix().
curv() );
2668 for (
unsigned i = 0, size = links.length(); i < size; ++i )
2670 if ( fabs( ( links[i]->wire()->xyPosition() - track.
helix().
center() ).mag() - r ) <
2671 dRcut[links[i]->wire()->superLayerId()] )
2673 if (
q * (
x * links[i]->wire()->xyPosition().y() -
2674 y * links[i]->wire()->xyPosition().
x() ) >
2677 list.remove( links[i] );
2678 list.append( links[i] );
2682 list.remove( cand );
2683 list.append( cand );
2700# define MAX_INDEX_MAKEMC 100
2702 std::cout <<
"(TCurlFinder)Now making tracks using MC info..." << std::endl;
2704 int index[MAX_INDEX_MAKEMC];
2705 for (
unsigned i = 0; i < MAX_INDEX_MAKEMC; ++i ) index[i] = 9999;
2710 for (
unsigned i = 0, size = axialHits.length(); i < size; ++i )
2712 if ( axialHits[i]->mc() && axialHits[i]->mc()->hep() &&
2716 for (
unsigned j = 0; j < MAX_INDEX_MAKEMC; ++j )
2718 if ( index[j] != 9999 && index[j] == axialHits[i]->mc()->hep()->
id() )
2726 index[counter] = axialHits[i]->mc()->hep()->id();
2732 std::cout <<
"(TCurlFinder)Found " << counter <<
" tracks with MC information." << std::endl;
2734 for (
unsigned j = 0; j < counter; ++j )
2736 AList<TMLink> axialList;
2737 AList<TMLink> stereoList;
2738 int axialCounter( 0 );
2739 int stereoCounter( 0 );
2741 for (
unsigned i = 0, size = axialHits.length(); i < size; ++i )
2743 if ( index[j] == axialHits[i]->mc()->hep()->
id() &&
2746 axialList.append(
new TMLink( 0, axialHits[i] ) );
2750 if ( axialCounter < 3 )
2752 HepAListDeleteAll( axialList );
2756 for (
unsigned i = 0, size = stereoHits.length(); i < size; ++i )
2758 if ( index[j] == stereoHits[i]->mc()->hep()->
id() &&
2761 stereoList.append(
new TMLink( 0, stereoHits[i] ) );
2765 if ( stereoCounter < 2 )
2767 HepAListDeleteAll( axialList );
2768 HepAListDeleteAll( stereoList );
2772 std::cout <<
"(TCurlFinder)#" << j <<
" : Use " << axialCounter <<
" axial hit wires and "
2773 << stereoCounter <<
" stereo hit wires" << std::endl;
2774 std::cout <<
"(TCurlFinder)Particle Type(LUND) = "
2775 << axialList[0]->hit()->mc()->hep()->pType() << std::endl;
2778 m_unusedAxialHitsOriginal.append( axialList );
2779 m_unusedAxialHitsOriginal.append( stereoList );
2780 TCircle* circle =
new TCircle( axialList );
2781 m_allCircles.append( circle );
2784 if ( axialList[0]->hit()->mc()->hep()->
pType() < 0 ) charge = -1.;
2785 if ( fabs( axialList[0]->hit()->mc()->hep()->
pType() ) == 11 ||
2786 fabs( axialList[0]->hit()->mc()->hep()->
pType() ) == 13 ||
2787 fabs( axialList[0]->hit()->mc()->hep()->
pType() ) == 15 )
2791 AList<TMLink> removeList;
2792 double x = circle->
center().x();
2793 double y = circle->
center().y();
2795 for (
unsigned i = 0, size = axialList.length(); i < size; ++i )
2798 (
x * axialList[i]->xyPosition().y() - y * axialList[i]->xyPosition().
x() ) <
2800 { removeList.append( axialList[i] ); }
2802 circle->
remove( removeList );
2803 if ( circle->
nLinks() < 3 )
continue;
2807 y = circle->
center().y();
2808 removeList.removeAll();
2810 for (
unsigned i = 0, size = stereoList.length(); i < size; ++i )
2813 (
x * stereoList[i]->xyPosition().y() - y * stereoList[i]->xyPosition().
x() ) <
2815 { removeList.append( stereoList[i] ); }
2817 stereoList.remove( removeList );
2818 if ( stereoList.length() < 2 )
continue;
2820 TTrack* track =
new TTrack( *circle );
2821 m_allTracks.append( track );
2822 if ( m_builder.buildStereoMC( *track, stereoList ) )
2824 if ( track->
links().length() >= 5 )
2827 tracks.append( track );
2828 m_allTracks.remove( track );
2830 else { std::cout <<
"Can not reconstruct with MC information!" << std::endl; }
2832 else { std::cout <<
"Can not reconstruct with MC information!" << std::endl; }
2838void TCurlFinder::makeCdcFrame(
void ) {
2839#if DEBUG_CURL_GNUPLOT + DEBUG_CURL_SEGMENT
2843 double R[12] = { 8.3, 16.9, 21.7, 31.3, 36.1, 44.1, 50.5, 58.5, 64.9, 72.9, 79.3, 87.4 };
2845 double dStep = 2. *
M_PI / step;
2847 std::string nameHead =
"tmp.cdc_";
2848 for (
int j = 0; j < 12; ++j )
2850 std::string nameFile = nameHead +
"0" + std::to_string( j );
2851 if ( j >= 10 ) nameFile = nameHead + std::to_string( j );
2852 if ( (
data = fopen( nameFile,
"w" ) ) != NULL )
2854 for (
int i = 0; i < step; ++i )
2856 double x = X +
R[j] *
cos( dStep *
static_cast<double>( i ) );
2857 double y = Y +
R[j] *
sin( dStep *
static_cast<double>( i ) );
2858 fprintf(
data,
"%lf, %lf\n",
x, y );
2864 if ( (
data = fopen(
"tmp_wires.dat",
"w" ) ) != NULL )
2866 AList<TMLink> list = m_unusedAxialHitsOriginal;
2867 list.append( m_unusedStereoHitsOriginal );
2868 for (
int i = 0; i < list.length(); i++ )
2870 double x = list[i]->hit()->wire()->xyPosition().x();
2871 double y = list[i]->hit()->wire()->xyPosition().y();
2872 fprintf(
data,
"%lf, %lf\n",
x, y );
2881#if DEBUG_CURL_GNUPLOT
2882 if ( !m_debugCdcFrame )
2885 m_debugCdcFrame =
true;
2887 double gmaxX = 90., gminX = -90.;
2888 double gmaxY = 90., gminY = -90.;
2889 FILE * gnuplot, *
data;
2890 if ( (
data = fopen(
"tmp.dat",
"w" ) ) != NULL )
2892 if (
flag ) std::cout <<
"Wire ID = ";
2893 for (
int i = 0; i < list.length(); i++ )
2895 double x = list[i]->hit()->wire()->xyPosition().x();
2896 double y = list[i]->hit()->wire()->xyPosition().y();
2897 fprintf(
data,
"%lf, %lf\n",
x, y );
2898 if (
flag ) std::cout << list[i]->hit()->wire()->id() <<
", ";
2900 if (
flag ) std::cout << std::endl;
2903 if ( ( gnuplot = popen(
"gnuplot",
"w" ) ) != NULL )
2905 fprintf( gnuplot,
"set nokey \n" );
2906 fprintf( gnuplot,
"set size 0.721,1.0 \n" );
2907 fprintf( gnuplot,
"set xrange [%f:%f] \n", gminX, gmaxX );
2908 fprintf( gnuplot,
"set yrange [%f:%f] \n", gminY, gmaxY );
2909 std::string longName =
"plot \"tmp_wires.dat\", \"tmp.dat\"";
2910 std::string nameHead =
",\"tmp.cdc_";
2911 for (
int j = 0; j < 12; ++j )
2913 std::string nameFile = nameHead +
"0" + std::to_string( j ) +
"\"w l 0";
2914 if ( j >= 10 ) nameFile = nameHead + std::to_string( j ) +
"\"w l 0";
2915 longName += nameFile;
2918 fprintf( gnuplot, longName );
2928void TCurlFinder::plotCircle(
const TCircle& circle,
const int flag ) {
2929#if DEBUG_CURL_GNUPLOT
2931 if ( !m_debugCdcFrame )
2934 m_debugCdcFrame =
true;
2936 double gmaxX = 90., gminX = -90.;
2937 double gmaxY = 90., gminY = -90.;
2938 FILE * gnuplot, *
data;
2939 if ( (
data = fopen(
"tmp.dat1",
"w" ) ) != NULL )
2941 if (
flag ) std::cout <<
"Axial Wire ID ==> " << std::endl;
2942 for (
int i = 0; i < circle.
nLinks(); ++i )
2944 if ( circle.
links()[i]->hit()->wire()->axial() )
2946 double x = circle.
links()[i]->hit()->wire()->xyPosition().x();
2947 double y = circle.
links()[i]->hit()->wire()->xyPosition().y();
2948 fprintf(
data,
"%lf, %lf\n",
x, y );
2960 if (
flag ) std::cout << std::endl;
2963 if ( (
data = fopen(
"tmp.dat2",
"w" ) ) != NULL )
2965 if (
flag ) std::cout <<
"Stereo Wire ID ==> " << std::endl;
2966 for (
int i = 0; i < circle.
nLinks(); ++i )
2968 if ( circle.
links()[i]->hit()->wire()->stereo() )
2970 double x = circle.
links()[i]->hit()->wire()->xyPosition().x();
2971 double y = circle.
links()[i]->hit()->wire()->xyPosition().y();
2972 fprintf(
data,
"%lf, %lf\n",
x, y );
2984 if (
flag ) std::cout << std::endl;
2987 double X = circle.
center().x();
2988 double Y = circle.
center().y();
2989 double R = fabs( circle.
radius() );
2991 double dStep = 2. *
M_PI / step;
2992 if ( (
data = fopen(
"tmp.dat3",
"w" ) ) != NULL )
2994 for (
int i = 0; i < step; ++i )
2996 double x = X +
R *
cos( dStep *
static_cast<double>( i ) );
2997 double y = Y +
R *
sin( dStep *
static_cast<double>( i ) );
2998 fprintf(
data,
"%lf, %lf\n",
x, y );
3002 if ( ( gnuplot = popen(
"gnuplot",
"w" ) ) != NULL )
3004 fprintf( gnuplot,
"set nokey \n" );
3005 fprintf( gnuplot,
"set size 0.721,1.0 \n" );
3006 fprintf( gnuplot,
"set xrange [%f:%f] \n", gminX, gmaxX );
3007 fprintf( gnuplot,
"set yrange [%f:%f] \n", gminY, gmaxY );
3008 std::string longName =
3009 "plot \"tmp_wires.dat\", \"tmp.dat1\", \"tmp.dat3\" w l, \"tmp.dat2\"";
3010 std::string nameHead =
",\"tmp.cdc_";
3011 for (
int j = 0; j < 12; ++j )
3013 std::string nameFile = nameHead +
"0" + std::string( j ) +
"\"w l 0";
3014 if ( j >= 10 ) nameFile = nameHead + std::string( j ) +
"\"w l 0";
3015 longName += nameFile;
3018 fprintf( gnuplot, longName );
3028void TCurlFinder::plotTrack(
const TTrack& track,
const int flag ) {
3029#if DEBUG_CURL_GNUPLOT
3030 if ( !m_debugCdcFrame )
3033 m_debugCdcFrame =
true;
3035 double gmaxX = 90., gminX = -90.;
3036 double gmaxY = 90., gminY = -90.;
3037 FILE * gnuplot, *
data;
3038 if ( (
data = fopen(
"tmp.dat1",
"w" ) ) != NULL )
3040 if (
flag ) std::cout <<
"Axial Wire ID ==> " << std::endl;
3041 for (
int i = 0; i < track.
nLinks(); ++i )
3043 if ( track.
links()[i]->hit()->wire()->axial() )
3045 double x = track.
links()[i]->hit()->wire()->xyPosition().x();
3046 double y = track.
links()[i]->hit()->wire()->xyPosition().y();
3047 fprintf(
data,
"%lf, %lf\n",
x, y );
3052 std::cout <<
" A:" << track.
links()[i]->hit()->wire()->id() <<
", ";
3053 std::cout <<
", HepTrackID = " << track.
links()[i]->hit()->mc()->hep()->id();
3054 std::cout <<
", HepLundID = " << track.
links()[i]->hit()->mc()->hep()->pType()
3057 else std::cout <<
" A:" << track.
links()[i]->hit()->wire()->id() << std::endl;
3061 if (
flag ) std::cout << std::endl;
3064 if ( (
data = fopen(
"tmp.dat2",
"w" ) ) != NULL )
3066 if (
flag ) std::cout <<
"Stereo Wire ID ==> " << std::endl;
3067 for (
int i = 0; i < track.
nLinks(); ++i )
3069 if ( track.
links()[i]->hit()->wire()->stereo() )
3071 double x = track.
links()[i]->hit()->wire()->xyPosition().x();
3072 double y = track.
links()[i]->hit()->wire()->xyPosition().y();
3073 fprintf(
data,
"%lf, %lf\n",
x, y );
3078 std::cout <<
" S:" << track.
links()[i]->hit()->wire()->id() <<
", ";
3079 std::cout <<
", HepTrackID = " << track.
links()[i]->hit()->mc()->hep()->id();
3080 std::cout <<
", HepLundID = " << track.
links()[i]->hit()->mc()->hep()->pType()
3083 else std::cout <<
" S:" << track.
links()[i]->hit()->wire()->id() << std::endl;
3087 if (
flag ) std::cout << std::endl;
3094 double dStep = 2. *
M_PI / step;
3095 if ( (
data = fopen(
"tmp.dat3",
"w" ) ) != NULL )
3097 for (
int i = 0; i < step; ++i )
3099 double x = X +
R *
cos( dStep *
static_cast<double>( i ) );
3100 double y = Y +
R *
sin( dStep *
static_cast<double>( i ) );
3101 fprintf(
data,
"%lf, %lf\n",
x, y );
3105 if ( ( gnuplot = popen(
"gnuplot",
"w" ) ) != NULL )
3107 fprintf( gnuplot,
"set nokey \n" );
3108 fprintf( gnuplot,
"set size 0.721,1.0 \n" );
3109 fprintf( gnuplot,
"set xrange [%f:%f] \n", gminX, gmaxX );
3110 fprintf( gnuplot,
"set yrange [%f:%f] \n", gminY, gmaxY );
3111 std::string longName =
3112 "plot \"tmp_wires.dat\", \"tmp.dat1\", \"tmp.dat3\" w l, \"tmp.dat2\"";
3113 std::string nameHead =
",\"tmp.cdc_";
3114 for (
int j = 0; j < 12; ++j )
3116 std::string nameFile = nameHead +
"0" + std::to_string( j ) +
"\"w l 0";
3117 if ( j >= 10 ) nameFile = nameHead + std::to_string( j ) +
"\"w l 0";
3118 longName += nameFile;
3121 fprintf( gnuplot, longName );
3132#if DEBUG_CURL_SEGMENT
3133 if ( !m_debugCdcFrame )
3136 m_debugCdcFrame =
true;
3138 double gmaxX = 90., gminX = -90.;
3139 double gmaxY = 90., gminY = -90.;
3142 std::string nameHead =
"tmp.segment_";
3143 std::string nameFile =
3144 nameHead + std::to_string( type ) +
"_" + std::to_string( m_debugFileNumber );
3145 ++m_debugFileNumber;
3146 if ( (
data = fopen( nameFile,
"w" ) ) != NULL )
3148 for (
int i = 0; i < list.length(); i++ )
3150 double x = list[i]->hit()->wire()->xyPosition().x();
3151 double y = list[i]->hit()->wire()->xyPosition().y();
3152 fprintf(
data,
"%lf, %lf\n",
x, y );
3160void TCurlFinder::dumpType1(
TTrack* track ) {
3162 for (
int j = 0; j < track->
nLinks(); ++j )
3164 std::cout <<
"Used Wire Info...";
3165 if ( track->
links()[j]->hit()->wire()->axial() )
3166 { std::cout <<
"A:" << track->
links()[j]->hit()->wire()->id() <<
", "; }
3167 else { std::cout <<
"S:" << track->
links()[j]->hit()->wire()->id() <<
", "; }
3170 std::cout <<
", HepTrackID = " << track->
links()[j]->hit()->mc()->hep()->id();
3171 std::cout <<
", HepLundID = " << track->
links()[j]->hit()->mc()->hep()->pType();
3173 double dist = distance( *track, *( track->
links()[j] ) );
3174 if ( dist > 2. ) std::cout <<
": Large Distance( >2cm ) = " << dist;
3175 std::cout << std::endl;
3177 AList<TMLink> list = m_unusedAxialHits;
3178 list.append( m_unusedStereoHits );
3179 for (
unsigned j = 0, nList = list.length(); j < nList; ++j )
3181 double dist = distance( *track, *( list[j] ) );
3182 std::cout <<
"Close Wire Info in ALL( <0.5cm )...";
3185 if ( list[j]->hit()->wire()->axial() )
3186 std::cout <<
"CA:" << list[j]->hit()->wire()->id() <<
", ";
3187 else std::cout <<
"CS:" << list[j]->hit()->wire()->id() <<
", ";
3190 std::cout <<
", HepTrackID = " << list[j]->hit()->mc()->hep()->id();
3191 std::cout <<
", HepLundID = " << list[j]->hit()->mc()->hep()->pType();
3193 std::cout <<
", Distance = " << dist << std::endl;
3200void TCurlFinder::dumpType2(
TTrack* track ) {
3202 unsigned size = track->
nLinks();
3203 if ( size == 0 )
return;
3205 set<int, less<int>> uniqueHepID;
3207 vector<double> ratio;
3208 for (
int i = 0; i < size; ++i )
3210 uniqueHepID.insert( track->
links()[i]->hit()->mc()->hep()->id() );
3211 hepID.push_back( track->
links()[i]->hit()->mc()->hep()->id() );
3215 set<int, less<int>>::iterator u = uniqueHepID.begin();
3216 vector<int>::size_type sizeInt;
3217 for (
unsigned i = 0; i < uniqueHepID.size(); ++i )
3220 count( hepID.begin(), hepID.end(), *u, sizeInt );
3221 ratio.push_back( (
static_cast<double>( sizeInt ) /
static_cast<double>( size ) ) );
3227 vector<double>::iterator m = max_element( ratio.begin(), ratio.end() );
3229 ::distance( ratio.begin(), m, maxIndex );
3230 u = uniqueHepID.begin();
3231 advance( u, maxIndex );
3233 std::cout <<
"Ratio " << ratio[maxIndex] << std::endl;
3234 for (
int i = 0; i < size; ++i )
3236 if ( track->
links()[i]->hit()->wire()->axial() ) std::cout <<
"A ";
3237 else std::cout <<
"S ";
3239 double dist = distance( *track, *( track->
links()[i] ) );
3240 if ( *u != track->
links()[i]->hit()->mc()->hep()->id() )
3241 { std::cout <<
"Bad " << dist << std::endl; }
3242 else { std::cout <<
"Good " << dist << std::endl; }
3264cluster2hep(Recsvd_cluster *clus) {
3266 Datsvd_hit_Manager& svdHitMgr = Datsvd_hit_Manager::get_manager();
3267 for(Datsvd_hit_Manager::iterator
3268 it = svdHitMgr.begin(),
3269 end = svdHitMgr.end();
3271 m_datsvd_hit.append(it);
3275 unsigned size = m_datsvd_hit.length();
3276 int startPosition = -1;
3279 for(
unsigned i=0;i<size;++i){
3281 std::cout << i <<
": " << clus->hit().get_ID() <<
" <--> " << m_datsvd_hit[i]->get_ID()
3282 <<
", RLA = " << m_datsvd_hit[i]->rla() <<
", LSA = " << m_datsvd_hit[i]->amp()
3283 <<
", Width = " << clus->width()
3284 <<
", Cluster LSA = " << clus->lsa() << std::endl;
3287 for(
unsigned i=0;i<size;++i){
3288 if(m_datsvd_hit[i]->amp() == 0)std::cout <<
"DatSVD_Hit:amp == 0" << std::endl;
3290 if(m_datsvd_hit[i]->rla() == 0)std::cout <<
"DatSVD_Hit:rla == 0" << std::endl;
3291 if(m_datsvd_hit[i]->rla() == 81920)std::cout <<
"DatSVD_Hit:rla == 81920" << std::endl;
3292 if(clus->hit().get_ID() == m_datsvd_hit[i]->get_ID()){
3294 if(
static_cast<double>(m_datsvd_hit[i]->amp()-1) > clus->lsa())direction = -1;
3298 if(startPosition == -1)
return NULL;
3299 int width = clus->width();
3301 std::cout <<
"Start # = " << startPosition
3302 <<
", Width = " << width
3303 <<
", Direction = " << direction <<std::endl;
3306 int* hepID =
new int[width];
3307 set< int, less<int> > uniqueHepID;
3309 for(
int i=startPosition;i<startPosition+width;++i)hepID[i-startPosition] = 0;
3311 Datsvd_mcdata_Manager& svdMcHitMgr = Datsvd_mcdata_Manager::get_manager();
3314 for(
int i=startPosition;i<startPosition+width;++i){
3315 for(Datsvd_mcdata_Manager::iterator
3316 it = svdMcHitMgr.begin(),
3317 end = svdMcHitMgr.end();
3320 if(m_datsvd_hit[i]->rla() == it->rla() &&
3321 it->Hep().get_ID() != 0){
3322 hepID[i-startPosition] = it->Hep().get_ID();
3323 uniqueHepID.insert(it->Hep().get_ID());
3331 for(
int i=startPosition;i<startPosition+width;++i){
3335 for(Datsvd_mcdata_Manager::iterator
3336 it = svdMcHitMgr.begin(),
3337 end = svdMcHitMgr.end();
3340 if(m_datsvd_hit[startPosition+1-reverse]->rla() == it->rla() &&
3341 it->Hep().get_ID() != 0){
3342 hepID[i-startPosition] = it->Hep().get_ID();
3343 uniqueHepID.insert(it->Hep().get_ID());
3351 unsigned num = uniqueHepID.size();
3352 int* counter =
new int[
num];
3353 set< int, less<int> >::iterator u = uniqueHepID.begin();
3354 for(
int i=0;i<
num;++i) counter[i] = 0;
3356 for(
int i=0;i<
num;++i){
3357 for(
int j=0;j<width;++j){
3365 Gen_hepevt_Manager& genMgr = Gen_hepevt_Manager::get_manager();
3367 u = uniqueHepID.begin();
3368 for(
int i=0;i<
num;++i){
3369 std::cout << i <<
": TrackID = "<< *u - 1
3370 <<
", Count = " << counter[i]
3371 <<
", LundID = " << genMgr[*u-1].idhep() << std::endl;
3380 return &(genMgr[*(uniqueHepID.begin())-1]);
3390void TCurlFinder::debugCheckSegments1(
void ) {
3391#if DEBUG_CURL_SEGMENT
3394 std::cout <<
"(TCurlFinder)checking consistency of segement..." << std::endl;
3395 unsigned nA = m_unusedAxialHitsOriginal.length();
3398 for (
unsigned i = 0; i < nA - 1; ++i )
3400 int superLayerId = (int)( m_unusedAxialHitsOriginal[i]->wire()->superLayerId() );
3401 int layerId = (int)( m_unusedAxialHitsOriginal[i]->wire()->layerId() );
3402 int localId = (int)( m_unusedAxialHitsOriginal[i]->wire()->localId() );
3403 int localIdP = (int)( m_unusedAxialHitsOriginal[i]->wire()->localIdForPlus() );
3404 int localIdM = (int)( m_unusedAxialHitsOriginal[i]->wire()->localIdForMinus() );
3405 for (
unsigned j = i + 1; j < nA; ++j )
3407 int superLayerId2 = (int)( m_unusedAxialHitsOriginal[j]->wire()->superLayerId() );
3408 int layerId2 = (int)( m_unusedAxialHitsOriginal[j]->wire()->layerId() );
3409 int localId2 = (int)( m_unusedAxialHitsOriginal[j]->wire()->localId() );
3410 if ( superLayerId == superLayerId2 )
3412 if ( layerId2 == layerId )
3414 if ( localIdP + 1 == localId2 || localIdM - 1 == localId2 )
3415 debugCheckSegments( localId, layerId, localId2, layerId2 );
3417 else if ( layerId2 == layerId - 1 || layerId2 == layerId + 1 )
3419 if ( offset( layerId ) == offset( layerId2 ) )
3421 std::cout <<
"(TCurlFinder: Waring) Offset is same at the same superlayer!!"
3424 else if ( offset( layerId ) > offset( layerId2 ) )
3426 if ( localId == localId2 || localIdP + 1 == localId2 )
3427 debugCheckSegments( localId, layerId, localId2, layerId2 );
3431 if ( localId == localId2 || localIdM - 1 == localId2 )
3432 debugCheckSegments( localId, layerId, localId2, layerId2 );
3439 unsigned nS = m_unusedStereoHitsOriginal.length();
3442 for (
unsigned i = 0; i < nS - 1; ++i )
3444 int superLayerId = (int)( m_unusedStereoHitsOriginal[i]->wire()->superLayerId() );
3445 int layerId = (int)( m_unusedStereoHitsOriginal[i]->wire()->layerId() );
3446 int localId = (int)( m_unusedStereoHitsOriginal[i]->wire()->localId() );
3447 int localIdP = (int)( m_unusedStereoHitsOriginal[i]->wire()->localIdForPlus() );
3448 int localIdM = (int)( m_unusedStereoHitsOriginal[i]->wire()->localIdForMinus() );
3449 for (
unsigned j = i + 1; j < nS; ++j )
3451 int superLayerId2 = (int)( m_unusedStereoHitsOriginal[j]->wire()->superLayerId() );
3452 int layerId2 = (int)( m_unusedStereoHitsOriginal[j]->wire()->layerId() );
3453 int localId2 = (int)( m_unusedStereoHitsOriginal[j]->wire()->localId() );
3454 if ( superLayerId == superLayerId2 )
3456 if ( layerId2 == layerId )
3458 if ( localIdP + 1 == localId2 || localIdM - 1 == localId2 )
3459 debugCheckSegments( localId, layerId, localId2, layerId2 );
3461 else if ( layerId2 == layerId - 1 || layerId2 == layerId + 1 )
3463 if ( offset( layerId ) == offset( layerId2 ) )
3465 std::cout <<
"(TCurlFinder: Waring) Offset is same at the same superlayer!!"
3468 else if ( offset( layerId ) > offset( layerId2 ) )
3470 if ( localId == localId2 || localIdP + 1 == localId2 )
3471 debugCheckSegments( localId, layerId, localId2, layerId2 );
3475 if ( localId == localId2 || localIdM - 1 == localId2 )
3476 debugCheckSegments( localId, layerId, localId2, layerId2 );
3483 std::cout <<
"(TCurlFinder)...done check of segement!" << std::endl;
3484 std::cout <<
"(TCurlFinder)...If no warning message exists, check of segement is complete!"
3486 std::cout <<
"(TCurlFinder)...Note: a segment size should be 1 or 2 to use this debugger."
3492void TCurlFinder::debugCheckSegments(
const double localId,
const double layerId,
3493 const double localId2,
const double layerId2 ) {
3495 unsigned nSeg = m_segmentList.length();
3496 unsigned nFound = 0;
3497 for (
unsigned i = 0; i < nSeg; ++i )
3499 unsigned nWire = m_segmentList[i]->list().length();
3500 unsigned mFound = 0;
3501 for (
unsigned j = 0; j < nWire; ++j )
3503 if ( ( ( m_segmentList[i]->list() )[j] )->wire()->layerId() == layerId &&
3504 ( ( m_segmentList[i]->list() )[j] )->wire()->localId() == localId )
3506 if ( ( ( m_segmentList[i]->list() )[j] )->wire()->layerId() == layerId2 &&
3507 ( ( m_segmentList[i]->list() )[j] )->wire()->localId() == localId2 )
3510 if ( mFound != 0 && mFound != 2 )
3512 std::cout <<
"(TCurlFinder: Warning) Segment is inconsistency(0)!! mFound = " << mFound
3515 if ( mFound == 2 ) ++nFound;
3518 std::cout <<
"(TCurlFinder: Warning) Segment is inconsistency(1)!! nFound = " << nFound
3524void TCurlFinder::debugCheckSegments0(
void ) {
3525#if DEBUG_CURL_SEGMENT
3526 unsigned nSeg = m_segmentList.length();
3528 for (
unsigned i = 0; i < nSeg; ++i ) nWire += m_segmentList[i]->list().length();
3530 unsigned nWireOriginal =
3531 m_unusedAxialHitsOriginal.length() + m_unusedStereoHitsOriginal.length();
3533 std::cout <<
"(TCurlFinder: SelfChecker) Segment Parts" << std::endl;
3534 std::cout <<
" MIN_SEGMENT = " << m_param.MIN_SEGMENT << std::endl;
3535 std::cout <<
" Wire # of Orinal List = " << nWireOriginal
3537 std::cout <<
" Wire # of Segments = " << nWire << std::endl;
3538 std::cout <<
" If MIN_SEGMENT <= 1, above numbers should be same."
3540 std::cout <<
" If MIN_SEGMENT > 1, former >= latter."
3546void TCurlFinder::debugCheckSegments2(
void ) {
3547#if DEBUG_CURL_SEGMENT
3549# define DEBUG_TMP_N_CURL 50
3551 unsigned nSeg = m_segmentList.length();
3552 unsigned nWire[DEBUG_TMP_N_CURL] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3553 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3554 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
3555 for (
unsigned i = 0; i < nSeg; ++i )
3557 if ( m_segmentList[i]->list().length() < DEBUG_TMP_N_CURL )
3558 ++( nWire[m_segmentList[i]->list().length()] );
3559 else ++( nWire[DEBUG_TMP_N_CURL - 1] );
3561 std::ifstream fin(
"tmp.wire.data" );
3562 unsigned nTotalWire[DEBUG_TMP_N_CURL] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3563 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
3567 for (
int i = 0; i < DEBUG_TMP_N_CURL; ++i ) fin >> nTotalWire[i];
3569 else { std::cout <<
"(TCurlFinder) tmp.wire.data does not exist!" << std::endl; }
3570 for (
int i = 0; i < DEBUG_TMP_N_CURL; ++i ) nTotalWire[i] += nWire[i];
3571 std::ofstream fout(
"tmp.wire.data" );
3574 fout << nTotalWire[0];
3575 for (
int i = 1; i < DEBUG_TMP_N_CURL; ++i ) fout <<
" " << nTotalWire[i];
3577 else { std::cout <<
"(TCurlFinder) tmp.wire.data can not be made!" << std::endl; }
3583 if (
nullptr == m_pmgnIMF )
3585 StatusCode sc = Gaudi::svcLocator()->service(
"MagneticFieldSvc", m_pmgnIMF );
3586 if ( sc.isFailure() )
3587 { std::cout <<
"Unable to open Magnetic field service" << std::endl; }
3592#undef DEBUG_CURL_DUMP
3593#undef DEBUG_CURL_SEGMENT
3594#undef DEBUG_CURL_GNUPLOT
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
DOUBLE_PRECISION count[3]
EvtTensor3C eps(const EvtVector3R &v)
double sin(const BesAngle a)
double cos(const BesAngle a)
#define WireHitFindingValid
#define WireHitFittingValid
#define WireHitCurlFinder
#define WireHitInvalidForFit
int SortByWireId(const void *a, const void *b)
Sorter.
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
int sortByArcLength(const void *av, const void *bv)
TMLink * findIsolatedCloseHits(TMLink *link)
int sortBySequentialLength(const void *av, const void *bv)
int TCurlFinder_doubleCompare(const void *i, const void *j)
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
const HepVector & a(void) const
returns helix parameters.
void add_point(double x, double y, double w=1)
A class to represent a circle in tracking.
double radius(void) const
returns radius.
const HepPoint3D & center(void) const
returns position of center.
void property(double charge, double radius, HepPoint3D center)
sets circle properties.
int fitForCurl(int ipConst=0)
fits itself. Error was happened if return value is not zero.
std::string name(void) const
returns name.
int doit(const AList< TMDCWireHit > &axialHits, const AList< TMDCWireHit > &stereoHits, AList< TTrack > &tracks, AList< TTrack > &tracks2D)
main function
std::string version(void) const
returns version.
void clear(void)
cleans all members of this class
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
const HepPoint3D & xyPosition(void) const
returns drift time
unsigned id(void) const
returns id.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const HepVector3D & direction(void) const
returns direction vector of the wire.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
unsigned superLayerId(void) const
returns super layer id.
const HepPoint3D & backwardPosition(void) const
returns position in backward endplate.
A class to relate TMDCWireHit and TTrack objects.
TMLink * neighbor(unsigned int) const
returns neighbor TMLink.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
const AList< TMLink > & list(void)
const unsigned size(void)
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
void remove(TMLink &a)
removes a TMLink.
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
A class to represent a track in tracking.
void assign(unsigned maskForWireHit)
assigns wire hits to this track.
const Helix & helix(void) const
returns helix parameter.
double charge(void) const
returns charge.
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)