BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TMDCTsf.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TMDCTsf.cxx,v 1.23 2012/05/28 05:16:29 maoh Exp $
3//-----------------------------------------------------------------------------
4// Filename : TMDCTsf.h
5// Section : Tracking MDC
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A class to represent a Track Finder Segment(TSF).
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13// #ifdef TRKRECO_DEBUG_DETAIL
14// #define TRKRECO_DEBUG
15// #endif
16#include <iostream>
17// #define HEP_SHORT_NAMES
18#include "CLHEP/Vector/ThreeVector.h"
19#include "TrkReco/TMDC.h"
20#include "TrkReco/TMDCLayer.h"
21#include "TrkReco/TMDCTsf.h"
22#include "TrkReco/TMDCWire.h"
23#include "TrkReco/TMDCWireHit.h"
24
25#include "CLHEP/Matrix/Vector.h"
26#include <math.h>
27
28using CLHEP::HepVector;
29
30extern TMDC* GMDC;
31
32TMDC* TMDCTsf::_cdc = 0;
33/*
34TMDCTsf::TMDCTsf(const TMDCWire * const w) {
35 //...Notice...
36 // This function creates TSF of 1,2,3,4(4 wire layers) or 1,2,3(3 wire
37 // layers) configuration of wires in each layer. The argument w must be
38 // in the first wire layer in super layer, or must be in the second.
39
40 AList<int> offset;
41 offset.append(new int(0));
42 offset.append(new int(-1));
43 offset.append(new int(-1));
44 offset.append(new int(-2));
45
46 AList<int> width;
47 width.append(new int(1));
48 width.append(new int(2));
49 width.append(new int(3));
50 width.append(new int(4));
51
52 create(offset, width, w);
53}
54
55TMDCTsf::TMDCTsf(const AList<int> & offset,
56 const AList<int> & width,
57 const TMDCWire * const w) {
58 create(offset, width, w);
59
60}*/
61
62TMDCTsf::TMDCTsf( unsigned sl ) : _sl( sl ), _angle( 0.8 ) {}
63
65
66void TMDCTsf::dump( const std::string& msg, const std::string& pre ) const {
67 std::cout << pre;
68 std::cout << "tsf : " << _wires.length() << " : ";
69 for ( unsigned i = 0; i < _wires.length(); i++ )
70 {
71 TMDCWire* w = _wires[i];
72 std::cout << w->layerId() << "-" << w->localId() << ", ";
73 }
74 std::cout << std::endl;
75}
76
77bool TMDCTsf::create( const AList<int>& offset, const AList<int>& width,
78 const TMDCWire* const w ) {
79
80 //...Check wire position...
81 unsigned localId = w->localLayerId();
82 unsigned superId = w->superLayerId();
83 unsigned availableLayer = GMDC->nLocalLayer( superId ) - localId;
84 if ( availableLayer < TMDCTSF_MIN_LAYERS )
85 {
86 std::cout << "TMDCTsf::create !!! can not create TSF for wire ";
87 std::cout << superId << "-" << localId << " because of ";
88 std::cout << "lack of layer(s)." << std::endl;
89 return false;
90 }
91 availableLayer = ( availableLayer > offset.length() ) ? offset.length() : availableLayer;
92
93 //...Check offset...
94 bool offsetLayer = false;
95 if ( w->layer()->offset() != 0. ) offsetLayer = true;
96
97 //...Loop over available layers...
98 for ( unsigned l = 0; l < availableLayer; l++ )
99 {
100 unsigned absLayerId = w->layerId() + l;
101 int wireId[2];
102 wireId[0] = w->localId() + ( *offset[l] );
103 wireId[1] = w->localId() + ( *offset[l] );
104 if ( offsetLayer ) ++wireId[1];
105
106 //...Loop over wires...
107 for ( unsigned j = 0; j < *( width[l] ); j++ )
108 { _wires.append( (TMDCWire*)GMDC->wire( absLayerId, wireId[l % 2] + j ) ); }
109 }
110
111 return true;
112}
113
115 //...For debug...
116 // this->dump();
117
118 // TMDCWire * innerWire = _wires[0];
119 // TMDCWireHit * innerHit = innerWire->hit();
120
121 // unsigned outerMostLayer = _wires.last()->layerId();
122 // unsigned i = _wires.length();
123 // while (_wires[--i]->layerId() == outerMostLayer) {
124 // TMDCWireHit * outerHit = _wires[i]->hit();
125 // if (! outerHit) continue;
126
127 // //...Find four lines by two hit points...
128 // // AList<TMDCLine> lines = innerHit->lines(outerHit);
129 // // AList<TMDCLine> lines; // = innerHit->lines(outerHit);
130
131 // //...Line loop...
132 // for (unsigned ii = 0; ii < 4; ii++) {
133 // TMDCLine * l = lines[ii];
134
135 // //...For debug...
136 // // l->dump();
137
138 // //...Find hits on this line...
139 // unsigned j = i;
140 // while (TMDCWire * w = _wires[--j]) {
141
142 // //...Check condition...
143 // if (w == innerWire) break;
144 // if (w->layerId() == outerMostLayer) continue;
145 // TMDCWireHit * hit = w->hit();
146 // if (! hit) continue;
147
148 // //...Append this hit...
149 // l->appendHit(hit);
150
151 // //...Obtain distance of closest approach...
152 // double distance = l->distance(* l->closest().last());
153
154 // //...Cal. tolerable distance...
155 // unsigned leftRight = * (l->leftRight().last());
156 // double tolerable = 5. * hit->dDistance(leftRight);
157
158 // //...Is this OK?...
159 // if (distance > tolerable) {
160 // l->removeLastHit();
161 // continue;
162 // }
163
164 // //...For debug...
165 // // hit->dump("", " ");
166 // // std::cout << "distance = " << distance << std::endl;
167 // }
168
169 // //...Check # of hits on this line
170 // if (l->hits().length() > 2) {
171 // unsigned i = 0;
172 // while (TMDCWireHit * h = (l->hits())[i]) {
173 // unsigned leftRight = * (l->leftRight())[i];
174 // unsigned newState = h->state() | (1 << leftRight);
175 // h->state(newState);
176 // ++i;
177
178 // //...For debug...
179 // // h->dump("", " ");
180 // }
181 // }
182
183 // //...Delete line here...
184 // delete l;
185 // }
186 // }
187}
188
189//----------------the following is added by liuqg--------------------//
191 _all.removeAll();
192 _all.append( links );
193
194 AList<TMLink> seeds1;
195 AList<TMLink> seeds2;
196 for ( int i = 0; i < _all.length(); ++i )
197 {
198 if ( _all[i]->wire()->localLayerId() == 0 ) seeds1.append( _all[i] );
199 else if ( _all[i]->wire()->localLayerId() == 1 ) seeds2.append( _all[i] );
200 else continue;
201 }
202 AList<TSegment> list = createTsf( 0 ); // get 1234 tsf.
203 unsigned n = list.length();
204 AList<TSegment> splitted;
205 AList<TMLink> seedNeighbors;
206 for ( unsigned i = 0; i < n; ++i )
207 {
208 seedNeighbors.removeAll();
209 TSegment* c = list[i];
210
211 // append seed's neighbors
212 for ( int j = 0; j < c->links().length(); ++j )
213 {
214 if ( c->links()[j]->wire()->localLayerId() > 0 ) continue;
215 unsigned seedId = c->links()[j]->wire()->localId();
216 for ( int k = 0; k < seeds1.length(); ++k )
217 {
218 if ( seeds1[k]->wire()->localIdForPlus() + 1 == seedId ||
219 seeds1[k]->wire()->localIdForMinus() - 1 == seedId )
220 seedNeighbors.append( seeds1[k] );
221 }
222 break;
223 }
224
225 AList<TSegment> newClusters = c->splitTsf( seedNeighbors );
226 // cout<<"newClusters.length = "<<newClusters.length()<<endl;
227 splitted.append( c ); // remove the segment created by TMDCTsf here!!!
228 if ( newClusters.length() == 0 ) continue;
229 list.append( newClusters );
230 }
231 list.remove( splitted );
232 HepAListDeleteAll( splitted );
233 // cout<<"sl = "<<_sl<<" list1234 = "<<list.length()<<endl;
234
235 AList<TSegment> list2 = createTsf( 1 ); // get 234 tsf.
236 n = list2.length();
237 AList<TSegment> splitted2;
238
239 for ( unsigned i = 0; i < n; ++i )
240 {
241 seedNeighbors.removeAll();
242 TSegment* c = list2[i];
243
244 // append seed's neighbors
245 for ( int j = 0; j < c->links().length(); ++j )
246 {
247 if ( c->links()[j]->wire()->localLayerId() != 1 ) continue;
248 unsigned seedId = c->links()[j]->wire()->localId();
249 for ( int k = 0; k < seeds2.length(); ++k )
250 {
251 if ( seeds2[k]->wire()->localIdForPlus() + 1 == seedId ||
252 seeds2[k]->wire()->localIdForMinus() - 1 == seedId )
253 seedNeighbors.append( seeds2[k] );
254 }
255 break;
256 }
257
258 AList<TSegment> newClusters2 = c->splitTsf( seedNeighbors );
259 // cout<<"newClusters2.length = "<<newClusters2.length()<<endl;
260 splitted2.append( c );
261 if ( newClusters2.length() == 0 ) continue;
262 list2.append( newClusters2 );
263 }
264 list2.remove( splitted2 );
265 HepAListDeleteAll( splitted2 );
266 // cout<<"sl = "<<_sl<<" list234 = "<<list2.length()<<endl;
267
268 list.append( list2 );
269
270 // check segment, remove the multi segs.
271 AList<TSegment> badList;
272 for ( int i = 0; i < list.length(); ++i )
273 {
274 for ( int j = i + 1; j < list.length(); ++j )
275 {
276 AList<TMLink> links = list[j]->links();
277 AList<TMLink> multiLinks;
278 for ( int k = 0; k < links.length(); ++k )
279 {
280 TMLink& l = *links[k];
281 if ( list[i]->links().hasMember( l ) ) multiLinks.append( l );
282 }
283 if ( multiLinks.length() < 2 ) continue;
284 unsigned minLength = links.length();
285 if ( links.length() > list[i]->links().length() ) minLength = list[i]->links().length();
286 if ( minLength - multiLinks.length() > 1 ) continue;
287 int nHits[4] = { 0 }; // in each layer.
288 int multiLayers = 0;
289 for ( int k = 0; k < multiLinks.length(); ++k )
290 ++nHits[multiLinks[k]->hit()->wire()->localLayerId()];
291 for ( int k = 0; k < 4; ++k )
292 if ( nHits[k] > 0 ) ++multiLayers;
293 if ( multiLayers >= 2 && ( links.length() > list[i]->links().length() ) )
294 badList.append( list[i] );
295 else if ( multiLayers >= 2 ) badList.append( list[j] );
296 else continue;
297 }
298 }
299 list.remove( badList );
300
301 // reset links in badList.
302 for ( int i = 0; i < badList.length(); ++i )
303 {
304 AList<TMLink> bads = badList[i]->links();
305 for ( int j = 0; j < bads.length(); ++j )
306 {
307 unsigned n = bads[j]->tsfTag();
308 if ( n == 0 ) continue;
309 else
310 {
311 --n;
312 bads[j]->tsfTag( n );
313 }
314 }
315 }
316 HepAListDeleteAll( badList );
317
318 return list;
319}
320
321AList<TSegment> TMDCTsf::createTsf( unsigned seedlayer ) const {
322 if ( _cdc == 0 ) _cdc = TMDC::getTMDC();
323
324 AList<TMLink> seeds;
325 AList<TMLink> exhits;
326 AList<TSegment> list;
327
328 unsigned n = _all.length();
329 if ( n < 3 ) return list;
330 if ( seedlayer == 1 && _sl == 10 ) return list;
331
332 for ( unsigned i = 0; i < n; ++i )
333 {
334 TMLink* ll = _all[i];
335 // if (ll->wire()->localLayerId() == seedlayer && ll->tsfTag() == 0) seeds.append(ll);
336 if ( ll->wire()->localLayerId() == seedlayer ) seeds.append( ll );
337 if ( ll->wire()->localLayerId() > seedlayer ) exhits.append( ll );
338 } // get seeds and exhits.
339
340 for ( unsigned i = 0; i < seeds.length(); ++i )
341 {
342 AList<TMLink> forSegment;
343 TMLink* seed = seeds[i];
344 unsigned lId = seed->wire()->layerId();
345 int local = (int)seed->wire()->localId();
346 // cout<<"lId: "<<lId<<" loId: "<<local<<endl;
347 float phi0 = _cdc->layer( lId )->offset();
348 int nWir = (int)_cdc->layer( lId )->nWires();
349 float phi = phi0 + local * 2 * M_PI / nWir; // phi angle of seed.
350 // double angle = alpha(sl, seed);
351 forSegment.append( seed );
352
353 // for check
354 int hitsOnLayer[3] = { 0, 0, 0 };
355
356 for ( unsigned m = 0; m < exhits.length(); ++m )
357 {
358 TMLink* l = exhits[m];
359 unsigned lLayer = l->wire()->localLayerId();
360 unsigned tmpId = l->wire()->layerId();
361 int tmpLocal = l->wire()->localId();
362 float phi0tmp = _cdc->layer( tmpId )->offset();
363 int nWirtmp = (int)_cdc->layer( tmpId )->nWires();
364 int localOffset =
365 (int)( ( phi - phi0tmp ) / ( 2 * M_PI / nWirtmp ) ); // get the corresponding localId
366 // of exhits.
367
368 int diff = abs( tmpLocal - localOffset );
369
370 if ( diff > nWirtmp / 2 ) diff = nWirtmp - diff;
371 // cout<<"lId: "<<tmpId<<" loId: "<<tmpLocal<<" diff wire: "<<diff
372 //<<" cal value = "<<fabs(acos((l->position() -
373 // seed->position()).unit().dot(-seed->position().unit())))<<endl;
374 if ( diff > lLayer + 2 ) continue; // check in natural phase..
375
376 // double DRIFT = l->cDrift();
377 // const HepPoint3D dirZ(0.0, 0.0, 1.0);
378 // HepPoint3D pos1 = l->positionD() - DRIFT *
379 // dirZ.cross(l->positionD().unit()); HepPoint3D pos2 = l->positionD() + DRIFT *
380 // dirZ.cross(l->positionD().unit()); if (fabs(acos((pos1 -
381 // seed->position()).unit().dot(-seed->position().unit()))) < _angle
382 // || fabs(acos((pos2 -
383 // seed->position()).unit().dot(-seed->position().unit()))) < _angle) {
384 if ( fabs( acos( ( l->position() - seed->position() )
385 .unit()
386 .dot( -seed->position().unit() ) ) ) < _angle )
387 {
388 forSegment.append( l );
389 ++hitsOnLayer[lLayer - 1 - seedlayer];
390 }
391 }
392
393 // check
394 int fireLayers = 0;
395 for ( unsigned j = 0; j < 3; ++j )
396 {
397 if ( hitsOnLayer[j] > 0 ) ++fireLayers;
398 }
399 if ( fireLayers < 2 ) { continue; }
400 list.append( new TSegment( forSegment ) );
401 }
402 return list;
403}
404
405double TMDCTsf::alpha( unsigned sl, TMLink* seed ) const {
406 double radius[11] = { 11.525, 16.160, 24.555, 31.060, 37.455, 44.760,
407 51.370, 57.855, 64.165, 71.570, 76.345 };
408 HepPoint3D pa, pb, pc;
409 double rcell;
410 if ( sl < 2 ) rcell = 0.6;
411 else rcell = 0.8;
412 pa.set( 0, 2 / radius[sl], 0 );
413 pb.set( -2 * rcell / ( rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
414 2 * ( radius[sl] + rcell ) /
415 ( rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
416 0 );
417 pc.set( 2 * rcell / ( rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
418 2 * ( radius[sl] + rcell ) /
419 ( rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
420 0 );
421 cout << "sl = " << sl
422 << "alpha2 = " << acos( ( pb - pa ).unit().dot( ( pc - pa ).unit() ) ) / 2 << endl;
423 HepPoint3D pa2, pb2, pc2;
424 pa2.set( 0, 2 / radius[sl], 0 );
425 pb2.set( -6 * rcell /
426 ( 9 * rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
427 2 * ( radius[sl] + rcell ) /
428 ( 9 * rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
429 0 );
430 pc2.set( 6 * rcell / ( 9 * rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
431 2 * ( radius[sl] + rcell ) /
432 ( 9 * rcell * rcell + ( radius[sl] + rcell ) * ( radius[sl] + rcell ) ),
433 0 );
434 cout << "alpha22 = " << acos( ( pb2 - pa2 ).unit().dot( ( pc2 - pa2 ).unit() ) ) / 2 << endl;
435 return 1.0;
436}
HepGeom::Point3D< double > HepPoint3D
const Int_t n
double w
*******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 saves r n generator level $ !Flag for chat level in !Latex Output unit
Definition FoamA.h:90
#define M_PI
Definition TConstant.h:4
TMDC * GMDC
Definition TMDC.cxx:58
TMDCTsf(unsigned sl)
Constructor of fixed shape.
Definition TMDCTsf.cxx:62
AList< TSegment > createTsf(unsigned) const
Definition TMDCTsf.cxx:321
AList< TSegment > segments(const AList< TMLink > &links)
finds segments.
Definition TMDCTsf.cxx:190
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition TMDCTsf.cxx:66
void solveLeftRight(void)
solves left-right ambiguityies.
Definition TMDCTsf.cxx:114
virtual ~TMDCTsf()
Destructor.
Definition TMDCTsf.cxx:64
unsigned localLayerId(void) const
returns local layer id in a super layer.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const TMDCWire *const wire(unsigned wireId) const
returns a pointer to a wire. 0 will be returned if 'wireId' is invalid.
static TMDC * getTMDC(void)
Definition TMDC.cxx:84
A class to relate TMDCWireHit and TTrack objects.
AList< TSegment > splitTsf(AList< TMLink > &)
const AList< TMLink > & links(unsigned mask=0) const