BOSS 7.0.8
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 : [email protected]
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/THistogram.h"
17#include "TrkReco/TCircle.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 _bins[i] = 0;
26 _masks[i] = false;
27 _links[i] = new AList<TMLink>;
28 }
29}
30
32 free(_bins);
33 free(_masks);
34 for (unsigned i = 0; i < _nBins; i++)
35 delete _links[i];
36 free(_links);
37}
38
39void
40THistogram::dump(const std::string & msg, const std::string & pre) const {
41 std::cout << pre;
42 std::cout << "THistogram dump:#bins=" << _nBins << std::endl;
43 unsigned nLoops = _nBins / 15 + 1;
44 unsigned n0 = 0;
45 unsigned n1 = 0;
46 for (unsigned i = 0; i < nLoops; i++) {
47 for (unsigned j = 0; j < 15; j++) {
48 if (n0 == _nBins) break;
49 printf("%4d", n0);
50 ++n0;
51 }
52 std::cout << std::endl;
53 for (unsigned j = 0; j < 15; j++) {
54 if (n1 == _nBins) break;
55 if (! _masks[n1]) printf("%4d", _bins[n1]);
56 else printf("-%3d", _bins[n1]);
57 ++n1;
58 }
59 std::cout << std::endl;
60 }
61
62 if (msg.find("detail") != std::string::npos) {
63 for (unsigned i = 0; i < _nBins; i++) {
64 std::cout << "bin " << i << " : ";
65 for (unsigned j = 0; j < _links[i]->length(); j++) {
66 std::cout << (* _links[i])[j]->wire()->name() << ",";
67 }
68 std::cout << std::endl;
69 }
70 }
71
72 return;
73}
74
75void
77 _all = (AList<TMLink> &) links;
78 unsigned nLinks = links.length();
79 double offset = _binSize / 4.;
80 for (unsigned i = 0; i < nLinks; i++) {
81 TMLink * l = links[i];
82 const HepPoint3D & p = l->position();
83 unsigned pos = (unsigned) floor((p.x() + offset) / _binSize);
84
85 //...Why is this needed?...
86 pos %= _nBins;
87
88 ++_bins[pos];
89 _links[pos]->append(l);
90 }
91}
92
93void
95 _all = (AList<TMLink> &) links;
96 unsigned nLinks = links.length();
97 for (unsigned i = 0; i < nLinks; i++) {
98 TMLink * l = links[i];
99 const HepPoint3D & p = l->position();
100 unsigned pos = (unsigned) floor(p.y() / _binSize);
101
102 //...Why is this needed?...
103 pos %= _nBins;
104
105 ++_bins[pos];
106 _links[pos]->append(l);
107 }
108}
109
110void
112 _all = (AList<TMLink> &) links;
113 unsigned nLinks = links.length();
114 double offset = _binSize / 4.;
115 for (unsigned i = 0; i < nLinks; i++) {
116 TMLink * l = links[i];
117 const HepPoint3D & p = l->position();
118 float phi = atan2(p.y(), p.x()) + M_PI;
119// std::cout<<"atan "<<atan2(-1., -1.)<<std::endl;
120 unsigned pos = (unsigned) floor((phi + offset) / _binSize);
121
122// std::cout <<"layer "<<l->wire()->layerId()<<" cell "<<l->wire()->localId()
123// <<" x "<<p.x()<<" y "<<p.y()<<" pos "<<pos<<" xypos hit "<<l->hit()->xyPosition()<<" xypos wire "<<l->wire()->xyPosition()<<" drift "<<l->hit()->drift(0)<< "+-" <<l->hit()->dDrift(0)<<std::endl;
124// std::cout<<"binsize "<<_binSize<<" offset "<<offset<<" phi "<<phi<<std::endl;
125 //...Why is this needed?...
126 pos %= _nBins;
127
128 ++_bins[pos];
129 _links[pos]->append(l);
130 }
131}
132
133void
135 for (unsigned i = 0; i < _nBins; i++) {
136 _links[i]->remove(links);
137 _bins[i] = _links[i]->length();
138 }
139 _all.remove(links);
140}
141
143THistogram::contents(unsigned center, unsigned width) const {
144 AList<TMLink> links;
145 for (int i = - (int) width;
146 i <= (int) width;
147 i++) {
148 links.append(* bin((int) center + i));
149 }
150 return links;
151}
152
154THistogram::contents(int start, int end) const {
155 AList<TMLink> links;
156 for (int i = start; i <= end; i++)
157 links.append(* bin(i));
158 return links;
159}
160
163 AList<TSegment0> list;
164
165 //...Serach for empty bin...
166 unsigned begin = 0;
167 while (_bins[begin] > 0) begin++;
168 if (begin == _nBins) return list;
169
170 //...Start searching...
171 unsigned loop = 0;
172 while (loop < _nBins) {
173 ++loop;
174 unsigned id = (begin + loop) % _nBins;
175 if (_bins[id]) {
176 unsigned size = 0;
177 TSegment0 * c = new TSegment0();
178 while (_bins[id]) {
179 if (_bins[id]) ++size;
180 c->append(* _links[id]);
181 ++loop;
182 id = (begin + loop) % _nBins;
183 if (loop == _nBins) break;
184 }
185 list.append(c);
186 }
187 }
188 return list;
189}
190
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 TSegment0 * c = list[i];
203
204 AList<TSegment0> newClusters = c->split();
205 if (newClusters.length() == 0) {
206 c->solveDualHits();
207 continue;
208 }
209
210 list.append(newClusters);
211 splitted.append(c);
212#ifdef TRKRECO_DEBUG_DETAIL
213 c->dump("hits", " ");
214 std::cout << " ... splitted as" << std::endl;
215 for (unsigned j = 0; j < newClusters.length(); j++) {
216 std::cout << " " << j << " : ";
217 newClusters[j]->dump("hits");
218 }
219#endif
220 }
221 list.remove(splitted);
222 HepAListDeleteAll(splitted);
223
224 return list;
225
226}
227
230 AList<TSegment> list;
231// std::cout<<"enter clusters"<<std::endl;
232 //...Serach for empty bin...
233 unsigned begin = 0;
234 while (_bins[begin] > 0)begin++;
235 if (begin == _nBins) return list;
236
237 //...Start searching...
238 unsigned loop = 0;
239 while (loop < _nBins) {
240 ++loop;
241 unsigned id = (begin + loop) % _nBins;
242 if (_bins[id]) {
243 unsigned size = 0;
244 TSegment * c = new TSegment();
245 while (_bins[id]) {
246 if (_bins[id]) ++size;
247 c->append(* _links[id]);
248 ++loop;
249 id = (begin + loop) % _nBins;
250 if (loop == _nBins) break;
251 }
252 list.append(c);
253 }
254 }
255 return list;
256}
257
260 //yuany
261 /*
262 for (unsigned i = 0; i < _nBins; i++) {
263 std::cout<<"i "<<i<<" bins[i] "<<_bins[i]<<std::endl;
264 }
265 */
266 //...Obtain raw clusters...
267 AList<TSegment> list = clusters();
268 unsigned n = list.length();
269 if (n == 0) return list;
270
271 //...Examine each cluster...
272 AList<TSegment> splitted;
273 for (unsigned i = 0; i < n; i++) {
274 TSegment * c = list[i];
275
276#ifdef TRKRECO_DEBUG_DETAIL
277 std::cout << " base segment : ";
278 c->dump("hits");
279#endif
280
281 AList<TSegment> newClusters = c->split();
282 if (newClusters.length() == 0) {
283#ifdef TRKRECO_DEBUG_DETAIL
284 std::cout << " ... Solving dual hits" << std::endl;
285#endif
286 c->solveDualHits();
287 continue;
288 }
289
290 list.append(newClusters);
291 splitted.append(c);
292#ifdef TRKRECO_DEBUG_DETAIL
293 c->dump("hits", " ");
294 std::cout << " ... splitted as" << std::endl;
295 for (unsigned j = 0; j < newClusters.length(); j++) {
296 std::cout << " " << j << " : ";
297 newClusters[j]->dump("hits");
298 }
299#endif
300 }
301 list.remove(splitted);
302 HepAListDeleteAll(splitted);
303
304 //yuany
305// n = list.length();
306// for (unsigned i = 0; i < n; i++) {
307// TSegment * c = list[i];
308// std::cout << " base segment : ";
309// c->dump("hits");
310// }
311
312 return list;
313}
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:54
#define M_PI
Definition: TConstant.h:4
const AList< TMLink > & contents(void) const
returns an AList<TMLink> of all contents.
Definition: THistogram.h:154
virtual ~THistogram()
Destructor.
Definition: THistogram.cxx:31
THistogram(unsigned nBins)
Constructor.
Definition: THistogram.cxx:19
AList< TSegment0 > clusters0(void) const
returns an AList<TSegment0> of clusters.
Definition: THistogram.cxx:162
void fillX(const AList< TMLink > &links)
fills with hits.
Definition: THistogram.cxx:76
void remove(const AList< TMLink > &links)
removes links.
Definition: THistogram.cxx:134
AList< TSegment > segments(void) const
returns an AList<TSegment0> using clusters() function.
Definition: THistogram.cxx:259
AList< TSegment0 > segments0(void) const
returns an AList<TSegment0> using clusters() function.
Definition: THistogram.cxx:192
void fillY(const AList< TMLink > &links)
fills with hits.
Definition: THistogram.cxx:94
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: THistogram.cxx:40
void fillPhi(const AList< TMLink > &links)
fills with hits.
Definition: THistogram.cxx:111
AList< TSegment > clusters(void) const
returns an AList<TSegment0> of clusters.
Definition: THistogram.cxx:229
A class to relate TMDCWireHit and TTrack objects.
Definition: TSegment0.h:41
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: TSegment0.cxx:51
int solveDualHits(void)
Definition: TSegment0.cxx:624
AList< TSegment0 > split(void) const
returns a list of sub TSegments in this cluster. If cluster type is 1, 2, or 7, no cluster is returne...
Definition: TSegment0.cxx:281
A class to relate TMDCWireHit and TTrack objects.
Definition: TSegment.h:43
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: TSegment.cxx:116
AList< TSegment > split(void) const
returns a list of sub TSegments in this cluster. If cluster type is 1, 2, or 7, no cluster is returne...
Definition: TSegment.cxx:388
int solveDualHits(void)
Definition: TSegment.cxx:736
void append(TMLink &)
appends a TMLink.
Definition: TTrackBase.cxx:362