StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcMath.cxx
1 #include <cmath>
2 #include <TArrayD.h>
3 #include "StEmcMath.h"
4 #include "StEvent/StMeasuredPoint.h"
5 #include "StarClassLibrary/StThreeVectorF.hh"
6 #include "StEmcUtil/others/emcInternalDef.h"
7 #include "StEmcUtil/geometry/StEmcGeom.h"
8 
9 ClassImp(StEmcMath)
10 
11 Bool_t
12 StEmcMath::etaPhi(StMeasuredPoint* point,StMeasuredPoint* vertex, Double_t &eta, Double_t &phi)
13 {
14 //
15 // point must be defined; vertex is zero on default
16 //
17  const StThreeVectorF *p1, *p2;
18  p1 = NULL;
19  StThreeVectorF vt;
20 
21  if(point) {
22  if(vertex) p1 = &vertex->position();
23  p2 = &point->position();
24 
25  if(p1) vt = (*p2) - (*p1); // shift
26  else vt = (*p2);
27 
28  eta = vt.pseudoRapidity();
29  phi = vt.phi();
30  return kTRUE;
31  }
32  return kFALSE; // point indefined
33 }
34 
35 Double_t
36 StEmcMath::pseudoRapidity(StMeasuredPoint* point,StMeasuredPoint* vertex)
37 {
38  Double_t eta, phi;
39  if(etaPhi(point,vertex, eta,phi)) return eta;
40  else return -9999.;
41 }
42 
43 Double_t
44 StEmcMath::phi(StMeasuredPoint* point,StMeasuredPoint* vertex)
45 {
46  Double_t eta, phi;
47  if(etaPhi(point,vertex, eta,phi)) return phi;
48  else return -9999.;
49 }
50 
51 UInt_t
52 StEmcMath::detectorId(const StDetectorId stId)
53 {
54  // Transition from STAR numeration to internal EMC numeration
55  Int_t id = stId - kBarrelEmcTowerIdentifier + 1;
56  if(id<BEMC || id> ESMDP) return 0; // Wrong value of stId
57  else return UInt_t(id);
58 }
59 
60 StDetectorId
61 StEmcMath::detectorId(const UInt_t id)
62 {
63  // Transition from internal EMC numeration numeration to STAR
64  StDetectorId stId = StDetectorId(id + kBarrelEmcTowerIdentifier - 1);
65  if(stId<kBarrelEmcTowerIdentifier || stId >kEndcapSmdVStripIdentifier)
66  return kUnknownId;
67  else return stId;
68 }
69 
70 Double_t
71 StEmcMath::getPhiPlusMinusPi(const Double_t phi)
72 {
73  // convert phi to the range from -pi<= phi< pi (as in StEmcGeom)
74  Double_t phiw = phi;
75  while(phiw >= M_PI) phiw -= 2.*M_PI;
76  while(phiw < -M_PI) phiw += 2.*M_PI;
77  return phiw;
78 }
79 
80 TArrayD *StEmcMath::binForSmde(Bool_t kprint)
81 {
82 // Calculate correct eta binnig for smd eta
83  StEmcGeom* geom = StEmcGeom::getEmcGeom(3); // For SMDE
84  const Int_t neta = geom->NEta();
85  Int_t iw1, iw2;
86  const Float_t *eb = geom->Eta();
87  TArrayD *xb = new TArrayD(2*neta+1);
88  (*xb)[neta] = 0.0;
89  for(Int_t ik=0; ik<neta; ik++){
90  iw1 = neta + 1 + ik;
91  iw2 = neta-ik-1;
92  Float_t x1 = eb[ik], x2, xw;
93  if(ik<neta-1) {
94  x2 = eb[ik+1];
95  xw = (x1+x2)*0.5;
96  }
97  else xw = 0.99;
98  (*xb)[iw1] = +xw;
99  (*xb)[iw2] = -xw;
100  if(kprint)
101  printf(" iw1 %i %f => iw2 %i %f => eta %f\n", iw1,(*xb)[iw1], iw2,(*xb)[iw2], eb[ik]);
102  }
103  return xb;
104 }