Back to home page

EIC code displayed by LXR

 
 

    


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

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 //      GEANT 4 class implementation file
0029 //      CERN Geneva Switzerland
0030 //
0031 //
0032 //      ------------ GammaRayTelCalorimeterSD  ------
0033 //           by  R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
0034 //
0035 // ************************************************************
0036 
0037 #include "G4RunManager.hh"
0038 #include "GammaRayTelCalorimeterSD.hh"
0039 #include "GammaRayTelCalorimeterHit.hh"
0040 #include "GammaRayTelDetectorConstruction.hh"
0041 
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4VPhysicalVolume.hh"
0044 #include "G4Step.hh"
0045 #include "G4VTouchable.hh"
0046 #include "G4TouchableHistory.hh"
0047 #include "G4SDManager.hh"
0048 #include "G4ios.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 GammaRayTelCalorimeterSD::GammaRayTelCalorimeterSD(G4String name) : G4VSensitiveDetector(name) {
0053     auto *runManager = G4RunManager::GetRunManager();
0054     detector = (GammaRayTelDetectorConstruction*) (runManager->GetUserDetectorConstruction());
0055 
0056     numberOfCALBars = detector->GetNbOfCALBars();
0057     numberOfCALLayers = detector->GetNbOfCALLayers();
0058 
0059     // G4cout << NbOfCALBars << " bars " << G4endl;
0060     // G4cout << NbOfCALLayers << " layers " << G4endl;
0061 
0062     numberOfCALChannels = numberOfCALBars * numberOfCALLayers;
0063 
0064     calHitXID = new G4int[numberOfCALChannels];
0065     calHitYID = new G4int[numberOfCALChannels];
0066     collectionName.insert("CalorimeterCollection");
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0070 
0071 GammaRayTelCalorimeterSD::~GammaRayTelCalorimeterSD() {
0072     delete[] calHitXID;
0073     delete[] calHitYID;
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0077 
0078 void GammaRayTelCalorimeterSD::Initialize(G4HCofThisEvent*) {
0079     calorimeterCollection = new GammaRayTelCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0080     for (auto i = 0; i < numberOfCALChannels; i++) {
0081         calHitXID[i] = -1;
0082         calHitYID[i] = -1;
0083     }
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0087 
0088 auto GammaRayTelCalorimeterSD::ProcessHits(G4Step *step, G4TouchableHistory*) -> G4bool {
0089     G4double depositedEnergy = 0.;
0090     depositedEnergy = step->GetTotalEnergyDeposit();
0091     if (depositedEnergy == 0.) {
0092         return false;
0093     }
0094 
0095     // This TouchableHistory is used to obtain the physical volume of the hit
0096     auto *theTouchable = (G4TouchableHistory*) (step->GetPreStepPoint()->GetTouchable());
0097     auto *calorimeterBar = theTouchable->GetVolume();
0098     auto *calorimeterPlane = theTouchable->GetVolume(1);
0099     auto calorimeterBarNumber = calorimeterBar->GetCopyNo();
0100     auto calorimeterBarName = calorimeterBar->GetName();
0101 
0102     G4int planeNumber{0};
0103     planeNumber = calorimeterPlane->GetCopyNo();
0104 
0105     auto planeName = calorimeterPlane->GetName();
0106 
0107     G4int NChannel = 0;
0108     NChannel = planeNumber * numberOfCALBars + calorimeterBarNumber;
0109 
0110     if (planeName == "CALLayerX") { // The hit is on a X CsI (cesium iodide) plane
0111         if (calHitXID[NChannel] == -1) { // This is a new hit
0112             auto *calorimeterHit = new GammaRayTelCalorimeterHit;
0113             calorimeterHit->SetCALType(1);
0114             calorimeterHit->AddEnergy(depositedEnergy);
0115             calorimeterHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0116             calorimeterHit->SetCALPlaneNumber(planeNumber);
0117             calorimeterHit->SetCALBarNumber(calorimeterBarNumber);
0118             calHitXID[NChannel] = calorimeterCollection->insert(calorimeterHit) - 1;
0119         } else { // This is not new
0120             (*calorimeterCollection)[calHitXID[NChannel]]->AddEnergy(depositedEnergy);
0121         }
0122     }
0123 
0124     if (planeName == "CALLayerY") { // The hit is on an Y CsI (cesium iodide) plane
0125         if (calHitYID[NChannel] == -1) { // This is a new hit
0126             auto *calorimeterHit = new GammaRayTelCalorimeterHit;
0127             calorimeterHit->SetCALType(0);
0128             calorimeterHit->AddEnergy(depositedEnergy);
0129             calorimeterHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0130             calorimeterHit->SetCALPlaneNumber(planeNumber);
0131             calorimeterHit->SetCALBarNumber(calorimeterBarNumber);
0132             calHitYID[NChannel] = calorimeterCollection->insert(calorimeterHit) - 1;
0133         } else { // This is not new
0134             (*calorimeterCollection)[calHitYID[NChannel]]->AddEnergy(depositedEnergy);
0135         }
0136     }
0137 
0138     return true;
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0142 
0143 void GammaRayTelCalorimeterSD::EndOfEvent(G4HCofThisEvent *HCE) {
0144     static G4int collectionIdentifier = -1;
0145     if (collectionIdentifier < 0) {
0146         collectionIdentifier = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0147     }
0148     HCE->AddHitsCollection(collectionIdentifier, calorimeterCollection);
0149 
0150     for (auto i = 0; i < numberOfCALChannels; i++) {
0151         calHitXID[i] = -1;
0152         calHitYID[i] = -1;
0153     }
0154 }
0155 
0156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0157 
0158 void GammaRayTelCalorimeterSD::clear() {
0159 }
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0162 
0163 void GammaRayTelCalorimeterSD::DrawAll() {
0164 }
0165 
0166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0167 
0168 void GammaRayTelCalorimeterSD::PrintAll() {
0169 }