/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/BOOST/MucSim/MucSim-00-01-03/src/BesMucEfficiency.cc

Go to the documentation of this file.
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 //  for(G4int part=0;part<3;part++){
00044 //    for(G4int seg=0;seg<8;seg++){ 
00045 //      for(G4int gap=0;gap<gap_Max;gap++){
00046 //      for(G4int strip=0;strip<strip_Max;strip++){
00047 //        for(G4int pad=0;pad<pad_Max;pad++){
00048 //            m_effi[part][seg][gap][strip][pad]=1;
00049 //        }
00050 //      }
00051   //    }
00052   //  }
00053   //}
00054  // G4cout<<"in BesMucEfficiency::Initialize()"<<G4endl;
00055 
00056  // TFile *f=new TFile("muc-effi.root");
00057  // TTree *t1=(TTree*)f->Get("t1");
00058 
00059 
00060     std::ifstream fin(filename);
00061 
00062      char buffer[100];
00063      G4int num=0;
00064 
00065      fin.getline(buffer,100,'\n');  //get info whether add effi or not
00066      std::istringstream stringBuf(buffer);
00067      stringBuf>>IsAddEffi;
00068      //G4cout<<"IsAddEffi ="<<IsAddEffi<<G4endl;
00069      fin.getline(buffer,100,'\n');
00070 
00071     if(!fin){
00072      G4cout<<"error opening effi data"<<G4endl; 
00073      IsAddEffi = 1.0;   // no effi data. set effi = 1.0
00074      }
00075 
00076 //      fin.getline(buffer,100,'\n');
00077 //      std::istringstream stringBuf2(buffer);
00078 //      stringBuf2>>part>>seg>>gap>>strip>>pad;
00079 //      G4cout<<"---------- "<<pad<<endl;
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     //G4cout<<"------------in Effi::init()----  "<<num<<G4endl;
00094 }
00095 
00096 void BesMucEfficiency::CheckCalibSvc()
00097 {
00098  
00099   ISvcLocator* svcLocator = Gaudi::svcLocator();
00100   //IMucCalibConstSvc* m_ptrCalibSvc;
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();     //different from BesMucdigit
00115   if ( (part == 1 && gap%2 != 0) || (part != 1 && gap%2 == 0) ) {
00116     m_Pos_Hit = m_pHit->GetPosLocal().x();
00117   }
00118   
00119   //set m_Strip, m_Pos_Strip, m_Length, m_Width
00120   BesMucDigit aDigit;
00121   aDigit.SetHit(m_pHit);
00122   m_Strip = aDigit.GetNearestStripNo();
00123   //  G4VPhysicalVolume* pvGasChamber = m_pHit->GetVolume();
00124   GetPosLengthWidth(aDigit.GetNearestStrip());
00125 
00126 //  G4cout<<"m_Pos_Hit = "<<m_Pos_Hit<<G4endl;
00127 }
00128 
00129 G4int BesMucEfficiency::GetPad()
00130 {//it will be better to put this function into Class BesMucDigit
00131   G4double pad1 = (m_Pos_Hit+m_Length/2-m_Pos_Strip)/m_Width;
00132   G4int pad =G4int(pad1);
00133   //G4cout<<"---in Effi::GetPad()--- hit: "<<m_Pos_Hit<<" part: "<<m_pHit->GetPart()<<" gap: "<<m_pHit->GetGap()<<"  L: "<<m_Length<<"  strip: "<<m_Pos_Strip<<"  width: "<<m_Width<<" pad: "<<pad<<G4endl;
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    // look up table with (part;seg;gap;m_Strip) 
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                 //G4cout << "Prt: " << part << "\tseg: " << seg << "\tlay: " << gap << "\tstr: " << m_Strip 
00154                 //                       << "\t:" << eff << endl;
00155   }     
00156   else
00157         {       
00158                 //G4cout << "CalibSvc unavailable!" << G4endl;                  
00159                 eff = 0.95;
00160         }       
00161   //G4cout<<part<<"\t"<<seg<<"\t"<<gap<<"\t"<<m_Strip<<"\t"<<eff<<G4endl;
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 //  G4String striplenght= pvStrip->GetLogicalVolume()->GetName();
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   //G4cout<<"in Set  "<<m_Length<<" "<<temp->GetXHalfLength()<<" "<<m_Width<<" "<<m_Pos_Strip<<G4endl;
00188 
00189 }

Generated on Tue Nov 29 23:14:28 2016 for BOSS_7.0.2 by  doxygen 1.4.7