bool AggregateCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { // check if energy was deposited G4double edep = aStep->GetTotalEnergyDeposit(); if(edep==0.) return false; // as in DD4hep::Simulation::Geant4GenericSD<Calorimeter> CLHEP::Hep3Vector prePos = aStep->GetPreStepPoint()->GetPosition(); CLHEP::Hep3Vector postPos = aStep->GetPostStepPoint()->GetPosition(); CLHEP::Hep3Vector midPos = 0.5*(postPos + prePos); DD4hep::Simulation::Position pos(midPos.x(), midPos.y(), midPos.z()); // check the cell ID uint64_t id = utils::cellID(m_seg, *aStep); DD4hep::Simulation::Geant4CalorimeterHit* hit = nullptr; DD4hep::Simulation::Geant4CalorimeterHit* hitMatch = nullptr; // Check if there is already some energy deposit in that cell for(int i=0; i<m_calorimeterCollection->entries(); i++) { hit = dynamic_cast<DD4hep::Simulation::Geant4CalorimeterHit*> (m_calorimeterCollection->GetHit(i)); if(hit->cellID == id) { hitMatch = hit; hitMatch->energyDeposit += edep; return true; } } // if not, create a new hit // deleted in ~G4Event hitMatch = new DD4hep::Simulation::Geant4CalorimeterHit(pos); hitMatch->cellID = id; hitMatch->energyDeposit = edep; m_calorimeterCollection->insert(hitMatch); return true; }
bool GflashCalorimeterSD::ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) { // This method will be called if gflash parametrisation is performed G4double edep = aSpot->GetEnergySpot()->GetEnergy(); // check if energy was deposited if (edep == 0.) return false; CLHEP::Hep3Vector geantPos = aSpot->GetEnergySpot()->GetPosition(); dd4hep::Position pos(geantPos.x(), geantPos.y(), geantPos.z()); // create a new hit // deleted in ~G4Event dd4hep::sim::Geant4CalorimeterHit* hit = new dd4hep::sim::Geant4CalorimeterHit(pos); hit->cellID = cellID(*aSpot); hit->energyDeposit = edep; m_calorimeterCollection->insert(hit); return true; }
bool SimpleCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { // check if energy was deposited G4double edep = aStep->GetTotalEnergyDeposit(); if(edep==0.) return false; // as in DD4hep::Simulation::Geant4GenericSD<Calorimeter> CLHEP::Hep3Vector prePos = aStep->GetPreStepPoint()->GetPosition(); DD4hep::Simulation::Position pos(prePos.x(), prePos.y(), prePos.z()); auto hit = new DD4hep::Simulation::Geant4CalorimeterHit(pos); hit->cellID = utils::cellID(m_seg, *aStep); hit->energyDeposit = edep; m_calorimeterCollection->insert(hit); return true; }
bool GflashCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { // This method is called if full simulation is performed // check if energy was deposited G4double edep = aStep->GetTotalEnergyDeposit(); if (edep == 0.) return false; CLHEP::Hep3Vector prePos = aStep->GetPreStepPoint()->GetPosition(); dd4hep::Position pos(prePos.x(), prePos.y(), prePos.z()); // create a new hit // deleted in ~G4Event dd4hep::sim::Geant4CalorimeterHit* hit = new dd4hep::sim::Geant4CalorimeterHit(pos); hit->cellID = utils::cellID(m_seg, *aStep); hit->energyDeposit = edep; m_calorimeterCollection->insert(hit); return true; }
void magFieldFromSegment(double * segment, double * pos, double * result) { CLHEP::Hep3Vector center(segment[0],segment[1],segment[2]); CLHEP::Hep3Vector length(segment[3],segment[4],segment[5]); CLHEP::Hep3Vector position(pos[0],pos[1],pos[2]); CLHEP::Hep3Vector dist = center - position; double L = length.mag(); double A = length.dot(dist) / L; double BSq = dist.mag2() - A*A; double APlusHalfL = (A + 0.5 * L); double AMinusHalfL = (A - 0.5 * L); double factor = APlusHalfL/sqrt(BSq + APlusHalfL*APlusHalfL) - AMinusHalfL/sqrt(BSq + AMinusHalfL*AMinusHalfL); CLHEP::Hep3Vector field = ((MUOVERFOURPI * factor) / (BSq * L )) * dist.cross(length); result[0] = field.x(); result[1] = field.y(); result[2] = field.z(); }
bool SimpleTrackerSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { // check if energy was deposited G4double edep = aStep->GetTotalEnergyDeposit(); if(edep==0.) return false; // as in DD4hep::Simulation::Geant4GenericSD<Tracker> CLHEP::Hep3Vector prePos = aStep->GetPreStepPoint()->GetPosition(); CLHEP::Hep3Vector postPos = aStep->GetPostStepPoint()->GetPosition(); DD4hep::Simulation::Position position(prePos.x(), prePos.y(), prePos.z()); CLHEP::Hep3Vector direction = postPos - prePos; // create a hit and add it to collection const G4Track* track = aStep->GetTrack(); // deleted in ~G4Event auto hit = new DD4hep::Simulation::Geant4TrackerHit( track->GetTrackID(), track->GetDefinition()->GetPDGEncoding(),edep, track->GetGlobalTime()); hit->cellID = segmentation::cellID(m_seg, *aStep); hit->energyDeposit = edep; hit->position = position; hit->momentum = direction; m_trackerCollection->insert(hit); return true; }