00001
00005
00011 #include <cmath>
00012 #include <iostream>
00013
00014 #include "TMath.h"
00015 #include "TVector3.h"
00016
00017 #if 0
00018 #include "SystemOfUnits.h"
00019 #include "StThreeVectorD.hh"
00020 #include "StPhysicalHelixD.hh"
00021
00022 #include "StEmcRawHit.h"
00023 #include "StTrackGeometry.h"
00024 #include "StTrack.h"
00025 #endif
00026
00027 #include "EEmcGeomDefs.h"
00028 #include "EEmcGeomSimple.h"
00029
00030
00031
00032
00033
00034 ClassImp(EEmcGeomSimple)
00035
00036
00037
00038 EEmcGeomSimple EEmcGeomSimple::sInstance;
00039
00040
00041
00042
00043 EEmcGeomSimple::EEmcGeomSimple()
00044 : TObject()
00045 {
00046
00047 mEtaBin = NULL;
00048 mNumSec = 0;
00049 mNumSSec = 0;
00050 mNumEta = 0;
00051
00052 mZ1 = 0.0;
00053 mZ2 = 0.0;
00054 mZSMD = 0.0;
00055 mPhi0 = 0.0;
00056 mClock = Undefined;
00057
00058 useDefaultGeometry();
00059 }
00060
00061
00062 EEmcGeomSimple::~EEmcGeomSimple()
00063 {
00064 if(mEtaBin) delete [] mEtaBin;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 void
00075 EEmcGeomSimple::useDefaultGeometry()
00076 {
00077
00078
00079 static const Float_t defaultEtaBin[] = {
00080 2.0 ,
00081 1.9008 , 1.8065 , 1.7168 , 1.6317 , 1.5507 , 1.4738 ,
00082 1.4007 , 1.3312 , 1.2651 , 1.2023 , 1.1427 , 1.086 ,
00083 0.0
00084 };
00085
00086 mNumSec = kEEmcNumSectors;
00087 mNumSSec = kEEmcNumSubSectors;
00088 mNumEta = kEEmcNumEtas;
00089
00090
00091 if(mEtaBin) delete [] mEtaBin;
00092 mEtaBin = new Float_t[mNumEta+1];
00093 for(UInt_t i=0;i<=mNumEta && defaultEtaBin[i]>0.0 ;i++) mEtaBin[i] = defaultEtaBin[i];
00094
00095 mZ1 = kEEmcZPRE1;
00096 mZ2 = kEEmcZPOST;
00097 mZSMD = kEEmcZSMD;
00098 mPhi0 = 75.0*M_PI/180.0;
00099 mClock = CounterClockwise;
00100 }
00101
00102
00103 TVector3
00104 EEmcGeomSimple::getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
00105 {
00106 Double_t phi = 0.0;
00107 Double_t eta = -1.0;
00108 Double_t z = 0.0;
00109 Double_t rho = 0.0;
00110
00111 phi = getPhiMean(sec,sub);
00112 eta = getEtaMean(etabin);
00113 if(eta<0.0) {
00114 LOG_ERROR << "invalid eta " << eta << endm;
00115 return TVector3(0, 0, 0);
00116 } else {
00117 z = getZMean();
00118 rho = z*tan(2.0*atan(exp(-1.0*eta)));
00119
00120 return TVector3(rho*cos(phi),rho*sin(phi),z);
00121 }
00122 }
00123
00124 TVector3
00125 EEmcGeomSimple::getDirection(const Float_t xetaBin, const Float_t xphiBin) const
00126 {
00127 int ietaBin=(int)(xetaBin+0.5);
00128 int iphiBin=(int)(xphiBin+0.5);
00129
00130 int isec=iphiBin/kEEmcNumSubSectors;
00131 int isub=iphiBin%kEEmcNumSubSectors;
00132
00133
00134
00135 Double_t phi = getPhiMean(isec,isub) - (xphiBin-iphiBin)*2*getPhiHalfWidth(isec,isub) ;
00136 Double_t eta = getEtaMean(ietaBin) - (xetaBin-ietaBin)*2*getEtaHalfWidth(ietaBin);
00137 if(eta<0.0) {
00138 LOG_ERROR << "invalid eta " << eta << endm;
00139 return TVector3(0, 0, 0);
00140 } else {
00141 Double_t z = getZMean();
00142 Double_t rho = z/sinh(eta);
00143
00144
00145 return TVector3(rho*cos(phi),rho*sin(phi),z);
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 bool
00159 EEmcGeomSimple::getTower(const TVector3& r,
00160 int &sec , int &sub, int &eta,
00161 Float_t &dphi, Float_t &deta) const
00162 {
00163 const double dPhiSec = 2.0*M_PI/mNumSec;
00164 const double dPhiSub = dPhiSec/mNumSSec;
00165
00166
00167
00168 double rEta = r.Eta();
00169 double rPhi = r.Phi();
00170 double rPhi0 = r.Phi() - mPhi0;
00171
00172 sec=sub=eta=-1;
00173
00174
00175
00176
00177 if(rEta<mEtaBin[mNumEta] || mEtaBin[0]<rEta ) return false;
00178
00179
00180
00181
00182
00183 for(eta=mNumEta;eta>=0;eta--) if(rEta<mEtaBin[eta]) break;
00184 #if 0
00185 int ek=0;
00186 int el=mNumEta;
00187 eta=(ek+el)/2;
00188 while(ek!=eta) {
00189 if( mEtaBin[eta]<rEta)
00190 el=eta;
00191 else
00192 ek=eta;
00193 eta=(ek+el)/2;
00194 }
00195 #endif
00196
00197
00198
00199 int k = isClockwise() ? (int)floor(rPhi0/dPhiSec) : (int) ceil(rPhi0/dPhiSec);
00200 sec = mClock*k;
00201 while(sec<0) sec+=mNumSec;
00202 sec %= mNumSec;
00203
00204
00205
00206 int m = isClockwise() ? (int)floor(rPhi0/dPhiSub) : (int) ceil(rPhi0/dPhiSub);
00207 sub = mClock*m;
00208 while(sub<0) sub+=mNumSSec*mNumSec;
00209 sub %= mNumSSec;
00210
00211
00212
00213
00214 float xxx=getPhiMean(sec,sub) - rPhi;
00215 if(xxx>TMath::Pi()) xxx=TMath::TwoPi()-xxx;
00216 else if(xxx<-TMath::Pi()) xxx=TMath::TwoPi()+xxx;
00217 dphi =xxx/ getPhiHalfWidth(sec,sub);
00218 deta =(getEtaMean(eta) - rEta ) / getEtaHalfWidth(eta);
00219
00220 return true;
00221 }
00222
00223
00224 #if 0
00225
00226
00227 void
00228 EEmcGeomSimple::direction2tower( TVector3 r,
00229 int &iSec, int &iSub, int &iEta, float &rPhi , float &rEta )
00230 {
00231
00232
00233
00234
00235 float eta=r.Eta();
00236 float phiDeg=180.*r.Phi()/3.14159;
00237 float phi=phiDeg -75;
00238 if(phi>0) phi-=360;
00239 phi=-phi;
00240
00241
00242 int ix=((int)phi)/6;
00243 iSec=ix/5;
00244 iSub=ix%5;
00245 rPhi =phi-iSec*30-iSub*5 -2.5;
00246
00247 Float_t *dEB= mEtaBin;
00248 iEta=-1;
00249 rEta=-999;
00250 for(int i=0;i<13;i++){
00251
00252 if(eta<dEB[i]) continue;
00253 iEta=i-1;
00254 if(i>0 && i<=12) rEta= -(dEB[i]+dEB[i-1]-2*eta)/2./(dEB[i]-dEB[i-1]);
00255 break;
00256 }
00257
00258
00259 }
00260
00261
00262
00263 Float_t
00264 EEmcGeomSimple::getR2Dist(const StThreeVectorD& point,const StEmcRawHit& hit)
00265 const
00266 {
00267 StThreeVectorD r = getTowerCenter(hit) - point;
00268 return r.mag2();
00269 }
00270
00271 Bool_t
00272 EEmcGeomSimple::pointMatch(const StThreeVectorD& pt, const StEmcRawHit& hit,
00273 Float_t deta, Float_t dphi, Float_t dz) const
00274 {
00275 StThreeVectorD tc = getTowerCenter(hit);
00276
00277
00278 if( fabs(tc.z() -pt.z() ) > (1.0+dz)*getZHalfWidth() ) return kFALSE;
00279
00280 if( fabs(tc.phi()-pt.phi()) > (1.0+dphi)*getPhiHalfWidth() ) return kFALSE;
00281
00282 if( fabs(tc.pseudoRapidity()-pt.pseudoRapidity()) >
00283 (1.0+deta)*getEtaHalfWidth(hit.eta()) ) return kFALSE;
00284 return kTRUE;
00285 }
00286
00287
00288
00289
00290 inline StThreeVectorD
00291 EEmcGeomSimple::getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
00292 {
00293 Double_t phi = getPhiMean(sec,sub);
00294 Double_t eta = getEtaMean(etabin);
00295 if(eta<0.0) return StThreeVectorD();
00296 Double_t z = getZMean();
00297 Double_t rho = z*tan(2.0*atan(exp(-1.0*eta)));
00298
00299
00300 return StThreeVectorD(rho*cos(phi),rho*sin(phi),z);
00301 }
00302
00303 inline StThreeVectorD
00304 EEmcGeomSimple::getTowerCenter(const StEmcRawHit &hit) const
00305 {
00306 return getTowerCenter(hit.module(),hit.sub(),hit.eta());
00307 }
00308
00309
00310 inline StThreeVectorD
00311 EEmcGeomSimple::getTrackPoint(const StTrack& track, Double_t z) const
00312 {
00313 StPhysicalHelixD helix = track.geometry()->helix();
00314 if(helix.dipAngle()<1e-13) return StThreeVectorD();
00315 double s = ( z - helix.origin().z() ) / sin( helix.dipAngle()) ;
00316 return StThreeVectorD(helix.at(s));
00317 }
00318
00319 #endif
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395