Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
28 //
29 // $Id: XAluminumElectrodeSensitivity.cc 92176 2015-08-20 13:07:22Z 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 
45 std::fstream* XAluminumElectrodeSensitivity::fWriter = 0;
46 std::fstream* XAluminumElectrodeSensitivity::fWriter2 = 0;
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 {
109  fHitsCollection =
111  collectionName[0]);
112  if (fHCID<0)
113  { fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection); }
114  HCE->AddHitsCollection(fHCID,fHitsCollection);
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 << "\n" << aHit->fWorldPos.getX()/mm
164  << "," << aHit->fWorldPos.getY()/mm
165  << "," << aHit->fWorldPos.getZ()/mm;
166 
167  *fWriter2 << "\n" << aHit->fTime/ns << " " << aHit->fEdep/eV;
168 }
169 
const XML_Char * name
Definition: expat.h:151
static constexpr double mm
Definition: G4SIunits.hh:115
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
G4double GetNonIonizingEnergyDeposit() const
double getY() const
G4int insert(T *aHit)
const G4VTouchable * GetTouchable() const
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4StepPoint * GetPreStepPoint() const
double getX() const
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
const G4ThreeVector & GetPosition() const
virtual G4VHit * GetHit(size_t i) const
bool G4bool
Definition: G4Types.hh:79
void WriteHitInfo(const XAluminumElectrodeHit *aHit)
XAluminumElectrodeHitsCollection * GetHitsCollection()
static constexpr double eV
Definition: G4SIunits.hh:215
Definition: G4Step.hh:76
G4THitsCollection< XAluminumElectrodeHit > XAluminumElectrodeHitsCollection
Definition of the XAluminumElectrodeHit class.
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
Definition of the XAluminumElectrodeSensitivity class.
G4int G4Mutex
Definition: G4Threading.hh:173
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4StepPoint * GetPostStepPoint() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
double getZ() const
virtual void Initialize(G4HCofThisEvent *)
#define G4endl
Definition: G4ios.hh:61
G4double GetGlobalTime() const
const G4AffineTransform & GetTopTransform() const
G4CollectionNameVector collectionName
const G4NavigationHistory * GetHistory() const
virtual void EndOfEvent(G4HCofThisEvent *)
double G4double
Definition: G4Types.hh:76
virtual size_t GetSize() const
#define ns
Definition: xmlparse.cc:614
G4GLOB_DLL std::ostream G4cerr