00001 #include "StGammaEEmcLeakage.h"
00002 ClassImp(StGammaEEmcLeakage);
00003
00004 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
00005 #include "StGammaTower.h"
00006
00007 #include <TVector2.h>
00008 #include <TFile.h>
00009 #include <TH2F.h>
00010 #include <TMarker.h>
00011 #include <iostream>
00012 #include <cassert>
00013
00014
00015 StGammaEEmcLeakage *StGammaEEmcLeakage::sInstance = 0;
00016
00017 StGammaEEmcLeakage *StGammaEEmcLeakage::instance(){
00018 if ( !sInstance )
00019 {
00020 sInstance=new StGammaEEmcLeakage();
00021 }
00022 return sInstance;
00023 }
00024
00025 StGammaEEmcLeakage::StGammaEEmcLeakage()
00026 {
00027
00028 const Char_t *fname = "/afs/rhic.bnl.gov/star/users/jwebb/2008/tower-leakage/eemc-shape.root";
00029 const Int_t numberOfEtabins=12;
00030
00031 mFile=new TFile(fname);
00032 assert(mFile);
00033
00034 mNumberOfEtabins=numberOfEtabins;
00035 for ( Int_t i=0;i<numberOfEtabins;i++ )
00036 {
00037 mEnergyFractions.push_back( (TH2F*)mFile->Get( Form("h12TC%02ifrac",i+1) ) );
00038 mEnergyFractions.back()->Print();
00039 }
00040 mEEmcGeom=new EEmcGeomSimple();
00041 }
00042
00043 StGammaEEmcLeakage::~StGammaEEmcLeakage()
00044 {
00045 mEnergyFractions.clear();
00046 mFile->Close();
00047 delete mFile;
00048 }
00049
00050 Float_t StGammaEEmcLeakage::expectation( const TVector3 &gamma )
00051 {
00052
00053 const Float_t zplane = 288.0;
00054
00055 TVector3 position = gamma;
00056 position.SetMagThetaPhi( zplane / position.CosTheta(),
00057 position.Theta(),
00058 position.Phi() );
00059
00060
00061 Int_t tSec, tSub, tEta;
00062 if ( !mEEmcGeom -> getTower( position, tSec, tSub, tEta ) ) return 0.0;
00063
00064 TVector3 tTower = mEEmcGeom->getTowerCenter( (UInt_t)tSec, (UInt_t)tSub, (UInt_t)tEta );
00065
00066 tTower.SetMagThetaPhi( zplane / tTower.CosTheta(),
00067 tTower.Theta(),
00068 tTower.Phi() );
00069
00070
00071 TH2F *hFraction = mEnergyFractions[ tEta ];
00072
00073
00074
00075 Float_t phi = TVector2::Phi_mpi_pi( position.Phi() - tTower.Phi() );
00076
00077
00078 Float_t D_eta = position.Perp() * TMath::Cos( phi ) - tTower.Perp();
00079 Float_t D_phi = position.Perp() * TMath::Sin( phi );
00080
00081
00082
00083 Int_t bin1 = hFraction -> FindBin( +D_phi, D_eta );
00084 Int_t bin2 = hFraction -> FindBin( -D_phi, D_eta );
00085
00086
00087
00088 Int_t nmax=hFraction->GetNbinsX();
00089 Int_t nmay=hFraction->GetNbinsY();
00090 nmax*=nmay;
00091 if ( bin1<=0 || bin2<=0 ) {
00092 std::cout << "bin <= 0" << std::endl;
00093 return 0.0;
00094 }
00095 if ( bin1 > nmax || bin2 > nmax ) {
00096 std::cout << "bin > max" << std::endl;
00097 return 0.0;
00098 }
00099
00100 Float_t frac1 = hFraction -> GetBinContent( bin1 );
00101 Float_t frac2 = hFraction -> GetBinContent( bin2 );
00102
00103 Float_t f = (frac1+frac2)/2.0;
00104
00105 if ( f < 0.5 )
00106 {
00107 std::cout << "=========================================================+" << std::endl;
00108 std::cout << "frac=" << f << std::endl;
00109
00110
00111 std::cout << "D_eta=" << D_eta<<" D_phi=" << D_phi << std::endl;
00112 std::cout << "bin1=" << bin1 << " bin2=" << bin2 << " frac1=" << frac1 << " frac2=" << frac2 << std::endl;
00113
00114
00115
00116
00117
00118
00119 }
00120
00121 return f;
00122
00123 }
00124
00125
00126 TCanvas *
00127 StGammaEEmcLeakage::draw( const TVector3 &gamma )
00128 {
00129
00130 const Float_t zplane = 288.0;
00131 TVector3 position = gamma;
00132 position.SetMagThetaPhi( zplane / position.CosTheta(),
00133 position.Theta(),
00134 position.Phi() );
00135
00136
00137
00138 Int_t tSec, tSub, tEta;
00139 if ( !mEEmcGeom -> getTower( position, tSec, tSub, tEta ) ) return NULL;
00140
00141
00142 TVector3 tTower = mEEmcGeom->getTowerCenter( (UInt_t)tSec, (UInt_t)tSub, (UInt_t)tEta );
00143
00144 tTower.SetMagThetaPhi( zplane / tTower.CosTheta(),
00145 tTower.Theta(),
00146 tTower.Phi() );
00147
00148
00149
00150 TH2F *hFraction = mEnergyFractions[ tEta ];
00151 TCanvas *c = new TCanvas();
00152 hFraction->Draw("colz");
00153
00154
00155
00156 Float_t phi = TVector2::Phi_mpi_pi( gamma.Phi() - tTower.Phi() );
00157
00158
00159 Float_t D_eta = position.Perp() * TMath::Cos( phi ) - tTower.Perp();
00160 Float_t D_phi = position.Perp() * TMath::Sin( phi );
00161
00162 TMarker *m=new TMarker(D_phi,D_eta,22);
00163
00164 m->Draw();
00165
00166 return c;
00167
00168 }