Loading...
Searching...
No Matches
XAluminumElectrodeSensitivity.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26/// \file exoticphysics/phonon/src/XAluminumElectrodeSensitivity.cc
27/// \brief Implementation of the XAluminumElectrodeSensitivity class
28//
29//
31
33#include "G4AutoLock.hh"
34#include "G4HCofThisEvent.hh"
35#include "G4Navigator.hh"
36#include "G4SDManager.hh"
37#include "G4Step.hh"
38#include "G4SystemOfUnits.hh"
39#include "G4Threading.hh"
40#include "G4TouchableHistory.hh"
41#include "G4Track.hh"
42#include <fstream>
43
46
47G4Mutex theMutex = G4MUTEX_INITIALIZER; // Just need one
48
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51
54 : G4VSensitiveDetector(name) {
55 collectionName.insert("XAluminumElectrodeHit");
56 fHCID = -1;
57
58 G4AutoLock lockIt(&theMutex); // Only one thread opens files!
59 fWriter = new std::fstream("caustic.ssv",std::fstream::out|std::fstream::ate);
60 if (!fWriter->is_open()) {
61 G4cerr << "XAluminumElectrodeSensitivity::Constructor:"
62 << "\n\tFailed to open caustic.ssv for appending data."
63 << "\n\tCreating caustic.ssv" << G4endl;
64 fWriter->open("caustic.ssv");
65 }
66
67 fWriter2 = new std::fstream("timing.ssv",std::fstream::out|std::fstream::ate);
68 if (!fWriter2->is_open()) {
69 G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
70 << "\n\tFailed to open timing.ssv for appending data."
71 << "\n\tCreating timing.ssv." << G4endl;
72 fWriter2->open("timing.ssv");
73 }
74
75 if (!(fWriter->is_open() && fWriter2->is_open())) {
76 G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
77 << "\nERROR: COULD NOT CREATE OUTPUT FILES FOR WRITING" << G4endl;
78 }
79}
80
81//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
82
84 G4AutoLock lockIt(&theMutex); // Only one thread deletes!
85
86 if (fWriter) {
87 fWriter->close();
88 delete fWriter; fWriter = 0;
89 }
90
91 if (fWriter2) {
92 fWriter2->close();
93 delete fWriter2; fWriter2 = 0;
94 }
95}
96
97//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
98
103
104//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
105
107{
109 new XAluminumElectrodeHitsCollection(SensitiveDetectorName,
110 collectionName[0]);
111 if (fHCID<0)
112 { fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection); }
113 HCE->AddHitsCollection(fHCID,fHitsCollection);
114}
115
116//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
117
119 G4TouchableHistory* /*ROhist*/)
120{
121 //if(aStep->GetTrack()->GetDefinition()!=Phonon::PhononDefinition()) return true;
122 G4double edp = aStep->GetNonIonizingEnergyDeposit();
123 if(edp==0.) return true;
124
125 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
126 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
127 G4TouchableHistory* theTouchable
128 = (G4TouchableHistory*)(preStepPoint->GetTouchable());
129 G4ThreeVector fWorldPos = postStepPoint->GetPosition();
130 G4ThreeVector fLocalPos
131 = theTouchable->GetHistory()->GetTopTransform().TransformPoint(fWorldPos);
132
134 aHit->fTime = postStepPoint->GetGlobalTime();
135 aHit->fEdep = edp;
136 aHit->fWorldPos = fWorldPos;
137 aHit->fLocalPos = fLocalPos;
138
139 fHitsCollection->insert(aHit);
140
141 return true;
142}
143
144//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
145
147 if (!fHitsCollection || fHitsCollection->GetSize()==0) return;
148
149 for (size_t i=0; i<fHitsCollection->GetSize(); i++) {
150 WriteHitInfo(dynamic_cast<XAluminumElectrodeHit*>(fHitsCollection->GetHit(i)));
151 }
152}
153
154//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
155
158 if (!aHit) return;
159
160 G4AutoLock lockIt(&theMutex); // Only one event can write at a time
161
162 *fWriter << aHit->fWorldPos.getX()/mm
163 << "," << aHit->fWorldPos.getY()/mm
164 << "," << aHit->fWorldPos.getZ()/mm
165 << "\n";
166
167 *fWriter2 << aHit->fTime/ns << " " << aHit->fEdep/eV << "\n";
168}
169
Definition of the XAluminumElectrodeHit class.
G4THitsCollection< XAluminumElectrodeHit > XAluminumElectrodeHitsCollection
Definition of the XAluminumElectrodeSensitivity class.
virtual void EndOfEvent(G4HCofThisEvent *)
XAluminumElectrodeHitsCollection * fHitsCollection
void WriteHitInfo(const XAluminumElectrodeHit *aHit)
XAluminumElectrodeHitsCollection * GetHitsCollection()
virtual void Initialize(G4HCofThisEvent *)
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)

Applications | User Support | Publications | Collaboration