Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:38

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