source: trunk/examples/extended/biasing/B02/src/B02Run.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 7.9 KB
Line 
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//
27// $Id: B02Run.cc,v 1.2 2007/06/21 15:03:45 gunter Exp $
28// GEANT4 tag $Name: $
29//
30
31//=====================================================================
32//
33// (Description)
34// B02Run 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 B02Run(const std::vector<G4String> mfdName)
39// needs a vector filled with MultiFunctionalDetector names which
40// was assigned at instantiation of MultiFunctionalDetector(MFD).
41// Then B02Run 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 B02Run objects as
48// data members.
49// std::vector<G4String> theCollName; // Collection Name,
50// std::vector<G4int> theCollID; // Collection ID,
51// std::vector<G4THitsMap<G4double>*> theRunMap; // HitsMap for RUN.
52//
53// The resualtant HitsMap objects are obtain using access method,
54// GetHitsMap(..).
55//
56//=====================================================================
57
58#include "B02Run.hh"
59#include "G4SDManager.hh"
60
61#include "G4MultiFunctionalDetector.hh"
62#include "G4VPrimitiveScorer.hh"
63
64//
65// Constructor.
66// (The vector of MultiFunctionalDetector name has to given.)
67B02Run::B02Run(const std::vector<G4String> mfdName): G4Run()
68{
69 G4SDManager* SDman = G4SDManager::GetSDMpointer();
70 //=================================================
71 // Initalize RunMaps for accumulation.
72 // Get CollectionIDs for HitCollections.
73 //=================================================
74 G4int Nmfd = mfdName.size();
75 for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD.
76 G4String detName = mfdName[idet];
77 //--- Seek and Obtain MFD objects from SDmanager.
78 G4MultiFunctionalDetector* mfd =
79 (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
80 //
81 if ( mfd ){
82 //--- Loop over the registered primitive scorers.
83 for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
84 // Get Primitive Scorer object.
85 G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
86 // collection name and collectionID for HitsCollection,
87 // where type of HitsCollection is G4THitsMap in case of primitive scorer.
88 // The collection name is given by <MFD name>/<Primitive Scorer name>.
89 G4String collectionName = scorer->GetName();
90 G4String fullCollectionName = detName+"/"+collectionName;
91 G4int collectionID = SDman->GetCollectionID(fullCollectionName);
92 //
93 if ( collectionID >= 0 ){
94 G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
95 // Store obtained HitsCollection information into data members.
96 // And, creates new G4THitsMap for accumulating quantities during RUN.
97 theCollName.push_back(fullCollectionName);
98 theCollID.push_back(collectionID);
99 theRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
100 }else{
101 G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
102 }
103 }
104 }
105 }
106}
107
108//
109// Destructor
110// clear all data members.
111B02Run::~B02Run()
112{
113 //--- Clear HitsMap for RUN
114 G4int Nmap = theRunMap.size();
115 for ( G4int i = 0; i < Nmap; i++){
116 if(theRunMap[i] ) theRunMap[i]->clear();
117 }
118 theCollName.clear();
119 theCollID.clear();
120 theRunMap.clear();
121}
122
123//
124// RecordEvent is called at end of event.
125// For scoring purpose, the resultant quantity in a event,
126// is accumulated during a Run.
127void B02Run::RecordEvent(const G4Event* aEvent)
128{
129 numberOfEvent++; // This is an original line.
130
131 //=============================
132 // HitsCollection of This Event
133 //============================
134 G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
135 if (!HCE) return;
136 //=======================================================
137 // Sum up HitsMap of this Event into HitsMap of this RUN
138 //=======================================================
139 G4int Ncol = theCollID.size();
140 for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
141 G4THitsMap<G4double>* EvtMap=0;
142 if ( theCollID[i] >= 0 ){ // Collection is attached to HCE
143 EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(theCollID[i]));
144 }else{
145 G4cout <<" Error EvtMap Not Found "<< i << G4endl;
146 }
147 if ( EvtMap ) {
148 //=== Sum up HitsMap of this event to HitsMap of RUN.===
149 *theRunMap[i] += *EvtMap;
150 //======================================================
151 }
152 }
153
154
155}
156
157//=================================================================
158// Access method for HitsMap of the RUN
159//
160//-----
161// Access HitsMap.
162// By MultiFunctionalDetector name and Collection Name.
163G4THitsMap<G4double>* B02Run::GetHitsMap(const G4String& detName,
164 const G4String& colName){
165 G4String fullName = detName+"/"+colName;
166 G4cout << " getting hits map " << fullName << G4endl;
167 return GetHitsMap(fullName);
168}
169
170//-----
171// Access HitsMap.
172// By full description of collection name, that is
173// <MultiFunctional Detector Name>/<Primitive Scorer Name>
174G4THitsMap<G4double>* B02Run::GetHitsMap(const G4String& fullName){
175 G4cout << " getting hits map " << fullName << G4endl;
176 G4int Ncol = theCollName.size();
177 for ( G4int i = 0; i < Ncol; i++){
178 if ( theCollName[i] == fullName ){
179 return theRunMap[i];
180 }
181 }
182 return NULL;
183}
184
185//-----
186// - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
187// This method calls G4THisMap::PrintAll() for individual HitsMap.
188void B02Run::DumpAllScorer(){
189
190 // - Number of HitsMap in this RUN.
191 G4int n = GetNumberOfHitsMap();
192 // - GetHitsMap and dump values.
193 for ( G4int i = 0; i < n ; i++ ){
194 G4THitsMap<G4double>* RunMap =GetHitsMap(i);
195 if ( RunMap ) {
196 G4cout << " PrimitiveScorer RUN "
197 << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
198 G4cout << " Number of entries " << RunMap->entries() << G4endl;
199 std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
200 for(; itr != RunMap->GetMap()->end(); itr++) {
201 G4cout << " copy no.: " << itr->first
202 << " Run Value : " << *(itr->second)
203 << G4endl;
204 }
205 }
206 }
207}
208
209
Note: See TracBrowser for help on using the repository browser.