Back to home page

EIC code displayed by LXR

 
 

    


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

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