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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/dna/microyz/src/TrackerSD.cc (Version 11.3.0) and /examples/extended/medical/dna/microyz/src/TrackerSD.cc (Version 11.1.2)


  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 // This example is provided by the Geant4-DNA      26 // This example is provided by the Geant4-DNA collaboration
 27 // Any report or published results obtained us <<  27 // Any report or published results obtained using the Geant4-DNA software 
 28 // shall cite the following Geant4-DNA collabo     28 // shall cite the following Geant4-DNA collaboration publications:
 29 // Med. Phys. 45 (2018) e722-e739              << 
 30 // Phys. Med. 31 (2015) 861-874                    29 // Phys. Med. 31 (2015) 861-874
 31 // Med. Phys. 37 (2010) 4692-4708                  30 // Med. Phys. 37 (2010) 4692-4708
 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) << 
 33 // The Geant4-DNA web site is available at htt     31 // The Geant4-DNA web site is available at http://geant4-dna.org
 34 //                                                 32 //
 35 /// \file TrackerSD.cc                             33 /// \file TrackerSD.cc
 36 /// \brief Implementation of the TrackerSD cla     34 /// \brief Implementation of the TrackerSD class
 37                                                    35 
 38 #include "TrackerSD.hh"                            36 #include "TrackerSD.hh"
 39                                                <<  37 #include "Randomize.hh"
 40 #include "G4AnalysisManager.hh"                    38 #include "G4AnalysisManager.hh"
 41 #include "G4SDManager.hh"                          39 #include "G4SDManager.hh"
                                                   >>  40 
                                                   >>  41 #include "G4RandomDirection.hh"
 42 #include "G4SystemOfUnits.hh"                      42 #include "G4SystemOfUnits.hh"
 43 #include "Randomize.hh"                        << 
 44                                                    43 
 45 //....oooOO0OOooo........oooOO0OOooo........oo     44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 46                                                    45 
 47 TrackerSD::TrackerSD(const G4String& name, con <<  46 TrackerSD::TrackerSD(const G4String& name,
 48   : G4VSensitiveDetector(name), fHitsCollectio <<  47                      const G4String& hitsCollectionName)
                                                   >>  48 :G4VSensitiveDetector(name),
                                                   >>  49 fHitsCollection(nullptr)
 49 {                                                  50 {
 50   collectionName.insert(hitsCollectionName);       51   collectionName.insert(hitsCollectionName);
 51 }                                                  52 }
 52                                                    53 
 53 //....oooOO0OOooo........oooOO0OOooo........oo     54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 54                                                    55 
 55 TrackerSD::~TrackerSD() = default;                 56 TrackerSD::~TrackerSD() = default;
 56                                                    57 
 57 //....oooOO0OOooo........oooOO0OOooo........oo     58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 58                                                    59 
 59 void TrackerSD::Initialize(G4HCofThisEvent* hc     60 void TrackerSD::Initialize(G4HCofThisEvent* hce)
 60 {                                                  61 {
 61   // Create hits collection                        62   // Create hits collection
 62   fHitsCollection = new TrackerHitsCollection( <<  63   fHitsCollection
                                                   >>  64     = new TrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
 63                                                    65 
 64   // Add this collection in hce                    66   // Add this collection in hce
 65   G4int hcID = G4SDManager::GetSDMpointer()->G << 
 66                                                    67 
 67   hce->AddHitsCollection(hcID, fHitsCollection <<  68   G4int hcID
                                                   >>  69     = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
                                                   >>  70 
                                                   >>  71   hce->AddHitsCollection( hcID, fHitsCollection );
 68 }                                                  72 }
 69                                                    73 
 70 //....oooOO0OOooo........oooOO0OOooo........oo     74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71                                                    75 
 72 G4bool TrackerSD::ProcessHits(G4Step* aStep, G <<  76 G4bool TrackerSD::ProcessHits(G4Step* aStep,
                                                   >>  77                                      G4TouchableHistory*)
 73 {                                                  78 {
 74   // Energy deposit                            <<  79   // energy deposit
 75   G4double edep = aStep->GetTotalEnergyDeposit     80   G4double edep = aStep->GetTotalEnergyDeposit();
 76                                                    81 
 77   if (edep == 0.) return false;                <<  82   if (edep==0.) return false;
 78                                                    83 
 79   auto newHit = new TrackerHit();                  84   auto newHit = new TrackerHit();
 80                                                    85 
 81   newHit->SetTrackID(aStep->GetTrack()->GetTra <<  86   newHit->SetTrackID  (aStep->GetTrack()->GetTrackID());
 82   newHit->SetEdep(edep);                           87   newHit->SetEdep(edep);
 83   newHit->SetPos(aStep->GetPostStepPoint()->Ge <<  88   newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
 84                                                    89 
 85   if (aStep->GetTrack()->GetTrackID() == 1 &&  <<  90   if (aStep->GetTrack()->GetTrackID()==1&&aStep->GetTrack()->GetParentID()==0){
 86     newHit->SetIncidentEnergy(aStep->GetTrack(     91     newHit->SetIncidentEnergy(aStep->GetTrack()->GetVertexKineticEnergy());
 87   }                                                92   }
 88   fHitsCollection->insert(newHit);             <<  93   fHitsCollection->insert( newHit );
 89   // newHit->Print();                          <<  94   //newHit->Print();
 90                                                    95 
 91   return true;                                     96   return true;
 92 }                                                  97 }
 93                                                    98 
 94 void TrackerSD::SetRadius(const G4double& valu     99 void TrackerSD::SetRadius(const G4double& value)
 95 {                                                 100 {
 96   fRadius = value;                                101   fRadius = value;
 97 }                                                 102 }
 98                                                   103 
 99 //....oooOO0OOooo........oooOO0OOooo........oo    104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100                                                   105 
101 void TrackerSD::EndOfEvent(G4HCofThisEvent*)      106 void TrackerSD::EndOfEvent(G4HCofThisEvent*)
102 {                                                 107 {
103   G4int nofHits = fHitsCollection->entries();     108   G4int nofHits = fHitsCollection->entries();
104                                                   109 
105   G4double Einc = 0;                           << 110   G4double Einc=0;
106                                                   111 
107   /*                                              112   /*
108   G4cout << G4endl                                113   G4cout << G4endl
109   << "-------->Hits Collection: in this event     114   << "-------->Hits Collection: in this event they are "
110   << nofHits                                      115   << nofHits
111   << " hits in the target volume " << G4endl;     116   << " hits in the target volume " << G4endl;
112   */                                              117   */
113                                                   118 
114   // PROCESSING OF MICRODOSIMETRY Y & Z SPECTR    119   // PROCESSING OF MICRODOSIMETRY Y & Z SPECTRA
115                                                   120 
116   // *************************************        121   // *************************************
117   // Please select herebelow :                    122   // Please select herebelow :
118   // the radius of the target sphere:             123   // the radius of the target sphere:
119   // variable name = radius                       124   // variable name = radius
120   // it is set to 5 nm by default)                125   // it is set to 5 nm by default)
                                                   >> 126   //
121                                                   127 
122   G4double radius = fRadius;                      128   G4double radius = fRadius;
123                                                   129 
124   //                                              130   //
125                                                   131 
126   //***************                               132   //***************
127   // y and z                                      133   // y and z
128   //***************                               134   //***************
129                                                   135 
130   // Select random hit                         << 136   // select random hit
131   G4int randHit = 0;  // Runs from 0 to number << 137   G4int randHit=0; // Runs from 0 to number of hits - 1
132   randHit = static_cast<G4int>(G4UniformRand() << 138   randHit = static_cast<G4int>( G4UniformRand()*nofHits );
133                                                   139 
134   /*                                              140   /*
135   G4cout                                          141   G4cout
136   << "======> random selection of hit number r    142   << "======> random selection of hit number randHit ="
137   << randHit << G4endl;                           143   << randHit << G4endl;
138   */                                              144   */
139                                                   145 
140   // Get selected random hit position          << 146   // get selected random hit position
141   G4ThreeVector hitPos = (*fHitsCollection)[ra << 147   G4ThreeVector hitPos =  (*fHitsCollection)[randHit]->GetPos();
142   // G4cout << "======> random hit position x/ << 148 //G4cout << "======> random hit position x/nm =" << hitPos.x()/nm << G4endl; 
143   // G4cout << "======> random hit position y/ << 149 //G4cout << "======> random hit position y/nm =" << hitPos.y()/nm << G4endl; 
144   // G4cout << "======> random hit position z/ << 150 //G4cout << "======> random hit position z/nm =" << hitPos.z()/nm << G4endl; 
145                                                << 151 
146   // Set random position of center of sphere w << 152   // set random position of center of sphere within radius
147   G4double chord = 4. * radius / 3;            << 153   G4double chord = 4.*radius/3;
148   G4double density = 1 * g / cm3;              << 154   G4double density = 1 * g/cm3;
149   G4double mass = (4. / 3) * CLHEP::pi * radiu << 155   G4double mass = (4./3)*CLHEP::pi*radius*radius*radius*density;
150                                                   156 
151   // Random placement of sphere: method 1      << 157   // random placement of sphere: method 1
152   /*                                              158   /*
153   G4ThreeVector randDir = G4RandomDirection();    159   G4ThreeVector randDir = G4RandomDirection();
154   G4double randRadius = G4UniformRand()*radius    160   G4double randRadius = G4UniformRand()*radius;
155   G4ThreeVector randCenterPos = randRadius*ran    161   G4ThreeVector randCenterPos = randRadius*randDir + hitPos;
156   */                                              162   */
157                                                   163 
158   // Random placement of sphere: method 2      << 164   // random placement of sphere: method 2
159                                                   165 
160   G4double xRand = 1.01 * radius;              << 166   G4double xRand = 1.01*radius;
161   G4double yRand = 1.01 * radius;              << 167   G4double yRand = 1.01*radius;
162   G4double zRand = 1.01 * radius;              << 168   G4double zRand = 1.01*radius;
163   G4double randRad = 1.01 * radius;            << 169   G4double randRad = 1.01*radius;
164   do {                                         << 170   do
165     xRand = (2 * G4UniformRand() - 1) * radius << 171   {
166     yRand = (2 * G4UniformRand() - 1) * radius << 172     xRand = (2*G4UniformRand()-1)*radius;
167     zRand = (2 * G4UniformRand() - 1) * radius << 173     yRand = (2*G4UniformRand()-1)*radius;
168     randRad = std::sqrt(xRand * xRand + yRand  << 174     zRand = (2*G4UniformRand()-1)*radius;
169   } while (randRad > radius);                  << 175     randRad = std::sqrt( xRand*xRand+yRand*yRand+zRand*zRand );
                                                   >> 176   }
                                                   >> 177   while (randRad>radius);
170                                                   178 
171   G4ThreeVector randCenterPos(xRand + hitPos.x << 179   G4ThreeVector
                                                   >> 180     randCenterPos(xRand+hitPos.x(),yRand+hitPos.y(),zRand+hitPos.z());
172                                                   181 
173   // Search for neighbouring hits in the spher << 182   // search for neighbouring hits in the sphere and cumulate deposited energy
174   //  in epsilon                                  183   //  in epsilon
175   G4double epsilon = 0;                           184   G4double epsilon = 0;
176   G4int nbEdep = 0;                               185   G4int nbEdep = 0;
177                                                   186 
178   for (G4int i = 0; i < nofHits; i++) {        << 187   for ( G4int i=0; i<nofHits; i++ )
179     if ((*fHitsCollection)[i]->GetIncidentEner << 188   {
                                                   >> 189 
                                                   >> 190     if ((*fHitsCollection)[i]->GetIncidentEnergy()>0)
180       Einc = (*fHitsCollection)[i]->GetInciden    191       Einc = (*fHitsCollection)[i]->GetIncidentEnergy();
181                                                   192 
182     G4ThreeVector localPos = (*fHitsCollection    193     G4ThreeVector localPos = (*fHitsCollection)[i]->GetPos();
183                                                   194 
184     // G4cout << i << " " << (*fHitsCollection    195     // G4cout << i << " " << (*fHitsCollection)[i] << G4endl;
185     // G4cout << i << " " << (*fHitsCollection    196     // G4cout << i << " " << (*fHitsCollection)[i]->GetEdep()/eV << G4endl;
186                                                   197 
187     if ((localPos.x() - randCenterPos.x()) * ( << 198     if (
188           + (localPos.y() - randCenterPos.y()) << 199         (localPos.x()-randCenterPos.x()) * (localPos.x()-randCenterPos.x()) +
189           + (localPos.z() - randCenterPos.z()) << 200         (localPos.y()-randCenterPos.y()) * (localPos.y()-randCenterPos.y()) +
190         <= radius * radius)                    << 201         (localPos.z()-randCenterPos.z()) * (localPos.z()-randCenterPos.z())
                                                   >> 202          <= radius*radius
                                                   >> 203        )
191                                                   204 
192     {                                             205     {
193       epsilon = epsilon + (*fHitsCollection)[i << 206       epsilon = epsilon + (*fHitsCollection)[i]->GetEdep() ;
194       nbEdep = nbEdep + 1;                     << 207       nbEdep = nbEdep+1;
195     }                                             208     }
                                                   >> 209 
196   }                                               210   }
197                                                   211 
198   // For testing only                          << 212   // for testing only
199   /*                                              213   /*
200   G4cout << "======> for hit number #" << rand    214   G4cout << "======> for hit number #" << randHit <<
201   ", we collect "                                 215   ", we collect "
202   << nbEdep << " energy depositions in a spher    216   << nbEdep << " energy depositions in a sphere of radius "
203   << radius/nm << " nm and mass "                 217   << radius/nm << " nm and mass "
204   << mass/kg << " kg for a total of "             218   << mass/kg << " kg for a total of "
205   << epsilon/eV << " eV or "                      219   << epsilon/eV << " eV or "
206   << (epsilon/joule)/(mass/kg) << " Gy" << G4e    220   << (epsilon/joule)/(mass/kg) << " Gy" << G4endl;
207   G4cout << "-" << G4endl;                        221   G4cout << "-" << G4endl;
208   */                                              222   */
209                                                   223 
210   /*                                              224   /*
211   FILE* myFile;                                   225   FILE* myFile;
212   myFile=fopen("yz.txt","a");                     226   myFile=fopen("yz.txt","a");
213   fprintf(myFile,"%e %e %e\n",radius/nm,(epsil    227   fprintf(myFile,"%e %e %e\n",radius/nm,(epsilon/eV)/(chord/nm),
214    (epsilon/joule)/(mass/kg));                    228    (epsilon/joule)/(mass/kg));
215   fclose(myFile);                                 229   fclose(myFile);
216   */                                              230   */
217                                                   231 
218   // Get analysis manager                      << 232   // get analysis manager
219   G4AnalysisManager* analysisManager = G4Analy    233   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
220                                                   234 
221   // Fill ntuple including weighting           << 235   // fill ntuple including weighting
222   analysisManager->FillNtupleDColumn(0, radius << 236   analysisManager->FillNtupleDColumn(0, radius/nm);
223   analysisManager->FillNtupleDColumn(2, nofHit    237   analysisManager->FillNtupleDColumn(2, nofHits);
224   analysisManager->FillNtupleDColumn(3, nbEdep    238   analysisManager->FillNtupleDColumn(3, nbEdep);
225   analysisManager->FillNtupleDColumn(4, (epsil << 239   analysisManager->FillNtupleDColumn(4, (epsilon/eV)/(chord/nm));
226   analysisManager->FillNtupleDColumn(5, (epsil << 240   analysisManager->FillNtupleDColumn(5, (epsilon/mass)/gray);
227   analysisManager->FillNtupleDColumn(6, Einc / << 241   analysisManager->FillNtupleDColumn(6, Einc/eV);
228   analysisManager->AddNtupleRow();                242   analysisManager->AddNtupleRow();
                                                   >> 243 
229 }                                                 244 }
230                                                   245 
231 //....oooOO0OOooo........oooOO0OOooo........oo    246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
232                                                   247