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 "MW_SD.h"
00021 #include "MW_Hit.h"
00022 #include "MW_Data.h"
00023 #include "MW_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 "G4TouchableHandle.hh"
00035 #include "G4StepPoint.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 MW_SD::MW_SD( G4String name ) : G4VSensitiveDetector( name ) {
00051
00052
00053
00054 collectionName.insert( "MW_HC" );
00055
00056
00057
00058 MW_Messenger::Instance()->setMW_SDptr( this );
00059
00060
00061
00062 MW_threshold = 1.0 * eV;
00063 MW_Xresol = 0.1 * cm;
00064 MW_Yresol = 0.1 * cm;
00065
00066
00067
00068 for( int i = 0; i < N_MW; ++i ) MW_Transform[i] = false;
00069 }
00070
00071
00072
00073 MW_SD::~MW_SD(){}
00074
00075
00076
00077 void MW_SD::Initialize( G4HCofThisEvent * HCE ) {
00078
00079 MW_HC = new
00080 MW_HitsCollection( SensitiveDetectorName, collectionName[0] );
00081
00082 static G4int HCID = -1;
00083 if( HCID < 0 ) {
00084 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
00085 }
00086
00087 HCE->AddHitsCollection( HCID, MW_HC );
00088 }
00089
00090
00091
00092 G4bool MW_SD::ProcessHits( G4Step * step, G4TouchableHistory * ROhist ) {
00093
00094
00095
00096 G4double edep = step->GetTotalEnergyDeposit();
00097
00098
00099
00100 if( edep < MW_threshold ) return false;
00101
00102
00103
00104 G4StepPoint * prestep = step->GetPreStepPoint();
00105
00106 G4TouchableHandle touchable = prestep->GetTouchableHandle();
00107
00108
00109
00110 G4int copyno = touchable->GetCopyNumber();
00111
00112
00113
00114 G4Track * track = step->GetTrack();
00115
00116
00117
00118 G4double time = prestep->GetGlobalTime();
00119 G4int id = track->GetTrackID();
00120
00121
00122
00123 G4ThreeVector trueworld = prestep->GetPosition();
00124
00125
00126
00127 if( !MW_Transform[copyno] ) {
00128 MW_WorldtoLocal[copyno] = touchable->GetHistory()->GetTopTransform();
00129 MW_LocaltoWorld[copyno] = MW_WorldtoLocal[copyno].Inverse();
00130 MW_Transform[copyno] = true;
00131 }
00132
00133 G4ThreeVector truelocal = MW_WorldtoLocal[copyno].TransformPoint(trueworld);
00134
00135
00136
00137 G4ThreeVector local(
00138 truelocal.x() + CLHEP::RandGauss::shoot( 0.0, MW_Xresol ),
00139 truelocal.y() + CLHEP::RandGauss::shoot( 0.0, MW_Yresol ),
00140 truelocal.z() );
00141
00142
00143
00144 G4ThreeVector world = MW_LocaltoWorld[copyno].TransformPoint( local );
00145
00146
00147
00148 MW_Hit * hit = new MW_Hit();
00149
00150
00151
00152 hit->copyno = copyno;
00153 hit->trackid = id;
00154 hit->edep = edep;
00155 hit->time = time;
00156 hit->tworld = trueworld;
00157 hit->tlocal = truelocal;
00158 hit->world = world;
00159 hit->local = local;
00160
00161
00162
00163 MW_HC->insert( hit );
00164
00165
00166
00167 return true;
00168 }
00169
00170
00171
00172 void MW_SD::EndOfEvent( G4HCofThisEvent * HCE ){
00173
00174
00175
00176 MW_Data * mwdata = EventAction::mwdata;
00177
00178 mwdata->Reset();
00179
00180 G4int N_Hits = MW_HC->entries();
00181
00182 mwdata->nMW = N_Hits;
00183
00184 for( G4int i = 0; i < N_Hits; ++i ) {
00185
00186 mwdata->id.push_back( ( *MW_HC )[i]->copyno );
00187 mwdata->tr.push_back( ( *MW_HC )[i]->trackid );
00188
00189 mwdata->e.push_back( ( *MW_HC )[i]->edep / eV );
00190 mwdata->t.push_back( ( *MW_HC )[i]->time / ns );
00191
00192 mwdata->tx.push_back( ( *MW_HC )[i]->tworld.x() / cm );
00193 mwdata->ty.push_back( ( *MW_HC )[i]->tworld.y() / cm );
00194 mwdata->tz.push_back( ( *MW_HC )[i]->tworld.z() / cm );
00195
00196 mwdata->txl.push_back( ( *MW_HC )[i]->tlocal.x() / cm );
00197 mwdata->tyl.push_back( ( *MW_HC )[i]->tlocal.y() / cm );
00198 mwdata->tzl.push_back( ( *MW_HC )[i]->tlocal.z() / cm );
00199
00200 mwdata->x.push_back( ( *MW_HC )[i]->world.x() / cm );
00201 mwdata->y.push_back( ( *MW_HC )[i]->world.y() / cm );
00202 mwdata->z.push_back( ( *MW_HC )[i]->world.z() / cm );
00203
00204 mwdata->xl.push_back( ( *MW_HC )[i]->local.x() / cm );
00205 mwdata->yl.push_back( ( *MW_HC )[i]->local.y() / cm );
00206 mwdata->zl.push_back( ( *MW_HC )[i]->local.z() / cm );
00207 }
00208
00209 }
00210
00211 void MW_SD::clear(){}
00212
00213 void MW_SD::DrawAll() {}
00214
00215
00216
00217 void MW_SD::PrintAll() {
00218 G4int N_Hits = MW_HC->entries();
00219 G4cout << "\nMW Hits Collection N_Hits = " << N_Hits << "\n" << G4endl;
00220 for ( G4int i = 0; i < N_Hits; ++i ) (*MW_HC)[i]->Print();
00221 }
00222
00223
00224
00225 G4double MW_SD::setThreshold( G4double thres ) { return MW_threshold = thres; }
00226 G4double MW_SD::getThreshold() { return MW_threshold; }
00227
00228
00229
00230 G4double MW_SD::setXresol( G4double res ) { return MW_Xresol = res; }
00231 G4double MW_SD::getXresol() { return MW_Xresol; }
00232
00233
00234
00235 G4double MW_SD::setYresol( G4double res ) { return MW_Yresol = res; }
00236 G4double MW_SD::getYresol() { return MW_Yresol; }