Skip to content
Snippets Groups Projects
RunAction.cc 3.78 KiB
Newer Older
  • Learn to ignore specific revisions
  • Chad Lantz's avatar
    Chad Lantz committed
    // ********************************************************************
    // * License and Disclaimer                                           *
    // *                                                                  *
    // * The  Geant4 software  is  copyright of the Copyright Holders  of *
    // * the Geant4 Collaboration.  It is provided  under  the terms  and *
    // * conditions of the Geant4 Software License,  included in the file *
    // * LICENSE and available at  http://cern.ch/geant4/license .  These *
    // * include a list of copyright holders.                             *
    // *                                                                  *
    // * Neither the authors of this software system, nor their employing *
    // * institutes,nor the agencies providing financial support for this *
    // * work  make  any representation or  warranty, express or implied, *
    // * regarding  this  software system or assume any liability for its *
    // * use.  Please see the license in the file  LICENSE  and URL above *
    // * for the full disclaimer and the limitation of liability.         *
    // *                                                                  *
    // * This  code  implementation is the result of  the  scientific and *
    // * technical work of the GEANT4 collaboration.                      *
    // * By using,  copying,  modifying or  distributing the software (or *
    // * any work based  on the software)  you  agree  to acknowledge its *
    // * use  in  resulting  scientific  publications,  and indicate your *
    // * acceptance of all terms of the Geant4 Software license.          *
    // ********************************************************************
    //
    
    clantz's avatar
    clantz committed
    /// \file /src/RunAction.cc
    /// \brief Implementation of the RunAction class
    
    Chad Lantz's avatar
    Chad Lantz committed
    //
    
    clantz's avatar
    clantz committed
    // @Author Chad Lantz
    
    
    Chad Lantz's avatar
    Chad Lantz committed
    
    // Make this appear first!
    #include "G4Timer.hh"
    
    
    clantz's avatar
    clantz committed
    #include "G4RunManager.hh"
    #include "G4Run.hh"
    
    
    clantz's avatar
    clantz committed
    #include "RunAction.hh"
    
    clantz's avatar
    clantz committed
    #include "G4VAnalysisManager.hh"
    
    #include "lgAnalysis.hh"
    
    Chad Lantz's avatar
    Chad Lantz committed
    
    
    
    clantz's avatar
    clantz committed
    /*
     *
     */
    
    clantz's avatar
    clantz committed
    RunAction::RunAction(G4String fileName)
    
    clantz's avatar
    clantz committed
     : G4UserRunAction(),ffileName(fileName),
    
    Chad Lantz's avatar
    Chad Lantz committed
      fTimer = new G4Timer;
    
    clantz's avatar
    clantz committed
    
    
      G4RunManager::GetRunManager()->SetPrintProgress(1);
    
    clantz's avatar
    clantz committed
    
      // Create analysis manager. The choice of analysis
      // technology is done via selectin of a namespace
      // in B4Analysis.hh
    
      auto analysisManager = G4AnalysisManager::Instance();
      G4cout << "Using " << analysisManager->GetType() << G4endl;
    
    
    clantz's avatar
    clantz committed
      // Create directories
      analysisManager->SetVerboseLevel(1);
      analysisManager->SetNtupleMerging(true);
    
      // Creating ntuple
    
      analysisManager->CreateNtuple("lightGuide", "pos and momentum");
    
    clantz's avatar
    clantz committed
      analysisManager->CreateNtupleDColumn("X");
      analysisManager->CreateNtupleDColumn("Y");
      analysisManager->CreateNtupleDColumn("hitX");
      analysisManager->CreateNtupleDColumn("hitY");
    
      analysisManager->CreateNtupleDColumn("time");
    
      analysisManager->FinishNtuple();
    
      analysisManager->SetFirstHistoId(1);
      analysisManager->CreateH2("1","Relative Efficiency",
                                150, -82.0*mm, 82.0*mm,
                                150, -44.875*mm, 44.875*mm);
    
    Chad Lantz's avatar
    Chad Lantz committed
    }
    
    
    clantz's avatar
    clantz committed
    /*
     *
     */
    
    clantz's avatar
    clantz committed
    RunAction::~RunAction(){
    
    Chad Lantz's avatar
    Chad Lantz committed
      delete fTimer;
    
    clantz's avatar
    clantz committed
      delete G4AnalysisManager::Instance();
    
    Chad Lantz's avatar
    Chad Lantz committed
    }
    
    
    clantz's avatar
    clantz committed
    /*
     *
     */
    
    clantz's avatar
    clantz committed
    void RunAction::BeginOfRunAction(const G4Run* aRun){
    
    Chad Lantz's avatar
    Chad Lantz committed
      G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
      fTimer->Start();
    
    clantz's avatar
    clantz committed
    
      // Get analysis manager
      auto analysisManager = G4AnalysisManager::Instance();
    
      // Open an output file
    
    clantz's avatar
    clantz committed
      if(ffileName == "") ffileName = "output";
      analysisManager->OpenFile(ffileName);
    
    clantz's avatar
    clantz committed
    }
    
    
    clantz's avatar
    clantz committed
    void RunAction::EndOfRunAction(const G4Run* aRun){
    
      fTimer->Stop();
      G4cout << "number of event = " << aRun->GetNumberOfEvent()
             << " " << *fTimer << G4endl;
    
    clantz's avatar
    clantz committed
    
    
    clantz's avatar
    clantz committed
      // Get analysis manager
      auto analysisManager = G4AnalysisManager::Instance();
    
    clantz's avatar
    clantz committed
      // save histograms & ntuple
      analysisManager->Write();
      analysisManager->CloseFile();
    }