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