Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:16:09

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0028 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0029 
0030 #include "EventAction.hh"
0031 
0032 #include "Run.hh"
0033 #include "PrimaryGeneratorAction.hh"
0034 #include "HistoManager.hh"
0035 
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Event.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 EventAction::EventAction(DetectorConstruction* det,PrimaryGeneratorAction* prim)
0043 :detector(det), primary(prim)
0044 {
0045   nbOfModules = detector->GetNbModules();       
0046   nbOfLayers  = detector->GetNbLayers();
0047   kLayerMax = nbOfModules*nbOfLayers + 1;
0048   
0049   EtotCalor = EvisCalor = 0.;
0050 }
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 EventAction::~EventAction()
0055 {
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 void EventAction::BeginOfEventAction(const G4Event*)
0061 {
0062   EtotLayer.resize(kLayerMax);
0063   EvisLayer.resize(kLayerMax);          
0064   for (G4int k=0; k<kLayerMax; k++) {
0065     EtotLayer[k] = EvisLayer[k] = 0.0;
0066   }
0067   EtotCalor = EvisCalor = 0.;
0068   EvisFiber.clear();
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 void EventAction::SumDeStep(G4int iModule, G4int iLayer, G4int iFiber,
0074                             G4double deStep )
0075 {
0076   if (iModule > 0) EtotCalor += deStep;
0077         
0078   G4int kLayer = 0; G4int kFiber = 0;
0079   if (iLayer > 0) {
0080     kLayer = (iModule-1)*nbOfLayers + iLayer;
0081     EtotLayer[kLayer] += deStep;
0082   }
0083   
0084   if (iFiber > 0) {
0085     EvisLayer[kLayer] += deStep;
0086     EvisCalor += deStep;
0087     kFiber = 1000*kLayer + iFiber;
0088     EvisFiber[kFiber] += deStep;        
0089   }   
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 void EventAction::EndOfEventAction(const G4Event*)
0095 {
0096   //pass informations to Run
0097   //
0098   Run* run = static_cast<Run*>(
0099              G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0100     
0101   for (G4int k=0; k<kLayerMax; k++) {
0102      run->SumEvents_1(k,EtotLayer[k],EvisLayer[k]);   
0103   }
0104   
0105   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();    
0106   analysisManager->FillH1(1,EtotCalor);
0107   analysisManager->FillH1(2,EvisCalor);
0108   
0109   G4double Ebeam = primary->GetParticleGun()->GetParticleEnergy();
0110   G4double Eleak = Ebeam - EtotCalor;
0111   run->SumEvents_2(EtotCalor,EvisCalor,Eleak);
0112   
0113   
0114   std::map<G4int,G4double>::iterator it;         
0115   for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
0116      G4int kFiber = it->first;
0117      G4int iFiber = kFiber%1000;
0118      G4double Evis = it->second;
0119      analysisManager->FillH1(5,iFiber+0.5,Evis);
0120   }
0121     
0122   //write fired fibers on a file
0123   //
0124   //// WriteFibers(evt); 
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128         
0129 #include <fstream>
0130 
0131 void EventAction::WriteFibers(const G4Event* evt)
0132 {
0133   // event is appended on a file
0134   //
0135   G4String name = G4AnalysisManager::Instance()->GetFileName();
0136   G4String fileName = name + ".fibers.ascii";
0137   
0138   std::ofstream File(fileName, std::ios::app);
0139   std::ios::fmtflags mode = File.flags();  
0140   File.setf( std::ios::scientific, std::ios::floatfield );
0141   G4int prec = File.precision(3);
0142     
0143   //write event number  
0144   //
0145   File << evt->GetEventID() << G4endl;
0146   
0147   //gun particle informations
0148   //
0149   G4ParticleGun* gun = primary->GetParticleGun();
0150   G4double ekin = gun->GetParticleEnergy();
0151   G4ThreeVector direction = gun->GetParticleMomentumDirection();
0152   G4ThreeVector position  = gun->GetParticlePosition();
0153   File << ekin << " " << direction << " " << position << G4endl;  
0154   
0155   //write fibers
0156   //
0157   File << EvisFiber.size() << G4endl;
0158   //
0159   std::map<G4int,G4double>::iterator it;         
0160   for (it = EvisFiber.begin(); it != EvisFiber.end(); it++) {
0161      G4int kFiber = it->first;
0162      G4double Evis = it->second;
0163      File << " " << std::setw(7) << kFiber << " "<< std::setw(10) << Evis
0164             << G4endl;
0165   }
0166            
0167   File << G4endl;
0168     
0169   // restaure default formats
0170   File.setf(mode,std::ios::floatfield);
0171   File.precision(prec);         
0172 }
0173 
0174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0175