Geant4  10.00.p02
ExP01TrackerSD.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 //
30 // $Id: ExP01TrackerSD.cc 71111 2013-06-11 10:51:02Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "ExP01TrackerSD.hh"
36 #include "G4HCofThisEvent.hh"
37 #include "G4Step.hh"
38 #include "G4ThreeVector.hh"
39 #include "G4SDManager.hh"
40 #include "G4ios.hh"
41 
42 #include "RootIO.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47  :G4VSensitiveDetector(name), fTrackerCollection(0), fHCID(0)
48 {
49  G4String HCname = name + "_HC";
50  collectionName.insert(HCname);
51  G4cout << collectionName.size() << " CalorimeterSD name: " << name << " collection Name: "
52  << HCname << G4endl;
53  fHCID = -1;
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 {
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
69  if (fHCID < 0) {
70  G4cout << "CalorimeterSD::Initialize: " << SensitiveDetectorName << " "
71  << collectionName[0] << G4endl;
73 
74  }
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  G4double edep = aStep->GetTotalEnergyDeposit();
83 
84  if(edep==0.) return false;
85 
86  ExP01TrackerHit* newHit = new ExP01TrackerHit();
87  newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
88  newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchable()
89  ->GetReplicaNumber());
90  newHit->SetEdep (edep);
91  newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
92  fTrackerCollection->insert( newHit );
93 
94  //newHit->Print();
95  //newHit->Draw();
96 
97  return true;
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
103 {
104  // storing the hits in ROOT file
105  G4int NbHits = fTrackerCollection->entries();
106  std::vector<ExP01TrackerHit*> hitsVector;
107 
108  {
109  G4cout << "\n-------->Storing hits in the ROOT file: in this event there are " << NbHits
110  << " hits in the tracker chambers: " << G4endl;
111  for (G4int i=0;i<NbHits;i++) (*fTrackerCollection)[i]->Print();
112  }
113 
114 
115  for (G4int i=0;i<NbHits;i++)
116  hitsVector.push_back((*fTrackerCollection)[i]);
117 
118  RootIO::GetInstance()->Write(&hitsVector);
119 
120  //
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124 
static RootIO * GetInstance()
Definition: RootIO.cc:71
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:131
virtual void Initialize(G4HCofThisEvent *)
G4String name
Definition: TRTMaterials.hh:40
G4int entries() const
G4int insert(T *aHit)
const G4VTouchable * GetTouchable() const
int G4int
Definition: G4Types.hh:78
G4StepPoint * GetPreStepPoint() const
Hit implementation for the persistency example.
Definition of the ExP01TrackerSD class.
G4GLOB_DLL std::ostream G4cout
const G4ThreeVector & GetPosition() const
bool G4bool
Definition: G4Types.hh:79
ExP01TrackerHitsCollection * fTrackerCollection
void Write(std::vector< ExP01TrackerHit * > *)
Definition: RootIO.cc:82
virtual void EndOfEvent(G4HCofThisEvent *)
Definition: G4Step.hh:76
G4int GetTrackID() const
void SetEdep(G4double de)
G4double GetTotalEnergyDeposit() const
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
G4THitsCollection< ExP01TrackerHit > ExP01TrackerHitsCollection
void SetPos(G4ThreeVector xyz)
void SetChamberNb(G4int chamb)
void Close()
Definition: RootIO.cc:100
G4StepPoint * GetPostStepPoint() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
Definition of the RootIO class.
ExP01TrackerSD(G4String)
#define G4endl
Definition: G4ios.hh:61
G4CollectionNameVector collectionName
double G4double
Definition: G4Types.hh:76
G4Track * GetTrack() const
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
void SetTrackID(G4int track)