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