Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-04 08:01:31

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 HadCalorimeterSD.cc
0027 /// \brief Implementation of the B5::HadCalorimeterSD class
0028 
0029 #include "HadCalorimeterSD.hh"
0030 
0031 #include "Constants.hh"
0032 #include "HadCalorimeterHit.hh"
0033 
0034 #include "G4AffineTransform.hh"
0035 #include "G4HCofThisEvent.hh"
0036 #include "G4SDManager.hh"
0037 #include "G4Step.hh"
0038 #include "G4StepPoint.hh"
0039 
0040 namespace B5
0041 {
0042 
0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0044 
0045 HadCalorimeterSD::HadCalorimeterSD(G4String name) : G4VSensitiveDetector(name)
0046 {
0047   collectionName.insert("HadCalorimeterColl");
0048 }
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 void HadCalorimeterSD::Initialize(G4HCofThisEvent* hce)
0053 {
0054   fHitsCollection = new HadCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0055   if (fHCID < 0) {
0056     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0057   }
0058   hce->AddHitsCollection(fHCID, fHitsCollection);
0059 
0060   // fill calorimeter hits with zero energy deposition
0061   for (auto column = 0; column < kNofHadColumns; column++) {
0062     for (auto row = 0; row < kNofHadRows; row++) {
0063       fHitsCollection->insert(new HadCalorimeterHit());
0064     }
0065   }
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 G4bool HadCalorimeterSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0071 {
0072   auto edep = step->GetTotalEnergyDeposit();
0073   if (edep == 0.) return true;
0074 
0075   auto touchable = step->GetPreStepPoint()->GetTouchable();
0076   auto rowNo = touchable->GetCopyNumber(2);
0077   auto columnNo = touchable->GetCopyNumber(3);
0078   auto hitID = kNofHadRows * columnNo + rowNo;
0079   auto hit = (*fHitsCollection)[hitID];
0080 
0081   // check if it is first touch
0082   if (hit->GetColumnID() < 0) {
0083     hit->SetColumnID(columnNo);
0084     hit->SetRowID(rowNo);
0085     auto depth = touchable->GetHistory()->GetDepth();
0086     auto transform = touchable->GetHistory()->GetTransform(depth - 2);
0087     transform.Invert();
0088     hit->SetRot(transform.NetRotation());
0089     hit->SetPos(transform.NetTranslation());
0090   }
0091   // add energy deposition
0092   hit->AddEdep(edep);
0093 
0094   return true;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 }  // namespace B5