Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!
The hits maps are created and filled automatically by Geant4 scorers, see eg. basic example B3, then the saved data can be processed and further analysed eg. in the EventAction (B3a) or the Run (B3b) classes.
Hello,
Thank you, mam, I did this. Can you please guide me on generating plot count vs energy?
‘’’ #include “Run.hh” #include “G4SDManager.hh” #include “G4Event.hh” #include “G4THitsMap.hh” #include “Randomize.hh” #include “G4SystemOfUnits.hh” #include “G4AnalysisManager.hh”
namespace B1
{
G4double GEB(G4double energy)
{
// Energy must be in MeV
G4double a = 0.000097789;
G4double b = 0.20498;
G4double c = -0.01999;
G4double fwhm = a + b * std::sqrt(energy + c * energy * energy);
return fwhm;
}
Run::Run()
: G4Run(), fEDepHCID(-1), fEDep(0.)
{
}
void Run::RecordEvent(const G4Event *anEvent)
{
if (fEDepHCID == -1)
fEDepHCID = G4SDManager::GetSDMpointer()->GetCollectionID("NaI/EDep");
auto HCE = anEvent->GetHCofThisEvent();
if (!HCE)
return;
auto analysisManager = G4AnalysisManager::Instance();
auto hitsMap = static_cast<G4THitsMap<G4double> *>(HCE->GetHC(fEDepHCID));
for (const auto &iter : *(hitsMap->GetMap()))
{
auto eDep = *(iter.second);
if (eDep > 0.)
{
analysisManager->FillH1(0, eDep);
G4double eDep_sampled = G4RandGauss::shoot(eDep, GEB(eDep / MeV / (2.35 * MeV)));
analysisManager->FillH1(1, eDep_sampled);
fEDep += eDep;
}
}
G4Run::RecordEvent(anEvent);
}
void Run::Merge(const G4Run *aRun)
{
auto localRun = static_cast<const Run *>(aRun);
fEDep += localRun->fEDep;
G4Run::Merge(aRun);
}
I cannot guess from a piece of your code what you try to do; usage of Geant4 analysis tools is demonstrated in basic examples B4 and B5, as well as in many extended examples.
The extended electromagnetic examples show many use cases of plotting various physics quantities.