Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: DicomRun.cc 74809 2013-10-22 09:49:26Z gcosmo $
27 //
28 /// \file medical/DICOM/src/DicomRun.cc
29 /// \brief Implementation of the DicomRun class
30 
31 //=====================================================================
32 ///
33 /// (Description)
34 /// DicomRun Class is for accumulating scored quantities which is
35 /// scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
36 /// Accumulation is done using G4THitsMap object.
37 ///
38 /// The constructor DicomRun(const std::vector<G4String> mfdName)
39 /// needs a vector filled with MultiFunctionalDetector names which
40 /// was assigned at instantiation of MultiFunctionalDetector(MFD).
41 /// Then DicomRun constructor automatically scans primitive scorers
42 /// in the MFD, and obtains collectionIDs of all collections associated
43 /// to those primitive scorers. Futhermore, the G4THitsMap objects
44 /// for accumulating during a RUN are automatically created too.
45 /// (*) Collection Name is same as primitive scorer name.
46 ///
47 /// The resultant information is kept inside DicomRun objects as
48 /// data members.
49 /// std::vector<G4String> fCollName; // Collection Name,
50 /// std::vector<G4int> fCollID; // Collection ID,
51 /// std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
52 ///
53 /// The resualtant HitsMap objects are obtain using access method,
54 /// GetHitsMap(..).
55 ///
56 //=====================================================================
57 
58 #include "DicomRun.hh"
59 #include "G4SDManager.hh"
60 
62 #include "G4VPrimitiveScorer.hh"
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 //
66 // Constructor.
68 : G4Run()
69 { }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 //
73 // Constructor.
74 // (The vector of MultiFunctionalDetector name has to given.)
75 DicomRun::DicomRun(const std::vector<G4String> mfdName): G4Run()
76 {
77  ConstructMFD(mfdName);
78 }
79 
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 //
82 // Destructor
83 // clear all data members.
85 {
86  //--- Clear HitsMap for RUN
87  G4int Nmap = fRunMap.size();
88  for ( G4int i = 0; i < Nmap; i++){
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.
100 void DicomRun::ConstructMFD(const std::vector<G4String>& mfdName)
101 {
102 
104  //=================================================
105  // Initalize RunMaps for accumulation.
106  // Get CollectionIDs for HitCollections.
107  //=================================================
108  G4int Nmfd = mfdName.size();
109  for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD.
110  G4String detName = mfdName[idet];
111  //--- Seek and Obtain MFD objects from SDmanager.
114  //
115  if ( mfd ){
116  //--- Loop over the registered primitive scorers.
117  for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
118  // Get Primitive Scorer object.
119  G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
120  // collection name and collectionID for HitsCollection,
121  // where type of HitsCollection is G4THitsMap in case of primitive scorer.
122  // The collection name is given by <MFD name>/<Primitive Scorer name>.
123  G4String collectionName = scorer->GetName();
124  G4String fullCollectionName = detName+"/"+collectionName;
125  G4int collectionID = SDman->GetCollectionID(fullCollectionName);
126  //
127  if ( collectionID >= 0 ){
128  G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
129  // Store obtained HitsCollection information into data members.
130  // And, creates new G4THitsMap for accumulating quantities during RUN.
131  fCollName.push_back(fullCollectionName);
132  fCollID.push_back(collectionID);
133  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
134  } else {
135  G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
136  }
137  }
138  }
139  }
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 //
144 // RecordEvent is called at end of event.
145 // For scoring purpose, the resultant quantity in a event,
146 // is accumulated during a Run.
147 void DicomRun::RecordEvent(const G4Event* aEvent)
148 {
149  numberOfEvent++; // This is an original line.
150 
151  //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID() << "..." << G4endl;
152  //=============================
153  // HitsCollection of This Event
154  //============================
155  G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
156  if (!HCE) return;
157 
158  //=======================================================
159  // Sum up HitsMap of this Event into HitsMap of this RUN
160  //=======================================================
161  G4int Ncol = fCollID.size();
162  for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
163  G4THitsMap<G4double>* EvtMap = 0;
164  if ( fCollID[i] >= 0 ){ // Collection is attached to HCE
165  EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i]));
166  }else{
167  G4cout <<" Error EvtMap Not Found "<< i << G4endl;
168  }
169  if ( EvtMap ) {
170  //=== Sum up HitsMap of this event to HitsMap of RUN.===
171  *fRunMap[i] += *EvtMap;
172  //G4cout << "Summing EvtMap into RunMap at " << i << "..." << G4endl;
173  //======================================================
174  } //else {
175  //G4cout << "Null pointer to EvtMap at " << i << "..." << G4endl;
176  //}
177  }
178 
179  G4Run::RecordEvent(aEvent);
180 
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 // Merge hits map from threads
185 void DicomRun::Merge(const G4Run* aRun)
186 {
187  const DicomRun* localRun = static_cast<const DicomRun*>(aRun);
188  copy(fCollName, localRun->fCollName);
189  copy(fCollID, localRun->fCollID);
190  unsigned ncopies = copy(fRunMap, localRun->fRunMap);
191  // copy function returns the fRunMap size if all data is copied
192  // so this loop isn't executed the first time around
193  std::cout << "DicomRun :: Num copies = " << ncopies << G4endl;
194  for(unsigned i = ncopies; i < fRunMap.size(); ++i) {
195  *fRunMap[i] += *localRun->fRunMap[i];
196  }
197  G4Run::Merge(aRun);
198 }
199 
200 
201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
202 //=================================================================
203 // Access method for HitsMap of the RUN
204 //
205 //-----
206 // Access HitsMap.
207 // By MultiFunctionalDetector name and Collection Name.
209  const G4String& colName) const
210 {
211  G4String fullName = detName+"/"+colName;
212  return GetHitsMap(fullName);
213 }
214 
215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
216 // Access HitsMap.
217 // By full description of collection name, that is
218 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
220 {
221 
222  //G4THitsMap<G4double>* hitsmap = 0;
223 
224  G4int Ncol = fCollName.size();
225  for ( G4int i = 0; i < Ncol; i++){
226  if ( fCollName[i] == fullName ){
227  return fRunMap[i];
228  //if(hitsmap) { *hitsmap += *fRunMap[i]; }
229  //if(!hitsmap) { hitsmap = fRunMap[i]; }
230  }
231  }
232 
233  //if(hitsmap) { return hitsmap; }
234 
235  G4Exception("DicomRun", fullName.c_str(), JustWarning,
236  "GetHitsMap failed to locate the requested HitsMap");
237  return NULL;
238 }
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int numberOfEvent
Definition: G4Run.hh:59
G4String GetName() const
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
virtual void Merge(const G4Run *)
Definition: DicomRun.cc:185
virtual void RecordEvent(const G4Event *)
Definition: DicomRun.cc:147
void ConstructMFD(const std::vector< G4String > &)
Definition: DicomRun.cc:100
virtual ~DicomRun()
Definition: DicomRun.cc:84
int G4int
Definition: G4Types.hh:78
Definition of the DicomRun class.
void copy(std::vector< T > &main, const std::vector< T > &data)
Definition: DicomRun.hh:91
G4GLOB_DLL std::ostream G4cout
DicomRun()
Definition: DicomRun.cc:67
G4VPrimitiveScorer * GetPrimitive(G4int id) const
Definition: G4Run.hh:46
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:124
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual void RecordEvent(const G4Event *)
Definition: G4Run.cc:51
#define G4endl
Definition: G4ios.hh:61
G4THitsMap< G4double > * GetHitsMap(G4int i) const
Definition: DicomRun.hh:71
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:174