00001
00002
00003
00004
00005
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/Bootstrap.h"
00008
00009 #include "BesMucEfficiency.hh"
00010 #include "G4Box.hh"
00011 #include "G4VSolid.hh"
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015 #include "TFile.h"
00016 #include "TTree.h"
00017
00018
00019 using namespace std;
00020 BesMucEfficiency * BesMucEfficiency::fPointer=0;
00021 BesMucEfficiency * BesMucEfficiency::Instance(void){
00022 if(!fPointer)fPointer = new BesMucEfficiency();
00023 return fPointer;
00024
00025 }
00026
00027 BesMucEfficiency::BesMucEfficiency()
00028 {
00029 if(fPointer)
00030 {G4Exception("BesMucEfficiency constructed twice.");}
00031 fPointer=this;
00032
00033 }
00034
00035 BesMucEfficiency::~BesMucEfficiency()
00036 {
00037 }
00038
00039
00040 void BesMucEfficiency::Initialize(G4String filename)
00041 { G4int part,seg,gap,strip,pad;
00042 G4double effi;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 std::ifstream fin(filename);
00061
00062 char buffer[100];
00063 G4int num=0;
00064
00065 fin.getline(buffer,100,'\n');
00066 std::istringstream stringBuf(buffer);
00067 stringBuf>>IsAddEffi;
00068
00069 fin.getline(buffer,100,'\n');
00070
00071 if(!fin){
00072 G4cout<<"error opening effi data"<<G4endl;
00073 IsAddEffi = 1.0;
00074 }
00075
00076
00077
00078
00079
00080
00081 while(fin.getline(buffer,100,'\n')){
00082 std::istringstream stringBuf2(buffer);
00083 stringBuf2>>part>>seg>>gap>>strip>>pad>>effi;
00084 m_effi[part][seg][gap][strip][pad] = effi;
00085 num++;
00086 }
00087 for(G4int seg=0;seg<8;seg++){
00088 for(G4int strip=0;strip<strip_Max;strip++){
00089 m_effi[1][seg][0][strip][105]=0;
00090 }
00091 }
00092
00093
00094 }
00095
00096 void BesMucEfficiency::CheckCalibSvc()
00097 {
00098
00099 ISvcLocator* svcLocator = Gaudi::svcLocator();
00100
00101 StatusCode sc = svcLocator->service("MucCalibConstSvc", m_ptrCalibSvc, true);
00102
00103 if( sc != StatusCode::SUCCESS){
00104 G4cout<< "Can not use MucCalibConstSvc!" << G4endl;
00105 }
00106
00107 }
00108
00109 void BesMucEfficiency::SetHit(BesMucHit* hit)
00110 {
00111 m_pHit = hit;
00112 G4int part = m_pHit->GetPart();
00113 G4int gap = m_pHit->GetGap();
00114 m_Pos_Hit = m_pHit->GetPosLocal().y();
00115 if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00116 m_Pos_Hit = m_pHit->GetPosLocal().x();
00117 }
00118
00119
00120 BesMucDigit aDigit;
00121 aDigit.SetHit(m_pHit);
00122 m_Strip = aDigit.GetNearestStripNo();
00123
00124 GetPosLengthWidth(aDigit.GetNearestStrip());
00125
00126
00127 }
00128
00129 G4int BesMucEfficiency::GetPad()
00130 {
00131 G4double pad1 = (m_Pos_Hit+m_Length/2-m_Pos_Strip)/m_Width;
00132 G4int pad =G4int(pad1);
00133
00134 if(abs(m_Pos_Hit-m_Pos_Strip)<m_Length/2)
00135 return pad;
00136 else
00137 return -999;
00138
00139 }
00140
00141 G4double BesMucEfficiency::GetEfficiency()
00142 {
00143
00144 G4int part = m_pHit->GetPart();
00145 G4int seg = m_pHit->GetSeg();
00146 G4int gap = m_pHit->GetGap();
00147 G4int strip = m_Strip;
00148 G4int pad = GetPad();
00149
00150 G4double eff = 0;
00151 if( 0 != m_ptrCalibSvc ){
00152 eff = m_ptrCalibSvc->getEff(part, seg, gap, strip);
00153
00154
00155 }
00156 else
00157 {
00158
00159 eff = 0.95;
00160 }
00161
00162 return eff;
00163 }
00164
00165 void BesMucEfficiency::GetPosLengthWidth(G4VPhysicalVolume* pvStrip)
00166 {
00167 m_Pos_Strip = 1.0e38;
00168
00169 G4int part = m_pHit->GetPart();
00170 G4int gap = m_pHit->GetGap();
00171
00172 m_Pos_Strip = pvStrip->GetObjectTranslation().y();
00173 if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00174 m_Pos_Strip = pvStrip->GetObjectTranslation().x();
00175 }
00176
00177 G4String striptype= pvStrip->GetLogicalVolume()->GetSolid()->GetEntityType();
00178
00179 G4Box *temp;
00180 temp = (G4Box *)pvStrip->GetLogicalVolume()->GetSolid();
00181 m_Width = temp->GetXHalfLength()*2;
00182 m_Length = temp->GetYHalfLength()*2;
00183 if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00184 m_Width =temp->GetYHalfLength()*2;
00185 m_Length=temp->GetXHalfLength()*2;
00186 }
00187
00188
00189 }