Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:16

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