Back to home page

EIC code displayed by LXR

 
 

    


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

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 "SiPMHit.hh"
0027 
0028 #include <cstdlib>
0029 
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 
0032 SiPMHit::SiPMHit(G4String aVolumeName, G4int aCopyNumSensor,
0033                  G4int aCopyNumCell)
0034     : fVolumeName(aVolumeName), fCopyNumCell(aCopyNumCell),
0035       fCopyNumSensor(aCopyNumSensor) {}
0036 
0037 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0038 
0039 void SiPMHit::Digitise(const G4double aTimeWindow,
0040                        const G4double aToaThreshold) {
0041 
0042   // process energy deposits
0043   if (fEdep.empty()) {
0044     fIsValidHit = false;
0045     return;
0046   }
0047 
0048   std::sort(fEdep.begin(), fEdep.end(),
0049             [](const std::pair<G4double, G4double> &left,
0050                const std::pair<G4double, G4double> &right) {
0051               return left.second < right.second; // second = time
0052             });
0053 
0054   G4double firstHitTime = fEdep[0].second;
0055   fEdepDigi = 0;
0056   for (size_t i = 0; i < fEdep.size(); ++i) {
0057     if (aTimeWindow < 0 || fEdep[i].second < firstHitTime + aTimeWindow)
0058       fEdepDigi += fEdep[i].first;
0059 #ifdef DEBUG
0060     else
0061       std::cout << "Rejecting hit (" << fEdep[i].first << " keV)  at time "
0062                 << fEdep[i].second << "(start: " << firstHitTime << ")"
0063                 << std::endl;
0064 #endif
0065     if ((fTimeOfArrival == -1) && (fEdepDigi > aToaThreshold))
0066       fTimeOfArrival = fEdep[i].second;
0067   }
0068   fIsValidHit = (fEdepDigi > 0);
0069 
0070   // non ionizing part, does not contribute to TOAs
0071   if (fEdepNonIonizing.empty())
0072     return;
0073 
0074   std::sort(fEdepNonIonizing.begin(), fEdepNonIonizing.end(),
0075             [](const std::pair<G4double, G4double> &left,
0076                const std::pair<G4double, G4double> &right) {
0077               return left.second < right.second; // second = time
0078             });
0079 
0080   fEdepNonIonizingDigi = 0;
0081   for (size_t i = 0; i < fEdepNonIonizing.size(); ++i) {
0082     if (aTimeWindow == -1 ||
0083         fEdepNonIonizing[i].second < firstHitTime + aTimeWindow)
0084       fEdepNonIonizingDigi += fEdepNonIonizing[i].first;
0085   }
0086 }