Belle II Software  release-05-01-25
PerfectFinder.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : PerfectFinder.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to find 2D tracks usning MC information
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
16 
17 #include <map>
18 #include "cdc/dataobjects/CDCSimHit.h"
19 #include "trg/trg/Debug.h"
20 #include "trg/trg/Utilities.h"
21 #include "trg/cdc/TRGCDC.h"
22 #include "trg/cdc/Layer.h"
23 #include "trg/cdc/Cell.h"
24 #include "trg/cdc/Wire.h"
25 #include "trg/cdc/WireHit.h"
26 #include "trg/cdc/PerfectFinder.h"
27 #include "trg/cdc/Segment.h"
28 #include "trg/cdc/SegmentHit.h"
29 #include "trg/cdc/Circle.h"
30 #include "trg/cdc/Track.h"
31 #include "trg/cdc/Link.h"
32 
33 #ifdef TRGCDC_DISPLAY
34 #include "trg/cdc/DisplayRphi.h"
35 namespace Belle2_TRGCDC {
36  extern Belle2::TRGCDCDisplayRphi* D;
37 }
38 using namespace Belle2_TRGCDC;
39 #endif
40 
41 using namespace std;
42 
43 namespace Belle2 {
49  string
50  TRGCDCPerfectFinder::version(void) const
51  {
52  return string("TRGCDCPerfectFinder 5.24");
53  }
54 
55  TRGCDCPerfectFinder::TRGCDCPerfectFinder(const string& name,
56  const TRGCDC& TRGCDC)
57  : _name(name), _cdc(TRGCDC)
58  {
59  }
60 
62  {
63  }
64 
65  int
66  TRGCDCPerfectFinder::doit(vector<TCTrack*>& trackListClone, vector<TCTrack*>& trackList)
67  {
68  int result = doitPerfectly(trackList);
69  trackListClone = trackList;
70  return result;
71  }
72 
73  int
74  TRGCDCPerfectFinder::doitPerfectly(vector<TRGCDCTrack*>& trackList)
75  {
76 
77  TRGDebug::enterStage("Perfect Finder");
78 
79  //...TS hit loop...
80  _mcList.clear();
81  map<int, vector<const TCSegment*> *> trackMap;
82  const vector<const TCSHit*> hits = _cdc.segmentHits();
83  for (unsigned i = 0; i < hits.size(); i++) {
84  const TCSHit& ts = * hits[i];
85  if (! ts.signal().active()) continue;
86  if (ts.segment().stereo()) continue;
87  //const TCWHit * wh = ts.segment().center().hit();
88  const TCWHit* wh = ts.segment().priority().hit();
89  if (! wh) continue;
90  const CDCSimHit& sh = * wh->simHit();
91  const int trackId = sh.getTrackId();
92  if (! trackMap[trackId]) {
93  trackMap[trackId] = new vector<const TCSegment*>();
94  _mcList.push_back(trackId);
95  }
96  trackMap[trackId]->push_back(& ts.segment());
97  }
98 
99  if (TRGDebug::level()) {
100  cout << TRGDebug::tab() << "#tracksInMC=" << trackMap.size() << endl;
101  map<int, vector<const TCSegment*> *>::iterator it = trackMap.begin();
102  while (it != trackMap.end()) {
103  cout << TRGDebug::tab(4) << it->first << ":";
104  const vector<const TCSegment*>& l = * it->second;
105  for (unsigned i = 0; i < l.size(); i++)
106  cout << l[i]->name() << ",";
107  cout << endl;
108  ++it;
109  }
110  }
111 
112  //...Make circles...
113  map<int, vector<const TCSegment*> *>::iterator it = trackMap.begin();
114  unsigned n = 0;
115  while (it != trackMap.end()) {
116 
117  //...Make links...
118  const vector<const TCSegment*>& l = * it->second;
119  vector<TCLink*> links;
120  for (unsigned i = 0; i < l.size(); i++) {
121  TCLink* link = new TCLink(0,
122  l[i]->hit(),
123  l[i]->hit()->cell().xyPosition());
124  links.push_back(link);
125  }
126 
127  //...Requires all axial super layer hits...
128  const unsigned nSuperLayers = TCLink::nSuperLayers(links);
129  if (nSuperLayers < 5) {
130  ++it;
131  continue;
132  }
133 
134  //...Check uniquness...
135  vector<TCLink*> layers[9];
136  vector<TCLink*> forCircle;
137  TCLink::separate(links, 9, layers);
138  for (unsigned i = 0; i < 9; i++) {
139  if (layers[i].size() < 1) continue;
140  if (layers[i].size() < 2) {
141  forCircle.push_back(layers[i][0]);
142  continue;
143  }
144  TCLink* best = 0;
145  //int timeMin = 99999;
146  float timeMin = 99999;
147  bool bestCenterHit = 0;
148  for (unsigned j = 0; j < layers[i].size(); j++) {
149  //const TRGTime & t = * (layers[i][j]->cell()->signal())[0];
150  const float tsDrift = layers[i][j]->cell()->hit()->drift();
151  const TRGCDCSegment* t_cell = (TRGCDCSegment*)(layers[i][j]->cell());
152  bool centerHit = (t_cell->priorityPosition() == 3);
153  //cout<<"PF2D ["<<layers[i][j]->cell()->superLayerId()<<"-"<<layers[i][j]->cell()->localId()<<"] Tick: "<<t.time()<<" Drift: "<<tsDrift<<endl;
154  //if (t.time() < timeMin) {
155  // timeMin = t.time();
156  if (centerHit == 1 && bestCenterHit == 0) {
157  timeMin = tsDrift;
158  best = layers[i][j];
159  bestCenterHit = 1;
160  } else if (centerHit == 0 && bestCenterHit == 1) {
161  } else {
162  if (tsDrift < timeMin) {
163  timeMin = tsDrift;
164  best = layers[i][j];
165  }
166  }
167  }
168  forCircle.push_back(best);
169  }
170 
171  if (TRGDebug::level())
172  TCLink::dump(forCircle,
173  "",
174  TRGDebug::tab() + "track_" + TRGUtil::itostring(n));
175 
176  //...Make a circle...
177  TCCircle c = TCCircle(forCircle);
178  c.fit();
179  c.name("CircleFitted_" + TRGUtil::itostring(n));
180 
181  //...Make a track...
182  TCTrack& t = * new TCTrack(c);
183  t.name("Track_" + TRGUtil::itostring(n));
184  trackList.push_back(& t);
185 
186  if (TRGDebug::level()) {
187  c.dump("detail");
188  t.dump("detail");
189  }
190 
191  //...Incriment for next loop...
192  ++it;
193  ++n;
194 
195 #ifdef TRGCDC_DISPLAY_HOUGH
196  vector<const TCCircle*> cc;
197  cc.push_back(& c);
198  vector<const TCTrack*> tt;
199  tt.push_back(& t);
200  string stg = "2D : Perfect Finder circle fit";
201  string inf = " ";
202  D->clear();
203  D->stage(stg);
204  D->information(inf);
205  D->area().append(cc, Gdk::Color("#FF0066009900"));
206 // D->area().append(tt, Gdk::Color("#990066009900"));
207  D->area().append(_cdc.hits());
208  D->area().append(_cdc.segmentHits());
209  D->show();
210  D->run();
211 #endif
212 
213  }
214 
215  if (TRGDebug::level()) {
216  cout << TRGDebug::tab() << "#tracksMade=" << trackList.size() << endl;
217  }
218 
219  TRGDebug::leaveStage("Perfect Finder");
220  return 0;
221  }
222 
224 } // namespace Belle2
Belle2::TRGCDCPerfectFinder::_cdc
const TRGCDC & _cdc
CDCTRG.
Definition: PerfectFinder.h:70
Belle2::TRGCDC::segmentHits
std::vector< const TRGCDCSegmentHit * > segmentHits(void) const
returns a list of TRGCDCSegmentHit.
Definition: TRGCDC.h:997
Belle2::TRGDebug::level
static int level(void)
returns the debug level.
Definition: Debug.cc:72
Belle2::TRGCDCPerfectFinder::_mcList
std::vector< int > _mcList
MC track ID list.
Definition: PerfectFinder.h:73
Belle2::TRGCDCPerfectFinder::name
std::string name(void) const
returns name.
Definition: PerfectFinder.h:80
Belle2::TRGCDCPerfectFinder::doit
int doit(std::vector< TRGCDCTrack * > &trackListClone, std::vector< TRGCDCTrack * > &trackList)
do track finding.
Definition: PerfectFinder.cc:66
Belle2::CDCSimHit
Example Detector.
Definition: CDCSimHit.h:33
Belle2::CDCSimHit::getTrackId
int getTrackId() const
The method to get track id.
Definition: CDCSimHit.h:192
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCSegment::priorityPosition
int priorityPosition(void) const
return priority cell position in TSHit. 0: no hit, 3: 1st priority, 1: 2nd right, 2: 2nd left
Belle2::TRGCDC
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:70
Belle2::TRGCDCSegment
A class to represent a wire in CDC.
Definition: Segment.h:40
Belle2::TRGCDCPerfectFinder::doitPerfectly
int doitPerfectly(std::vector< TRGCDCTrack * > &trackList)
do perfect finding.
Definition: PerfectFinder.cc:74
Belle2::TRGDebug::tab
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:52
Belle2::TRGCDC::hits
std::vector< const TRGCDCWireHit * > hits(void) const
returns a list of TRGCDCWireHit.
Definition: TRGCDC.cc:1703
Belle2::TRGCDCPerfectFinder::~TRGCDCPerfectFinder
virtual ~TRGCDCPerfectFinder()
Destructor.
Definition: PerfectFinder.cc:61
Belle2::TRGDebug::leaveStage
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
Definition: Debug.cc:39
Belle2::TRGDebug::enterStage
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
Definition: Debug.cc:29