Files
minicalosim/src/EventAction.cc
T
Jan Kieseler 51001d1b59 renamed
2023-10-07 11:14:45 +02:00

139 lines
4.9 KiB
C++

//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
/// \file B4/B4a/src/EventAction.cc
/// \brief Implementation of the B4a::EventAction class
#include "GeometryDescriptor.hh"
#include "EventAction.hh"
#include "RunAction.hh"
#include "G4AnalysisManager.hh"
#include "G4RunManager.hh"
#include "G4Event.hh"
#include "G4UnitsTable.hh"
#include "PrimaryGeneratorAction.hh"
#include "Randomize.hh"
#include <iomanip>
#include "DetectorConstruction.hh"
namespace B4a
{
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void EventAction::BeginOfEventAction(const G4Event* /*event*/)
{
auto cw = B4::DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor();
// initialisation per event
if(cw == nullptr){
G4cout << "GeometryDescriptor not found" << G4endl;
throw std::runtime_error("GeometryDescriptor not found");
}
if(gen == nullptr){
G4cout << "PrimaryGeneratorAction not found" << G4endl;
throw std::runtime_error("PrimaryGeneratorAction not found");
}
cw->resetSensorEnergies();
if(run->hitEnergy.size() != cw->getNSensors()){
run->hitEnergy.resize(cw->getNSensors(),0);
run->hitX.resize(cw->getNSensors(),0);
run->hitY.resize(cw->getNSensors(),0);
run->hitZ.resize(cw->getNSensors(),0);
run->hitDX.resize(cw->getNSensors(),0);
run->hitDY.resize(cw->getNSensors(),0);
run->hitDZ.resize(cw->getNSensors(),0);
run->hitLayer.resize(cw->getNSensors(),0);
run->hitCopyNumber.resize(cw->getNSensors(),0);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void EventAction::EndOfEventAction(const G4Event* event)
{
// Accumulate statistics
//
// get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
auto cw = B4::DetectorConstruction::getDetectorConstruction()->getGeometryDescriptor();
//cw->printSensorEnergies();//DEBUG
std::vector<double> sensorEnergies;
double tot_energy=0;
int sensorNumber=0;
int layerNumber=0;
int nactive =0;
for(const auto& layer: cw->getLayers()){
for(const auto& sensor: layer.sensors){
sensorEnergies.push_back(sensor.getEnergy());
tot_energy+= sensor.getEnergy();
//fill the vectors
run->hitEnergy[sensorNumber] = sensor.getEnergy();
run->hitX[sensorNumber] = sensor.getPos().x();
run->hitY[sensorNumber] = sensor.getPos().y();
run->hitZ[sensorNumber] = sensor.getPos().z();
run->hitDX[sensorNumber] = sensor.getSize().x();
run->hitDY[sensorNumber] = sensor.getSize().y();
run->hitDZ[sensorNumber] = sensor.getSize().z();
run->hitLayer[sensorNumber] = layerNumber;
run->hitCopyNumber[sensorNumber] = sensorNumber;
sensorNumber++;
}
layerNumber++;
if(layer.isActive){
nactive++;
}
}
//assign the vectors
// fill ntuple
analysisManager->FillNtupleDColumn(0, gen->getPartEnergy()); //needs to be true energy DEBUG
analysisManager->FillNtupleDColumn(1, tot_energy);
analysisManager->FillNtupleIColumn(2, (int)cw->getLayers().size());
analysisManager->FillNtupleIColumn(3, nactive);
analysisManager->FillNtupleIColumn(4, cw->getNSensors());
//vectors are stored automatically
analysisManager->AddNtupleRow();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}