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

Last change on this file since 1319 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 7.3 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// ------------------------------------------------------------
28//      GEANT 4 class implementation file
29//      CERN Geneva Switzerland
30//
31//
32//      ------------ GammaRayTelTrackerSD  ------
33//           by  R.Giannitrapani, F.Longo & G.Santin (13 nov 2000)
34//
35// ************************************************************
36#include "G4RunManager.hh"
37#include "GammaRayTelTrackerSD.hh"
38
39#include "GammaRayTelTrackerHit.hh"
40#include "GammaRayTelDetectorConstruction.hh"
41
42#include "G4VPhysicalVolume.hh"
43
44#include "G4Step.hh"
45#include "G4VTouchable.hh"
46#include "G4TouchableHistory.hh"
47#include "G4SDManager.hh"
48
49#include "G4ios.hh"
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52
53GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4String name):G4VSensitiveDetector(name)
54{
55 G4RunManager* runManager = G4RunManager::GetRunManager();
56  Detector =
57    (GammaRayTelDetectorConstruction*)(runManager->GetUserDetectorConstruction());
58 
59  G4int NbOfTKRTiles  =  Detector->GetNbOfTKRTiles();
60  NbOfTKRStrips  = Detector->GetNbOfTKRStrips();
61  NbOfTKRLayers  = Detector->GetNbOfTKRLayers(); 
62  NbOfTKRStrips = NbOfTKRStrips*NbOfTKRTiles; 
63 
64  NbOfTKRChannels = NbOfTKRStrips* NbOfTKRTiles * NbOfTKRLayers;
65 
66  ThitXID = new G4int[NbOfTKRChannels];
67  ThitYID = new G4int[NbOfTKRChannels];
68  collectionName.insert("TrackerCollection");
69}
70
71//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
72
73GammaRayTelTrackerSD::~GammaRayTelTrackerSD()
74{
75  delete [] ThitXID;
76  delete [] ThitYID;
77}
78
79//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
80
81void GammaRayTelTrackerSD::Initialize(G4HCofThisEvent*)
82{
83  TrackerCollection = new GammaRayTelTrackerHitsCollection
84    (SensitiveDetectorName,collectionName[0]);
85
86 for (G4int i=0;i<NbOfTKRChannels;i++)
87   {
88     ThitXID[i] = -1;
89     ThitYID[i] = -1;
90   };
91}
92
93//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94
95G4bool GammaRayTelTrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory* ROhist)
96{ 
97   
98  G4double edep = aStep->GetTotalEnergyDeposit();
99  if ((edep/keV == 0.)) return false;     
100 
101  G4int StripTotal = Detector->GetNbOfTKRStrips();
102  G4int TileTotal  = Detector->GetNbOfTKRTiles(); 
103
104  // This TouchableHistory is used to obtain the physical volume
105  // of the hit
106  G4TouchableHistory* theTouchable
107    = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
108 
109  //G4VPhysicalVolume* phys_tile = theTouchable->GetVolume(); 
110 
111  G4VPhysicalVolume* plane = theTouchable->GetVolume(1); 
112 
113  G4int PlaneNumber = 0;
114  PlaneNumber=plane->GetCopyNo();
115  G4String PlaneName = plane->GetName();
116
117  // The RO History is used to obtain the real strip
118  // of the hit
119
120  G4int StripNumber = 0;
121  G4VPhysicalVolume* strip = 0;
122  strip = ROhist->GetVolume();
123
124  //  if (strip){
125    G4String StripName = strip->GetName();
126    StripNumber= strip->GetCopyNo(); 
127    //  }
128  //  ROhist->MoveUpHistory();
129  G4VPhysicalVolume* tile = ROhist->GetVolume(1); 
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.