15#define TRGCDC_SHORT_NAMES
19#include <pangomm/init.h>
20#include "trg/trg/Constants.h"
21#include "trg/cdc/TRGCDC.h"
22#include "trg/cdc/Link.h"
23#include "trg/cdc/Wire.h"
24#include "trg/cdc/WireHit.h"
25#include "trg/cdc/Segment.h"
26#include "trg/cdc/SegmentHit.h"
27#include "trg/cdc/Circle.h"
28#include "trg/cdc/TRGCDCTrack.h"
29#include "trg/cdc/FrontEnd.h"
30#include "trg/cdc/Merger.h"
31#include "trg/cdc/DisplayDrawingAreaRphi.h"
32#include "cdc/dataobjects/CDCSimHit.h"
42 TRGCDCDisplayDrawingAreaRphi::TRGCDCDisplayDrawingAreaRphi(TRGCDCDisplay& w,
46 : TRGCDCDisplayDrawingArea(w, size, outerR),
47 _scale(double(size) / outerR / 2),
54 _winx(0), _winy(0), _winw(0), _winh(0), _wind(0),
58 _blue(Gdk::Color(
"blue")),
59 _red(Gdk::Color(
"red")),
60 _green(Gdk::Color(
"green")),
61 _black(Gdk::Color(
"black")),
62 _white(Gdk::Color(
"white")),
63 _grey(Gdk::Color(
"grey")),
64 _yellow(Gdk::Color(
"yellow")),
65 _grey0(Gdk::Color(
"gray90"))
68 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
69 colormap->alloc_color(_blue);
70 colormap->alloc_color(_red);
71 colormap->alloc_color(_green);
72 colormap->alloc_color(_black);
73 colormap->alloc_color(_white);
74 colormap->alloc_color(_grey);
75 colormap->alloc_color(_yellow);
78 Glib::ustring wn =
"unknown";
79 _pl = create_pango_layout(wn);
81 add_events(Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK);
84 TRGCDCDisplayDrawingAreaRphi::~TRGCDCDisplayDrawingAreaRphi()
89 TRGCDCDisplayDrawingAreaRphi::on_realize()
91 Gtk::DrawingArea::on_realize();
92 _window = get_window();
93 _gc = Gdk::GC::create(_window);
94 _window->set_background(_white);
99 TRGCDCDisplayDrawingAreaRphi::on_expose_event(GdkEventExpose*)
101 Glib::RefPtr<Gdk::Window> window = get_window();
102 window->get_geometry(_winx, _winy, _winw, _winh, _wind);
110 TRGCDCDisplayDrawingAreaRphi::on_button_press_event(GdkEventButton* e)
114 on_expose_event((GdkEventExpose*) NULL);
119 TRGCDCDisplayDrawingAreaRphi::drawCDC(
void)
123 _gc->set_foreground(_grey);
124 _gc->set_line_attributes(1,
128 _window->draw_line(_gc,
133 _window->draw_line(_gc,
140 _gc->set_foreground(_grey);
141 _gc->set_line_attributes(1,
145 _window->draw_arc(_gc,
149 int(2 * _innerR * _scale),
150 int(2 * _innerR * _scale),
153 _window->draw_arc(_gc,
157 int(2 * _outerR * _scale),
158 int(2 * _outerR * _scale),
164 const double innerR = 118;
165 const double outerR = 880;
166 _gc->set_foreground(_grey);
167 _gc->set_line_attributes(1,
168 Gdk::LINE_ON_OFF_DASH,
171 _window->draw_arc(_gc,
175 int(2 * innerR * _scale),
176 int(2 * innerR * _scale),
179 _window->draw_arc(_gc,
183 int(2 * outerR * _scale),
184 int(2 * outerR * _scale),
191 TRGCDCDisplayDrawingAreaRphi::draw(
void)
194 for (
unsigned i = 0; i < _segments.size(); i++)
195 drawSegment(* _segments[i],
199 for (
unsigned i = 0; i < _segmentHits.size(); i++)
200 drawSegment(_segmentHits[i]->segment(),
202 _segmentHitsColor[i],
204 for (
unsigned i = 0; i < _circles.size(); i++)
205 drawCircle(* _circles[i], 1, _circlesColor[i], Gdk::LINE_SOLID);
206 for (
unsigned i = 0; i < _tracks.size(); i++)
207 drawTrack(* _tracks[i], 1, _tracksColor[i], Gdk::LINE_SOLID);
208 for (
unsigned i = 0; i < _fronts.size(); i++)
209 drawFrontEnd(* _fronts[i],
214 for (
unsigned i = 0; i < _mergers.size(); i++)
215 drawMerger(* _mergers[i],
223 TRGCDCDisplayDrawingAreaRphi::drawWires(
void)
225 for (
unsigned i = 0; i < _wires.size(); i++)
226 drawWire(* _wires[i], 1, _wiresColor[i], Gdk::LINE_SOLID);
230 TRGCDCDisplayDrawingAreaRphi::drawHits(
void)
232 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
233 const unsigned n = _hits.size();
234 for (
unsigned i = 0; i < n; i++) {
236 if (_hits[i]->wire().stereo())
239 if (_hits[i]->wire().axial())
243 const TCWire& w = _hits[i]->wire();
246 double t_driftTime = _hits[i]->drift();
248 if (t_driftTime == 0) t_driftTime = 0.3;
249 if (t_driftTime < 0) {
251 cout <<
"[DisplayDrawingAreaRphi] Error. DriftTime is minus." << endl;
253 if (t_driftTime > 2) {
255 cout <<
"[DisplayDrawingAreaRphi] Error. DriftTime is larger than 800 ns." << endl;
259 const double radius = t_driftTime;
261 colormap->alloc_color(_hitsColor[i]);
262 _gc->set_foreground(_hitsColor[i]);
263 _gc->set_line_attributes(1,
275 _window->draw_arc(_gc,
277 x((p.x() - radius) * 10),
278 y((p.y() + radius) * 10),
279 int(2 * radius * 10 * _scale),
280 int(2 * radius * 10 * _scale),
284 Glib::ustring wn = _hits[i]->wire().name().c_str();
286 _window->draw_layout(_gc, x(p.x() * 10.), y(p.y() * 10.), _pl);
288 colormap->free_color(_hitsColor[i]);
293 TRGCDCDisplayDrawingAreaRphi::drawWire(
const TCWire& w,
306 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
307 colormap->alloc_color(c);
308 _gc->set_foreground(c);
309 _gc->set_line_attributes(lineWidth,
316 vector<Gdk::Point> points;
317 const unsigned nDivisions = 5;
318 const float ri = w.layer().innerRadius();
319 const float ro = w.layer().outerRadius();
320 const float cPhi = w.backwardPosition().phi();
321 const float dPhi = M_PI / w.layer().nCells();
322 for (
unsigned j = 0; j < nDivisions + 1; j++) {
323 const float phi = cPhi - dPhi
324 + (2 * dPhi / float(nDivisions)) *
float(j);
325 const float xx = ri * cos(phi) * 10;
326 const float yy = ri * sin(phi) * 10;
331 points.push_back(Gdk::Point(x(xx), y(yy)));
333 for (
unsigned j = 0; j < nDivisions + 1; j++) {
334 const float phi = cPhi + dPhi
335 - (2 * dPhi / float(nDivisions)) *
float(j);
336 const float xx = ro * cos(phi) * 10;
337 const float yy = ro * sin(phi) * 10;
338 points.push_back(Gdk::Point(x(xx), y(yy)));
340 points.push_back(p0);
342 _gc->set_foreground(c);
343 _window->draw_lines(_gc, points);
347 TRGCDCDisplayDrawingAreaRphi::drawSegment(
const TCSegment& w,
352 const vector<const TCWire*> wires = w.wires();
353 const unsigned n = wires.size();
354 for (
unsigned i = 0; i < n; i++) {
355 drawWire(* wires[i], lineWidth, c, s);
363 TRGCDCDisplayDrawingAreaRphi::drawCircle(
const TCCircle& t,
369 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
370 colormap->alloc_color(c);
371 _gc->set_foreground(c);
372 _gc->set_line_attributes(1,
378 const TRGPoint2D& h = t.center();
379 double radius = fabs(t.radius());
380 _window->draw_arc(_gc,
382 x((h.x() - radius) * 10),
383 y((h.y() + radius) * 10),
384 int(2 * radius * 10 * _scale),
385 int(2 * radius * 10 * _scale),
388 colormap->free_color(c);
395 TRGCDCDisplayDrawingAreaRphi::drawTrack(
const TCTrack& t,
401 Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
402 colormap->alloc_color(c);
403 _gc->set_foreground(c);
404 _gc->set_line_attributes(1,
409 const TRGCDC& cdc = * TRGCDC::getTRGCDC();
412 for (
unsigned i = 0; i < cdc.nSuperLayers(); i++) {
413 const vector<TCLink*>& links = t.links(i);
414 for (
unsigned j = 0; j < links.size(); j++) {
415 const TCLink& l = * links[j];
416 const TCSegment* seg =
dynamic_cast<const TCSegment*
>(l.cell());
423 _window->draw_line(_gc,
424 x(l.positionOnTrack().x() * 10),
425 y(l.positionOnTrack().y() * 10),
426 x(l.positionOnWire().x() * 10),
427 y(l.positionOnWire().y() * 10));
432 TCHelix hIp = t.helix();
435 const double radius = fabs(hIp.radius());
437 TCLink::innerMost(t.links())->positionOnTrack() - h;
439 TCLink::outerMost(t.links())->positionOnTrack() - h;
440 double a0 = atan2(pIn.y(), pIn.x()) / M_PI * 180;
441 double a1 = atan2(pOut.y(), pOut.x()) / M_PI * 180;
443 if (d > 180) d -= 360;
444 else if (d < -180) d += 360;
445 _window->draw_arc(_gc,
447 x((h.x() - radius) * 10),
448 y((h.y() + radius) * 10),
449 int(2 * radius * 10 * _scale),
450 int(2 * radius * 10 * _scale),
454 cout <<
"a0,d=" << a0 <<
"," << d << endl;
456 colormap->free_color(c);
460 TRGCDCDisplayDrawingAreaRphi::drawFrontEnd(
const TCFrontEnd& w,
465 const unsigned n = w.size();
466 for (
unsigned i = 0; i < n; i++) {
467 drawWire(* w[i], lineWidth, c, s);
472 TRGCDCDisplayDrawingAreaRphi::drawMerger(
const TCMerger& w,
477 const unsigned n = w.size();
478 for (
unsigned i = 0; i < n; i++) {
479 drawFrontEnd(* w[i], lineWidth, c, s);
484 TRGCDCDisplayDrawingAreaRphi::resetPosition(
void)
487 _scale = double(_winw) / _outerR / 2;
489 _scale = double(_winh) / _outerR / 2;
492 on_expose_event((GdkEventExpose*) NULL);
496 TRGCDCDisplayDrawingAreaRphi::append(
const vector<const TCWire*>& l,
499 const unsigned n = l.size();
500 for (
unsigned i = 0; i < n; i++) {
501 _wires.push_back(l[i]);
502 _wiresColor.push_back(c);
504 on_expose_event((GdkEventExpose*) NULL);
508 TRGCDCDisplayDrawingAreaRphi::append(
const vector<const TCWHit*>& l,
511 const unsigned n = l.size();
512 for (
unsigned i = 0; i < n; i++) {
513 _hits.push_back(l[i]);
514 _hitsColor.push_back(c);
516 on_expose_event((GdkEventExpose*) NULL);
520 TRGCDCDisplayDrawingAreaRphi::append(
const TCSegment& s,
523 _segments.push_back(& s);
524 _segmentsColor.push_back(c);
525 on_expose_event((GdkEventExpose*) NULL);
529 TRGCDCDisplayDrawingAreaRphi::append(
const vector<const TCSegment*>& l,
532 const unsigned n = l.size();
533 for (
unsigned i = 0; i < n; i++) {
534 _segments.push_back(l[i]);
535 _segmentsColor.push_back(c);
537 on_expose_event((GdkEventExpose*) NULL);
541 TRGCDCDisplayDrawingAreaRphi::append(
542 const vector<const TCSHit*>& l,
545 const unsigned n = l.size();
546 for (
unsigned i = 0; i < n; i++) {
547 _segmentHits.push_back(l[i]);
548 _segmentHitsColor.push_back(c);
550 on_expose_event((GdkEventExpose*) NULL);
554 TRGCDCDisplayDrawingAreaRphi::append(
const TCCircle& s,
557 _circles.push_back(& s);
558 _circlesColor.push_back(c);
559 on_expose_event((GdkEventExpose*) NULL);
563 TRGCDCDisplayDrawingAreaRphi::append(
const vector<const TCCircle*>& l,
566 const unsigned n = l.size();
567 for (
unsigned i = 0; i < n; i++) {
568 _circles.push_back(l[i]);
569 _circlesColor.push_back(c);
571 on_expose_event((GdkEventExpose*) NULL);
575 TRGCDCDisplayDrawingAreaRphi::append(
const TCTrack& s,
578 _tracks.push_back(& s);
579 _tracksColor.push_back(c);
580 on_expose_event((GdkEventExpose*) NULL);
584 TRGCDCDisplayDrawingAreaRphi::append(
const vector<const TCTrack*>& l,
587 const unsigned n = l.size();
588 for (
unsigned i = 0; i < n; i++) {
589 _tracks.push_back(l[i]);
590 _tracksColor.push_back(c);
592 on_expose_event((GdkEventExpose*) NULL);
596 TRGCDCDisplayDrawingAreaRphi::append(
const TCFrontEnd& s,
599 _fronts.push_back(& s);
600 _frontColors.push_back(c);
601 on_expose_event((GdkEventExpose*) NULL);
605 TRGCDCDisplayDrawingAreaRphi::append(
const TCMerger& s,
608 _mergers.push_back(& s);
609 _mergerColors.push_back(c);
610 on_expose_event((GdkEventExpose*) NULL);
614 TRGCDCDisplayDrawingAreaRphi::clear(
void)
621 _segmentsColor.clear();
622 _segmentHits.clear();
623 _segmentHitsColor.clear();
625 _circlesColor.clear();
627 _tracksColor.clear();
629 _frontColors.clear();
631 _mergerColors.clear();
635 TRGCDCDisplayDrawingAreaRphi::oneShot(
const vector<const TCSegment*>& l,
638 for (
unsigned i = 0; i < l.size(); i++)
639 drawSegment(* l[i], 1, color, Gdk::LINE_SOLID);
Abstract base class for different kinds of events.