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