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