![]() |
|
|||
File indexing completed on 2025-04-10 08:05:57
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 /// \file G4H1Wrapper.cc 0027 /// \brief This allows statistics compatible with FLUKA. 0028 /// It is fully relying on G4VAnalysisManager's G4H1. 0029 // 0030 // Author: G.Hugo, 08 December 2022 0031 // 0032 // *************************************************************************** 0033 // 0034 // G4H1Wrapper 0035 // 0036 /// This allows event-level statistics. 0037 /// This is necessary IN THIS SPECIFIC CASE ONLY, to be able to compare errors on results 0038 /// with e.g. FLUKA, MCNP, PENELOPE, SERPENT, which all use an event-based error approach. 0039 /// 0040 /// It is fully relying on G4VAnalysisManager's G4H1. 0041 /// Collects info within an event, then flush it to G4VAnalysisManager's G4H1. 0042 // 0043 // *************************************************************************** 0044 0045 #include "G4H1Wrapper.hh" 0046 0047 #include "G4RootAnalysisManager.hh" 0048 0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0050 0051 G4H1Wrapper::G4H1Wrapper(G4VAnalysisManager* const analysisManager, const G4int histoIndex) 0052 : fAnalysisManager(analysisManager), 0053 fHistoIndex(histoIndex), 0054 fHisto(dynamic_cast<G4RootAnalysisManager*>(analysisManager)->GetH1(histoIndex)), 0055 // fAxis(fHisto->axis()), 0056 fNumBins(fHisto->axis().bins()), 0057 fIsSet(false), 0058 fUnderflow(0.), 0059 fOverflow(0.), 0060 fSumSquaredEventTotals(0.), 0061 fSumSquaredEventInRangeTotals(0.) 0062 { 0063 fEventData.assign(fNumBins, 0.); 0064 } 0065 0066 // *************************************************************************** 0067 // Fill data WITHIN THE EVENT. Can be called an arbitrary number of times. 0068 // *************************************************************************** 0069 void G4H1Wrapper::Fill(const G4double abscissaValue, const G4double weight) 0070 { 0071 if (!fIsSet) { 0072 fIsSet = true; 0073 } 0074 0075 const G4int binIndex = fHisto->axis().coord_to_index(abscissaValue); 0076 0077 // underflow 0078 // See external/g4tools/include/tools/histo/axis. 0079 if (binIndex == tools::histo::axis_UNDERFLOW_BIN) { 0080 fUnderflow += weight; 0081 } 0082 // overflow 0083 // See external/g4tools/include/tools/histo/axis. 0084 else if (binIndex == tools::histo::axis_OVERFLOW_BIN) { 0085 fOverflow += weight; 0086 } 0087 // in range 0088 else { 0089 fEventData[binIndex] += weight; 0090 } 0091 } 0092 0093 // *************************************************************************** 0094 // End of event: flush all data collected during the event 0095 // to G4VAnalysisManager's G4H1, then reset event data. 0096 // *************************************************************************** 0097 void G4H1Wrapper::EndOfEvent() 0098 { 0099 // Only do the flush if there was at least one fill during the event. 0100 if (fIsSet) { 0101 G4double eventTotal = 0.; 0102 // FLUSH IN RANGE DATA. 0103 for (G4int binIndex = 0; binIndex < fNumBins; ++binIndex) { 0104 if (fEventData[binIndex] > 0.) { 0105 const G4double binKineticEnergy = fHisto->axis().bin_center(binIndex); 0106 const G4double binEventWeight = fEventData[binIndex]; 0107 fAnalysisManager->FillH1(fHistoIndex, binKineticEnergy, binEventWeight); 0108 eventTotal += binEventWeight; 0109 0110 fEventData[binIndex] = 0.; 0111 } 0112 } 0113 // Also keep track of the event's total (INTEGRAL over abscissa range). 0114 const G4double squaredEventTotal = eventTotal * eventTotal; 0115 fSumSquaredEventInRangeTotals += squaredEventTotal; 0116 fSumSquaredEventTotals += squaredEventTotal; 0117 0118 // FLUSH UNDERFLOW DATA. 0119 if (fUnderflow > 0.) { 0120 fAnalysisManager->FillH1(fHistoIndex, fHisto->axis().lower_edge() - 1., fUnderflow); 0121 fSumSquaredEventTotals += fUnderflow; 0122 fUnderflow = 0.; 0123 } 0124 0125 // FLUSH OVERFLOW DATA. 0126 if (fOverflow > 0.) { 0127 fAnalysisManager->FillH1(fHistoIndex, fHisto->axis().upper_edge() + 1., fOverflow); 0128 fSumSquaredEventTotals += fOverflow; 0129 fOverflow = 0.; 0130 } 0131 0132 fIsSet = false; 0133 } 0134 } 0135 0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |