#include #include #include #include "FCALDetectorConstruction.hh" #include "FCALPrimaryGeneratorAction.hh" #include "FCALEventAction.hh" #include "G4Event.hh" #include "G4UnitsTable.hh" #include "TTree.h" FCALEventAction::FCALEventAction(FCALDetectorConstruction* detector_Con, FCALPrimaryGeneratorAction* generator_Act, G4int Interact, TTree* tree) : detector_Construction(detector_Con), generator_Action(generator_Act), Interactive(Interact), FCAL_Tree(tree) { n_Cells = detector_Construction->getRows() * detector_Construction->getColumns(); n_ExcitedCells = 0; total_Photons = new G4int[n_Cells]; // secure the necessary memory space. detected_Photons = new G4int[n_Cells]; energy_Detected = new G4double[n_Cells]; energy_Deposited = new G4double[n_Cells]; energy_Attenuated = new G4double[n_Cells]; for (G4int i=0; iBranch("event_ID", &event_ID, "event_ID/I"); FCAL_Tree->Branch("in_Energy", &in_Energy, "in_Energy/F"); FCAL_Tree->Branch("Shower_Wx", &ShowerStartWx, "Shower_Wx/F"); FCAL_Tree->Branch("Shower_Wy", &ShowerStartWy, "Shower_Wy/F"); FCAL_Tree->Branch("Shower_Wz", &ShowerStartWz, "Shower_Wz/F"); FCAL_Tree->Branch("Shower_Lx", &ShowerStartLx, "Shower_Lx/F"); FCAL_Tree->Branch("Shower_Ly", &ShowerStartLy, "Shower_Ly/F"); FCAL_Tree->Branch("Shower_Lz", &ShowerStartLz, "Shower_Lz/F"); FCAL_Tree->Branch("n_ExCells", &n_ExCells, "n_ExCells/I"); FCAL_Tree->Branch("row_No", row_No, "row_No[n_ExCells]/I"); FCAL_Tree->Branch("column_No", column_No, "column_No[n_ExCells]/I"); FCAL_Tree->Branch("n_RescaledPhotons", n_RescaledPhotons, "n_RescaledPhotons[n_ExCells]/F"); FCAL_Tree->Branch("op_Energy", op_Energy, "op_Energy[n_ExCells]/F"); FCAL_Tree->Branch("dep_Energy", dep_Energy, "dep_Energy[n_ExCells]/F"); FCAL_Tree->Branch("att_Energy", att_Energy, "att_Energy[n_ExCells]/F"); } } FCALEventAction::~FCALEventAction() { delete total_Photons; delete detected_Photons; delete energy_Detected; delete energy_Deposited; delete energy_Attenuated; } void FCALEventAction::BeginOfEventAction(const G4Event* anEvent) { resetCounters(); if ((Interactive)||!(anEvent->GetEventID()%1)) G4cout << "### Event " << anEvent->GetEventID() << " start." << G4endl;// print the run id } void FCALEventAction::EndOfEventAction(const G4Event* anEvent) { G4int row_Number, column_Number; G4double detection_Efficiency; G4double total_PhotonEnergy = 0; // total energy G4double total_DepositEnergy = 0; // total energy deposited in LeadGlass G4double total_AttenuateEnergy = 0; // total energy deposited in LeadGlass considering attenuation // open file-output stream std::ofstream file_Out; if(Interactive){ file_Out.open("FCAL_Data.txt", std::ios::out | std::ios::app); if (!file_Out) { G4cout << "Can't open the target file to write!" << G4endl; } G4cout << "Block ID\tProduced\tDetected\t Energy \tDetection \tDeposited\tAttenuated" << G4endl; G4cout << " \tPhotons \tPhotons \tDetection\tEfficiency\t Energy \t Energy " << G4endl; G4cout << "--------\t--------\t--------\t---------\t----------\t---------\t----------" << G4endl; } for (G4int i=0; igetColumns()); row_Number = ((i - column_Number) / detector_Construction->getColumns()); if(Interactive){ G4cout << " [" << row_Number+1 << ", " << column_Number+1 << "] \t" << std::setw(8) < 0) // if ( gettotalDepositEnergy(i)> 0) { if (Interactive){ using namespace std; file_Out << setw(5) << anEvent->GetEventID() << " "; file_Out << setw(5) << generator_Action->getParticleEnergy() << " "; file_Out << setw(2) << n_ExcitedCells << " "; file_Out << row_Number+1 << " " << column_Number+1 << " "; file_Out << setw(6) << getdetectedPhotons(i) << " "; file_Out << setw(10) << setprecision(4) << gettotalPhotonEnergy(i) << " "; file_Out << setw(10) << setprecision(4) << gettotalDepositEnergy(i) << " "; file_Out << setw(10) << setprecision(4) << gettotalAttenuateEnergy(i) << G4endl; } else{ row_No[n_ExCells] = row_Number + 1; column_No[n_ExCells] = column_Number + 1; // n_RescaledPhotons[n_ExCells] = getdetectedPhotons(i)/16239.82; // when the index of refraction of the interface cookie is 1.7 n_RescaledPhotons[n_ExCells] = getdetectedPhotons(i); op_Energy[n_ExCells] = gettotalPhotonEnergy(i); dep_Energy[n_ExCells] = gettotalDepositEnergy(i)/1000.; // make unit GeV att_Energy[n_ExCells] = gettotalAttenuateEnergy(i)/1000.; // make unit GeV n_ExCells++; assert(n_ExCells < kMaxCells); } } } if (Interactive){ file_Out.close(); } else{ FCAL_Tree->Fill(); // G4cout << "EVENT RESULT: hits "<< n_ExCells<<" E:" << dep_Energy[0]<< " P:"<getColumns() * detector_Construction->getXLength(); y_Reduced = y_Pos + detector_Construction->getRows() * detector_Construction->getYLength(); for (G4int i=0; i<(detector_Construction->getColumns()); i++) // get the column number { if ((x_Reduced >= 2*i*detector_Construction->getXLength()) && (x_Reduced < 2*(i+1)*detector_Construction->getXLength())) { column_Num = i; } } for (G4int j=0; j<(detector_Construction->getRows()); j++) // get the row number { if ((y_Reduced >= 2*j*detector_Construction->getYLength()) && (y_Reduced < 2*(j+1)*detector_Construction->getYLength())) { row_Num = j; } } copy_No = row_Num * detector_Construction->getColumns() + column_Num; total_Photons[copy_No] += 1; } void FCALEventAction::countHits(G4int copy_No) { detected_Photons[copy_No] += 1; } void FCALEventAction::addEnergy(G4double photon_Eng, G4int copy_No) { energy_Detected[copy_No] += photon_Eng; } void FCALEventAction::addEnergyDeposit(G4double energy_Dep, G4int copy_No) { energy_Deposited[copy_No] += energy_Dep; } void FCALEventAction::addEnergyAttenuate(G4double energy_Att, G4int copy_No) { energy_Attenuated[copy_No] +=energy_Att; } void FCALEventAction::resetCounters() { n_ExcitedCells =0; n_ExCells = 0; for (G4int i=0; i