StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGammaEEmcLeakage.cxx
1 #include "StGammaEEmcLeakage.h"
2 ClassImp(StGammaEEmcLeakage);
3 
4 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
5 #include "StGammaTower.h"
6 
7 #include <TVector2.h>
8 #include <TFile.h>
9 #include <TH2F.h>
10 #include <TMarker.h>
11 #include <iostream>
12 #include <cassert>
13 
14 
15 StGammaEEmcLeakage *StGammaEEmcLeakage::sInstance = 0;
16 
17 StGammaEEmcLeakage *StGammaEEmcLeakage::instance(){
18  if ( !sInstance )
19  {
20  sInstance=new StGammaEEmcLeakage();
21  }
22  return sInstance;
23 }
24 
25 StGammaEEmcLeakage::StGammaEEmcLeakage()
26 {
27  // const Char_t *fname = "share-shape1.root";
28  const Char_t *fname = "/afs/rhic.bnl.gov/star/users/jwebb/2008/tower-leakage/eemc-shape.root";
29  const Int_t numberOfEtabins=12;
30 
31  mFile=new TFile(fname);
32  assert(mFile);
33 
34  mNumberOfEtabins=numberOfEtabins;
35  for ( Int_t i=0;i<numberOfEtabins;i++ )
36  {
37  mEnergyFractions.push_back( (TH2F*)mFile->Get( Form("h12TC%02ifrac",i+1) ) );
38  mEnergyFractions.back()->Print();
39  }
40  mEEmcGeom=new EEmcGeomSimple();
41 }
42 
43 StGammaEEmcLeakage::~StGammaEEmcLeakage()
44 {
45  mEnergyFractions.clear();
46  mFile->Close();
47  delete mFile;
48 }
49 
50 Float_t StGammaEEmcLeakage::expectation( const TVector3 &gamma )
51 {
52 
53  const Float_t zplane = 288.0;
54 
55  TVector3 position = gamma;
56  position.SetMagThetaPhi( zplane / position.CosTheta(),
57  position.Theta(),
58  position.Phi() );
59 
60  // Get the centroid of the requested tower (should be but not required to be the same vector)
61  Int_t tSec, tSub, tEta;
62  if ( !mEEmcGeom -> getTower( position, tSec, tSub, tEta ) ) return 0.0; // passed invalid tower
63 
64  TVector3 tTower = mEEmcGeom->getTowerCenter( (UInt_t)tSec, (UInt_t)tSub, (UInt_t)tEta );
65 
66  tTower.SetMagThetaPhi( zplane / tTower.CosTheta(),
67  tTower.Theta(),
68  tTower.Phi() );
69 
70  // 2D histogram which contains the fraction of the photon's energy
71  TH2F *hFraction = mEnergyFractions[ tEta ];
72 
73  // angle between gamma vector and tower vector (may have botched the sign here... but it should
74  // be symmetric (and we will enforce ths below!)
75  Float_t phi = TVector2::Phi_mpi_pi( position.Phi() - tTower.Phi() );
76 
77  // the following distances should be measured in [cm]
78  Float_t D_eta = position.Perp() * TMath::Cos( phi ) - tTower.Perp();
79  Float_t D_phi = position.Perp() * TMath::Sin( phi );
80 
81  // std::cout << "find bin D_phi, D_eta = " << D_phi << ", " << D_eta << std::endl;
82 
83  Int_t bin1 = hFraction -> FindBin( +D_phi, D_eta );
84  Int_t bin2 = hFraction -> FindBin( -D_phi, D_eta );
85 
86 
87  // return nothing on over/underflow
88  Int_t nmax=hFraction->GetNbinsX();
89  Int_t nmay=hFraction->GetNbinsY();
90  nmax*=nmay;
91  if ( bin1<=0 || bin2<=0 ) {
92  std::cout << "bin <= 0" << std::endl;
93  return 0.0;
94  }
95  if ( bin1 > nmax || bin2 > nmax ) {
96  std::cout << "bin > max" << std::endl;
97  return 0.0;
98  }
99 
100  Float_t frac1 = hFraction -> GetBinContent( bin1 );
101  Float_t frac2 = hFraction -> GetBinContent( bin2 );
102 
103  Float_t f = (frac1+frac2)/2.0;
104 
105  if ( f < 0.5 )
106  {
107  std::cout << "=========================================================+" << std::endl;
108  std::cout << "frac=" << f << std::endl;
109  // position.Print();
110  // tTower.Print();
111  std::cout << "D_eta=" << D_eta<<" D_phi=" << D_phi << std::endl;
112  std::cout << "bin1=" << bin1 << " bin2=" << bin2 << " frac1=" << frac1 << " frac2=" << frac2 << std::endl;
113 
114  // std::cout << "gamma position is" << std::endl;
115  // position.Print();
116  // const Char_t *subs[]={"A","B","C","D","E","X"};
117  // std::cout << Form("tower containing photon returned as %02iT%s%02i",tSec+1,subs[tSub],tEta+1) << std::endl;
118 
119  }
120 
121  return f;
122 
123 }
124 
125 
126 TCanvas *
127 StGammaEEmcLeakage::draw( const TVector3 &gamma )
128 {
129 
130  const Float_t zplane = 288.0;
131  TVector3 position = gamma;
132  position.SetMagThetaPhi( zplane / position.CosTheta(),
133  position.Theta(),
134  position.Phi() );
135 
136 
137  // Get the centroid of the requested tower (should be but not required to be the same vector)
138  Int_t tSec, tSub, tEta;
139  if ( !mEEmcGeom -> getTower( position, tSec, tSub, tEta ) ) return NULL; // passed invalid tower
140 
141  // if ( !mEEmcGeom -> getTower( tower, tSec, tSub, tEta ) ) return NULL;
142  TVector3 tTower = mEEmcGeom->getTowerCenter( (UInt_t)tSec, (UInt_t)tSub, (UInt_t)tEta );
143 
144  tTower.SetMagThetaPhi( zplane / tTower.CosTheta(),
145  tTower.Theta(),
146  tTower.Phi() );
147 
148 
149  // 2D histogram which contains the fraction of the photon's energy
150  TH2F *hFraction = mEnergyFractions[ tEta ];
151  TCanvas *c = new TCanvas();
152  hFraction->Draw("colz");
153 
154  // angle between gamma vector and tower vector (may have botched the sign here... but it should
155  // be symmetric (and we will enforce ths below!)
156  Float_t phi = TVector2::Phi_mpi_pi( gamma.Phi() - tTower.Phi() );
157 
158  // the following distances should be measured in [cm]
159  Float_t D_eta = position.Perp() * TMath::Cos( phi ) - tTower.Perp();
160  Float_t D_phi = position.Perp() * TMath::Sin( phi );
161 
162  TMarker *m=new TMarker(D_phi,D_eta,22);
163 
164  m->Draw();
165 
166  return c;
167 
168 }
TVector3 getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
TCanvas * draw(const TVector3 &gamma)
EEMC simple geometry.
Float_t expectation(const TVector3 &gamma)