Message: Re: Deposited energy incorrectly saved Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Deposited energy incorrectly saved 

Forum: Analysis
Re: Question Deposited energy incorrectly saved
Re: None Re: Deposited energy incorrectly saved (Ivana Hrivnacova)
Date: Jan 24, 09:02
From: <fceraudo>

Here is the relevant code (I think) of my latest attempt.

I use geant4-10-04-patch-02 [MT]. There are a bunch of variables created to fully identify the step, but this time I tried to save the data directly into the Ntuple at each step instead of doing that in the DetectorSD::EndOfEvent, because I was afraid the number of entries could somehow cause memory issues that prevented the data to be saved correctly. However, as I previously mentioned, the results are the same, as long as the file is concerned. I also thought it could be that Geant4 did not save all the Ntuple lines, but I have 16030 lines in the txt file to which I dumped the output and 16030 entries in the Ntuple, so it is not that either...

Please, tell me if this helps.

Francesco

/* DetectorSD.cc */

G4bool DetectorSD::ProcessHits(G4Step* step,
				 G4TouchableHistory* /*history*/)
{  
  // event id
  const G4Event* event =
    G4EventManager::GetEventManager()->GetConstCurrentEvent();
  G4int eventID = event->GetEventID();

  // event energy
  G4double eventEnergy =
    event->GetPrimaryVertex()->GetPrimary()->GetKineticEnergy();

  // track
  G4Track* track = step->GetTrack();

  // track id
  G4int trackID = track->GetTrackID();

  // parent id
  G4int parentID = track->GetParentID();

  // name
  G4String name = track->GetDefinition()->GetParticleName();

  // id
  G4int id = track->GetDefinition()->GetPDGEncoding();

  // energy
  G4double Edep =
    step->GetTotalEnergyDeposit();

  // weight
  G4double W = step->GetPreStepPoint()->GetWeight();

  // path
  G4double l = step->GetStepLength();

  // position
  G4ThreeVector pos = step->GetPreStepPoint()->GetPosition();
  G4double X = pos.x();
  G4double Y = pos.y();
  G4double Z = pos.z();

  // Creation process
  G4String origProcess;
  if (track->GetCreatorProcess() != 0) {
    origProcess = track->GetCreatorProcess()->GetProcessName();
  } else {
    origProcess = "Primary";
  }

  // Step-limiting process
  G4String stepProcess =
    step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();

  fTotEnDep += Edep;
  G4cout << eventID << " " << Edep/keV << " " << fTotEnDep/keV << G4endl;

  fAnalysisManager->FillNtupleIColumn(0, eventID);
  fAnalysisManager->FillNtupleIColumn(1, trackID);
  fAnalysisManager->FillNtupleIColumn(2, parentID);
  fAnalysisManager->FillNtupleSColumn(3, name);
  fAnalysisManager->FillNtupleIColumn(4, id);
  fAnalysisManager->FillNtupleDColumn(5, Edep/keV);
  fAnalysisManager->FillNtupleDColumn(6, l/um);
  fAnalysisManager->FillNtupleDColumn(7, X/um);
  fAnalysisManager->FillNtupleDColumn(8, Y/um);
  fAnalysisManager->FillNtupleDColumn(9, Z/um);
  fAnalysisManager->FillNtupleSColumn(10, origProcess);
  fAnalysisManager->FillNtupleDColumn(11, eventEnergy/keV);
  fAnalysisManager->FillNtupleDColumn(12, W);
  fAnalysisManager->FillNtupleSColumn(13, stepProcess);
  fAnalysisManager->FillNtupleDColumn(14, fTotEnDep/keV);
  fAnalysisManager->AddNtupleRow();  

  return true;
}

/* RunAction.cc */

RunAction::RunAction()
: G4UserRunAction()
{
  // Create analysis manager
  // The choice of analysis technology is done via selectin
  // of a namespace in Analysis.hh
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  analysisManager->SetVerboseLevel(1);
  analysisManager->SetNtupleMerging(true);
  G4cout << "Using " << analysisManager->GetType() 
         << " analysis manager" << G4endl;

  // Creating ntuples
  analysisManager->CreateNtuple("Detector", "Detector hits");
  analysisManager->CreateNtupleIColumn("eventID");  // column id = 0
  analysisManager->CreateNtupleIColumn("trackID");  // column id = 1
  analysisManager->CreateNtupleIColumn("parentID"); // column id = 2
  analysisManager->CreateNtupleSColumn("Name");     // column id = 3
  analysisManager->CreateNtupleIColumn("ID");       // column id = 4
  analysisManager->CreateNtupleDColumn("Edep");     // column id = 5
  analysisManager->CreateNtupleDColumn("L");        // column id = 6
  analysisManager->CreateNtupleDColumn("Xpos");     // column id = 7
  analysisManager->CreateNtupleDColumn("Ypos");     // column id = 8
  analysisManager->CreateNtupleDColumn("Zpos");     // column id = 9
  analysisManager->CreateNtupleSColumn("OrigProcess"); // column id = 10
  analysisManager->CreateNtupleDColumn("eventEnergy"); // column id = 11
  analysisManager->CreateNtupleDColumn("Weight");   // column id = 12
  analysisManager->CreateNtupleSColumn("StepProcess"); // column id = 13
  analysisManager->CreateNtupleDColumn("TotEnDep"); // column id = 14
  analysisManager->FinishNtuple();
}

void RunAction::EndOfRunAction(const G4Run* /*run*/)
{  
  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  analysisManager->Write();
  analysisManager->CloseFile();
}

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

1 None: Re: Deposited energy incorrectly saved   (Ivana Hrivnacova - Jan 25, 07:59)
(_ None: Re: Deposited energy incorrectly saved   (fceraudo - Jan 26, 01:28)
(_ None: Re: Deposited energy incorrectly saved   (Ivana Hrivnacova - Jan 28, 03:02)
 Add Message Add Message
to: "Re: Deposited energy incorrectly saved"

 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 ]