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