Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:51: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 /// \file ExTGRCRegionCutsMgr.cc
0027 /// \brief Implementation of the ExTGRCRegionCutsMgr class
0028 
0029 #include "ExTGRCRegionCutsMgr.hh"
0030 
0031 #include "ExTGRCRegionData.hh"
0032 
0033 #include "G4LogicalVolume.hh"
0034 #include "G4ProductionCuts.hh"
0035 #include "G4Region.hh"
0036 #include "G4RegionStore.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4tgbVolumeMgr.hh"
0039 #include "G4tgrUtils.hh"
0040 
0041 ExTGRCRegionCutsMgr* ExTGRCRegionCutsMgr::fInstance = 0;
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 ExTGRCRegionCutsMgr* ExTGRCRegionCutsMgr::GetInstance()
0045 {
0046   if (!fInstance) {
0047     fInstance = new ExTGRCRegionCutsMgr;
0048   }
0049   return fInstance;
0050 }
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 ExTGRCRegionCutsMgr::ExTGRCRegionCutsMgr() {}
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 ExTGRCRegionCutsMgr::~ExTGRCRegionCutsMgr()
0057 {
0058   delete fInstance;
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0062 void ExTGRCRegionCutsMgr::AddRegionData(const std::vector<G4String>& rd)
0063 {
0064   if ((rd.size() > 1) && (FindRegionData(rd[0]).size() != 0)) {
0065     G4Exception("ExTGRCRegionCutsMgr::AddRegionData", "InvalidArgument", JustWarning,
0066                 G4String("Region already exists: " + rd[0]).c_str());
0067     return;
0068   }
0069   fRegionDatae.push_back(new ExTGRCRegionData(rd));
0070 }
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 void ExTGRCRegionCutsMgr::AddRegionCuts(const std::vector<G4String>& rc)
0074 {
0075   if (rc.size() == 0) {
0076     G4cerr << "ERROR - ExTGRCRegionCutsMgr::AddRegionCuts()" << G4endl
0077            << "        Must have 3 or 4 arguments : REGION_NAME, gamma_CUT,"
0078            << " e-_CUT (e+_CUT)." << G4endl << "        It has only " << rc.size() << " !"
0079            << G4endl;
0080     G4Exception("ExTGRCRegionCutsMgr::AddRegionCuts()", "InvalidArgument", FatalErrorInArgument,
0081                 G4UIcommand::ConvertToString(G4int(rc.size())));
0082   }
0083 
0084   // Find region
0085   // std::vector<ExTGRCRegionData*>::const_iterator iter;
0086   std::vector<ExTGRCRegionData*> regs = FindRegionData(rc[0]);
0087 
0088   if (regs.size() == 0) {
0089     G4Exception("ExTGRCRegionCutsMgr::AddRegionCuts()", "InvalidArgument", FatalErrorInArgument,
0090                 G4String(" region does not exist: " + rc[0]).c_str());
0091   }
0092 
0093   for (size_t ii = 0; ii < regs.size(); ii++) {
0094     regs[ii]->SetCutsData(rc);
0095   }
0096 }
0097 
0098 std::vector<ExTGRCRegionData*> ExTGRCRegionCutsMgr::FindRegionData(const G4String& name)
0099 {
0100   std::vector<ExTGRCRegionData*> regs;
0101   std::vector<ExTGRCRegionData*>::const_iterator iter;
0102   for (iter = fRegionDatae.begin(); iter != fRegionDatae.end(); iter++) {
0103     if (G4tgrUtils::AreWordsEquivalent(name, (*iter)->GetRegionName())) {
0104       regs.push_back(*iter);
0105     }
0106   }
0107   return regs;
0108 }
0109 
0110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0111 void ExTGRCRegionCutsMgr::BuildRegions()
0112 {
0113   std::vector<ExTGRCRegionData*>::const_iterator iter;
0114   std::vector<G4String>::const_iterator ites;
0115   // std::vector<G4LogicalVolume*>::const_iterator itelv;
0116   for (iter = fRegionDatae.begin(); iter != fRegionDatae.end(); iter++) {
0117     G4Region* reg = new G4Region((*iter)->GetRegionName());
0118     std::vector<G4String> lvs = (*iter)->GetLVNames();
0119     for (ites = lvs.begin(); ites != lvs.end(); ites++) {
0120       G4LogicalVolume* logVol = G4tgbVolumeMgr::GetInstance()->FindG4LogVol(*ites, true);
0121       reg->AddRootLogicalVolume(logVol);
0122     }
0123   }
0124 }
0125 
0126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0127 void ExTGRCRegionCutsMgr::BuildProductionCuts()
0128 {
0129   std::vector<ExTGRCRegionData*>::const_iterator iter;
0130   G4RegionStore* regions = G4RegionStore::GetInstance();
0131   //----- loop to region datae
0132   for (iter = fRegionDatae.begin(); iter != fRegionDatae.end(); iter++) {
0133     if ((*iter)->CutsAreSet()) {
0134       G4Region* reg = regions->GetRegion((*iter)->GetRegionName());
0135       if (!reg) {
0136         G4Exception("ExTGRCRegionCutsMgr::BuildProductionCuts()", "InvalidArgument",
0137                     FatalErrorInArgument,
0138                     G4String("Region not found: " + (*iter)->GetRegionName()).c_str());
0139       }
0140       G4ProductionCuts* cuts = new G4ProductionCuts;
0141 
0142       cuts->SetProductionCut((*iter)->GetGammaCut(), "gamma");
0143       cuts->SetProductionCut((*iter)->GetElectronCut(), "e-");
0144       cuts->SetProductionCut((*iter)->GetPositronCut(), "e+");
0145       reg->SetProductionCuts(cuts);
0146     }
0147   }
0148 }