Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBCALPoint.cc
Go to the documentation of this file.
1 /*
2  * DBCALPoint.cc
3  *
4  * Created by Matthew Shepherd on 3/13/11.
5  *
6  */
7 
8 #include <iostream>
9 
10 using namespace std;
11 
12 #include "BCAL/DBCALHit.h"
13 #include "BCAL/DBCALPoint.h"
14 #include "BCAL/DBCALGeometry.h"
15 
16 #include "units.h"
17 
18 DBCALPoint::DBCALPoint(const DBCALUnifiedHit& hit1, const DBCALUnifiedHit& hit2, double z_target_center,
19  double attenuation_length, double c_effective, double track_p0, double track_p1,
20  double track_p2, const DBCALGeometry *locGeom) : m_BCALGeom(locGeom)
21 {
22 
23  // this is a problem -- both hits are on the same end...
24  // this constructor is not equipped for this!
25 
26  assert( hit1.end != hit2.end );
27 
28  // check to be sure both hits are in the same cell
29 
30  int cellId = m_BCALGeom->cellId( hit1.module, hit1.layer, hit1.sector );
31  assert( cellId ==
32  m_BCALGeom->cellId( hit2.module, hit2.layer, hit2.sector ) );
33 
34  // save typing
35 
36  float fibLen = m_BCALGeom->GetBCAL_length();
37 
38  // figure out which hit is upstream and which is downstream
39  // (downstream means farthest from the target)
40 
41  const DBCALUnifiedHit& upHit =
42  ( hit1.end == m_BCALGeom->kUpstream ? hit1 : hit2 );
43  const DBCALUnifiedHit& downHit =
44  ( hit1.end == m_BCALGeom->kDownstream ? hit1 : hit2 );
45 
46  double tUp = upHit.t;
47  double tDown = downHit.t;
48  m_t_US = tUp;
49  m_t_DS = tDown;
50 
51  // get the position with respect to the beginning of the module
52  // the parameters were extracted from quadratic fits in histograms of z_track = f(tUp - tDown)
53  // we are thus defining z_point so that it matches the z-coordinate of the track (at the middle of each layer)
54  // the p0, p1 and p2 tags are the usual names for the parameters of a quadratic fit in ROOT
55  m_zGlobal = track_p0 + track_p1 * ( tUp - tDown ) + track_p2 * ( tUp - tDown ) * ( tUp - tDown );
56 
57  // get the position with respect to the center of the module -- positive
58  // z in the downstream direction
60 
61  // set the z position relative to the center of the target
62  m_z = m_zGlobal - z_target_center;
63 
64 /* the old method -- kept now for reference. Will be deleted
65  *
66  // get the position with respect to the center of the module -- positive
67  // z in the downstream direction
68  m_zLocal = 0.5 * c_effective * ( tUp - tDown );
69 
70  // set the z position relative to the center of the target
71  m_z = m_zLocal + m_BCALGeom->GetBCAL_center() - z_target_center;
72 */
73 
74  //At this point m_z may be unphysical, i.e. it may be outside the BCAL.
75  //For the time being, this is okay. Forcing the z-position inside the
76  //BCAL at this point will bias the clustering procedure:
77  //1) Consider a cluster with a true position of z=400 cm (where the
78  //downstream end of the BCAL is at 407 cm). Say we have three points, one each
79  //at z=380 cm, 400 cm, 420 cm. If we force the latter point inside the BCAL
80  //the average of the z-positions will be biased toward the upstream direction.
81  //2) A point reconstructed at "410 cm" should not be treated equivalently to
82  //a point reconstructed at "430 cm", though these would both be truncated to
83  //407 cm. The latter should be more likely to
84  //match a cluster at 390 cm.
85  //The z-position will be forced inside the BCAL *after* clustering
86  //and averaging.
87 
88  // compute the arrival time of the energy at the cell
89  m_t = 0.5 * ( tUp + tDown - fibLen / c_effective );
90 
91  // now compute attentuation factors for each end based on distance
92  // the light must travel
93  // Make sure not to correct the energy by a distance longer than the length
94  // of the BCAL.
95 
96  float dUp = 0.5 * fibLen + m_zLocal;
97  float dDown = 0.5 * fibLen - m_zLocal;
98  if (dUp>fibLen) dUp=fibLen;
99  if (dUp<0) dUp=0;
100  if (dDown>fibLen) dDown=fibLen;
101  if (dDown<0) dDown=0;
102  float attUp = exp( -dUp / attenuation_length );
103  float attDown = exp( -dDown / attenuation_length );
104 
105  // use these to correct the energy
106  m_E_US = ( upHit.E / attUp );
107  m_E_DS = ( downHit.E / attDown );
108  m_E = ( m_E_US + m_E_DS ) / 2;
109 
110  m_r = m_BCALGeom->r( cellId );
111  //for a uniform distribution of width a, the RMS is a/sqrt(12)
112  m_sig_r = m_BCALGeom->rSize( cellId )/sqrt(12.0);
113 
114  m_phi = m_BCALGeom->phi( cellId );
115  m_sig_phi = m_BCALGeom->phiSize( cellId )/sqrt(12.0);
116 
117  //make a rough guess of sigma_z for now
118  //if we have TDC info
119  if (upHit.has_TDC_hit && downHit.has_TDC_hit) {
120  //We have TDC hits at both ends, timing is more precise
121  //Set z resolution to 1.1 cm/sqrt(E) as in NIM paper
122 
123  m_sig_z = 1.1 / sqrt(m_E);
124  } else {
125  //If we don't have TDC info at both ends then timing is less precise.
126  //A reasonable value might be 4 ns/sqrt(12)/sqrt(2)*c_eff=14 cm
127  //Although the ADC timing resolution will actually be better than
128  //4 ns/sqrt(12) due to FPGA algorithm.
129  //For now just set the value as large as needed.
130 
131  m_sig_z = 10.0;
132  }
133 
134  m_module = hit1.module;
135  m_layer = hit1.layer;
136  m_sector = hit1.sector;
137 
138  // recast in terms of spherical coordinates
140 }
141 
142 float
144 
145  // the path length in the module
146 
147  float modulePath = m_rho - m_BCALGeom->GetBCAL_inner_rad() / sin( m_theta );
148 
149  // retard the time by that distance divided by the speed of light
150 
151  return m_t - modulePath / ( 30 * k_cm / k_nsec );
152 }
153 
154 void
156 
157  m_rho = sqrt( m_r * m_r + m_z * m_z );
158  m_theta = fabs( atan2( m_r, m_z ) );
159 
160  float d_rho_d_r = m_r / sqrt( m_r * m_r + m_z * m_z );
161  float d_rho_d_z = m_z / sqrt( m_r * m_r + m_z * m_z );
162 
163  m_sig_rho = sqrt( m_sig_r * m_sig_r * d_rho_d_r * d_rho_d_r +
164  m_sig_z * m_sig_z * d_rho_d_z * d_rho_d_z );
165 
166  float d_theta_d_r = m_z / ( m_r * m_r + m_z * m_z );
167  float d_theta_d_z = -m_r / ( m_r * m_r + m_z * m_z );
168 
169  m_sig_theta = sqrt( m_sig_r * m_sig_r * d_theta_d_r * d_theta_d_r +
170  m_sig_z * m_sig_z * d_theta_d_z * d_theta_d_z );
171 
172 }
173 
174 
175 // Using const_cast is generally not a good idea, but we
176 // really want these to be const functions since, in practice,
177 // they don't change the location of the point.
178 // Clearly we can't make m_phi mutable -- that would be worse.
179 
180 void
182 
183  const_cast< DBCALPoint* >( this )->m_phi += 2*M_PI;
184 }
185 
186 void
188 
189  const_cast< DBCALPoint* >( this )->m_phi -= 2*M_PI;
190 }
void convertCylindricalToSpherical()
Definition: DBCALPoint.cc:155
DBCALPoint(const DBCALUnifiedHit &hit1, const DBCALUnifiedHit &hit2, double z_target_center, double attenutation_length, double c_effective, double track_p0, double track_p1, double track_p2, const DBCALGeometry *locGeom)
Definition: DBCALPoint.cc:18
float m_z
Definition: DBCALPoint.h:100
int m_module
Definition: DBCALPoint.h:95
float tInnerRadius() const
Definition: DBCALPoint.cc:143
float m_sig_r
distance from beam axis
Definition: DBCALPoint.h:101
float rSize(int fADC_cellId) const
float m_t
Arrival time.
Definition: DBCALPoint.h:91
float m_r
Definition: DBCALPoint.h:101
void sub2Pi() const
Definition: DBCALPoint.cc:187
float m_E
Energy of the Point used in higher objects.
Definition: DBCALPoint.h:88
float m_theta
Definition: DBCALPoint.h:106
float m_sig_rho
spherical distance wrt target center
Definition: DBCALPoint.h:105
float phi(int fADC_cellId) const
these functions are about the physical location and dimensions of a readout cell
float m_zLocal
z-coordinate relative to the center of BCAL
Definition: DBCALPoint.h:99
float m_phi
Definition: DBCALPoint.h:102
int m_layer
Definition: DBCALPoint.h:95
float GetBCAL_length() const
float m_zGlobal
z-coordinate relative to the beginning of the BCAL
Definition: DBCALPoint.h:98
float m_E_DS
Attenuation corrected Energy of DS Hit that contributed to the Point.
Definition: DBCALPoint.h:90
float m_sig_z
z-coordinate relative to the center of the target
Definition: DBCALPoint.h:100
const double k_cm
Definition: units.h:14
bool has_TDC_hit
Flag if the Unified Time is the TDC time.
DBCALGeometry::End end
float GetBCAL_inner_rad() const
float phiSize(int fADC_cellId) const
float m_t_US
Time of DS Hit that contributed to the Point.
Definition: DBCALPoint.h:92
float r(int fADC_cellId) const
float m_sig_phi
azimuthal angle
Definition: DBCALPoint.h:102
double sqrt(double)
double sin(double)
int m_sector
Definition: DBCALPoint.h:95
const double k_nsec
Definition: units.h:67
float GetBCAL_center() const
void add2Pi() const
Definition: DBCALPoint.cc:181
const DBCALGeometry * m_BCALGeom
Definition: DBCALPoint.h:108
int cellId(int module, int layer, int sector) const
these functions are about encoding/decoding module/layer/sector info in a cellId
float m_t_DS
Time of DS Hit that contributed to the Point.
Definition: DBCALPoint.h:93
float m_E_US
Attenuation corrected Energy of US Hit that contributed to the Point.
Definition: DBCALPoint.h:89
float m_sig_theta
polar angle wrt target center
Definition: DBCALPoint.h:106
float m_rho
Definition: DBCALPoint.h:105
float t
Unified time, obtained from ADC and/or TDC and used for further analysis.