GT_SD.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for Gem_Tracker sensitive detector class.
00004 //!
00005 //! The GT_SD class defines the member functions for processing the hit
00006 //! information whenever a hit is simulated in the detector.  These
00007 //! routines initialise the hit collection, process hits, and perform
00008 //! the end of event action which fills the hit information arrays.
00009 //!
00010 //! \author D.K. Hasell
00011 //! \version 1.0
00012 //! \date 2010-10-15
00013 //!
00014 //! \ingroup detector
00015 
00016 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00017 
00018 // Include the GT header files and the user header files referenced here.
00019 
00020 #include "GT_SD.h"
00021 #include "GT_Hit.h"
00022 #include "GT_Data.h"
00023 #include "GT_Messenger.h"
00024 
00025 #include "EventAction.h"
00026 
00027 // Include the GEANT4 header files referenced in this file.
00028 
00029 #include "G4VSensitiveDetector.hh"
00030 #include "G4HCofThisEvent.hh"
00031 #include "G4SDManager.hh"
00032 #include "G4Step.hh"
00033 #include "G4TouchableHistory.hh"
00034 #include "G4StepPoint.hh"
00035 #include "G4TouchableHandle.hh"
00036 #include "G4ThreeVector.hh"
00037 
00038 #include "Randomize.hh"
00039 
00040 // Use the standard namespace.
00041 
00042 using namespace std;
00043 
00044 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00045 
00046 // GT_SD source code.
00047 
00048 // Constructor.
00049 
00050 GT_SD::GT_SD( G4String name ) : G4VSensitiveDetector( name ) {
00051 
00052    // Insert hits collection name.
00053 
00054    collectionName.insert( "GT_HC" );
00055 
00056    // Create pointer to GT_SD Messenger.
00057 
00058    GT_Messenger::Instance()->setGT_SDptr( this );
00059 
00060    // Set defaults.
00061 
00062    GT_threshold =   1.0 * eV;
00063    GT_Xresol    = 100.0 * um;
00064    GT_Yresol    = 100.0 * um;
00065 
00066    // Initially transformations are not defined so Boolean is false.
00067 
00068    for( int i = 0; i < N_GT; ++i ) GT_Transform[i] = false;
00069 }
00070 
00071 // Destructor.
00072 
00073 GT_SD::~GT_SD(){}
00074 
00075 // Initialize hits collection.
00076 
00077 void GT_SD::Initialize( G4HCofThisEvent * HCE ) {
00078 
00079    GT_HC = new GT_HitsCollection( SensitiveDetectorName, collectionName[0] ); 
00080 
00081    static G4int HCID = -1;
00082    if( HCID < 0 ) HCID = G4SDManager::GetSDMpointer()->
00083                      GetCollectionID(collectionName[0]);
00084 
00085    HCE->AddHitsCollection( HCID, GT_HC );
00086 }
00087 
00088 // Process hits.
00089 
00090 G4bool GT_SD::ProcessHits( G4Step * step, G4TouchableHistory * ROhist ) {
00091 
00092    // Get the total energy deposited in this step.
00093 
00094    G4double edep = step->GetTotalEnergyDeposit();
00095 
00096    // Skip this hit if below threshold.
00097 
00098    if( edep < GT_threshold ) return false;
00099 
00100    // Get the PreStepPoint and TouchableHandle.
00101 
00102    G4StepPoint * prestep = step->GetPreStepPoint();
00103 
00104    G4TouchableHandle touchable = prestep->GetTouchableHandle();
00105 
00106    // Get copy number (used to identify which GT).
00107 
00108    G4int copyno = touchable->GetCopyNumber();
00109 
00110    // Get the track.
00111 
00112    G4Track * track = step->GetTrack();
00113 
00114    // Get the global time and track ID.
00115 
00116    G4double time = prestep->GetGlobalTime();
00117    G4int tr = track->GetTrackID();
00118 
00119    // Get the true world and local coordinate positions.
00120 
00121    G4ThreeVector trueworld = prestep->GetPosition();
00122 
00123    // If this first time for this detector store transformation and inverse.
00124 
00125    if( !GT_Transform[copyno] ) {
00126       GT_WorldtoLocal[copyno] = touchable->GetHistory()->GetTopTransform();
00127       GT_LocaltoWorld[copyno] = GT_WorldtoLocal[copyno].Inverse();
00128       GT_Transform[copyno] = true;
00129    }
00130 
00131    G4ThreeVector truelocal = GT_WorldtoLocal[copyno].TransformPoint(trueworld);
00132 
00133    // Create local and world coordinates smeared by resolution.
00134 
00135    G4ThreeVector local(
00136       truelocal.x() + CLHEP::RandGauss::shoot( 0.0, GT_Xresol ),
00137       truelocal.y() + CLHEP::RandGauss::shoot( 0.0, GT_Yresol ),
00138       truelocal.z() );
00139 
00140    G4ThreeVector world = GT_LocaltoWorld[copyno].TransformPoint(local);
00141 
00142    // Create a pointer to a new Hit.
00143 
00144    GT_Hit * hit = new GT_Hit();
00145 
00146    // Fill the Hit information.
00147 
00148    hit->copyno  = copyno;
00149    hit->trackid = tr;
00150    hit->edep    = edep;
00151    hit->time    = time;
00152    hit->tworld  = trueworld;
00153    hit->tlocal  = truelocal;
00154    hit->world   = world;
00155    hit->local   = local;
00156 
00157    // Add the Hit to the Hit Collection.
00158 
00159    GT_HC->insert( hit );
00160    
00161    return true;
00162 }
00163 
00164 // Routine to process the hits at the end of an event.
00165 
00166 void GT_SD::EndOfEvent( G4HCofThisEvent * HCE ){
00167 
00168    GT_Data * gtdata = EventAction::gtdata;
00169 
00170    gtdata->Reset();
00171 
00172    G4int N_Hits = GT_HC->entries();
00173    
00174    gtdata->nGT = N_Hits;
00175 
00176    for( G4int i = 0; i < N_Hits; ++i ) {
00177 
00178       gtdata->id.push_back( ( *GT_HC )[i]->copyno );
00179       gtdata->tr.push_back( ( *GT_HC )[i]->trackid );
00180 
00181       gtdata->e.push_back( ( *GT_HC )[i]->edep / eV );
00182       gtdata->t.push_back( ( *GT_HC )[i]->time / ns );
00183 
00184       gtdata->tx.push_back( ( *GT_HC )[i]->tworld.x() / cm );
00185       gtdata->ty.push_back( ( *GT_HC )[i]->tworld.y() / cm );
00186       gtdata->tz.push_back( ( *GT_HC )[i]->tworld.z() / cm );
00187 
00188       gtdata->txl.push_back( ( *GT_HC )[i]->tlocal.x() / cm );
00189       gtdata->tyl.push_back( ( *GT_HC )[i]->tlocal.y() / cm );
00190       gtdata->tzl.push_back( ( *GT_HC )[i]->tlocal.z() / cm );
00191 
00192       gtdata->x.push_back( ( *GT_HC )[i]->world.x() / cm );
00193       gtdata->y.push_back( ( *GT_HC )[i]->world.y() / cm );
00194       gtdata->z.push_back( ( *GT_HC )[i]->world.z() / cm );
00195 
00196       gtdata->xl.push_back( ( *GT_HC )[i]->local.x() / cm );
00197       gtdata->yl.push_back( ( *GT_HC )[i]->local.y() / cm );
00198       gtdata->zl.push_back( ( *GT_HC )[i]->local.z() / cm );
00199    }
00200 
00201 }
00202 
00203 void GT_SD::clear(){} 
00204 
00205 void GT_SD::DrawAll() {} 
00206 
00207 // Print all the hits.
00208 
00209 void GT_SD::PrintAll() {
00210    G4int N_Hits = GT_HC->entries();
00211    G4cout << "\nGT Hits Collection N_Hits = " << N_Hits << "\n" << G4endl; 
00212    for ( G4int i = 0; i < N_Hits; ++i ) ( *GT_HC )[i]->Print();
00213 } 
00214 
00215 // Set/Get energy threshold.
00216 
00217 G4double GT_SD::setThreshold( G4double thres ) { return GT_threshold = thres; }
00218 G4double GT_SD::getThreshold() { return GT_threshold; }
00219 
00220 // Set/Get X resolution.
00221 
00222 G4double GT_SD::setXresol( G4double res ) { return GT_Xresol = res; }
00223 G4double GT_SD::getXresol() { return GT_Xresol; }
00224 
00225 // Set/Get Y resolution.
00226 
00227 G4double GT_SD::setYresol( G4double res ) { return GT_Yresol = res; }
00228 G4double GT_SD::getYresol() { return GT_Yresol; }