|
|
|||
File indexing completed on 2026-09-13 08:28:42
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 B03Run.cc 0027 /// \brief Implementation of the B03Run class 0028 0029 //===================================================================== 0030 // 0031 // (Description) 0032 // B03Run Class is for accumulating scored quantities which is 0033 // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer. 0034 // Accumulation is done using G4THitsMap object. 0035 // 0036 // The constructor B03Run(const std::vector<G4String> mfdName) 0037 // needs a vector filled with MultiFunctionalDetector names which 0038 // was assigned at instantiation of MultiFunctionalDetector(MFD). 0039 // Then B03Run constructor automatically scans primitive scorers 0040 // in the MFD, and obtains collectionIDs of all collections associated 0041 // to those primitive scorers. Futhermore, the G4THitsMap objects 0042 // for accumulating during a RUN are automatically created too. 0043 // (*) Collection Name is same as primitive scorer name. 0044 // 0045 // The resultant information is kept inside B03Run objects as 0046 // data members. 0047 // std::vector<G4String> fCollName; // Collection Name, 0048 // std::vector<G4int> fCollID; // Collection ID, 0049 // std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN. 0050 // 0051 // The resualtant HitsMap objects are obtain using access method, 0052 // GetHitsMap(..). 0053 // 0054 //===================================================================== 0055 0056 #include "B03Run.hh" 0057 0058 #include "G4MultiFunctionalDetector.hh" 0059 #include "G4SDManager.hh" 0060 #include "G4VPrimitiveScorer.hh" 0061 0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0063 0064 // Constructor. 0065 // (The vector of MultiFunctionalDetector name has to given.) 0066 B03Run::B03Run(const std::vector<G4String> mfdName) : G4Run() 0067 { 0068 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 0069 //================================================= 0070 // Initalize RunMaps for accumulation. 0071 // Get CollectionIDs for HitCollections. 0072 //================================================= 0073 G4int Nmfd = mfdName.size(); 0074 for (G4int idet = 0; idet < Nmfd; idet++) { // Loop for all MFD. 0075 G4String detName = mfdName[idet]; 0076 //--- Seek and Obtain MFD objects from SDmanager. 0077 G4MultiFunctionalDetector* mfd = 0078 (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName)); 0079 // 0080 if (mfd) { 0081 //--- Loop over the registered primitive scorers. 0082 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++) { 0083 // Get Primitive Scorer object. 0084 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol); 0085 // collection name and collectionID for HitsCollection, 0086 // where type of HitsCollection is G4THitsMap in case of primitive scorer. 0087 // The collection name is given by <MFD name>/<Primitive Scorer name>. 0088 G4String collectionName = scorer->GetName(); 0089 G4String fullCollectionName = detName + "/" + collectionName; 0090 G4int collectionID = SDman->GetCollectionID(fullCollectionName); 0091 // 0092 if (collectionID >= 0) { 0093 G4cout << "++ " << fullCollectionName << " id " << collectionID << G4endl; 0094 // Store obtained HitsCollection information into data members. 0095 // And, creates new G4THitsMap for accumulating quantities during RUN. 0096 fCollName.push_back(fullCollectionName); 0097 fCollID.push_back(collectionID); 0098 fRunMap.push_back(new G4THitsMap<G4double>(detName, collectionName)); 0099 } 0100 else { 0101 G4cout << "** collection " << fullCollectionName << " not found. " << G4endl; 0102 } 0103 } 0104 } 0105 } 0106 } 0107 0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0109 0110 // Destructor 0111 // clear all data members. 0112 B03Run::~B03Run() 0113 { 0114 //--- Clear HitsMap for RUN 0115 G4int Nmap = fRunMap.size(); 0116 for (G4int i = 0; i < Nmap; i++) { 0117 if (fRunMap[i]) fRunMap[i]->clear(); 0118 } 0119 fCollName.clear(); 0120 fCollID.clear(); 0121 fRunMap.clear(); 0122 } 0123 0124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0125 0126 // RecordEvent is called at end of event. 0127 // For scoring purpose, the resultant quantity in a event, 0128 // is accumulated during a Run. 0129 void B03Run::RecordEvent(const G4Event* aEvent) 0130 { 0131 numberOfEvent++; // This is an original line. 0132 0133 //============================= 0134 // HitsCollection of This Event 0135 //============================ 0136 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent(); 0137 if (!HCE) return; 0138 //======================================================= 0139 // Sum up HitsMap of this Event into HitsMap of this RUN 0140 //======================================================= 0141 G4int Ncol = fCollID.size(); 0142 for (G4int i = 0; i < Ncol; i++) { // Loop over HitsCollection 0143 G4THitsMap<G4double>* EvtMap = 0; 0144 if (fCollID[i] >= 0) { // Collection is attached to HCE 0145 EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID[i])); 0146 } 0147 else { 0148 G4cout << " Error EvtMap Not Found " << i << G4endl; 0149 } 0150 if (EvtMap) { 0151 //=== Sum up HitsMap of this event to HitsMap of RUN.=== 0152 *fRunMap[i] += *EvtMap; 0153 //====================================================== 0154 } 0155 } 0156 } 0157 0158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0159 0160 // Access method for HitsMap of the RUN 0161 // 0162 // Access HitsMap. 0163 // By MultiFunctionalDetector name and Collection Name. 0164 G4THitsMap<G4double>* B03Run::GetHitsMap(const G4String& detName, const G4String& colName) 0165 { 0166 G4String fullName = detName + "/" + colName; 0167 G4cout << " getting hits map " << fullName << G4endl; 0168 return GetHitsMap(fullName); 0169 } 0170 0171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0172 0173 // Access HitsMap. 0174 // By full description of collection name, that is 0175 // <MultiFunctional Detector Name>/<Primitive Scorer Name> 0176 G4THitsMap<G4double>* B03Run::GetHitsMap(const G4String& fullName) 0177 { 0178 G4cout << " getting hits map " << fullName << G4endl; 0179 G4int Ncol = fCollName.size(); 0180 for (G4int i = 0; i < Ncol; i++) { 0181 if (fCollName[i] == fullName) { 0182 return fRunMap[i]; 0183 } 0184 } 0185 return NULL; 0186 } 0187 0188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0189 0190 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity). 0191 // This method calls G4THisMap::PrintAll() for individual HitsMap. 0192 void B03Run::DumpAllScorer() 0193 { 0194 // - Number of HitsMap in this RUN. 0195 G4int n = GetNumberOfHitsMap(); 0196 // - GetHitsMap and dump values. 0197 for (G4int i = 0; i < n; i++) { 0198 G4THitsMap<G4double>* RunMap = GetHitsMap(i); 0199 if (RunMap) { 0200 G4cout << " PrimitiveScorer RUN " << RunMap->GetSDname() << "," << RunMap->GetName() 0201 << G4endl; 0202 G4cout << " Number of entries " << RunMap->entries() << G4endl; 0203 std::map<G4int, G4double*>::iterator itr = RunMap->GetMap()->begin(); 0204 for (; itr != RunMap->GetMap()->end(); itr++) { 0205 G4cout << " copy no.: " << itr->first << " Run Value : " << *(itr->second) << G4endl; 0206 } 0207 } 0208 } 0209 } 0210 0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0212 0213 void B03Run::Merge(const G4Run* aRun) 0214 { 0215 const B03Run* localRun = static_cast<const B03Run*>(aRun); 0216 //======================================================= 0217 // Merge HitsMap of working threads 0218 //======================================================= 0219 G4int nCol = localRun->fCollID.size(); 0220 for (G4int i = 0; i < nCol; i++) { // Loop over HitsCollection 0221 if (localRun->fCollID[i] >= 0) { 0222 *fRunMap[i] += *localRun->fRunMap[i]; 0223 } 0224 } 0225 0226 G4Run::Merge(aRun); 0227 } 0228 0229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|