Loading...
Searching...
No Matches
DicomRun.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27/// \file medical/DICOM/src/DicomRun.cc
28/// \brief Implementation of the DicomRun class
29
30//=====================================================================
31///
32/// (Description)
33/// DicomRun Class is for accumulating scored quantities which is
34/// scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
35/// Accumulation is done using G4THitsMap object.
36///
37/// The constructor DicomRun(const std::vector<G4String> mfdName)
38/// needs a vector filled with MultiFunctionalDetector names which
39/// was assigned at instantiation of MultiFunctionalDetector(MFD).
40/// Then DicomRun constructor automatically scans primitive scorers
41/// in the MFD, and obtains collectionIDs of all collections associated
42/// to those primitive scorers. Futhermore, the G4THitsMap objects
43/// for accumulating during a RUN are automatically created too.
44/// (*) Collection Name is same as primitive scorer name.
45///
46/// The resultant information is kept inside DicomRun objects as
47/// data members.
48/// std::vector<G4String> fCollName; // Collection Name,
49/// std::vector<G4int> fCollID; // Collection ID,
50/// std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
51///
52/// The resualtant HitsMap objects are obtain using access method,
53/// GetHitsMap(..).
54///
55//=====================================================================
56
57#include "DicomRun.hh"
58#include "G4SDManager.hh"
59
60#include "G4MultiFunctionalDetector.hh"
61#include "G4VPrimitiveScorer.hh"
62
63//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64//
65// Constructor.
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71//
72// Constructor.
73// (The vector of MultiFunctionalDetector name has to given.)
74DicomRun::DicomRun(const std::vector<G4String> mfdName): G4Run()
75{
76 ConstructMFD(mfdName);
77}
78
79//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80//
81// Destructor
82// clear all data members.
84{
85 //--- Clear HitsMap for RUN
86 size_t Nmap = fRunMap.size();
87 for ( size_t i = 0; i < Nmap; ++i)
88 {
89 if(fRunMap[i] ) fRunMap[i]->clear();
90 }
91 fCollName.clear();
92 fCollID.clear();
93 fRunMap.clear();
94}
95
96//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
97//
98// Destructor
99// clear all data members.
100void DicomRun::ConstructMFD(const std::vector<G4String>& mfdName)
101{
102
103 G4SDManager* SDman = G4SDManager::GetSDMpointer();
104 //=================================================
105 // Initalize RunMaps for accumulation.
106 // Get CollectionIDs for HitCollections.
107 //=================================================
108 size_t Nmfd = mfdName.size();
109 for ( size_t idet = 0; idet < Nmfd ; ++idet) // Loop for all MFD.
110 {
111 G4String detName = mfdName[idet];
112 //--- Seek and Obtain MFD objects from SDmanager.
114 (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
115 //
116 if ( mfd )
117 {
118 //--- Loop over the registered primitive scorers.
119 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); ++icol)
120 {
121 // Get Primitive Scorer object.
122 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
123 // collection name and collectionID for HitsCollection,
124 // where type of HitsCollection is G4THitsMap in case
125 // of primitive scorer.
126 // The collection name is given by <MFD name>/<Primitive
127 // Scorer name>.
128 G4String collectionName = scorer->GetName();
129 G4String fullCollectionName = detName+"/"+collectionName;
130 G4int collectionID = SDman->GetCollectionID(fullCollectionName);
131 //
132 if ( collectionID >= 0 )
133 {
134 G4cout << "++ "<<fullCollectionName<< " id " << collectionID
135 << G4endl;
136 // Store obtained HitsCollection information into data members.
137 // And, creates new G4THitsMap for accumulating quantities during RUN.
138 fCollName.push_back(fullCollectionName);
139 fCollID.push_back(collectionID);
140 fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
141 }
142 else
143 {
144 G4cout << "** collection " << fullCollectionName << " not found. "
145 <<G4endl;
146 }
147 }
148 }
149 }
150}
151
152//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
153//
154// RecordEvent is called at end of event.
155// For scoring purpose, the resultant quantity in a event,
156// is accumulated during a Run.
158{
159 // disable below because this is done in G4Run::RecordEvent(aEvent);
160 //numberOfEvent++; // This is an original line.
161
162 //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID()
163 //<< "..." << G4endl;
164 //=============================
165 // HitsCollection of This Event
166 //============================
167 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
168 if (!HCE) return;
169
170 //=======================================================
171 // Sum up HitsMap of this Event into HitsMap of this RUN
172 //=======================================================
173 size_t Ncol = fCollID.size();
174 for ( size_t i = 0; i < Ncol ; ++i ) // Loop over HitsCollection
175 {
176 G4THitsMap<G4double>* EvtMap = nullptr;
177 if ( fCollID[i] >= 0 ) // Collection is attached to HCE
178 {
179 EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i]));
180 }
181 else
182 {
183 G4cout <<" Error EvtMap Not Found "<< i << G4endl;
184 }
185 if ( EvtMap )
186 {
187 //=== Sum up HitsMap of this event to HitsMap of RUN.===
188 *fRunMap[i] += *EvtMap;
189 //G4cout << "Summing EvtMap into RunMap at " << i << "..." << G4endl;
190 //======================================================
191 } //else {
192 //G4cout << "Null pointer to EvtMap at " << i << "..." << G4endl;
193 //}
194 }
195
196 G4Run::RecordEvent(aEvent);
197
198}
199
200//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
201// Merge hits map from threads
202void DicomRun::Merge(const G4Run* aRun)
203{
204 const DicomRun* localRun = static_cast<const DicomRun*>(aRun);
205 Copy(fCollName, localRun->fCollName);
206 Copy(fCollID, localRun->fCollID);
207 size_t ncopies = Copy(fRunMap, localRun->fRunMap);
208 // copy function returns the fRunMap size if all data is copied
209 // so this loop isn't executed the first time around
210 for(size_t i = ncopies; i < fRunMap.size(); ++i)
211 {
212 *fRunMap[i] += *localRun->fRunMap[i];
213 }
214 G4Run::Merge(aRun);
215}
216
217//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
218//=================================================================
219// Access method for HitsMap of the RUN
220//
221//-----
222// Access HitsMap.
223// By MultiFunctionalDetector name and Collection Name.
225 const G4String& colName) const
226{
227 G4String fullName = detName+"/"+colName;
228 return GetHitsMap(fullName);
229}
230
231//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
232// Access HitsMap.
233// By full description of collection name, that is
234// <MultiFunctional Detector Name>/<Primitive Scorer Name>
236{
237
238 //G4THitsMap<G4double>* hitsmap = 0;
239
240 size_t Ncol = fCollName.size();
241 for ( size_t i = 0; i < Ncol; ++i)
242 {
243 if ( fCollName[i] == fullName )
244 {
245 return fRunMap[i];
246 //if(hitsmap) { *hitsmap += *fRunMap[i]; }
247 //if(!hitsmap) { hitsmap = fRunMap[i]; }
248 }
249 }
250
251 G4Exception("DicomRun", fullName.c_str(), JustWarning,
252 "GetHitsMap failed to locate the requested HitsMap");
253 return nullptr;
254}
Definition of the DicomRun class.
void Copy(std::vector< T > &main, const std::vector< T > &data)
Definition DicomRun.hh:91
DicomRun class.
std::vector< G4String > fCollName
Definition DicomRun.hh:82
DicomRun()
(Description) DicomRun Class is for accumulating scored quantities which is scored using G4MutiFuncti...
Definition DicomRun.cc:66
std::vector< G4THitsMap< G4double > * > fRunMap
Definition DicomRun.hh:84
virtual ~DicomRun()
Definition DicomRun.cc:83
G4THitsMap< G4double > * GetHitsMap(G4int i) const
Definition DicomRun.hh:71
virtual void RecordEvent(const G4Event *)
Definition DicomRun.cc:157
std::vector< G4int > fCollID
Definition DicomRun.hh:83
virtual void Merge(const G4Run *)
Definition DicomRun.cc:202
void ConstructMFD(const std::vector< G4String > &)
Definition DicomRun.cc:100

Applications | User Support | Publications | Collaboration