Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE02Run.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 //=====================================================================
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 << G4endl;
99  // Store obtained HitsCollection information into data members.
100  // And, creates new G4THitsMap for accumulating quantities during RUN.
101  fCollName.push_back(fullCollectionName);
102  fCollID.push_back(collectionID);
103  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
104  }else{
105  G4cout << "** collection " << fullCollectionName << " not found. "
106  << G4endl;
107  }
108  }
109  }
110  }
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
114 //
115 // Destructor
116 // clear all data members.
118 {
119  //--- Clear HitsMap for RUN
120  G4int nMap = fRunMap.size();
121  for ( G4int i = 0; i < nMap; i++){
122  if(fRunMap[i] ) fRunMap[i]->clear();
123  }
124  fCollName.clear();
125  fCollID.clear();
126  fRunMap.clear();
127 }
128 
129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
130 //
131 // RecordEvent is called at end of event.
132 // For scoring purpose, the resultant quantity in a event,
133 // is accumulated during a Run.
134 void RE02Run::RecordEvent(const G4Event* aEvent)
135 {
136  numberOfEvent++; // This is an original line.
137 
138  //=============================
139  // HitsCollection of This Event
140  //============================
141  G4HCofThisEvent* pHCE = aEvent->GetHCofThisEvent();
142  if (!pHCE) return;
143 
144  //=======================================================
145  // Sum up HitsMap of this Event into HitsMap of this RUN
146  //=======================================================
147  G4int nCol = fCollID.size();
148  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
149  G4THitsMap<G4double>* evtMap=0;
150  if ( fCollID[i] >= 0 ){ // Collection is attached to pHCE
151  evtMap = (G4THitsMap<G4double>*)(pHCE->GetHC(fCollID[i]));
152  }else{
153  G4cout <<" Error evtMap Not Found "<< i << G4endl;
154  }
155  if ( evtMap ) {
156  //=== Sum up HitsMap of this event to HitsMap of RUN.===
157  *fRunMap[i] += *evtMap;
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 //
178 //-----
179 // Access HitsMap.
180 // By full description of collection name, that is
181 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
183  G4int nCol = fCollName.size();
184  for ( G4int i = 0; i < nCol; i++){
185  if ( fCollName[i] == fullName ){
186  return fRunMap[i];
187  }
188  }
189  return NULL;
190 }
191 
192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193 //
194 //-----
195 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
196 // This method calls G4THisMap::PrintAll() for individual HitsMap.
198 
199  // - Number of HitsMap in this RUN.
201  // - GetHitsMap and dump values.
202  for ( G4int i = 0; i < n ; i++ ){
203  G4THitsMap<G4double>* runMap =GetHitsMap(i);
204  if ( runMap ) {
205  G4cout << " PrimitiveScorer RUN "
206  << runMap->GetSDname() <<","<< runMap->GetName() << G4endl;
207  G4cout << " Number of entries " << runMap->entries() << G4endl;
208  std::map<G4int,G4double*>::iterator itr = runMap->GetMap()->begin();
209  for(; itr != runMap->GetMap()->end(); itr++) {
210  G4cout << " copy no.: " << itr->first
211  << " Run Value : " << *(itr->second)
212  << G4endl;
213  }
214  }
215  }
216 }
217 
218