VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E02
src
Ex02TrackerSD.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
10
/// \file Ex02TrackerSD.cxx
11
/// \brief Implementation of the Ex02TrackerSD class
12
///
13
/// Geant4 ExampleN02 adapted to Virtual Monte Carlo \n
14
/// Id: ExN02TrackerSD.cc,v 1.6 2002/01/09 17:24:10 ranjard Exp \n
15
/// GEANT4 tag Name: geant4-04-00-patch-02
16
///
17
/// \date 21/04/2002
18
/// \author I. Hrivnacova; IPN, Orsay
19
20
#include <iostream>
21
22
#include <TLorentzVector.h>
23
#include <TMCRootManager.h>
24
#include <TTree.h>
25
#include <TVirtualMC.h>
26
27
#include "
Ex02TrackerHit.h
"
28
#include "
Ex02TrackerSD.h
"
29
30
/// \cond CLASSIMP
31
ClassImp(
Ex02TrackerSD
)
32
/// \endcond
33
34
using namespace
std;
35
36
//_____________________________________________________________________________
37
Ex02TrackerSD::Ex02TrackerSD
(
const
char
* name)
38
:
TNamed
(name,
""
),
39
fTrackerCollection
(0),
40
fSensitiveVolumeID
(-1),
41
fVerboseLevel
(1)
42
{
43
/// Standard constructor
44
/// \param name The tracker hits collection name
45
}
46
47
//_____________________________________________________________________________
48
Ex02TrackerSD::Ex02TrackerSD
(
const
Ex02TrackerSD
& origin)
49
:
TNamed
(origin.GetName(), origin.GetTitle()),
50
fTrackerCollection
(0),
51
fSensitiveVolumeID
(-1),
52
fVerboseLevel
(1)
53
{
54
/// Copy constructor (for clonig on worker thread in MT mode).
55
/// \param origin The source object (on master).
56
}
57
58
//_____________________________________________________________________________
59
Ex02TrackerSD::Ex02TrackerSD
()
60
:
TNamed
(),
fTrackerCollection
(0),
fSensitiveVolumeID
(-1),
fVerboseLevel
(1)
61
{
62
/// Default constructor
63
}
64
65
//_____________________________________________________________________________
66
Ex02TrackerSD::~Ex02TrackerSD
()
67
{
68
/// Destructor
69
}
70
71
//
72
// private methods
73
//
74
75
//_____________________________________________________________________________
76
Ex02TrackerHit
*
Ex02TrackerSD::AddHit
()
77
{
78
/// Create a new hit in the TClonesArray.
79
/// \return The new hit
80
81
TClonesArray& ref = *
fTrackerCollection
;
82
Int_t size = ref.GetEntriesFast();
83
84
return
new
(ref[size])
Ex02TrackerHit
();
85
}
86
87
//
88
// public methods
89
//
90
91
//_____________________________________________________________________________
92
void
Ex02TrackerSD::Initialize
()
93
{
94
/// Register hits collection in the Root manager;
95
/// set sensitive volumes.
96
97
static
__thread Bool_t registered =
false
;
98
if
(!registered) {
99
// cout << "... creating TClonesArray" << endl;
100
101
// Lock Root when creating data - seems not to be needed ?
102
fTrackerCollection
=
new
TClonesArray(
"Ex02TrackerHit"
);
103
104
// Register to Root IO only if RootManager is instantiated
105
if
(TMCRootManager::Instance())
Register
();
106
registered =
true
;
107
}
108
109
fSensitiveVolumeID
= gMC->VolId(
"CHMB"
);
110
}
111
112
//_____________________________________________________________________________
113
Bool_t
Ex02TrackerSD::ProcessHits
()
114
{
115
/// Create hits (in stepping).
116
117
Int_t copyNo;
118
Int_t
id
= gMC->CurrentVolID(copyNo);
119
120
if
(
id
!=
fSensitiveVolumeID
)
return
false
;
121
122
Double_t edep = gMC->Edep();
123
124
if
(edep == 0.)
return
false
;
125
126
Ex02TrackerHit
* newHit =
AddHit
();
127
128
// Track ID
129
newHit->
SetTrackID
(gMC->GetStack()->GetCurrentTrackNumber());
130
131
// Chamber no
132
newHit->
SetChamberNb
(copyNo);
133
134
// Energy deposit
135
newHit->
SetEdep
(edep);
136
137
// Position
138
TLorentzVector pos;
139
gMC->TrackPosition(pos);
140
newHit->
SetPos
(TVector3(pos.X(), pos.Y(), pos.Z()));
141
142
// newHit->Print();
143
// newHit->Draw();
144
145
return
true
;
146
}
147
148
//_____________________________________________________________________________
149
void
Ex02TrackerSD::EndOfEvent
()
150
{
151
/// Print hits collection (if verbose)
152
/// and delete hits afterwards.
153
154
if
(
fVerboseLevel
> 0)
Print
();
155
156
// Reset hits collection
157
fTrackerCollection
->Clear();
158
}
159
160
//_____________________________________________________________________________
161
void
Ex02TrackerSD::Register
()
162
{
163
/// Register the hits collection in the Root manager.
164
165
TMCRootManager::Instance()->Register(
166
"hits"
,
"TClonesArray"
, &
fTrackerCollection
);
167
}
168
169
//_____________________________________________________________________________
170
void
Ex02TrackerSD::Print
(
const
Option_t*
/*option*/
)
const
171
{
172
/// Print the hits collection.
173
174
Int_t nofHits =
fTrackerCollection
->GetEntriesFast();
175
176
cout <<
"\n-------->Hits Collection: in this event they are "
<< nofHits
177
<<
" hits in the tracker chambers: "
<< endl;
178
179
for
(Int_t i = 0; i < nofHits; i++) (*
fTrackerCollection
)[i]->Print();
180
}
Ex02TrackerHit.h
Definition of the Ex02TrackerHit class.
Ex02TrackerSD.h
Definition of the Ex02TrackerSD class.
Ex02TrackerHit
The tracker hit.
Definition
Ex02TrackerHit.h:32
Ex02TrackerHit::SetChamberNb
void SetChamberNb(Int_t chamb)
Definition
Ex02TrackerHit.h:50
Ex02TrackerHit::SetTrackID
void SetTrackID(Int_t track)
Definition
Ex02TrackerHit.h:46
Ex02TrackerHit::SetPos
void SetPos(TVector3 xyz)
Definition
Ex02TrackerHit.h:58
Ex02TrackerHit::SetEdep
void SetEdep(Double_t de)
Definition
Ex02TrackerHit.h:54
Ex02TrackerSD
The tracker sensitive detector.
Definition
Ex02TrackerSD.h:34
Ex02TrackerSD::ProcessHits
Bool_t ProcessHits()
Definition
Ex02TrackerSD.cxx:113
Ex02TrackerSD::Initialize
void Initialize()
Definition
Ex02TrackerSD.cxx:92
Ex02TrackerSD::EndOfEvent
void EndOfEvent()
Definition
Ex02TrackerSD.cxx:149
Ex02TrackerSD::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
Ex02TrackerSD.h:58
Ex02TrackerSD::Ex02TrackerSD
Ex02TrackerSD(const char *name)
Definition
Ex02TrackerSD.cxx:37
Ex02TrackerSD::AddHit
Ex02TrackerHit * AddHit()
Definition
Ex02TrackerSD.cxx:76
Ex02TrackerSD::Print
virtual void Print(const Option_t *option=0) const
Definition
Ex02TrackerSD.cxx:170
Ex02TrackerSD::~Ex02TrackerSD
virtual ~Ex02TrackerSD()
Definition
Ex02TrackerSD.cxx:66
Ex02TrackerSD::Register
void Register()
Definition
Ex02TrackerSD.cxx:161
Ex02TrackerSD::Ex02TrackerSD
Ex02TrackerSD()
Definition
Ex02TrackerSD.cxx:59
Ex02TrackerSD::fSensitiveVolumeID
Int_t fSensitiveVolumeID
Sensitive volume Id.
Definition
Ex02TrackerSD.h:57
Ex02TrackerSD::fTrackerCollection
TClonesArray * fTrackerCollection
Hits collection.
Definition
Ex02TrackerSD.h:56
TNamed
Generated on
for VMC Examples by
1.17.0