00001 //---------------------------------------------------------------------------// 00002 // BOOST --- BESIII Object_Oreiented Simulation Tool // 00003 //---------------------------------------------------------------------------// 00004 //Descpirtion: EMC detector 00005 //Author: Fu Chengdong 00006 //Created: Dec 15, 2003 00007 //Comment: 00008 //---------------------------------------------------------------------------// 00009 // 00010 #include "BesEmcDigitization.hh" 00011 #include "BesEmcHit.hh" 00012 00013 #include "G4Event.hh" 00014 #include "G4EventManager.hh" 00015 #include "G4HCofThisEvent.hh" 00016 #include "G4VHitsCollection.hh" 00017 #include "G4SDManager.hh" 00018 #include "G4ios.hh" 00019 #include "G4UnitsTable.hh" 00020 00021 BesEmcDigitization::BesEmcDigitization() 00022 :calorimeterCollID(-1),fNHits(0),fTotECrystal(0),fTotLCrystal(0), 00023 fNCrystalSignal(0) 00024 { 00025 for(int i=0;i<50;i++) 00026 {for(int j=0;j<150;j++) 00027 fSingleECrystal[i][j]=0; 00028 } 00029 G4SDManager * SDman = G4SDManager::GetSDMpointer(); 00030 calorimeterCollID= SDman->GetCollectionID("CalCollection"); 00031 } 00032 00033 BesEmcDigitization::~BesEmcDigitization() 00034 { 00035 delete[]fEnergySignal; 00036 delete[]fNThetaSignal; 00037 delete[]fNPhiSignal; 00038 } 00039 00040 G4bool BesEmcDigitization::Digitize(const G4Event* evt, G4double ecut) 00041 { 00042 G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); 00043 BesEmcHitsCollection* CHC = 0; 00044 00045 if (HCE) 00046 CHC = (BesEmcHitsCollection*)(HCE->GetHC(calorimeterCollID)); 00047 else 00048 return false; 00049 00050 G4int i=0,j=0; 00051 if (CHC) 00052 { 00053 fNHits = CHC->entries(); 00054 if(fNHits) 00055 for (i=0;i<fNHits;i++) 00056 { 00057 fTotECrystal += (*CHC)[i]->GetEdepCrystal(); 00058 fTotLCrystal += (*CHC)[i]->GetTrakCrystal(); 00059 G4int nTheta=45-(*CHC)[i]->GetNumThetaCrystal(); 00060 G4int nPhi =(*CHC)[i]->GetNumPhiCrystal(); 00061 if(nTheta>0&&nTheta<50&&nPhi>0&&nPhi<150)//waiting upgrade 00062 { 00063 fSingleECrystal[nTheta][nPhi]+=(*CHC)[i]->GetEdepCrystal(); 00064 //G4cout << "EMC Hit in crystal(" 00065 // << nTheta << "," <<nPhi<< ")" << G4endl; 00066 } 00067 else 00068 { 00069 G4cout << "EMC Hit out range:" 00070 << nTheta <<','<< nPhi << G4endl; 00071 } 00072 } 00073 } 00074 else 00075 return false; 00076 00077 for(i=1;i<50;i++) 00078 {for(j=1;j<150;j++) 00079 { 00080 if(fSingleECrystal[i][j]>ecut) 00081 { 00082 fNCrystalSignal++; 00083 } 00084 } 00085 } 00086 if((fEnergySignal=new G4double[fNCrystalSignal+1])==NULL|| 00087 (fNThetaSignal=new G4int[fNCrystalSignal+1])==NULL|| 00088 (fNPhiSignal=new G4int[fNCrystalSignal+1])==NULL) 00089 { 00090 G4Exception("BesEmcDigitization:can't allocate memory for Signal"); 00091 } 00092 G4int n=0; 00093 for(i=1;i<50;i++) 00094 {for(j=1;j<150;j++) 00095 { 00096 if(fSingleECrystal[i][j]>ecut) 00097 { 00098 n++; 00099 fEnergySignal[n]=fSingleECrystal[i][j]; 00100 fNThetaSignal[n]=45-i; 00101 fNPhiSignal [n]=j; 00102 } 00103 } 00104 } 00105 00106 return true; 00107 } 00108 00109 G4double BesEmcDigitization::GetEmcSignal(G4int nTheta, G4int nPhi) 00110 { 00111 if(nTheta>0&&nTheta<50&&nPhi>0&&nPhi<150) 00112 return fSingleECrystal[nTheta][nPhi]; 00113 else 00114 return 0; 00115 } 00116 00117 void BesEmcDigitization::Print() 00118 { 00119 G4cout 00120 << " Absorber: total energy: " 00121 << fTotECrystal/GeV << " GeV" << G4endl 00122 << " total track length: " 00123 << fTotLCrystal/cm << " cm" << G4endl; 00124 00125 G4cout << "\n " << fNHits 00126 << " hits are stored in BesEmcHitsCollection." << G4endl; 00127 }