Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:47

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 // ********************************************************************
0027 //
0028 //  CaTS (Calorimetry and Tracking Simulation)
0029 //
0030 //  Authors : Hans Wenzel
0031 //            Soon Yung Jun
0032 //            (Fermi National Accelerator Laboratory)
0033 //
0034 // History
0035 //   October 18th, 2021 : first implementation
0036 //
0037 // ********************************************************************
0038 //
0039 /// \file InteractionSD.cc
0040 /// \brief Implementation of the CaTS::InteractionSD class
0041 
0042 // Geant4 headers:
0043 #include "G4HCofThisEvent.hh"
0044 #include "G4Step.hh"
0045 #include "G4ThreeVector.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4ios.hh"
0048 #include "G4SystemOfUnits.hh"
0049 // project headers
0050 #include "InteractionSD.hh"
0051 #include "ParticleChange.hh"
0052 
0053 InteractionSD::InteractionSD(G4String name)
0054   : G4VSensitiveDetector(name)
0055 {
0056   G4String HCname = name + "_HC";
0057   collectionName.insert(HCname);
0058   G4cout << collectionName.size() << "   InteractionSD name:  " << name
0059          << " collection Name: " << HCname << G4endl;
0060   fHCID = -1;
0061 }
0062 
0063 InteractionSD::~InteractionSD()
0064 {
0065   delete fFirstInter;
0066   delete fOtherInter;
0067 }
0068 
0069 void InteractionSD::Initialize(G4HCofThisEvent* HCE)
0070 {
0071   G4cout << "Hits Collection capacity:  " << HCE->GetCapacity() << G4endl;
0072   fInteractionHitsCollection =
0073     new InteractionHitsCollection(SensitiveDetectorName, collectionName[0]);
0074   if(fHCID < 0)
0075   {
0076     G4cout << "InteractionSD::Initialize:  " << SensitiveDetectorName << "   "
0077            << collectionName[0] << G4endl;
0078     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0079   }
0080   HCE->AddHitsCollection(fHCID, fInteractionHitsCollection);
0081   fFirstInter = new ParticleChange(true);
0082   fOtherInter = new ParticleChange();
0083 }
0084 
0085 G4bool InteractionSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0086 {
0087   G4int nsc = fFirstInter->GetNumberOfSecondaries();
0088   if(nsc > 0)
0089   {
0090     for(G4int i = 0; i < nsc; i++)
0091     {
0092       delete fFirstInter->GetSecondary(i);
0093     }
0094     fFirstInter->Clear();
0095   }
0096   nsc = fOtherInter->GetNumberOfSecondaries();
0097   if(nsc > 0)
0098   {
0099     for(G4int i = 0; i < nsc; i++)
0100     {
0101       delete fOtherInter->GetSecondary(i);
0102     }
0103     fOtherInter->Clear();
0104   }
0105   const std::vector<const G4Track*>* secs = aStep->GetSecondaryInCurrentStep();
0106   G4int nsec                              = secs->size();
0107   for(G4int i = 0; i < nsec; i++)
0108   {
0109     G4Track* tr = new G4Track(*((*secs)[i]));
0110     if(aStep->GetTrack()->GetTrackStatus() != fAlive)  // track looses identity
0111     {
0112       if(aStep->GetTrack()->GetParentID() == 0)  // primary track
0113       {
0114         fFirstInter->AddSecondary(tr);
0115       }
0116       else  // secondary track, and it's also looses identity (re-interaction)
0117       {
0118         fOtherInter->AddSecondary(tr);
0119       }
0120     }
0121   }  // end loop over secondaries
0122   G4int NSec = fFirstInter->GetNumberOfSecondaries();
0123   if(NSec > 0)
0124   {
0125     const G4DynamicParticle* sec = 0;
0126     for(G4int i = 0; i < NSec; i++)
0127     {
0128       sec = fFirstInter->GetSecondary(i)->GetDynamicParticle();
0129       const G4String& pname  = sec->GetDefinition()->GetParticleName();
0130       G4double pmom          = (sec->GetTotalMomentum()) / GeV;
0131       G4double Ekin          = (sec->GetKineticEnergy()) / GeV;
0132       G4double theta         = (sec->GetMomentum()).theta();
0133       InteractionHit* newHit = new InteractionHit(pname, pmom, Ekin, theta);
0134       fInteractionHitsCollection->insert(newHit);
0135     }
0136   }
0137   return true;
0138 }