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 runAndEvent/RE02/src/RE02Run.cc << 27 /// \brief Implementation of the RE02Run class << 28 // << 29 // 26 // >> 27 // $Id: RE02Run.cc,v 1.3 2006/11/18 01:37:24 asaim Exp $ >> 28 // GEANT4 tag $Name: geant4-08-02 $ 30 // 29 // 31 30 32 //============================================ 31 //===================================================================== 33 // 32 // 34 // (Description) 33 // (Description) 35 // RE02Run Class is for accumulating scored << 34 // RE02Run Class is for accumulating scored quantities which is 36 // scored using G4MutiFunctionalDetector and 35 // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer. 37 // Accumulation is done using G4THitsMap obje 36 // Accumulation is done using G4THitsMap object. 38 // 37 // 39 // The constructor RE02Run(const std::vecto 38 // The constructor RE02Run(const std::vector<G4String> mfdName) 40 // needs a vector filled with MultiFunctional 39 // needs a vector filled with MultiFunctionalDetector names which 41 // was assigned at instantiation of MultiFunc 40 // was assigned at instantiation of MultiFunctionalDetector(MFD). 42 // Then RE02Run constructor automatically sca 41 // Then RE02Run constructor automatically scans primitive scorers 43 // in the MFD, and obtains collectionIDs of a 42 // in the MFD, and obtains collectionIDs of all collections associated 44 // to those primitive scorers. Futhermore, th << 43 // to those primitive scorers. Futhermore, the G4THitsMap objects 45 // for accumulating during a RUN are automati 44 // for accumulating during a RUN are automatically created too. 46 // (*) Collection Name is same as primitive s 45 // (*) Collection Name is same as primitive scorer name. 47 // << 46 // 48 // The resultant information is kept inside 47 // The resultant information is kept inside RE02Run objects as 49 // data members. 48 // data members. 50 // std::vector<G4String> fCollName; << 49 // std::vector<G4String> theCollName; // Collection Name, 51 // std::vector<G4int> fCollID; << 50 // std::vector<G4int> theCollID; // Collection ID, 52 // std::vector<G4THitsMap<G4double>*> fRunMap << 51 // std::vector<G4THitsMap<G4double>*> theRunMap; // HitsMap for RUN. 53 // 52 // 54 // The resualtant HitsMap objects are obtain 53 // The resualtant HitsMap objects are obtain using access method, 55 // GetHitsMap(..). 54 // GetHitsMap(..). 56 // 55 // 57 //============================================ 56 //===================================================================== 58 57 59 #include "RE02Run.hh" 58 #include "RE02Run.hh" >> 59 #include "G4SDManager.hh" 60 60 61 #include "G4MultiFunctionalDetector.hh" 61 #include "G4MultiFunctionalDetector.hh" 62 #include "G4SDManager.hh" << 63 #include "G4VPrimitiveScorer.hh" 62 #include "G4VPrimitiveScorer.hh" 64 63 65 //....oooOO0OOooo........oooOO0OOooo........oo << 66 // 64 // 67 // Constructor. << 65 // Constructor. 68 // (The vector of MultiFunctionalDetector na 66 // (The vector of MultiFunctionalDetector name has to given.) 69 RE02Run::RE02Run(const std::vector<G4String> m << 67 RE02Run::RE02Run(const std::vector<G4String> mfdName): G4Run() 70 { 68 { 71 G4SDManager* pSDman = G4SDManager::GetSDMpoi << 69 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 72 //========================================== 70 //================================================= 73 // Initalize RunMaps for accumulation. 71 // Initalize RunMaps for accumulation. 74 // Get CollectionIDs for HitCollections. 72 // Get CollectionIDs for HitCollections. 75 //========================================== 73 //================================================= 76 G4int nMfd = mfdName.size(); << 74 G4int Nmfd = mfdName.size(); 77 for (G4int idet = 0; idet < nMfd; idet++) { << 75 for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD. 78 G4String detName = mfdName[idet]; 76 G4String detName = mfdName[idet]; 79 //--- Seek and Obtain MFD objects from SDm 77 //--- Seek and Obtain MFD objects from SDmanager. 80 G4MultiFunctionalDetector* mfd = 78 G4MultiFunctionalDetector* mfd = 81 (G4MultiFunctionalDetector*)(pSDman->Fin << 79 (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName)); 82 // 80 // 83 if (mfd) { << 81 if ( mfd ){ 84 //--- Loop over the registered primitive << 82 //--- Loop over the registered primitive scorers. 85 for (G4int icol = 0; icol < mfd->GetNumb << 83 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){ 86 // Get Primitive Scorer object. << 84 // Get Primitive Scorer object. 87 G4VPrimitiveScorer* scorer = mfd->GetP << 85 G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol); 88 // collection name and collectionID fo << 86 // collection name and collectionID for HitsCollection, 89 // where type of HitsCollection is G4T << 87 // where type of HitsCollection is G4THitsMap in case of primitive scorer. 90 // scorer. << 88 // The collection name is given by <MFD name>/<Primitive Scorer name>. 91 // The collection name is given by <MF << 89 G4String collectionName = scorer->GetName(); 92 G4String collectionName = scorer->GetN << 90 G4String fullCollectionName = detName+"/"+collectionName; 93 G4String fullCollectionName = detName << 91 G4int collectionID = SDman->GetCollectionID(fullCollectionName); 94 G4int collectionID = pSDman->GetCollec << 92 // 95 // << 93 if ( collectionID >= 0 ){ 96 if (collectionID >= 0) { << 94 G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl; 97 G4cout << "++ " << fullCollectionNam << 95 // Store obtained HitsCollection information into data members. 98 // Store obtained HitsCollection inf << 96 // And, creates new G4THitsMap for accumulating quantities during RUN. 99 // And, creates new G4THitsMap for a << 97 theCollName.push_back(fullCollectionName); 100 fCollName.push_back(fullCollectionNa << 98 theCollID.push_back(collectionID); 101 fCollID.push_back(collectionID); << 99 theRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName)); 102 fRunMap.push_back(new G4THitsMap<G4d << 100 }else{ 103 } << 101 G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl; 104 else { << 102 } 105 G4cout << "** collection " << fullCo << 103 } 106 } << 107 } << 108 } 104 } 109 } 105 } 110 } 106 } 111 107 112 //....oooOO0OOooo........oooOO0OOooo........oo << 113 // 108 // 114 // Destructor 109 // Destructor 115 // clear all data members. 110 // clear all data members. 116 RE02Run::~RE02Run() 111 RE02Run::~RE02Run() 117 { 112 { 118 //--- Clear HitsMap for RUN 113 //--- Clear HitsMap for RUN 119 G4int nMap = fRunMap.size(); << 114 G4int Nmap = theRunMap.size(); 120 for (G4int i = 0; i < nMap; i++) { << 115 for ( G4int i = 0; i < Nmap; i++){ 121 if (fRunMap[i]) fRunMap[i]->clear(); << 116 if(theRunMap[i] ) theRunMap[i]->clear(); 122 } << 117 } 123 fCollName.clear(); << 118 theCollName.clear(); 124 fCollID.clear(); << 119 theCollID.clear(); 125 fRunMap.clear(); << 120 theRunMap.clear(); 126 } 121 } 127 122 128 //....oooOO0OOooo........oooOO0OOooo........oo << 129 // 123 // 130 // RecordEvent is called at end of event. 124 // RecordEvent is called at end of event. 131 // For scoring purpose, the resultant quantit 125 // For scoring purpose, the resultant quantity in a event, 132 // is accumulated during a Run. 126 // is accumulated during a Run. 133 void RE02Run::RecordEvent(const G4Event* aEven 127 void RE02Run::RecordEvent(const G4Event* aEvent) 134 { 128 { 135 numberOfEvent++; // This is an original lin 129 numberOfEvent++; // This is an original line. 136 130 137 //============================= 131 //============================= 138 // HitsCollection of This Event 132 // HitsCollection of This Event 139 //============================ 133 //============================ 140 G4HCofThisEvent* pHCE = aEvent->GetHCofThisE << 134 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent(); 141 if (!pHCE) return; << 135 if (!HCE) return; 142 136 143 //========================================== 137 //======================================================= 144 // Sum up HitsMap of this Event into HitsMa 138 // Sum up HitsMap of this Event into HitsMap of this RUN 145 //========================================== 139 //======================================================= 146 G4int nCol = fCollID.size(); << 140 G4int Ncol = theCollID.size(); 147 for (G4int i = 0; i < nCol; i++) { // Loop << 141 for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection 148 G4THitsMap<G4double>* evtMap = 0; << 142 G4THitsMap<G4double>* EvtMap=0; 149 if (fCollID[i] >= 0) { // Collection is a << 143 if ( theCollID[i] >= 0 ){ // Collection is attached to HCE 150 evtMap = (G4THitsMap<G4double>*)(pHCE->G << 144 EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(theCollID[i])); 151 } << 145 }else{ 152 else { << 146 G4cout <<" Error EvtMap Not Found "<< i << G4endl; 153 G4cout << " Error evtMap Not Found " << << 154 } 147 } 155 if (evtMap) { << 148 if ( EvtMap ) { 156 //=== Sum up HitsMap of this event to Hi 149 //=== Sum up HitsMap of this event to HitsMap of RUN.=== 157 *fRunMap[i] += *evtMap; << 150 *theRunMap[i] += *EvtMap; 158 //====================================== 151 //====================================================== 159 } 152 } 160 } 153 } 161 } 154 } 162 155 163 //....oooOO0OOooo........oooOO0OOooo........oo << 156 //================================================================= 164 void RE02Run::Merge(const G4Run* aRun) << 165 { << 166 const RE02Run* localRun = static_cast<const << 167 << 168 //========================================== << 169 // Merge HitsMap of working threads << 170 //========================================== << 171 G4int nCol = localRun->fCollID.size(); << 172 for (G4int i = 0; i < nCol; i++) { // Loop << 173 if (localRun->fCollID[i] >= 0) { << 174 *fRunMap[i] += *localRun->fRunMap[i]; << 175 } << 176 } << 177 << 178 G4Run::Merge(aRun); << 179 } << 180 << 181 //....oooOO0OOooo........oooOO0OOooo........oo << 182 // << 183 // Access method for HitsMap of the RUN 157 // Access method for HitsMap of the RUN 184 // 158 // 185 //----- 159 //----- 186 // Access HitsMap. 160 // Access HitsMap. 187 // By MultiFunctionalDetector name and Colle 161 // By MultiFunctionalDetector name and Collection Name. 188 G4THitsMap<G4double>* RE02Run::GetHitsMap(cons << 162 G4THitsMap<G4double>* RE02Run::GetHitsMap(const G4String& detName, 189 { << 163 const G4String& colName){ 190 G4String fullName = detName + "/" + colName; << 164 G4String fullName = detName+"/"+colName; 191 return GetHitsMap(fullName); << 165 return GetHitsMap(fullName); 192 } 166 } 193 167 194 //....oooOO0OOooo........oooOO0OOooo........oo << 195 // << 196 //----- 168 //----- 197 // Access HitsMap. 169 // Access HitsMap. 198 // By full description of collection name, th 170 // By full description of collection name, that is 199 // <MultiFunctional Detector Name>/<Primiti 171 // <MultiFunctional Detector Name>/<Primitive Scorer Name> 200 G4THitsMap<G4double>* RE02Run::GetHitsMap(cons << 172 G4THitsMap<G4double>* RE02Run::GetHitsMap(const G4String& fullName){ 201 { << 173 G4int Ncol = theCollName.size(); 202 G4int nCol = fCollName.size(); << 174 for ( G4int i = 0; i < Ncol; i++){ 203 for (G4int i = 0; i < nCol; i++) { << 175 if ( theCollName[i] == fullName ){ 204 if (fCollName[i] == fullName) { << 176 return theRunMap[i]; 205 return fRunMap[i]; << 177 } 206 } 178 } 207 } << 179 return NULL; 208 return NULL; << 209 } 180 } 210 181 211 //....oooOO0OOooo........oooOO0OOooo........oo << 212 // << 213 //----- 182 //----- 214 // - Dump All HitsMap of this RUN. (for debugi 183 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity). 215 // This method calls G4THisMap::PrintAll() f 184 // This method calls G4THisMap::PrintAll() for individual HitsMap. 216 void RE02Run::DumpAllScorer() << 185 void RE02Run::DumpAllScorer(){ 217 { << 186 218 // - Number of HitsMap in this RUN. 187 // - Number of HitsMap in this RUN. 219 G4int n = GetNumberOfHitsMap(); 188 G4int n = GetNumberOfHitsMap(); 220 // - GetHitsMap and dump values. 189 // - GetHitsMap and dump values. 221 for (G4int i = 0; i < n; i++) { << 190 for ( G4int i = 0; i < n ; i++ ){ 222 G4THitsMap<G4double>* runMap = GetHitsMap( << 191 G4THitsMap<G4double>* RunMap =GetHitsMap(i); 223 if (runMap) { << 192 if ( RunMap ) { 224 G4cout << " PrimitiveScorer RUN " << run << 193 G4cout << " PrimitiveScorer RUN " 225 << G4endl; << 194 << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl; 226 G4cout << " Number of entries " << runMa << 195 G4cout << " Number of entries " << RunMap->entries() << G4endl; 227 //// std::map<G4int,G4double*>::ite << 196 std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin(); 228 //// for(; itr != runMap->GetMap()- << 197 for(; itr != RunMap->GetMap()->end(); itr++) { 229 //// G4cout << " copy no.: " << << 198 G4cout << " copy no.: " << itr->first 230 //// << " Run Value : " < << 199 << " Run Value : " << *(itr->second) 231 //// << G4endl; << 200 << G4endl; 232 //// } << 201 } 233 } 202 } 234 } 203 } 235 } 204 } >> 205 >> 206 236 207