Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:34

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software 
0028 // shall cite the following Geant4-DNA collaboration publication:
0029 // Med. Phys. 37 (2010) 4692-4708
0030 // The Geant4-DNA web site is available at http://geant4-dna.org
0031 // 
0032 // If you use this example, please cite the following publication:
0033 // Rad. Prot. Dos. 133 (2009) 2-11
0034 //
0035 #include "RunAction.hh"
0036 
0037 #include "G4UImanager.hh"
0038 #include "G4AnalysisManager.hh"
0039 #include "Randomize.hh"
0040 
0041 RunAction::RunAction(const DetectorConstruction* det) 
0042 :fDetector(det)
0043 {   
0044   fSaveRndm = 0;  
0045   fDose3DDose = nullptr;
0046   fMapVoxels =  nullptr;
0047 }
0048 
0049 RunAction::~RunAction()
0050 {
0051   if (fDose3DDose) delete[] fDose3DDose;
0052   if (fMapVoxels) delete[] fMapVoxels;
0053 }
0054 
0055 void RunAction::BeginOfRunAction(const G4Run*)
0056 {  
0057   // Read phantom - Singleton
0058   CellParameterisation* fMyCellParameterisation = CellParameterisation::Instance(); 
0059   
0060   // Histograms
0061   // Get/create analysis manager
0062   G4cout << "##### Create analysis manager " << "  " << this << G4endl;
0063   
0064   G4AnalysisManager* man = G4AnalysisManager::Instance();
0065   man->SetDefaultFileType("root");
0066   
0067   G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
0068 
0069   // Open an output file
0070   man->OpenFile("microbeam");
0071   man->SetFirstNtupleId(1);
0072 
0073   //Declare ntuples
0074   //
0075   // Create 1st ntuple (id = 1)
0076   //
0077   man->CreateNtuple("ntuple0", "Stopping power");
0078   man->CreateNtupleDColumn("e");
0079   man->CreateNtupleDColumn("sp");
0080   man->FinishNtuple();
0081   //G4cout << "Ntuple-1 created" << G4endl;
0082 
0083   //
0084   // Create 2nd ntuple (id = 2)
0085   //
0086   man->CreateNtuple("ntuple1", "Beam position");
0087   man->CreateNtupleDColumn("x");
0088   man->CreateNtupleDColumn("y");
0089   man->FinishNtuple();
0090   //G4cout << "Ntuple-2 created" << G4endl;
0091 
0092   //
0093   // Create 3rd ntuple (id = 3)
0094   //
0095   man->CreateNtuple("ntuple2", "Range");
0096   man->CreateNtupleDColumn("x");
0097   man->CreateNtupleDColumn("y");
0098   man->CreateNtupleDColumn("z");
0099   man->FinishNtuple();
0100   //G4cout << "Ntuple-3 created" << G4endl;
0101 
0102   //
0103   // Create 4th ntuple (id = 4)
0104   //
0105   man->CreateNtuple("ntuple3", "Doses");
0106   man->CreateNtupleDColumn("doseN");
0107   man->CreateNtupleDColumn("doseC");
0108   man->FinishNtuple();
0109   //G4cout << "Ntuple-4 created" << G4endl;
0110 
0111   //
0112   // Create 5th ntuple (id = 5)
0113   //
0114   man->CreateNtuple("ntuple4", "3D");
0115   man->CreateNtupleDColumn("x");
0116   man->CreateNtupleDColumn("y");
0117   man->CreateNtupleDColumn("z");
0118   man->CreateNtupleDColumn("doseV");
0119   man->FinishNtuple();
0120   //G4cout << "Ntuple-3 created" << G4endl;
0121 
0122   G4cout << "All Ntuples have been created " << G4endl;
0123 
0124   // save Rndm status
0125   if (fSaveRndm > 0)
0126   { 
0127     CLHEP::HepRandom::showEngineStatus();
0128     CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
0129   }
0130  
0131   fNumEvent = 0;
0132   fNbOfHitsGas = 0;
0133     
0134   // ABSORBED DOSES INITIALIZATION
0135   fDoseN = 0;
0136   fDoseC = 0;
0137     
0138   fMassCytoplasm = fDetector->GetMassCytoplasm();
0139   fMassNucleus   = fDetector->GetMassNucleus();
0140   fNbOfPixels = fDetector->GetNbOfPixelsInPhantom();
0141   
0142   fMapVoxels = new G4ThreeVector[fNbOfPixels];
0143   fDose3DDose = new G4double[fNbOfPixels];
0144 
0145   for (G4int i=0; i<fNbOfPixels; i++)
0146   {
0147     fMapVoxels [i]=fMyCellParameterisation->GetVoxelThreeVector(i);
0148     fDose3DDose[i]=0;
0149   }
0150 }
0151 
0152 void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
0153 {     
0154   G4AnalysisManager* man = G4AnalysisManager::Instance();
0155   
0156   // save Rndm status
0157   if (fSaveRndm == 1)
0158   { 
0159     CLHEP::HepRandom::showEngineStatus();
0160     CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
0161   }   
0162   
0163   for (G4int i=0; i<fNbOfPixels; i++) 
0164   {  
0165     if (fDose3DDose[i]>0)
0166     {
0167       G4ThreeVector v;
0168       v = fMapVoxels[i];
0169       man->FillNtupleDColumn(5,0,v.x());
0170       man->FillNtupleDColumn(5,1,v.y());
0171       man->FillNtupleDColumn(5,2,v.z());
0172       man->FillNtupleDColumn(5,3,fDose3DDose[i]);
0173       man->AddNtupleRow(5);
0174     }
0175   }
0176    
0177   G4cout << "-> Total number of particles detected by the gas detector : " << GetNbOfHitsGas() << G4endl;  
0178   G4cout << G4endl;    
0179   
0180   //save histograms      
0181   man->Write();
0182   man->CloseFile();
0183 
0184   // Complete clean-up
0185   man->Clear();
0186 }