BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
THistogram.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: THistogram.cxx,v 1.8 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : THistogram.h
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A class for a histogram used in tracking.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#include <stdio.h>
14#include <stdlib.h>
15
16#include "TrkReco/TCircle.h"
17#include "TrkReco/THistogram.h"
18
19THistogram::THistogram( unsigned nBins ) : _nBins( nBins ) {
20 _binSize = 2. * M_PI / (float)_nBins;
21 _bins = (unsigned*)malloc( _nBins * sizeof( unsigned ) );
22 _masks = (bool*)malloc( _nBins * sizeof( bool ) );
23 _links = (AList<TMLink>**)malloc( _nBins * sizeof( AList<TMLink>* ) );
24 for ( unsigned i = 0; i < _nBins; i++ )
25 {
26 _bins[i] = 0;
27 _masks[i] = false;
28 _links[i] = new AList<TMLink>;
29 }
30}
31
33 free( _bins );
34 free( _masks );
35 for ( unsigned i = 0; i < _nBins; i++ ) delete _links[i];
36 free( _links );
37}
38
39void THistogram::dump( const std::string& msg, const std::string& pre ) const {
40 std::cout << pre;
41 std::cout << "THistogram dump:#bins=" << _nBins << std::endl;
42 unsigned nLoops = _nBins / 15 + 1;
43 unsigned n0 = 0;
44 unsigned n1 = 0;
45 for ( unsigned i = 0; i < nLoops; i++ )
46 {
47 for ( unsigned j = 0; j < 15; j++ )
48 {
49 if ( n0 == _nBins ) break;
50 printf( "%4d", n0 );
51 ++n0;
52 }
53 std::cout << std::endl;
54 for ( unsigned j = 0; j < 15; j++ )
55 {
56 if ( n1 == _nBins ) break;
57 if ( !_masks[n1] ) printf( "%4d", _bins[n1] );
58 else printf( "-%3d", _bins[n1] );
59 ++n1;
60 }
61 std::cout << std::endl;
62 }
63
64 if ( msg.find( "detail" ) != std::string::npos )
65 {
66 for ( unsigned i = 0; i < _nBins; i++ )
67 {
68 std::cout << "bin " << i << " : ";
69 for ( unsigned j = 0; j < _links[i]->length(); j++ )
70 { std::cout << ( *_links[i] )[j]->wire()->name() << ","; }
71 std::cout << std::endl;
72 }
73 }
74
75 return;
76}
77
78void THistogram::fillX( const AList<TMLink>& links ) {
79 _all = (AList<TMLink>&)links;
80 unsigned nLinks = links.length();
81 double offset = _binSize / 4.;
82 for ( unsigned i = 0; i < nLinks; i++ )
83 {
84 TMLink* l = links[i];
85 const HepPoint3D& p = l->position();
86 unsigned pos = (unsigned)floor( ( p.x() + offset ) / _binSize );
87
88 //...Why is this needed?...
89 pos %= _nBins;
90
91 ++_bins[pos];
92 _links[pos]->append( l );
93 }
94}
95
96void THistogram::fillY( const AList<TMLink>& links ) {
97 _all = (AList<TMLink>&)links;
98 unsigned nLinks = links.length();
99 for ( unsigned i = 0; i < nLinks; i++ )
100 {
101 TMLink* l = links[i];
102 const HepPoint3D& p = l->position();
103 unsigned pos = (unsigned)floor( p.y() / _binSize );
104
105 //...Why is this needed?...
106 pos %= _nBins;
107
108 ++_bins[pos];
109 _links[pos]->append( l );
110 }
111}
112
113void THistogram::fillPhi( const AList<TMLink>& links ) {
114 _all = (AList<TMLink>&)links;
115 unsigned nLinks = links.length();
116 double offset = _binSize / 4.;
117 for ( unsigned i = 0; i < nLinks; i++ )
118 {
119 TMLink* l = links[i];
120 const HepPoint3D& p = l->position();
121 float phi = atan2( p.y(), p.x() ) + M_PI;
122 // std::cout<<"atan "<<atan2(-1., -1.)<<std::endl;
123 unsigned pos = (unsigned)floor( ( phi + offset ) / _binSize );
124
125 // std::cout <<"layer "<<l->wire()->layerId()<<" cell "<<l->wire()->localId()
126 // <<" x "<<p.x()<<" y "<<p.y()<<" pos "<<pos<<" xypos hit
127 //"<<l->hit()->xyPosition()<<" xypos wire "<<l->wire()->xyPosition()<<" drift
128 //"<<l->hit()->drift(0)<< "+-" <<l->hit()->dDrift(0)<<std::endl; std::cout<<"binsize
129 //"<<_binSize<<" offset "<<offset<<" phi "<<phi<<std::endl;
130 //...Why is this needed?...
131 pos %= _nBins;
132
133 ++_bins[pos];
134 _links[pos]->append( l );
135 }
136}
137
138void THistogram::remove( const AList<TMLink>& links ) {
139 for ( unsigned i = 0; i < _nBins; i++ )
140 {
141 _links[i]->remove( links );
142 _bins[i] = _links[i]->length();
143 }
144 _all.remove( links );
145}
146
147AList<TMLink> THistogram::contents( unsigned center, unsigned width ) const {
148 AList<TMLink> links;
149 for ( int i = -(int)width; i <= (int)width; i++ )
150 { links.append( *bin( (int)center + i ) ); }
151 return links;
152}
153
154AList<TMLink> THistogram::contents( int start, int end ) const {
155 AList<TMLink> links;
156 for ( int i = start; i <= end; i++ ) links.append( *bin( i ) );
157 return links;
158}
159
161 AList<TSegment0> list;
162
163 //...Serach for empty bin...
164 unsigned begin = 0;
165 while ( _bins[begin] > 0 ) begin++;
166 if ( begin == _nBins ) return list;
167
168 //...Start searching...
169 unsigned loop = 0;
170 while ( loop < _nBins )
171 {
172 ++loop;
173 unsigned id = ( begin + loop ) % _nBins;
174 if ( _bins[id] )
175 {
176 unsigned size = 0;
177 TSegment0* c = new TSegment0();
178 while ( _bins[id] )
179 {
180 if ( _bins[id] ) ++size;
181 c->append( *_links[id] );
182 ++loop;
183 id = ( begin + loop ) % _nBins;
184 if ( loop == _nBins ) break;
185 }
186 list.append( c );
187 }
188 }
189 return list;
190}
191
193
194 //...Obtain raw clusters...
196 unsigned n = list.length();
197 if ( n == 0 ) return list;
198
199 //...Examine each cluster...
200 AList<TSegment0> splitted;
201 for ( unsigned i = 0; i < n; i++ )
202 {
203 TSegment0* c = list[i];
204
205 AList<TSegment0> newClusters = c->split();
206 if ( newClusters.length() == 0 )
207 {
208 c->solveDualHits();
209 continue;
210 }
211
212 list.append( newClusters );
213 splitted.append( c );
214#ifdef TRKRECO_DEBUG_DETAIL
215 c->dump( "hits", " " );
216 std::cout << " ... splitted as" << std::endl;
217 for ( unsigned j = 0; j < newClusters.length(); j++ )
218 {
219 std::cout << " " << j << " : ";
220 newClusters[j]->dump( "hits" );
221 }
222#endif
223 }
224 list.remove( splitted );
225 HepAListDeleteAll( splitted );
226
227 return list;
228}
229
231 AList<TSegment> list;
232 // std::cout<<"enter clusters"<<std::endl;
233 //...Serach for empty bin...
234 unsigned begin = 0;
235 while ( _bins[begin] > 0 ) begin++;
236 if ( begin == _nBins ) return list;
237
238 //...Start searching...
239 unsigned loop = 0;
240 while ( loop < _nBins )
241 {
242 ++loop;
243 unsigned id = ( begin + loop ) % _nBins;
244 if ( _bins[id] )
245 {
246 unsigned size = 0;
247 TSegment* c = new TSegment();
248 while ( _bins[id] )
249 {
250 if ( _bins[id] ) ++size;
251 c->append( *_links[id] );
252 ++loop;
253 id = ( begin + loop ) % _nBins;
254 if ( loop == _nBins ) break;
255 }
256 list.append( c );
257 }
258 }
259 return list;
260}
261
263 // yuany
264 /*
265 for (unsigned i = 0; i < _nBins; i++) {
266 std::cout<<"i "<<i<<" bins[i] "<<_bins[i]<<std::endl;
267 }
268 */
269 //...Obtain raw clusters...
270 AList<TSegment> list = clusters();
271 unsigned n = list.length();
272 if ( n == 0 ) return list;
273
274 //...Examine each cluster...
275 AList<TSegment> splitted;
276 for ( unsigned i = 0; i < n; i++ )
277 {
278 TSegment* c = list[i];
279
280#ifdef TRKRECO_DEBUG_DETAIL
281 std::cout << " base segment : ";
282 c->dump( "hits" );
283#endif
284
285 AList<TSegment> newClusters = c->split();
286 if ( newClusters.length() == 0 )
287 {
288#ifdef TRKRECO_DEBUG_DETAIL
289 std::cout << " ... Solving dual hits" << std::endl;
290#endif
291 c->solveDualHits();
292 continue;
293 }
294
295 list.append( newClusters );
296 splitted.append( c );
297#ifdef TRKRECO_DEBUG_DETAIL
298 c->dump( "hits", " " );
299 std::cout << " ... splitted as" << std::endl;
300 for ( unsigned j = 0; j < newClusters.length(); j++ )
301 {
302 std::cout << " " << j << " : ";
303 newClusters[j]->dump( "hits" );
304 }
305#endif
306 }
307 list.remove( splitted );
308 HepAListDeleteAll( splitted );
309
310 // yuany
311 // n = list.length();
312 // for (unsigned i = 0; i < n; i++) {
313 // TSegment * c = list[i];
314 // std::cout << " base segment : ";
315 // c->dump("hits");
316 // }
317
318 return list;
319}
HepGeom::Point3D< double > HepPoint3D
const Int_t n
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
Definition FoamA.h:85
int n1
Definition SD0Tag.cxx:58
#define M_PI
Definition TConstant.h:4
const AList< TMLink > & contents(void) const
returns an AList<TMLink> of all contents.
virtual ~THistogram()
Destructor.
THistogram(unsigned nBins)
Constructor.
unsigned nBins(void) const
returns # of bins.
AList< TSegment0 > clusters0(void) const
returns an AList<TSegment0> of clusters.
void fillX(const AList< TMLink > &links)
fills with hits.
void remove(const AList< TMLink > &links)
removes links.
AList< TSegment > segments(void) const
returns an AList<TSegment0> using clusters() function.
AList< TSegment0 > segments0(void) const
returns an AList<TSegment0> using clusters() function.
const AList< TMLink > *const bin(unsigned i) const
returns a pointer to i'th AList<TMLink>.
void fillY(const AList< TMLink > &links)
fills with hits.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
void fillPhi(const AList< TMLink > &links)
fills with hits.
AList< TSegment > clusters(void) const
returns an AList<TSegment0> of clusters.
A class to relate TMDCWireHit and TTrack objects.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition TSegment0.cxx:49
int solveDualHits(void)
AList< TSegment0 > split(void) const
A class to relate TMDCWireHit and TTrack objects.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition TSegment.cxx:113
AList< TSegment > split(void) const
Definition TSegment.cxx:406
int solveDualHits(void)
Definition TSegment.cxx:778
void append(TMLink &)
appends a TMLink.