00001
00002
00003
00004 #include "RVersion.h"
00005 #if ROOT_VERSION_CODE < 331013
00006 #include "TCL.h"
00007 #else
00008 #include "TCernLib.h"
00009 #endif
00010 #include <Stiostream.h>
00011 #include "StEventTypes.h"
00012 #include "StiHit.h"
00013 #include "StiDetector.h"
00014 #include "StiPlacement.h"
00015 #ifdef Sti_DEBUG
00016 # include "TRMatrix.h"
00017 # include "TRVector.h"
00018 # define PrP(A) cout << "\t" << (#A) << " = \t" << ( A )
00019 # define PrPP(A,B) cout << "=== StiHit::" << (#A); PrP((B)); cout << endl;
00020 #endif
00021
00022
00023
00024 StiHit::StiHit()
00025 {
00026 reset();
00027 }
00028
00029
00030
00031 StiHit::StiHit(const StiHit &h)
00032 {
00033 memcpy(mBeg,h.mBeg,mEnd-mBeg+1);
00034 }
00035
00036
00037 const StiHit& StiHit::operator=(const StiHit & h)
00038 {
00039 memcpy(mBeg,h.mBeg,mEnd-mBeg+1);
00040 return *this;
00041 }
00042
00043
00044 StiHit::~StiHit()
00045 {}
00046
00047
00050 void StiHit::rotate(double alpha)
00051 {
00052 assert(!mdetector);
00053 static float rotMx[3][3]={{1,0,0},{0,1,0},{0,0,1}}, s[6];
00054
00055 mrefangle+=alpha;
00056 double ca = cos(alpha);
00057 double sa = sin(alpha);
00058 rotMx[0][0] = ca; rotMx[0][1] = sa;
00059 rotMx[1][0] =-sa; rotMx[1][1] = ca;
00060
00061 double x = rotMx[0][0]*mx + rotMx[0][1]*my;
00062 double y = rotMx[1][0]*mx + rotMx[1][1]*my;
00063 mx = x; my = y;
00064
00065
00066 memcpy(s,&msxx,sizeof(s));
00067 TCL::trasat(rotMx[0],s,&msxx,3,3);
00068 }
00069
00070
00071 void StiHit::setError(const StMatrixF& matrix)
00072 {
00073 enum Labels {x=1, y=2, z=3};
00074
00075
00076 msxx = matrix(x,x);
00077 msyy = matrix(y,y);
00078 mszz = matrix(z,z);
00079
00080 msxy = matrix(x,y);
00081 msxz = matrix(x,z);
00082 msyz = matrix(y,z);
00083 return;
00084 }
00085
00086 void StiHit::setError(const float matrix[6])
00087 {
00088 memcpy(&msxx,matrix,6*sizeof(msxx));
00089 }
00090
00091
00093 ostream& operator<<(ostream& os, const StiHit& hit)
00094 {
00095 return os <<hit.refangle() <<" "<<hit.position()
00096 <<"L:"<<hit.x() <<" "<<hit.y() <<" "<<hit.z()
00097 <<"G:"<<hit.x_g()<<" "<<hit.y_g()<<" "<<hit.z_g();
00098 }
00099
00100
00101
00102 double StiHit::getValue(int key) const
00103 {
00104 double value;
00105 switch (key)
00106 {
00107 case kZ: value = _zg; break;
00108 case kR: value = ::sqrt(_xg*_xg+_yg*_yg); break;
00109 case kPseudoRapidity: value = getPseudoRapidity(); break;
00110 case kPhi: value = atan2(_yg,_xg);break;
00111 default: value = -999999.; break;
00112 }
00113 return value;
00114 }
00115
00116
00117 double StiHit::getPseudoRapidity() const
00118 {
00119 double r=::sqrt(_xg*_xg+_yg*_yg);
00120 double tanTheta = ::tan(::atan2(r,_zg)/2.);
00121 if (tanTheta>0.)
00122 return -::log(tanTheta);
00123 else
00124 return 1.e10;
00125 }
00126
00127 void StiHit::reset()
00128 {
00129 memset(mBeg,0,mEnd-mBeg+1);
00130 static unsigned int myCount=0;
00131 mCount = ++myCount;
00132 }
00133
00134
00135
00136 void StiHit::setGlobal(const StiDetector * detector,
00137 const StMeasuredPoint * stHit,
00138 float gx, float gy, float gz,
00139 float energy)
00140 {
00141 if (detector)
00142 {
00143 StiPlacement * placement = detector->getPlacement();
00144 mrefangle = placement->getLayerAngle();
00145 mposition = placement->getLayerRadius();
00146 double togra = 180./M_PI;
00147 double centerAngle = placement->getCenterRefAngle()*togra;
00148 double myAngle = atan2(gy,gx)*togra;
00149 double dif = myAngle-centerAngle;
00150 if (dif > 180) dif-=360;
00151 if (dif <-180) dif+=360;
00152 if (fabs(dif) > 1.1*22) {
00153 LOG_WARN <<
00154 Form("**** StiHit.%s wrong angle: hitAng=%f ctrAng=%g dif=%g ****"
00155 ,detector->getName().c_str(),myAngle,centerAngle,dif)
00156 << endm;
00157 assert( fabs(dif) <33 );
00158 }
00159 double normalAngle = placement->getNormalRefAngle()*togra;
00160 dif = myAngle-normalAngle;
00161 if (dif > 180) dif-=360;
00162 if (dif <-180) dif+=360;
00163 if (fabs(dif) > 1.1*30) {
00164 LOG_WARN <<
00165 Form("**** StiHit.%s wrong angle: hitAng=%f norAng=%g dif=%g ****"
00166 ,detector->getName().c_str(),myAngle,normalAngle,dif)
00167 << endm;
00168 }
00169
00170 mx = detector->_cos*gx + detector->_sin*gy;
00171 my = -detector->_sin*gx + detector->_cos*gy;
00172 }
00173 else
00174 {
00175 mrefangle = 0.;
00176 mposition = 0.;
00177 mx = gx;
00178 my = gy;
00179 }
00180 mz = gz;
00181 msxx = -1.;
00182 msyy = -1.;
00183 mszz = -1.;
00184 msxy = 0.;
00185 msxz = 0.;
00186 msyz = 0.;
00187 _xg = gx;
00188 _yg = gy;
00189 _zg = gz;
00190 mTimesUsed = 0;
00191 mdetector = detector; msthit = stHit;
00192 _energy = energy;
00193 if (!stHit ) return;
00194 if (!detector) return;
00195 double pos = detector->getPlacement()->getNormalRadius();
00196 double dif = mx-pos;
00197 if (fabs(dif)<0.05*pos) return;
00198 LOG_WARN <<
00199 Form("**** StiHit.%s too far: x=%f pos=%g dif=%g ****\n"
00200 ,detector->getName().c_str(),mx,pos,dif)
00201 << endm;
00202 assert(fabs(dif)<0.30*pos);
00203 }
00204
00205
00206
00207 void StiHit::set(const StiDetector * detector,
00208 const StMeasuredPoint * stHit,
00209 float energy,
00210 float x, float y, float z,
00211 float sxx, float sxy, float sxz, float syy, float syz, float szz)
00212 {
00213 if (detector)
00214 {
00215 StiPlacement * placement = detector->getPlacement();
00216 mrefangle = placement->getLayerAngle();
00217 mposition = placement->getLayerRadius();
00218 _xg = detector->_cos*x - detector->_sin*y;
00219 _yg = detector->_sin*x + detector->_cos*y;
00220 }
00221 else
00222 {
00223 mrefangle = 0.;
00224 mposition = 0.;
00225 _xg = x;
00226 _yg = y;
00227 }
00228 mx = x;
00229 my = y;
00230 mz = z;
00231 msxx = sxx;
00232 msyy = syy;
00233 mszz = szz;
00234 msxy = sxy;
00235 msxz = sxz;
00236 msyz = syz;
00237 mTimesUsed = 0;
00238 mdetector = detector;
00239 msthit = stHit;
00240 _energy = energy;
00241 _zg = z;
00242 if (!stHit) return;
00243 assert( fabs(stHit->position().x()-_xg)< 1.e-6
00244 && fabs(stHit->position().y()-_yg)< 1.e-6
00245 && fabs(stHit->position().z()-_zg)< 1.e-6);
00246
00247 if (!detector) return;
00248 double pos = detector->getPlacement()->getNormalRadius();
00249 double dif = mx-pos;
00250 if (fabs(dif)<1.) return;
00251 LOG_ERROR <<
00252
00253 Form("**** StiHit.%s too far: x=%f pos=%g dif=%g ****\n"
00254 ,detector->getName().c_str(),mx,pos,dif)
00255 << endm;
00256 }
00257
00258
00259 void StiHit::setTimesUsed(unsigned int val)
00260 {
00261 mTimesUsed=(unsigned char)val;
00262 }
00263
00264
00265 float StiHit::getEloss()
00266 {
00267 return _energy;
00268 }
00269
00270
00271 const StThreeVectorF StiHit::globalPosition() const
00272 {
00273 return StThreeVectorF(_xg,_yg,_zg);
00274 }
00275
00276
00277 void StiHit::set(float position, float angle, float y, float z)
00278 {
00279 memset(mBeg,0,mEnd-mBeg+1);
00280 mrefangle = angle;
00281 mposition = position;
00282 mx = position;
00283 my = y;
00284 mz = z;
00285
00286 _xg = 100000.;
00287 _yg = 100000.;
00288 _zg = 100000.;
00289 }
00290
00291 void StiHit::makeDca()
00292 {
00293 memset(mBeg,0,mEnd-mBeg+1);
00294 mszz = 1e12;
00295 }
00296
00297 int StiHit::isDca() const
00298 {
00299 if (mdetector) return 0;
00300 if (mx || my || mz) return 0;
00301 if (mszz<1000) return 0;
00302 return 1;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311