/home/cern/BDSIM_new/src/BDSEnergyCounterSD.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 24.7.2002
00004    Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 */
00006 #include "BDSGlobalConstants.hh"
00007 
00008 #include "BDSEnergyCounterSD.hh"
00009 #include "BDSEnergyCounterHit.hh"
00010 #include "G4VPhysicalVolume.hh"
00011 #include "G4LogicalVolume.hh"
00012 #include "G4Track.hh"
00013 #include "G4Step.hh"
00014 #include "G4ParticleDefinition.hh"
00015 #include "G4VTouchable.hh"
00016 #include "G4TouchableHistory.hh"
00017 #include "G4ios.hh"
00018 #include "G4RotationMatrix.hh"
00019 #include "G4ThreeVector.hh"
00020 
00021 #include "G4Navigator.hh"
00022 #include "G4AffineTransform.hh"
00023 
00024 #include "G4RunManager.hh"
00025 
00026 #include<string>
00027 
00028 extern G4int event_number;
00029 extern G4bool verbose;
00030 
00031 BDSEnergyCounterSD::BDSEnergyCounterSD(G4String name)
00032 :G4VSensitiveDetector(name)
00033 {
00034   collectionName.insert("EC_"+name);
00035   nMaxCopy=150;
00036   HitID = new G4int[150];
00037 }
00038 
00039 BDSEnergyCounterSD::~BDSEnergyCounterSD()
00040 {delete [] HitID;}
00041 
00042 void BDSEnergyCounterSD::Initialize(G4HCofThisEvent*HCE)
00043 {
00044   BDSEnergyCounterCollection = new BDSEnergyCounterHitsCollection
00045     (SensitiveDetectorName,collectionName[0]); 
00046   for(G4int i=0; i<nMaxCopy;i++)HitID[i]=-1;
00047 }
00048 
00049 G4bool BDSEnergyCounterSD::ProcessHits(G4Step*aStep,G4TouchableHistory*ROhist)
00050 { 
00051   G4double edep = aStep->GetTotalEnergyDeposit();
00052   G4int partID = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
00053   G4int parentID = aStep->GetTrack()->GetParentID();
00054   G4double enrg;
00055 
00056   if(BDSGlobals->GetStopTracks())
00057     enrg = aStep->GetTrack()->GetTotalEnergy() - aStep->GetDeltaEnergy();
00058   else
00059     enrg = edep;
00060 
00061   if (enrg==0.) return false;      
00062   
00063 
00064   G4int nCopy=aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
00065   if(nCopy>nMaxCopy-1)
00066     {
00067       G4cout<<" BDSEnergyCounterSD: nCopy too large: nCopy="<<nCopy<<
00068         "nMaxCopy="<<nMaxCopy<<" Volume="<<
00069         aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName()<<G4endl;
00070       G4Exception("Killing program in BDSEnergyCounterSD::ProcessHits");
00071     }
00072 
00073   G4double zpos=0.5*(aStep->GetPreStepPoint()->GetPosition().z()
00074                      + aStep->GetPostStepPoint()->GetPosition().z());
00075 
00076   
00077   if(verbose && BDSGlobals->GetStopTracks()) G4cout << "BDSEnergyCounterSD: Current Volume: " << aStep->GetTrack()->GetVolume()->GetName() <<"\tEvent: " << event_number << "\tEnergy: " << enrg/GeV << "GeV\tPosition: " << zpos/m <<"m"<< G4endl;
00078 
00079   if (HitID[nCopy]==-1)
00080     { 
00081       BDSEnergyCounterHit* ECHit= 
00082         new BDSEnergyCounterHit(nCopy,enrg,zpos*enrg,partID,parentID);
00083       HitID[nCopy]= BDSEnergyCounterCollection->insert(ECHit)-1;
00084     }
00085   else
00086     {
00087       (*BDSEnergyCounterCollection)[HitID[nCopy]]-> AddEnergy(enrg);
00088       (*BDSEnergyCounterCollection)[HitID[nCopy]]-> 
00089         AddEnergyWeightedPosition(enrg*zpos);
00090     }
00091   
00092     
00093   if(BDSGlobals->GetStopTracks())
00094     aStep->GetTrack()->SetTrackStatus(fStopAndKill);
00095 
00096   
00097   return true;
00098 }
00099 
00100 void BDSEnergyCounterSD::EndOfEvent(G4HCofThisEvent*HCE)
00101 {
00102   G4int HCID = GetCollectionID(0); 
00103   HCE->AddHitsCollection( HCID, BDSEnergyCounterCollection );
00104 }
00105 
00106 void BDSEnergyCounterSD::clear()
00107 {} 
00108 
00109 void BDSEnergyCounterSD::DrawAll()
00110 {} 
00111 
00112 void BDSEnergyCounterSD::PrintAll()
00113 {} 
00114 

Generated on Wed Mar 5 17:25:22 2008 for BDSIM by  doxygen 1.5.3