Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:56

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software
0028 // shall cite the following Geant4-DNA collaboration publications:
0029 // Med. Phys. 45 (2018) e722-e739
0030 // Phys. Med. 31 (2015) 861-874
0031 // Med. Phys. 37 (2010) 4692-4708
0032 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0033 //
0034 // The Geant4-DNA web site is available at http://geant4-dna.org
0035 //
0036 /// \file TrackerSD.cc
0037 /// \brief Implementation of the TrackerSD class
0038 
0039 #include "TrackerSD.hh"
0040 
0041 #include "G4AnalysisManager.hh"
0042 #include "G4SDManager.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "Randomize.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 TrackerSD::TrackerSD(const G4String& name, const G4String& hitsCollectionName)
0049   : G4VSensitiveDetector(name), fHitsCollection(NULL)
0050 {
0051   collectionName.insert(hitsCollectionName);
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 TrackerSD::~TrackerSD() {}
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 void TrackerSD::Initialize(G4HCofThisEvent* hce)
0061 {
0062   // Create hits collection
0063   fHitsCollection = new TrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
0064 
0065   // Add this collection in hce
0066   G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0067 
0068   hce->AddHitsCollection(hcID, fHitsCollection);
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 G4bool TrackerSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0074 {
0075   // Energy deposit
0076   G4double edep = aStep->GetTotalEnergyDeposit();
0077 
0078   if (edep == 0.) return false;
0079 
0080   TrackerHit* newHit = new TrackerHit();
0081 
0082   newHit->SetTrackID(aStep->GetTrack()->GetTrackID());
0083   newHit->SetEdep(edep);
0084   newHit->SetPos(aStep->GetPostStepPoint()->GetPosition());
0085 
0086   if (aStep->GetTrack()->GetTrackID() == 1 && aStep->GetTrack()->GetParentID() == 0)
0087     newHit->SetIncidentEnergy(aStep->GetTrack()->GetVertexKineticEnergy());
0088 
0089   fHitsCollection->insert(newHit);
0090 
0091   // Print
0092   // newHit->Print();
0093 
0094   return true;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 void TrackerSD::EndOfEvent(G4HCofThisEvent*)
0099 {
0100   G4int nofHits = fHitsCollection->entries();
0101 
0102   G4double Einc = 0;
0103 
0104   /*
0105   G4cout << G4endl
0106   << "-------->Hits Collection: in this event they are "
0107   << nofHits
0108   << " hits in the target volume " << G4endl;
0109   */
0110 
0111   // PROCESSING OF PROXIMITY FUNCTION t(x)
0112 
0113   // *************************************
0114   // Please select herebelow :
0115   // - the minimum value of x radius
0116   // - the maximum value of x radius
0117   // - the number of steps in radius
0118 
0119   G4double minRadius = 0.1 * nm;
0120 
0121   G4double maxRadius = 10000 * nm;
0122   G4int nRadiusSteps = 101;
0123 
0124   //
0125 
0126   auto analysisManager = G4AnalysisManager::Instance();
0127 
0128   G4double radius(minRadius);
0129   G4double stpRadius(std::pow(maxRadius / radius, 1. / static_cast<G4double>(nRadiusSteps - 1)));
0130   G4int step(nRadiusSteps);
0131   G4int noRadius(0);
0132 
0133   // 1) loop on radius
0134 
0135   while (step > 0) {
0136     step--;
0137     noRadius = nRadiusSteps - step;
0138 
0139     // G4cout << "---radius/nm=" << radius/nm  << G4endl;
0140 
0141     // Computation of t(x)
0142 
0143     G4double tNum = 0.;
0144     G4double tDenom = 0.;
0145     G4int nbEdep = 0;
0146 
0147     // 2) loop on hits
0148 
0149     for (G4int k = 0; k < nofHits; k++) {
0150       G4ThreeVector hitPos = (*fHitsCollection)[k]->GetPos();
0151       G4double hitNrj = (*fHitsCollection)[k]->GetEdep();
0152 
0153       // G4cout << "======> hit position x/nm =" << hitPos.x()/nm << G4endl;
0154       // G4cout << "======> hit position y/nm =" << hitPos.y()/nm << G4endl;
0155       // G4cout << "======> hit position z/nm =" << hitPos.z()/nm << G4endl;
0156 
0157       // 3) loop on all other hits located within shell
0158 
0159       G4double localSum = 0.;
0160 
0161       for (G4int i = 0; i < nofHits; i++) {
0162         if ((*fHitsCollection)[i]->GetIncidentEnergy() > 0)
0163           Einc = (*fHitsCollection)[i]->GetIncidentEnergy();
0164 
0165         G4ThreeVector localPosi = (*fHitsCollection)[i]->GetPos();
0166 
0167         if (((localPosi.x() - hitPos.x()) * (localPosi.x() - hitPos.x())
0168                + (localPosi.y() - hitPos.y()) * (localPosi.y() - hitPos.y())
0169                + (localPosi.z() - hitPos.z()) * (localPosi.z() - hitPos.z())
0170              < radius * stpRadius * radius * stpRadius)
0171             && ((localPosi.x() - hitPos.x()) * (localPosi.x() - hitPos.x())
0172                   + (localPosi.y() - hitPos.y()) * (localPosi.y() - hitPos.y())
0173                   + (localPosi.z() - hitPos.z()) * (localPosi.z() - hitPos.z())
0174                 >= radius * radius))
0175 
0176         {
0177           localSum = localSum + (*fHitsCollection)[i]->GetEdep();
0178           nbEdep = nbEdep + 1;
0179         }
0180       }
0181 
0182       tNum = tNum + localSum * hitNrj;
0183       tDenom = tDenom + hitNrj;
0184 
0185     }  // loop on hits
0186 
0187     // fill ntuple including weighting
0188     // does not work with ntuple merging...
0189 
0190     analysisManager->FillNtupleDColumn(0, 0, radius / nm);
0191     analysisManager->FillNtupleIColumn(0, 1, noRadius);
0192     analysisManager->FillNtupleDColumn(0, 2, nofHits);
0193     analysisManager->FillNtupleDColumn(0, 3, nbEdep);
0194     analysisManager->FillNtupleDColumn(0, 4, (tNum / tDenom) / eV);
0195     analysisManager->FillNtupleDColumn(0, 5, (stpRadius * radius) / nm);
0196     analysisManager->FillNtupleDColumn(0, 6, Einc / eV);
0197     analysisManager->AddNtupleRow();
0198 
0199     // G4cout << "---radius/nm=" << radius/nm << G4endl;
0200     // G4cout << "----end of radius--- " << radius/nm << G4endl;
0201 
0202     radius *= stpRadius;
0203 
0204   }  // loop on radii
0205 }
0206 
0207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......