ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ML2Run.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ML2Run.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 //
26 // SUSANNA: This class is based on the RE02 extended example
27 //
28 
29 #include "ML2Run.hh"
30 #include "G4SDManager.hh"
31 
33 #include "G4VPrimitiveScorer.hh"
34 
35 ML2Run::ML2Run(const std::vector<G4String> mfdName) : G4Run()
36 {
38  //=================================================
39  // Initalize RunMaps for accumulation.
40  // Get CollectionIDs for HitCollections.
41  //=================================================
42  G4int nMfd = mfdName.size();
43  for ( G4int idet = 0; idet < nMfd ; idet++){ // Loop for all MFD.
44  G4String detName = mfdName[idet];
45  //--- Seek and Obtain MFD objects from SDmanager.
48  //
49  if ( mfd ){
50  //--- Loop over the registered primitive scorers.
51  for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
52  // Get Primitive Scorer object.
53  G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
54  // collection name and collectionID for HitsCollection,
55  // where type of HitsCollection is G4THitsMap in case of primitive
56  // scorer.
57  // The collection name is given by <MFD name>/<Primitive Scorer name>.
58  G4String collectionName = scorer->GetName();
59  G4String fullCollectionName = detName+"/"+collectionName;
60  G4int collectionID = pSDman->GetCollectionID(fullCollectionName);
61  //
62  if ( collectionID >= 0 ){
63  G4cout << "++ "<<fullCollectionName<< " id " << collectionID
64  << G4endl;
65  // Store obtained HitsCollection information into data members.
66  // And, creates new G4THitsMap for accumulating quantities during RUN.
67  fCollName.push_back(fullCollectionName);
68  fCollID.push_back(collectionID);
69  fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
70  }else{
71  G4cout << "** collection " << fullCollectionName << " not found. "
72  << G4endl;
73  }
74  }
75  }
76  }
77 }
78 
79 // clear all data members.
81 {
82  //--- Clear HitsMap for RUN
83  G4int nMap = fRunMap.size();
84  for ( G4int i = 0; i < nMap; i++){
85  if(fRunMap[i] ) fRunMap[i]->clear();
86  }
87  fCollName.clear();
88  fCollID.clear();
89  fRunMap.clear();
90 }
91 
92 //
93 // RecordEvent is called at end of event.
94 // For scoring purpose, the resultant quantity in a event,
95 // is accumulated during a Run.
96 void ML2Run::RecordEvent(const G4Event* aEvent)
97 {
98  numberOfEvent++; // This is an original line.
99 
100  //=============================
101  // HitsCollection of This Event
102  //============================
103  G4HCofThisEvent* pHCE = aEvent->GetHCofThisEvent();
104  if (!pHCE) return;
105 
106  //=======================================================
107  // Sum up HitsMap of this Event into HitsMap of this RUN
108  //=======================================================
109  G4int nCol = fCollID.size();
110  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
111  G4THitsMap<G4double>* evtMap=0;
112  if ( fCollID[i] >= 0 ){ // Collection is attached to pHCE
113  evtMap = (G4THitsMap<G4double>*)(pHCE->GetHC(fCollID[i]));
114  }else{
115  G4cout <<" Error evtMap Not Found "<< i << G4endl;
116  }
117  if ( evtMap ) {
118  //=== Sum up HitsMap of this event to HitsMap of RUN.===
119  *fRunMap[i] += *evtMap;
120  //======================================================
121  }
122  }
123 }
124 
125 void ML2Run::Merge(const G4Run * aRun)
126 {
127  const ML2Run * localRun = static_cast<const ML2Run *>(aRun);
128 
129  //=======================================================
130  // Merge HitsMap of working threads
131  //=======================================================
132  G4int nCol = localRun->fCollID.size();
133  for ( G4int i = 0; i < nCol ; i++ ){ // Loop over HitsCollection
134  if ( localRun->fCollID[i] >= 0 ){
135  *fRunMap[i] += *localRun->fRunMap[i];
136  }
137  }
138 
139  G4Run::Merge(aRun);
140 }
141 
142 // Access method for HitsMap of the RUN
143 //
144 //-----
145 // Access HitsMap.
146 // By MultiFunctionalDetector name and Collection Name.
148  const G4String& colName){
149  G4String fullName = detName+"/"+colName;
150  return GetHitsMap(fullName);
151 }
152 
153 // Access HitsMap.
154 // By full description of collection name, that is
155 // <MultiFunctional Detector Name>/<Primitive Scorer Name>
157  G4int nCol = fCollName.size();
158  for ( G4int i = 0; i < nCol; i++){
159  if ( fCollName[i] == fullName ){
160  return fRunMap[i];
161  }
162  }
163  return NULL;
164 }
165 
167 
168  // - Number of HitsMap in this RUN.
170  // - GetHitsMap and dump values.
171  for ( G4int i = 0; i < n ; i++ ){
172  G4THitsMap<G4double>* runMap =GetHitsMap(i);
173  if ( runMap ) {
174  G4cout << " PrimitiveScorer RUN "
175  << runMap->GetSDname() <<","<< runMap->GetName() << G4endl;
176  G4cout << " Number of entries " << runMap->entries() << G4endl;
177  }
178  }
179 }
180 
181