VMC Examples Version 6.6
Loading...
Searching...
No Matches
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
31ClassImp(Ex02TrackerSD)
32 /// \endcond
33
34 using namespace std;
35
36//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
60 : TNamed(), fTrackerCollection(0), fSensitiveVolumeID(-1), fVerboseLevel(1)
61{
62 /// Default constructor
63}
64
65//_____________________________________________________________________________
67{
68 /// Destructor
69}
70
71//
72// private methods
73//
74
75//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
162{
163 /// Register the hits collection in the Root manager.
164
165 TMCRootManager::Instance()->Register(
166 "hits", "TClonesArray", &fTrackerCollection);
167}
168
169//_____________________________________________________________________________
170void 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}
Definition of the Ex02TrackerHit class.
Definition of the Ex02TrackerSD class.
The tracker hit.
void SetChamberNb(Int_t chamb)
void SetTrackID(Int_t track)
void SetPos(TVector3 xyz)
void SetEdep(Double_t de)
The tracker sensitive detector.
Int_t fVerboseLevel
Verbosity level.
Ex02TrackerHit * AddHit()
virtual void Print(const Option_t *option=0) const
virtual ~Ex02TrackerSD()
Int_t fSensitiveVolumeID
Sensitive volume Id.
TClonesArray * fTrackerCollection
Hits collection.