Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
RE02Run.cc
이 파일의 문서화 페이지로 가기
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: RE02Run.cc 108892 2018-03-15 07:06:47Z gcosmo $
31 //
32 
33 //=====================================================================
34 //
35 // (Description)
36 // RE02Run Class is for accumulating scored quantities which is
37 // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
38 // Accumulation is done using G4THitsMap object.
39 //
40 // The constructor RE02Run(const std::vector<G4String> mfdName)
41 // needs a vector filled with MultiFunctionalDetector names which
42 // was assigned at instantiation of MultiFunctionalDetector(MFD).
43 // Then RE02Run constructor automatically scans primitive scorers
44 // in the MFD, and obtains collectionIDs of all collections associated
45 // to those primitive scorers. Futhermore, the G4THitsMap objects
46 // for accumulating during a RUN are automatically created too.
47 // (*) Collection Name is same as primitive scorer name.
48 //
49 // The resultant information is kept inside RE02Run objects as
50 // data members.
51 // std::vector<G4String> fCollName; // Collection Name,
52 // std::vector<G4int> fCollID; // Collection ID,
53 // std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
54 //
55 // The resualtant HitsMap objects are obtain using access method,
56 // GetHitsMap(..).
57 //
58 //=====================================================================
59 
60 #include "RE02Run.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 RE02Run::RE02Run(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
91  // scorer.
92  // The collection name is given by <MFD name>/<Primitive Scorer name>.
93  G4String collectionName = scorer->GetName();
94  G4String fullCollectionName = detName+"/"+collectionName;
95  G4int collectionID = pSDman->GetCollectionID(fullCollectionName);
96  //
97  if ( collectionID >= 0 ){
98  G4cout << "++ "<<fullCollectionName<< " id " << collectionID
99  << G4endl;
100  // Store obtained HitsCollection information into data members.
101  // And, creates new G4THitsMap for accumulating quantities during RUN.
102  fCollName.push_back(fullCollectionName);
103  fCollID.push_back(collectionID);
104  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
105  }else{
106  G4cout << "** collection " << fullCollectionName << " not found. "
107  << G4endl;
108  }
109  }
110  }
111  }
112 }
113 
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
115 //
116 // Destructor
117 // clear all data members.
119 {
120  //--- Clear HitsMap for RUN
121  G4int nMap = fRunMap.size();
122  for ( G4int i = 0; i < nMap; i++){
123  if(fRunMap[i] ) fRunMap[i]->clear();
124  }
125  fCollName.clear();
126  fCollID.clear();
127  fRunMap.clear();
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 //
132 // RecordEvent is called at end of event.
133 // For scoring purpose, the resultant quantity in a event,
134 // is accumulated during a Run.
135 void RE02Run::RecordEvent(const G4Event* aEvent)
136 {
137  numberOfEvent++; // This is an original line.
138 
139  //=============================
140  // HitsCollection of This Event
141  //============================
142  G4HCofThisEvent* pHCE = aEvent->GetHCofThisEvent();
143  if (!pHCE) return;
144 
145  //=======================================================
146  // Sum up HitsMap of this Event into HitsMap of this RUN
147  //=======================================================
148  G4int nCol = fCollID.size();
149  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
150  G4THitsMap<G4double>* evtMap=0;
151  if ( fCollID[i] >= 0 ){ // Collection is attached to pHCE
152  evtMap = (G4THitsMap<G4double>*)(pHCE->GetHC(fCollID[i]));
153  }else{
154  G4cout <<" Error evtMap Not Found "<< i << G4endl;
155  }
156  if ( evtMap ) {
157  //=== Sum up HitsMap of this event to HitsMap of RUN.===
158  *fRunMap[i] += *evtMap;
159  //======================================================
160  }
161  }
162 }
163 
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
166 void RE02Run::Merge(const G4Run * aRun) {
167  const RE02Run * localRun = static_cast<const RE02Run *>(aRun);
168 
169  //=======================================================
170  // Merge HitsMap of working threads
171  //=======================================================
172  G4int nCol = localRun->fCollID.size();
173  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
174  if ( localRun->fCollID[i] >= 0 ){
175  *fRunMap[i] += *localRun->fRunMap[i];
176  }
177  }
178 
179  G4Run::Merge(aRun);
180 }
181 
182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
183 //
184 // Access method for HitsMap of the RUN
185 //
186 //-----
187 // Access HitsMap.
188 // By MultiFunctionalDetector name and Collection Name.
190  const G4String& colName){
191  G4String fullName = detName+"/"+colName;
192  return GetHitsMap(fullName);
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 //
197 //-----
198 // Access HitsMap.
199 // By full description of collection name, that is
200 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
202  G4int nCol = fCollName.size();
203  for ( G4int i = 0; i < nCol; i++){
204  if ( fCollName[i] == fullName ){
205  return fRunMap[i];
206  }
207  }
208  return NULL;
209 }
210 
211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212 //
213 //-----
214 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
215 // This method calls G4THisMap::PrintAll() for individual HitsMap.
217 
218  // - Number of HitsMap in this RUN.
220  // - GetHitsMap and dump values.
221  for ( G4int i = 0; i < n ; i++ ){
222  G4THitsMap<G4double>* runMap =GetHitsMap(i);
223  if ( runMap ) {
224  G4cout << " PrimitiveScorer RUN "
225  << runMap->GetSDname() <<","<< runMap->GetName() << G4endl;
226  G4cout << " Number of entries " << runMap->entries() << G4endl;
233  }
234  }
235 }
236 
237 
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
std::vector< G4String > fCollName
Definition: RE02Run.hh:105
Definition of the RE02Run class.
G4String GetName() const
G4VPrimitiveScorer * GetPrimitive(G4int id) const
G4int numberOfEvent
Definition: G4Run.hh:59
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:128
std::vector< G4int > fCollID
Definition: RE02Run.hh:106
#define G4endl
Definition: G4ios.hh:61
G4int GetNumberOfHitsMap() const
Definition: RE02Run.hh:92
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
std::vector< G4THitsMap< G4double > * > fRunMap
Definition: RE02Run.hh:107
RE02Run(const std::vector< G4String > mfdName)
Definition: RE02Run.cc:70
G4THitsMap< G4double > * GetHitsMap(G4int i)
Definition: RE02Run.hh:96
Definition: G4Run.hh:46
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
int G4int
Definition: G4Types.hh:78
virtual void RecordEvent(const G4Event *)
Definition: RE02Run.cc:135
G4GLOB_DLL std::ostream G4cout
virtual void Merge(const G4Run *)
Definition: RE02Run.cc:166
void DumpAllScorer()
Definition: RE02Run.cc:216
Char_t n[5]
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int entries() const
Definition: G4THitsMap.hh:121
virtual ~RE02Run()
Definition: RE02Run.cc:118