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 10.5 ] [ 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/runAndEvent/RE02/src/RE02Run.cc (Version 11.3.0) and /examples/extended/runAndEvent/RE02/src/RE02Run.cc (Version 8.0)


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