ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B02Run.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B02Run.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 //
31 
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //
34 // (Description)
35 // B02Run Class is for accumulating scored quantities which is
36 // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
37 // Accumulation is done using G4THitsMap object.
38 //
39 // The constructor B02Run(const std::vector<G4String> mfdName)
40 // needs a vector filled with MultiFunctionalDetector names which
41 // was assigned at instantiation of MultiFunctionalDetector(MFD).
42 // Then B02Run constructor automatically scans primitive scorers
43 // in the MFD, and obtains collectionIDs of all collections associated
44 // to those primitive scorers. Futhermore, the G4THitsMap objects
45 // for accumulating during a RUN are automatically created too.
46 // (*) Collection Name is same as primitive scorer name.
47 //
48 // The resultant information is kept inside B02Run objects as
49 // data members.
50 // std::vector<G4String> fCollName; // Collection Name,
51 // std::vector<G4int> fCollID; // Collection ID,
52 // std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
53 //
54 // The resualtant HitsMap objects are obtain using access method,
55 // GetHitsMap(..).
56 //
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 #include "B02Run.hh"
60 #include "G4SDManager.hh"
61 
63 #include "G4VPrimitiveScorer.hh"
64 
65 //
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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
97  << G4endl;
98  // Store obtained HitsCollection information into data members.
99  // And, creates new G4THitsMap for accumulating quantities during RUN.
100  fCollName.push_back(fullCollectionName);
101  fCollID.push_back(collectionID);
102  fRunMap.push_back(new G4THitsMap<G4double>(detName
103  ,collectionName));
104  }else{
105  G4cout << "** collection " << fullCollectionName
106  << " not found. "<<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 B02Run::RecordEvent(const G4Event* aEvent)
135 {
136  numberOfEvent++; // This is an original line.
137 
138  //=============================
139  // HitsCollection of This Event
140  //============================
141  G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
142  if (!HCE) 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 HCE
151  EvtMap = (G4THitsMap<G4double>*)(HCE->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 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
165 //
166 // Access method for HitsMap of the RUN
167 //
168 //-----
169 // Access HitsMap.
170 // By MultiFunctionalDetector name and Collection Name.
172  const G4String& colName){
173  G4String fullName = detName+"/"+colName;
174  return GetHitsMap(fullName);
175 }
176 
177 //-----
178 // Access HitsMap.
179 // By full description of collection name, that is
180 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
182  G4int Ncol = fCollName.size();
183  for ( G4int i = 0; i < Ncol; i++){
184  if ( fCollName[i] == fullName ){
185  return fRunMap[i];
186  }
187  }
188  return NULL;
189 }
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192 
193 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
194 // This method calls G4THisMap::PrintAll() for individual HitsMap.
196 
197  // - Number of HitsMap in this RUN.
199  // - GetHitsMap and dump values.
200  for ( G4int i = 0; i < n ; i++ ){
201  G4THitsMap<G4double>* RunMap =GetHitsMap(i);
202  if ( RunMap ) {
203  G4cout << " PrimitiveScorer RUN "
204  << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
205  G4cout << " Number of entries " << RunMap->entries() << G4endl;
206  std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
207  for(; itr != RunMap->GetMap()->end(); itr++) {
208  G4cout << " copy no.: " << itr->first
209  << " Run Value : " << *(itr->second)
210  << G4endl;
211  }
212  }
213  }
214 }
215 
216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217 
218 void B02Run::Merge(const G4Run* aRun)
219 {
220  const B02Run * localRun = static_cast<const B02Run *>(aRun);
221  //=======================================================
222  // Merge HitsMap of working threads
223  //=======================================================
224  G4int nCol = localRun->fCollID.size();
225  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
226  if ( localRun->fCollID[i] >= 0 ){
227  *fRunMap[i] += *localRun->fRunMap[i];
228  }
229  }
230 
231  G4Run::Merge(aRun);
232 }
233 
234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......