HitTower.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file HitTower.cxx
3 /// \brief Plot hits (Raw, Calib, ...) as a tower in 3D
4 /// \author messier@indiana.edu
5 /// \version $Id: HitTower.cxx,v 1.5 2011-11-02 18:56:08 gsdavies Exp $
6 ///////////////////////////////////////////////////////////////////////
7 #include <algorithm>
8 #include <cmath>
9 #include <iostream>
10 
11 #include "TPolyLine3D.h"
12 
14 
15 #include "EventDisplay/HitTower.h"
17 #include "Geometry/Geometry.h"
18 
19 namespace evd
20 {
21  //.....................................................................
22  bool comp_hitdata(const HitData& h1, const HitData& h2)
23  {
24  if (h1.fView < h2.fView) return true;
25  if (h1.fView > h2.fView) return false;
26  if (h1.fPlane < h2.fPlane) return true;
27  if (h1.fPlane > h2.fPlane) return false;
28  if (h1.fCell < h2.fCell) return true;
29  if (h1.fCell > h2.fCell) return false;
30  return h1.fT < h2.fT;
31  }
32 
33  //......................................................................
34  HitData::HitData(int v, int p, int c, float tp, float zp, float q, float t) :
35  fView(v),
36  fPlane(p),
37  fCell(c),
38  fTpos(tp),
39  fZpos(zp),
40  fQ(q),
41  fT(t)
42  {}
43 
44  //......................................................................
45 
46  void HitTower::AddHit(int v, int p, int c, float tp, float zp,
47  float q, float t)
48  {
49  fHitData.push_back(HitData(v,p,c,tp,zp,q,t));
50  }
51 
52  //......................................................................
53 
55  {
56  unsigned int i;
57 
59 
60  // Sort hits by view, plane, cell, time
61  std::sort(fHitData.begin(), fHitData.end(), comp_hitdata);
62 
63  // _
64  // Render hits in this style: _| |_
65  // _| |_
66  //
67  TPolyLine3D* polyline = 0;
68  int ipoint = 0;
69  for (i=0; i<fHitData.size(); ++i) {
70  // Get information about the current cell in the list
71  const HitData& hit0 = fHitData[i];
72  double pos0[3] = {0,0,0};
73  double pos1[3] = {0,0,0};
74  double dpos[3] = {0,0,0};
76  geom->CellInfo(hit0.fPlane, hit0.fCell, &v, pos0, dpos);
77  if (hit0.fView == geo::kX) {
78  pos0[0] = hit0.fTpos - dpos[0];
79  pos0[1] = geom->DetHalfHeight()+fQscale*hit0.fQ;
80  pos0[2] = hit0.fZpos;
81 
82  pos1[0] = hit0.fTpos + dpos[0];
83  pos1[1] = pos0[1];
84  pos1[2] = pos0[2];
85  }
86  else if (hit0.fView == geo::kY) {
87  pos0[0] = geom->DetHalfWidth()+fQscale*hit0.fQ;
88  pos0[1] = hit0.fTpos-dpos[1];
89  pos0[2] = hit0.fZpos;
90 
91  pos1[0] = pos0[0];
92  pos1[1] = hit0.fTpos+dpos[1];
93  pos1[2] = pos0[2];
94  }
95  else abort();
96 
97  // Get information about the previous hit in the list
98  bool connectL = false;
99  if (i>0) {
100  const HitData& hitL = fHitData[i-1];
101  double tcut = 9E9;
102  bool samePlane = (hit0.fPlane==hitL.fPlane);
103  bool adjaCell = (abs(hit0.fCell-hitL.fCell)==1);
104  bool sameTime = (fabs(hit0.fT-hitL.fT)<tcut);
105  if (samePlane && adjaCell && sameTime) connectL = true;
106  }
107 
108  // Get information about the next hit in the list
109  bool connectR = false;
110  if (i+1<fHitData.size()) {
111  const HitData& hitR = fHitData[i+1];
112  double tcut = 9E9;
113  bool samePlane = (hit0.fPlane==hitR.fPlane);
114  bool adjaCell = (abs(hit0.fCell-hitR.fCell)==1);
115  bool sameTime = (fabs(hit0.fT-hitR.fT)<tcut);
116  if (samePlane && adjaCell && sameTime) connectR = true;
117  }
118 
119  // If we don't have a left connection, then we need to start a new
120  // line
121  if (connectL == false) {
122  // How long a lead in stub to draw? 2.0 would fill the whole
123  // adjacent cell
124  double stubfrac = 1.90;
125 
126  // The coordinates for the two points on the stub
127  double x0, y0, z0;
128  double x1, y1, z1;
129  if (hit0.fView == geo::kX) {
130  x1 = pos0[0];
131  y1 = geom->DetHalfHeight();
132  z1 = pos0[2];
133 
134  x0 = x1 - stubfrac*dpos[0];
135  y0 = y1;
136  z0 = z1;
137  }
138  else if (hit0.fView == geo::kY) {
139  x1 = geom->DetHalfWidth();
140  y1 = pos0[1];
141  z1 = pos0[2];
142 
143  x0 = x1;
144  y0 = y1 - stubfrac*dpos[1];
145  z0 = z1;
146  }
147  else abort();
148 
149  // Make a new line and add two points to the left of the first hit
150  ipoint = 0;
151  int c = kRed-9;
152  int w = 1;
153  int s = 1;
154  polyline = &view->AddPolyLine3D(0,c,w,s);
155  polyline->SetPoint(ipoint,x0,y0,z0); ++ipoint;
156  polyline->SetPoint(ipoint,x1,y1,z1); ++ipoint;
157  }
158 
159  // At this point in the code we better have a polyline or
160  // something has gone wrong...
161  if (polyline==0) {
162  std::cerr << __FILE__ ":" << __LINE__
163  << " Polyline=0? connectL=" << connectL << std::endl;
164  }
165 
166  // Always add two points to the line for the current hit
167  polyline->SetPoint(ipoint, pos0[0], pos0[1], pos0[2]); ++ipoint;
168  polyline->SetPoint(ipoint, pos1[0], pos1[1], pos1[2]); ++ipoint;
169 
170  // If we don't have a right connection, then we need to end this
171  // line
172  if (connectR == false) {
173  // How long a lead in stub to draw? 2 would fill the whole
174  // adjact cell
175  double stubfrac = 1.90;
176 
177  // The coordinates on the two ends of the stub
178  double x0, y0, z0;
179  double x1, y1, z1;
180  if (hit0.fView == geo::kX) {
181  x0 = pos1[0];
182  y0 = geom->DetHalfHeight();
183  z0 = pos1[2];
184 
185  x1 = x0 + stubfrac*dpos[0];
186  y1 = y0;
187  z1 = z0;
188  }
189  else if (hit0.fView == geo::kY) {
190  x0 = geom->DetHalfWidth();
191  y0 = pos1[1];
192  z0 = pos1[2];
193 
194  x1 = x0;
195  y1 = y0 + stubfrac*dpos[1];
196  z1 = z0;
197  }
198  else abort();
199  polyline->SetPoint(ipoint, x0, y0, z0); ++ipoint;
200  polyline->SetPoint(ipoint, x1, y1, z1); ++ipoint;
201  }
202  } // loop on i in fHitData
203  }
204 } // end namespace evd
205 ////////////////////////////////////////////////////////////////////////
float fQ
Charge (arb. units)
Definition: HitTower.h:25
enum BeamMode kRed
float fTpos
Transverse position (X or Y, cm)
Definition: HitTower.h:23
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
float fT
Time (arb. units)
Definition: HitTower.h:26
Float_t y1[n_points_granero]
Definition: compare.C:5
X or Y views.
Definition: PlaneGeo.h:30
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
bool comp_hitdata(const HitData &h1, const HitData &h2)
Definition: HitTower.cxx:22
Float_t x1[n_points_granero]
Definition: compare.C:5
const char * p
Definition: xmltok.h:285
Vertical planes which measure X.
Definition: PlaneGeo.h:28
OStream cerr
Definition: OStream.cxx:7
void abs(TH1 *hist)
void Draw(evdb::View3D *view)
Definition: HitTower.cxx:54
Horizontal planes which measure Y.
Definition: PlaneGeo.h:29
void CellInfo(unsigned int ip, unsigned int ic, View_t *view=0, double *pos=0, double *dpos=0) const
float fZpos
Longitudinal postiion (Z, cm)
Definition: HitTower.h:24
TPolyLine3D & AddPolyLine3D(int n, int c, int w, int s)
Definition: View3D.cxx:105
const XML_Char * s
Definition: expat.h:262
nova event display
int fCell
Which cell?
Definition: HitTower.h:22
double DetHalfHeight() const
int fPlane
Which plane?
Definition: HitTower.h:21
TH1F * h2
Definition: plot.C:45
TH1F * h1
double DetHalfWidth() const
Plot hits (Raw, Calib, ...) as a tower in 3D.
void geom(int which=0)
Definition: geom.C:163
int fView
Which view is the hit in? (X or Y)
Definition: HitTower.h:20
A collection of 3D drawable objects.
HitData(int v, int p, int c, float tp, float zp, float q, float t)
Definition: HitTower.cxx:34
void AddHit(int v, int p, int c, float tp, float zp, float q, float t)
Definition: HitTower.cxx:46
Some glue so that hits of various types call all use the HitTower class.
Definition: HitTower.h:15
Float_t w
Definition: plot.C:20
Encapsulate the geometry of one entire detector (near, far, ndos)