21{
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 CLHEP::Hep3Vector
thrust(0,0,0);
38
39 int agree=0;
40 int disagree=0;
41
42 CLHEP::Hep3Vector n_0[20];
43 short add0[20] = { 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1,-1 };
44 short add1[20] = { 0, 1, 0, 0, 1, 1, 1, 1,-1,-1,-1,-1, 1, 1, 1, 1,-1,-1,-1,-1 };
45 short add2[20] = { 0, 0, 1, 0, 1, 1,-1,-1, 1, 1,-1,-1, 1, 1,-1,-1, 1, 1,-1,-1 };
46 short add3[20] = { 0, 0, 0, 1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1 };
47
48 std::vector<const INavigable4Momentum*> v_copy(4);
49
50
51
52
53 partial_sort_copy( iBeg, iEnd,
54 v_copy.begin(), v_copy.end(),
55 P4Sorters::Descending::Ene() );
56
57 int n_tests=0;
58 int max_tests=std::min<int>(20, std::distance(iBeg, iEnd));
59 do{
60 n_0[n_tests]=CLHEP::Hep3Vector(0,0,0);
61
62
63 n_0[n_tests] +=
64 add0[n_tests] * CLHEP::Hep3Vector(v_copy.at(0)->px(), v_copy.at(0)->py(), v_copy.at(0)->pz()) +
65 add1[n_tests] * CLHEP::Hep3Vector(v_copy.at(1)->px(), v_copy.at(1)->py(), v_copy.at(1)->pz()) +
66 add2[n_tests] * CLHEP::Hep3Vector(v_copy.at(2)->px(), v_copy.at(2)->py(), v_copy.at(2)->pz()) +
67 add3[n_tests] * CLHEP::Hep3Vector(v_copy.at(3)->px(), v_copy.at(3)->py(), v_copy.at(3)->pz());
68
69 if(!useThreeD)
70 n_0[n_tests].setZ(0);
71
72
73
74
75
76
77 if(n_0[n_tests].
mag()>0)
78 n_0[n_tests] /= n_0[n_tests].mag();
79
82 do{
83 CLHEP::Hep3Vector n_1(0,0,0);
85 {
86
87 if((*itr)->px() * n_0[n_tests].x() +
88 (*itr)->py() * n_0[n_tests].y() +
89 (*itr)->pz() * n_0[n_tests].z() > 0 )
90 n_1 += CLHEP::Hep3Vector((*itr)->px(), (*itr)->py(), (*itr)->pz() );
91 else
92 n_1 -= CLHEP::Hep3Vector((*itr)->px(), (*itr)->py(), (*itr)->pz() );
93 }
94
95 if(!useThreeD)
96 n_1.setZ(0);
97
98
99 if(n_1.mag()>0)
100 n_1 /= n_1.mag();
101
102
103 run = ( n_0[n_tests]!=n_1 ) && ( -n_0[n_tests]!=n_1 ) &&
loop++<10;
104 n_0[n_tests] = n_1;
105 }while( run );
106
107
108
109 if( n_tests>0 && ( n_0[0] == n_0[n_tests] || n_0[0] == -n_0[n_tests] ) ) agree++;
110 if( n_tests>0 && n_0[0] != n_0[n_tests] && n_0[0] != -n_0[n_tests] ) disagree++;
111
112
113
114 }while( ( disagree>0 || agree<4 ) && ++n_tests < max_tests);
115
116
117
118
119 n_tests=0;
120 do{
122 double numerator_t = 0;
123 double numerator_m = 0;
125 {
126 CLHEP::Hep3Vector
c((*itr)->hlv().vect());
128 numerator_t += abs(
c.dot(n_0[n_tests]));
129 numerator_m += (
c.cross(n_0[n_tests])).mag();
131 }
133 if( numerator_t * inv_denominator > thrust_major )
134 {
135 thrust_major = numerator_t * inv_denominator;
136 thrust_minor = numerator_m * inv_denominator;
138 }
139 }while(disagree>0 && ++n_tests < max_tests);
140
141
142
143
144
145
146
148}
Scalar mag() const
mag method