BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TCurlFinder.cxx
Go to the documentation of this file.
1//
2// ... Section of Include Files
3//
4#include <fstream>
5#include <iostream>
6#include <math.h>
7#include <stdlib.h>
8// #include "panther/panther.h"
9// #include "CLHEP/String/Strings.h"
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"
17// #include "TrkReco/TSvdFinder.h"
18// #include "TrkReco/TSvdHit.h"
19// #include MDC_H
20// #include SVD_H
21
22#include "MdcTables/MdcTables.h"
23
24// Following 3 parameters : (0,0,0,0) is best!
25// Other cases are for the development.
26#define DEBUG_CURL_DUMP 0
27#define DEBUG_CURL_SEGMENT 0
28#define DEBUG_CURL_GNUPLOT 0
29#define DEBUG_CURL_MC 0
30
31#if ( DEBUG_CURL_DUMP + DEBUG_CURL_GNUPLOT + DEBUG_CURL_MC )
32# include "TrkReco/TMDCWireHitMC.h"
33# include "TrkReco/TTrackHEP.h"
34# include <algo.h>
35# include <set>
36// #include "tables/belletdf.h"
37static int debugMcFlag = 1;
38#endif
39
40//
41// ... Constructor and Destructor Section ...
42//
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 ) {
50 // *****NOTE*****
51 // Do not use this!!!!!
52 // Because parameters can not be set correctly.
53}
54
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,
64 //
65 const double selector_max_impact, const double selector_max_sigma,
66 const double selector_strange_pz, const double selector_replace_dz,
67 //
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,
73 //
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,
77
78 // jialk
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 ) {
89 //...Set Parameter
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;
105 //
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;
110 //
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;
123 //
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;
131 m_param.now();
132 // jialk
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;
139
140 //...Set up TBuilder...
141 m_builder.setParam( m_param );
142}
143
145
146//
147// ... Version and Name Section ...
148//
149std::string TCurlFinder::name( void ) const { return std::string( "Curling Track Finder" ); }
150
151std::string TCurlFinder::version( void ) const { return std::string( "3.00" ); }
152
153//
154// ... AList Sorter Section...
155//
156#if defined( __GNUG__ )
157int sortBySequentialLength( const TSegmentCurl** a, const TSegmentCurl** b ) {
158 if ( ( *a )->maxSeq() < ( *b )->maxSeq() ) { return 1; }
159 else if ( ( *a )->maxSeq() == ( *b )->maxSeq() ) { return 0; }
160 else { return -1; }
161}
162#else
163extern "C" int sortBySequentialLength( const void* av, const void* bv ) {
164 const TSegmentCurl** a( (const TSegmentCurl**)av );
165 const TSegmentCurl** b( (const TSegmentCurl**)bv );
166 if ( ( *a )->maxSeq() < ( *b )->maxSeq() ) { return 1; }
167 else if ( ( *a )->maxSeq() == ( *b )->maxSeq() ) { return 0; }
168 else { return -1; }
169}
170#endif
171
172#if defined( __GNUG__ )
173int sortByArcLength( const TMLink** a, const TMLink** b ) {
174 if ( ( *a )->position().x() > ( *b )->position().x() ) { return 1; }
175 else if ( ( *a )->position().x() == ( *b )->position().x() ) { return 0; }
176 else { return -1; }
177}
178#else
179int sortByArcLength( const void* av, const void* bv ) {
180 const TMLink** a( (const TMLink**)av );
181 const TMLink** b( (const TMLink**)bv );
182 if ( ( *a )->position().x() > ( *b )->position().x() ) { return 1; }
183 else if ( ( *a )->position().x() == ( *b )->position().x() ) { return 0; }
184 else { return -1; }
185}
186#endif
187//
188// ... Utility Section ...
189//
190double TCurlFinder::distance( const double x, const double y ) const {
191 return sqrt( x * x + y * y );
192}
193
194unsigned TCurlFinder::offset( const unsigned layerId ) const {
195 // input - layer id#(0-49)
196 // output - offset of its layer
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 )
203 return 1; // off set is 0.5
204 return 0; // off set is 0
205}
206
207unsigned TCurlFinder::layerId( const double& R ) const {
208 // R is radius for MDC but is 2*radius for track
209 double r = R * 10.; // cm -> mm
210 /* if(r < 83.0 || r > 874.)return 50;
211 if(r <= 93.0)return 0; if(r <= 103.25)return 1; if(r <= 113.5)return 2;
212 if(r <= 136.0)return 3; if(r <= 152.0)return 4; if(r <= 169.0)return 5;
213 if(r <= 186.0)return 6; if(r <= 202.0)return 7; if(r <= 217.0)return 8;
214 if(r <= 232.0)return 9; if(r <= 248.0)return 10; if(r <= 264.0)return 11;
215 if(r <= 280.0)return 12; if(r <= 297.0)return 13; if(r <= 313.0)return 14;
216 if(r <= 330.0)return 15; if(r <= 346.0)return 16; if(r <= 361.0)return 17;
217 if(r <= 376.0)return 18; if(r <= 392.0)return 19; if(r <= 408.0)return 20;
218 if(r <= 424.0)return 21; if(r <= 441.0)return 22; if(r <= 458.0)return 23;
219 if(r <= 474.0)return 24; if(r <= 490.0)return 25; if(r <= 505.0)return 26;
220 if(r <= 520.0)return 27; if(r <= 536.0)return 28; if(r <= 552.0)return 29;
221 if(r <= 568.0)return 30; if(r <= 585.0)return 31; if(r <= 602.0)return 32;
222 if(r <= 618.0)return 33; if(r <= 634.0)return 34; if(r <= 649.0)return 35;
223 if(r <= 664.0)return 36; if(r <= 680.0)return 37; if(r <= 696.0)return 38;
224 if(r <= 712.0)return 39; if(r <= 729.0)return 40; if(r <= 746.0)return 41;
225 if(r <= 762.0)return 42; if(r <= 778.0)return 43; if(r <= 793.0)return 44;
226 if(r <= 808.0)return 45; if(r <= 824.0)return 46; if(r <= 840.0)return 47;
227 if(r <= 856.0)return 48; if(r <= 874.0)return 49;
228 */
229 // Liuqg 060915
230 // if ( r < 73.0 || r > 772.2 ) return 43;
231 if ( r < 73.0 ) return 0; // yzhang add for 720 upgrade 24-11-19
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;
275 else return 42; // yzhang add for 720 upgrade 24-11-19
276}
277
278unsigned TCurlFinder::maxLocalLayerId( const unsigned superLayerId ) const {
279 // input - superlayer id#(0-10)
280 // output - max# id of locallayer in its superlayer.
281 // Liuqg 060926, change to BES, superLayerId means the max num of layers in each superlayers.
282 /* if(superLayerId == 1 || superLayerId == 3)return 2;
283 if(superLayerId == 5 || superLayerId == 7 ||
284 superLayerId == 9)return 3;
285 if(superLayerId == 4 || superLayerId == 6 ||
286 superLayerId == 8 || superLayerId == 10)return 4;
287 if(superLayerId == 0 || superLayerId == 2)return 5; */
288 if ( superLayerId == 10 ) return 2;
289 if ( superLayerId >= 0 && superLayerId < 10 ) return 3;
290
291 std::cerr << "Error in the CurlFinder(maxLocalLayerId). superLayerId = " << superLayerId
292 << std::endl;
293 return 0;
294}
295
296int TCurlFinder::nextSuperAxialLayerId( const unsigned superLayerId, const int in ) const {
297 // This function is to find next axial superlayer!
298 // input - superLayerId = superlayer id#(0-10)
299 // - in = find inner axial superlayer from "superLayerID"
300 // This is depth of it.
301 // ex1. If superLayerID = 2, in = 1, return 0
302 // ex2. If superLayerID = 2, in = -1, return 4
303 // output - return 0, 2, 4, 6, 8, 10 = no error
304 // -1 = error
305 if ( superLayerId > 10 || superLayerId < 0 )
306 {
307 std::cerr << "Error in the CurlFinder(nextSuperAxialLayerId)." << std::endl;
308 return -1;
309 }
310 // Liuqg 060920, the following numbers have been changed from belle to besiii
311 if ( in == 0 )
312 {
313 if ( superLayerId == 2 || superLayerId == 3 || superLayerId == 4 || superLayerId == 9 ||
314 superLayerId == 10 )
315 { return superLayerId; }
316 else
317 {
318 // return superLayerId - 1;
319 return -1;
320 }
321 }
322 // almost case --> inner type
323 if ( ( superLayerId == 3 ) && in == 1 ) return 2;
324 if ( superLayerId == 4 )
325 {
326 if ( in == 1 ) return 3;
327 if ( in == 2 ) return 2;
328 }
329 if ( superLayerId == 5 || superLayerId == 6 || superLayerId == 7 || superLayerId == 8 ||
330 superLayerId == 9 )
331 {
332 if ( in == 1 ) return 4;
333 if ( in == 2 ) return 3;
334 if ( in == 3 ) return 2;
335 }
336 if ( superLayerId == 10 )
337 {
338 if ( in == 1 ) return 9;
339 if ( in == 2 ) return 4;
340 if ( in == 3 ) return 3;
341 if ( in == 4 ) return 2;
342 }
343 // rare case --> outer type
344 if ( superLayerId == 0 || superLayerId == 1 )
345 {
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;
351 }
352 if ( superLayerId == 2 )
353 {
354 if ( in == -1 ) return 3;
355 if ( in == -2 ) return 4;
356 if ( in == -3 ) return 9;
357 if ( in == -4 ) return 10;
358 }
359 if ( superLayerId == 3 )
360 {
361 if ( in == -1 ) return 4;
362 if ( in == -2 ) return 9;
363 if ( in == -3 ) return 10;
364 }
365 if ( superLayerId == 4 )
366 {
367 if ( in == -1 ) return 9;
368 if ( in == -2 ) return 10;
369 }
370 if ( superLayerId == 5 || superLayerId == 6 || superLayerId == 7 || superLayerId == 8 ||
371 superLayerId == 9 )
372 {
373 if ( in == -1 ) return 10;
374 }
375
376 return -1;
377}
378
379int TCurlFinder::nextSuperStereoLayerId( const unsigned superLayerId, const int in ) const {
380 // This function is to find next stereo superlayer!
381 // input - superLayerId = superlayer id#(0-10)
382 // - in = find inner stereo superlayer from "superLayerID"
383 // This is depth of it.
384 // ex1. If superLayerID = 2, in = 1, return 1
385 // ex2. If superLayerID = 2, in = -1, return 3
386 // output - return 1, 3, 5, 7, 9 = no error
387 // -1 = error
388 if ( superLayerId > 10 || superLayerId < 0 )
389 {
390 std::cerr << "Error in the CurlFinder(nextSuperStereoLayerId)." << std::endl;
391 return -1;
392 }
393 // Liuqg 060920, the following numbers have been changed from belle to besiii
394 if ( in == 0 )
395 {
396 if ( superLayerId == 0 || superLayerId == 1 || superLayerId == 5 || superLayerId == 6 ||
397 superLayerId == 7 || superLayerId == 8 )
398 { return superLayerId; }
399 else { return -1; }
400 }
401 // almost case --> inner type
402 if ( ( superLayerId == 1 || superLayerId == 2 || superLayerId == 3 || superLayerId == 4 ) &&
403 in == 1 )
404 return 0;
405 if ( superLayerId == 5 )
406 {
407 if ( in == 1 ) return 1;
408 if ( in == 2 ) return 0;
409 }
410 if ( superLayerId == 6 )
411 {
412 if ( in == 1 ) return 5;
413 if ( in == 2 ) return 1;
414 if ( in == 3 ) return 0;
415 }
416 if ( superLayerId == 7 )
417 {
418 if ( in == 1 ) return 6;
419 if ( in == 2 ) return 5;
420 if ( in == 3 ) return 1;
421 if ( in == 4 ) return 0;
422 }
423 if ( superLayerId == 8 )
424 {
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;
430 }
431 if ( superLayerId == 9 || superLayerId == 10 )
432 {
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;
439 }
440 // rare case --> outer type
441 if ( superLayerId == 0 )
442 {
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;
448 }
449 if ( superLayerId == 1 || superLayerId == 2 || superLayerId == 3 || superLayerId == 4 )
450 {
451 if ( in == -1 ) return 5;
452 if ( in == -2 ) return 6;
453 if ( in == -3 ) return 7;
454 if ( in == -4 ) return 8;
455 }
456 if ( superLayerId == 5 )
457 {
458 if ( in == -1 ) return 6;
459 if ( in == -2 ) return 7;
460 if ( in == -3 ) return 8;
461 }
462 if ( superLayerId == 6 )
463 {
464 if ( in == -1 ) return 7;
465 if ( in == -2 ) return 8;
466 }
467 if ( superLayerId == 7 )
468 {
469 if ( in == -1 ) return 8;
470 }
471
472 return -1;
473}
474
475unsigned TCurlFinder::nAxialHits( const double& r ) const {
476 // r is radius for MDC but is 2*radius for track
477 const double eps = 0.2;
478 // changed to BESIII, Liuqg 060921
479 /* if(r < 8.8-eps) return 0;
480 else if(r < 9.8-eps) return 1;
481 else if(r < 10.85-eps) return 2;
482 else if(r < 12.8-eps) return 3;
483 else if(r < 14.4-eps) return 4;
484 else if(r < 15.95-eps) return 5;
485 else if(r < 22.45-eps) return 6;
486 else if(r < 24.0-eps) return 7;
487 else if(r < 25.6-eps) return 8;
488 else if(r < 27.2-eps) return 9;
489 else if(r < 28.8-eps) return 10;
490 else if(r < 30.4-eps) return 11;
491 else if(r < 36.85-eps) return 12;
492 else if(r < 38.4-eps) return 13;
493 else if(r < 40.0-eps) return 14;
494 else if(r < 41.6-eps) return 15;
495 else if(r < 43.15-eps) return 16;
496 else if(r < 51.25-eps) return 17;
497 else if(r < 52.8-eps) return 18;
498 else if(r < 54.4-eps) return 19;
499 else if(r < 56.0-eps) return 20;
500 else if(r < 57.55-eps) return 21;
501 else if(r < 65.65-eps) return 22;
502 else if(r < 67.2-eps) return 23;
503 else if(r < 68.8-eps) return 24;
504 else if(r < 70.4-eps) return 25;
505 else if(r < 71.9-eps) return 26;
506 else if(r < 80.05-eps) return 27;
507 else if(r < 81.6-eps) return 28;
508 else if(r < 83.2-eps) return 29;
509 else if(r < 84.8-eps) return 30;
510 else if(r < 86.3-eps) return 31;
511 else return 32;
512 */
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;
532 else return 18; // yzhang add for 720 upgrade 241119
533}
534
535//
536// ... Clean or Remove Section ...
537//
538void TCurlFinder::makeList( AList<TMLink>& madeList, const AList<TSegmentCurl>& originalList,
539 const AList<TMLink>& removeList ) {
540 // This is to make "madeList" from "originalList",
541 // but remove "removeList" from this "madeList", that is,
542 // madeList = originalList - removeList.
543 madeList.removeAll();
544 for ( unsigned i = 0, size = originalList.length(); i < size; ++i )
545 madeList.append( originalList[i]->list() );
546 madeList.remove( removeList );
547}
548
549void TCurlFinder::makeList( AList<TMLink>& madeList, const AList<TMLink>& originalList,
550 const AList<TMLink>& removeList ) {
551 // This is to make "madeList" from "originalList",
552 // but remove "removeList" from this "madeList", that is,
553 // madeList = originalList - removeList.
554 madeList.removeAll();
555 madeList.append( originalList );
556 madeList.remove( removeList );
557}
558
559void TCurlFinder::clear( void ) {
560 // This is to clear this Class(TCurlFinder) in TrkReco.cc .
561 // Private members are cleaned.
562 HepAListDeleteAll( m_allAxialHitsOriginal );
563 HepAListDeleteAll( m_allStereoHitsOriginal );
564 HepAListDeleteAll( m_segmentList );
565 HepAListDeleteAll( m_allCircles );
566 HepAListDeleteAll( m_allTracks );
567
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();
576 // Liuqg 060917
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();
582}
583
584//
585// ... doit .. Section ... This is a main section.
586//
588 const AList<TMDCWireHit>& stereoHits, AList<TTrack>& tracks,
589 AList<TTrack>& tracks2D ) {
590#if ( DEBUG_CURL_DUMP + DEBUG_CURL_GNUPLOT + DEBUG_CURL_MC )
591 Belle_event_Manager& evtMgr = Belle_event_Manager::get_manager();
592 debugMcFlag = 1;
593 if ( evtMgr.count() != 0 && evtMgr[0].ExpMC() != 2 ) debugMcFlag = 0; // not MC
594 m_debugCdcFrame = false;
595#endif
596#if !( DEBUG_CURL_MC )
597# if DEBUG_CURL_DUMP
598 std::cout << "(TCurlFinder)Plot Menu : All Off = 0, Interactive = 1, All On = 2"
599 << std::endl;
600 cin >> m_debugPlotFlag;
601# endif
602 // sub main functions #1, #2, #3
603 //...#1
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();
610# endif
611 //...#2
612 if ( checkSortSegments() == 0 ) return 0;
613# if DEBUG_CURL_DUMP
614 if ( m_debugPlotFlag )
615 {
616 int noPlot = 1;
617 if ( m_debugPlotFlag == 1 )
618 {
619 std::cout << "(TCurlFinder) Do you want to see Segment Plot? : yes = 1, no = other #"
620 << std::endl;
621 cin >> noPlot;
622 }
623 if ( noPlot == 1 )
624 {
625 for ( int i = 0; i < m_segmentList.length(); ++i )
626 plotSegment( m_segmentList[i]->list(), 0 );
627 }
628 }
629# endif
630 //...#3
631 makeCurlTracks( tracks, tracks2D );
632#else
633 makeWithMC( axialHits, stereoHits, tracks );
634#endif
635
636 //...iw 2001/01/26...
637 unsigned n = tracks2D.length();
638 for ( unsigned i = 0; i < n; i++ ) tracks2D[i]->quality( TrackQuality2D );
639 //...iw end...
640 return 0;
641}
642
643//
644// ... Sub Section #1 -- makes segments --
645// ... fuction name = "TMakeUnusedWireHitsList"
646//
647void TCurlFinder::makeWireHitsListsSegments( const AList<TMDCWireHit>& axialList,
648 const AList<TMDCWireHit>& stereoList ) {
649 // A sub main function ... called by "doit".
650 // #0 makes lists.
651 // #1 makes segments.
652
653 //...makes original lists(axial and stereo)
654 //
655 //......axial
656 unsigned size = axialList.length();
657 for ( unsigned i = 0; i < size; ++i )
658 {
659 if ( axialList[i]->reccdc()->tdc > 500 ) continue; // Liuqg, tmp
660 if ( axialList[i]->state() & WireHitFindingValid )
661 {
662 m_allAxialHitsOriginal.append( new TMLink( 0, axialList[i] ) );
663 if ( axialList[i]->wire()->superLayerId() <= 3 ) // origin is 2, Liuqg
664 m_hitsOnInnerSuperLayer.append( axialList[i] );
665 }
666 }
667 size = m_allAxialHitsOriginal.length();
668 for ( unsigned i = 0; i < size; ++i )
669 {
670 if ( !( m_allAxialHitsOriginal[i]->hit()->state() & WireHitUsed ) )
671 {
672 if ( m_allAxialHitsOriginal[i]->hit()->state() & WireHitInvalidForFit )
673 {
674 unsigned newState =
675 m_allAxialHitsOriginal[i]->hit()->state() & ( ~WireHitInvalidForFit );
676 m_allAxialHitsOriginal[i]->hit()->state( newState );
677 }
678 m_unusedAxialHitsOriginal.append( m_allAxialHitsOriginal[i] );
679 }
680 }
681 m_unusedAxialHits = m_unusedAxialHitsOriginal;
682 //......stereo
683 size = stereoList.length();
684 for ( unsigned i = 0; i < size; ++i )
685 {
686 if ( stereoList[i]->reccdc()->tdc > 500 ) continue; // Liuqg, tmp to exclude looping tracks
687 if ( stereoList[i]->state() & WireHitFindingValid )
688 {
689 m_allStereoHitsOriginal.append( new TMLink( 0, stereoList[i] ) );
690 if ( stereoList[i]->wire()->superLayerId() <= 3 ) // origin is 2, Liuqg
691 m_hitsOnInnerSuperLayer.append( stereoList[i] );
692 }
693 }
694 size = m_allStereoHitsOriginal.length();
695 for ( unsigned i = 0; i < size; ++i )
696 {
697 if ( !( m_allStereoHitsOriginal[i]->hit()->state() & WireHitUsed ) )
698 {
699 if ( m_allStereoHitsOriginal[i]->hit()->state() & WireHitInvalidForFit )
700 {
701 unsigned newState =
702 m_allStereoHitsOriginal[i]->hit()->state() & ( ~WireHitInvalidForFit );
703 m_allStereoHitsOriginal[i]->hit()->state( newState );
704 }
705 m_unusedStereoHitsOriginal.append( m_allStereoHitsOriginal[i] );
706 }
707 }
708 m_unusedStereoHits = m_unusedStereoHitsOriginal;
709
710 //...shares unsed hit wires to each layer.
711 size = m_unusedAxialHitsOriginal.length();
712 for ( unsigned i = 0; i < size; ++i )
713 {
714 m_unusedAxialHitsOnEachLayer
715 [m_unusedAxialHitsOriginal[i]->hit()->wire()->axialStereoLayerId()]
716 .append( m_unusedAxialHitsOriginal[i] );
717 }
718 size = m_unusedStereoHitsOriginal.length();
719 for ( unsigned i = 0; i < size; ++i )
720 {
721 m_unusedStereoHitsOnEachLayer
722 [m_unusedStereoHitsOriginal[i]->hit()->wire()->axialStereoLayerId()]
723 .append( m_unusedStereoHitsOriginal[i] );
724 }
725
726 //...sets pointers to neighboring hit wires of each TMLink
727 linkNeighboringWires( m_unusedAxialHitsOnEachLayer, 19 ); // Belle 32
728 linkNeighboringWires( m_unusedStereoHitsOnEachLayer, 24 ); // Belle 18
729
730 //...makes _unusedSuperAxialHits and _unusedSuperStereoHits
731 createSuperLayer();
732 //...makes segments by linking neighboring hit wires in the same super layer
733 m_segmentList.removeAll();
734 for ( unsigned i = 0; i < 5; ++i ) // Belle 6
735 if ( m_unusedAxialHitsOnEachSuperLayer[i].length() > 0 )
736 createSegments( m_unusedAxialHitsOnEachSuperLayer[i] );
737 for ( unsigned i = 0; i < 6; ++i ) // Belle 5
738 if ( m_unusedStereoHitsOnEachSuperLayer[i].length() > 0 )
739 createSegments( m_unusedStereoHitsOnEachSuperLayer[i] );
740}
741
742void TCurlFinder::linkNeighboringWires( AList<TMLink>* list, const unsigned num ) {
743 // Axial(num == 19) and Stereo(num == 24).
744 // ...sets pointers to neighboring wires
745 // in "neighbor" of "AList<TMLink> *list" element
746
747 for ( int i = 0; i < num; ++i )
748 {
749 if ( list[i].length() == 0 ) continue;
750 for ( int j = 0; j < list[i].length(); ++j )
751 {
752 // find two links of list[i][j]
753 //...inner layer
754 if ( num == 19 )
755 {
756 if ( i == 0 || i == 4 || i == 8 || i == 12 || i == 16 ) goto outer;
757 }
758 else if ( num == 24 )
759 {
760 if ( i == 0 || i == 4 || i == 8 || i == 12 || i == 16 || i == 20 ) goto outer;
761 }
762
763 for ( int k = 0; k < list[i - 1].length(); ++k )
764 {
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] );
771 } // k
772 outer:
773 //...outer layer
774 if ( num == 19 )
775 {
776 if ( i == 3 || i == 7 || i == 11 || i == 15 || i == 18 ) goto same;
777 }
778 else if ( num == 24 )
779 {
780 if ( i == 3 || i == 7 || i == 11 || i == 15 || i == 19 || i == 23 ) goto same;
781 }
782 for ( int k = 0; k < list[i + 1].length(); ++k )
783 {
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] );
790 } // k
791 same:
792 //...same layer
793 for ( int k = 0; k < list[i].length(); ++k )
794 {
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] ); }
801 } // k
802 } // j
803 } // i
804}
805
806void TCurlFinder::setNeighboringWires( TMLink* list, const TMLink* next ) {
807 // ...sets a neighboring wire of "list".
808 // Its candidate is "next".
809 for ( int i = 0; i < 6; ++i )
810 {
811 if ( !list->neighbor( i ) )
812 {
813 list->neighbor( i, const_cast<TMLink*>( next ) );
814 break;
815 }
816 }
817}
818
819void TCurlFinder::createSuperLayer( void ) {
820 // Liuqg
821 for ( int i = 0; i < 4; ++i )
822 {
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] );
833 }
834 for ( int i = 0; i < 4; ++i )
835 {
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] );
848 }
849}
850
851void TCurlFinder::createSegments( AList<TMLink>& list ) {
852 // ...makes segments from AList<TMLink> &list, in every superlayer.
853 // These segments are add to _segmentList.(# of segments >= MIN_SEGMENT)
854 AList<TMLink> seedStock;
855 do {
856 TSegmentCurl* segment =
857 new TSegmentCurl( list[0]->hit()->wire()->superLayerId(),
858 maxLocalLayerId( list[0]->hit()->wire()->superLayerId() ) );
859
860 segment->append( list[0] );
861 TMLink* seed = list[0];
862 list.remove( seed );
863 next:
864 searchSegment( seed, list, seedStock, segment );
865 if ( seedStock.length() > 0 )
866 {
867 seed = seedStock[0];
868 seedStock.remove( seed );
869 goto next;
870 }
871 else if ( segment->size() >= m_param.MIN_SEGMENT )
872 {
873 segment->update();
874 m_segmentList.append( segment );
875#if DEBUG_CURL_DUMP
876 std::cout << "Segment # = " << m_segmentList.length() << std::endl;
877 segment->dump();
878#endif
879 }
880 else { delete segment; }
881 } while ( list.length() > 0 );
882}
883
884void TCurlFinder::searchSegment( TMLink* seed, AList<TMLink>& list, AList<TMLink>& seedStock,
885 TSegmentCurl* segment ) {
886 for ( int i = 0; i < 6; ++i )
887 {
888 if ( seed->neighbor( i ) )
889 {
890 if ( !findLink( seed->neighbor( i ), list ) ) continue;
891 segment->append( seed->neighbor( i ) );
892 seedStock.append( seed->neighbor( i ) );
893 list.remove( seed->neighbor( i ) );
894 }
895 else { break; }
896 }
897}
898
899TMLink* TCurlFinder::findLink( const TMLink* seed, const AList<TMLink>& list ) {
900 // This is to search "TMLink *seed" in "AList<TMLink> &list".
901 // Return is when found, the "TMLink *list[i]"
902 // when not found, NULL.
903 unsigned size = list.length();
904 if ( size == 0 ) return NULL;
905 for ( unsigned i = 0; i < size; ++i )
906 {
907 if ( seed == list[i] ) return list[i];
908 }
909 return NULL;
910}
911
912//
913// ... Sub Section #2 -- checks and sorts segments --
914// ... fuction name = "checkSortSegments"
915//
916int TCurlFinder::checkSortSegments( void ) {
917 // A sub main function ...called by "doit".
918#if DEBUG_CURL_DUMP
919 std::cout << "(TCurlFinder)checking and sorting segments..." << std::endl;
920#endif
921 unsigned length = m_segmentList.length();
922 if ( length == 0 ) return 0;
923 checkExceptionalSegmentsType03(); //...exception #3
924 // checkExceptionalSegmentsType02();//...exception #2
925 checkExceptionalSegmentsType01(); //...exception #1
926 m_segmentList.sort( sortBySequentialLength );
927#if DEBUG_CURL_DUMP
928 std::cout << "(TCurlFinder)...done check and sort of segments." << std::endl;
929#endif
930 return 1;
931}
932
933void TCurlFinder::checkExceptionalSegmentsType03( void ) {
934 int max = m_param.MAX_FULLWIRE;
935 int nMinWires = 7; // add initialize 25-05-15
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;
944
945 AList<TSegmentCurl> removeList;
946 for ( unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
947 {
948 if ( m_segmentList[i]->size() >= nMinWires )
949 {
950 unsigned nWires = m_segmentList[i]->size();
951 unsigned n6Wires = 0;
952 for ( unsigned j = 0; j < nWires; ++j )
953 {
954 if ( ( ( m_segmentList[i]->list() )[j] )->neighbor( 5 ) ) ++n6Wires;
955 if ( n6Wires > max ) break;
956 }
957 if ( n6Wires <= max ) continue;
958 removeList.append( m_segmentList[i] );
959#if DEBUG_CURL_SEGMENT
960 writeSegment( m_segmentList[i]->list(), 3 );
961#endif
962 }
963 }
964 if ( removeList.length() >= 1 )
965 {
966#if DEBUG_CURL_DUMP
967 std::cout << "(TCurlFinder)removing large segments: # = " << removeList.length()
968 << std::endl;
969#endif
970 m_segmentList.remove( removeList );
971 HepAListDeleteAll( removeList );
972 }
973}
974
975void TCurlFinder::checkExceptionalSegmentsType02( void ) {
976 int max = 10;
977 int hmax = 5;
978 AList<TSegmentCurl> removeList;
979 for ( unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
980 {
981 int lSize = max * 3 + hmax * 3;
982 int lNum = 3;
983 if ( m_segmentList[i]->superLayerId() == 1 || m_segmentList[i]->superLayerId() == 3 )
984 {
985 lSize = max * 2 + hmax;
986 lNum = 2;
987 }
988 if ( m_segmentList[i]->superLayerId() == 5 || m_segmentList[i]->superLayerId() == 7 ||
989 m_segmentList[i]->superLayerId() == 9 )
990 {
991 lSize = max * 2 + hmax * 2;
992 lNum = 2;
993 }
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;
998 int nL = 0;
999 for ( unsigned j = 0, size = m_segmentList[i]->maxLocalLayerId(); j < size; ++j )
1000 {
1001 if ( m_segmentList[i]->sizeOfLayer( j ) >= max ) ++nL;
1002 }
1003 if ( nL < lNum ) continue;
1004 removeList.append( m_segmentList[i] );
1005 // plotSegment(m_segmentList[i]->list(),0);
1006#if DEBUG_CURL_SEGMENT
1007 // writeSegment(m_segmentList[i]->list(),2);
1008#endif
1009 }
1010 if ( removeList.length() >= 1 )
1011 {
1012#if DEBUG_CURL_DUMP
1013 std::cout << "(TCurlFinder)removing large segments: # = " << removeList.length()
1014 << std::endl;
1015#endif
1016 m_segmentList.remove( removeList );
1017 HepAListDeleteAll( removeList );
1018 }
1019}
1020
1021void TCurlFinder::checkExceptionalSegmentsType01( void ) {
1022 for ( unsigned i = 0, length = m_segmentList.length(); i < length; ++i )
1023 {
1024 if ( m_segmentList[i]->maxLocalLayerId() != m_segmentList[i]->layerIdOfMaxSeq() &&
1025 m_segmentList[i]->maxSeq() >= m_param.MIN_SEQUENCE )
1026 {
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 )
1032 {
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() )
1040 { ++innerHits; }
1041 }
1042 if ( innerHits != 0 && outer->size() != 0 )
1043 {
1044#if DEBUG_CURL_DUMP
1045 std::cout << "(TCurlFinder)removing some wires in the segment." << std::endl;
1046#endif
1047#if DEBUG_CURL_SEGMENT
1048 // writeSegment(m_segmentList[i]->list(),1);
1049#endif
1050 m_segmentList[i]->remove( const_cast<AList<TMLink>&>( outer->list() ) );
1051 outer->removeAll();
1052 delete outer;
1053 }
1054 else
1055 {
1056 outer->removeAll();
1057 delete outer;
1058 }
1059 }
1060 }
1061}
1062
1063//
1064// ... Sub Section #3 -- makes curl tracks --
1065// ... fuction name = "makeCurlTracks"
1066//
1067
1068//............................................
1069//..............2D+3D Manage Parts............
1070//............................................
1071
1072void TCurlFinder::makeCurlTracks( AList<TTrack>& tracks, AList<TTrack>& tracks2D ) {
1073 AList<TSegmentCurl> segmentList = m_segmentList;
1074 // cout<<"segments: "<<m_segmentList.length()<<endl;
1075 // if(m_param.SVD_RECONSTRUCTION)m_builder.setSvdClusters();
1076 for ( unsigned i = 0, size = m_segmentList.length(); i < size; ++i )
1077 {
1078 TCircle* circle =
1079 make2DTrack( segmentList[i]->list(), segmentList, 1 ); // order by sequential num
1080 if ( circle )
1081 {
1082 AList<TMLink> tmp( circle->links() );
1083#if DEBUG_CURL_DUMP
1084 std::cout << "(TCurlFinder) 2D:Created Circle!!!" << std::endl;
1085 if ( m_debugPlotFlag )
1086 {
1087 int noPlot = 1;
1088 if ( m_debugPlotFlag == 1 )
1089 {
1090 std::cout
1091 << "(TCurlFinder) Do you want to see Circle Plot(2D)? : yes = 1, no = other #"
1092 << std::endl;
1093 cin >> noPlot;
1094 }
1095 if ( noPlot == 1 ) plotCircle( *circle, 0 );
1096 }
1097#endif
1098
1099 /* if (tmp.length()>0) {
1100 cout<<"circle ok.............."<<endl;
1101 for(int j = 0; j < tmp.length(); ++j){
1102 TMLink *ll = tmp[j];
1103 cout<<"layerId: "<<ll->wire()->layerId()
1104 <<" localId: "<<ll->wire()->localId()<<endl;
1105 }
1106 }
1107 */
1108 if ( TCircle* dividedCircle = dividing2DTrack( circle ) )
1109 {
1110#if DEBUG_CURL_DUMP
1111 std::cout << "(TCurlFinder) 2D:dividing...good...2 Circles!!!" << std::endl;
1112#endif
1113 TTrack *track1( NULL ), *track2( NULL );
1114 int ok2d[2] = { 0, 0 };
1115 int ok3d[2] = { 0, 0 };
1116 // cout<<"trac2D: "<<trace2DTrack(circle)<<" check2D: "<< check2DCircle(circle)
1117 //<<" fit: "<< circle->fitForCurl(1)<<endl;
1118 if ( trace2DTrack( circle ) && check2DCircle( circle ) &&
1119 circle->fitForCurl( 1 ) != -1 )
1120 {
1121 ok2d[0] = 1;
1122#if DEBUG_CURL_DUMP
1123 std::cout << "(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1124#endif
1125 track1 = make3DTrack( circle, segmentList );
1126 }
1127 // cout<<"trac2D: "<<trace2DTrack(dividedCircle)<<" check2D: "<<
1128 // check2DCircle(dividedCircle)
1129 //<<" fit: "<< dividedCircle->fitForCurl(1)<<endl;
1130 if ( trace2DTrack( dividedCircle ) && check2DCircle( dividedCircle ) &&
1131 dividedCircle->fitForCurl( 1 ) != -1 )
1132 {
1133 ok2d[1] = 1;
1134#if DEBUG_CURL_DUMP
1135 std::cout << "(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1136#endif
1137 track2 = make3DTrack( dividedCircle, segmentList );
1138 }
1139 if ( track1 && track2 )
1140 {
1141#if DEBUG_CURL_DUMP
1142 std::cout << "(TCurlFinder) 3D:Create Track!!! in track1 && track2"
1143 << std::endl;
1144#endif
1145 salvage3DTrack( track1, true );
1146 salvage3DTrack( track2, true );
1147#if DEBUG_CURL_DUMP
1148 std::cout << "(TCurlFinder) 1:dz = " << track1->helix().dz()
1149 << ", 2:dz = " << track2->helix().dz() << std::endl;
1150#endif
1151 if ( m_param.DETERMINE_ONE_TRACK )
1152 {
1153 if ( fabs( track1->helix().dz() ) < fabs( track2->helix().dz() ) )
1154 {
1155 m_tracks.remove( track2 );
1156 if ( merge3DTrack( track1, tracks ) )
1157 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1158 {
1159 ok3d[0] = 1;
1160 ok3d[1] = 1;
1161 mask3DTrack( track1, tmp );
1162 tmp.append( track1->links() );
1163 }
1164 }
1165 else
1166 {
1167 m_tracks.remove( track1 );
1168 if ( merge3DTrack( track2, tracks ) )
1169 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1170 {
1171 ok3d[0] = 1;
1172 ok3d[1] = 1;
1173 mask3DTrack( track2, tmp );
1174 tmp.append( track2->links() );
1175 }
1176 }
1177 }
1178 else
1179 {
1180 int isSaved[2] = { 0, 0 };
1181 if ( merge3DTrack( track1, tracks ) )
1182 {
1183 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1184 {
1185 ok3d[0] = 1;
1186 mask3DTrack( track1, tmp );
1187 tmp.append( track1->links() );
1188 isSaved[0] = 1;
1189 }
1190 }
1191 if ( merge3DTrack( track2, tracks ) )
1192 {
1193 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1194 {
1195 ok3d[1] = 1;
1196 mask3DTrack( track2, tmp );
1197 tmp.append( track2->links() );
1198 isSaved[1] = 1;
1199 }
1200 }
1201 if ( isSaved[0] == 1 && isSaved[1] == 1 )
1202 {
1203 track1->daughter( track2 );
1204 track2->daughter( track1 );
1205 }
1206 }
1207 }
1208 else if ( track1 )
1209 {
1210#if DEBUG_CURL_DUMP
1211 std::cout << "(TCurlFinder) 3D:Create Track!!! in track1" << std::endl;
1212#endif
1213 salvage3DTrack( track1, true );
1214 if ( merge3DTrack( track1, tracks ) )
1215 if ( check3DTrack( track1 ) && trace3DTrack( track1 ) )
1216 {
1217 ok3d[0] = 1;
1218 mask3DTrack( track1, tmp );
1219 tmp.append( track1->links() );
1220 }
1221 }
1222 else if ( track2 )
1223 {
1224#if DEBUG_CURL_DUMP
1225 std::cout << "(TCurlFinder) 3D:Create Track!!! in track2" << std::endl;
1226#endif
1227 salvage3DTrack( track2, true );
1228 if ( merge3DTrack( track2, tracks ) )
1229 if ( check3DTrack( track2 ) && trace3DTrack( track2 ) )
1230 {
1231 ok3d[1] = 1;
1232 mask3DTrack( track2, tmp );
1233 tmp.append( track2->links() );
1234 }
1235 }
1236
1237 if ( m_param.OUTPUT_2DTRACKS )
1238 {
1239 // When 2d is OK but 3d is BAD, a 2dtrk is saved.
1240 if ( ok2d[0] == 1 && ok3d[0] == 0 )
1241 {
1242 removeStereo( *circle );
1243 double chi2_2d;
1244 int ndf_2d;
1245 if ( fitWDD( *circle, chi2_2d, ndf_2d ) )
1246 {
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 );
1252 }
1253#if DEBUG_CURL_DUMP
1254 else
1255 { std::cout << "(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1256#endif
1257 }
1258 if ( ok2d[1] == 1 && ok3d[1] == 0 )
1259 {
1260 removeStereo( *dividedCircle );
1261 double chi2_2d;
1262 int ndf_2d;
1263 if ( fitWDD( *dividedCircle, chi2_2d, ndf_2d ) )
1264 {
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 );
1270 }
1271#if DEBUG_CURL_DUMP
1272 else
1273 { std::cout << "(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1274#endif
1275 }
1276 }
1277 }
1278 else
1279 {
1280#if DEBUG_CURL_DUMP
1281 std::cout << "(TCurlFinder) 2D:dividing...no good...1 Circles!!!" << std::endl;
1282#endif
1283 int ok2d = 0;
1284 int ok3d = 0;
1285 // cout<<"trac2D: "<<trace2DTrack(circle)<<" check2D: "<< check2DCircle(circle)
1286 //<<" fit: "<< circle->fitForCurl(1)<<endl;
1287 if ( trace2DTrack( circle ) && check2DCircle( circle ) &&
1288 circle->fitForCurl( 1 ) != -1 )
1289 {
1290#if DEBUG_CURL_DUMP
1291 std::cout << "(TCurlFinder) 2D:Success Circle Fit!!!" << std::endl;
1292#endif
1293 ok2d = 1;
1294 TTrack* track3 = make3DTrack( circle, segmentList );
1295 if ( track3 )
1296 {
1297#if DEBUG_CURL_DUMP
1298 std::cout << "(TCurlFinder) 3D:Create Track!!! in track3" << std::endl;
1299#endif
1300 salvage3DTrack( track3, true );
1301 if ( merge3DTrack( track3, tracks ) )
1302 if ( check3DTrack( track3 ) && trace3DTrack( track3 ) )
1303 {
1304 ok3d = 1;
1305 mask3DTrack( track3, tmp );
1306 tmp.append( track3->links() );
1307 }
1308 }
1309
1310 if ( m_param.OUTPUT_2DTRACKS )
1311 {
1312 // When 2d is OK but 3d is BAD, a 2dtrk is saved.
1313 if ( ok2d == 1 && ok3d == 0 )
1314 {
1315 removeStereo( *circle );
1316 double chi2_2d;
1317 int ndf_2d;
1318 if ( fitWDD( *circle, chi2_2d, ndf_2d ) )
1319 {
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 );
1325 }
1326#if DEBUG_CURL_DUMP
1327 else
1328 { std::cout << "(TCurlFinder) 2D:fit with drift information!!!" << std::endl; }
1329#endif
1330 }
1331 }
1332 }
1333 }
1334 m_unusedAxialHits.remove( tmp );
1335 m_unusedStereoHits.remove( tmp );
1336 for ( unsigned ii = 0, nsize = m_segmentList.length(); ii < nsize; ++ii )
1337 {
1338 m_segmentList[ii]->remove( tmp );
1339 if ( m_segmentList[ii]->list().length() < m_param.MIN_SEGMENT )
1340 m_segmentList[ii]->removeAll();
1341 }
1342 }
1343 segmentList[i]->removeAll();
1344 }
1345
1346 // Check 2D trk's wires
1347 // check2DTracks(); // ... not need because of the current algorithm
1348
1349 // 3D & 2D trks information
1350 assignTracks();
1351
1352#if DEBUG_CURL_DUMP
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 )
1357 {
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 )
1362 {
1363 if ( m_tracks[j]->links()[i]->wire()->stereo() ) ++nS;
1364 else ++nA;
1365 if ( /*!(m_tracks[j]->links()[i]->hit()->state() & WireHitInvalidForFit) &&*/
1366 ( m_tracks[j]->links()[i]->hit()->state() & WireHitFittingValid ) )
1367 {
1368 if ( m_tracks[j]->links()[i]->wire()->stereo() ) ++nSOK;
1369 else ++nAOK;
1370 }
1371 }
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;
1376 }
1377 std::cout << "2D Track List" << std::endl;
1378 for ( int j = 0; j < m_2dTracks.length(); ++j )
1379 {
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 )
1383 {
1384 if ( m_2dTracks[j]->links()[i]->wire()->stereo() ) ++nS;
1385 else ++nA;
1386 if ( /*!(m_2dTracks[j]->links()[i]->hit()->state() & WireHitInvalidForFit) &&*/
1387 ( m_2dTracks[j]->links()[i]->hit()->state() & WireHitFittingValid ) )
1388 {
1389 if ( m_2dTracks[j]->links()[i]->wire()->stereo() ) ++nSOK;
1390 else ++nAOK;
1391 }
1392 }
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()
1396 << std::endl;
1397 if ( m_2dTracks[j]->daughter() )
1398 std::cout << "(TCurlFinder) Relation = EXIST" << std::endl;
1399 else std::cout << "(TCurlFinder) Relation = NO EXIST" << std::endl;
1400 }
1401#endif
1402
1403 // 3D trks
1404 m_allTracks.remove( m_tracks );
1405 checkRelation( m_tracks );
1406 tracks.append( m_tracks );
1407 if ( m_param.OUTPUT_2DTRACKS )
1408 {
1409 // 2D trks
1410 m_allTracks.remove( m_2dTracks );
1411 tracks2D.append( m_2dTracks );
1412 }
1413}
1414
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() ); }
1420 // cout << "ALL Wire(3D) " << allWires_3Dtrks.length() << endl;
1421
1422 for ( int i = 0; i < m_2dTracks.length(); ++i )
1423 {
1424 AList<TMLink> usedWires;
1425 for ( int j = 0; j < m_2dTracks[i]->nLinks(); ++j )
1426 {
1427 int ok = 1;
1428 for ( int k = 0; k < allWires_3Dtrks.length(); ++k )
1429 {
1430 if ( m_2dTracks[i]->links()[j]->wire()->id() == allWires_3Dtrks[k]->wire()->id() )
1431 {
1432 ok = 0;
1433 break;
1434 }
1435 }
1436 if ( ok == 0 ) { usedWires.append( m_2dTracks[i]->links()[j] ); }
1437 }
1438 // cout << i << " : used # " << usedWires.length()
1439 // << ", all # " << m_2dTracks[i]->nLinks() << endl;
1440 m_2dTracks[i]->remove( usedWires );
1441 }
1442}
1443
1444void TCurlFinder::checkRelation( AList<TTrack>& list ) {
1445 unsigned nT = list.length();
1446 if ( nT <= 1 ) return;
1447 for ( unsigned i = 0; i < nT; ++i )
1448 {
1449 if ( list[i]->daughter() )
1450 {
1451 int isHere = 0;
1452 for ( unsigned j = 0; j < nT; ++j )
1453 {
1454 if ( i != j && list[i]->daughter() == list[j] )
1455 {
1456 isHere = 1;
1457 break;
1458 }
1459 }
1460 if ( isHere == 0 ) { list[i]->daughter( NULL ); }
1461 }
1462 }
1463}
1464
1465TCircle* TCurlFinder::dividing2DTrack( TCircle* circle ) {
1466 AList<TMLink> positive, negative;
1467 for ( unsigned i = 0, size = circle->nLinks(); i < size; ++i )
1468 {
1469 if ( circle->center().x() * circle->links()[i]->hit()->wire()->xyPosition().y() -
1470 circle->center().y() * circle->links()[i]->hit()->wire()->xyPosition().x() >
1471 0. )
1472 { positive.append( circle->links()[i] ); }
1473 else { negative.append( circle->links()[i] ); }
1474 }
1475 if ( positive.length() > negative.length() )
1476 {
1477 circle->remove( negative );
1478 circle->property( 1., fabs( circle->radius() ), circle->center() );
1479 if ( negative.length() >= 3 )
1480 {
1481 TCircle* new_circle = new TCircle( negative );
1482 m_allCircles.append( new_circle );
1483 new_circle->property( -1., -1. * fabs( circle->radius() ), circle->center() );
1484 return new_circle;
1485 }
1486 else { return NULL; }
1487 }
1488 else
1489 {
1490 circle->remove( positive );
1491 circle->property( -1., -1. * fabs( circle->radius() ), circle->center() );
1492 if ( positive.length() >= 3 )
1493 {
1494 TCircle* new_circle = new TCircle( positive );
1495 m_allCircles.append( new_circle );
1496 new_circle->property( 1., fabs( circle->radius() ), circle->center() );
1497 return new_circle;
1498 }
1499 else { return NULL; }
1500 }
1501}
1502
1503void TCurlFinder::assignTracks( void ) {
1504 // 3D trks
1505 for ( int i = 0, size = m_tracks.length(); i < size; ++i )
1506 {
1507 m_tracks[i]->assign( WireHitCurlFinder );
1508 m_tracks[i]->finder( TrackCurlFinder );
1509 // m_tracks[i]->assign(WireHitCurlFinder, TrackCurlFinder | TrackValid | Track3D);
1510 }
1511
1512 // 2D trks
1513 for ( int i = 0, size = m_2dTracks.length(); i < size; ++i )
1514 {
1515 m_2dTracks[i]->assign( WireHitCurlFinder );
1516 m_2dTracks[i]->finder( TrackCurlFinder );
1517 }
1518}
1519
1520extern "C" int TCurlFinder_doubleCompare( const void* i, const void* j ) {
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;
1523 return 0;
1524}
1525
1526int TCurlFinder::trace2DTrack( TCircle* circle ) {
1527 // 0 is bad, 1 is good
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; // to reject "r=0cm" circles.
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;
1536
1537 unsigned innerOK = 0;
1538 double* angle = new double[circle->links().length()];
1539 for ( unsigned i = 0, size = nSize; i < size; ++i )
1540 {
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;
1547 angle[i] = diff;
1548 }
1549 qsort( angle, nSize, sizeof( double ), TCurlFinder_doubleCompare ); // chiisai-jun
1550 double maxDiffAngle = 0.;
1551 unsigned maxIndex = 0;
1552 for ( unsigned i = 0, size = nSize; i < size - 1; ++i )
1553 {
1554 if ( angle[i + 1] - angle[i] > maxDiffAngle )
1555 {
1556 maxDiffAngle = angle[i + 1] - angle[i];
1557 maxIndex = i;
1558 }
1559 }
1560 delete[] angle;
1561 // std::cout << "2D TRACE : maxDifAngle = " << maxDiffAngle
1562 // << ", r = " << r << ", dist = " << r*maxDiffAngle << std::endl;
1563
1564 // if(r*maxDiffAngle > m_param.TRACE2D_DISTANCE)return 0; //Liuqg, tmp. BES layer
1565 // distribution is not uniform.
1566 if ( innerOK == 1 ) return 1;
1567
1568 double q = circle->radius() > 0. ? 1. : -1;
1569 for ( unsigned i = 0, size = m_hitsOnInnerSuperLayer.length(); i < size; ++i )
1570 {
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() ) >
1576 0. )
1577 { return 1; }
1578 }
1579 return 0;
1580}
1581
1582bool TCurlFinder::check2DCircle( TCircle* circle ) {
1583 unsigned nA( nAxialHits( fabs( circle->radius() ) * 2.0 ) );
1584
1585 unsigned nMA =
1586 static_cast<unsigned>( floor( m_param.RATIO_USED_WIRE * static_cast<double>( nA ) ) );
1587 if ( nMA < 3 ) nMA = 3;
1588
1589 unsigned nAhits( 0 ), nShits( 0 );
1590 for ( unsigned i = 0, size = circle->nLinks(); i < size; ++i )
1591 {
1592 if ( ( circle->links()[i] )->wire()->axial() ) ++nAhits;
1593 else ++nShits;
1594 }
1595#if DEBUG_CURL_DUMP
1596 if ( nAhits < nMA )
1597 {
1598 std::cout << "(TCurlFinder) 2D:Fail...checking axial wires # = " << nAhits << " < "
1599 << nMA << std::endl;
1600 }
1601#endif
1602 if ( nAhits >= nMA ) return true;
1603 return false;
1604}
1605
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 )
1610 {
1611 if ( !( track->links()[i]->hit()->state() & WireHitFittingValid ) ) continue;
1612 if ( track->links()[i]->wire()->stereo() ) ++nS;
1613 else ++nA;
1614 if ( nA >= 3 && nS >= 2 ) return true;
1615 }
1616 m_tracks.remove( track );
1617#if DEBUG_CURL_DUMP
1618 std::cout << "(TCurlFinder) 3D:Checked...Fail...removing this track. Valid Axial # = "
1619 << nA << ", Stereo # = " << nS << std::endl;
1620#endif
1621 return false;
1622}
1623
1624int TCurlFinder::trace3DTrack( TTrack* track ) {
1625 // 0 is bad, 1 is good
1626 unsigned nSize = track->links().length();
1627 if ( nSize == 0 )
1628 {
1629 m_tracks.remove( track );
1630 return 0;
1631 }
1632 double r = fabs( track->helix().radius() );
1633 if ( r < 0.01 )
1634 {
1635 m_tracks.remove( track );
1636 return 0; // to reject "r=0cm" circles.
1637 }
1638 double cx = track->helix().center().x();
1639 double cy = track->helix().center().y();
1640 double th = atan2( -cy, -cx );
1641 if ( th < 0. ) th += 2. * M_PI;
1642
1643 double* angle = new double[track->links().length()];
1644 for ( unsigned i = 0, size = nSize; i < size; ++i )
1645 {
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;
1651 angle[i] = diff;
1652 }
1653 qsort( angle, nSize, sizeof( double ), TCurlFinder_doubleCompare ); // chiisai-jun
1654 double maxDiffAngle = 0.;
1655 unsigned maxIndex = 0;
1656 for ( unsigned i = 0, size = nSize; i < size - 1; ++i )
1657 {
1658 if ( angle[i + 1] - angle[i] > maxDiffAngle )
1659 {
1660 maxDiffAngle = angle[i + 1] - angle[i];
1661 maxIndex = i;
1662 }
1663 }
1664 delete[] angle;
1665 /* std::cout << "3D TRACE : maxDifAngle = " << maxDiffAngle
1666 << ", r = " << r << ", dist = " << r*maxDiffAngle << std::endl; */
1667 if ( r * maxDiffAngle > m_param.TRACE3D_DISTANCE )
1668 {
1669 m_tracks.remove( track );
1670 return 0;
1671 }
1672 else { return 1; }
1673}
1674
1675void TCurlFinder::mask3DTrack( TTrack* track, AList<TMLink>& maskList ) {
1676 double r( fabs( track->helix().radius() ) );
1677 double cx( track->helix().center().x() );
1678 double cy( track->helix().center().y() );
1679
1680 AList<TMLink> list( m_unusedAxialHits );
1681 list.append( m_unusedStereoHits );
1682 list.remove( track->links() );
1683 list.sort( SortByWireId );
1684
1685 AList<TMLink> removeList;
1686 for ( unsigned i = 0, size = list.length(); i < size; ++i )
1687 {
1688 double d = distance( *track, *( list[i] ) );
1689 if ( d < m_param.MASK_DISTANCE )
1690 {
1691 HepPoint3D tmp( d, 0., 0. );
1692 list[i]->position( tmp );
1693 removeList.append( list[i] );
1694 }
1695 }
1696
1697 int pLayerId1 = static_cast<int>( layerId( 2. * r ) );
1698 if ( pLayerId1 != 50 ) pLayerId1 -= 1; // hard coding parameter
1699 int pLayerId2 = pLayerId1 + 2; // hard coding parameter
1700
1701 AList<TMLink> preCand, cand;
1702 while ( removeList.length() )
1703 {
1704 preCand.removeAll();
1705 preCand.append( removeList[0] );
1706 if ( removeList.length() >= 2 )
1707 {
1708 for ( unsigned j = 1, size = removeList.length(); j < size; ++j )
1709 {
1710 if ( removeList[0]->wire()->layerId() == removeList[j]->wire()->layerId() )
1711 {
1712 for ( unsigned k = 0, num = preCand.length(); k < num; ++k )
1713 {
1714 if ( preCand[k]->wire()->localIdForPlus() + 1 == removeList[j]->wire()->localId() )
1715 {
1716 preCand.append( removeList[j] );
1717 break;
1718 }
1719 }
1720 }
1721 }
1722#if 1
1723 // new
1724 if ( preCand[0]->wire()->layerId() >= pLayerId1 &&
1725 preCand[0]->wire()->layerId() <= pLayerId2 )
1726 { cand.append( preCand ); }
1727 else if ( preCand.length() == 2 )
1728 { // hard coding parameter
1729 cand.append( preCand );
1730 }
1731 else if ( preCand.length() == 1 ) { cand.append( preCand[0] ); }
1732#else
1733 if ( preCand.length() == 1 )
1734 {
1735 if ( preCand[0]->position().x() < MASK_DISTANCE ) cand.append( preCand[0] );
1736 }
1737 else
1738 {
1739 if ( preCand[0]->wire()->layerId() >= pLayerId1 &&
1740 preCand[0]->wire()->layerId() <= pLayerId2 )
1741 { cand.append( preCand ); }
1742 else if ( preCand.length() == 2 )
1743 { // hard coding parameter
1744 cand.append( preCand );
1745 }
1746 }
1747#endif
1748 }
1749 else { cand.append( removeList[0] ); }
1750 removeList.remove( removeList[0] );
1751 removeList.remove( cand );
1752 }
1753 maskList.append( cand );
1754}
1755
1756TTrack* TCurlFinder::merge3DTrack( TTrack* track, AList<TTrack>& confTracks ) {
1757 if ( !m_param.MERGE_EXE ) return track;
1758
1759 AList<TTrack> tracks( confTracks );
1760 tracks.append( m_tracks );
1761 tracks.remove( track );
1762 if ( tracks.length() == 0 ) return track;
1763
1764 double r = track->helix().radius();
1765 double cx = track->helix().center().x();
1766 double cy = track->helix().center().y();
1767
1768 unsigned bestIndex = 0;
1769 double bestDiff = 1.0e+20;
1770 double R, cX, cY;
1771 for ( unsigned i = 0, size = tracks.length(); i < size; ++i )
1772 {
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 ) )
1778 {
1779 if ( fabs( cx - cX ) <= fabs( r ) * m_param.MERGE_RATIO &&
1780 fabs( cy - cY ) <= fabs( r ) * m_param.MERGE_RATIO )
1781 {
1782 double diff = fabs( ( fabs( r ) - fabs( R ) ) * ( cx - cX ) * ( cy - cY ) );
1783 if ( diff < bestDiff )
1784 {
1785 bestDiff = diff;
1786 bestIndex = i;
1787 }
1788 }
1789 }
1790 }
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();
1795 if ( r * R >= 0. )
1796 {
1797 if ( fabs( track->helix().dz() - tracks[bestIndex]->helix().dz() ) < m_param.MERGE_Z_DIFF )
1798 {
1799 if ( track->nLinks() > tracks[bestIndex]->nLinks() )
1800 {
1801 m_tracks.remove( tracks[bestIndex] );
1802 return track;
1803 }
1804 else
1805 {
1806 m_tracks.remove( track );
1807#if DEBUG_CURL_DUMP
1808 std::cout << "(TCurlFinder) 3D:Merged...removing this track.(type1)"
1809 << std::endl;
1810#endif
1811 return NULL;
1812 }
1813 }
1814 }
1815 else
1816 {
1817 bool newTrack( false ), oldTrack( false );
1818 unsigned newCounter( 0 ), oldCounter( 0 );
1819 for ( unsigned i = 0, size = m_hitsOnInnerSuperLayer.length(); i < size; ++i )
1820 {
1821 if ( !oldTrack )
1822 {
1823 if ( ( R > 0. &&
1824 cX * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY ) -
1825 cY * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cX ) >
1826 0. ) ||
1827 ( R < 0. &&
1828 cX * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY ) -
1829 cY * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cX ) <
1830 0. ) )
1831 {
1832 double dist = distance( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cX,
1833 m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cY );
1834 if ( dist < fabs( R ) )
1835 {
1836 if ( fabs( fabs( R ) - dist - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1837 {
1838 ++oldCounter;
1839 if ( oldCounter >= 3 ) oldTrack = true;
1840 }
1841 }
1842 else
1843 {
1844 if ( fabs( dist - fabs( R ) - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1845 {
1846 ++oldCounter;
1847 if ( oldCounter >= 3 ) oldTrack = true;
1848 }
1849 }
1850 }
1851 }
1852 if ( !newTrack )
1853 {
1854 if ( ( r > 0. &&
1855 cx * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy ) -
1856 cy * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cx ) >
1857 0. ) ||
1858 ( r < 0. &&
1859 cx * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy ) -
1860 cy * ( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cx ) <
1861 0. ) )
1862 {
1863 double dist = distance( m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().x() - cx,
1864 m_hitsOnInnerSuperLayer[i]->wire()->xyPosition().y() - cy );
1865 if ( dist < fabs( r ) )
1866 {
1867 if ( fabs( fabs( r ) - dist - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1868 {
1869 ++newCounter;
1870 if ( newCounter >= 3 ) newTrack = true;
1871 }
1872 }
1873 else
1874 {
1875 if ( fabs( dist - fabs( r ) - m_hitsOnInnerSuperLayer[i]->drift() ) < 0.5 )
1876 {
1877 ++newCounter;
1878 if ( newCounter >= 3 ) newTrack = true;
1879 }
1880 }
1881 }
1882 }
1883 if ( oldTrack && newTrack ) break;
1884 }
1885 if ( oldTrack && !newTrack )
1886 {
1887 m_tracks.remove( track );
1888#if DEBUG_CURL_DUMP
1889 std::cout << "(TCurlFinder) 3D:Merged...removing this track.(type2)" << std::endl;
1890#endif
1891 return NULL;
1892 }
1893 else if ( !oldTrack && newTrack )
1894 {
1895 m_tracks.remove( tracks[bestIndex] );
1896 return track;
1897 }
1898 else if ( !oldTrack && !newTrack )
1899 {
1900 m_tracks.remove( track );
1901 m_tracks.remove( tracks[bestIndex] );
1902#if DEBUG_CURL_DUMP
1903 std::cout << "(TCurlFinder) 3D:Merged...removing this track.(type3)" << std::endl;
1904#endif
1905 return NULL;
1906 }
1907 else if ( oldTrack && newTrack )
1908 {
1909 if ( fabs( track->helix().dz() ) > fabs( tracks[bestIndex]->helix().dz() ) &&
1910 fabs( track->helix().dz() ) >
1911 fabs( tracks[bestIndex]->helix().dz() ) + m_param.MERGE_Z_DIFF )
1912 {
1913 m_tracks.remove( track );
1914#if DEBUG_CURL_DUMP
1915 std::cout << "(TCurlFinder) 3D:Merged...removing this track.(type4)"
1916 << std::endl;
1917#endif
1918 return NULL;
1919 }
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 )
1923 {
1924 m_tracks.remove( tracks[bestIndex] );
1925 return track;
1926 }
1927 }
1928 }
1929 return track;
1930}
1931
1932void TCurlFinder::salvage3DTrack( TTrack* track, bool half ) {
1933 if ( track->nLinks() >= m_param.MIN_SALVAGE )
1934 {
1935 AList<TMLink> list = m_unusedAxialHits;
1936 list.append( m_unusedStereoHits );
1937 list.remove( track->links() );
1938
1939 if ( half )
1940 {
1941 double q = track->charge();
1942 double x = track->helix().center().x();
1943 double y = track->helix().center().y();
1944 AList<TMLink> removeList;
1945 const double Bz = -1000 * getPmgnIMF()->getReferField();
1946 for ( unsigned i = 0, size = list.length(); i < size; ++i )
1947 {
1948 if ( q * Bz *
1949 ( x * list[i]->wire()->xyPosition().y() -
1950 y * list[i]->wire()->xyPosition().x() ) <
1951 0. )
1952 {
1953 // if(q*(x*list[i]->wire()->xyPosition().y()-y*list[i]->wire()->xyPosition().x())<0.)
1954#ifdef TRKRECO_DEBUG_DETAIL
1955 std::cout << " " << __FILE__ << " " << __LINE__ << " removeList append " << i
1956 << std::endl;
1957#endif
1958 removeList.append( list[i] );
1959 }
1960 }
1961 list.remove( removeList );
1962 }
1963
1964 AList<TMLink> badCand, goodCand;
1965 double dist;
1966 for ( unsigned j = 0, nLinks = track->nLinks(); j < nLinks; ++j )
1967 {
1968 dist = distance( *track, *( track->links()[j] ) );
1969#ifdef TRKRECO_DEBUG_DETAIL
1970 std::cout << " " << __FILE__ << " " << __LINE__ << " " << j << " distance " << dist
1971 << std::endl;
1972#endif
1973 if ( dist > m_param.BAD_DISTANCE_FOR_SALVAGE ) badCand.append( track->links()[j] );
1974 }
1975 for ( unsigned j = 0, nList = list.length(); j < nList; ++j )
1976 {
1977 dist = distance( *track, *( list[j] ) );
1978#ifdef TRKRECO_DEBUG_DETAIL
1979 std::cout << " " << __FILE__ << " " << __LINE__ << " " << j << " distance " << dist
1980 << std::endl;
1981#endif
1982 if ( dist < m_param.GOOD_DISTANCE_FOR_SALVAGE ) goodCand.append( list[j] );
1983 }
1984 track->TTrackBase::remove( badCand );
1985 track->TTrackBase::append( goodCand );
1986 if ( m_fitter.fit( *track ) < 0 )
1987 {
1988 track->TTrackBase::remove( goodCand );
1989 track->TTrackBase::append( badCand );
1990 m_fitter.fit( *track );
1991 }
1992 }
1993 return;
1994}
1995
1996double TCurlFinder::distance( const TTrack& track, const TMLink& link ) const {
1997 // if(link.wire()->axial()){ Liuqg 060926
1998 if ( ( link.wire()->superLayerId() > 1 && link.wire()->superLayerId() < 5 ) ||
1999 link.wire()->superLayerId() > 8 )
2000 {
2001 //...axial
2002 double d = distance( track.helix().center().x() - link.xyPosition().x(),
2003 track.helix().center().y() - link.xyPosition().y() );
2004 double diff = fabs( d - fabs( track.helix().radius() ) );
2005 return fabs( link.hit()->drift() - diff );
2006 }
2007 //...stereo
2008 HepPoint3D xc( track.helix().center() );
2009 HepPoint3D xw( link.xyPosition() );
2010 HepPoint3D xt( track.helix().x() );
2011 HepVector3D v0( xt - xc ), v1( xw - xc );
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 );
2015 Vector a( track.helix().a() );
2016 double kappa = a[2];
2017 double phi0 = a[1];
2018
2019 const double Bz = -1000 * getPmgnIMF()->getReferField();
2020 // yzhang 2012-05-03
2021 double rho = m_param.ALPHA_SAME_WITH_HELIX / kappa / Bz;
2022 double tanLambda = a[4];
2023 HepVector3D v = link.wire()->direction();
2024 Vector c( 3 );
2025 c = HepPoint3D( link.wire()->backwardPosition() -
2026 ( v * link.wire()->backwardPosition() ) * v );
2027
2028 HepDiagMatrix e( 3, 1 );
2029 Matrix t( 3, 3 );
2030 t[0][0] = v.x() * v.x();
2031 t[0][1] = v.x() * v.y();
2032 t[0][2] = v.x() * v.z();
2033 t[1][0] = t[0][1];
2034 t[1][1] = v.y() * v.y();
2035 t[1][2] = v.y() * v.z();
2036 t[2][0] = t[0][2];
2037 t[2][1] = t[1][2];
2038 t[2][2] = v.z() * v.z();
2039 t -= e;
2040
2041 double factor = 1.;
2042 unsigned nTrial = 0;
2043
2044 //...Cal. closest point(Newton method)...
2045 Vector x( 3 );
2046 Vector dXdPhi( 3 );
2047 Vector d2Xd2Phi( 3 );
2048 double fOld = 0.; // The initialization is not needed.
2049 const double convergence = 1.0e-5;
2050 while ( nTrial < 100 )
2051 {
2052 x = track.helix().x( dPhi );
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;
2058
2059 //...f = d(Distance) / d phi...
2060 double f = dot( c, dXdPhi ) + dot( x, ( t * dXdPhi ) );
2061
2062 if ( fabs( f ) < convergence ) break;
2063 if ( nTrial > 0 )
2064 {
2065 double eval = ( 1. - 0.25 * factor ) * fabs( fOld ) - fabs( f );
2066 if ( eval <= 0. ) factor *= 0.5;
2067 }
2068 //...Cal. next phi...
2069 d2Xd2Phi[0] = rho * cosPhi;
2070 d2Xd2Phi[1] = rho * sinPhi;
2071 d2Xd2Phi[2] = 0.;
2072 double df =
2073 dot( c, d2Xd2Phi ) + dot( dXdPhi, ( t * dXdPhi ) ) + dot( x, ( t * d2Xd2Phi ) );
2074 dPhi -= factor * f / df;
2075
2076 fOld = f;
2077 ++nTrial;
2078 }
2079
2080 double beta = v * ( track.helix().x( dPhi ) - link.wire()->backwardPosition() );
2081 return fabs( ( link.wire()->backwardPosition() + beta * v - track.helix().x( dPhi ) ).mag() -
2082 link.hit()->drift() );
2083}
2084
2085//............................................
2086//.................2D Parts...................
2087//............................................
2088
2089TCircle* TCurlFinder::make2DTrack( const AList<TMLink>& seed,
2090 const AList<TSegmentCurl>& segmentList,
2091 const unsigned ip ) {
2092 // jialk origin is 3
2093 if ( seed.length() < m_param.minimum_seedLength ) return NULL;
2094 TCircle* circle = new TCircle( seed );
2095 m_allCircles.append( circle );
2096 int errorFlag = circle->fitForCurl( ip );
2097 // jialk add a limitation of ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK
2098 // if(fabs(circle->radius()) > m_param.MIN_RADIUS_OF_STRANGE_TRACK)return NULL;
2099 if ( ( fabs( circle->radius() ) > m_param.MIN_RADIUS_OF_STRANGE_TRACK ) ||
2100 ( fabs( circle->radius() ) < m_param.ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK ) )
2101 return NULL;
2102 int searchDirection = 1; //[ 1 : inner ], [ -1 : outer ]
2103 int searchPath( searchDirection );
2104 bool searchZero( false );
2105 bool changeDirection( false );
2106 unsigned superLayerId = seed[0]->hit()->wire()->superLayerId();
2107
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 )
2112 {
2113 if ( tmpList[i]->wire() )
2114 {
2115 if ( tmpList[i]->wire()->axial() ) preAxialCand.append( tmpList[i] );
2116 else preStereoCand.append( tmpList[i] );
2117 }
2118 }
2119#if DEBUG_CURL_DUMP
2120 std::cout << "(TCurlFinder) 2D: Superlayer of seed = " << superLayerId << std::endl;
2121#endif
2122
2123 bool appendFlag = false;
2124nextStep:
2125#if DEBUG_CURL_DUMP
2126 std::cout << "(TCurlFinder) 2D: SearchPath = " << searchPath
2127 << " Search SelfSuperlayer = " << (int)( searchZero )
2128 << " Change Direction of Search = " << (int)( changeDirection ) << std::endl;
2129#endif
2130 if ( preAxialCand.length() == 0 && preStereoCand.length() == 0 )
2131 {
2132 if ( circle->links().length() >= 3 )
2133 {
2134 if ( m_unusedAxialHits.length() == 0 )
2135 if ( errorFlag == -1 ) return NULL;
2136 else return circle;
2137 else goto salvage;
2138 }
2139 else
2140 {
2141 if ( m_unusedAxialHits.length() == 0 ) return NULL;
2142 else goto salvage;
2143 }
2144 }
2145 searchAxialCand( cand, preAxialCand, circle, searchPath, superLayerId,
2146 m_param.RANGE_FOR_AXIAL_SEARCH );
2147 if ( cand.length() > 0 )
2148 {
2149 appendFlag = true;
2150 for ( unsigned i = 0, size = cand.length(); i < size; ++i ) circle->append( *cand[i] );
2151 errorFlag = circle->fitForCurl( ip );
2152 preAxialCand.remove( circle->links() );
2153 if ( m_param.STEREO_2DFIND )
2154 {
2155 searchStereoCand( cand, preStereoCand, circle, searchPath, superLayerId,
2156 m_param.RANGE_FOR_STEREO_SEARCH );
2157 if ( cand.length() > 0 )
2158 {
2159 appendFlag = true;
2160 for ( unsigned i = 0, size = cand.length(); i < size; ++i ) circle->append( *cand[i] );
2161 errorFlag = circle->fitForCurl( ip );
2162 preStereoCand.remove( circle->links() );
2163 }
2164 }
2165 if ( searchDirection == 1 ) ++searchPath;
2166 else --searchPath;
2167 goto nextStep;
2168 }
2169 else
2170 {
2171 if ( m_param.STEREO_2DFIND )
2172 {
2173 searchStereoCand( cand, preStereoCand, circle, searchPath, superLayerId,
2174 m_param.RANGE_FOR_STEREO_SEARCH );
2175 if ( cand.length() > 0 )
2176 {
2177 appendFlag = true;
2178 for ( unsigned i = 0, size = cand.length(); i < size; ++i ) circle->append( *cand[i] );
2179 errorFlag = circle->fitForCurl( ip );
2180 preStereoCand.remove( circle->links() );
2181 if ( searchDirection == 1 ) ++searchPath;
2182 else --searchPath;
2183 goto nextStep;
2184 }
2185 else if ( ( searchPath == 1 || searchPath == -1 ) && !searchZero )
2186 {
2187 searchPath = 0;
2188 searchZero = true;
2189 goto nextStep;
2190 }
2191 else if ( ( searchPath == 1 || searchPath == -1 ) && searchZero && !changeDirection )
2192 {
2193 searchPath *= -1;
2194 searchDirection *= -1;
2195 changeDirection = true;
2196 goto nextStep;
2197 }
2198 else
2199 {
2200 if ( circle->links().length() >= 3 )
2201 {
2202 if ( m_unusedAxialHits.length() == 0 )
2203 if ( errorFlag == -1 ) return NULL;
2204 else return circle;
2205 else goto salvage;
2206 }
2207 else
2208 {
2209 if ( m_unusedAxialHits.length() == 0 ) return NULL;
2210 else goto salvage;
2211 }
2212 }
2213 }
2214 else
2215 {
2216 if ( ( searchPath == 1 || searchPath == -1 ) && !searchZero )
2217 {
2218 searchPath = 0;
2219 searchZero = true;
2220 goto nextStep;
2221 }
2222 else if ( ( searchPath == 1 || searchPath == -1 ) && searchZero && !changeDirection )
2223 {
2224 searchPath *= -1;
2225 searchDirection *= -1;
2226 changeDirection = true;
2227 goto nextStep;
2228 }
2229 else
2230 {
2231 if ( circle->links().length() >= 3 )
2232 {
2233 if ( m_unusedAxialHits.length() == 0 )
2234 if ( errorFlag == -1 ) return NULL;
2235 else return circle;
2236 else goto salvage;
2237 }
2238 else
2239 {
2240 if ( m_unusedAxialHits.length() == 0 ) return NULL;
2241 else goto salvage;
2242 }
2243 }
2244 }
2245 }
2246
2247salvage:
2248 cand.removeAll();
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 ) )
2253 {
2254 circle->append( cand );
2255 if ( circle->nLinks() >= 3 )
2256 if ( circle->fitForCurl( ip ) == -1 ) return NULL;
2257 else return circle;
2258 else return NULL;
2259 }
2260 else if ( circle->nLinks() >= 3 ) { return circle; }
2261 else return NULL;
2262}
2263
2265
2266void TCurlFinder::searchAxialCand( AList<TMLink>& cand, const AList<TMLink>& preCand,
2267 const TCircle* circle, const int depth,
2268 const unsigned superLayerID, const double searchError ) {
2269 cand.removeAll();
2270 int innerSuperLayerId = nextSuperAxialLayerId( superLayerID, depth );
2271 if ( innerSuperLayerId < 0 ) return;
2272 for ( unsigned i = 0, size = preCand.length(); i < size; ++i )
2273 {
2274 if ( preCand[i]->hit()->wire()->superLayerId() ==
2275 ( static_cast<unsigned>( innerSuperLayerId ) ) )
2276 {
2277#if 0
2278 if(searchHits(preCand[i], circle, searchError))cand.append(preCand[i]);
2279#else
2280 if ( searchHits( preCand[i], circle, searchError ) )
2281 {
2282 cand.remove( preCand[i] );
2283 cand.append( preCand[i] );
2284 TMLink* cand2 = findIsolatedCloseHits( preCand[i] );
2285 if ( cand2 )
2286 {
2287 for ( unsigned j = 0; j < size; ++j )
2288 {
2289 if ( preCand[j]->wire()->id() == cand2->wire()->id() )
2290 {
2291 cand.remove( cand2 );
2292 cand.append( cand2 );
2293# if 0
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;
2299 }else{
2300 std::cout << " Good!! this cannot be added by default!" << std::endl;
2301 }
2302# endif
2303 break;
2304 }
2305 }
2306 }
2307 }
2308#endif
2309 }
2310 }
2311}
2312
2313void TCurlFinder::searchStereoCand( AList<TMLink>& cand, const AList<TMLink>& preCand,
2314 const TCircle* circle, const int depth,
2315 const unsigned superLayerID, const double searchError ) {
2316 cand.removeAll();
2317 int innerSuperLayerId = nextSuperStereoLayerId( superLayerID, depth );
2318 if ( innerSuperLayerId < 0 || innerSuperLayerId > m_param.SUPERLAYER_FOR_STEREO_SEARCH )
2319 return;
2320 for ( unsigned i = 0, size = preCand.length(); i < size; ++i )
2321 {
2322 if ( preCand[i]->hit()->wire()->superLayerId() ==
2323 ( static_cast<unsigned>( innerSuperLayerId ) ) )
2324 {
2325 if ( searchHits( preCand[i], circle, searchError ) ) cand.append( preCand[i] );
2326 }
2327 }
2328}
2329
2330unsigned TCurlFinder::searchHits( const TMLink* link, const TCircle* circle,
2331 const double searchError ) const {
2332 // ...checks whether "link" can be added to circle.
2333 // ..."searchError" is length for checking.
2334 // ...returns 0 = error
2335 // 1 = no error
2336 double dist = distance( link->hit()->wire()->xyPosition().x() - circle->center().x(),
2337 link->hit()->wire()->xyPosition().y() - circle->center().y() );
2338 double radius = fabs( circle->radius() );
2339 // std::cout << link->wire()->localId() << " " << link->wire()->layerId() << " r="
2340 // << radius << " e=" << searchError << " d=" << dist << std::endl;
2341 if ( radius - searchError < dist && radius + searchError > dist ) return 1;
2342 return 0;
2343}
2344
2345unsigned TCurlFinder::searchHits( AList<TMLink>& cand, const AList<TMLink>& preCand,
2346 const TCircle* circle, const double searchError ) const {
2347 unsigned numBefore = cand.length();
2348 for ( unsigned i = 0, size = preCand.length(); i < size; ++i )
2349 {
2350 if ( searchHits( preCand[i], circle, searchError ) )
2351 {
2352#if 0
2353 cand.append(preCand[i]);
2354#else
2355 cand.remove( preCand[i] );
2356 cand.append( preCand[i] );
2357 TMLink* cand2 = findIsolatedCloseHits( preCand[i] );
2358 if ( cand2 )
2359 {
2360 for ( unsigned j = 0; j < size; ++j )
2361 {
2362 if ( preCand[j]->wire()->id() == cand2->wire()->id() )
2363 {
2364 cand.remove( cand2 );
2365 cand.append( cand2 );
2366 break;
2367 }
2368 }
2369 }
2370#endif
2371 }
2372 }
2373 if ( numBefore == cand.length() ) return 0;
2374 return 1;
2375}
2376
2377unsigned TCurlFinder::checkAppendHits( const AList<TMLink>& link, AList<TMLink>& cand ) const {
2378 if ( cand.length() == 0 ) return 0;
2379 AList<TMLink> tmp;
2380 for ( unsigned i = 0, size1 = cand.length(), size2 = link.length(); i < size1; ++i )
2381 {
2382 for ( unsigned j = 0; j < size2; ++j )
2383 {
2384 if ( ( cand[i] )->wire()->id() == ( link[j] )->wire()->id() )
2385 {
2386 tmp.append( cand[i] );
2387 break;
2388 }
2389 }
2390 }
2391 cand.remove( tmp );
2392 if ( cand.length() > 0 ) return 1;
2393 return 0;
2394}
2395
2396void TCurlFinder::removeStereo( TCircle& c ) const {
2397 AList<TMLink> stereoList;
2398 for ( int i = 0; i < c.links().length(); ++i )
2399 {
2400 if ( c.links()[i]->wire()->stereo() ) { stereoList.append( c.links()[i] ); }
2401 }
2402 if ( stereoList.length() > 0 ) c.remove( stereoList );
2403}
2404
2405bool TCurlFinder::fitWDD( TCircle& c, double& chi2, int& ndf ) const {
2406 if ( c.links().length() <= 3 ) return false;
2407 Lpav circle;
2408 // MDC
2409 for ( int i = 0; i < c.links().length(); ++i )
2410 {
2411 circle.add_point( ( c.links()[i] )->wire()->xyPosition().x(),
2412 ( c.links()[i] )->wire()->xyPosition().y(), 1.0 );
2413 }
2414 circle.add_point( 0., 0., 1.0 ); // IP Constraint
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 )
2421 {
2422 Lpav circle2;
2423 circle2.clear();
2424 // MDC
2425 for ( int i = 0; i < c.links().length(); ++i )
2426 {
2427 if ( !( ( c.links()[i] )->hit()->state() & WireHitFittingValid ) ) continue;
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;
2433 double U = 1. / R;
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() );
2439 circle2.add_point( X, Y, 1.0 );
2440 }
2441 circle2.add_point( 0., 0., 1.0 ); // IP Constraint
2442 if ( circle2.fit() < 0.0 || circle2.kappa() == 0.0 ) return false;
2443 xc = circle2.center()[0];
2444 yc = circle2.center()[1];
2445 r = circle2.radius();
2446 // cout << xc << ", " << yc << " : " << r << endl;
2447 }
2448
2449 // update of point information
2450 double totalChi2 = 0.;
2451 int totalNHit = 0;
2452 for ( int i = 0; i < c.links().length(); ++i )
2453 {
2454 if ( !( ( c.links()[i] )->hit()->state() & WireHitFittingValid ) ) continue;
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;
2459 double U = 1. / R;
2460 double X = xc + ( xw - xc ) * U * r;
2461 double Y = yc + ( yw - yc ) * U * r;
2462 double zlr = xw * Y - yw * X;
2463 unsigned leftRight = zlr > 0. ? WireHitRight : WireHitLeft;
2464 double pChi2 = sqrt( ( X - xw ) * ( X - xw ) + ( Y - yw ) * ( Y - yw ) ) -
2465 ( c.links()[i] )->hit()->drift();
2466 // cout << sqrt((X-xw)*(X-xw)+(Y-yw)*(Y-yw)) << " - " << (c.links()[i])->hit()->drift() <<
2467 // endl; cout << i << ": " << pChi2 << endl;
2468 if ( ( c.links()[i] )->hit()->dDrift() != 0. )
2469 {
2470 pChi2 *=
2471 pChi2 / ( ( c.links()[i] )->hit()->dDrift() * ( c.links()[i] )->hit()->dDrift() );
2472 totalChi2 += pChi2;
2473 // cout << pChi2 << ", " << c.links()[i]->hit()->dDrift() << endl;
2474 ++totalNHit;
2475 }
2476 else pChi2 = 1.0e+10;
2477 ( c.links()[i] )
2478 ->update( HepPoint3D( X, Y, 0. ), HepPoint3D( xw, yw, 0. ), leftRight, pChi2 );
2479 // cout << i << ": trk(" << X << "," << Y << "), wir(" << xw << "," << yw << ")" << endl;
2480 }
2481 chi2 = totalChi2;
2482 if ( totalNHit <= 3 ) return false;
2483 ndf = totalNHit - 3;
2484
2485 HepPoint3D center( xc, yc, 0. );
2486 double charge = 0.;
2487 //...Determine charge...Better way???
2488 int qSum = 0;
2489 for ( int i = 0; i < c.links().length(); ++i )
2490 {
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;
2497 else qSum -= 1;
2498 }
2499 if ( qSum >= 0 ) charge = +1.;
2500 else charge = -1.;
2501 r *= charge;
2502 // cout << "B q = " << c.charge() << ", r = " << c.radius() << ", center = " << c.center() <<
2503 // endl;
2504 c.property( charge, r, center );
2505 // cout << "A q = " << c.charge() << ", r = " << c.radius() << ", center = " << c.center() <<
2506 // endl;
2507 return true;
2508}
2509
2510//............................................
2511//.................3D Parts...................
2512//............................................
2513
2514TTrack* TCurlFinder::make3DTrack( const TCircle* circle, AList<TSegmentCurl>& segmentList ) {
2515 unsigned size = segmentList.length();
2516 if ( TTrack* track = make3DTrack( circle ) )
2517 {
2518 m_tracks.append( track );
2519#if 0
2520 std::cout << "MDC Helix+Pt: " << track->helix().dr() << ", "
2521 << track->helix().phi0() << ", "
2522 << track->helix().kappa() << ", "
2523 << track->helix().dz() << ", "
2524 << track->helix().tanl()
2525 << ": " << 10000./2.9979258/15./track->helix().kappa() << std::endl;
2526#endif
2527 return track;
2528 }
2529 return NULL;
2530}
2531
2532TTrack* TCurlFinder::make3DTrack( const TCircle* circle ) {
2533 TTrack* track = new TTrack( *circle );
2534 m_allTracks.append( track );
2535 // cout<<"2D: nAHits: "<<track->links().length()<<endl;
2536 // jialk caution origin is 3
2537 if ( track->links().length() < m_param.minimum_2DTrackLength )
2538 {
2539#if DEBUG_CURL_DUMP
2540 std::cout << "(TCurlFinder) 3D:Fail...inital hit wire # < 3." << std::endl;
2541#endif
2542 return NULL;
2543 }
2544 AList<TMLink> allStereoHits( m_unusedStereoHits );
2545 allStereoHits.remove( track->links() );
2546 AList<TMLink> closeHits;
2547 findCloseHits( allStereoHits, *track, closeHits );
2548 // if(!m_builder.buildStereo(*track, closeHits)){
2549 // jialk inorder to improve track robustness
2550 if ( closeHits.length() < m_param.minimum_closeHitsLength )
2551 {
2552#if DEBUG_CURL_DUMP
2553 std::cout << "(TCurlFinder) 3D:Fail...stereohit wire # < 5." << std::endl;
2554#endif
2555 return NULL;
2556 }
2557 // if(!m_builder.buildStereo(*track, closeHits)){
2558 if ( !m_builder.buildStereo( *track, closeHits, m_allStereoHitsOriginal ) )
2559 {
2560#if DEBUG_CURL_DUMP
2561 std::cout << "(TCurlFinder) 3D:Fail...can not build stereo." << std::endl;
2562#endif
2563 return NULL;
2564 }
2565 // jialk add a limitation ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK
2566 // if(fabs(track->helix().radius()) > m_param.MIN_RADIUS_OF_STRANGE_TRACK){
2567 if ( ( fabs( circle->radius() ) > m_param.MIN_RADIUS_OF_STRANGE_TRACK ) ||
2568 ( fabs( circle->radius() ) < m_param.ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK ) )
2569 {
2570#if DEBUG_CURL_DUMP
2571 std::cout << "(TCurlFinder) 3D:Fail...success 3D fit, but large radius > "
2572 << m_param.MIN_RADIUS_OF_STRANGE_TRACK << "." << std::endl;
2573#endif
2574 return NULL;
2575 }
2576 // jialk caution origin is 5
2577 if ( track->links().length() >= m_param.minimum_3DTrackLength )
2578 {
2579#if DEBUG_CURL_DUMP
2580 std::cout << "(TCurlFinder) 3D:Success...can build stereo!!!" << std::endl;
2581#endif
2582 return track;
2583 }
2584 else
2585 {
2586#if DEBUG_CURL_DUMP
2587 std::cout << "(TCurlFinder) 3D:Fail...success 3D fit, but final hit wire # < 3."
2588 << std::endl;
2589#endif
2590 return NULL;
2591 }
2592}
2593
2595 int nNeighbor = 0;
2596 int nIsolated = 0;
2597 TMLink* isolatedLink[2] = { NULL, NULL };
2598 unsigned layerID = link->wire()->layerId();
2599 unsigned localID = link->wire()->localId();
2600 for ( int i = 0; i < 6; ++i )
2601 {
2602 if ( link->neighbor( i ) )
2603 {
2604 if ( link->neighbor( i )->wire()->layerId() == layerID )
2605 {
2606 ++nNeighbor;
2607 int isolated = 1;
2608 int testEach = 0; // for test
2609 for ( int j = 0; j < 6; ++j )
2610 {
2611 if ( link->neighbor( i )->neighbor( j ) )
2612 {
2613 if ( link->neighbor( i )->neighbor( j )->wire()->layerId() == layerID &&
2614 link->neighbor( i )->neighbor( j )->wire()->localId() != localID )
2615 { isolated = 0; }
2616#if 1
2617 else if ( link->neighbor( i )->neighbor( j )->wire()->layerId() == layerID &&
2618 link->neighbor( i )->neighbor( j )->wire()->localId() == localID )
2619 { testEach = 1; }
2620#endif
2621 }
2622 else break;
2623 }
2624 if ( isolated == 1 )
2625 {
2626 if ( nIsolated < 2 ) isolatedLink[nIsolated] = link->neighbor( i );
2627 ++nIsolated;
2628 }
2629#if 1
2630 if ( testEach == 0 )
2631 { std::cout << "Why?? Neighborhood info. dose not exist!!" << std::endl; }
2632#endif
2633 }
2634 }
2635 else break;
2636 }
2637#if 0
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;
2644#endif
2645 if ( nIsolated == 1 && nNeighbor == 1 && isolatedLink[0] ) return isolatedLink[0];
2646 else return NULL;
2647}
2648
2649void TCurlFinder::findCloseHits( AList<TMLink>& links, TTrack& track, AList<TMLink>& list ) {
2650 // ...finds candidates in the "links".
2651 // ...Candidates mean |"track" - wire(from "links" elements)| < dRcut
2652 // ...returns these candidates("list").
2653 double dRcut[11] = { m_param.RANGE_FOR_STEREO_FIRST,
2654 m_param.RANGE_FOR_STEREO_SECOND,
2655 0.,
2656 0.,
2657 0.,
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,
2662 0.,
2663 0. };
2664 double r = fabs( track.helix().curv() );
2665 double q = track.charge();
2666 double x = track.helix().center().x();
2667 double y = track.helix().center().y();
2668 for ( unsigned i = 0, size = links.length(); i < size; ++i )
2669 {
2670 if ( fabs( ( links[i]->wire()->xyPosition() - track.helix().center() ).mag() - r ) <
2671 dRcut[links[i]->wire()->superLayerId()] )
2672 {
2673 if ( q * ( x * links[i]->wire()->xyPosition().y() -
2674 y * links[i]->wire()->xyPosition().x() ) >
2675 0. )
2676 {
2677 list.remove( links[i] );
2678 list.append( links[i] );
2679 TMLink* cand = findIsolatedCloseHits( links[i] );
2680 if ( cand )
2681 {
2682 list.remove( cand );
2683 list.append( cand );
2684 }
2685 }
2686 }
2687 }
2688 return;
2689}
2690
2691//..................................................
2692//..................................................
2693//..................................................
2694//..................................................
2695//..................................................
2696
2697int TCurlFinder::makeWithMC( const AList<TMDCWireHit>& axialHits,
2698 const AList<TMDCWireHit>& stereoHits, AList<TTrack>& tracks ) {
2699#if DEBUG_CURL_MC
2700# define MAX_INDEX_MAKEMC 100
2701# if DEBUG_CURL_DUMP
2702 std::cout << "(TCurlFinder)Now making tracks using MC info..." << std::endl;
2703# endif
2704 int index[MAX_INDEX_MAKEMC];
2705 for ( unsigned i = 0; i < MAX_INDEX_MAKEMC; ++i ) index[i] = 9999;
2706
2707 int counter( 0 );
2708 bool first( true );
2709
2710 for ( unsigned i = 0, size = axialHits.length(); i < size; ++i )
2711 {
2712 if ( axialHits[i]->mc() && axialHits[i]->mc()->hep() &&
2713 !( axialHits[i]->state() & WireHitUsed ) )
2714 {
2715 int flag( 1 );
2716 for ( unsigned j = 0; j < MAX_INDEX_MAKEMC; ++j )
2717 {
2718 if ( index[j] != 9999 && index[j] == axialHits[i]->mc()->hep()->id() )
2719 {
2720 flag = 0;
2721 break;
2722 }
2723 }
2724 if ( flag )
2725 {
2726 index[counter] = axialHits[i]->mc()->hep()->id();
2727 ++counter;
2728 }
2729 }
2730 }
2731# if DEBUG_CURL_DUMP
2732 std::cout << "(TCurlFinder)Found " << counter << " tracks with MC information." << std::endl;
2733# endif
2734 for ( unsigned j = 0; j < counter; ++j )
2735 {
2736 AList<TMLink> axialList;
2737 AList<TMLink> stereoList;
2738 int axialCounter( 0 );
2739 int stereoCounter( 0 );
2740 //...axial
2741 for ( unsigned i = 0, size = axialHits.length(); i < size; ++i )
2742 {
2743 if ( index[j] == axialHits[i]->mc()->hep()->id() &&
2744 !( axialHits[i]->state() & WireHitUsed ) )
2745 {
2746 axialList.append( new TMLink( 0, axialHits[i] ) );
2747 ++axialCounter;
2748 }
2749 }
2750 if ( axialCounter < 3 )
2751 {
2752 HepAListDeleteAll( axialList );
2753 continue;
2754 }
2755 //...stereo
2756 for ( unsigned i = 0, size = stereoHits.length(); i < size; ++i )
2757 {
2758 if ( index[j] == stereoHits[i]->mc()->hep()->id() &&
2759 !( stereoHits[i]->state() & WireHitUsed ) )
2760 {
2761 stereoList.append( new TMLink( 0, stereoHits[i] ) );
2762 ++stereoCounter;
2763 }
2764 }
2765 if ( stereoCounter < 2 )
2766 {
2767 HepAListDeleteAll( axialList );
2768 HepAListDeleteAll( stereoList );
2769 continue;
2770 }
2771# if DEBUG_CURL_DUMP
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;
2776# endif
2777
2778 m_unusedAxialHitsOriginal.append( axialList );
2779 m_unusedAxialHitsOriginal.append( stereoList );
2780 TCircle* circle = new TCircle( axialList );
2781 m_allCircles.append( circle );
2782 circle->fitForCurl();
2783 double charge = 1.;
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 )
2788 charge *= -1.;
2789 circle->property( charge, charge * fabs( circle->radius() ), circle->center() );
2790
2791 AList<TMLink> removeList;
2792 double x = circle->center().x();
2793 double y = circle->center().y();
2794 //...axial
2795 for ( unsigned i = 0, size = axialList.length(); i < size; ++i )
2796 {
2797 if ( charge *
2798 ( x * axialList[i]->xyPosition().y() - y * axialList[i]->xyPosition().x() ) <
2799 0. )
2800 { removeList.append( axialList[i] ); }
2801 }
2802 circle->remove( removeList );
2803 if ( circle->nLinks() < 3 ) continue;
2804 //...refits
2805 circle->fitForCurl( 1 );
2806 x = circle->center().x();
2807 y = circle->center().y();
2808 removeList.removeAll();
2809 ///...stereo
2810 for ( unsigned i = 0, size = stereoList.length(); i < size; ++i )
2811 {
2812 if ( charge *
2813 ( x * stereoList[i]->xyPosition().y() - y * stereoList[i]->xyPosition().x() ) <
2814 0. )
2815 { removeList.append( stereoList[i] ); }
2816 }
2817 stereoList.remove( removeList );
2818 if ( stereoList.length() < 2 ) continue;
2819
2820 TTrack* track = new TTrack( *circle );
2821 m_allTracks.append( track );
2822 if ( m_builder.buildStereoMC( *track, stereoList ) )
2823 {
2824 if ( track->links().length() >= 5 )
2825 {
2826 track->assign( WireHitCurlFinder, TrackCurlFinder | TrackValid | Track3D );
2827 tracks.append( track );
2828 m_allTracks.remove( track );
2829 }
2830 else { std::cout << "Can not reconstruct with MC information!" << std::endl; }
2831 }
2832 else { std::cout << "Can not reconstruct with MC information!" << std::endl; }
2833 }
2834#endif
2835 return 0;
2836}
2837
2838void TCurlFinder::makeCdcFrame( void ) {
2839#if DEBUG_CURL_GNUPLOT + DEBUG_CURL_SEGMENT
2840 // #if 1
2841 double X = 0.;
2842 double Y = 0.;
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 };
2844 double step = 300.;
2845 double dStep = 2. * M_PI / step;
2846 FILE* data;
2847 std::string nameHead = "tmp.cdc_";
2848 for ( int j = 0; j < 12; ++j )
2849 {
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 )
2853 {
2854 for ( int i = 0; i < step; ++i )
2855 {
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 );
2859 }
2860 fclose( data );
2861 }
2862 }
2863
2864 if ( ( data = fopen( "tmp_wires.dat", "w" ) ) != NULL )
2865 {
2866 AList<TMLink> list = m_unusedAxialHitsOriginal;
2867 list.append( m_unusedStereoHitsOriginal );
2868 for ( int i = 0; i < list.length(); i++ )
2869 {
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 );
2873 }
2874 fclose( data );
2875 }
2876#endif
2877 return;
2878}
2879
2880void TCurlFinder::plotSegment( const AList<TMLink>& list, const int flag ) {
2881#if DEBUG_CURL_GNUPLOT
2882 if ( !m_debugCdcFrame )
2883 {
2884 makeCdcFrame();
2885 m_debugCdcFrame = true;
2886 }
2887 double gmaxX = 90., gminX = -90.;
2888 double gmaxY = 90., gminY = -90.;
2889 FILE * gnuplot, *data;
2890 if ( ( data = fopen( "tmp.dat", "w" ) ) != NULL )
2891 {
2892 if ( flag ) std::cout << "Wire ID = ";
2893 for ( int i = 0; i < list.length(); i++ )
2894 {
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() << ", ";
2899 }
2900 if ( flag ) std::cout << std::endl;
2901 fclose( data );
2902 }
2903 if ( ( gnuplot = popen( "gnuplot", "w" ) ) != NULL )
2904 {
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 )
2912 {
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;
2916 }
2917 longName += " \n";
2918 fprintf( gnuplot, longName );
2919 fflush( gnuplot );
2920 char tmp[8];
2921 gets( tmp );
2922 pclose( gnuplot );
2923 }
2924#endif
2925 return;
2926}
2927
2928void TCurlFinder::plotCircle( const TCircle& circle, const int flag ) {
2929#if DEBUG_CURL_GNUPLOT
2930 // #if 1
2931 if ( !m_debugCdcFrame )
2932 {
2933 makeCdcFrame();
2934 m_debugCdcFrame = true;
2935 }
2936 double gmaxX = 90., gminX = -90.;
2937 double gmaxY = 90., gminY = -90.;
2938 FILE * gnuplot, *data;
2939 if ( ( data = fopen( "tmp.dat1", "w" ) ) != NULL )
2940 {
2941 if ( flag ) std::cout << "Axial Wire ID ==> " << std::endl;
2942 for ( int i = 0; i < circle.nLinks(); ++i )
2943 {
2944 if ( circle.links()[i]->hit()->wire()->axial() )
2945 {
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 );
2949 if ( flag )
2950 {
2951 /*if(debugMcFlag){
2952 std::cout << " A:" << circle.links()[i]->hit()->wire()->id() << ", ";
2953 std::cout << ", HepTrackID = " << circle.links()[i]->hit()->mc()->hep()->id();
2954 std::cout << ", HepLundID = " << circle.links()[i]->hit()->mc()->hep()->pType() <<
2955 std::endl; }else std::cout << " A:" << circle.links()[i]->hit()->wire()->id() <<
2956 std::endl;*/
2957 }
2958 }
2959 }
2960 if ( flag ) std::cout << std::endl;
2961 fclose( data );
2962 }
2963 if ( ( data = fopen( "tmp.dat2", "w" ) ) != NULL )
2964 {
2965 if ( flag ) std::cout << "Stereo Wire ID ==> " << std::endl;
2966 for ( int i = 0; i < circle.nLinks(); ++i )
2967 {
2968 if ( circle.links()[i]->hit()->wire()->stereo() )
2969 {
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 );
2973 if ( flag )
2974 {
2975 /*if(debugMcFlag){
2976 std::cout << " S:" << circle.links()[i]->hit()->wire()->id() << ", ";
2977 std::cout << ", HepTrackID = " << circle.links()[i]->hit()->mc()->hep()->id();
2978 std::cout << ", HepLundID = " << circle.links()[i]->hit()->mc()->hep()->pType() <<
2979 std::endl; }else std::cout << " S:" << circle.links()[i]->hit()->wire()->id() <<
2980 std::endl;*/
2981 }
2982 }
2983 }
2984 if ( flag ) std::cout << std::endl;
2985 fclose( data );
2986 }
2987 double X = circle.center().x();
2988 double Y = circle.center().y();
2989 double R = fabs( circle.radius() );
2990 double step = 300.;
2991 double dStep = 2. * M_PI / step;
2992 if ( ( data = fopen( "tmp.dat3", "w" ) ) != NULL )
2993 {
2994 for ( int i = 0; i < step; ++i )
2995 {
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 );
2999 }
3000 fclose( data );
3001 }
3002 if ( ( gnuplot = popen( "gnuplot", "w" ) ) != NULL )
3003 {
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 )
3012 {
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;
3016 }
3017 longName += " \n";
3018 fprintf( gnuplot, longName );
3019 fflush( gnuplot );
3020 char tmp[8];
3021 gets( tmp );
3022 pclose( gnuplot );
3023 }
3024#endif
3025 return;
3026}
3027
3028void TCurlFinder::plotTrack( const TTrack& track, const int flag ) {
3029#if DEBUG_CURL_GNUPLOT
3030 if ( !m_debugCdcFrame )
3031 {
3032 makeCdcFrame();
3033 m_debugCdcFrame = true;
3034 }
3035 double gmaxX = 90., gminX = -90.;
3036 double gmaxY = 90., gminY = -90.;
3037 FILE * gnuplot, *data;
3038 if ( ( data = fopen( "tmp.dat1", "w" ) ) != NULL )
3039 {
3040 if ( flag ) std::cout << "Axial Wire ID ==> " << std::endl;
3041 for ( int i = 0; i < track.nLinks(); ++i )
3042 {
3043 if ( track.links()[i]->hit()->wire()->axial() )
3044 {
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 );
3048 if ( flag )
3049 {
3050 if ( debugMcFlag )
3051 {
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()
3055 << std::endl;
3056 }
3057 else std::cout << " A:" << track.links()[i]->hit()->wire()->id() << std::endl;
3058 }
3059 }
3060 }
3061 if ( flag ) std::cout << std::endl;
3062 fclose( data );
3063 }
3064 if ( ( data = fopen( "tmp.dat2", "w" ) ) != NULL )
3065 {
3066 if ( flag ) std::cout << "Stereo Wire ID ==> " << std::endl;
3067 for ( int i = 0; i < track.nLinks(); ++i )
3068 {
3069 if ( track.links()[i]->hit()->wire()->stereo() )
3070 {
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 );
3074 if ( flag )
3075 {
3076 if ( debugMcFlag )
3077 {
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()
3081 << std::endl;
3082 }
3083 else std::cout << " S:" << track.links()[i]->hit()->wire()->id() << std::endl;
3084 }
3085 }
3086 }
3087 if ( flag ) std::cout << std::endl;
3088 fclose( data );
3089 }
3090 double X = track.helix().center().x();
3091 double Y = track.helix().center().y();
3092 double R = fabs( track.helix().radius() );
3093 double step = 300.;
3094 double dStep = 2. * M_PI / step;
3095 if ( ( data = fopen( "tmp.dat3", "w" ) ) != NULL )
3096 {
3097 for ( int i = 0; i < step; ++i )
3098 {
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 );
3102 }
3103 fclose( data );
3104 }
3105 if ( ( gnuplot = popen( "gnuplot", "w" ) ) != NULL )
3106 {
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 )
3115 {
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;
3119 }
3120 longName += " \n";
3121 fprintf( gnuplot, longName );
3122 fflush( gnuplot );
3123 char tmp[8];
3124 gets( tmp );
3125 pclose( gnuplot );
3126 }
3127#endif
3128 return;
3129}
3130
3131void TCurlFinder::writeSegment( const AList<TMLink>& list, const int type ) {
3132#if DEBUG_CURL_SEGMENT
3133 if ( !m_debugCdcFrame )
3134 {
3135 makeCdcFrame();
3136 m_debugCdcFrame = true;
3137 }
3138 double gmaxX = 90., gminX = -90.;
3139 double gmaxY = 90., gminY = -90.;
3140
3141 FILE* data;
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 )
3147 {
3148 for ( int i = 0; i < list.length(); i++ )
3149 {
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 );
3153 }
3154 fclose( data );
3155 }
3156#endif
3157 return;
3158}
3159
3160void TCurlFinder::dumpType1( TTrack* track ) {
3161#if DEBUG_CURL_DUMP
3162 for ( int j = 0; j < track->nLinks(); ++j )
3163 {
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() << ", "; }
3168 if ( debugMcFlag )
3169 {
3170 std::cout << ", HepTrackID = " << track->links()[j]->hit()->mc()->hep()->id();
3171 std::cout << ", HepLundID = " << track->links()[j]->hit()->mc()->hep()->pType();
3172 }
3173 double dist = distance( *track, *( track->links()[j] ) );
3174 if ( dist > 2. ) std::cout << ": Large Distance( >2cm ) = " << dist;
3175 std::cout << std::endl;
3176 }
3177 AList<TMLink> list = m_unusedAxialHits;
3178 list.append( m_unusedStereoHits );
3179 for ( unsigned j = 0, nList = list.length(); j < nList; ++j )
3180 {
3181 double dist = distance( *track, *( list[j] ) );
3182 std::cout << "Close Wire Info in ALL( <0.5cm )...";
3183 if ( dist < 0.5 )
3184 {
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() << ", ";
3188 if ( debugMcFlag )
3189 {
3190 std::cout << ", HepTrackID = " << list[j]->hit()->mc()->hep()->id();
3191 std::cout << ", HepLundID = " << list[j]->hit()->mc()->hep()->pType();
3192 }
3193 std::cout << ", Distance = " << dist << std::endl;
3194 }
3195 }
3196#endif
3197 return;
3198}
3199
3200void TCurlFinder::dumpType2( TTrack* track ) {
3201#if DEBUG_CURL_DUMP
3202 unsigned size = track->nLinks();
3203 if ( size == 0 ) return;
3204
3205 set<int, less<int>> uniqueHepID;
3206 vector<int> hepID;
3207 vector<double> ratio;
3208 for ( int i = 0; i < size; ++i )
3209 {
3210 uniqueHepID.insert( track->links()[i]->hit()->mc()->hep()->id() );
3211 hepID.push_back( track->links()[i]->hit()->mc()->hep()->id() );
3212 // std::cout << i << " : " << track->links()[i]->hit()->mc()->hep()->id() << std::endl;
3213 }
3214
3215 set<int, less<int>>::iterator u = uniqueHepID.begin();
3216 vector<int>::size_type sizeInt;
3217 for ( unsigned i = 0; i < uniqueHepID.size(); ++i )
3218 {
3219 sizeInt = 0;
3220 count( hepID.begin(), hepID.end(), *u, sizeInt );
3221 ratio.push_back( ( static_cast<double>( sizeInt ) / static_cast<double>( size ) ) );
3222 // std::cout << "HepID = " << *u << ", Ratio = " << ratio[i] << " = " << sizeInt << "/" <<
3223 // size << std::endl;
3224 ++u;
3225 }
3226
3227 vector<double>::iterator m = max_element( ratio.begin(), ratio.end() );
3228 int maxIndex = 0;
3229 ::distance( ratio.begin(), m, maxIndex );
3230 u = uniqueHepID.begin();
3231 advance( u, maxIndex );
3232 // std::cout << "MAX HepID = " << *u << ", Ratio = " << ratio[maxIndex] << std::endl;
3233 std::cout << "Ratio " << ratio[maxIndex] << std::endl;
3234 for ( int i = 0; i < size; ++i )
3235 {
3236 if ( track->links()[i]->hit()->wire()->axial() ) std::cout << "A ";
3237 else std::cout << "S ";
3238
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; }
3243 }
3244#endif
3245 return;
3246}
3247
3248// #if DEBUG_CURL_MC
3249#if 0
3250// --> TSegmentUtil.h
3251/*
3252sortBySvdRLA( const Datsvd_hit **a, const Datsvd_hit **b ) {
3253 if( (*a)->rla() < (*b)->rla() ){
3254 return -1;
3255 }else if( (*a)->rla() == (*b)->rla() ){
3256 return 0;
3257 }else{
3258 return 1;
3259 }
3260}
3261*/
3262
3263Gen_hepevt *
3264cluster2hep(Recsvd_cluster *clus) {
3265 AList<Datsvd_hit> m_datsvd_hit;
3266 Datsvd_hit_Manager& svdHitMgr = Datsvd_hit_Manager::get_manager();
3267 for(Datsvd_hit_Manager::iterator
3268 it = svdHitMgr.begin(),
3269 end = svdHitMgr.end();
3270 it != end; ++it){
3271 m_datsvd_hit.append(it);
3272 }
3273// m_datsvd_hit.sort(sortBySvdRLA);
3274
3275 unsigned size = m_datsvd_hit.length();
3276 int startPosition = -1;
3277 int direction = 1;
3278# if 0
3279 for(unsigned i=0;i<size;++i){
3280 //if(clus->width() == 1)
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;
3285 }
3286# endif
3287 for(unsigned i=0;i<size;++i){
3288 if(m_datsvd_hit[i]->amp() == 0)std::cout << "DatSVD_Hit:amp == 0" << std::endl;
3289 //if(m_datsvd_hit[i]->amp() == 640)std::cout << "DatSVD_Hit:amp == 640" << 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()){
3293 startPosition = i;
3294 if(static_cast<double>(m_datsvd_hit[i]->amp()-1) > clus->lsa())direction = -1;
3295 break;
3296 }
3297 }
3298 if(startPosition == -1)return NULL;
3299 int width = clus->width();
3300# if 0
3301 std::cout << "Start # = " << startPosition
3302 << ", Width = " << width
3303 << ", Direction = " << direction <<std::endl;
3304# endif
3305
3306 int* hepID = new int[width];
3307 set< int, less<int> > uniqueHepID;
3308
3309 for(int i=startPosition;i<startPosition+width;++i)hepID[i-startPosition] = 0;
3310 //Datsvd_mchit_Manager& svdMcHitMgr = Datsvd_mchit_Manager::get_manager();
3311 Datsvd_mcdata_Manager& svdMcHitMgr = Datsvd_mcdata_Manager::get_manager();
3312 //std::cout << "SVD MC# = " << svdMcHitMgr.count() << std::endl;
3313 if(direction == 1){
3314 for(int i=startPosition;i<startPosition+width;++i){
3315 for(Datsvd_mcdata_Manager::iterator
3316 it = svdMcHitMgr.begin(),
3317 end = svdMcHitMgr.end();
3318 it != end; ++it){
3319 if(it->Hep()){
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());
3324 break;
3325 }
3326 }
3327 }
3328 }
3329 }else{
3330 int reverse = 0;
3331 for(int i=startPosition;i<startPosition+width;++i){
3332 ++reverse;
3333 //std::cout << startPosition+1-reverse << " --- "
3334 // << i << std::endl;
3335 for(Datsvd_mcdata_Manager::iterator
3336 it = svdMcHitMgr.begin(),
3337 end = svdMcHitMgr.end();
3338 it != end; ++it){
3339 if(it->Hep()){
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());
3344 break;
3345 }
3346 }
3347 }
3348 }
3349 }
3350
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;
3355
3356 for(int i=0;i<num;++i){
3357 for(int j=0;j<width;++j){
3358 if(*u == hepID[j]){
3359 counter[i] += 1;
3360 }
3361 }
3362 ++u;
3363 }
3364
3365 Gen_hepevt_Manager& genMgr = Gen_hepevt_Manager::get_manager();
3366# if 0
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;
3372 ++u;
3373 }
3374# endif
3375
3376 delete [] hepID;
3377 delete [] counter;
3378 if(num == 1){
3379 //std::cout << *(uniqueHepID.begin())-1 << std::endl;
3380 return &(genMgr[*(uniqueHepID.begin())-1]);
3381 }else if(num >= 2){
3382 //std::cout << "A svd cluster is not unique." << std::endl;
3383 return NULL;
3384 }else{
3385 return NULL;
3386 }
3387}
3388#endif
3389
3390void TCurlFinder::debugCheckSegments1( void ) {
3391#if DEBUG_CURL_SEGMENT
3392 // Slow Checker(CPU time increases!!)
3393 // Neighboring wires should be included in the same segement.
3394 std::cout << "(TCurlFinder)checking consistency of segement..." << std::endl;
3395 unsigned nA = m_unusedAxialHitsOriginal.length();
3396 if ( nA >= 2 )
3397 {
3398 for ( unsigned i = 0; i < nA - 1; ++i )
3399 {
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 )
3406 {
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 )
3411 {
3412 if ( layerId2 == layerId )
3413 {
3414 if ( localIdP + 1 == localId2 || localIdM - 1 == localId2 )
3415 debugCheckSegments( localId, layerId, localId2, layerId2 );
3416 }
3417 else if ( layerId2 == layerId - 1 || layerId2 == layerId + 1 )
3418 {
3419 if ( offset( layerId ) == offset( layerId2 ) )
3420 {
3421 std::cout << "(TCurlFinder: Waring) Offset is same at the same superlayer!!"
3422 << std::endl;
3423 }
3424 else if ( offset( layerId ) > offset( layerId2 ) )
3425 {
3426 if ( localId == localId2 || localIdP + 1 == localId2 )
3427 debugCheckSegments( localId, layerId, localId2, layerId2 );
3428 }
3429 else
3430 {
3431 if ( localId == localId2 || localIdM - 1 == localId2 )
3432 debugCheckSegments( localId, layerId, localId2, layerId2 );
3433 }
3434 }
3435 }
3436 }
3437 }
3438 }
3439 unsigned nS = m_unusedStereoHitsOriginal.length();
3440 if ( nS >= 2 )
3441 {
3442 for ( unsigned i = 0; i < nS - 1; ++i )
3443 {
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 )
3450 {
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 )
3455 {
3456 if ( layerId2 == layerId )
3457 {
3458 if ( localIdP + 1 == localId2 || localIdM - 1 == localId2 )
3459 debugCheckSegments( localId, layerId, localId2, layerId2 );
3460 }
3461 else if ( layerId2 == layerId - 1 || layerId2 == layerId + 1 )
3462 {
3463 if ( offset( layerId ) == offset( layerId2 ) )
3464 {
3465 std::cout << "(TCurlFinder: Waring) Offset is same at the same superlayer!!"
3466 << std::endl;
3467 }
3468 else if ( offset( layerId ) > offset( layerId2 ) )
3469 {
3470 if ( localId == localId2 || localIdP + 1 == localId2 )
3471 debugCheckSegments( localId, layerId, localId2, layerId2 );
3472 }
3473 else
3474 {
3475 if ( localId == localId2 || localIdM - 1 == localId2 )
3476 debugCheckSegments( localId, layerId, localId2, layerId2 );
3477 }
3478 }
3479 }
3480 }
3481 }
3482 }
3483 std::cout << "(TCurlFinder)...done check of segement!" << std::endl;
3484 std::cout << "(TCurlFinder)...If no warning message exists, check of segement is complete!"
3485 << std::endl;
3486 std::cout << "(TCurlFinder)...Note: a segment size should be 1 or 2 to use this debugger."
3487 << std::endl;
3488#endif
3489 return;
3490}
3491
3492void TCurlFinder::debugCheckSegments( const double localId, const double layerId,
3493 const double localId2, const double layerId2 ) {
3494#if DEBUG_CURL_DUMP
3495 unsigned nSeg = m_segmentList.length();
3496 unsigned nFound = 0;
3497 for ( unsigned i = 0; i < nSeg; ++i )
3498 {
3499 unsigned nWire = m_segmentList[i]->list().length();
3500 unsigned mFound = 0;
3501 for ( unsigned j = 0; j < nWire; ++j )
3502 {
3503 if ( ( ( m_segmentList[i]->list() )[j] )->wire()->layerId() == layerId &&
3504 ( ( m_segmentList[i]->list() )[j] )->wire()->localId() == localId )
3505 ++mFound;
3506 if ( ( ( m_segmentList[i]->list() )[j] )->wire()->layerId() == layerId2 &&
3507 ( ( m_segmentList[i]->list() )[j] )->wire()->localId() == localId2 )
3508 ++mFound;
3509 }
3510 if ( mFound != 0 && mFound != 2 )
3511 {
3512 std::cout << "(TCurlFinder: Warning) Segment is inconsistency(0)!! mFound = " << mFound
3513 << std::endl;
3514 }
3515 if ( mFound == 2 ) ++nFound;
3516 }
3517 if ( nFound != 1 )
3518 std::cout << "(TCurlFinder: Warning) Segment is inconsistency(1)!! nFound = " << nFound
3519 << std::endl;
3520#endif
3521 return;
3522}
3523
3524void TCurlFinder::debugCheckSegments0( void ) {
3525#if DEBUG_CURL_SEGMENT
3526 unsigned nSeg = m_segmentList.length();
3527 unsigned nWire = 0;
3528 for ( unsigned i = 0; i < nSeg; ++i ) nWire += m_segmentList[i]->list().length();
3529
3530 unsigned nWireOriginal =
3531 m_unusedAxialHitsOriginal.length() + m_unusedStereoHitsOriginal.length();
3532
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
3536 << std::endl;
3537 std::cout << " Wire # of Segments = " << nWire << std::endl;
3538 std::cout << " If MIN_SEGMENT <= 1, above numbers should be same."
3539 << std::endl;
3540 std::cout << " If MIN_SEGMENT > 1, former >= latter."
3541 << std::endl;
3542#endif
3543 return;
3544}
3545
3546void TCurlFinder::debugCheckSegments2( void ) {
3547#if DEBUG_CURL_SEGMENT
3548
3549# define DEBUG_TMP_N_CURL 50
3550
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 )
3556 {
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] );
3560 }
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 };
3565 if ( fin )
3566 {
3567 for ( int i = 0; i < DEBUG_TMP_N_CURL; ++i ) fin >> nTotalWire[i];
3568 }
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" );
3572 if ( fout )
3573 {
3574 fout << nTotalWire[0];
3575 for ( int i = 1; i < DEBUG_TMP_N_CURL; ++i ) fout << " " << nTotalWire[i];
3576 }
3577 else { std::cout << "(TCurlFinder) tmp.wire.data can not be made!" << std::endl; }
3578#endif
3579 return;
3580}
3581
3582IBesMagFieldSvc* TCurlFinder::getPmgnIMF() const {
3583 if ( nullptr == m_pmgnIMF )
3584 {
3585 StatusCode sc = Gaudi::svcLocator()->service( "MagneticFieldSvc", m_pmgnIMF );
3586 if ( sc.isFailure() )
3587 { std::cout << "Unable to open Magnetic field service" << std::endl; }
3588 }
3589 return m_pmgnIMF;
3590}
3591
3592#undef DEBUG_CURL_DUMP
3593#undef DEBUG_CURL_SEGMENT
3594#undef DEBUG_CURL_GNUPLOT
3595#undef DEBUG_CURL_MC
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const Int_t n
TTree * data
Double_t x[10]
#define max(a, b)
DOUBLE_PRECISION count[3]
EvtTensor3C eps(const EvtVector3R &v)
****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
Definition KKsem.h:33
**********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
Definition KarLud.h:35
#define M_PI
Definition TConstant.h:4
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.
HepVector center() const
void add_point(double x, double y, double w=1)
A class to represent a circle in tracking.
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.
Definition TCircle.cxx:131
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
TCurlFinder(void)
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 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.
void append(TMLink &)
void dump(void)
void update(void)
void removeAll(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
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.
Definition TTrack.cxx:3648
const Helix & helix(void) const
returns helix parameter.
double charge(void) const
returns charge.
Index next(Index i)
Index first(Pair i)
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)
Definition TUtil.h:22
int t()
Definition t.c:1