Loading...
Searching...
No Matches
Dicom2Run.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 Dicom2Run.cc
28/// \brief Implementation of the Dicom2Run class
29
30//=====================================================================
31///
32/// (Description)
33/// Dicom2Run Class is for accumulating scored quantities which is
34/// scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
35/// Accumulation is done using G4THitsVector object.
36///
37/// The constructor Dicom2Run(const std::vector<G4String> mfdName)
38/// needs a vector filled with MultiFunctionalDetector names which
39/// was assigned at instantiation of MultiFunctionalDetector(MFD).
40/// Then Dicom2Run constructor automatically scans primitive scorers
41/// in the MFD, and obtains collectionIDs of all collections associated
42/// to those primitive scorers. Futhermore, the G4THitsVector 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 Dicom2Run objects as
47/// data members.
48/// std::vector<G4String> fCollName; // Collection Name,
49/// std::vector<G4int> fCollID; // Collection ID,
50/// std::vector<Dicom2RunVector*> fRunMap; // HitsVector for RUN.
51///
52/// The resualtant HitsVector objects are obtain using access method,
53/// GetHitsVector(..).
54///
55//=====================================================================
56
57#include "Dicom2Run.hh"
59
60#include "G4SDManager.hh"
61#include "G4MultiFunctionalDetector.hh"
62#include "G4VPrimitiveScorer.hh"
63
64#include <cstdint>
65
66//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67//
68// Constructor.
72
73//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74//
75// Constructor.
76// (The vector of MultiFunctionalDetector name has to given.)
77Dicom2Run::Dicom2Run(const std::vector<G4String> mfdName)
78: DicomRun()
79{
80 ConstructMFD(mfdName);
81}
82
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84//
85// Destructor
86// clear all data members.
88{
89 //--- Clear HitsVector for RUN
90 for(std::size_t i = 0; i < fRunMap.size(); ++i)
91 {
92 if(fRunMap[i])
93 fRunMap[i]->clear();
94 }
95 fCollName.clear();
96 fCollID.clear();
97 fRunMap.clear();
98}
99
100//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101//
102// Destructor
103// clear all data members.
104void Dicom2Run::ConstructMFD(const std::vector<G4String>& mfdName)
105{
106 DicomRun::ConstructMFD(mfdName);
107
108 G4SDManager* SDman = G4SDManager::GetSDMpointer();
109 //=================================================
110 // Initalize RunMaps for accumulation.
111 // Get CollectionIDs for HitCollections.
112 //=================================================
113 for(std::size_t idet = 0; idet < mfdName.size(); ++idet)
114 {
115 // Loop for all MFD.
116 G4String detName = mfdName[idet];
117 //--- Seek and Obtain MFD objects from SDmanager.
120 (SDman->FindSensitiveDetector(detName));
121 //
122 if(mfd)
123 {
124 //--- Loop over the registered primitive scorers.
125 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); ++icol)
126 {
127 // Get Primitive Scorer object.
128 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
129 // collection name and collectionID for HitsCollection,
130 // where type of HitsCollection is G4THitsVector in case
131 // of primitive scorer.
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 }
156 }
157 }
158}
159
160//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161//
162// RecordEvent is called at end of event.
163// For scoring purpose, the resultant quantity in a event,
164// is accumulated during a Run.
166{
167 DicomRun::RecordEvent(aEvent);
168
169 //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID()
170 //<< "..." << G4endl;
171 //=============================
172 // HitsCollection of This Event
173 //============================
174 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
175 if (!HCE)
176 return;
177
178 //=======================================================
179 // Sum up HitsVector of this Event into HitsVector of this RUN
180 //=======================================================
181 for(std::size_t i = 0; i < fCollID.size(); ++i)
182 {
183 // Loop over HitsCollection
184 G4THitsMap<G4double>* EvtMap = nullptr;
185 if(fCollID[i] >= 0)
186 {
187 // Collection is attached to HCE
188 EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i]));
189 }
190 else
191 {
192 G4cout <<" Error EvtMap Not Found "<< i << G4endl;
193 }
194
195 // if valid pointer, add the pointer
196 if(EvtMap)
197 {
198 //for(auto itr = EvtMap->begin(); itr != EvtMap->end(); ++itr)
199 // G4cout << "adding " << *EvtMap->GetObject(itr) << G4endl;
200 //=== Sum up HitsVector of this event to HitsVector of RUN.===
201 *fRunMap[i] += *EvtMap;
202 }
203 }
204}
205
206//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
207// Merge hits map from threads
208void Dicom2Run::Merge(const G4Run* aRun)
209{
210 DicomRun::Merge(aRun);
211
212 const Dicom2Run* localRun = static_cast<const Dicom2Run*>(aRun);
213
214 Copy(fCollName, localRun->fCollName);
215 Copy(fCollID, localRun->fCollID);
216 std::size_t ncopies = Copy(fRunMap, localRun->fRunMap);
217 // copy function returns the fRunMap size if all data is copied
218 // so this loop isn't executed the first time around
219 for(std::size_t i = ncopies; i < fRunMap.size(); ++i)
220 *fRunMap[i] += *localRun->fRunMap[i];
221}
222
223//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224//=================================================================
225// Access method for HitsVector of the RUN
226//
227//-----
228// Access HitsVector.
229// By MultiFunctionalDetector name and Collection Name.
232 const G4String& colName) const
233{
234 G4String fullName = detName+"/"+colName;
235 return GetHitsVector(fullName);
236}
237
238//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
239// Access HitsVector.
240// By full description of collection name, that is
241// <MultiFunctional Detector Name>/<Primitive Scorer Name>
243Dicom2Run::GetHitsVector(const G4String& fullName) const
244{
245
246 std::size_t Ncol = fCollName.size();
247 for(std::size_t i = 0; i < Ncol; ++i)
248 {
249 if(fCollName[i] == fullName)
250 {
251 return fRunMap[i];
252 }
253 }
254
255 G4Exception("Dicom2Run", fullName.c_str(), JustWarning,
256 "GetHitsVector failed to locate the requested HitsVector");
257 return nullptr;
258}
Definition of the Dicom2Run class.
Definition of the DicomDetectorConstruction class.
void Copy(std::vector< T > &main, const std::vector< T > &data)
Definition DicomRun.hh:91
Dicom2Run class.
Definition Dicom2Run.hh:53
Dicom2Run()
(Description) Dicom2Run Class is for accumulating scored quantities which is scored using G4MutiFunct...
Definition Dicom2Run.cc:69
virtual void RecordEvent(const G4Event *)
Definition Dicom2Run.cc:165
std::vector< G4int > fCollID
Definition Dicom2Run.hh:87
virtual void Merge(const G4Run *)
Definition Dicom2Run.cc:208
G4VTHitsVector< G4StatAnalysis, std::vector< G4StatAnalysis > > Dicom2RunVector
Definition Dicom2Run.hh:56
std::vector< G4String > fCollName
Definition Dicom2Run.hh:86
void ConstructMFD(const std::vector< G4String > &)
Definition Dicom2Run.cc:104
virtual ~Dicom2Run()
Definition Dicom2Run.cc:87
Dicom2RunVector * GetHitsVector(G4int i) const
Definition Dicom2Run.hh:75
std::vector< Dicom2RunVector * > fRunMap
Definition Dicom2Run.hh:88
DicomRun class.
virtual void RecordEvent(const G4Event *)
Definition DicomRun.cc:157
virtual void Merge(const G4Run *)
Definition DicomRun.cc:202
void ConstructMFD(const std::vector< G4String > &)
Definition DicomRun.cc:100

Applications | User Support | Publications | Collaboration