BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
TMDCUtil.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TMDCUtil.cxx,v 1.7 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TMDCUtil.cc
5// Section : Tracking MDC
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : Utilities for MDC analyses and tracking.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13/* for erfc */
14#if defined(__sparc)
15# if defined(__EXTENSIONS__)
16# include <cmath>
17# else
18# define __EXTENSIONS__
19# include <cmath>
20# undef __EXTENSIONS__
21# endif
22#elif defined(__GNUC__)
23# if defined(_XOPEN_SOURCE)
24# include <cmath>
25# else
26# define _XOPEN_SOURCE
27# include <cmath>
28# undef _XOPEN_SOURCE
29# endif
30#endif
31
32#if defined(__SUNPRO_CC)
33// for erfc and other functions (lgamma and cbrt
34# include <math.h>
35#endif
36
37//#include "panther/panther.h"
38//#include MDC_H
39//#include "MdcRecGeo/MdcRecGeo.h"
40//#include "MdcGeomSvc/MdcGeomSvc.h"
41#include "TrkReco/TMDCUtil.h"
42#include "TrkReco/TMDCWire.h"
43#include "TrkReco/TMDCWireHit.h"
45#include "TrkReco/TMLink.h"
46
47const HepPoint3D ORIGIN = HepPoint3D(0., 0., 0.);
48
49//added by matsu
50
51// CathodeSectorId
52//---------------------------------------
53// input : wire id ( 0 - 189 )
54// output : cathode sector id ( 0 - 23 )
55// ( layer 0 : 0,1,...,7 )
56// ( layer 1 : 8,8.5,9,...,15,15.5)
57// ( layer 2 : 16,17,...,23)
58
59float
60CathodeSectorId(unsigned id) {
61
62 unsigned layer = id/64;
63
64 if ( layer == 0 ){
65 return int(id/8);
66 }
67
68 if( layer == 1 ){
69 if( id >= 127 ) id -= 64;
70 if( (id-6)%8 == 0 ) return (id-6)/8 + 0.5;
71 else return int((id+1)/8);
72 }
73
74 if ( layer == 2 ) {
75 if( id <= 129 ) id += 64;
76 return int((id-2)/8);
77 }
78
79 return 9999;
80
81}
82// end
83
84void
85bitDisplay(unsigned val) {
86 bitDisplay(val, 31, 0);
87}
88
89void
90bitDisplay(unsigned val, unsigned f, unsigned l) {
91 unsigned i;
92 for (i = 0; i < f - l; i++) {
93 if ((i % 8) == 0) std::cout << " ";
94 std::cout << (val >> (f - i)) % 2;
95 }
96}
97
98int
100 double r1,
101 const HepPoint3D & c2,
102 double r2,
103 double eps,
104 HepPoint3D & x1,
105 HepPoint3D & x2) {
106
107 double c0x = c2.x() - c1.x() ;
108 double c0y = c2.y() - c1.y() ;
109 double c0 = sqrt ( c0x*c0x + c0y*c0y ) ;
110 double rr1 = abs(r1) ;
111 double rr2 = abs(r2) ;
112 double Radd = rr1 + rr2 ;
113 double Rsub = abs( rr1 - rr2 ) ;
114
115 // no intersections
116
117 if ( c0 > Radd + eps || c0 < 0.001 || c0 < Rsub - eps ) {
118 //-- debug
119 //std::cout << "Int2Cir return 0 " << std::endl;
120 //-- debug end
121 return 0 ;
122 }
123
124 // single intersection
125
126 else {
127 if ( c0 > Radd - eps ) {
128 x1.setX(c1.x() + rr1*c0x/c0);
129 x1.setY(c1.y() + rr1*c0y/c0);
130 x2.setX(0.0);
131 x2.setY(0.0);
132 //--debug
133 //std::cout << "Int2Cir return 1" << std::endl;
134 //--debug end
135 return 1 ;
136 }
137 }
138
139 // two intersections
140
141 double chg = abs(r1) / r1 ;
142 double cosPsi = ( c0*c0 + rr1*rr1 - rr2*rr2 ) / (2.*c0*rr1 ) ;
143 double sinPsi = - ( chg/abs(chg) ) * sqrt(1.0 - cosPsi*cosPsi) ;
144 x1.setX(c1.x() + ( rr1/c0 )*( cosPsi*c0x - sinPsi*c0y ));
145 x1.setY(c1.y() + ( rr1/c0 )*( cosPsi*c0y + sinPsi*c0x ));
146 x2.setX(c1.x() + ( rr1/c0 )*( cosPsi*c0x + sinPsi*c0y ));
147 x2.setY(c1.y() + ( rr1/c0 )*( cosPsi*c0y - sinPsi*c0x ));
148 //-- debug
149 //std::cout << "Int2Cir return 2" << std::endl;
150 //-- debug end
151 return 2 ;
152
153}
154
155// from by jtanaka
156double chisq2confLevel(int n,double chi2){
157#define SRTOPI 0.7978846
158#define UPL 340.0
159#define ROOT2I 0.70710678
160
161 double prob = 0.0;
162 double sum,term;
163 int m;
164 int i,k;
165 double temp_i,temp_n;
166 double srty;
167
168 if((n <= 0)||(chi2 < 0.0)){
169 return prob;
170 }
171 if(n > 60){
172 temp_n = (double)n;
173 srty = sqrt(chi2) - sqrt(temp_n-0.5);
174 if (srty < 12.0){
175 prob = 0.5*erfc(srty);
176 return prob;
177 }
178 return prob;
179 }
180 if(chi2 > UPL){
181 return prob;
182 }
183 sum = exp( -0.5 * chi2 );
184 term = sum;
185 m = (int)floor(n/2.);
186
187 if( 2*m == n ){
188 if( m == 1 ){
189 prob = sum;
190 return prob;
191 }else{
192 for(i=2;i<m+1;i++){
193 temp_i = (double)i;
194 term = 0.5*chi2*term/(temp_i-1.0);
195 sum = sum + term;
196
197 }
198 prob = sum;
199 return prob;
200 }
201 }else{
202 srty = sqrt(chi2);
203 prob = erfc(ROOT2I*srty);
204 if(n == 1){
205 return prob;
206 }
207 if(n == 3){
208 prob = SRTOPI*srty*sum + prob;
209 return prob;
210 }else{
211 k = m - 1;
212 for(i=1;i<k+1;i++){
213 temp_i = (double)i;
214 term = term*chi2/(2.0*temp_i + 1.0);
215 sum = sum + term;
216 }
217 prob = SRTOPI*srty*sum + prob;
218 return prob;
219 }
220 }
221}
const Int_t n
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtTensor3C eps(const EvtVector3R &v)
Definition: EvtTensor3C.cc:307
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
#define UPL
#define ROOT2I
int intersection(const HepPoint3D &c1, double r1, const HepPoint3D &c2, double r2, double eps, HepPoint3D &x1, HepPoint3D &x2)
Circle utilities.
Definition: TMDCUtil.cxx:99
void bitDisplay(unsigned val)
Definition: TMDCUtil.cxx:85
const HepPoint3D ORIGIN
Constants.
Definition: TMDCUtil.cxx:47
double chisq2confLevel(int n, double chi2)
ALPHA = 10000. / 2.99792458 / 15.
Definition: TMDCUtil.cxx:156
float CathodeSectorId(unsigned id)
geocdc utilities
Definition: TMDCUtil.cxx:60
#define SRTOPI
TCanvas * c1
Definition: tau_mode.c:75