Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21: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 /// \file exoticphysics/phonon/src/XAluminumElectrodeSensitivity.cc
0027 /// \brief Implementation of the XAluminumElectrodeSensitivity class
0028 //
0029 //
0030 #include "XAluminumElectrodeSensitivity.hh"
0031 
0032 #include "XAluminumElectrodeHit.hh"
0033 
0034 #include "G4AutoLock.hh"
0035 #include "G4HCofThisEvent.hh"
0036 #include "G4Navigator.hh"
0037 #include "G4SDManager.hh"
0038 #include "G4Step.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4Threading.hh"
0041 #include "G4TouchableHistory.hh"
0042 #include "G4Track.hh"
0043 
0044 #include <fstream>
0045 
0046 std::fstream* XAluminumElectrodeSensitivity::fWriter = 0;
0047 std::fstream* XAluminumElectrodeSensitivity::fWriter2 = 0;
0048 
0049 G4Mutex theMutex = G4MUTEX_INITIALIZER;  // Just need one
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0052 
0053 XAluminumElectrodeSensitivity::XAluminumElectrodeSensitivity(const G4String& name)
0054   : G4VSensitiveDetector(name)
0055 {
0056   collectionName.insert("XAluminumElectrodeHit");
0057   fHCID = -1;
0058 
0059   G4AutoLock lockIt(&theMutex);  // Only one thread opens files!
0060   fWriter = new std::fstream("caustic.ssv", std::fstream::out | std::fstream::ate);
0061   if (!fWriter->is_open()) {
0062     G4cerr << "XAluminumElectrodeSensitivity::Constructor:"
0063            << "\n\tFailed to open caustic.ssv for appending data."
0064            << "\n\tCreating caustic.ssv" << G4endl;
0065     fWriter->open("caustic.ssv");
0066   }
0067 
0068   fWriter2 = new std::fstream("timing.ssv", std::fstream::out | std::fstream::ate);
0069   if (!fWriter2->is_open()) {
0070     G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
0071            << "\n\tFailed to open timing.ssv for appending data."
0072            << "\n\tCreating timing.ssv." << G4endl;
0073     fWriter2->open("timing.ssv");
0074   }
0075 
0076   if (!(fWriter->is_open() && fWriter2->is_open())) {
0077     G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
0078            << "\nERROR: COULD NOT CREATE OUTPUT FILES FOR WRITING" << G4endl;
0079   }
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0083 
0084 XAluminumElectrodeSensitivity::~XAluminumElectrodeSensitivity()
0085 {
0086   G4AutoLock lockIt(&theMutex);  // Only one thread deletes!
0087 
0088   if (fWriter) {
0089     fWriter->close();
0090     delete fWriter;
0091     fWriter = 0;
0092   }
0093 
0094   if (fWriter2) {
0095     fWriter2->close();
0096     delete fWriter2;
0097     fWriter2 = 0;
0098   }
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0102 
0103 XAluminumElectrodeHitsCollection* XAluminumElectrodeSensitivity::GetHitsCollection()
0104 {
0105   return fHitsCollection;
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0109 
0110 void XAluminumElectrodeSensitivity::Initialize(G4HCofThisEvent* HCE)
0111 {
0112   fHitsCollection = new XAluminumElectrodeHitsCollection(SensitiveDetectorName, collectionName[0]);
0113   if (fHCID < 0) {
0114     fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0115   }
0116   HCE->AddHitsCollection(fHCID, fHitsCollection);
0117 }
0118 
0119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0120 
0121 G4bool XAluminumElectrodeSensitivity::ProcessHits(G4Step* aStep, G4TouchableHistory* /*ROhist*/)
0122 {
0123   // if(aStep->GetTrack()->GetDefinition()!=Phonon::PhononDefinition()) return true;
0124   G4double edp = aStep->GetNonIonizingEnergyDeposit();
0125   if (edp == 0.) return true;
0126 
0127   G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0128   G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
0129   G4TouchableHistory* theTouchable = (G4TouchableHistory*)(preStepPoint->GetTouchable());
0130   G4ThreeVector fWorldPos = postStepPoint->GetPosition();
0131   G4ThreeVector fLocalPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint(fWorldPos);
0132 
0133   XAluminumElectrodeHit* aHit = new XAluminumElectrodeHit();
0134   aHit->fTime = postStepPoint->GetGlobalTime();
0135   aHit->fEdep = edp;
0136   aHit->fWorldPos = fWorldPos;
0137   aHit->fLocalPos = fLocalPos;
0138 
0139   fHitsCollection->insert(aHit);
0140 
0141   return true;
0142 }
0143 
0144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0145 
0146 void XAluminumElectrodeSensitivity::EndOfEvent(G4HCofThisEvent* /*HCE*/)
0147 {
0148   if (!fHitsCollection || fHitsCollection->GetSize() == 0) return;
0149 
0150   for (size_t i = 0; i < fHitsCollection->GetSize(); i++) {
0151     WriteHitInfo(dynamic_cast<XAluminumElectrodeHit*>(fHitsCollection->GetHit(i)));
0152   }
0153 }
0154 
0155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0156 
0157 void XAluminumElectrodeSensitivity::WriteHitInfo(const XAluminumElectrodeHit* aHit)
0158 {
0159   if (!aHit) return;
0160 
0161   G4AutoLock lockIt(&theMutex);  // Only one event can write at a time
0162 
0163   *fWriter << aHit->fWorldPos.getX() / mm << "," << aHit->fWorldPos.getY() / mm << ","
0164            << aHit->fWorldPos.getZ() / mm << "\n";
0165 
0166   *fWriter2 << aHit->fTime / ns << " " << aHit->fEdep / eV << "\n";
0167 }