Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:10

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 // Authors: Susanna Guatelli and Francesco Romano
0027 // susanna@uow.edu.au, francesco.romano@ct.infn.it
0028 //
0029 //  code based on the basic example B2
0030 //
0031 #include "SensitiveDetector.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4Step.hh"
0034 #include "G4ThreeVector.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4ios.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4RunManager.hh"
0039 
0040 SensitiveDetector::SensitiveDetector(const G4String& name,
0041                          const G4String& hitsCollectionName, 
0042                          G4bool isThisAMicrodosimeter,
0043                          AnalysisManager* analysis_manager) 
0044  : G4VSensitiveDetector(name),
0045    fHitsCollection(NULL)
0046 {
0047   collectionName.insert(hitsCollectionName);
0048   analysis = analysis_manager;
0049   isMicrod = isThisAMicrodosimeter; // only false for the E-stage of the telescope
0050 }
0051 
0052 SensitiveDetector::~SensitiveDetector() 
0053 {}
0054 
0055 void SensitiveDetector::Initialize(G4HCofThisEvent* hce)
0056 {
0057   // Create hits collection
0058 
0059   fHitsCollection 
0060     = new SensitiveDetectorHitsCollection(SensitiveDetectorName, collectionName[0]); 
0061 
0062   // Add this collection in hce
0063 
0064   G4int hcID 
0065     = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0066   hce->AddHitsCollection( hcID, fHitsCollection ); 
0067 }
0068 
0069 G4bool SensitiveDetector::ProcessHits(G4Step* aStep, 
0070                                      G4TouchableHistory*)
0071 {  
0072   // energy deposit
0073   G4double edep = aStep->GetTotalEnergyDeposit();
0074   
0075   if (edep==0.) return false;
0076 
0077   // Uncomment the following lines to only score specific physical volumes 
0078   /*
0079   G4String volumeName = aStep -> GetPreStepPoint() -> GetPhysicalVolume()-> GetName();
0080   if(volumeName != "SV_phys1" && volumeName != "sen_bridge" && volumeName != "physSensitiveBridgeVolume" ) 
0081     return false;  
0082   */
0083   
0084   SensitiveDetectorHit* newHit = new SensitiveDetectorHit();
0085 
0086   newHit -> SetEdep(edep);
0087   
0088   // step length
0089   G4double len = aStep->GetStepLength();
0090 
0091   // only consider ions, protons, and neutrons for path length
0092   const G4ParticleDefinition* thisParticle = aStep ->
0093                       GetTrack() -> GetParticleDefinition() ;
0094   G4String particleName = thisParticle -> GetParticleName();
0095   G4int particleZ = thisParticle -> GetAtomicNumber();
0096 
0097   if ( (particleZ < 1) && (particleName != "neutron"))
0098     len = 0.;
0099 
0100   newHit->SetPath(len);
0101   
0102   fHitsCollection -> insert( newHit );
0103 
0104   return true;
0105 }
0106 
0107 void SensitiveDetector::EndOfEvent(G4HCofThisEvent*)
0108 {
0109 #ifdef ANALYSIS_USE
0110 // Initialisation of total energy deposition per event to zero
0111  G4double totalEdepInOneEvent=0;
0112  G4double totalPathLengthInOneEvent=0;
0113  
0114  G4int NbHits = fHitsCollection->entries();
0115    //G4cout << "number of hits " <<NbHits << G4endl;
0116  
0117  G4double edep, len; 
0118  
0119  for (G4int i=0;i<NbHits;i++) 
0120  {
0121      edep = (*fHitsCollection)[i]->GetEdep();
0122      totalEdepInOneEvent = totalEdepInOneEvent + edep;
0123  
0124      len = (*fHitsCollection)[i]->GetPath();
0125      totalPathLengthInOneEvent = totalPathLengthInOneEvent + len;
0126  }
0127  
0128  G4int eventID = G4RunManager::GetRunManager() ->
0129      GetCurrentEvent() -> GetEventID();
0130 
0131 
0132  if (totalEdepInOneEvent!=0)
0133  {
0134      if (isMicrod==true) analysis -> StoreEnergyDeposition(totalEdepInOneEvent/keV, totalPathLengthInOneEvent/um, eventID);
0135      else analysis -> StoreSecondStageEnergyDeposition(totalEdepInOneEvent/keV, eventID); 
0136  }
0137 #endif 
0138 }