Message: Re: FillNtupleDColumn Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: FillNtupleDColumn 

Forum: Analysis
Re: Question FillNtupleDColumn (sergi)
Re: None Re: FillNtupleDColumn (Ivana Hrivnacova)
Date: 15 May, 2013
From: sergi <sergi>

Dear Ivana,

Thank you very much for your quick response and for your interest. Finally I used a "for" command in order to fill the Ntuple but I don't know if there are an easy way to do it. I have attached my Sensitive Detector class (newSD), my EventAction class (newEventAction) and my RunAction class (newRunAction).

---------------------------newSD.cc class

newSD::newSD( const G4String& name, const G4String& hitsCollectionName)
  : G4VSensitiveDetector(name),fHitsCollection(NULL)

{collectionName.insert(hitsCollectionName);}

newSD::~newSD() {}

void newSD::Initialize(G4HCofThisEvent* hce) {

fHitsCollection = new newHitsCollection(SensitiveDetectorName,collectionName[0]);

G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);

hce->AddHitsCollection( hcID, fHitsCollection ); }

G4bool newSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {

if((aStep->GetTrack()->GetDynamicParticle()->GetDefinition()->GetParticleName())=="alpha")
    {

  G4double edep = aStep->GetTotalEnergyDeposit(); 

  newHit* newhit= new newHit();

  newhit->SetEdep(edep);

  fHitsCollection->insert(newhit);

  return true;
    }

}

void newSD::EndOfEvent(G4HCofThisEvent*) {}

------------------- newEventAction.cc class

newEventAction::newEventAction()
  :G4UserEventAction(),fPrintModulo(1000)

 {}

newEventAction::~newEventAction() {}

void newEventAction::BeginOfEventAction(const G4Event* event) {

  G4int eventID = event->GetEventID();
  if ( eventID % fPrintModulo == 0 )  { 
    G4cout << "\n---> Begin of event: " << eventID << G4endl;

  }}

void newEventAction::EndOfEventAction(const G4Event* event)
{  
  //de N05

  G4SDManager * SDman = G4SDManager::GetSDMpointer();
  G4String colNam;
  SilicioCollID    = SDman->GetCollectionID(colNam="SilicioHitsCollection");
  TrenchesCollID = SDman->GetCollectionID(colNam="TrenchesHitsCollection");

   G4cout << ">>> Event " << event->GetEventID() << G4endl;

  G4HCofThisEvent * hce = event->GetHCofThisEvent();
  newHitsCollection* SiliHC    = 0;
  newHitsCollection* TrenHC = 0;

 if(hce)
    {
      SiliHC    = (newHitsCollection*)(hce->GetHC(SilicioCollID));
      TrenHC = (newHitsCollection*)(hce->GetHC(TrenchesCollID));
    }

  if(SiliHC)
    {
      int n_hit = SiliHC->entries();
      G4cout << "     " << n_hit
           << " hits are stored in Silicio" << G4endl;
      G4double totE = 0;
      for(int i=0;i<n_hit;i++)
        { totE += (*SiliHC)[i]->GetEdep(); }
      G4cout << "     Total energy deposition in Silicio : "
           << totE / GeV << " (GeV)" << G4endl;

    }

if(TrenHC)
    {
      int n_hit = TrenHC->entries();
      G4cout << "     " << n_hit
           << " hits are stored in boron' trenches" << G4endl;
      G4double totE = 0;
      for(int i=0;i<n_hit;i++)
        { totE += (*TrenHC)[i]->GetEdep(); }
      G4cout << "     Total energy deposition in boron's trenches : "
           << totE / GeV << " (GeV)" << G4endl;
    }

  // Fill ntuple

  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

  analysisManager->FillNtupleDColumn(0, SiliHC->entries());
  analysisManager->FillNtupleDColumn(1, TrenHC->entries());

 int n_hit_sili=SiliHC->entries();
 for(int i=0;i<n_hit_sili;i++)
    {
  analysisManager->FillNtupleDColumn(2,(*SiliHC)[i]->GetEdep());

    }

int n_hit_tren=TrenHC->entries();
 for(int i=0;i<n_hit_tren;i++)
    {

  analysisManager->FillNtupleDColumn(3,(*TrenHC)[i]->GetEdep());
    }

 analysisManager->AddNtupleRow();  

}

-----------------newRunAction.cc clas

newRunAction::newRunAction()
 : G4UserRunAction()
{}

newRunAction::~newRunAction() {}

void newRunAction::BeginOfRunAction(const G4Run* run)
{ 
  G4cout << "### Run " << run->GetRunID() << " start." << G4endl;

//Get/create a analysisManager

  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

  // Open an output file

  G4String fileName = "newNtuple";
  analysisManager->OpenFile(fileName);

  // Creating ntuple

   analysisManager->CreateNtuple("new", "Edep");

   analysisManager->CreateNtupleDColumn("numHitsAlphaDet");
   analysisManager->CreateNtupleDColumn("numHitsALphaBor");

   analysisManager->CreateNtupleDColumn("EdepAlphaDet");
   analysisManager->CreateNtupleDColumn("EdepALphaBor");

 analysisManager->FinishNtuple();
}

void newRunAction::EndOfRunAction(const G4Run* run)
{
  G4int nofEvents = run->GetNumberOfEvent();
  if ( nofEvents == 0 ) return;

  G4cout
     << "\n-------------------- END OF RUN ------------------------------\n"
     << " The run consists of " << nofEvents << " events" <<G4endl;

  delete G4AnalysisManager::Instance();  

}

 Thank you very much. 

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

1 None: Re: FillNtupleDColumn   (Ivana Hrivnacova - 15 May, 2013)
 Add Message Add Message
to: "Re: FillNtupleDColumn"

 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 ]