Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-20 08:04:56

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   auto man = G4AnalysisManager::Instance();
0049   man->SetFirstNtupleId(1);
0050   man->SetDefaultFileType("root");
0051   man->SetNtupleMerging(true);
0052 
0053   //Declare ntuples
0054   //
0055   // Create 1st ntuple (id = 1)
0056   //
0057   man->CreateNtuple("ntuple0", "Stopping power");
0058   man->CreateNtupleDColumn("e");
0059   man->CreateNtupleDColumn("sp");
0060   man->FinishNtuple();
0061   //G4cout << "Ntuple-1 created" << G4endl;
0062 
0063   //
0064   // Create 2nd ntuple (id = 2)
0065   //
0066   man->CreateNtuple("ntuple1", "Beam position");
0067   man->CreateNtupleDColumn("x");
0068   man->CreateNtupleDColumn("y");
0069   man->FinishNtuple();
0070   //G4cout << "Ntuple-2 created" << G4endl;
0071 
0072   //
0073   // Create 3rd ntuple (id = 3)
0074   //
0075   man->CreateNtuple("ntuple2", "Range");
0076   man->CreateNtupleDColumn("x");
0077   man->CreateNtupleDColumn("y");
0078   man->CreateNtupleDColumn("z");
0079   man->FinishNtuple();
0080   //G4cout << "Ntuple-3 created" << G4endl;
0081 
0082   //
0083   // Create 4th ntuple (id = 4)
0084   //
0085   man->CreateNtuple("ntuple3", "Doses");
0086   man->CreateNtupleDColumn("doseN");
0087   man->CreateNtupleDColumn("doseC");
0088   man->FinishNtuple();
0089   //G4cout << "Ntuple-4 created" << G4endl;
0090 
0091   //
0092   // Create 5th ntuple (id = 5)
0093   //
0094   man->CreateNtuple("ntuple4", "3D");
0095   man->CreateNtupleDColumn("x");
0096   man->CreateNtupleDColumn("y");
0097   man->CreateNtupleDColumn("z");
0098   man->CreateNtupleDColumn("doseV");
0099   man->FinishNtuple();
0100   //G4cout << "Ntuple-3 created" << G4endl;
0101 
0102   G4cout << "All Ntuples have been created " << G4endl;
0103 
0104 
0105 }
0106 
0107 RunAction::~RunAction()
0108 {
0109   if (fDose3DDose) delete[] fDose3DDose;
0110   if (fMapVoxels) delete[] fMapVoxels;
0111 }
0112 
0113 void RunAction::BeginOfRunAction(const G4Run*)
0114 {
0115   // Read phantom - Singleton
0116   CellParameterisation* fMyCellParameterisation = CellParameterisation::Instance();
0117 
0118   // Histograms
0119   auto man = G4AnalysisManager::Instance();
0120   man->OpenFile("microbeam");
0121 
0122   // save Rndm status
0123   if (fSaveRndm > 0)
0124   {
0125     CLHEP::HepRandom::showEngineStatus();
0126     CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
0127   }
0128 
0129   fNumEvent = 0;
0130   fNbOfHitsGas = 0;
0131 
0132   // ABSORBED DOSES INITIALIZATION
0133   fDoseN = 0;
0134   fDoseC = 0;
0135 
0136   fMassCytoplasm = fDetector->GetMassCytoplasm();
0137   fMassNucleus   = fDetector->GetMassNucleus();
0138   fNbOfPixels = fDetector->GetNbOfPixelsInPhantom();
0139 
0140   fMapVoxels = new G4ThreeVector[fNbOfPixels];
0141   fDose3DDose = new G4double[fNbOfPixels];
0142 
0143   for (G4int i=0; i<fNbOfPixels; i++)
0144   {
0145     fMapVoxels [i]=fMyCellParameterisation->GetVoxelThreeVector(i);
0146     fDose3DDose[i]=0;
0147   }
0148 }
0149 
0150 void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
0151 {
0152   G4AnalysisManager* man = G4AnalysisManager::Instance();
0153 
0154   // save Rndm status
0155   if (fSaveRndm == 1)
0156   {
0157     CLHEP::HepRandom::showEngineStatus();
0158     CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
0159   }
0160 
0161   for (G4int i=0; i<fNbOfPixels; i++)
0162   {
0163     if (fDose3DDose[i]>0)
0164     {
0165       G4ThreeVector v;
0166       v = fMapVoxels[i];
0167       man->FillNtupleDColumn(5,0,v.x());
0168       man->FillNtupleDColumn(5,1,v.y());
0169       man->FillNtupleDColumn(5,2,v.z());
0170       man->FillNtupleDColumn(5,3,fDose3DDose[i]);
0171       man->AddNtupleRow(5);
0172     }
0173   }
0174 
0175   G4cout << "-> Total number of particles detected by the gas detector : " << GetNbOfHitsGas() << G4endl;
0176   G4cout << G4endl;
0177 
0178   //save histograms
0179   man->Write();
0180   man->CloseFile();
0181 
0182   // Complete clean-up
0183   man->Clear();
0184 }