source: trunk/examples/advanced/gammaray_telescope/src/GammaRayTelTrackerSD.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 7.4 KB
Line 
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//
27// $Id: GammaRayTelTrackerSD.cc,v 1.9 2006/06/29 15:57:13 gunter Exp $
28// GEANT4 tag $Name: geant4-09-01-patch-02 $
29// ------------------------------------------------------------
30// GEANT 4 class implementation file
31// CERN Geneva Switzerland
32//
33//
34// ------------ GammaRayTelTrackerSD ------
35// by R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
36//
37// ************************************************************
38#include "G4RunManager.hh"
39#include "GammaRayTelTrackerSD.hh"
40
41#include "GammaRayTelTrackerHit.hh"
42#include "GammaRayTelDetectorConstruction.hh"
43
44#include "G4VPhysicalVolume.hh"
45
46#include "G4Step.hh"
47#include "G4VTouchable.hh"
48#include "G4TouchableHistory.hh"
49#include "G4SDManager.hh"
50
51#include "G4ios.hh"
52
53//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
54
55GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4String name):G4VSensitiveDetector(name)
56{
57 G4RunManager* runManager = G4RunManager::GetRunManager();
58 Detector =
59 (GammaRayTelDetectorConstruction*)(runManager->GetUserDetectorConstruction());
60
61 G4int NbOfTKRTiles = Detector->GetNbOfTKRTiles();
62 NbOfTKRStrips = Detector->GetNbOfTKRStrips();
63 NbOfTKRLayers = Detector->GetNbOfTKRLayers();
64 NbOfTKRStrips = NbOfTKRStrips*NbOfTKRTiles;
65
66 NbOfTKRChannels = NbOfTKRStrips* NbOfTKRTiles * NbOfTKRLayers;
67
68 ThitXID = new G4int[NbOfTKRChannels];
69 ThitYID = new G4int[NbOfTKRChannels];
70 collectionName.insert("TrackerCollection");
71}
72
73//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
74
75GammaRayTelTrackerSD::~GammaRayTelTrackerSD()
76{
77 delete [] ThitXID;
78 delete [] ThitYID;
79}
80
81//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
82
83void GammaRayTelTrackerSD::Initialize(G4HCofThisEvent*)
84{
85 TrackerCollection = new GammaRayTelTrackerHitsCollection
86 (SensitiveDetectorName,collectionName[0]);
87
88 for (G4int i=0;i<NbOfTKRChannels;i++)
89 {
90 ThitXID[i] = -1;
91 ThitYID[i] = -1;
92 };
93}
94
95//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
96
97G4bool GammaRayTelTrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist)
98{
99
100 G4double edep = aStep->GetTotalEnergyDeposit();
101 if ((edep/keV == 0.)) return false;
102
103 G4int StripTotal = Detector->GetNbOfTKRStrips();
104 G4int TileTotal = Detector->GetNbOfTKRTiles();
105
106 // This TouchableHistory is used to obtain the physical volume
107 // of the hit
108 G4TouchableHistory* theTouchable
109 = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
110
111 //G4VPhysicalVolume* phys_tile = theTouchable->GetVolume();
112
113 G4VPhysicalVolume* plane = theTouchable->GetVolume(1);
114
115 G4int PlaneNumber = 0;
116 PlaneNumber=plane->GetCopyNo();
117 G4String PlaneName = plane->GetName();
118
119 // The RO History is used to obtain the real strip
120 // of the hit
121
122 G4int StripNumber = 0;
123 G4VPhysicalVolume* strip = 0;
124 strip = ROhist->GetVolume();
125 G4String StripName = strip->GetName();
126 StripNumber= strip->GetCopyNo();
127
128 ROhist->MoveUpHistory();
129 G4VPhysicalVolume* tile = ROhist->GetVolume();
130 G4int TileNumber = tile->GetCopyNo();
131 G4String TileName = tile->GetName();
132
133 G4int NTile = (TileNumber%TileTotal);
134 G4int j=0;
135
136 G4int NChannel = 0;
137
138 for (j=0;j<TileTotal;j++)
139 {
140 if(NTile==j) StripNumber += StripTotal*NTile;
141 }
142
143 NChannel = PlaneNumber*TileTotal*StripTotal + StripNumber;
144
145 /* G4cout << NChannel << " Channel Number" << G4endl;
146 G4cout << " Plane Number = " << PlaneNumber << " " << PlaneName
147 << G4endl;
148 G4cout << StripName << " " << StripNumber << G4endl; */
149
150 if (PlaneName == "TKRDetectorX" )
151 // The hit is on an X silicon plane
152 {
153 // This is a new hit
154 if (ThitXID[NChannel]==-1)
155 {
156 GammaRayTelTrackerHit* TrackerHit = new GammaRayTelTrackerHit;
157 TrackerHit->SetPlaneType(1);
158 TrackerHit->AddSil(edep);
159 TrackerHit->SetPos(aStep->GetPreStepPoint()->GetPosition());
160 TrackerHit->SetNSilPlane(PlaneNumber);
161 TrackerHit->SetNStrip(StripNumber);
162 ThitXID[NChannel] =
163 TrackerCollection->insert(TrackerHit) -1;
164 }
165 else // This is not new
166 {
167 (*TrackerCollection)[ThitXID[NChannel]]->AddSil(edep);
168 // G4cout << "X" << PlaneNumber << " " << StripNumber << G4endl;
169 }
170 }
171
172 if (PlaneName == "TKRDetectorY")
173 // The hit is on an Y silicon plane
174 {
175 // This is a new hit
176 if (ThitYID[NChannel]==-1)
177 {
178 GammaRayTelTrackerHit* TrackerHit = new GammaRayTelTrackerHit;
179 TrackerHit->SetPlaneType(0);
180 TrackerHit->AddSil(edep);
181 TrackerHit->SetPos(aStep->GetPreStepPoint()->GetPosition());
182 TrackerHit->SetNSilPlane(PlaneNumber);
183 TrackerHit->SetNStrip(StripNumber);
184 ThitYID[NChannel] =
185 TrackerCollection->insert(TrackerHit)-1;
186 }
187 else // This is not new
188 {
189 (*TrackerCollection)[ThitYID[NChannel]]->AddSil(edep);
190 // G4cout << "Y" << PlaneNumber << " " << StripNumber << G4endl;
191 }
192 }
193
194 return true;
195}
196
197//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
198
199void GammaRayTelTrackerSD::EndOfEvent(G4HCofThisEvent* HCE)
200{
201 static G4int HCID = -1;
202 if(HCID<0)
203 {
204 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
205 }
206 HCE->AddHitsCollection(HCID,TrackerCollection);
207
208
209 for (G4int i=0;i<NbOfTKRChannels;i++)
210 {
211 ThitXID[i] = -1;
212 ThitYID[i] = -1;
213 };
214}
215
216//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
217
218void GammaRayTelTrackerSD::clear()
219{}
220
221//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
222
223void GammaRayTelTrackerSD::DrawAll()
224{}
225
226//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
227
228void GammaRayTelTrackerSD::PrintAll()
229{}
230
231//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
232
233
234
235
236
237
238
239
240
241
242
243
244
Note: See TracBrowser for help on using the repository browser.