Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:36:58

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 /// \file CalorimeterSD.cc
0027 /// \brief Implementation of the B4c::CalorimeterSD class
0028 
0029 #include "CalorimeterSD.hh"
0030 
0031 #include "G4HCofThisEvent.hh"
0032 #include "G4SDManager.hh"
0033 #include "G4Step.hh"
0034 
0035 namespace B4c
0036 {
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 CalorimeterSD::CalorimeterSD(const G4String& name, const G4String& hitsCollectionName,
0041                              G4int nofCells)
0042   : G4VSensitiveDetector(name), fNofCells(nofCells)
0043 {
0044   collectionName.insert(hitsCollectionName);
0045 }
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 void CalorimeterSD::Initialize(G4HCofThisEvent* hce)
0050 {
0051   // Create hits collection
0052   fHitsCollection = new CalorHitsCollection(SensitiveDetectorName, collectionName[0]);
0053 
0054   // Add this collection in hce
0055   auto hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0056   hce->AddHitsCollection(hcID, fHitsCollection);
0057 
0058   // Create hits
0059   // fNofCells for cells + one more for total sums
0060   for (G4int i = 0; i < fNofCells + 1; i++) {
0061     fHitsCollection->insert(new CalorHit());
0062   }
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 G4bool CalorimeterSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0068 {
0069   // energy deposit
0070   auto edep = step->GetTotalEnergyDeposit();
0071 
0072   // step length
0073   G4double stepLength = 0.;
0074   if (step->GetTrack()->GetDefinition()->GetPDGCharge() != 0.) {
0075     stepLength = step->GetStepLength();
0076   }
0077 
0078   if (edep == 0. && stepLength == 0.) return false;
0079 
0080   auto touchable = (step->GetPreStepPoint()->GetTouchable());
0081 
0082   // Get calorimeter cell id
0083   auto layerNumber = touchable->GetReplicaNumber(1);
0084 
0085   // Get hit accounting data for this cell
0086   auto hit = (*fHitsCollection)[layerNumber];
0087   if (!hit) {
0088     G4ExceptionDescription msg;
0089     msg << "Cannot access hit " << layerNumber;
0090     G4Exception("CalorimeterSD::ProcessHits()", "MyCode0004", FatalException, msg);
0091   }
0092 
0093   // Get hit for total accounting
0094   auto hitTotal = (*fHitsCollection)[fHitsCollection->entries() - 1];
0095 
0096   // Add values
0097   hit->Add(edep, stepLength);
0098   hitTotal->Add(edep, stepLength);
0099 
0100   return true;
0101 }
0102 
0103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0104 
0105 void CalorimeterSD::EndOfEvent(G4HCofThisEvent*)
0106 {
0107   if (verboseLevel > 1) {
0108     auto nofHits = fHitsCollection->entries();
0109     G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits
0110            << " hits in the tracker chambers: " << G4endl;
0111     for (std::size_t i = 0; i < nofHits; ++i)
0112       (*fHitsCollection)[i]->Print();
0113   }
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 }  // namespace B4c