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