Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-02 07:37:30

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 Par04ParallelFullSensitiveDetector.cc
0027 /// \brief Implementation of the Par04ParallelFullSensitiveDetector class
0028 
0029 #include "Par04ParallelFullSensitiveDetector.hh"
0030 
0031 #include "Par04EventInformation.hh"  // for Par04EventInformation
0032 #include "Par04Hit.hh"  // for Par04Hit, Par04HitsCollection
0033 
0034 #include "G4Event.hh"  // for G4Event
0035 #include "G4EventManager.hh"  // for G4EventManager
0036 #include "G4HCofThisEvent.hh"  // for G4HCofThisEvent
0037 #include "G4SDManager.hh"  // for G4SDManager
0038 #include "G4Step.hh"  // for G4Step
0039 #include "G4Track.hh"  // for G4Track
0040 
0041 #include <CLHEP/Vector/Rotation.h>  // for HepRotation
0042 #include <CLHEP/Vector/ThreeVector.h>  // for Hep3Vector
0043 #include <G4CollectionNameVector.hh>  // for G4CollectionNameVector
0044 #include <G4FastHit.hh>  // for G4FastHit
0045 #include <G4FastTrack.hh>  // for G4FastTrack
0046 #include <G4RotationMatrix.hh>  // for G4RotationMatrix
0047 #include <G4StepPoint.hh>  // for G4StepPoint
0048 #include <G4THitsCollection.hh>  // for G4THitsCollection
0049 #include <G4ThreeVector.hh>  // for G4ThreeVector
0050 #include <G4VSensitiveDetector.hh>  // for G4VSensitiveDetector
0051 #include <G4VUserEventInformation.hh>  // for G4VUserEventInformation
0052 #include <cmath>  // for floor
0053 #include <cstddef>  // for size_t
0054 #include <vector>  // for vector
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 Par04ParallelFullSensitiveDetector::Par04ParallelFullSensitiveDetector(G4String aName)
0059   : G4VSensitiveDetector(aName)
0060 {
0061   collectionName.insert("physicalCellsFullSim");
0062 }
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 Par04ParallelFullSensitiveDetector::Par04ParallelFullSensitiveDetector(G4String aName,
0066                                                                        G4int aNbOfLayers,
0067                                                                        G4int aNbOfSlices,
0068                                                                        G4int aNbOfRows)
0069   : G4VSensitiveDetector(aName),
0070     fNbOfLayers(aNbOfLayers),
0071     fNbOfSlices(aNbOfSlices),
0072     fNbOfRows(aNbOfRows)
0073 {
0074   collectionName.insert("physicalCellsFullSim");
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 Par04ParallelFullSensitiveDetector::~Par04ParallelFullSensitiveDetector() = default;
0080 
0081 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0082 
0083 void Par04ParallelFullSensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
0084 {
0085   fHitsCollection = new Par04HitsCollection(SensitiveDetectorName, collectionName[0]);
0086   if (fHitCollectionID < 0) {
0087     fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0088   }
0089   aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 G4bool Par04ParallelFullSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0095 {
0096   G4double edep = aStep->GetTotalEnergyDeposit();
0097   if (edep == 0.) return true;
0098 
0099   auto touchable = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
0100 
0101   G4int layerNo = touchable->GetCopyNumber(0);
0102   G4int sliceNo = touchable->GetCopyNumber(1);
0103   G4int rowNo = touchable->GetCopyNumber(2);
0104 
0105   G4int hitID = fNbOfLayers * fNbOfSlices * rowNo + fNbOfLayers * sliceNo + layerNo;
0106   if (layerNo >= fNbOfLayers) {
0107     G4cout << "ERROR, problem with  Layer IDs: " << layerNo << " > " << fNbOfLayers << G4endl;
0108     return false;
0109   }
0110   if (sliceNo >= fNbOfSlices) {
0111     G4cout << "ERROR, problem with Slice IDs: " << sliceNo << " >= " << fNbOfSlices << G4endl;
0112     return false;
0113   }
0114   if (rowNo >= fNbOfRows) {
0115     G4cout << "ERROR, problem with Row  IDs: " << rowNo << " >= " << fNbOfRows << G4endl;
0116     return false;
0117   }
0118   auto hit = fHitsMap[hitID].get();
0119   if (hit == nullptr) {
0120     fHitsMap[hitID] = std::unique_ptr<Par04Hit>(new Par04Hit());
0121     hit = fHitsMap[hitID].get();
0122     hit->SetPhiId(sliceNo);
0123     hit->SetRhoId(layerNo);
0124     hit->SetZid(rowNo);
0125   }
0126 
0127   // Add energy deposit from G4Step
0128   hit->AddEdep(edep);
0129   // Increment the counter
0130   hit->AddNdep(1);
0131 
0132   // Fill time information from G4Step
0133   // If it's already filled, choose hit with earliest global time
0134   if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
0135     hit->SetTime(aStep->GetTrack()->GetGlobalTime());
0136 
0137   // Set type to parallel world full hit
0138   hit->SetType(2);
0139 
0140   return true;
0141 }
0142 
0143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0144 void Par04ParallelFullSensitiveDetector::EndOfEvent(G4HCofThisEvent*)
0145 {
0146   for (const auto& hits : fHitsMap) {
0147     fHitsCollection->insert(new Par04Hit(*hits.second.get()));
0148   }
0149   fHitsMap.clear();
0150 }