LM_SD.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for Luminosity_Monitor sensitive detector class.
00004 //!
00005 //! The LM_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-31
00013 //!
00014 //! \ingroup detector
00015 
00016 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00017 
00018 // Include the LM header files and the user header files referenced here.
00019 
00020 #include "LM_SD.h"
00021 #include "LM_Hit.h"
00022 #include "LM_Data.h"
00023 #include "LM_Messenger.h"
00024 
00025 #include "EventAction.h"
00026 
00027 // Include the GEANT4 header files used here.
00028 
00029 #include "G4VSensitiveDetector.hh"
00030 #include "G4HCofThisEvent.hh"
00031 #include "G4SDManager.hh"
00032 #include "G4Step.hh"
00033 #include "G4TouchableHistory.hh"
00034 #include "G4TouchableHandle.hh"
00035 #include "G4StepPoint.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 // LM_SD source code.
00047 
00048 LM_SD::LM_SD( G4String name ) : G4VSensitiveDetector( name ) {
00049 
00050    // Insert hits collection name.
00051 
00052    collectionName.insert( "LM_HC" );
00053 
00054    // Create pointer to GT SD Messenger.
00055 
00056    LM_Messenger::Instance()->setLM_SDptr( this );
00057 
00058    // Set defaults.
00059 
00060    LM_threshold = 1.0 * eV;
00061    LM_Xresol = 0.01 * cm;
00062    LM_Yresol = 0.01 * cm;
00063 
00064    // Initially transformations are not defined so Boolean is false.
00065 
00066    for( int i = 0; i < N_LM; ++i ) LM_Transform[i] = false;
00067 }
00068 
00069 // Destructor.
00070 
00071 LM_SD::~LM_SD(){}
00072 
00073 // Initialize hits collection.
00074 
00075 void LM_SD::Initialize( G4HCofThisEvent * HCE ) {
00076 
00077    LM_HC = new
00078       LM_HitsCollection( SensitiveDetectorName, collectionName[0] ); 
00079 
00080    static G4int HCID = -1;   
00081    if( HCID < 0 ) {
00082       HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
00083    }
00084 
00085    HCE->AddHitsCollection( HCID, LM_HC );
00086 }
00087 
00088 // Process hits.
00089 
00090 G4bool LM_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 < LM_threshold ) return false;
00099 
00100    // Get the PreStepPoint and the TouchableHandle.
00101 
00102    G4StepPoint * prestep = step->GetPreStepPoint();
00103 
00104    G4TouchableHandle touchable = prestep->GetTouchableHandle();
00105 
00106    // Get copy number (used to identify which LM).
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 id = track->GetTrackID();
00118 
00119    // Get the true world and local coordinate positions.
00120 
00121    G4ThreeVector trueworld = prestep->GetPosition();
00122 
00123    // If this first time store transformation and inverse.
00124 
00125    if( !LM_Transform[copyno] ) {
00126       LM_WorldtoLocal[copyno] = touchable->GetHistory()->GetTopTransform();
00127       LM_LocaltoWorld[copyno] = LM_WorldtoLocal[copyno].Inverse();
00128       LM_Transform[copyno] = true;
00129    }
00130 
00131    G4ThreeVector truelocal = LM_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, LM_Xresol ),
00137       truelocal.y() + CLHEP::RandGauss::shoot( 0.0, LM_Yresol ),
00138       truelocal.z() );
00139 
00140    G4ThreeVector world = LM_LocaltoWorld[copyno].TransformPoint(local);
00141 
00142    // Create a pointer to a new Hit.
00143 
00144    LM_Hit * hit = new LM_Hit();
00145 
00146    // Fill the Hit information.
00147 
00148    hit->copyno  = copyno;
00149    hit->trackid = id;
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    LM_HC->insert( hit );
00160    
00161    //hit->Print();
00162 
00163    return true;
00164 }
00165 
00166 // Routine to process the hits at the end of an event.
00167 
00168 void LM_SD::EndOfEvent( G4HCofThisEvent * HCE ){
00169 
00170    LM_Data * lmdata = EventAction::lmdata;
00171 
00172    lmdata->Reset();
00173 
00174    G4int N_Hits = LM_HC->entries();
00175    
00176    lmdata->nLM = N_Hits;
00177 
00178    for( G4int i = 0; i < N_Hits; ++i ) {
00179 
00180       lmdata->id.push_back( ( *LM_HC )[i]->copyno );
00181       lmdata->tr.push_back( ( *LM_HC )[i]->trackid );
00182 
00183       lmdata->e.push_back( ( *LM_HC )[i]->edep / eV );
00184       lmdata->t.push_back( ( *LM_HC )[i]->time / ns );
00185 
00186       lmdata->tx.push_back( ( *LM_HC )[i]->tworld.x() / cm );
00187       lmdata->ty.push_back( ( *LM_HC )[i]->tworld.y() / cm );
00188       lmdata->tz.push_back( ( *LM_HC )[i]->tworld.z() / cm );
00189 
00190       lmdata->txl.push_back( ( *LM_HC )[i]->tlocal.x() / cm );
00191       lmdata->tyl.push_back( ( *LM_HC )[i]->tlocal.y() / cm );
00192       lmdata->tzl.push_back( ( *LM_HC )[i]->tlocal.z() / cm );
00193 
00194       lmdata->x.push_back( ( *LM_HC )[i]->world.x() / cm );
00195       lmdata->y.push_back( ( *LM_HC )[i]->world.y() / cm );
00196       lmdata->z.push_back( ( *LM_HC )[i]->world.z() / cm );
00197 
00198       lmdata->xl.push_back( ( *LM_HC )[i]->local.x() / cm );
00199       lmdata->yl.push_back( ( *LM_HC )[i]->local.y() / cm );
00200       lmdata->zl.push_back( ( *LM_HC )[i]->local.z() / cm );
00201    }
00202 
00203 }
00204 
00205 void LM_SD::clear(){} 
00206 
00207 void LM_SD::DrawAll() {} 
00208 
00209 // Print all the hits.
00210 
00211 void LM_SD::PrintAll() {
00212    G4int N_Hits = LM_HC->entries();
00213    G4cout << "\nLM Hits Collection N_Hits = " << N_Hits << "\n" << G4endl; 
00214    for ( G4int i = 0; i < N_Hits; ++i ) (*LM_HC)[i]->Print();
00215 } 
00216 
00217 // Set/Get energy threshold.
00218 
00219 G4double LM_SD::setThreshold( G4double thres ) { return LM_threshold = thres; }
00220 G4double LM_SD::getThreshold() { return LM_threshold; }
00221 
00222 // Set/Get X resolution.
00223 
00224 G4double LM_SD::setXresol( G4double res ) { return LM_Xresol = res; }
00225 G4double LM_SD::getXresol() { return LM_Xresol; }
00226 
00227 // Set/Get Y resolution.
00228 
00229 G4double LM_SD::setYresol( G4double res ) { return LM_Yresol = res; }
00230 G4double LM_SD::getYresol() { return LM_Yresol; }