Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LCDG4LumSD.cc

Go to the documentation of this file.
00001 // $Id: LCDG4LumSD.cc,v 1.11 2004/08/17 23:24:03 uid561 Exp $
00002 
00003 #include "LCDG4LumSD.hh"
00004 
00005 #include "G4Step.hh"
00006 #include "G4HCofThisEvent.hh"
00007 #include "G4TouchableHistory.hh"
00008 #include "G4ios.hh"
00009 #include "G4Track.hh"
00010 
00011 /*
00012  * Constructor
00013  */
00014 LCDG4LumSD::LCDG4LumSD(G4String name):G4VSensitiveDetector(name) {
00015   G4String HCname;
00016   collectionName.insert(HCname="lumCollection");
00017   m_cellhitb.clear();
00018   m_cellhite.clear();
00019   m_phiseg  [0]=1; m_phiseg  [1]=1;
00020   m_thetaseg[0]=1; m_thetaseg[1]=1;
00021 }
00022 
00023 /*
00024  * Destructor
00025  */
00026 LCDG4LumSD::~LCDG4LumSD(){
00027 }
00028 
00029 
00030 /*
00031  * Intialize the hit collection for this event
00032  */
00033 void LCDG4LumSD::Initialize(G4HCofThisEvent*HCE) {
00034   static int HCID = -1;
00035   m_lumCollection = new LCDG4CalHitsCollection
00036     (SensitiveDetectorName,collectionName[0]);
00037   if(HCID < 0) {
00038     HCID = GetCollectionID(0);
00039   }
00040   HCE->AddHitsCollection(HCID,m_lumCollection);
00041 }
00042 
00043 
00044 /*
00045  * Process step information into G4 Hit
00046  */
00047 G4bool LCDG4LumSD::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist) {
00048 
00049   G4double edep = aStep->GetTotalEnergyDeposit();
00050 
00051   if(edep==0.) return false;
00052 
00053   const G4VPhysicalVolume* physVol
00054     = aStep->GetPreStepPoint()->GetPhysicalVolume();
00055   if( ROhist!=NULL ) {
00056     G4VPhysicalVolume* phyVol = ROhist->GetVolume();
00057     if(phyVol != physVol) G4cout<<"phy,phys="<< phyVol<<' '<<physVol <<G4endl;
00058   }
00059 
00060   G4LogicalVolume* logVol=physVol->GetLogicalVolume();
00061 
00062   G4Track* mclum = aStep->GetTrack();
00063   G4int    trkID  = mclum->GetTrackID();
00064   G4double tdep   = mclum->GetGlobalTime();
00065   G4int    layno  = m_maplayer[logVol];
00066   G4int    sysNo  = m_mapsys[logVol];
00067   G4int    barend = m_mapbe[logVol];
00068 
00069   G4ThreeVector pos = 0.5*(aStep->GetPreStepPoint()->GetPosition() +
00070                            aStep->GetPostStepPoint()->GetPosition() );
00071   G4double dphi     = 360.0*degree/m_phiseg[barend];
00072   G4double dtheta   = 180.0*degree/m_thetaseg[barend];
00073   G4double trkphi   = pos.phi();
00074   if (trkphi < 0.0) {
00075     trkphi += 360.0*degree;
00076   }
00077   G4double trkthe = pos.theta();
00078   G4int    sphi   = int(trkphi/dphi);
00079   G4int    sthe   = int(trkthe/dtheta);
00080   G4int    icell  = sthe + m_thetaseg[barend]*sphi
00081     + m_thetaseg[barend]*m_phiseg[barend]*layno;
00082 
00083   std::map<G4int,LCDG4CalHit*>* pcellhit=0;
00084   if (barend == 0) {
00085     pcellhit=&m_cellhitb;
00086   } else {
00087     pcellhit=&m_cellhite;
00088   }
00089   LCDG4CalHit *hit=(*pcellhit)[icell];
00090 
00091   if(hit == 0) {
00092     G4double r = pos.mag();
00093     G4ThreeVector hpos(r*sin((sthe+0.5)*dtheta)*cos((sphi+0.5)*dphi),
00094                        r*sin((sthe+0.5)*dtheta)*sin((sphi+0.5)*dphi),
00095                        r*cos((sthe+0.5)*dtheta));
00096 
00097     (*pcellhit).erase(icell);
00098     hit = new LCDG4CalHit();
00099     hit->SetLayer(layno);
00100     hit->SetSystem(sysNo);
00101     hit->SetBarEnd(barend);
00102     hit->SetPhi(sphi);
00103     hit->SetTheta(sthe);
00104     hit->SetPos(hpos);
00105     m_lumCollection->insert(hit);
00106     pcellhit->insert(std::pair<G4int,LCDG4CalHit*>(icell,hit));
00107   }
00108 
00109   if (m_mapsens[logVol]) {
00110     hit->AddMcPart(trkID,edep,tdep);
00111   } else {
00112     hit->AddMcPartAbs(edep);
00113   }
00114   return true;
00115 }
00116 
00117 /*
00118  * EndOfEvent method clear cell hit maps for barrel and endcaps
00119  */
00120 void LCDG4LumSD::EndOfEvent(G4HCofThisEvent*HCE) {
00121   if(HCE) ;  // make compiler happy about unused vars
00122   m_cellhitb.clear();
00123   m_cellhite.clear();
00124 }
00125 
00126 /*
00127  * Clear method, not used
00128  */
00129 void LCDG4LumSD::clear() {
00130 }
00131 
00132 /*
00133  * Draw method, not used
00134  */
00135 void LCDG4LumSD::DrawAll() {
00136 }
00137 
00138 /*
00139  * Print method, not used
00140  */
00141 void LCDG4LumSD::PrintAll() {
00142 }
00143 
00144 /*
00145  * Add layer number, sysNo, barrel/endcap, N/S, and sens info to logical volume maps
00146  */
00147 G4int LCDG4LumSD::AddLogVolInfo
00148 (G4LogicalVolume* g4lumlog,G4int startlayerNo,G4int sysNo,G4int be, G4int ns,
00149  G4int sens) {
00150   m_maplayer.insert(std::pair<G4LogicalVolume*,G4int>(g4lumlog,startlayerNo));
00151   m_mapsys.insert(std::pair<G4LogicalVolume*,G4int>(g4lumlog,sysNo));
00152   m_mapbe.insert(std::pair<G4LogicalVolume*,G4int>(g4lumlog,be));
00153   m_mapns.insert(std::pair<G4LogicalVolume*,G4int>(g4lumlog,ns));
00154   m_mapsens.insert(std::pair<G4LogicalVolume*,G4int>(g4lumlog,sens));
00155   return m_maplayer.size();
00156 }

Generated on Thu Oct 7 18:44:46 2004 for LCDG4 by doxygen 1.3.4