BOSS 8.0.0
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 : yoshihito.iwasaki@kek.jp
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"
44#include "TrkReco/TMDCWireHitMC.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 CathodeSectorId( unsigned id ) {
60
61 unsigned layer = id / 64;
62
63 if ( layer == 0 ) { return int( id / 8 ); }
64
65 if ( layer == 1 )
66 {
67 if ( id >= 127 ) id -= 64;
68 if ( ( id - 6 ) % 8 == 0 ) return ( id - 6 ) / 8 + 0.5;
69 else return int( ( id + 1 ) / 8 );
70 }
71
72 if ( layer == 2 )
73 {
74 if ( id <= 129 ) id += 64;
75 return int( ( id - 2 ) / 8 );
76 }
77
78 return 9999;
79}
80// end
81
82void bitDisplay( unsigned val ) { bitDisplay( val, 31, 0 ); }
83
84void bitDisplay( unsigned val, unsigned f, unsigned l ) {
85 unsigned i;
86 for ( i = 0; i < f - l; i++ )
87 {
88 if ( ( i % 8 ) == 0 ) std::cout << " ";
89 std::cout << ( val >> ( f - i ) ) % 2;
90 }
91}
92
93int intersection( const HepPoint3D& c1, double r1, const HepPoint3D& c2, double r2, double eps,
94 HepPoint3D& x1, HepPoint3D& x2 ) {
95
96 double c0x = c2.x() - c1.x();
97 double c0y = c2.y() - c1.y();
98 double c0 = sqrt( c0x * c0x + c0y * c0y );
99 double rr1 = abs( r1 );
100 double rr2 = abs( r2 );
101 double Radd = rr1 + rr2;
102 double Rsub = abs( rr1 - rr2 );
103
104 // no intersections
105
106 if ( c0 > Radd + eps || c0 < 0.001 || c0 < Rsub - eps )
107 {
108 //-- debug
109 // std::cout << "Int2Cir return 0 " << std::endl;
110 //-- debug end
111 return 0;
112 }
113
114 // single intersection
115
116 else
117 {
118 if ( c0 > Radd - eps )
119 {
120 x1.setX( c1.x() + rr1 * c0x / c0 );
121 x1.setY( c1.y() + rr1 * c0y / c0 );
122 x2.setX( 0.0 );
123 x2.setY( 0.0 );
124 //--debug
125 // std::cout << "Int2Cir return 1" << std::endl;
126 //--debug end
127 return 1;
128 }
129 }
130
131 // two intersections
132
133 double chg = abs( r1 ) / r1;
134 double cosPsi = ( c0 * c0 + rr1 * rr1 - rr2 * rr2 ) / ( 2. * c0 * rr1 );
135 double sinPsi = -( chg / abs( chg ) ) * sqrt( 1.0 - cosPsi * cosPsi );
136 x1.setX( c1.x() + ( rr1 / c0 ) * ( cosPsi * c0x - sinPsi * c0y ) );
137 x1.setY( c1.y() + ( rr1 / c0 ) * ( cosPsi * c0y + sinPsi * c0x ) );
138 x2.setX( c1.x() + ( rr1 / c0 ) * ( cosPsi * c0x + sinPsi * c0y ) );
139 x2.setY( c1.y() + ( rr1 / c0 ) * ( cosPsi * c0y - sinPsi * c0x ) );
140 //-- debug
141 // std::cout << "Int2Cir return 2" << std::endl;
142 //-- debug end
143 return 2;
144}
145
146// from by jtanaka
147double chisq2confLevel( int n, double chi2 ) {
148#define SRTOPI 0.7978846
149#define UPL 340.0
150#define ROOT2I 0.70710678
151
152 double prob = 0.0;
153 double sum, term;
154 int m;
155 int i, k;
156 double temp_i, temp_n;
157 double srty;
158
159 if ( ( n <= 0 ) || ( chi2 < 0.0 ) ) { return prob; }
160 if ( n > 60 )
161 {
162 temp_n = (double)n;
163 srty = sqrt( chi2 ) - sqrt( temp_n - 0.5 );
164 if ( srty < 12.0 )
165 {
166 prob = 0.5 * erfc( srty );
167 return prob;
168 }
169 return prob;
170 }
171 if ( chi2 > UPL ) { return prob; }
172 sum = exp( -0.5 * chi2 );
173 term = sum;
174 m = (int)floor( n / 2. );
175
176 if ( 2 * m == n )
177 {
178 if ( m == 1 )
179 {
180 prob = sum;
181 return prob;
182 }
183 else
184 {
185 for ( i = 2; i < m + 1; i++ )
186 {
187 temp_i = (double)i;
188 term = 0.5 * chi2 * term / ( temp_i - 1.0 );
189 sum = sum + term;
190 }
191 prob = sum;
192 return prob;
193 }
194 }
195 else
196 {
197 srty = sqrt( chi2 );
198 prob = erfc( ROOT2I * srty );
199 if ( n == 1 ) { return prob; }
200 if ( n == 3 )
201 {
202 prob = SRTOPI * srty * sum + prob;
203 return prob;
204 }
205 else
206 {
207 k = m - 1;
208 for ( i = 1; i < k + 1; i++ )
209 {
210 temp_i = (double)i;
211 term = term * chi2 / ( 2.0 * temp_i + 1.0 );
212 sum = sum + term;
213 }
214 prob = SRTOPI * srty * sum + prob;
215 return prob;
216 }
217 }
218}
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const Int_t n
EvtComplex exp(const EvtComplex &c)
EvtTensor3C eps(const EvtVector3R &v)
const HepPoint3D ORIGIN
Constants.
Definition TMDCUtil.cxx:47
#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:93
void bitDisplay(unsigned val)
Definition TMDCUtil.cxx:82
double chisq2confLevel(int n, double chi2)
ALPHA = 10000. / 2.99792458 / 15.
Definition TMDCUtil.cxx:147
float CathodeSectorId(unsigned id)
geocdc utilities
Definition TMDCUtil.cxx:59
#define SRTOPI