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 //      ------------ GammaRayTelTrackerSD  ------
0033 //           by  R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
0034 //
0035 // ************************************************************
0036 
0037 #include "GammaRayTelTrackerSD.hh"
0038 #include "GammaRayTelTrackerHit.hh"
0039 #include "GammaRayTelDetectorConstruction.hh"
0040 
0041 #include "G4RunManager.hh"
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 GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4String name) : G4VSensitiveDetector(name) {
0053     auto *runManager = G4RunManager::GetRunManager();
0054 
0055     detector = (GammaRayTelDetectorConstruction*) (runManager->GetUserDetectorConstruction());
0056 
0057     auto numberOfTKRTiles = detector->GetNbOfTKRTiles();
0058     numberOfTKRStrips = detector->GetNbOfTKRStrips();
0059     numberOfTKRLayers = detector->GetNbOfTKRLayers();
0060     numberOfTKRStrips = numberOfTKRStrips * numberOfTKRTiles;
0061     numberOfTKRChannels = numberOfTKRStrips * numberOfTKRTiles * numberOfTKRLayers;
0062 
0063     tkrHitXID = new G4int[numberOfTKRChannels];
0064     tkrHitYID = new G4int[numberOfTKRChannels];
0065     
0066     constexpr auto TRACKER_COLLECTION_NAME = "TrackerCollection";
0067     collectionName.insert(TRACKER_COLLECTION_NAME);
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0071 
0072 GammaRayTelTrackerSD::~GammaRayTelTrackerSD() {
0073     delete[] tkrHitXID;
0074     delete[] tkrHitYID;
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0078 
0079 void GammaRayTelTrackerSD::Initialize(G4HCofThisEvent*) {
0080     trackerCollection = new GammaRayTelTrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
0081 
0082     for (auto i = 0; i < numberOfTKRChannels; i++) {
0083         tkrHitXID[i] = -1;
0084         tkrHitYID[i] = -1;
0085     };
0086 }
0087 
0088 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0089 
0090 auto GammaRayTelTrackerSD::ProcessHits(G4Step *step, G4TouchableHistory*) -> G4bool {
0091     G4double depositedEnergy = 0.;
0092     depositedEnergy = step->GetTotalEnergyDeposit();
0093     if (depositedEnergy == 0.) {
0094         return false;
0095     }
0096 
0097     auto totalNumberOfStrips = detector->GetNbOfTKRStrips();
0098     auto totalnumberOfTiles = detector->GetNbOfTKRTiles();
0099 
0100     // This TouchableHistory is used to obtain the physical volume of the hit
0101     auto *touchable = (G4TouchableHistory*) (step->GetPreStepPoint()->GetTouchable());
0102     auto *plane = touchable->GetVolume(2);
0103 
0104     G4int planeNumber = 0;
0105     planeNumber = plane->GetCopyNo();
0106     auto planeName = plane->GetName();
0107 
0108     // The hits sees now the real strip
0109 
0110     G4int stripNumber = 0;
0111     G4VPhysicalVolume *strip{nullptr};
0112     strip = touchable->GetVolume();
0113 
0114     G4String stripName = strip->GetName();
0115     stripNumber = strip->GetCopyNo();
0116 
0117     auto *tile = touchable->GetVolume(1);
0118     auto tileNumber = tile->GetCopyNo();
0119     auto tileName = tile->GetName();
0120     auto NTile = (tileNumber % totalnumberOfTiles);
0121     
0122     G4int channelNumber = 0;
0123 
0124     for (auto j = 0; j < totalnumberOfTiles; j++) {
0125         if (NTile == j) {
0126             stripNumber += totalNumberOfStrips * NTile;
0127         }
0128     }
0129 
0130     channelNumber = planeNumber * totalnumberOfTiles * totalNumberOfStrips + stripNumber;
0131 
0132 /*
0133     G4cout << " Channel: " << channelNumber << G4endl;
0134     G4cout << " Plane: " << planeNumber << " " << planeName << G4endl;
0135     G4cout << " Strip: " << stripNumber << " " << stripName << G4endl;
0136 */
0137 
0138     // The hit is on an X silicon plane
0139     if (planeName == "TKRDetectorX") {
0140         if (tkrHitXID[channelNumber] == -1) { // This is a new hit
0141             auto *trackerHit = new GammaRayTelTrackerHit;
0142             trackerHit->SetPlaneType(1);
0143             trackerHit->AddDepositedEnergy(depositedEnergy);
0144             trackerHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0145             trackerHit->SetSiliconPlaneNumber(planeNumber);
0146             trackerHit->SetStripNumber(stripNumber);
0147             tkrHitXID[channelNumber] = trackerCollection->insert(trackerHit) - 1;
0148         } else { // This is not new
0149             (*trackerCollection)[tkrHitXID[channelNumber]]->AddDepositedEnergy(depositedEnergy);
0150             // G4cout << "X" << planeNumber << " " << stripNumber << G4endl;
0151         }
0152     }
0153 
0154     // The hit is on an Y silicon plane
0155     if (planeName == "TKRDetectorY") {
0156         if (tkrHitYID[channelNumber] == -1) { // This is a new hit
0157             auto *trackerHit = new GammaRayTelTrackerHit;
0158             trackerHit->SetPlaneType(0);
0159             trackerHit->AddDepositedEnergy(depositedEnergy);
0160             trackerHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0161             trackerHit->SetSiliconPlaneNumber(planeNumber);
0162             trackerHit->SetStripNumber(stripNumber);
0163             tkrHitYID[channelNumber] = trackerCollection->insert(trackerHit) - 1;
0164         } else { // This is not new
0165             (*trackerCollection)[tkrHitYID[channelNumber]]->AddDepositedEnergy(depositedEnergy);
0166             // G4cout << "Y" << planeNumber << " " << stripNumber << G4endl;
0167         }
0168     }
0169 
0170     return true;
0171 }
0172 
0173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0174 
0175 void GammaRayTelTrackerSD::EndOfEvent(G4HCofThisEvent *collection) {
0176     static G4int collectionIdentifier = -1;
0177     if (collectionIdentifier < 0) {
0178         collectionIdentifier = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0179     }
0180     collection->AddHitsCollection(collectionIdentifier, trackerCollection);
0181 
0182     for (auto i = 0; i < numberOfTKRChannels; i++) {
0183         tkrHitXID[i] = -1;
0184         tkrHitYID[i] = -1;
0185     }
0186 }
0187 
0188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0189 
0190 void GammaRayTelTrackerSD::clear() {
0191 }
0192 
0193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0194 
0195 void GammaRayTelTrackerSD::DrawAll() {
0196 }
0197 
0198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0199 
0200 void GammaRayTelTrackerSD::PrintAll() {
0201 }