Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
XAluminumElectrodeSensitivity.cc
이 파일의 문서화 페이지로 가기
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 //
28 //
29 // $Id: XAluminumElectrodeSensitivity.cc 106987 2017-10-31 10:09:40Z gcosmo $
30 //
32 
33 #include "XAluminumElectrodeHit.hh"
34 #include "G4AutoLock.hh"
35 #include "G4HCofThisEvent.hh"
36 #include "G4Navigator.hh"
37 #include "G4SDManager.hh"
38 #include "G4Step.hh"
39 #include "G4SystemOfUnits.hh"
40 #include "G4Threading.hh"
41 #include "G4TouchableHistory.hh"
42 #include "G4Track.hh"
43 #include <fstream>
44 
47 
49 
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52 
55  : G4VSensitiveDetector(name) {
56  collectionName.insert("XAluminumElectrodeHit");
57  fHCID = -1;
58 
59  G4AutoLock lockIt(&theMutex); // Only one thread opens files!
60  fWriter = new std::fstream("caustic.ssv",std::fstream::out|std::fstream::ate);
61  if (!fWriter->is_open()) {
62  G4cerr << "XAluminumElectrodeSensitivity::Constructor:"
63  << "\n\tFailed to open caustic.ssv for appending data."
64  << "\n\tCreating caustic.ssv" << G4endl;
65  fWriter->open("caustic.ssv");
66  }
67 
68  fWriter2 = new std::fstream("timing.ssv",std::fstream::out|std::fstream::ate);
69  if (!fWriter2->is_open()) {
70  G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
71  << "\n\tFailed to open timing.ssv for appending data."
72  << "\n\tCreating timing.ssv." << G4endl;
73  fWriter2->open("timing.ssv");
74  }
75 
76  if (!(fWriter->is_open() && fWriter2->is_open())) {
77  G4cerr << "XAluminumElectrodeSensitivity::Constructor: "
78  << "\nERROR: COULD NOT CREATE OUTPUT FILES FOR WRITING" << G4endl;
79  }
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
83 
85  G4AutoLock lockIt(&theMutex); // Only one thread deletes!
86 
87  if (fWriter) {
88  fWriter->close();
89  delete fWriter; fWriter = 0;
90  }
91 
92  if (fWriter2) {
93  fWriter2->close();
94  delete fWriter2; fWriter2 = 0;
95  }
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
99 
102  return fHitsCollection;
103 }
104 
105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
106 
108 {
111  collectionName[0]);
112  if (fHCID<0)
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
118 
120  G4TouchableHistory* /*ROhist*/)
121 {
122  //if(aStep->GetTrack()->GetDefinition()!=Phonon::PhononDefinition()) return true;
123  G4double edp = aStep->GetNonIonizingEnergyDeposit();
124  if(edp==0.) return true;
125 
126  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
127  G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
128  G4TouchableHistory* theTouchable
129  = (G4TouchableHistory*)(preStepPoint->GetTouchable());
130  G4ThreeVector fWorldPos = postStepPoint->GetPosition();
131  G4ThreeVector fLocalPos
132  = theTouchable->GetHistory()->GetTopTransform().TransformPoint(fWorldPos);
133 
135  aHit->fTime = postStepPoint->GetGlobalTime();
136  aHit->fEdep = edp;
137  aHit->fWorldPos = fWorldPos;
138  aHit->fLocalPos = fLocalPos;
139 
140  fHitsCollection->insert(aHit);
141 
142  return true;
143 }
144 
145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
146 
148  if (!fHitsCollection || fHitsCollection->GetSize()==0) return;
149 
150  for (size_t i=0; i<fHitsCollection->GetSize(); i++) {
151  WriteHitInfo(dynamic_cast<XAluminumElectrodeHit*>(fHitsCollection->GetHit(i)));
152  }
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
156 
159  if (!aHit) return;
160 
161  G4AutoLock lockIt(&theMutex); // Only one event can write at a time
162 
163  *fWriter << aHit->fWorldPos.getX()/mm
164  << "," << aHit->fWorldPos.getY()/mm
165  << "," << aHit->fWorldPos.getZ()/mm
166  << "\n";
167 
168  *fWriter2 << aHit->fTime/ns << " " << aHit->fEdep/eV << "\n";
169 }
170 
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
const XML_Char * name
Definition: expat.h:151
const G4VTouchable * GetTouchable() const
G4StepPoint * GetPreStepPoint() const
static constexpr double mm
Definition: G4SIunits.hh:115
double getZ() const
#define G4endl
Definition: G4ios.hh:61
XAluminumElectrodeHitsCollection * GetHitsCollection()
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
XAluminumElectrodeHitsCollection * fHitsCollection
Definition of the XAluminumElectrodeSensitivity class.
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:88
const G4NavigationHistory * GetHistory() const
const G4ThreeVector & GetPosition() const
double getX() const
const G4AffineTransform & GetTopTransform() const
Definition of the XAluminumElectrodeHit class.
static constexpr double eV
Definition: G4SIunits.hh:215
G4double GetGlobalTime() const
Definition: G4Step.hh:76
G4StepPoint * GetPostStepPoint() const
double getY() const
G4GLOB_DLL std::ostream G4cerr
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual void Initialize(G4HCofThisEvent *)
G4THitsCollection< XAluminumElectrodeHit > XAluminumElectrodeHitsCollection
G4CollectionNameVector collectionName
virtual void EndOfEvent(G4HCofThisEvent *)
G4double GetNonIonizingEnergyDeposit() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
#define ns
Definition: xmlparse.cc:614
void WriteHitInfo(const XAluminumElectrodeHit *aHit)
std::mutex G4Mutex
Definition: G4Threading.hh:84