00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "TStandard_Analysis.hh"
00027 #include "TStandard_Analysis_Messenger.hh"
00028
00029
00030
00031
00032
00033 TStandard_Analysis::TStandard_Analysis ( TAlphaRad_DetectorConstruction* theTAlphaRad_DetectorConstruction , TGPS_PrimaryGeneratorAction* theTGPS_PrimaryGeneratorAction )
00034 {
00035
00036 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::TStandard_Analysis() \n" ; }
00037
00038 fTAlphaRad_DetectorConstruction = theTAlphaRad_DetectorConstruction ;
00039 fTGPS_PrimaryGeneratorAction = theTGPS_PrimaryGeneratorAction ;
00040
00041 fTStandard_Analysis_msg = new TStandard_Analysis_Messenger (this) ;
00042
00043
00044
00045 fRootFout = NULL ; fRootFoutName = "" ;
00046 fRootTree = NULL ;
00047
00048 fNCells = fTAlphaRad_DetectorConstruction->GetNCells() ;
00049 fTMyRootEvent = new TMyRootEvent () ;
00050 fTMyRootEvent->InitEvent(fNCells) ;
00051
00052 fRunNumber = -1 ;
00053 fNEvents = -1 ;
00054 fEventNumber = -1 ;
00055 fTimer_tot = new G4Timer () ; fTimer_tot->Start() ;
00056 fTimer_run = new G4Timer () ;
00057
00058
00059
00060 fSDManager = G4SDManager::GetSDMpointer() ;
00061
00062 fCell_HC_ID = new G4int [fNCells] ; for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++) { fCell_HC_ID[cellNumber] = -1 ; }
00063 fCell_HC = new THitsCollection* [fNCells] ; for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++) { fCell_HC [cellNumber] = NULL ; }
00064 fHCE = NULL ;
00065 fHit = NULL ;
00066 fNHits = -1 ;
00067 fTrackID = -1 ;
00068 fTrackIDarray = NULL ;
00069 fDirection_z = G4ThreeVector(0.,0.,1.) ;
00070
00071
00072
00073
00074
00075
00076
00077 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::TStandard_Analysis() \n" ; }
00078
00079 }
00080
00081
00082
00083
00084
00085 TStandard_Analysis::~TStandard_Analysis ()
00086 {
00087
00088 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::~TStandard_Analysis() \n" ; }
00089
00090 fTimer_tot->Stop() ;
00091 fprintf (stdout,"\n\n") ;
00092 fprintf (stdout,"*********************************************\n") ;
00093 fprintf (stdout," >> Total Computing time = %.1f s\n",fTimer_tot->GetRealElapsed()) ;
00094 fprintf (stdout,"*********************************************\n") ;
00095
00096 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::~TStandard_Analysis() \n" ; }
00097
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 void TStandard_Analysis::BeginOfRun ( const G4Run* aRun )
00109 {
00110
00111 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::BeginOfRun() \n" ; }
00112
00113 fTimer_run->Start() ;
00114 fRunNumber = aRun->GetRunID() + 1 ;
00115 fNEvents = aRun->GetNumberOfEventToBeProcessed() ;
00116
00117 if ( fRootFoutName == "" )
00118 {
00119 fRootFoutName = TString(Form("alpharad_%.0e_%s_t=%03dmum_r=%03dmm_sdd=%03dmm.root",
00120 Double_t(fNEvents), TString(fTGPS_PrimaryGeneratorAction->GetGPS()->GetCurrentSource()->GetParticleDefinition()->GetParticleName()).Data(),
00121 Int_t(fTGPS_PrimaryGeneratorAction->GetGPS()->GetCurrentSource()->GetPosDist()->GetHalfZ()/micrometer),
00122 Int_t(fTGPS_PrimaryGeneratorAction->GetGPS()->GetCurrentSource()->GetPosDist()->GetRadius()/mm),
00123 Int_t(fTAlphaRad_DetectorConstruction->GetSourceToDetectorDistance()/mm))) ;
00124 }
00125 fRootFout = new TFile (fRootFoutName,"RECREATE","AlphaRad GEANT4 simulation") ;
00126 if ( fRootFout == NULL ) { G4Exception( G4String("\n!!!\n!!! Error in TDummy_RunAction::BeginOfRunAction(): '" + fRootFoutName + "' cannot be created. \n!!!").data() ) ; }
00127 fRootTree = new TTree ("tree","AlphaRad GEANT4 simulation") ;
00128
00129 fNInitialParticles = new TParameter<long> ("nInitialParticles",fNEvents) ;
00130 fRootTree->GetUserInfo()->Add(fNInitialParticles) ;
00131 fRootTree->Branch("evt","TMyRootEvent",&fTMyRootEvent) ;
00132
00133 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::BeginOfRun() \n" ; }
00134
00135 return ;
00136
00137 }
00138
00139
00140
00141
00142
00143 void TStandard_Analysis::EndOfRun ( const G4Run* aRun )
00144 {
00145
00146 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::EndOfRun() \n" ; }
00147
00148 fRootTree->Write() ;
00149 fRootFout->Close() ;
00150
00151 fTimer_run->Stop() ;
00152 fprintf (stdout,"\n\n###########################################################################################################################################") ;
00153 fprintf (stdout,"\n#") ;
00154 fprintf (stdout,"\n# Simulation successful (See file '%s', running time = %.1f s) ",fRootFoutName.Data(),fTimer_run->GetRealElapsed()) ;
00155 fprintf (stdout,"\n#") ;
00156 fprintf (stdout,"\n###########################################################################################################################################\n\n") ;
00157
00158 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::EndOfRun() \n" ; }
00159
00160 return ;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 void TStandard_Analysis::BeginOfEvent ( const G4Event* aEvent )
00172 {
00173
00174 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::BeginOfEvent() \n" ; }
00175
00176 fEventNumber = aEvent->GetEventID()+1 ;
00177
00178 if ( ( fEventNumber%1000 ) == 0 ) { fprintf (stdout,"*** Event %010ld/%010ld \n",fEventNumber,fNEvents) ; }
00179
00180 for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++)
00181 {
00182 fCell_HC_ID[cellNumber] = fSDManager->GetCollectionID( fTAlphaRad_DetectorConstruction->GetSDName(cellNumber) + "/" + fTAlphaRad_DetectorConstruction->GetSDName(cellNumber) + "_HC" ) ;
00183 }
00184
00185 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::BeginOfEvent() \n" ; }
00186
00187 return ;
00188
00189 }
00190
00191
00192
00193
00194
00195 void TStandard_Analysis::EndOfEvent ( const G4Event* aEvent )
00196 {
00197
00198 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::EndOfEvent() \n" ; }
00199
00200
00201
00202 fHCE = aEvent->GetHCofThisEvent() ;
00203 if ( fHCE != NULL ) {
00204 for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++) {
00205 if ( fCell_HC_ID [cellNumber] != -1 ) { fCell_HC [cellNumber] = (THitsCollection*) (fHCE->GetHC(fCell_HC_ID [cellNumber])) ; }
00206 }
00207 }
00208
00209
00210
00211 fTrackID = -1 ;
00212 fTrackIDarray = new std::vector<G4int> ;
00213
00214 for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++)
00215 {
00216 if ( fCell_HC[cellNumber] != NULL )
00217 {
00218 fNHits = fCell_HC[cellNumber]->entries() ;
00219 for (G4int hitNumber=0; hitNumber<fNHits; hitNumber++)
00220 {
00221 fHit = (*fCell_HC[cellNumber])[hitNumber] ;
00222 if ( !binary_search(fTrackIDarray->begin(),fTrackIDarray->end(),fHit->GetTrackID()) ) { fTrackID = fHit->GetTrackID() ; fTrackIDarray->push_back(fTrackID) ; }
00223 }
00224 }
00225 }
00226
00227
00228 fTMyRootEvent->SetNParticlesPerEvent(fTrackIDarray->size()) ;
00229
00230
00231
00232 for (unsigned ppe=0; ppe<fTrackIDarray->size() ; ppe++)
00233 {
00234 for (G4int cellNumber=0; cellNumber<fNCells; cellNumber++)
00235 {
00236 fTMyRootEvent->SetVolumeName(cellNumber,TString(fTAlphaRad_DetectorConstruction->GetSDName(cellNumber).data())) ;
00237 if ( fCell_HC[cellNumber] != NULL )
00238 {
00239 fNHits = fCell_HC[cellNumber]->entries() ;
00240 fNHitsPerParticlePerCell = 0 ; fEdep_cumul = 0. ; fDose_cumul = 0. ; fRangeTot_cumul = 0. ; fRangeProj_cumul = 0. ; fRangeProjZ_cumul = 0. ;
00241 for (G4int hitNumber=0; hitNumber<fNHits; hitNumber++)
00242 {
00243 fHit = (*fCell_HC[cellNumber])[hitNumber] ;
00244 if ( fHit->GetTrackID() == fTrackIDarray->at(ppe) )
00245 {
00246
00247 fNHitsPerParticlePerCell ++ ;
00248 if ( fNHitsPerParticlePerCell == 1 ) {
00249
00250 fTMyRootEvent->SetEventNumber (fEventNumber) ;
00251 fTMyRootEvent->SetParticleName ( fHit->GetParticleName () ) ;
00252 fTMyRootEvent->SetZ ( fHit->GetZ () ) ;
00253 fTMyRootEvent->SetA ( fHit->GetA () ) ;
00254 fTMyRootEvent->SetTrackID ( fHit->GetTrackID () ) ;
00255 fTMyRootEvent->SetParentTrackID ( fHit->GetParentTrackID () ) ;
00256 fTMyRootEvent->SetCreatorProcessName ( fHit->GetCreatorProcessName () ) ;
00257 fTMyRootEvent->SetEkin0 ( fHit->GetEkin0 ()/MeV ) ;
00258 fTMyRootEvent->SetRx0 ( fHit->GetRx0 ()/um ) ;
00259 fTMyRootEvent->SetRy0 ( fHit->GetRy0 ()/um ) ;
00260 fTMyRootEvent->SetRz0 ( fHit->GetRz0 ()/um ) ;
00261 fTMyRootEvent->SetTheta0 ( fHit->GetTheta0 ()/deg ) ;
00262 fTMyRootEvent->SetPhi0 ( fHit->GetPhi0 ()/deg ) ;
00263
00264 fTMyRootEvent->SetEkin (cellNumber, fHit->GetEkin ()/MeV ) ;
00265 fTMyRootEvent->SetRx (cellNumber, fHit->GetRx ()/um ) ;
00266 fTMyRootEvent->SetRy (cellNumber, fHit->GetRy ()/um ) ;
00267 fTMyRootEvent->SetRz (cellNumber, fHit->GetRz ()/um ) ;
00268 fTMyRootEvent->SetTheta (cellNumber, fHit->GetTheta ()/deg ) ;
00269 fTMyRootEvent->SetPhi (cellNumber, fHit->GetPhi ()/deg ) ;
00270 fTMyRootEvent->SetGlobalTime (cellNumber, fHit->GetGlobalTime () ) ;
00271 fTMyRootEvent->SetLocalTime (cellNumber, fHit->GetLocalTime () ) ;
00272 fTMyRootEvent->SetWeight (cellNumber, fHit->GetWeight () ) ;
00273 fDirection_ref = fHit->GetDirection() ;
00274 }
00275
00276 fEdep = fHit->GetEdep () ; fEdep_cumul += fEdep ;
00277 fDose = fHit->GetDose () ; fDose_cumul += fDose ;
00278 fRangeTot = fHit->GetRangeTot() ; fRangeTot_cumul += fRangeTot ;
00279 fRangeProj = fRangeTot*( (fHit->GetDirection()*fDirection_ref) / (fHit->GetDirection().mag()*fDirection_ref.mag()) ) ; fRangeProj_cumul += fRangeProj ;
00280 fRangeProjZ = fRangeTot*( (fHit->GetDirection()*fDirection_z ) / (fHit->GetDirection().mag()*fDirection_z.mag() ) ) ; fRangeProjZ_cumul += fRangeProjZ ;
00281
00282
00283
00284
00285 }
00286 }
00287 fTMyRootEvent->SetEdep (cellNumber, fEdep_cumul /MeV ) ;
00288 fTMyRootEvent->SetDose (cellNumber, fDose_cumul /gray ) ;
00289 fTMyRootEvent->SetRangeTot (cellNumber, fRangeTot_cumul /um ) ;
00290 fTMyRootEvent->SetRangeProj (cellNumber, fRangeProj_cumul /um ) ;
00291 fTMyRootEvent->SetRangeProjZ (cellNumber, fRangeProjZ_cumul /um ) ;
00292
00293
00294
00295
00296 fTMyRootEvent->SetNHits (cellNumber, fNHitsPerParticlePerCell) ;
00297
00298
00299 }
00300 }
00301 fRootTree->Fill() ;
00302 fTMyRootEvent->ClearEvent() ;
00303 }
00304
00305
00306 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::EndOfEvent() \n" ; }
00307
00308 return ;
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 void TStandard_Analysis::Stepping ( const G4Step* aStep )
00320 {
00321
00322 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::Stepping() \n" ; }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::Stepping() \n" ; }
00373
00374 return ;
00375
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 void TStandard_Analysis::SetRootFileName ( G4String aFileName )
00387 {
00388
00389 if (gMyDebug) { G4cout << "\n### In TStandard_Analysis::Stepping() \n" ; }
00390
00391 fRootFoutName = aFileName ;
00392
00393 if (gMyDebug) { G4cout << "\n### Out of TStandard_Analysis::SetRootFileName() \n" ; }
00394
00395 return ;
00396
00397 }