StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEmcGeomSimple.cxx
1 // $Id: EEmcGeomSimple.cxx,v 1.26 2010/08/26 22:48:47 ogrebeny Exp $
5 
11 #include <cmath>
12 #include <iostream>
13 
14 #include "TMath.h"
15 #include "TVector3.h"
16 
17 #if 0
18 #include "SystemOfUnits.h"
19 #include "StThreeVectorD.hh"
20 #include "StPhysicalHelixD.hh"
21 
22 #include "StEmcRawHit.h"
23 #include "StTrackGeometry.h"
24 #include "StTrack.h"
25 #endif
26 
27 #include "EEmcGeomDefs.h"
28 #include "EEmcGeomSimple.h"
29 
30 // ######################################################################
31 // *** WARNING NOT TESTED FOR mClock==1 (clock-wise) ***
32 // see EEmcGeomSimple.h for function documentation
33 // ######################################################################
34 ClassImp(EEmcGeomSimple)
35 
36 
37 // single instance of EEmcGeomSimple
39 
40 //
41 
42 //
44  : TObject()
45 {
46  // always initialize
47  mEtaBin = NULL;
48  mNumSec = 0;
49  mNumSSec = 0;
50  mNumEta = 0;
51 
52  mZ1 = 0.0;
53  mZ2 = 0.0;
54  mZSMD = 0.0;
55  mPhi0 = 0.0;
56  mClock = Undefined;
57 
58  useDefaultGeometry();
59 }
60 
61 //
63 {
64  if(mEtaBin) delete [] mEtaBin;
65 }
66 
67 //
68 // default geometry
69 // counter-clockwise (actual) Endcap (mClock==-1)
70 // 3'clock [2] : center at 0 deg
71 // 6'clock [5] : center at -90 deg
72 // 9'clock [8] : center at -180 deg
73 // 12'clock [11]: center at -270 deg
74 void
75 EEmcGeomSimple::useDefaultGeometry()
76 {
77  // default EtaBins 2.0 -> 1.086
78  // the first 13 entries mark the bounds of the 12 eta Bins. 14th value is not used
79  static const Float_t defaultEtaBin[] = {
80  2.0 ,
81  1.9008 , 1.8065 , 1.7168 , 1.6317 , 1.5507 , 1.4738 ,
82  1.4007 , 1.3312 , 1.2651 , 1.2023 , 1.1427 , 1.086 ,
83  0.0
84  };
85 
86  mNumSec = kEEmcNumSectors;
87  mNumSSec = kEEmcNumSubSectors;
88  mNumEta = kEEmcNumEtas;
89 
90  // fill in eta boundaries
91  if(mEtaBin) delete [] mEtaBin;
92  mEtaBin = new Float_t[mNumEta+1];
93  for(UInt_t i=0;i<=mNumEta && defaultEtaBin[i]>0.0 ;i++) mEtaBin[i] = defaultEtaBin[i];
94 
95  mZ1 = kEEmcZPRE1; // preshower
96  mZ2 = kEEmcZPOST; // postshower
97  mZSMD = kEEmcZSMD; //
98  mPhi0 = 75.0*M_PI/180.0; // first sector (1 o'clock) phi value [index 0]
99  mClock = CounterClockwise; // indexing goes counter-clockwise
100 }
101 
102 
103 TVector3
104 EEmcGeomSimple::getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
105 {
106  Double_t phi = 0.0;
107  Double_t eta = -1.0;
108  Double_t z = 0.0;
109  Double_t rho = 0.0;
110 
111  phi = getPhiMean(sec,sub);
112  eta = getEtaMean(etabin);
113  if(eta<0.0) {
114  LOG_ERROR << "invalid eta " << eta << endm;
115  return TVector3(0, 0, 0);
116  } else {
117  z = getZMean();
118  rho = z*tan(2.0*atan(exp(-1.0*eta)));
119  // create vector pointing toward the center of the tower
120  return TVector3(rho*cos(phi),rho*sin(phi),z);
121  }
122 }
123 
124 TVector3
125 EEmcGeomSimple::getDirection(const Float_t xetaBin, const Float_t xphiBin) const
126 {
127  int ietaBin=(int)(xetaBin+0.5);
128  int iphiBin=(int)(xphiBin+0.5);
129 
130  int isec=iphiBin/kEEmcNumSubSectors;
131  int isub=iphiBin%kEEmcNumSubSectors;
132 
133  // note the higher etaBin the smaller eta,
134  // the larger sec/sub the smaller phi-angle
135  Double_t phi = getPhiMean(isec,isub) - (xphiBin-iphiBin)*2*getPhiHalfWidth(isec,isub) ;
136  Double_t eta = getEtaMean(ietaBin) - (xetaBin-ietaBin)*2*getEtaHalfWidth(ietaBin);
137  if(eta<0.0) {
138  LOG_ERROR << "invalid eta " << eta << endm;
139  return TVector3(0, 0, 0);
140  } else {
141  Double_t z = getZMean();
142  Double_t rho = z/sinh(eta);
143 
144  // create vector pointing toward's the point in the tower
145  return TVector3(rho*cos(phi),rho*sin(phi),z);
146  }
147 }
148 
149 
150 
151 
152 
153 // =========================================================================
154 // gets a hit vector r checks if inside the EEmc
155 // and returns sector (0..mNumSec-1), subsector (0..mNumSSec-1)
156 // and eta(0..mNumEta)
157 // =========================================================================
158 bool
159 EEmcGeomSimple::getTower(const TVector3& r,
160  int &sec , int &sub, int &eta,
161  Float_t &dphi, Float_t &deta) const
162 {
163  const double dPhiSec = 2.0*M_PI/mNumSec; // phi width of a sector
164  const double dPhiSub = dPhiSec/mNumSSec; // phi width of a subsector
165 
166  // some shorcuts
167  // double rZ = r.Z();
168  double rEta = r.Eta();
169  double rPhi = r.Phi();
170  double rPhi0 = r.Phi() - mPhi0;
171 
172  sec=sub=eta=-1; // set invalid values
173 
174  // check if inside EEMC
175  //if(rZ <mZ1 || mZ2<rZ ) return false; // do not check the z-depth
176  // FIXME assumes that mEtaBin[i] decreas monotonically with increasing i
177  if(rEta<mEtaBin[mNumEta] || mEtaBin[0]<rEta ) return false;
178 
179  // ------------------------------------------------------------------------
180  // get the eta index
181  // FIXME assumes that mEtaBin[i] decreas monotonically with increasing i
182  // TODO use bisection for (slightly) faster search
183  for(eta=mNumEta;eta>=0;eta--) if(rEta<mEtaBin[eta]) break;
184 #if 0 /* use bisection */
185  int ek=0;
186  int el=mNumEta;
187  eta=(ek+el)/2;
188  while(ek!=eta) {
189  if( mEtaBin[eta]<rEta)
190  el=eta;
191  else
192  ek=eta;
193  eta=(ek+el)/2;
194  }
195 #endif
196 
197  // ------------------------------------------------------------------------
198  // get the sector index
199  int k = isClockwise() ? (int)floor(rPhi0/dPhiSec) : (int) ceil(rPhi0/dPhiSec);
200  sec = mClock*k;
201  while(sec<0) sec+=mNumSec; // adjust the numbers to [0,mNumSec)
202  sec %= mNumSec; //
203 
204  // ------------------------------------------------------------------------
205  // get the subsector index
206  int m = isClockwise() ? (int)floor(rPhi0/dPhiSub) : (int) ceil(rPhi0/dPhiSub);
207  sub = mClock*m;
208  while(sub<0) sub+=mNumSSec*mNumSec; // adjust the numbers to [0,mNumSec)
209  sub %= mNumSSec;//
210 
211 
212  // -------------------------------------------------
213  // these are (very) fast inline's
214  float xxx=getPhiMean(sec,sub) - rPhi;
215  if(xxx>TMath::Pi()) xxx=TMath::TwoPi()-xxx;
216  else if(xxx<-TMath::Pi()) xxx=TMath::TwoPi()+xxx;
217  dphi =xxx/ getPhiHalfWidth(sec,sub);
218  deta =(getEtaMean(eta) - rEta ) / getEtaHalfWidth(eta);
219 
220  return true;
221 }
222 
223 
224 #if 0
225 
226 // converts direction vector 'r' to sec/sub/eta bin. All counted from zero.
227 void
228 EEmcGeomSimple::direction2tower( TVector3 r,
229  int &iSec, int &iSub, int &iEta, float &rPhi , float &rEta )
230 {
231  // printf("in GetTowNo() \n");
232 
233  //printf("intersection at x/y/z=%f/%f/%f\n",r.x(),r.y(),r.z());
234 
235  float eta=r.Eta();
236  float phiDeg=180.*r.Phi()/3.14159;
237  float phi=phiDeg -75;
238  if(phi>0) phi-=360;
239  phi=-phi;
240 
241  // printf("phiDeg=%f --> phi=%f eta=%f\n",phiDeg,phi,eta);
242  int ix=((int)phi)/6;
243  iSec=ix/5;
244  iSub=ix%5;
245  rPhi =phi-iSec*30-iSub*5 -2.5;
246 
247  Float_t *dEB= mEtaBin;
248  iEta=-1;
249  rEta=-999;
250  for(int i=0;i<13;i++){
251  // printf(" %d %f %f %d \n",i,eta,defaultEtaBin[i],iEta);
252  if(eta<dEB[i]) continue;
253  iEta=i-1;
254  if(i>0 && i<=12) rEta= -(dEB[i]+dEB[i-1]-2*eta)/2./(dEB[i]-dEB[i-1]);
255  break;
256  }
257  // printf(" ix=%d sec=%d sub=%c eta=%d\n",ix,iSec+1,iSub+'A',iEta+1);
258 
259 }
260 
261 
262 // compute the distance of a point from the center of a tower pointed by hit
263 Float_t
264 EEmcGeomSimple::getR2Dist(const StThreeVectorD& point,const StEmcRawHit& hit)
265  const
266 {
267  StThreeVectorD r = getTowerCenter(hit) - point;
268  return r.mag2();
269 }
270 
271 Bool_t
272 EEmcGeomSimple::pointMatch(const StThreeVectorD& pt, const StEmcRawHit& hit,
273  Float_t deta, Float_t dphi, Float_t dz) const
274 {
275  StThreeVectorD tc = getTowerCenter(hit);
276 
277  // check z
278  if( fabs(tc.z() -pt.z() ) > (1.0+dz)*getZHalfWidth() ) return kFALSE;
279  // check phi
280  if( fabs(tc.phi()-pt.phi()) > (1.0+dphi)*getPhiHalfWidth() ) return kFALSE;
281  // finally check eta
282  if( fabs(tc.pseudoRapidity()-pt.pseudoRapidity()) >
283  (1.0+deta)*getEtaHalfWidth(hit.eta()) ) return kFALSE;
284  return kTRUE;
285 }
286 
287 
288 
289 
290 inline StThreeVectorD
291 EEmcGeomSimple::getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
292 {
293  Double_t phi = getPhiMean(sec,sub);
294  Double_t eta = getEtaMean(etabin);
295  if(eta<0.0) return StThreeVectorD();
296  Double_t z = getZMean();
297  Double_t rho = z*tan(2.0*atan(exp(-1.0*eta)));
298 
299  // create vector pointing toward the center of the tower
300  return StThreeVectorD(rho*cos(phi),rho*sin(phi),z);
301 }
302 
303 inline StThreeVectorD
305 {
306  return getTowerCenter(hit.module(),hit.sub(),hit.eta());
307 }
308 
309 
310 inline StThreeVectorD
311 EEmcGeomSimple::getTrackPoint(const StTrack& track, Double_t z) const
312 {
313  StPhysicalHelixD helix = track.geometry()->helix();
314  if(helix.dipAngle()<1e-13) return StThreeVectorD();
315  double s = ( z - helix.origin().z() ) / sin( helix.dipAngle()) ;
316  return StThreeVectorD(helix.at(s));
317 }
318 
319 #endif
320 
321 
322 // $Log: EEmcGeomSimple.cxx,v $
323 // Revision 1.26 2010/08/26 22:48:47 ogrebeny
324 // Improved constness
325 //
326 // Revision 1.25 2009/02/11 20:37:36 ogrebeny
327 // *** empty log message ***
328 //
329 // Revision 1.24 2009/02/11 20:04:23 ogrebeny
330 // 1. Fix the sectors initialization.
331 // 2. Remove exceptions from the geom code.
332 //
333 // Revision 1.23 2005/04/29 03:06:03 balewski
334 // *** empty log message ***
335 //
336 // Revision 1.22 2004/06/03 20:59:54 zolnie
337 // - phi angle now adjusted to [-pi,pi] interval in accordace to TVecror3 convention
338 // - replaced Jan's interesting implementation of direction2tower method with
339 // a resurrected getTower (formerly getHit) method see EEmcGeomSimple.h
340 //
341 // Revision 1.21 2004/06/01 21:20:49 balewski
342 // direction2tower ()
343 //
344 // Revision 1.20 2004/05/25 15:32:36 zolnie
345 // phi angles adjusted to [0,2pi] interval
346 //
347 // Revision 1.19 2004/05/24 18:33:39 zolnie
348 // comment cleanup, added a small exception class
349 // more argument checking, exception thrown when argument invalid
350 //
351 // Revision 1.18 2004/05/20 21:12:07 zolnie
352 // added a static instance of EEmcGeomSimple
353 //
354 // Revision 1.17 2003/09/17 22:05:33 zolnie
355 // delete mumbo-jumbo
356 //
357 // Revision 1.16 2003/09/11 19:41:06 zolnie
358 // updates for gcc3.2
359 //
360 // Revision 1.15 2003/09/05 15:04:24 zolnie
361 // remove Stiostream/iostream from the source code
362 //
363 // Revision 1.14 2003/09/02 17:57:56 perev
364 // gcc 3.2 updates + WarnOff
365 //
366 // Revision 1.13 2003/07/01 14:13:25 balewski
367 // simplified formulano clue
368 //
369 // Revision 1.12 2003/05/23 22:13:04 zolnie
370 // SUN does not like inlines (why??)
371 //
372 // Revision 1.11 2003/04/25 15:53:52 zolnie
373 // always initalize
374 //
375 // Revision 1.10 2003/04/23 18:11:19 balewski
376 // 'continous' eta & phi bins added
377 //
378 // Revision 1.9 2003/03/22 22:44:57 zolnie
379 // make it standalone library
380 //
381 // Revision 1.8 2003/03/06 18:54:21 zolnie
382 // improvements for track/tower matching
383 //
384 // Revision 1.7 2003/02/20 21:47:25 zolnie
385 // *** empty log message ***
386 //
387 // Revision 1.4 2003/01/19 03:47:10 zolnie
388 // still further improvements
389 //
390 // Revision 1.3 2003/01/18 02:35:53 zolnie
391 // further modifications
392 //
393 // Revision 1.1 2003/01/16 19:33:50 zolnie
394 // added a simple Geom class to conver a track hit -> tower hit
395 //
Bool_t isClockwise() const
is endcap labeling clockwise?
TVector3 getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
Float_t getZHalfWidth() const
returns the half-width of EEMC (in z-direction)
Float_t getEtaHalfWidth(UInt_t eta) const
Float_t getZMean() const
returns the center of EEMC in z direction
virtual ~EEmcGeomSimple()
the destructor
Float_t getPhiMean(UInt_t sec) const
TVector3 getDirection(const Float_t detaBin, const Float_t dphiBin) const
const StThreeVector< double > & origin() const
-sign(q*B);
Definition: StHelix.hh:224
Float_t getPhiHalfWidth(UInt_t sec=0, UInt_t ssec=0) const
EEMC simple geometry.
bool getTower(const TVector3 &r, int &sec, int &sub, int &etabin, Float_t &dphi, Float_t &deta) const
Float_t getEtaMean(UInt_t eta) const