// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // /// \file analysis/AnaEx02/src/HistoManager.cc /// \brief Implementation of the HistoManager class // // $Id: HistoManager.cc 98060 2016-07-01 16:24:08Z gcosmo $ // GEANT4 tag $Name: geant4-09-04 $ // //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... #include "G4SystemOfUnits.hh" #include "G4PhysicalConstants.hh" #include "HistoManager.hh" #include "G4UnitsTable.hh" #include "EventAction.hh" #include "RunAction.hh" #include "SteppingAction.hh" #include "DetectorConstruction.hh" #include "G4Run.hh" #include "G4RunManager.hh" #include "G4Event.hh" #include "G4Step.hh" #include "G4Track.hh" #include "G4ProcessManager.hh" #include #include #include "G4LogicalVolume.hh" #include //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... using namespace std; //atomic U238number(0),U235number(0); HistoManager::HistoManager(DetectorConstruction*Detector) :fFactoryOn(false),fScoringVolume(0) { } HistoManager::~HistoManager() { } void HistoManager::BeginOfRunAction(const G4Run* aRun) { G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; Book(); time_begin=time(NULL); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void HistoManager::EndOfRunAction(const G4Run* aRun) { Save(); time_curr=time(NULL); G4cout<<"final cost time: "<GetEventID(); if ( evtNb%1000 == 0) { G4cout << "\n---> finish: " << evtNb << G4endl; time_curr=time(NULL); G4cout<<"cost time: "<GetEventID(); if(energy > 0.5) {analysisManager->FillNtupleFColumn(0,0,energy);} analysisManager->AddNtupleRow(0); std:: ofstream EnergyDeposit; EnergyDeposit.open("EnergyDeposit.txt",std::ios::app); if(EnergyDeposit.is_open()) { EnergyDeposit<GetTotalEnergyDeposit()/keV; G4LogicalVolume* fvolume = aStep->GetPreStepPoint()->GetTouchableHandle() ->GetVolume()->GetLogicalVolume(); if (!fScoringVolume) { const DetectorConstruction* detectorConstruction = static_cast (G4RunManager::GetRunManager()->GetUserDetectorConstruction()); fScoringVolume = detectorConstruction->GetScoringVolume(); } if( fvolume == fScoringVolume) { G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); energy=Energy_pre; } } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void HistoManager::Book() { auto analysisManager = G4AnalysisManager ::Instance(); analysisManager->SetVerboseLevel(1); analysisManager->SetNtupleMerging(true); G4String fileName = "AnaEx02.root"; G4bool fRootFile = analysisManager->OpenFile("AnaEx02.root"); if (! fRootFile) { G4cout << " HistoManager::Book :" << " problem creating the ROOT TFile " << G4endl; return; } fFactoryOn = true; analysisManager->CreateNtuple("Ntuple1", "particle"); analysisManager->CreateNtupleFColumn("energy"); analysisManager->FinishNtuple(); G4cout << "\n----> Output file is open in " << fileName << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void HistoManager::Save() { if (! fFactoryOn) return; auto analysisManager = G4AnalysisManager ::Instance(); analysisManager->Write(); analysisManager->CloseFile(); // and closing the tree (and the file) G4cout << "\n----> Histograms and ntuples are saved\n" << G4endl; delete G4AnalysisManager::Instance(); fFactoryOn = false; }