Message: Save vectors into Ntuples Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Save vectors into Ntuples 

Forum: Analysis
Date: Jan 08, 08:52
From: <fceraudo>

Hello,

I would like to save a vector (Edep) into a ntuple in Geant4 10.3.03. I use a SensitiveDetector for scoring.

Here is the relevant code.

<RunAction.hh>

class RunAction : public G4UserRunAction
{
public:
  RunAction();
  virtual ~RunAction();

  virtual void BeginOfRunAction(const G4Run*);
  virtual void   EndOfRunAction(const G4Run*);

  std::vector<G4double>& GetEdep() {return fEdep;}

private:
  std::vector<G4double> fEdep;
};

<RunAction.cc>

void RunAction::BeginOfRunAction(const G4Run* run)
{
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

  if (run->GetRunID() == 0) {
    // Creating ntuples
    //
    analysisManager->CreateNtuple("Detector", "Detector hits");
    analysisManager->
      CreateNtupleDColumn("Edep", fEdep);         // column id = 0
    analysisManager->FinishNtuple();
  }
}

<DetectorHit.hh>

class DetectorHit: public G4VHit
{
public:
  DetectorHit();
  virtual ~DetectorHit();
  DetectorHit(const DetectorHit& right);
  const DetectorHit& operator=(const DetectorHit& right);
  int operator==(const DetectorHit& right) const;

  inline void* operator new(size_t);
  inline void  operator delete(void* hit);

  void SetEdepAddr(std::vector<G4double>& EdepAddr) {fEdep = EdepAddr;}
  void AppendEdep(G4double Edep) {fEdep.push_back(Edep);}
  std::vector<G4double> GetEdep() const {return fEdep;}

private:
  std::vector<G4double> fEdep;
};

<DetectorSD.cc>

void DetectorSD::Initialize(G4HCofThisEvent* hce)
{
  fHitsCollection 
    = new DetectorHitsCollection(SensitiveDetectorName,
				 collectionName[0]);

  // Add this collection in hce
  G4int hcID 
    = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
  hce->AddHitsCollection(hcID, fHitsCollection); 

  DetectorHit* newHit = new DetectorHit();
  RunAction* myRun = (RunAction*) G4RunManager::GetRunManager()->GetUserRunAction();
  myRun->GetEdep().clear();
  newHit->SetEdepAddr(myRun->GetEdep());

  fHitsCollection->insert(newHit);
}

G4bool DetectorSD::ProcessHits(G4Step* step,
                                      G4TouchableHistory* /*history*/)
{
  DetectorHit* hit = (*fHitsCollection)[0];
  G4double edep = step->GetTotalEnergyDeposit();
  hit->AppendEdep(edep);

  return true;  
}

void DetectorSD::EndOfEvent(G4HCofThisEvent* /*hce*/)
{
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  DetectorHit* hit = (DetectorHit*)(*fHitsCollection)[0];
  std::vector<G4double> Edep = hit->GetEdep();

  analysisManager->FillNtupleDColumn(0, Edep);
  analysisManager->AddNtupleRow();     
}

<Analysis.hh>

#ifndef Analysis_h
#define Analysis_h 1

#include "g4root.hh"

#endif

If I try to compile the code, I get the following error:

no matching function for call to G4RootAnalysisManager::FillNtupleDColumn(int, std::vector<double>&)
     analysisManager->FillNtupleDColumn(0, Edep);

Could someone please tell me what I am getting wrong?

Thank you very much for your help.

Francesco

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Save vectors into Ntuples   (Ivana Hrivnacova - Jan 09, 04:25)
(_ None: Re: Save vectors into Ntuples   (fceraudo - Jan 11, 08:12)
(_ None: Re: Save vectors into Ntuples   (Ivana Hrivnacova - Jan 14, 02:59)
 Add Message Add Message
to: "Save vectors into Ntuples"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]