Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:49:53

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 /// \file GB03Run.cc
0027 /// \brief Implementation of the GB03Run class
0028 
0029 #include "GB03Run.hh"
0030 
0031 #include <algorithm>
0032 #include <iomanip>
0033 
0034 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0035 
0036 void ParticlesCount::Count(const G4String& partName, G4double weight, G4double E)
0037 {
0038   // G4cout << "Count " << partName << " " << weight << G4endl;
0039 
0040   const auto& [it, inserted] = fPartCntr.try_emplace(
0041     partName, std::tuple<G4double, G4int, G4double, G4double>(weight, 1, E, E));
0042 
0043   // G4cout << "Count " << inserted << " " << G4endl;
0044 
0045   // return;
0046 
0047   if (!inserted) {
0048     // Exists already
0049     std::get<0>(it->second) += weight;
0050     std::get<1>(it->second) += 1;
0051     std::get<2>(it->second) = std::min(std::get<2>(it->second), E);
0052     std::get<3>(it->second) = std::max(std::get<3>(it->second), E);
0053   }
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 void ParticlesCount::Print() const
0059 {
0060   for (const auto& it : fPartCntr) {
0061     G4String partName = it.first;
0062     auto [weight, count, Emin, Emax] = it.second;
0063     G4cout << " " << std::setw(20) << partName << " " << std::setw(7) << count << " "
0064            << std::setw(12) << weight << " Emin " << std::setw(12) << Emin << " Emax "
0065            << std::setw(12) << Emax << " (MeV) " << G4endl;
0066   }
0067   G4cout << G4endl;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void ParticlesCount::Merge(const ParticlesCount& worker)
0073 {
0074   for (const auto& part : worker.fPartCntr) {
0075     const auto& [it, inserted] = fPartCntr.emplace(part);
0076     if (!inserted) {
0077       // already in master counters
0078       std::get<0>(it->second) += std::get<0>(part.second);
0079       std::get<1>(it->second) += std::get<1>(part.second);
0080       std::get<2>(it->second) = std::min(std::get<2>(it->second), std::get<2>(part.second));
0081       std::get<3>(it->second) = std::max(std::get<3>(it->second), std::get<3>(part.second));
0082     }
0083   }
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 // Destructor
0089 GB03Run::~GB03Run()
0090 {
0091   //    clear all data members.
0092   fPartCounter.Reset();
0093 }
0094 
0095 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0096 
0097 void GB03Run::CountParticle(const G4String& n, G4double w, G4double e)
0098 {
0099   fPartCounter.Count(n, w, e);
0100 }
0101 
0102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0103 
0104 void GB03Run::Merge(const G4Run* aRun)
0105 {
0106   const GB03Run* localRun = static_cast<const GB03Run*>(aRun);
0107   //=======================================================
0108   // Merge Partice Counters
0109   //=======================================================
0110   fPartCounter.Merge(localRun->fPartCounter);
0111 
0112   G4Run::Merge(aRun);
0113 }
0114 
0115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......