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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/medical/DICOM/src/DicomRun.cc (Version 11.3.0) and /examples/extended/medical/DICOM/src/DicomRun.cc (Version 10.0.p4)


  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 // $Id: DicomRun.cc 74809 2013-10-22 09:49:26Z gcosmo $
 26 //                                                 27 //
 27 /// \file medical/DICOM/src/DicomRun.cc            28 /// \file medical/DICOM/src/DicomRun.cc
 28 /// \brief Implementation of the DicomRun clas     29 /// \brief Implementation of the DicomRun class
 29                                                    30 
 30 //============================================     31 //=====================================================================
 31 ///                                                32 ///
 32 ///  (Description)                                 33 ///  (Description)
 33 ///    DicomRun Class is for accumulating scor <<  34 ///    DicomRun Class is for accumulating scored quantities which is 
 34 ///  scored using G4MutiFunctionalDetector and     35 ///  scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
 35 ///  Accumulation is done using G4THitsMap obj     36 ///  Accumulation is done using G4THitsMap object.
 36 ///                                                37 ///
 37 ///    The constructor DicomRun(const std::vec     38 ///    The constructor DicomRun(const std::vector<G4String> mfdName)
 38 ///  needs a vector filled with MultiFunctiona     39 ///  needs a vector filled with MultiFunctionalDetector names which
 39 ///  was assigned at instantiation of MultiFun     40 ///  was assigned at instantiation of MultiFunctionalDetector(MFD).
 40 ///  Then DicomRun constructor automatically s     41 ///  Then DicomRun constructor automatically scans primitive scorers
 41 ///  in the MFD, and obtains collectionIDs of      42 ///  in the MFD, and obtains collectionIDs of all collections associated
 42 ///  to those primitive scorers. Futhermore, t <<  43 ///  to those primitive scorers. Futhermore, the G4THitsMap objects 
 43 ///  for accumulating during a RUN are automat     44 ///  for accumulating during a RUN are automatically created too.
 44 ///  (*) Collection Name is same as primitive      45 ///  (*) Collection Name is same as primitive scorer name.
 45 ///                                            <<  46 /// 
 46 ///    The resultant information is kept insid     47 ///    The resultant information is kept inside DicomRun objects as
 47 ///  data members.                                 48 ///  data members.
 48 ///  std::vector<G4String> fCollName;              49 ///  std::vector<G4String> fCollName;            // Collection Name,
 49 ///  std::vector<G4int> fCollID;                   50 ///  std::vector<G4int> fCollID;                 // Collection ID,
 50 ///  std::vector<G4THitsMap<G4double>*> fRunMa     51 ///  std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
 51 ///                                                52 ///
 52 ///  The resualtant HitsMap objects are obtain     53 ///  The resualtant HitsMap objects are obtain using access method,
 53 ///  GetHitsMap(..).                               54 ///  GetHitsMap(..).
 54 ///                                                55 ///
 55 //============================================     56 //=====================================================================
 56                                                    57 
 57 #include "DicomRun.hh"                             58 #include "DicomRun.hh"
                                                   >>  59 #include "G4SDManager.hh"
 58                                                    60 
 59 #include "G4MultiFunctionalDetector.hh"            61 #include "G4MultiFunctionalDetector.hh"
 60 #include "G4SDManager.hh"                      << 
 61 #include "G4VPrimitiveScorer.hh"                   62 #include "G4VPrimitiveScorer.hh"
 62                                                    63 
 63 //....oooOO0OOooo........oooOO0OOooo........oo     64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 64 //                                                 65 //
 65 //  Constructor.                               <<  66 //  Constructor. 
 66 DicomRun::DicomRun() : G4Run() {}              <<  67 DicomRun::DicomRun()
                                                   >>  68 : G4Run()
                                                   >>  69 { }
 67                                                    70 
 68 //....oooOO0OOooo........oooOO0OOooo........oo     71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 69 //                                                 72 //
 70 //  Constructor.                                   73 //  Constructor.
 71 //   (The vector of MultiFunctionalDetector na     74 //   (The vector of MultiFunctionalDetector name has to given.)
 72 DicomRun::DicomRun(const std::vector<G4String> <<  75 DicomRun::DicomRun(const std::vector<G4String> mfdName): G4Run()
 73 {                                                  76 {
 74   ConstructMFD(mfdName);                       <<  77     ConstructMFD(mfdName);
 75 }                                                  78 }
 76                                                    79 
 77 //....oooOO0OOooo........oooOO0OOooo........oo     80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 78 //                                                 81 //
 79 // Destructor                                      82 // Destructor
 80 //    clear all data members.                      83 //    clear all data members.
 81 DicomRun::~DicomRun()                              84 DicomRun::~DicomRun()
 82 {                                                  85 {
 83   //--- Clear HitsMap for RUN                      86   //--- Clear HitsMap for RUN
 84   size_t Nmap = fRunMap.size();                <<  87   G4int Nmap = fRunMap.size();
 85   for (size_t i = 0; i < Nmap; ++i) {          <<  88   for ( G4int i = 0; i < Nmap; i++){
 86     if (fRunMap[i]) fRunMap[i]->clear();       <<  89     if(fRunMap[i] ) fRunMap[i]->clear();
 87   }                                                90   }
 88   fCollName.clear();                               91   fCollName.clear();
 89   fCollID.clear();                                 92   fCollID.clear();
 90   fRunMap.clear();                                 93   fRunMap.clear();
 91 }                                                  94 }
 92                                                    95 
 93 //....oooOO0OOooo........oooOO0OOooo........oo     96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 94 //                                                 97 //
 95 // Destructor                                      98 // Destructor
 96 //    clear all data members.                      99 //    clear all data members.
 97 void DicomRun::ConstructMFD(const std::vector<    100 void DicomRun::ConstructMFD(const std::vector<G4String>& mfdName)
 98 {                                                 101 {
 99   G4SDManager* SDman = G4SDManager::GetSDMpoin << 102 
100   //========================================== << 103     G4SDManager* SDman = G4SDManager::GetSDMpointer();
101   //  Initalize RunMaps for accumulation.      << 104     //=================================================
102   //  Get CollectionIDs for HitCollections.    << 105     //  Initalize RunMaps for accumulation.
103   //========================================== << 106     //  Get CollectionIDs for HitCollections.
104   size_t Nmfd = mfdName.size();                << 107     //=================================================
105   for (size_t idet = 0; idet < Nmfd; ++idet)   << 108     G4int Nmfd = mfdName.size();
106   {                                            << 109     for ( G4int idet = 0; idet < Nmfd ; idet++){  // Loop for all MFD.
107     G4String detName = mfdName[idet];          << 110         G4String detName = mfdName[idet];
108     //--- Seek and Obtain MFD objects from SDm << 111         //--- Seek and Obtain MFD objects from SDmanager.
109     G4MultiFunctionalDetector* mfd =           << 112         G4MultiFunctionalDetector* mfd =
110       (G4MultiFunctionalDetector*)(SDman->Find << 113         (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
111     //                                         << 
112     if (mfd) {                                 << 
113       //--- Loop over the registered primitive << 
114       for (G4int icol = 0; icol < mfd->GetNumb << 
115         // Get Primitive Scorer object.        << 
116         G4VPrimitiveScorer* scorer = mfd->GetP << 
117         // collection name and collectionID fo << 
118         // where type of HitsCollection is G4T << 
119         // of primitive scorer.                << 
120         // The collection name is given by <MF << 
121         // Scorer name>.                       << 
122         G4String collectionName = scorer->GetN << 
123         G4String fullCollectionName = detName  << 
124         G4int collectionID = SDman->GetCollect << 
125         //                                        114         //
126         if (collectionID >= 0) {               << 115         if ( mfd ){
127           G4cout << "++ " << fullCollectionNam << 116             //--- Loop over the registered primitive scorers.
128           // Store obtained HitsCollection inf << 117             for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
129           // And, creates new G4THitsMap for a << 118                 // Get Primitive Scorer object.
130           fCollName.push_back(fullCollectionNa << 119                 G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
131           fCollID.push_back(collectionID);     << 120                 // collection name and collectionID for HitsCollection,
132           fRunMap.push_back(new G4THitsMap<G4d << 121                 // where type of HitsCollection is G4THitsMap in case of primitive scorer.
133         }                                      << 122                 // The collection name is given by <MFD name>/<Primitive Scorer name>.
134         else {                                 << 123                 G4String collectionName = scorer->GetName();
135           G4cout << "** collection " << fullCo << 124                 G4String fullCollectionName = detName+"/"+collectionName;
                                                   >> 125                 G4int    collectionID = SDman->GetCollectionID(fullCollectionName);
                                                   >> 126                 //
                                                   >> 127                 if ( collectionID >= 0 ){
                                                   >> 128                     G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
                                                   >> 129                     // Store obtained HitsCollection information into data members.
                                                   >> 130                     // And, creates new G4THitsMap for accumulating quantities during RUN.
                                                   >> 131                     fCollName.push_back(fullCollectionName);
                                                   >> 132                     fCollID.push_back(collectionID);
                                                   >> 133                     fRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
                                                   >> 134                 } else {
                                                   >> 135                     G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
                                                   >> 136                 }
                                                   >> 137             }
136         }                                         138         }
137       }                                        << 
138     }                                             139     }
139   }                                            << 
140 }                                                 140 }
141                                                   141 
142 //....oooOO0OOooo........oooOO0OOooo........oo    142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 //                                                143 //
144 //  RecordEvent is called at end of event.        144 //  RecordEvent is called at end of event.
145 //  For scoring purpose, the resultant quantit    145 //  For scoring purpose, the resultant quantity in a event,
146 //  is accumulated during a Run.                  146 //  is accumulated during a Run.
147 void DicomRun::RecordEvent(const G4Event* aEve    147 void DicomRun::RecordEvent(const G4Event* aEvent)
148 {                                                 148 {
149   // disable below because this is done in G4R << 149     numberOfEvent++;  // This is an original line.
150   // numberOfEvent++;  // This is an original  << 
151                                                   150 
152   // G4cout << "Dicom Run :: Recording event " << 151     //G4cout << "Dicom Run :: Recording event " << aEvent->GetEventID() << "..." << G4endl;
153   //<< "..." << G4endl;                        << 152     //=============================
154   //=============================              << 153     // HitsCollection of This Event
155   //  HitsCollection of This Event             << 154     //============================
156   //============================               << 155     G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
157   G4HCofThisEvent* HCE = aEvent->GetHCofThisEv << 156     if (!HCE) return;
158   if (!HCE) return;                            << 157 
159                                                << 158     //=======================================================
160   //========================================== << 159     // Sum up HitsMap of this Event  into HitsMap of this RUN
161   // Sum up HitsMap of this Event  into HitsMa << 160     //=======================================================
162   //========================================== << 161     G4int Ncol = fCollID.size();
163   size_t Ncol = fCollID.size();                << 162     for ( G4int i = 0; i < Ncol ; i++ ){  // Loop over HitsCollection
164   for (size_t i = 0; i < Ncol; ++i)  // Loop o << 163         G4THitsMap<G4double>* EvtMap = 0;
165   {                                            << 164         if ( fCollID[i] >= 0 ){           // Collection is attached to HCE
166     G4THitsMap<G4double>* EvtMap = nullptr;    << 165             EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID[i]));
167     if (fCollID[i] >= 0)  // Collection is att << 166         }else{
168     {                                          << 167             G4cout <<" Error EvtMap Not Found "<< i << G4endl;
169       EvtMap = static_cast<G4THitsMap<G4double << 168         }
170     }                                          << 169         if ( EvtMap )  {
171     else {                                     << 170             //=== Sum up HitsMap of this event to HitsMap of RUN.===
172       G4cout << " Error EvtMap Not Found " <<  << 171             *fRunMap[i] += *EvtMap;
                                                   >> 172             //G4cout << "Summing EvtMap into RunMap at " << i << "..." << G4endl;
                                                   >> 173             //======================================================
                                                   >> 174         } //else {
                                                   >> 175           //G4cout << "Null pointer to EvtMap at " << i << "..." << G4endl;
                                                   >> 176           //}
173     }                                             177     }
174     if (EvtMap) {                              << 
175       //=== Sum up HitsMap of this event to Hi << 
176       *fRunMap[i] += *EvtMap;                  << 
177       // G4cout << "Summing EvtMap into RunMap << 
178       //====================================== << 
179     }  // else {                               << 
180     // G4cout << "Null pointer to EvtMap at "  << 
181     // }                                       << 
182   }                                            << 
183                                                   178 
184   G4Run::RecordEvent(aEvent);                  << 179     G4Run::RecordEvent(aEvent);
                                                   >> 180 
185 }                                                 181 }
186                                                   182 
187 //....oooOO0OOooo........oooOO0OOooo........oo    183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
188 // Merge hits map from threads                    184 // Merge hits map from threads
189 void DicomRun::Merge(const G4Run* aRun)           185 void DicomRun::Merge(const G4Run* aRun)
190 {                                                 186 {
191   const DicomRun* localRun = static_cast<const << 187     const DicomRun* localRun = static_cast<const DicomRun*>(aRun);
192   Copy(fCollName, localRun->fCollName);        << 188     copy(fCollName, localRun->fCollName);
193   Copy(fCollID, localRun->fCollID);            << 189     copy(fCollID, localRun->fCollID);
194   size_t ncopies = Copy(fRunMap, localRun->fRu << 190     unsigned ncopies = copy(fRunMap, localRun->fRunMap);
195   // copy function returns the fRunMap size if << 191     // copy function returns the fRunMap size if all data is copied
196   // so this loop isn't executed the first tim << 192     // so this loop isn't executed the first time around
197   for (size_t i = ncopies; i < fRunMap.size(); << 193     std::cout << "DicomRun :: Num copies = " << ncopies << G4endl;
198     *fRunMap[i] += *localRun->fRunMap[i];      << 194     for(unsigned i = ncopies; i < fRunMap.size(); ++i) {
199   }                                            << 195         *fRunMap[i] += *localRun->fRunMap[i];
200   G4Run::Merge(aRun);                          << 196     }
                                                   >> 197     G4Run::Merge(aRun);
201 }                                                 198 }
202                                                   199 
                                                   >> 200 
203 //....oooOO0OOooo........oooOO0OOooo........oo    201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204 //============================================    202 //=================================================================
205 //  Access method for HitsMap of the RUN          203 //  Access method for HitsMap of the RUN
206 //                                                204 //
207 //-----                                           205 //-----
208 // Access HitsMap.                                206 // Access HitsMap.
209 //  By  MultiFunctionalDetector name and Colle    207 //  By  MultiFunctionalDetector name and Collection Name.
210 G4THitsMap<G4double>* DicomRun::GetHitsMap(con << 208 G4THitsMap<G4double>* DicomRun::GetHitsMap(const G4String& detName,
                                                   >> 209                                            const G4String& colName) const
211 {                                                 210 {
212   G4String fullName = detName + "/" + colName; << 211     G4String fullName = detName+"/"+colName;
213   return GetHitsMap(fullName);                 << 212     return GetHitsMap(fullName);
214 }                                                 213 }
215                                                   214 
216 //....oooOO0OOooo........oooOO0OOooo........oo    215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217 // Access HitsMap.                                216 // Access HitsMap.
218 //  By full description of collection name, th    217 //  By full description of collection name, that is
219 //    <MultiFunctional Detector Name>/<Primiti    218 //    <MultiFunctional Detector Name>/<Primitive Scorer Name>
220 G4THitsMap<G4double>* DicomRun::GetHitsMap(con    219 G4THitsMap<G4double>* DicomRun::GetHitsMap(const G4String& fullName) const
221 {                                                 220 {
222   // G4THitsMap<G4double>* hitsmap = 0;        << 
223                                                   221 
224   size_t Ncol = fCollName.size();              << 222     //G4THitsMap<G4double>* hitsmap = 0;
225   for (size_t i = 0; i < Ncol; ++i) {          << 223     
226     if (fCollName[i] == fullName) {            << 224     G4int Ncol = fCollName.size();
227       return fRunMap[i];                       << 225     for ( G4int i = 0; i < Ncol; i++){
228       // if(hitsmap) { *hitsmap += *fRunMap[i] << 226         if ( fCollName[i] == fullName ){
229       // if(!hitsmap) { hitsmap = fRunMap[i];  << 227             return fRunMap[i];
                                                   >> 228             //if(hitsmap) { *hitsmap += *fRunMap[i]; }
                                                   >> 229             //if(!hitsmap) { hitsmap = fRunMap[i]; }
                                                   >> 230         }
230     }                                             231     }
231   }                                            << 
232                                                   232 
233   G4Exception("DicomRun", fullName.c_str(), Ju << 233     //if(hitsmap) { return hitsmap; }
234               "GetHitsMap failed to locate the << 234     
235   return nullptr;                              << 235     G4Exception("DicomRun", fullName.c_str(), JustWarning,
                                                   >> 236         "GetHitsMap failed to locate the requested HitsMap");
                                                   >> 237     return NULL;
236 }                                                 238 }
                                                   >> 239 
                                                   >> 240 
                                                   >> 241 
                                                   >> 242 
                                                   >> 243 
                                                   >> 244 
                                                   >> 245 
                                                   >> 246 
                                                   >> 247 
                                                   >> 248 
                                                   >> 249 
237                                                   250