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