Geant4  9.6.p02
 All Classes 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 //
28 //
29 //
30 // $Id$
31 //
32 
33 //=====================================================================
58 //=====================================================================
59 
60 #include "DicomRun.hh"
61 #include "G4SDManager.hh"
62 
64 #include "G4VPrimitiveScorer.hh"
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 //
68 // Constructor.
69 // (The vector of MultiFunctionalDetector name has to given.)
70 DicomRun::DicomRun(const std::vector<G4String> mfdName): G4Run()
71 {
73  //=================================================
74  // Initalize RunMaps for accumulation.
75  // Get CollectionIDs for HitCollections.
76  //=================================================
77  G4int Nmfd = mfdName.size();
78  for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD.
79  G4String detName = mfdName[idet];
80  //--- Seek and Obtain MFD objects from SDmanager.
83  //
84  if ( mfd ){
85  //--- Loop over the registered primitive scorers.
86  for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
87  // Get Primitive Scorer object.
88  G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
89  // collection name and collectionID for HitsCollection,
90  // where type of HitsCollection is G4THitsMap in case of primitive scorer.
91  // The collection name is given by <MFD name>/<Primitive Scorer name>.
92  G4String collectionName = scorer->GetName();
93  G4String fullCollectionName = detName+"/"+collectionName;
94  G4int collectionID = SDman->GetCollectionID(fullCollectionName);
95  //
96  if ( collectionID >= 0 ){
97  G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
98  // Store obtained HitsCollection information into data members.
99  // And, creates new G4THitsMap for accumulating quantities during RUN.
100  fCollName.push_back(fullCollectionName);
101  fCollID.push_back(collectionID);
102  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
103  }else{
104  G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
105  }
106  }
107  }
108  }
109 }
110 
111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112 //
113 // Destructor
114 // clear all data members.
116 {
117  //--- Clear HitsMap for RUN
118  G4int Nmap = fRunMap.size();
119  for ( G4int i = 0; i < Nmap; i++){
120  if(fRunMap[i] ) fRunMap[i]->clear();
121  }
122  fCollName.clear();
123  fCollID.clear();
124  fRunMap.clear();
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 //
129 // RecordEvent is called at end of event.
130 // For scoring purpose, the resultant quantity in a event,
131 // is accumulated during a Run.
132 void DicomRun::RecordEvent(const G4Event* aEvent)
133 {
134  numberOfEvent++; // This is an original line.
135 
136  //=============================
137  // HitsCollection of This Event
138  //============================
139  G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
140  if (!HCE) return;
141 
142  //=======================================================
143  // Sum up HitsMap of this Event into HitsMap of this RUN
144  //=======================================================
145  G4int Ncol = fCollID.size();
146  for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
147  G4THitsMap<G4double>* EvtMap=0;
148  if ( fCollID[i] >= 0 ){ // Collection is attached to HCE
149  EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID[i]));
150  }else{
151  G4cout <<" Error EvtMap Not Found "<< i << G4endl;
152  }
153  if ( EvtMap ) {
154  //=== Sum up HitsMap of this event to HitsMap of RUN.===
155  *fRunMap[i] += *EvtMap;
156  //======================================================
157  }
158  }
159 
160 
161 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 //=================================================================
165 // Access method for HitsMap of the RUN
166 //
167 //-----
168 // Access HitsMap.
169 // By MultiFunctionalDetector name and Collection Name.
171  const G4String& colName){
172  G4String fullName = detName+"/"+colName;
173  return GetHitsMap(fullName);
174 }
175 
176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
177 // Access HitsMap.
178 // By full description of collection name, that is
179 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
181  G4int Ncol = fCollName.size();
182  for ( G4int i = 0; i < Ncol; i++){
183  if ( fCollName[i] == fullName ){
184  return fRunMap[i];
185  }
186  }
187  return NULL;
188 }
189