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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/B02/src/B02Run.cc (Version 11.3.0) and /examples/extended/biasing/B02/src/B02Run.cc (Version 9.1.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/B02/src/B02Run.cc            << 
 27 /// \brief Implementation of the B02Run class  << 
 28 //                                             << 
 29 //                                                 26 //
                                                   >>  27 // $Id: B02Run.cc,v 1.2 2007/06/21 15:03:45 gunter Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-01-patch-03 $
 30 //                                                 29 //
 31                                                    30 
 32 //....oooOO0OOooo........oooOO0OOooo........oo <<  31 //=====================================================================
 33 //                                                 32 //
 34 //  (Description)                                  33 //  (Description)
 35 //    B02Run Class is for accumulating scored  <<  34 //    B02Run Class is for accumulating scored quantities which is 
 36 //  scored using G4MutiFunctionalDetector and      35 //  scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
 37 //  Accumulation is done using G4THitsMap obje     36 //  Accumulation is done using G4THitsMap object.
 38 //                                                 37 //
 39 //    The constructor B02Run(const std::vector     38 //    The constructor B02Run(const std::vector<G4String> mfdName)
 40 //  needs a vector filled with MultiFunctional     39 //  needs a vector filled with MultiFunctionalDetector names which
 41 //  was assigned at instantiation of MultiFunc     40 //  was assigned at instantiation of MultiFunctionalDetector(MFD).
 42 //  Then B02Run constructor automatically scan     41 //  Then B02Run constructor automatically scans primitive scorers
 43 //  in the MFD, and obtains collectionIDs of a     42 //  in the MFD, and obtains collectionIDs of all collections associated
 44 //  to those primitive scorers. Futhermore, th <<  43 //  to those primitive scorers. Futhermore, the G4THitsMap objects 
 45 //  for accumulating during a RUN are automati     44 //  for accumulating during a RUN are automatically created too.
 46 //  (*) Collection Name is same as primitive s     45 //  (*) Collection Name is same as primitive scorer name.
 47 //                                             <<  46 // 
 48 //    The resultant information is kept inside     47 //    The resultant information is kept inside B02Run objects as
 49 //  data members.                                  48 //  data members.
 50 //  std::vector<G4String> fCollName;           <<  49 //  std::vector<G4String> theCollName;            // Collection Name,
 51 //  std::vector<G4int> fCollID;                <<  50 //  std::vector<G4int> theCollID;                 // Collection ID,
 52 //  std::vector<G4THitsMap<G4double>*> fRunMap <<  51 //  std::vector<G4THitsMap<G4double>*> theRunMap; // HitsMap for RUN.
 53 //                                                 52 //
 54 //  The resualtant HitsMap objects are obtain      53 //  The resualtant HitsMap objects are obtain using access method,
 55 //  GetHitsMap(..).                                54 //  GetHitsMap(..).
 56 //                                                 55 //
 57 //....oooOO0OOooo........oooOO0OOooo........oo <<  56 //=====================================================================
 58                                                    57 
 59 #include "B02Run.hh"                               58 #include "B02Run.hh"
                                                   >>  59 #include "G4SDManager.hh"
 60                                                    60 
 61 #include "G4MultiFunctionalDetector.hh"            61 #include "G4MultiFunctionalDetector.hh"
 62 #include "G4SDManager.hh"                      << 
 63 #include "G4VPrimitiveScorer.hh"                   62 #include "G4VPrimitiveScorer.hh"
 64                                                    63 
 65 //                                                 64 //
 66 //....oooOO0OOooo........oooOO0OOooo........oo <<  65 //  Constructor. 
 67 //  Constructor.                               << 
 68 //   (The vector of MultiFunctionalDetector na     66 //   (The vector of MultiFunctionalDetector name has to given.)
 69 B02Run::B02Run(const std::vector<G4String> mfd <<  67 B02Run::B02Run(const std::vector<G4String> mfdName): G4Run()
 70 {                                                  68 {
 71   G4SDManager* SDman = G4SDManager::GetSDMpoin     69   G4SDManager* SDman = G4SDManager::GetSDMpointer();
 72   //==========================================     70   //=================================================
 73   //  Initalize RunMaps for accumulation.          71   //  Initalize RunMaps for accumulation.
 74   //  Get CollectionIDs for HitCollections.        72   //  Get CollectionIDs for HitCollections.
 75   //==========================================     73   //=================================================
 76   G4int Nmfd = mfdName.size();                     74   G4int Nmfd = mfdName.size();
 77   for (G4int idet = 0; idet < Nmfd; idet++) {  <<  75   for ( G4int idet = 0; idet < Nmfd ; idet++){  // Loop for all MFD.
 78     G4String detName = mfdName[idet];              76     G4String detName = mfdName[idet];
 79     //--- Seek and Obtain MFD objects from SDm     77     //--- Seek and Obtain MFD objects from SDmanager.
 80     G4MultiFunctionalDetector* mfd =               78     G4MultiFunctionalDetector* mfd =
 81       (G4MultiFunctionalDetector*)(SDman->Find     79       (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
 82     //                                             80     //
 83     if (mfd) {                                 <<  81     if ( mfd ){
 84       //--- Loop over the registered primitive <<  82   //--- Loop over the registered primitive scorers.
 85       for (G4int icol = 0; icol < mfd->GetNumb <<  83   for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
 86         // Get Primitive Scorer object.        <<  84       // Get Primitive Scorer object.
 87         G4VPrimitiveScorer* scorer = mfd->GetP <<  85       G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
 88         // collection name and collectionID fo <<  86       // collection name and collectionID for HitsCollection,
 89         // where type of HitsCollection is G4T <<  87             // where type of HitsCollection is G4THitsMap in case of primitive scorer.
 90         // The collection name is given by <MF <<  88             // The collection name is given by <MFD name>/<Primitive Scorer name>.
 91         G4String collectionName = scorer->GetN <<  89       G4String collectionName = scorer->GetName();
 92         G4String fullCollectionName = detName  <<  90       G4String fullCollectionName = detName+"/"+collectionName;
 93         G4int collectionID = SDman->GetCollect <<  91       G4int    collectionID = SDman->GetCollectionID(fullCollectionName);
 94                                                <<  92       //
 95         if (collectionID >= 0) {               <<  93       if ( collectionID >= 0 ){
 96           G4cout << "++ " << fullCollectionNam <<  94     G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
 97           // Store obtained HitsCollection inf <<  95     // Store obtained HitsCollection information into data members.
 98           // And, creates new G4THitsMap for a <<  96     // And, creates new G4THitsMap for accumulating quantities during RUN.
 99           fCollName.push_back(fullCollectionNa <<  97     theCollName.push_back(fullCollectionName);
100           fCollID.push_back(collectionID);     <<  98     theCollID.push_back(collectionID);
101           fRunMap.push_back(new G4THitsMap<G4d <<  99     theRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
102         }                                      << 100       }else{
103         else {                                 << 101     G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
104           G4cout << "** collection " << fullCo << 102       }
105         }                                      << 103   }
106       }                                        << 
107     }                                             104     }
108   }                                               105   }
109 }                                                 106 }
110                                                   107 
111 //....oooOO0OOooo........oooOO0OOooo........oo << 108 //
112                                                << 
113 // Destructor                                     109 // Destructor
114 //    clear all data members.                     110 //    clear all data members.
115 B02Run::~B02Run()                                 111 B02Run::~B02Run()
116 {                                                 112 {
117   //--- Clear HitsMap for RUN                     113   //--- Clear HitsMap for RUN
118   G4int Nmap = fRunMap.size();                 << 114   G4int Nmap = theRunMap.size();
119   for (G4int i = 0; i < Nmap; i++) {           << 115   for ( G4int i = 0; i < Nmap; i++){
120     if (fRunMap[i]) fRunMap[i]->clear();       << 116     if(theRunMap[i] ) theRunMap[i]->clear();
121   }                                            << 117   }
122   fCollName.clear();                           << 118   theCollName.clear();
123   fCollID.clear();                             << 119   theCollID.clear();
124   fRunMap.clear();                             << 120   theRunMap.clear();
125 }                                                 121 }
126                                                   122 
127 //....oooOO0OOooo........oooOO0OOooo........oo << 123 //
128                                                << 
129 //  RecordEvent is called at end of event.        124 //  RecordEvent is called at end of event.
130 //  For scoring purpose, the resultant quantit    125 //  For scoring purpose, the resultant quantity in a event,
131 //  is accumulated during a Run.                  126 //  is accumulated during a Run.
132 void B02Run::RecordEvent(const G4Event* aEvent    127 void B02Run::RecordEvent(const G4Event* aEvent)
133 {                                                 128 {
134   numberOfEvent++;  // This is an original lin    129   numberOfEvent++;  // This is an original line.
135                                                   130 
136   //=============================                 131   //=============================
137   // HitsCollection of This Event                 132   // HitsCollection of This Event
138   //============================                  133   //============================
139   G4HCofThisEvent* HCE = aEvent->GetHCofThisEv    134   G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
140   if (!HCE) return;                               135   if (!HCE) return;
141                                                << 
142   //==========================================    136   //=======================================================
143   // Sum up HitsMap of this Event  into HitsMa    137   // Sum up HitsMap of this Event  into HitsMap of this RUN
144   //==========================================    138   //=======================================================
145   G4int Ncol = fCollID.size();                 << 139   G4int Ncol = theCollID.size();
146   for (G4int i = 0; i < Ncol; i++) {  // Loop  << 140   for ( G4int i = 0; i < Ncol ; i++ ){  // Loop over HitsCollection
147     G4THitsMap<G4double>* EvtMap = 0;          << 141     G4THitsMap<G4double>* EvtMap=0;
148     if (fCollID[i] >= 0) {  // Collection is a << 142     if ( theCollID[i] >= 0 ){           // Collection is attached to HCE
149       EvtMap = (G4THitsMap<G4double>*)(HCE->Ge << 143       EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(theCollID[i]));
150     }                                          << 144     }else{
151     else {                                     << 145       G4cout <<" Error EvtMap Not Found "<< i << G4endl;
152       G4cout << " Error EvtMap Not Found " <<  << 
153     }                                             146     }
154     if (EvtMap) {                              << 147     if ( EvtMap )  {
155       //=== Sum up HitsMap of this event to Hi    148       //=== Sum up HitsMap of this event to HitsMap of RUN.===
156       *fRunMap[i] += *EvtMap;                  << 149       *theRunMap[i] += *EvtMap;
157       //======================================    150       //======================================================
158     }                                             151     }
159   }                                               152   }
                                                   >> 153 
                                                   >> 154   
160 }                                                 155 }
161                                                   156 
162 //....oooOO0OOooo........oooOO0OOooo........oo << 157 //=================================================================
163 //                                             << 
164 //  Access method for HitsMap of the RUN          158 //  Access method for HitsMap of the RUN
165 //                                                159 //
166 //-----                                           160 //-----
167 // Access HitsMap.                                161 // Access HitsMap.
168 //  By  MultiFunctionalDetector name and Colle    162 //  By  MultiFunctionalDetector name and Collection Name.
169 G4THitsMap<G4double>* B02Run::GetHitsMap(const << 163 G4THitsMap<G4double>* B02Run::GetHitsMap(const G4String& detName,
170 {                                              << 164            const G4String& colName){
171   G4String fullName = detName + "/" + colName; << 165     G4String fullName = detName+"/"+colName;
172   return GetHitsMap(fullName);                 << 166     G4cout << " getting hits map " << fullName << G4endl;
                                                   >> 167     return GetHitsMap(fullName);
173 }                                                 168 }
174                                                   169 
175 //-----                                           170 //-----
176 // Access HitsMap.                                171 // Access HitsMap.
177 //  By full description of collection name, th    172 //  By full description of collection name, that is
178 //    <MultiFunctional Detector Name>/<Primiti    173 //    <MultiFunctional Detector Name>/<Primitive Scorer Name>
179 G4THitsMap<G4double>* B02Run::GetHitsMap(const << 174 G4THitsMap<G4double>* B02Run::GetHitsMap(const G4String& fullName){
180 {                                              << 175     G4cout << " getting hits map " << fullName << G4endl;
181   G4int Ncol = fCollName.size();               << 176     G4int Ncol = theCollName.size();
182   for (G4int i = 0; i < Ncol; i++) {           << 177     for ( G4int i = 0; i < Ncol; i++){
183     if (fCollName[i] == fullName) {            << 178   if ( theCollName[i] == fullName ){
184       return fRunMap[i];                       << 179       return theRunMap[i];
                                                   >> 180   }
185     }                                             181     }
186   }                                            << 182     return NULL;
187   return NULL;                                 << 
188 }                                                 183 }
189                                                   184 
190 //....oooOO0OOooo........oooOO0OOooo........oo << 185 //-----
191                                                << 
192 // - Dump All HitsMap of this RUN. (for debugi    186 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
193 //   This method calls G4THisMap::PrintAll() f    187 //   This method calls G4THisMap::PrintAll() for individual HitsMap.
194 void B02Run::DumpAllScorer()                   << 188 void B02Run::DumpAllScorer(){
195 {                                              << 189 
196   // - Number of HitsMap in this RUN.             190   // - Number of HitsMap in this RUN.
197   G4int n = GetNumberOfHitsMap();                 191   G4int n = GetNumberOfHitsMap();
198   // - GetHitsMap and dump values.                192   // - GetHitsMap and dump values.
199   for (G4int i = 0; i < n; i++) {              << 193   for ( G4int i = 0; i < n ; i++ ){
200     G4THitsMap<G4double>* RunMap = GetHitsMap( << 194     G4THitsMap<G4double>* RunMap =GetHitsMap(i);
201     if (RunMap) {                              << 195     if ( RunMap ) {
202       G4cout << " PrimitiveScorer RUN " << Run << 196       G4cout << " PrimitiveScorer RUN " 
203              << G4endl;                        << 197        << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
204       G4cout << " Number of entries " << RunMa    198       G4cout << " Number of entries " << RunMap->entries() << G4endl;
205       std::map<G4int, G4double*>::iterator itr << 199       std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
206       for (; itr != RunMap->GetMap()->end(); i << 200       for(; itr != RunMap->GetMap()->end(); itr++) {
207         G4cout << "  copy no.: " << itr->first << 201   G4cout << "  copy no.: " << itr->first
                                                   >> 202          << "  Run Value : " << *(itr->second) 
                                                   >> 203          << G4endl;
208       }                                           204       }
209     }                                             205     }
210   }                                               206   }
211 }                                                 207 }
212                                                   208 
213 //....oooOO0OOooo........oooOO0OOooo........oo << 
214                                                << 
215 void B02Run::Merge(const G4Run* aRun)          << 
216 {                                              << 
217   const B02Run* localRun = static_cast<const B << 
218   //========================================== << 
219   // Merge HitsMap of working threads          << 
220   //========================================== << 
221   G4int nCol = localRun->fCollID.size();       << 
222   for (G4int i = 0; i < nCol; i++) {  // Loop  << 
223     if (localRun->fCollID[i] >= 0) {           << 
224       *fRunMap[i] += *localRun->fRunMap[i];    << 
225     }                                          << 
226   }                                            << 
227                                                << 
228   G4Run::Merge(aRun);                          << 
229 }                                              << 
230                                                   209 
231 //....oooOO0OOooo........oooOO0OOooo........oo << 
232                                                   210