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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/medical/DICOM2/src/Dicom2Run.cc (Version 11.3.0) and /examples/extended/medical/DICOM2/src/Dicom2Run.cc (Version 5.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 /// \file Dicom2Run.cc                            
 28 /// \brief Implementation of the Dicom2Run cla    
 29                                                   
 30 //============================================    
 31 ///                                               
 32 ///  (Description)                                
 33 ///    Dicom2Run Class is for accumulating sco    
 34 ///  scored using G4MutiFunctionalDetector and    
 35 ///  Accumulation is done using G4THitsVector     
 36 ///                                               
 37 ///    The constructor Dicom2Run(const std::ve    
 38 ///  needs a vector filled with MultiFunctiona    
 39 ///  was assigned at instantiation of MultiFun    
 40 ///  Then Dicom2Run constructor automatically     
 41 ///  in the MFD, and obtains collectionIDs of     
 42 ///  to those primitive scorers. Futhermore, t    
 43 ///  for accumulating during a RUN are automat    
 44 ///  (*) Collection Name is same as primitive     
 45 ///                                               
 46 ///    The resultant information is kept insid    
 47 ///  data members.                                
 48 ///  std::vector<G4String> fCollName;             
 49 ///  std::vector<G4int> fCollID;                  
 50 ///  std::vector<Dicom2RunVector*> fRunMap; //    
 51 ///                                               
 52 ///  The resualtant HitsVector objects are obt    
 53 ///  GetHitsVector(..).                           
 54 ///                                               
 55 //============================================    
 56                                                   
 57 #include "Dicom2Run.hh"                           
 58                                                   
 59 #include "DicomDetectorConstruction.hh"           
 60                                                   
 61 #include "G4MultiFunctionalDetector.hh"           
 62 #include "G4SDManager.hh"                         
 63 #include "G4VPrimitiveScorer.hh"                  
 64                                                   
 65 #include <cstdint>                                
 66                                                   
 67 //....oooOO0OOooo........oooOO0OOooo........oo    
 68 //                                                
 69 //  Constructor.                                  
 70 Dicom2Run::Dicom2Run() : DicomRun() {}            
 71                                                   
 72 //....oooOO0OOooo........oooOO0OOooo........oo    
 73 //                                                
 74 //  Constructor.                                  
 75 //   (The vector of MultiFunctionalDetector na    
 76 Dicom2Run::Dicom2Run(const std::vector<G4Strin    
 77 {                                                 
 78   ConstructMFD(mfdName);                          
 79 }                                                 
 80                                                   
 81 //....oooOO0OOooo........oooOO0OOooo........oo    
 82 //                                                
 83 // Destructor                                     
 84 //    clear all data members.                     
 85 Dicom2Run::~Dicom2Run()                           
 86 {                                                 
 87   //--- Clear HitsVector for RUN                  
 88   for (std::size_t i = 0; i < fRunMap.size();     
 89     if (fRunMap[i]) fRunMap[i]->clear();          
 90   }                                               
 91   fCollName.clear();                              
 92   fCollID.clear();                                
 93   fRunMap.clear();                                
 94 }                                                 
 95                                                   
 96 //....oooOO0OOooo........oooOO0OOooo........oo    
 97 //                                                
 98 // Destructor                                     
 99 //    clear all data members.                     
100 void Dicom2Run::ConstructMFD(const std::vector    
101 {                                                 
102   DicomRun::ConstructMFD(mfdName);                
103                                                   
104   G4SDManager* SDman = G4SDManager::GetSDMpoin    
105   //==========================================    
106   //  Initalize RunMaps for accumulation.         
107   //  Get CollectionIDs for HitCollections.       
108   //==========================================    
109   for (std::size_t idet = 0; idet < mfdName.si    
110     // Loop for all MFD.                          
111     G4String detName = mfdName[idet];             
112     //--- Seek and Obtain MFD objects from SDm    
113     G4MultiFunctionalDetector* mfd =              
114       (G4MultiFunctionalDetector*)(SDman->Find    
115     //                                            
116     if (mfd) {                                    
117       //--- Loop over the registered primitive    
118       for (G4int icol = 0; icol < mfd->GetNumb    
119         // Get Primitive Scorer object.           
120         G4VPrimitiveScorer* scorer = mfd->GetP    
121         // collection name and collectionID fo    
122         // where type of HitsCollection is G4T    
123         // of primitive scorer.                   
124         // The collection name is given by :      
125         //  <MFD name>/<Primitive Scorer name>    
126         G4String collectionName = scorer->GetN    
127         G4String fullCollectionName = detName     
128         G4int collectionID = SDman->GetCollect    
129         //                                        
130         if (collectionID >= 0) {                  
131           G4cout << "++ " << fullCollectionNam    
132           // Store obtained HitsCollection inf    
133           // members. qnd creates new G4THitsV    
134           // quantities during RUN.               
135           fCollName.push_back(fullCollectionNa    
136           fCollID.push_back(collectionID);        
137           fRunMap.push_back(new Dicom2RunVecto    
138         }                                         
139         else {                                    
140           G4cout << "** collection " << fullCo    
141         }                                         
142       }                                           
143     }                                             
144   }                                               
145 }                                                 
146                                                   
147 //....oooOO0OOooo........oooOO0OOooo........oo    
148 //                                                
149 //  RecordEvent is called at end of event.        
150 //  For scoring purpose, the resultant quantit    
151 //  is accumulated during a Run.                  
152 void Dicom2Run::RecordEvent(const G4Event* aEv    
153 {                                                 
154   DicomRun::RecordEvent(aEvent);                  
155                                                   
156   // G4cout << "Dicom Run :: Recording event "    
157   //<< "..." << G4endl;                           
158   //=============================                 
159   //  HitsCollection of This Event                
160   //============================                  
161   G4HCofThisEvent* HCE = aEvent->GetHCofThisEv    
162   if (!HCE) return;                               
163                                                   
164   //==========================================    
165   // Sum up HitsVector of this Event  into Hit    
166   //==========================================    
167   for (std::size_t i = 0; i < fCollID.size();     
168     // Loop over HitsCollection                   
169     G4THitsMap<G4double>* EvtMap = nullptr;       
170     if (fCollID[i] >= 0) {                        
171       // Collection is attached to HCE            
172       EvtMap = static_cast<G4THitsMap<G4double    
173     }                                             
174     else {                                        
175       G4cout << " Error EvtMap Not Found " <<     
176     }                                             
177                                                   
178     // if valid pointer, add the pointer          
179     if (EvtMap) {                                 
180       // for(auto itr = EvtMap->begin(); itr !    
181       //     G4cout << "adding " << *EvtMap->G    
182       //=== Sum up HitsVector of this event to    
183       *fRunMap[i] += *EvtMap;                     
184     }                                             
185   }                                               
186 }                                                 
187                                                   
188 //....oooOO0OOooo........oooOO0OOooo........oo    
189 // Merge hits map from threads                    
190 void Dicom2Run::Merge(const G4Run* aRun)          
191 {                                                 
192   DicomRun::Merge(aRun);                          
193                                                   
194   const Dicom2Run* localRun = static_cast<cons    
195                                                   
196   Copy(fCollName, localRun->fCollName);           
197   Copy(fCollID, localRun->fCollID);               
198   std::size_t ncopies = Copy(fRunMap, localRun    
199   // copy function returns the fRunMap size if    
200   // so this loop isn't executed the first tim    
201   for (std::size_t i = ncopies; i < fRunMap.si    
202     *fRunMap[i] += *localRun->fRunMap[i];         
203 }                                                 
204                                                   
205 //....oooOO0OOooo........oooOO0OOooo........oo    
206 //============================================    
207 //  Access method for HitsVector of the RUN       
208 //                                                
209 //-----                                           
210 // Access HitsVector.                             
211 //  By  MultiFunctionalDetector name and Colle    
212 Dicom2Run::Dicom2RunVector* Dicom2Run::GetHits    
213                                                   
214 {                                                 
215   G4String fullName = detName + "/" + colName;    
216   return GetHitsVector(fullName);                 
217 }                                                 
218                                                   
219 //....oooOO0OOooo........oooOO0OOooo........oo    
220 // Access HitsVector.                             
221 //  By full description of collection name, th    
222 //    <MultiFunctional Detector Name>/<Primiti    
223 Dicom2Run::Dicom2RunVector* Dicom2Run::GetHits    
224 {                                                 
225   std::size_t Ncol = fCollName.size();            
226   for (std::size_t i = 0; i < Ncol; ++i) {        
227     if (fCollName[i] == fullName) {               
228       return fRunMap[i];                          
229     }                                             
230   }                                               
231                                                   
232   G4Exception("Dicom2Run", fullName.c_str(), J    
233               "GetHitsVector failed to locate     
234   return nullptr;                                 
235 }                                                 
236