Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file biasing/B01/src/B01Run.cc 26 /// \file biasing/B01/src/B01Run.cc 27 /// \brief Implementation of the B01Run class 27 /// \brief Implementation of the B01Run class 28 // 28 // 29 // 29 // 30 // 30 // 31 31 32 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 // 33 // 34 // (Description) 34 // (Description) 35 // B01Run Class is for accumulating scored << 35 // B01Run Class is for accumulating scored quantities which is 36 // scored using G4MutiFunctionalDetector and 36 // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer. 37 // Accumulation is done using G4THitsMap obje 37 // Accumulation is done using G4THitsMap object. 38 // 38 // 39 // The constructor B01Run(const std::vector 39 // The constructor B01Run(const std::vector<G4String> mfdName) 40 // needs a vector filled with MultiFunctional 40 // needs a vector filled with MultiFunctionalDetector names which 41 // was assigned at instantiation of MultiFunc 41 // was assigned at instantiation of MultiFunctionalDetector(MFD). 42 // Then B01Run constructor automatically scan 42 // Then B01Run constructor automatically scans primitive scorers 43 // in the MFD, and obtains collectionIDs of a 43 // in the MFD, and obtains collectionIDs of all collections associated 44 // to those primitive scorers. Futhermore, th << 44 // to those primitive scorers. Futhermore, the G4THitsMap objects 45 // for accumulating during a RUN are automati 45 // for accumulating during a RUN are automatically created too. 46 // (*) Collection Name is same as primitive s 46 // (*) Collection Name is same as primitive scorer name. 47 // << 47 // 48 // The resultant information is kept inside 48 // The resultant information is kept inside B01Run objects as 49 // data members. 49 // data members. 50 // std::vector<G4String> fCollName; 50 // std::vector<G4String> fCollName; // Collection Name, 51 // std::vector<G4int> fCollID; 51 // std::vector<G4int> fCollID; // Collection ID, 52 // std::vector<G4THitsMap<G4double>*> fRunMap 52 // std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN. 53 // 53 // 54 // The resualtant HitsMap objects are obtain 54 // The resualtant HitsMap objects are obtain using access method, 55 // GetHitsMap(..). 55 // GetHitsMap(..). 56 // 56 // 57 //....oooOO0OOooo........oooOO0OOooo........oo 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 58 59 #include "B01Run.hh" 59 #include "B01Run.hh" >> 60 #include "G4SDManager.hh" 60 61 61 #include "G4MultiFunctionalDetector.hh" 62 #include "G4MultiFunctionalDetector.hh" 62 #include "G4SDManager.hh" << 63 #include "G4VPrimitiveScorer.hh" 63 #include "G4VPrimitiveScorer.hh" 64 64 65 // 65 // 66 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 // Constructor. << 67 // Constructor. 68 // (The vector of MultiFunctionalDetector na 68 // (The vector of MultiFunctionalDetector name has to given.) 69 B01Run::B01Run(const std::vector<G4String> mfd << 69 B01Run::B01Run(const std::vector<G4String> mfdName): G4Run() 70 { 70 { 71 G4SDManager* SDman = G4SDManager::GetSDMpoin 71 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 72 //========================================== 72 //================================================= 73 // Initalize RunMaps for accumulation. 73 // Initalize RunMaps for accumulation. 74 // Get CollectionIDs for HitCollections. 74 // Get CollectionIDs for HitCollections. 75 //========================================== 75 //================================================= 76 G4int Nmfd = mfdName.size(); 76 G4int Nmfd = mfdName.size(); 77 for (G4int idet = 0; idet < Nmfd; idet++) { << 77 for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD. 78 G4String detName = mfdName[idet]; 78 G4String detName = mfdName[idet]; 79 //--- Seek and Obtain MFD objects from SDm 79 //--- Seek and Obtain MFD objects from SDmanager. 80 G4MultiFunctionalDetector* mfd = 80 G4MultiFunctionalDetector* mfd = 81 (G4MultiFunctionalDetector*)(SDman->Find 81 (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName)); 82 // 82 // 83 if (mfd) { << 83 if ( mfd ){ 84 //--- Loop over the registered primitive << 84 //--- Loop over the registered primitive scorers. 85 for (G4int icol = 0; icol < mfd->GetNumb << 85 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){ 86 // Get Primitive Scorer object. << 86 // Get Primitive Scorer object. 87 G4VPrimitiveScorer* scorer = mfd->GetP << 87 G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol); 88 // collection name and collectionID fo << 88 // collection name and collectionID for HitsCollection, 89 // where type of HitsCollection is G4T << 89 // where type of HitsCollection is G4THitsMap in case of primitive scorer. 90 // The collection name is given by <MF << 90 // The collection name is given by <MFD name>/<Primitive Scorer name>. 91 G4String collectionName = scorer->GetN << 91 G4String collectionName = scorer->GetName(); 92 G4String fullCollectionName = detName << 92 G4String fullCollectionName = detName+"/"+collectionName; 93 G4int collectionID = SDman->GetCollect << 93 G4int collectionID = SDman->GetCollectionID(fullCollectionName); 94 << 94 95 if (collectionID >= 0) { << 95 if ( collectionID >= 0 ){ 96 G4cout << "++ " << fullCollectionNam << 96 G4cout << "++ "<<fullCollectionName<< " id " << collectionID 97 // Store obtained HitsCollection inf << 97 << G4endl; 98 // And, creates new G4THitsMap for a << 98 // Store obtained HitsCollection information into data members. 99 fCollName.push_back(fullCollectionNa << 99 // And, creates new G4THitsMap for accumulating quantities during RUN. 100 fCollID.push_back(collectionID); << 100 fCollName.push_back(fullCollectionName); 101 fRunMap.push_back(new G4THitsMap<G4d << 101 fCollID.push_back(collectionID); 102 } << 102 fRunMap.push_back(new G4THitsMap<G4double>(detName 103 else { << 103 ,collectionName)); 104 G4cout << "** collection " << fullCo << 104 }else{ >> 105 G4cout << "** collection " << fullCollectionName >> 106 << " not found. "<<G4endl; >> 107 } 105 } 108 } 106 } << 107 } 109 } 108 } 110 } 109 } 111 } 110 112 111 //....oooOO0OOooo........oooOO0OOooo........oo 113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 112 114 113 // Destructor 115 // Destructor 114 // clear all data members. 116 // clear all data members. 115 B01Run::~B01Run() 117 B01Run::~B01Run() 116 { 118 { 117 //--- Clear HitsMap for RUN 119 //--- Clear HitsMap for RUN 118 G4int Nmap = fRunMap.size(); 120 G4int Nmap = fRunMap.size(); 119 for (G4int i = 0; i < Nmap; i++) { << 121 for ( G4int i = 0; i < Nmap; i++){ 120 if (fRunMap[i]) fRunMap[i]->clear(); << 122 if(fRunMap[i] ) fRunMap[i]->clear(); 121 } 123 } 122 fCollName.clear(); 124 fCollName.clear(); 123 fCollID.clear(); 125 fCollID.clear(); 124 fRunMap.clear(); 126 fRunMap.clear(); 125 } 127 } 126 128 127 //....oooOO0OOooo........oooOO0OOooo........oo 129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 128 130 129 // RecordEvent is called at end of event. 131 // RecordEvent is called at end of event. 130 // For scoring purpose, the resultant quantit 132 // For scoring purpose, the resultant quantity in a event, 131 // is accumulated during a Run. 133 // is accumulated during a Run. 132 void B01Run::RecordEvent(const G4Event* aEvent 134 void B01Run::RecordEvent(const G4Event* aEvent) 133 { 135 { 134 numberOfEvent++; // This is an original lin 136 numberOfEvent++; // This is an original line. 135 137 136 //============================= 138 //============================= 137 // HitsCollection of This Event 139 // HitsCollection of This Event 138 //============================ 140 //============================ 139 G4HCofThisEvent* HCE = aEvent->GetHCofThisEv 141 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent(); 140 if (!HCE) return; 142 if (!HCE) return; 141 143 142 //========================================== 144 //======================================================= 143 // Sum up HitsMap of this Event into HitsMa 145 // Sum up HitsMap of this Event into HitsMap of this RUN 144 //========================================== 146 //======================================================= 145 G4int Ncol = fCollID.size(); 147 G4int Ncol = fCollID.size(); 146 for (G4int i = 0; i < Ncol; i++) { // Loop << 148 for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection 147 G4THitsMap<G4double>* EvtMap = 0; << 149 G4THitsMap<G4double>* EvtMap=0; 148 if (fCollID[i] >= 0) { // Collection is a << 150 if ( fCollID[i] >= 0 ){ // Collection is attached to HCE 149 EvtMap = (G4THitsMap<G4double>*)(HCE->Ge 151 EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID[i])); >> 152 }else{ >> 153 G4cout <<" Error EvtMap Not Found "<< i << G4endl; 150 } 154 } 151 else { << 155 if ( EvtMap ) { 152 G4cout << " Error EvtMap Not Found " << << 153 } << 154 if (EvtMap) { << 155 //=== Sum up HitsMap of this event to Hi 156 //=== Sum up HitsMap of this event to HitsMap of RUN.=== 156 *fRunMap[i] += *EvtMap; 157 *fRunMap[i] += *EvtMap; 157 //====================================== 158 //====================================================== 158 } 159 } 159 } 160 } >> 161 >> 162 160 } 163 } 161 164 162 //....oooOO0OOooo........oooOO0OOooo........oo 165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 163 // 166 // 164 // Access method for HitsMap of the RUN 167 // Access method for HitsMap of the RUN 165 // 168 // 166 //----- 169 //----- 167 // Access HitsMap. 170 // Access HitsMap. 168 // By MultiFunctionalDetector name and Colle 171 // By MultiFunctionalDetector name and Collection Name. 169 G4THitsMap<G4double>* B01Run::GetHitsMap(const << 172 G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& detName, 170 { << 173 const G4String& colName){ 171 G4String fullName = detName + "/" + colName; << 174 G4String fullName = detName+"/"+colName; 172 return GetHitsMap(fullName); << 175 return GetHitsMap(fullName); 173 } 176 } 174 177 175 //----- 178 //----- 176 // Access HitsMap. 179 // Access HitsMap. 177 // By full description of collection name, th 180 // By full description of collection name, that is 178 // <MultiFunctional Detector Name>/<Primiti 181 // <MultiFunctional Detector Name>/<Primitive Scorer Name> 179 G4THitsMap<G4double>* B01Run::GetHitsMap(const << 182 G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& fullName){ 180 { << 183 G4int Ncol = fCollName.size(); 181 G4int Ncol = fCollName.size(); << 184 for ( G4int i = 0; i < Ncol; i++){ 182 for (G4int i = 0; i < Ncol; i++) { << 185 if ( fCollName[i] == fullName ){ 183 if (fCollName[i] == fullName) { << 186 return fRunMap[i]; 184 return fRunMap[i]; << 187 } 185 } 188 } 186 } << 189 return NULL; 187 return NULL; << 188 } 190 } 189 191 190 //....oooOO0OOooo........oooOO0OOooo........oo 192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 191 193 192 // - Dump All HitsMap of this RUN. (for debugi 194 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity). 193 // This method calls G4THisMap::PrintAll() f 195 // This method calls G4THisMap::PrintAll() for individual HitsMap. 194 void B01Run::DumpAllScorer() << 196 void B01Run::DumpAllScorer(){ 195 { << 197 196 // - Number of HitsMap in this RUN. 198 // - Number of HitsMap in this RUN. 197 G4int n = GetNumberOfHitsMap(); 199 G4int n = GetNumberOfHitsMap(); 198 // - GetHitsMap and dump values. 200 // - GetHitsMap and dump values. 199 for (G4int i = 0; i < n; i++) { << 201 for ( G4int i = 0; i < n ; i++ ){ 200 G4THitsMap<G4double>* RunMap = GetHitsMap( << 202 G4THitsMap<G4double>* RunMap =GetHitsMap(i); 201 if (RunMap) { << 203 if ( RunMap ) { 202 G4cout << " PrimitiveScorer RUN " << Run << 204 G4cout << " PrimitiveScorer RUN " 203 << G4endl; << 205 << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl; 204 G4cout << " Number of entries " << RunMa 206 G4cout << " Number of entries " << RunMap->entries() << G4endl; 205 std::map<G4int, G4double*>::iterator itr << 207 std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin(); 206 for (; itr != RunMap->GetMap()->end(); i << 208 for(; itr != RunMap->GetMap()->end(); itr++) { 207 G4cout << " copy no.: " << itr->first << 209 G4cout << " copy no.: " << itr->first >> 210 << " Run Value : " << *(itr->second) >> 211 << G4endl; 208 } 212 } 209 } 213 } 210 } 214 } 211 } 215 } 212 216 213 //....oooOO0OOooo........oooOO0OOooo........oo 217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 214 218 215 void B01Run::Merge(const G4Run* aRun) 219 void B01Run::Merge(const G4Run* aRun) 216 { 220 { 217 const B01Run* localRun = static_cast<const B << 221 const B01Run * localRun = static_cast<const B01Run *>(aRun); 218 //========================================== 222 //======================================================= 219 // Merge HitsMap of working threads 223 // Merge HitsMap of working threads 220 //========================================== 224 //======================================================= 221 G4int nCol = localRun->fCollID.size(); 225 G4int nCol = localRun->fCollID.size(); 222 for (G4int i = 0; i < nCol; i++) { // Loop << 226 for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection 223 if (localRun->fCollID[i] >= 0) { << 227 if ( localRun->fCollID[i] >= 0 ){ 224 *fRunMap[i] += *localRun->fRunMap[i]; 228 *fRunMap[i] += *localRun->fRunMap[i]; 225 } 229 } 226 } 230 } 227 << 231 228 G4Run::Merge(aRun); 232 G4Run::Merge(aRun); 229 } << 233 } 230 234 231 //....oooOO0OOooo........oooOO0OOooo........oo 235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 236 232 237