Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B01Run.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 // B01Run 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 B01Run(const std::vector<G4String> mfdName)
41 // needs a vector filled with MultiFunctionalDetector names which
42 // was assigned at instantiation of MultiFunctionalDetector(MFD).
43 // Then B01Run 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 B01Run 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 "B01Run.hh"
61 #include "G4SDManager.hh"
62 
64 #include "G4VPrimitiveScorer.hh"
65 
66 //
67 // Constructor.
68 // (The vector of MultiFunctionalDetector name has to given.)
69 B01Run::B01Run(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 B01Run::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  //=======================================================
140  // Sum up HitsMap of this Event into HitsMap of this RUN
141  //=======================================================
142  G4int Ncol = theCollID.size();
143  for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
144  G4THitsMap<G4double>* EvtMap=0;
145  if ( theCollID[i] >= 0 ){ // Collection is attached to HCE
146  EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(theCollID[i]));
147  }else{
148  G4cout <<" Error EvtMap Not Found "<< i << G4endl;
149  }
150  if ( EvtMap ) {
151  //=== Sum up HitsMap of this event to HitsMap of RUN.===
152  *theRunMap[i] += *EvtMap;
153  //======================================================
154  }
155  }
156 
157 
158 }
159 
160 //=================================================================
161 // Access method for HitsMap of the RUN
162 //
163 //-----
164 // Access HitsMap.
165 // By MultiFunctionalDetector name and Collection Name.
167  const G4String& colName){
168  G4String fullName = detName+"/"+colName;
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  G4int Ncol = theCollName.size();
178  for ( G4int i = 0; i < Ncol; i++){
179  if ( theCollName[i] == fullName ){
180  return theRunMap[i];
181  }
182  }
183  return NULL;
184 }
185 
186 //-----
187 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
188 // This method calls G4THisMap::PrintAll() for individual HitsMap.
190 
191  // - Number of HitsMap in this RUN.
193  // - GetHitsMap and dump values.
194  for ( G4int i = 0; i < n ; i++ ){
195  G4THitsMap<G4double>* RunMap =GetHitsMap(i);
196  if ( RunMap ) {
197  G4cout << " PrimitiveScorer RUN "
198  << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
199  G4cout << " Number of entries " << RunMap->entries() << G4endl;
200  std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
201  for(; itr != RunMap->GetMap()->end(); itr++) {
202  G4cout << " copy no.: " << itr->first
203  << " Run Value : " << *(itr->second)
204  << G4endl;
205  }
206  }
207  }
208 }
209 
210