Belle II Software  release-05-01-25
Wire.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : Wire.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to represent a wire in CDC.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
16 
17 #include "trg/trg/Clock.h"
18 #include "trg/trg/Utilities.h"
19 #include "trg/cdc/TRGCDC.h"
20 #include "trg/cdc/Wire.h"
21 #include "trg/cdc/WireHit.h"
22 #include "trg/cdc/WireHitMC.h"
23 #include "trg/cdc/Segment.h"
24 
25 #define P3D HepGeom::Point3D<double>
26 
27 using namespace std;
28 
29 namespace Belle2 {
35  TRGCDCWire::TRGCDCWire(unsigned id,
36  unsigned localId,
37  const TCLayer& l,
38  const P3D& fp,
39  const P3D& bp,
40  const TRGClock& clock)
41  : TCCell(id, localId, l, fp, bp),
42  _mcHits(),
43  _signal(clock)
44  {
45  _signal.name(name());
46  }
47 
49  {
50  }
51 
52  void
53  TRGCDCWire::dump(const string& msg, const string& pre) const
54  {
55  cout << pre;
56  cout << "w " << id();
57  cout << ",local " << localId();
58  cout << ",layer " << layerId();
59  cout << ",super layer " << superLayerId();
60  cout << ",local layer " << localLayerId();
61  cout << endl;
62  if (msg.find("neighbor") != string::npos) {
63  for (unsigned i = 0; i < 7; i++)
64  if (neighbor(i))
65  neighbor(i)->dump("", pre + TRGUtil::itostring(i) + " ");
66  }
67  if (msg.find("trigger") != string::npos ||
68  msg.find("detail") != string::npos) {
69  signal().dump(msg, pre + " ");
70  }
71  }
72 
73  const TRGCDCWire*
74  TRGCDCWire::neighbor(unsigned i) const
75  {
76  static bool first = false;
77  if (first)
78  cout << "TRGCDCWire::neighbor !!! "
79  << "this function is not tested yet"
80  << endl;
81 
82  const TRGCDC& cdc = * TRGCDC::getTRGCDC();
83  const unsigned layerId = layer().id();
84  const unsigned superLayerId = layer().superLayerId();
85  const unsigned localLayerId = layer().localLayerId();
86  const unsigned nLayers = cdc.superLayer(superLayerId)->size();
87  const int local = int(localId());
88 
89  if (i == WireInnerLeft || i == WireInnerRight) {
90  if (localLayerId == 0)
91  return 0;
92  if (layer().offset() != 0) {
93  if (i == WireInnerLeft)
94  return cdc.wire(layerId - 1, local);
95  else
96  return cdc.wire(layerId - 1, local + 1);
97  } else {
98  if (i == WireInnerLeft)
99  return cdc.wire(layerId - 1, local - 1);
100  else
101  return cdc.wire(layerId - 1, local);
102  }
103  } else if (i == WireLeft || i == WireRight) {
104  if (i == WireLeft)
105  return cdc.wire(layerId, local - 1);
106  else
107  return cdc.wire(layerId, local + 1);
108  } else if (i == WireOuterLeft || i == WireOuterRight) {
109  if (localLayerId == (nLayers - 1))
110  return 0;
111  if (layer().offset() != 0) {
112  if (i == WireOuterLeft)
113  return cdc.wire(layerId + 1, local);
114  else
115  return cdc.wire(layerId + 1, local + 1);
116  } else {
117  if (i == WireOuterLeft)
118  return cdc.wire(layerId + 1, local - 1);
119  else
120  return cdc.wire(layerId + 1, local);
121  }
122  }
123  return 0;
124  }
125 
126 // int
127 // TRGCDCWire::localIdForPlus(void) const {
128 
129 // const unsigned li = layerId();
130 
131 // //
132 // // used in curl finder
133 // //
134 // // new version by NK
135 // //
136 // const TCLayer &l = *layer();
137 // const int nw = l.nWires();
138 // if(_localId+1==nw) return -1;
139 // else return _localId;
140 // #if 0
141 // if (ms_smallcell) {
142 // if ((li == 1) || (li == 2)) {
143 // if (_localId == 127) return -1;
144 // else return _localId;
145 // }
146 // if(_localId == 63) return -1;
147 // else return _localId;
148 // }
149 // else {
150 // if (li <= 5) {
151 // if(_localId == 63)
152 // return -1;
153 // else return _localId;
154 // }
155 // }
156 
157 // if(li >= 6 && li <= 8){
158 // if(_localId == 79)
159 // return -1;
160 // else return _localId;
161 // }
162 
163 // if(li >= 9 && li <= 14){
164 // if(_localId == 95)
165 // return -1;
166 // else return _localId;
167 // }
168 
169 // if(li >= 15 && li <= 17){
170 // if(_localId == 127)
171 // return -1;
172 // else return _localId;
173 // }
174 
175 // if(li >= 18 && li <= 22){
176 // if(_localId == 143)
177 // return -1;
178 // else return _localId;
179 // }
180 
181 // if(li >= 23 && li <= 26){
182 // if(_localId == 159)
183 // return -1;
184 // else return _localId;
185 // }
186 
187 // if(li >= 27 && li <= 31){
188 // if(_localId == 191)
189 // return -1;
190 // else return _localId;
191 // }
192 
193 // if(li >= 32 && li <= 35){
194 // if(_localId == 207)
195 // return -1;
196 // else return _localId;
197 // }
198 
199 // if(li >= 36 && li <= 40){
200 // if(_localId == 239)
201 // return -1;
202 // else return _localId;
203 // }
204 
205 // if(li >= 41 && li <= 44){
206 // if(_localId == 255)
207 // return -1;
208 // else return _localId;
209 // }
210 
211 // if(li >= 45){
212 // if(_localId == 287)
213 // return -1;
214 // else return _localId;
215 // }
216 // #endif
217 
218 // return -1;
219 // }
220 
221 // int
222 // TRGCDCWire::localIdForMinus(void) const {
223 
224 // const unsigned li = layerId();
225 
226 // //
227 // // used in curl finder
228 // //
229 // // new version ny NK
230 // //
231 // const TCLayer &l = *layer();
232 // const int nw = l.nWires();
233 // if(0==_localId) return nw;
234 // else return _localId;
235 // #if 0
236 // if (ms_smallcell) {
237 // if ((li == 1) || (li == 2)) {
238 // if (_localId == 0) return 128;
239 // else return _localId;
240 // }
241 // if(_localId == 63) return -1;
242 // else return _localId;
243 // }
244 // else {
245 // if (li <= 5){
246 // if(_localId == 0)
247 // return 64;
248 // else return _localId;
249 // }
250 // }
251 
252 // if(li >= 6 && li <= 8){
253 // if(_localId == 0)
254 // return 80;
255 // else return _localId;
256 // }
257 
258 // if(li >= 9 && li <= 14){
259 // if(_localId == 0)
260 // return 96;
261 // else return _localId;
262 // }
263 
264 // if(li >= 15 && li <= 17){
265 // if(_localId == 0)
266 // return 128;
267 // else return _localId;
268 // }
269 
270 // if(li >= 18 && li <= 22){
271 // if(_localId == 0)
272 // return 144;
273 // else return _localId;
274 // }
275 
276 // if(li >= 23 && li <= 26){
277 // if(_localId == 0)
278 // return 160;
279 // else return _localId;
280 // }
281 
282 // if(li >= 27 && li <= 31){
283 // if(_localId == 0)
284 // return 192;
285 // else return _localId;
286 // }
287 
288 // if(li >= 32 && li <= 35){
289 // if(_localId == 0)
290 // return 208;
291 // else return _localId;
292 // }
293 
294 // if(li >= 36 && li <= 40){
295 // if(_localId == 0)
296 // return 240;
297 // else return _localId;
298 // }
299 
300 // if(li >= 41 && li <= 44){
301 // if(_localId == 0)
302 // return 256;
303 // else return _localId;
304 // }
305 
306 // if(li >= 45){
307 // if(_localId == 0)
308 // return 288;
309 // else return _localId;
310 // }
311 // #endif
312 
313 // return -1;
314 // }
315 
316 // void
317 // TRGCDCWire::wirePosition(float z,
318 // HepGeom::Point3D<double> & xy,
319 // HepGeom::Point3D<double> & back,
320 // Vector3D & dir) const {
321 // cout << "TRGCDCWire::wirePosition !!! this function is not test yet"
322 // << endl;
323 
324 // back = _backwardPosition;
325 
326 // //...Check z position...
327 // if (! (z > _backwardPosition.z() && z < _forwardPosition.z())) {
328 // xy = _xyPosition;
329 // dir = _direction;
330 // }
331 
332 // //...Setup...
333 // int wireID = id();
334 // float wirePosition[3] = {0., 0., 0.};
335 // float dydz = 0;
336 // float ybSag = 0;
337 // float yfSag = 0;
338 
339 // //...Get corrections...
340 // if(ms_superb) {
341 // double dz = _forwardPosition.z() - _backwardPosition.z();
342 // double dzb = (z - _backwardPosition.z()) / dz;
343 // double dzf = (_forwardPosition.z() - z) / dz;
344 
345 // xy = dzb * _forwardPosition + dzf * _backwardPosition;
346 // cout << "f=" << _forwardPosition << endl;
347 // cout << "b=" << _backwardPosition << endl;
348 // cout << "p" << xy << endl;
349 // cout << "z=" << z << " dz=" << dz << " dzb=" << dzb << " dzf=" << dzf << endl;
350 // dir = _direction;
351 // return;
352 // }
353 // calcdc_sag3_(& wireID, & z, wirePosition, & dydz, & ybSag, & yfSag);
354 
355 // //...Wire position...
356 // xy.setX((double) wirePosition[0]);
357 // xy.setY((double) wirePosition[1]);
358 // xy.setZ((double) wirePosition[2]);
359 // back.setY((double) ybSag);
360 // Vector3D v_aux(_forwardPosition.x() - _backwardPosition.x(),
361 // yfSag - ybSag,
362 // _forwardPosition.z() - _backwardPosition.z());
363 // dir = v_aux.unit();
364 
365 // return;
366 // }
367 
368  void
370  {
371  TCCell::clear();
372 
373  for (unsigned i = 0; i < _mcHits.size(); i++)
374  delete _mcHits[i];
375  _mcHits.clear();
376 
377  _signal.clear();
378  _signal.name(name());
379  }
380 
381  string
382  TRGCDCWire::name(void) const
383  {
384  if (axial())
385  return string("w") +
386  TRGUtil::itostring(layerId()) +
387  string("-") +
388  TRGUtil::itostring(localId());
389  return string("w") +
390  TRGUtil::itostring(layerId()) +
391  string("=") +
392  TRGUtil::itostring(localId());
393  }
394 
396 } // namespace Belle2
397 
Belle2::TRGCDCCell::localId
unsigned localId(void) const
returns local id in a layer.
Definition: Cell.h:205
Belle2::TRGCDCWire::clear
void clear(void) override
clears information.
Definition: Wire.cc:369
WireInnerRight
#define WireInnerRight
type of the wire
Definition: Wire.h:39
Belle2::TRGCDCCell::layer
const TRGCDCLayer & layer(void) const
returns a pointer to a layer.
Definition: Cell.h:233
Belle2::TRGCDCWire
A class to represent a wire in CDC.
Definition: Wire.h:57
Belle2::TRGCDCWire::_signal
TRGSignal _signal
Trigger output.
Definition: Wire.h:127
Belle2::TRGCDCWire::name
std::string name(void) const override
returns name.
Definition: Wire.cc:382
WireOuterLeft
#define WireOuterLeft
type of the wire
Definition: Wire.h:45
Belle2::TRGCDCCell::localLayerId
unsigned localLayerId(void) const
returns local layer id in a super layer.
Definition: Cell.h:226
WireOuterRight
#define WireOuterRight
type of the wire
Definition: Wire.h:47
Belle2::TRGSignal::name
const std::string & name(void) const
returns name.
Definition: Signal.h:190
WireLeft
#define WireLeft
type of the wire
Definition: Wire.h:41
Belle2::TRGSignal::dump
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Definition: Signal.cc:144
Belle2::TRGCDCWire::dump
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const override
dumps debug information.
Definition: Wire.cc:53
Belle2::TRGCDCCell::axial
bool axial(void) const
returns true if this wire is in an axial layer.
Definition: Cell.h:254
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
WireInnerLeft
#define WireInnerLeft
type of the wire
Definition: Wire.h:37
Belle2::TRGCDCWire::~TRGCDCWire
virtual ~TRGCDCWire()
Destructor.
Definition: Wire.cc:48
Belle2::TRGCDC::getTRGCDC
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
Belle2::TRGCDCCell::superLayerId
unsigned superLayerId(void) const
returns super layer id.
Definition: Cell.h:219
Belle2::TRGCDCCell::id
unsigned id(void) const
returns id.
Definition: Cell.h:198
Belle2::TRGCDC
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:70
Belle2::TRGCDCWire::_mcHits
std::vector< const TRGCDCWireHitMC * > _mcHits
MC wire hit.
Definition: Wire.h:124
Belle2::TRGSignal::clear
void clear(void)
clears contents.
Definition: Signal.h:267
Belle2::TRGCDCWire::neighbor
const TRGCDCWire * neighbor(unsigned) const
returns a pointer to a neighbor wire. This function is expensive.
Definition: Wire.cc:74
Belle2::TRGCDCCell::layerId
unsigned layerId(void) const
returns layer id.
Definition: Cell.h:212
WireRight
#define WireRight
type of the wire
Definition: Wire.h:43
Belle2::TRGCDCWire::signal
const TRGSignal & signal(void) const override
returns an input to the trigger. This is sync'ed to 1GHz clock.
Definition: Wire.h:225
Belle2::TRGClock
A class to represent a digitized signal. Unit is nano second.
Definition: Clock.h:43