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 // 26 // 27 /// \file Dicom2Run.cc 27 /// \file Dicom2Run.cc 28 /// \brief Implementation of the Dicom2Run cla 28 /// \brief Implementation of the Dicom2Run class 29 29 30 //============================================ 30 //===================================================================== 31 /// 31 /// 32 /// (Description) 32 /// (Description) 33 /// Dicom2Run Class is for accumulating sco 33 /// Dicom2Run Class is for accumulating scored quantities which is 34 /// scored using G4MutiFunctionalDetector and 34 /// scored using G4MutiFunctionalDetector and G4VPrimitiveScorer. 35 /// Accumulation is done using G4THitsVector 35 /// Accumulation is done using G4THitsVector object. 36 /// 36 /// 37 /// The constructor Dicom2Run(const std::ve 37 /// The constructor Dicom2Run(const std::vector<G4String> mfdName) 38 /// needs a vector filled with MultiFunctiona 38 /// needs a vector filled with MultiFunctionalDetector names which 39 /// was assigned at instantiation of MultiFun 39 /// was assigned at instantiation of MultiFunctionalDetector(MFD). 40 /// Then Dicom2Run constructor automatically 40 /// Then Dicom2Run constructor automatically scans primitive scorers 41 /// in the MFD, and obtains collectionIDs of 41 /// in the MFD, and obtains collectionIDs of all collections associated 42 /// to those primitive scorers. Futhermore, t 42 /// to those primitive scorers. Futhermore, the G4THitsVector objects 43 /// for accumulating during a RUN are automat 43 /// for accumulating during a RUN are automatically created too. 44 /// (*) Collection Name is same as primitive 44 /// (*) Collection Name is same as primitive scorer name. 45 /// 45 /// 46 /// The resultant information is kept insid 46 /// The resultant information is kept inside Dicom2Run objects as 47 /// data members. 47 /// data members. 48 /// std::vector<G4String> fCollName; 48 /// std::vector<G4String> fCollName; // Collection Name, 49 /// std::vector<G4int> fCollID; 49 /// std::vector<G4int> fCollID; // Collection ID, 50 /// std::vector<Dicom2RunVector*> fRunMap; // 50 /// std::vector<Dicom2RunVector*> fRunMap; // HitsVector for RUN. 51 /// 51 /// 52 /// The resualtant HitsVector objects are obt 52 /// The resualtant HitsVector objects are obtain using access method, 53 /// GetHitsVector(..). 53 /// GetHitsVector(..). 54 /// 54 /// 55 //============================================ 55 //===================================================================== 56 56 57 #include "Dicom2Run.hh" 57 #include "Dicom2Run.hh" 58 << 59 #include "DicomDetectorConstruction.hh" 58 #include "DicomDetectorConstruction.hh" 60 59 61 #include "G4MultiFunctionalDetector.hh" << 62 #include "G4SDManager.hh" 60 #include "G4SDManager.hh" >> 61 #include "G4MultiFunctionalDetector.hh" 63 #include "G4VPrimitiveScorer.hh" 62 #include "G4VPrimitiveScorer.hh" 64 63 65 #include <cstdint> 64 #include <cstdint> 66 65 67 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 68 // 67 // 69 // Constructor. 68 // Constructor. 70 Dicom2Run::Dicom2Run() : DicomRun() {} << 69 Dicom2Run::Dicom2Run() >> 70 : DicomRun() >> 71 { } 71 72 72 //....oooOO0OOooo........oooOO0OOooo........oo 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 // 74 // 74 // Constructor. 75 // Constructor. 75 // (The vector of MultiFunctionalDetector na 76 // (The vector of MultiFunctionalDetector name has to given.) 76 Dicom2Run::Dicom2Run(const std::vector<G4Strin << 77 Dicom2Run::Dicom2Run(const std::vector<G4String> mfdName) >> 78 : DicomRun() 77 { 79 { 78 ConstructMFD(mfdName); << 80 ConstructMFD(mfdName); 79 } 81 } 80 82 81 //....oooOO0OOooo........oooOO0OOooo........oo 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 // 84 // 83 // Destructor 85 // Destructor 84 // clear all data members. 86 // clear all data members. 85 Dicom2Run::~Dicom2Run() 87 Dicom2Run::~Dicom2Run() 86 { 88 { 87 //--- Clear HitsVector for RUN << 89 //--- Clear HitsVector for RUN 88 for (std::size_t i = 0; i < fRunMap.size(); << 90 for(std::size_t i = 0; i < fRunMap.size(); ++i) 89 if (fRunMap[i]) fRunMap[i]->clear(); << 91 { 90 } << 92 if(fRunMap[i]) 91 fCollName.clear(); << 93 fRunMap[i]->clear(); 92 fCollID.clear(); << 94 } 93 fRunMap.clear(); << 95 fCollName.clear(); >> 96 fCollID.clear(); >> 97 fRunMap.clear(); 94 } 98 } 95 99 96 //....oooOO0OOooo........oooOO0OOooo........oo 100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 97 // 101 // 98 // Destructor 102 // Destructor 99 // clear all data members. 103 // clear all data members. 100 void Dicom2Run::ConstructMFD(const std::vector 104 void Dicom2Run::ConstructMFD(const std::vector<G4String>& mfdName) 101 { 105 { 102 DicomRun::ConstructMFD(mfdName); << 106 DicomRun::ConstructMFD(mfdName); 103 107 104 G4SDManager* SDman = G4SDManager::GetSDMpoin << 108 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 105 //========================================== << 109 //================================================= 106 // Initalize RunMaps for accumulation. << 110 // Initalize RunMaps for accumulation. 107 // Get CollectionIDs for HitCollections. << 111 // Get CollectionIDs for HitCollections. 108 //========================================== << 112 //================================================= 109 for (std::size_t idet = 0; idet < mfdName.si << 113 for(std::size_t idet = 0; idet < mfdName.size(); ++idet) 110 // Loop for all MFD. << 114 { 111 G4String detName = mfdName[idet]; << 115 // Loop for all MFD. 112 //--- Seek and Obtain MFD objects from SDm << 116 G4String detName = mfdName[idet]; 113 G4MultiFunctionalDetector* mfd = << 117 //--- Seek and Obtain MFD objects from SDmanager. 114 (G4MultiFunctionalDetector*)(SDman->Find << 118 G4MultiFunctionalDetector* mfd = 115 // << 119 (G4MultiFunctionalDetector*) 116 if (mfd) { << 120 (SDman->FindSensitiveDetector(detName)); 117 //--- Loop over the registered primitive << 118 for (G4int icol = 0; icol < mfd->GetNumb << 119 // Get Primitive Scorer object. << 120 G4VPrimitiveScorer* scorer = mfd->GetP << 121 // collection name and collectionID fo << 122 // where type of HitsCollection is G4T << 123 // of primitive scorer. << 124 // The collection name is given by : << 125 // <MFD name>/<Primitive Scorer name> << 126 G4String collectionName = scorer->GetN << 127 G4String fullCollectionName = detName << 128 G4int collectionID = SDman->GetCollect << 129 // 121 // 130 if (collectionID >= 0) { << 122 if(mfd) 131 G4cout << "++ " << fullCollectionNam << 123 { 132 // Store obtained HitsCollection inf << 124 //--- Loop over the registered primitive scorers. 133 // members. qnd creates new G4THitsV << 125 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); ++icol) 134 // quantities during RUN. << 126 { 135 fCollName.push_back(fullCollectionNa << 127 // Get Primitive Scorer object. 136 fCollID.push_back(collectionID); << 128 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol); 137 fRunMap.push_back(new Dicom2RunVecto << 129 // collection name and collectionID for HitsCollection, 138 } << 130 // where type of HitsCollection is G4THitsVector in case 139 else { << 131 // of primitive scorer. 140 G4cout << "** collection " << fullCo << 132 // The collection name is given by : >> 133 // <MFD name>/<Primitive Scorer name>. >> 134 G4String collectionName = scorer->GetName(); >> 135 G4String fullCollectionName = detName+"/"+collectionName; >> 136 G4int collectionID = SDman->GetCollectionID(fullCollectionName); >> 137 // >> 138 if(collectionID >= 0) >> 139 { >> 140 G4cout << "++ "<<fullCollectionName<< " id " << collectionID >> 141 << G4endl; >> 142 // Store obtained HitsCollection information into data >> 143 // members. qnd creates new G4THitsVector for accumulating >> 144 // quantities during RUN. >> 145 fCollName.push_back(fullCollectionName); >> 146 fCollID.push_back(collectionID); >> 147 fRunMap.push_back(new Dicom2RunVector(detName, >> 148 collectionName)); >> 149 } >> 150 else >> 151 { >> 152 G4cout << "** collection " << fullCollectionName << " not found. " >> 153 <<G4endl; >> 154 } >> 155 } 141 } 156 } 142 } << 143 } 157 } 144 } << 145 } 158 } 146 159 147 //....oooOO0OOooo........oooOO0OOooo........oo 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 148 // 161 // 149 // RecordEvent is called at end of event. 162 // RecordEvent is called at end of event. 150 // For scoring purpose, the resultant quantit 163 // For scoring purpose, the resultant quantity in a event, 151 // is accumulated during a Run. 164 // is accumulated during a Run. 152 void Dicom2Run::RecordEvent(const G4Event* aEv 165 void Dicom2Run::RecordEvent(const G4Event* aEvent) 153 { 166 { 154 DicomRun::RecordEvent(aEvent); << 167 DicomRun::RecordEvent(aEvent); 155 168 156 // G4cout << "Dicom Run :: Recording event " << 169 //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID() 157 //<< "..." << G4endl; << 170 //<< "..." << G4endl; 158 //============================= << 171 //============================= 159 // HitsCollection of This Event << 172 // HitsCollection of This Event 160 //============================ << 173 //============================ 161 G4HCofThisEvent* HCE = aEvent->GetHCofThisEv << 174 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent(); 162 if (!HCE) return; << 175 if (!HCE) 163 << 176 return; 164 //========================================== << 177 165 // Sum up HitsVector of this Event into Hit << 178 //======================================================= 166 //========================================== << 179 // Sum up HitsVector of this Event into HitsVector of this RUN 167 for (std::size_t i = 0; i < fCollID.size(); << 180 //======================================================= 168 // Loop over HitsCollection << 181 for(std::size_t i = 0; i < fCollID.size(); ++i) 169 G4THitsMap<G4double>* EvtMap = nullptr; << 182 { 170 if (fCollID[i] >= 0) { << 183 // Loop over HitsCollection 171 // Collection is attached to HCE << 184 G4THitsMap<G4double>* EvtMap = nullptr; 172 EvtMap = static_cast<G4THitsMap<G4double << 185 if(fCollID[i] >= 0) 173 } << 186 { 174 else { << 187 // Collection is attached to HCE 175 G4cout << " Error EvtMap Not Found " << << 188 EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i])); 176 } << 189 } >> 190 else >> 191 { >> 192 G4cout <<" Error EvtMap Not Found "<< i << G4endl; >> 193 } 177 194 178 // if valid pointer, add the pointer << 195 // if valid pointer, add the pointer 179 if (EvtMap) { << 196 if(EvtMap) 180 // for(auto itr = EvtMap->begin(); itr ! << 197 { 181 // G4cout << "adding " << *EvtMap->G << 198 //for(auto itr = EvtMap->begin(); itr != EvtMap->end(); ++itr) 182 //=== Sum up HitsVector of this event to << 199 // G4cout << "adding " << *EvtMap->GetObject(itr) << G4endl; 183 *fRunMap[i] += *EvtMap; << 200 //=== Sum up HitsVector of this event to HitsVector of RUN.=== >> 201 *fRunMap[i] += *EvtMap; >> 202 } 184 } 203 } 185 } << 186 } 204 } 187 205 188 //....oooOO0OOooo........oooOO0OOooo........oo 206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 189 // Merge hits map from threads 207 // Merge hits map from threads 190 void Dicom2Run::Merge(const G4Run* aRun) 208 void Dicom2Run::Merge(const G4Run* aRun) 191 { 209 { 192 DicomRun::Merge(aRun); << 210 DicomRun::Merge(aRun); 193 211 194 const Dicom2Run* localRun = static_cast<cons << 212 const Dicom2Run* localRun = static_cast<const Dicom2Run*>(aRun); 195 213 196 Copy(fCollName, localRun->fCollName); << 214 Copy(fCollName, localRun->fCollName); 197 Copy(fCollID, localRun->fCollID); << 215 Copy(fCollID, localRun->fCollID); 198 std::size_t ncopies = Copy(fRunMap, localRun << 216 G4int ncopies = G4int(Copy(fRunMap, localRun->fRunMap)); 199 // copy function returns the fRunMap size if << 217 // copy function returns the fRunMap size if all data is copied 200 // so this loop isn't executed the first tim << 218 // so this loop isn't executed the first time around 201 for (std::size_t i = ncopies; i < fRunMap.si << 219 for(G4int i = ncopies; i < G4int(fRunMap.size()); ++i) 202 *fRunMap[i] += *localRun->fRunMap[i]; << 220 *fRunMap[i] += *localRun->fRunMap[i]; 203 } 221 } 204 222 205 //....oooOO0OOooo........oooOO0OOooo........oo 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 206 //============================================ 224 //================================================================= 207 // Access method for HitsVector of the RUN 225 // Access method for HitsVector of the RUN 208 // 226 // 209 //----- 227 //----- 210 // Access HitsVector. 228 // Access HitsVector. 211 // By MultiFunctionalDetector name and Colle 229 // By MultiFunctionalDetector name and Collection Name. 212 Dicom2Run::Dicom2RunVector* Dicom2Run::GetHits << 230 Dicom2Run::Dicom2RunVector* 213 << 231 Dicom2Run::GetHitsVector(const G4String& detName, >> 232 const G4String& colName) const 214 { 233 { 215 G4String fullName = detName + "/" + colName; << 234 G4String fullName = detName+"/"+colName; 216 return GetHitsVector(fullName); << 235 return GetHitsVector(fullName); 217 } 236 } 218 237 219 //....oooOO0OOooo........oooOO0OOooo........oo 238 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 220 // Access HitsVector. 239 // Access HitsVector. 221 // By full description of collection name, th 240 // By full description of collection name, that is 222 // <MultiFunctional Detector Name>/<Primiti 241 // <MultiFunctional Detector Name>/<Primitive Scorer Name> 223 Dicom2Run::Dicom2RunVector* Dicom2Run::GetHits << 242 Dicom2Run::Dicom2RunVector* >> 243 Dicom2Run::GetHitsVector(const G4String& fullName) const 224 { 244 { 225 std::size_t Ncol = fCollName.size(); << 245 226 for (std::size_t i = 0; i < Ncol; ++i) { << 246 std::size_t Ncol = fCollName.size(); 227 if (fCollName[i] == fullName) { << 247 for(std::size_t i = 0; i < Ncol; ++i) 228 return fRunMap[i]; << 248 { >> 249 if(fCollName[i] == fullName) >> 250 { >> 251 return fRunMap[i]; >> 252 } 229 } 253 } 230 } << 231 254 232 G4Exception("Dicom2Run", fullName.c_str(), J << 255 G4Exception("Dicom2Run", fullName.c_str(), JustWarning, 233 "GetHitsVector failed to locate << 256 "GetHitsVector failed to locate the requested HitsVector"); 234 return nullptr; << 257 return nullptr; 235 } 258 } 236 259