I'm trying to generate hit map but its showing an error

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!

_Geant4 Version:_11.02
_Operating System:_Ubuntu_23
_CMake Version:_3.27

/home/ratilal/B1/src/Run.cc:4:10: fatal error: G4HitsMap.hh: No such file or directory
4 | #include “G4HitsMap.hh”
| ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/exampleB1.dir/build.make:132: CMakeFiles/exampleB1.dir/src/Run.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/exampleB1.dir/all] Error 2
make: *** [Makefile:136: all] Error 2


You have to include G4THitsMap.hh.

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.

Best regards,

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;

    : 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)

    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;

void Run::Merge(const G4Run *aRun)
    auto localRun = static_cast<const Run *>(aRun);
    fEDep += localRun->fEDep;


} // namespace B1



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.

Best regards,