Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00041
00042 using namespace std;
00043
00044
00045
00046
00047
00048
00049
00050 GT_SD::GT_SD( G4String name ) : G4VSensitiveDetector( name ) {
00051
00052
00053
00054 collectionName.insert( "GT_HC" );
00055
00056
00057
00058 GT_Messenger::Instance()->setGT_SDptr( this );
00059
00060
00061
00062 GT_threshold = 1.0 * eV;
00063 GT_Xresol = 100.0 * um;
00064 GT_Yresol = 100.0 * um;
00065
00066
00067
00068 for( int i = 0; i < N_GT; ++i ) GT_Transform[i] = false;
00069 }
00070
00071
00072
00073 GT_SD::~GT_SD(){}
00074
00075
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
00089
00090 G4bool GT_SD::ProcessHits( G4Step * step, G4TouchableHistory * ROhist ) {
00091
00092
00093
00094 G4double edep = step->GetTotalEnergyDeposit();
00095
00096
00097
00098 if( edep < GT_threshold ) return false;
00099
00100
00101
00102 G4StepPoint * prestep = step->GetPreStepPoint();
00103
00104 G4TouchableHandle touchable = prestep->GetTouchableHandle();
00105
00106
00107
00108 G4int copyno = touchable->GetCopyNumber();
00109
00110
00111
00112 G4Track * track = step->GetTrack();
00113
00114
00115
00116 G4double time = prestep->GetGlobalTime();
00117 G4int tr = track->GetTrackID();
00118
00119
00120
00121 G4ThreeVector trueworld = prestep->GetPosition();
00122
00123
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
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
00143
00144 GT_Hit * hit = new GT_Hit();
00145
00146
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
00158
00159 GT_HC->insert( hit );
00160
00161 return true;
00162 }
00163
00164
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
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
00216
00217 G4double GT_SD::setThreshold( G4double thres ) { return GT_threshold = thres; }
00218 G4double GT_SD::getThreshold() { return GT_threshold; }
00219
00220
00221
00222 G4double GT_SD::setXresol( G4double res ) { return GT_Xresol = res; }
00223 G4double GT_SD::getXresol() { return GT_Xresol; }
00224
00225
00226
00227 G4double GT_SD::setYresol( G4double res ) { return GT_Yresol = res; }
00228 G4double GT_SD::getYresol() { return GT_Yresol; }