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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/biasing/B03/src/B03Run.cc (Version 11.3.0) and /examples/extended/biasing/B03/src/B03Run.cc (Version 10.3.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /// \file biasing/B03/src/B03Run.cc                26 /// \file biasing/B03/src/B03Run.cc
 27 /// \brief Implementation of the B03Run class      27 /// \brief Implementation of the B03Run class
 28 //                                                 28 //
 29 //                                                 29 //
                                                   >>  30 // $Id: B03Run.cc 70528 2013-05-31 16:50:36Z gcosmo $
 30 //                                                 31 //
 31                                                    32 
 32 //============================================     33 //=====================================================================
 33 //                                                 34 //
 34 //  (Description)                                  35 //  (Description)
 35 //    B03Run Class is for accumulating scored  <<  36 //    B03Run Class is for accumulating scored quantities which is 
 36 //  scored using G4MutiFunctionalDetector and      37 //  scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
 37 //  Accumulation is done using G4THitsMap obje     38 //  Accumulation is done using G4THitsMap object.
 38 //                                                 39 //
 39 //    The constructor B03Run(const std::vector     40 //    The constructor B03Run(const std::vector<G4String> mfdName)
 40 //  needs a vector filled with MultiFunctional     41 //  needs a vector filled with MultiFunctionalDetector names which
 41 //  was assigned at instantiation of MultiFunc     42 //  was assigned at instantiation of MultiFunctionalDetector(MFD).
 42 //  Then B03Run constructor automatically scan     43 //  Then B03Run constructor automatically scans primitive scorers
 43 //  in the MFD, and obtains collectionIDs of a     44 //  in the MFD, and obtains collectionIDs of all collections associated
 44 //  to those primitive scorers. Futhermore, th <<  45 //  to those primitive scorers. Futhermore, the G4THitsMap objects 
 45 //  for accumulating during a RUN are automati     46 //  for accumulating during a RUN are automatically created too.
 46 //  (*) Collection Name is same as primitive s     47 //  (*) Collection Name is same as primitive scorer name.
 47 //                                             <<  48 // 
 48 //    The resultant information is kept inside     49 //    The resultant information is kept inside B03Run objects as
 49 //  data members.                                  50 //  data members.
 50 //  std::vector<G4String> fCollName;               51 //  std::vector<G4String> fCollName;            // Collection Name,
 51 //  std::vector<G4int> fCollID;                    52 //  std::vector<G4int> fCollID;                 // Collection ID,
 52 //  std::vector<G4THitsMap<G4double>*> fRunMap     53 //  std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
 53 //                                                 54 //
 54 //  The resualtant HitsMap objects are obtain      55 //  The resualtant HitsMap objects are obtain using access method,
 55 //  GetHitsMap(..).                                56 //  GetHitsMap(..).
 56 //                                                 57 //
 57 //============================================     58 //=====================================================================
 58                                                    59 
 59 #include "B03Run.hh"                               60 #include "B03Run.hh"
                                                   >>  61 #include "G4SDManager.hh"
 60                                                    62 
 61 #include "G4MultiFunctionalDetector.hh"            63 #include "G4MultiFunctionalDetector.hh"
 62 #include "G4SDManager.hh"                      << 
 63 #include "G4VPrimitiveScorer.hh"                   64 #include "G4VPrimitiveScorer.hh"
 64                                                    65 
 65 //....oooOO0OOooo........oooOO0OOooo........oo     66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 66                                                    67 
 67 //  Constructor.                               <<  68 //  Constructor. 
 68 //   (The vector of MultiFunctionalDetector na     69 //   (The vector of MultiFunctionalDetector name has to given.)
 69 B03Run::B03Run(const std::vector<G4String> mfd <<  70 B03Run::B03Run(const std::vector<G4String> mfdName): G4Run()
 70 {                                                  71 {
 71   G4SDManager* SDman = G4SDManager::GetSDMpoin     72   G4SDManager* SDman = G4SDManager::GetSDMpointer();
 72   //==========================================     73   //=================================================
 73   //  Initalize RunMaps for accumulation.          74   //  Initalize RunMaps for accumulation.
 74   //  Get CollectionIDs for HitCollections.        75   //  Get CollectionIDs for HitCollections.
 75   //==========================================     76   //=================================================
 76   G4int Nmfd = mfdName.size();                     77   G4int Nmfd = mfdName.size();
 77   for (G4int idet = 0; idet < Nmfd; idet++) {  <<  78   for ( G4int idet = 0; idet < Nmfd ; idet++){  // Loop for all MFD.
 78     G4String detName = mfdName[idet];              79     G4String detName = mfdName[idet];
 79     //--- Seek and Obtain MFD objects from SDm     80     //--- Seek and Obtain MFD objects from SDmanager.
 80     G4MultiFunctionalDetector* mfd =               81     G4MultiFunctionalDetector* mfd =
 81       (G4MultiFunctionalDetector*)(SDman->Find     82       (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
 82     //                                             83     //
 83     if (mfd) {                                 <<  84     if ( mfd ){
 84       //--- Loop over the registered primitive <<  85         //--- Loop over the registered primitive scorers.
 85       for (G4int icol = 0; icol < mfd->GetNumb <<  86         for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
 86         // Get Primitive Scorer object.        <<  87             // Get Primitive Scorer object.
 87         G4VPrimitiveScorer* scorer = mfd->GetP <<  88             G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
 88         // collection name and collectionID fo <<  89       // collection name and collectionID for HitsCollection,
 89         // where type of HitsCollection is G4T <<  90       // where type of HitsCollection is G4THitsMap in case of primitive scorer.
 90         // The collection name is given by <MF <<  91       // The collection name is given by <MFD name>/<Primitive Scorer name>.
 91         G4String collectionName = scorer->GetN <<  92             G4String collectionName = scorer->GetName();
 92         G4String fullCollectionName = detName  <<  93             G4String fullCollectionName = detName+"/"+collectionName;
 93         G4int collectionID = SDman->GetCollect <<  94             G4int    collectionID = SDman->GetCollectionID(fullCollectionName);
 94         //                                     <<  95             //
 95         if (collectionID >= 0) {               <<  96             if ( collectionID >= 0 ){
 96           G4cout << "++ " << fullCollectionNam <<  97                 G4cout << "++ "<<fullCollectionName<< " id " 
                                                   >>  98                        << collectionID << G4endl;
 97           // Store obtained HitsCollection inf     99           // Store obtained HitsCollection information into data members.
 98           // And, creates new G4THitsMap for a    100           // And, creates new G4THitsMap for accumulating quantities during RUN.
 99           fCollName.push_back(fullCollectionNa << 101                 fCollName.push_back(fullCollectionName);
100           fCollID.push_back(collectionID);     << 102                 fCollID.push_back(collectionID);
101           fRunMap.push_back(new G4THitsMap<G4d << 103                 fRunMap.push_back(new G4THitsMap<G4double>(detName
102         }                                      << 104                                                           ,collectionName));
103         else {                                 << 105             }else{
104           G4cout << "** collection " << fullCo << 106                 G4cout << "** collection " << fullCollectionName 
                                                   >> 107                        << " not found. "<<G4endl;
                                                   >> 108             }
105         }                                         109         }
106       }                                        << 
107     }                                             110     }
108   }                                               111   }
109 }                                                 112 }
110                                                   113 
111 //....oooOO0OOooo........oooOO0OOooo........oo    114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
112                                                   115 
113 // Destructor                                     116 // Destructor
114 //    clear all data members.                     117 //    clear all data members.
115 B03Run::~B03Run()                                 118 B03Run::~B03Run()
116 {                                                 119 {
117   //--- Clear HitsMap for RUN                     120   //--- Clear HitsMap for RUN
118   G4int Nmap = fRunMap.size();                    121   G4int Nmap = fRunMap.size();
119   for (G4int i = 0; i < Nmap; i++) {           << 122   for ( G4int i = 0; i < Nmap; i++){
120     if (fRunMap[i]) fRunMap[i]->clear();       << 123     if(fRunMap[i] ) fRunMap[i]->clear();
121   }                                               124   }
122   fCollName.clear();                              125   fCollName.clear();
123   fCollID.clear();                                126   fCollID.clear();
124   fRunMap.clear();                                127   fRunMap.clear();
125 }                                                 128 }
126                                                   129 
127 //....oooOO0OOooo........oooOO0OOooo........oo    130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128                                                   131 
129 //  RecordEvent is called at end of event.        132 //  RecordEvent is called at end of event.
130 //  For scoring purpose, the resultant quantit    133 //  For scoring purpose, the resultant quantity in a event,
131 //  is accumulated during a Run.                  134 //  is accumulated during a Run.
132 void B03Run::RecordEvent(const G4Event* aEvent    135 void B03Run::RecordEvent(const G4Event* aEvent)
133 {                                                 136 {
134   numberOfEvent++;  // This is an original lin    137   numberOfEvent++;  // This is an original line.
135                                                   138 
136   //=============================                 139   //=============================
137   // HitsCollection of This Event                 140   // HitsCollection of This Event
138   //============================                  141   //============================
139   G4HCofThisEvent* HCE = aEvent->GetHCofThisEv    142   G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
140   if (!HCE) return;                               143   if (!HCE) return;
141   //==========================================    144   //=======================================================
142   // Sum up HitsMap of this Event  into HitsMa    145   // Sum up HitsMap of this Event  into HitsMap of this RUN
143   //==========================================    146   //=======================================================
144   G4int Ncol = fCollID.size();                    147   G4int Ncol = fCollID.size();
145   for (G4int i = 0; i < Ncol; i++) {  // Loop  << 148   for ( G4int i = 0; i < Ncol ; i++ ){  // Loop over HitsCollection
146     G4THitsMap<G4double>* EvtMap = 0;          << 149     G4THitsMap<G4double>* EvtMap=0;
147     if (fCollID[i] >= 0) {  // Collection is a << 150     if ( fCollID[i] >= 0 ){           // Collection is attached to HCE
148       EvtMap = (G4THitsMap<G4double>*)(HCE->Ge    151       EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID[i]));
                                                   >> 152     }else{
                                                   >> 153       G4cout <<" Error EvtMap Not Found "<< i << G4endl;
149     }                                             154     }
150     else {                                     << 155     if ( EvtMap )  {
151       G4cout << " Error EvtMap Not Found " <<  << 
152     }                                          << 
153     if (EvtMap) {                              << 
154       //=== Sum up HitsMap of this event to Hi    156       //=== Sum up HitsMap of this event to HitsMap of RUN.===
155       *fRunMap[i] += *EvtMap;                     157       *fRunMap[i] += *EvtMap;
156       //======================================    158       //======================================================
157     }                                             159     }
158   }                                               160   }
                                                   >> 161 
                                                   >> 162   
159 }                                                 163 }
160                                                   164 
161 //....oooOO0OOooo........oooOO0OOooo........oo    165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162                                                   166 
163 //  Access method for HitsMap of the RUN          167 //  Access method for HitsMap of the RUN
164 //                                                168 //
165 // Access HitsMap.                                169 // Access HitsMap.
166 //  By  MultiFunctionalDetector name and Colle    170 //  By  MultiFunctionalDetector name and Collection Name.
167 G4THitsMap<G4double>* B03Run::GetHitsMap(const << 171 G4THitsMap<G4double>* B03Run::GetHitsMap(const G4String& detName,
168 {                                              << 172                                          const G4String& colName){
169   G4String fullName = detName + "/" + colName; << 173     G4String fullName = detName+"/"+colName;
170   G4cout << " getting hits map " << fullName < << 174     G4cout << " getting hits map " << fullName << G4endl;
171   return GetHitsMap(fullName);                 << 175     return GetHitsMap(fullName);
172 }                                                 176 }
173                                                   177 
174 //....oooOO0OOooo........oooOO0OOooo........oo    178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175                                                   179 
176 // Access HitsMap.                                180 // Access HitsMap.
177 //  By full description of collection name, th    181 //  By full description of collection name, that is
178 //    <MultiFunctional Detector Name>/<Primiti    182 //    <MultiFunctional Detector Name>/<Primitive Scorer Name>
179 G4THitsMap<G4double>* B03Run::GetHitsMap(const << 183 G4THitsMap<G4double>* B03Run::GetHitsMap(const G4String& fullName){
180 {                                              << 184     G4cout << " getting hits map " << fullName << G4endl;
181   G4cout << " getting hits map " << fullName < << 185     G4int Ncol = fCollName.size();
182   G4int Ncol = fCollName.size();               << 186     for ( G4int i = 0; i < Ncol; i++){
183   for (G4int i = 0; i < Ncol; i++) {           << 187         if ( fCollName[i] == fullName ){
184     if (fCollName[i] == fullName) {            << 188             return fRunMap[i];
185       return fRunMap[i];                       << 189         }
186     }                                             190     }
187   }                                            << 191     return NULL;
188   return NULL;                                 << 
189 }                                                 192 }
190                                                   193 
191 //....oooOO0OOooo........oooOO0OOooo........oo    194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192                                                   195 
193 // - Dump All HitsMap of this RUN. (for debugi    196 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
194 //   This method calls G4THisMap::PrintAll() f    197 //   This method calls G4THisMap::PrintAll() for individual HitsMap.
195 void B03Run::DumpAllScorer()                   << 198 void B03Run::DumpAllScorer(){
196 {                                              << 199 
197   // - Number of HitsMap in this RUN.             200   // - Number of HitsMap in this RUN.
198   G4int n = GetNumberOfHitsMap();                 201   G4int n = GetNumberOfHitsMap();
199   // - GetHitsMap and dump values.                202   // - GetHitsMap and dump values.
200   for (G4int i = 0; i < n; i++) {              << 203   for ( G4int i = 0; i < n ; i++ ){
201     G4THitsMap<G4double>* RunMap = GetHitsMap( << 204     G4THitsMap<G4double>* RunMap =GetHitsMap(i);
202     if (RunMap) {                              << 205     if ( RunMap ) {
203       G4cout << " PrimitiveScorer RUN " << Run << 206       G4cout << " PrimitiveScorer RUN " 
204              << G4endl;                        << 207              << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
205       G4cout << " Number of entries " << RunMa    208       G4cout << " Number of entries " << RunMap->entries() << G4endl;
206       std::map<G4int, G4double*>::iterator itr << 209       std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
207       for (; itr != RunMap->GetMap()->end(); i << 210       for(; itr != RunMap->GetMap()->end(); itr++) {
208         G4cout << "  copy no.: " << itr->first << 211         G4cout << "  copy no.: " << itr->first
                                                   >> 212                << "  Run Value : " << *(itr->second) 
                                                   >> 213                << G4endl;
209       }                                           214       }
210     }                                             215     }
211   }                                               216   }
212 }                                                 217 }
213                                                   218 
214 //....oooOO0OOooo........oooOO0OOooo........oo    219 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
215                                                   220 
216 void B03Run::Merge(const G4Run* aRun)             221 void B03Run::Merge(const G4Run* aRun)
217 {                                                 222 {
218   const B03Run* localRun = static_cast<const B << 223   const B03Run * localRun = static_cast<const B03Run *>(aRun);
219   //==========================================    224   //=======================================================
220   // Merge HitsMap of working threads             225   // Merge HitsMap of working threads
221   //==========================================    226   //=======================================================
222   G4int nCol = localRun->fCollID.size();          227   G4int nCol = localRun->fCollID.size();
223   for (G4int i = 0; i < nCol; i++) {  // Loop  << 228   for ( G4int i = 0; i < nCol ; i++ ){  // Loop over HitsCollection
224     if (localRun->fCollID[i] >= 0) {           << 229     if ( localRun->fCollID[i] >= 0 ){
225       *fRunMap[i] += *localRun->fRunMap[i];       230       *fRunMap[i] += *localRun->fRunMap[i];
226     }                                             231     }
227   }                                               232   }
228                                                << 233   
229   G4Run::Merge(aRun);                             234   G4Run::Merge(aRun);
230 }                                              << 235 } 
231                                                   236 
232 //....oooOO0OOooo........oooOO0OOooo........oo    237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233                                                   238