Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:35

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