Geant4  10.02
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 92820 2015-09-17 15:22:14Z gcosmo $
27 //
30 
31 //=====================================================================
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
122  // of primitive scorer.
123  // The collection name is given by <MFD name>/<Primitive
124  // Scorer name>.
125  G4String collectionName = scorer->GetName();
126  G4String fullCollectionName = detName+"/"+collectionName;
127  G4int collectionID = SDman->GetCollectionID(fullCollectionName);
128  //
129  if ( collectionID >= 0 ){
130  G4cout << "++ "<<fullCollectionName<< " id " << collectionID
131  << G4endl;
132  // Store obtained HitsCollection information into data members.
133  // And, creates new G4THitsMap for accumulating quantities during RUN.
134  fCollName.push_back(fullCollectionName);
135  fCollID.push_back(collectionID);
136  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
137  } else {
138  G4cout << "** collection " << fullCollectionName << " not found. "
139  <<G4endl;
140  }
141  }
142  }
143  }
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 //
148 // RecordEvent is called at end of event.
149 // For scoring purpose, the resultant quantity in a event,
150 // is accumulated during a Run.
151 void DicomRun::RecordEvent(const G4Event* aEvent)
152 {
153  numberOfEvent++; // This is an original line.
154 
155  //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID()
156  //<< "..." << G4endl;
157  //=============================
158  // HitsCollection of This Event
159  //============================
160  G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
161  if (!HCE) return;
162 
163  //=======================================================
164  // Sum up HitsMap of this Event into HitsMap of this RUN
165  //=======================================================
166  G4int Ncol = fCollID.size();
167  for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
168  G4THitsMap<G4double>* EvtMap = 0;
169  if ( fCollID[i] >= 0 ){ // Collection is attached to HCE
170  EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i]));
171  }else{
172  G4cout <<" Error EvtMap Not Found "<< i << G4endl;
173  }
174  if ( EvtMap ) {
175  //=== Sum up HitsMap of this event to HitsMap of RUN.===
176  *fRunMap[i] += *EvtMap;
177  //G4cout << "Summing EvtMap into RunMap at " << i << "..." << G4endl;
178  //======================================================
179  } //else {
180  //G4cout << "Null pointer to EvtMap at " << i << "..." << G4endl;
181  //}
182  }
183 
184  G4Run::RecordEvent(aEvent);
185 
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 // Merge hits map from threads
190 void DicomRun::Merge(const G4Run* aRun)
191 {
192  const DicomRun* localRun = static_cast<const DicomRun*>(aRun);
193  Copy(fCollName, localRun->fCollName);
194  Copy(fCollID, localRun->fCollID);
195  unsigned ncopies = Copy(fRunMap, localRun->fRunMap);
196  // copy function returns the fRunMap size if all data is copied
197  // so this loop isn't executed the first time around
198  G4cout << "DicomRun :: Num copies = " << ncopies << G4endl;
199  for(unsigned i = ncopies; i < fRunMap.size(); ++i) {
200  *fRunMap[i] += *localRun->fRunMap[i];
201  }
202  G4Run::Merge(aRun);
203 }
204 
205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
206 //=================================================================
207 // Access method for HitsMap of the RUN
208 //
209 //-----
210 // Access HitsMap.
211 // By MultiFunctionalDetector name and Collection Name.
213  const G4String& colName) const
214 {
215  G4String fullName = detName+"/"+colName;
216  return GetHitsMap(fullName);
217 }
218 
219 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
220 // Access HitsMap.
221 // By full description of collection name, that is
222 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
224 {
225 
226  //G4THitsMap<G4double>* hitsmap = 0;
227 
228  G4int Ncol = fCollName.size();
229  for ( G4int i = 0; i < Ncol; i++){
230  if ( fCollName[i] == fullName ){
231  return fRunMap[i];
232  //if(hitsmap) { *hitsmap += *fRunMap[i]; }
233  //if(!hitsmap) { hitsmap = fRunMap[i]; }
234  }
235  }
236 
237  //if(hitsmap) { return hitsmap; }
238 
239  G4Exception("DicomRun", fullName.c_str(), JustWarning,
240  "GetHitsMap failed to locate the requested HitsMap");
241  return NULL;
242 }
DicomRun class.
Definition: DicomRun.hh:50
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int numberOfEvent
Definition: G4Run.hh:59
G4String GetName() const
G4VHitsCollection * GetHC(G4int i)
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
virtual void Merge(const G4Run *)
Definition: DicomRun.cc:190
void Copy(std::vector< T > &main, const std::vector< T > &data)
Definition: DicomRun.hh:91
virtual void RecordEvent(const G4Event *)
Definition: DicomRun.cc:151
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.
G4GLOB_DLL std::ostream G4cout
DicomRun()
(Description) DicomRun Class is for accumulating scored quantities which is scored using G4MutiFuncti...
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
std::vector< G4THitsMap< G4double > * > fRunMap
Definition: DicomRun.hh:83
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:185
std::vector< G4String > fCollName
Definition: DicomRun.hh:81
std::vector< G4int > fCollID
Definition: DicomRun.hh:82