Logo ROOT   6.18/05
Reference Guide
JetEvent.cxx
Go to the documentation of this file.
1// A JetEvent emulates 2 detectors A and B producing each
2// a TClonesArray of Hit objects.
3// A TClonesArray of Track objects is built with Hits objects
4// of detectors A and B. Eack Track object has a TRefArray of hits.
5// A TClonesArray of Jets is made with a subset of the Track objects
6// also stored in a TRefArray.
7// see $ROOTSYS/tutorials/jets.C for an example creating a Tree
8// with JetEvents.
9
10#include "TMath.h"
11#include "TRandom.h"
12#include "JetEvent.h"
13
18
19////////////////////////////////////////////////////////////////////////////////
20/// Create a JetEvent object.
21/// When the constructor is invoked for the first time, the class static
22/// variables fgxxx are 0 and the TClonesArray fgxxx are created.
23
25{
26 if (!fgTracks) fgTracks = new TClonesArray("Track", 100);
27 if (!fgJets) fgJets = new TClonesArray("Jet", 10);
28 if (!fgHitsA) fgHitsA = new TClonesArray("Hit", 10000);
29 if (!fgHitsB) fgHitsB = new TClonesArray("Hit", 1000);
30 fJets = fgJets;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37
39{
40 Reset();
41}
42
43////////////////////////////////////////////////////////////////////////////////
44///Build one event
45
46void JetEvent::Build(Int_t jetm, Int_t trackm, Int_t hitam, Int_t hitbm) {
47 //Save current Object count
48 Int_t ObjectNumber = TProcessID::GetObjectCount();
49 Clear();
50
51 Hit *hit;
52 Track *track;
53 Jet *jet;
54 fNjet = fNtrack = fNhitA = fNhitB = 0;
55
56 fVertex.SetXYZ(gRandom->Gaus(0,0.1),
57 gRandom->Gaus(0,0.2),
58 gRandom->Gaus(0,10));
59
60 Int_t njets = (Int_t)gRandom->Gaus(jetm,1); if (njets < 1) njets = 1;
61 for (Int_t j=0;j<njets;j++) {
62 jet = AddJet();
63 jet->fPt = gRandom->Gaus(0,10);
64 jet->fPhi = 2*TMath::Pi()*gRandom->Rndm();
65 Int_t ntracks = (Int_t)gRandom->Gaus(trackm,3); if (ntracks < 1) ntracks = 1;
66 for (Int_t t=0;t<ntracks;t++) {
67 track = AddTrack();
68 track->fPx = gRandom->Gaus(0,1);
69 track->fPy = gRandom->Gaus(0,1);
70 track->fPz = gRandom->Gaus(0,5);
71 jet->fTracks.Add(track);
72 Int_t nhitsA = (Int_t)gRandom->Gaus(hitam,5);
73 for (Int_t ha=0;ha<nhitsA;ha++) {
74 hit = AddHitA();
75 hit->fX = 10000*j + 100*t +ha;
76 hit->fY = 10000*j + 100*t +ha+0.1;
77 hit->fZ = 10000*j + 100*t +ha+0.2;
78 track->fHits.Add(hit);
79 }
80 Int_t nhitsB = (Int_t)gRandom->Gaus(hitbm,2);
81 for (Int_t hb=0;hb<nhitsB;hb++) {
82 hit = AddHitB();
83 hit->fX = 20000*j + 100*t +hb+0.3;
84 hit->fY = 20000*j + 100*t +hb+0.4;
85 hit->fZ = 20000*j + 100*t +hb+0.5;
86 track->fHits.Add(hit);
87 }
88 track->fNhit = nhitsA + nhitsB;
89 }
90 }
91 //Restore Object count
92 //To save space in the table keeping track of all referenced objects
93 //we assume that our events do not address each other. We reset the
94 //object count to what it was at the beginning of the event.
95 TProcessID::SetObjectCount(ObjectNumber);
96}
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// Add a new Jet to the list of tracks for this event.
101
103{
105 Jet *jet = new(jets[fNjet++]) Jet();
106 return jet;
107}
108
109
110////////////////////////////////////////////////////////////////////////////////
111/// Add a new track to the list of tracks for this event.
112
114{
116 Track *track = new(tracks[fNtrack++]) Track();
117 return track;
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Add a new hit to the list of hits in detector A
123
125{
126 TClonesArray &hitsA = *fHitsA;
127 Hit *hit = new(hitsA[fNhitA++]) Hit();
128 return hit;
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Add a new hit to the list of hits in detector B
133
135{
136 TClonesArray &hitsB = *fHitsB;
137 Hit *hit = new(hitsB[fNhitB++]) Hit();
138 return hit;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142
144{
145 fJets->Clear(option);
146 fTracks->Clear(option);
147 fHitsA->Clear(option);
148 fHitsB->Clear(option);
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Static function to reset all static objects for this event
153
155{
156 delete fgJets; fgJets = 0;
157 delete fgTracks; fgTracks = 0;
158 delete fgHitsA; fgHitsA = 0;
159 delete fgHitsB; fgHitsB = 0;
160}
161
162
163
164
165
166
int Int_t
Definition: RtypesCore.h:41
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Definition: JetEvent.h:16
Float_t fZ
Definition: JetEvent.h:21
Float_t fX
Definition: JetEvent.h:19
Float_t fY
Definition: JetEvent.h:20
Int_t fNjet
Definition: JetEvent.h:68
TClonesArray * fHitsB
Definition: JetEvent.h:75
static TClonesArray * fgTracks
Definition: JetEvent.h:78
TClonesArray * fJets
Definition: JetEvent.h:72
Int_t fNhitA
Definition: JetEvent.h:70
Jet * AddJet()
Add a new Jet to the list of tracks for this event.
Definition: JetEvent.cxx:102
Hit * AddHitB()
Add a new hit to the list of hits in detector B.
Definition: JetEvent.cxx:134
virtual ~JetEvent()
Definition: JetEvent.cxx:38
static TClonesArray * fgJets
Definition: JetEvent.h:77
static TClonesArray * fgHitsB
Definition: JetEvent.h:80
Int_t fNhitB
Definition: JetEvent.h:71
Int_t fNtrack
Definition: JetEvent.h:69
JetEvent()
Create a JetEvent object.
Definition: JetEvent.cxx:24
Hit * AddHitA()
Add a new hit to the list of hits in detector A.
Definition: JetEvent.cxx:124
static TClonesArray * fgHitsA
Definition: JetEvent.h:79
TClonesArray * fHitsA
Definition: JetEvent.h:74
TClonesArray * fTracks
Definition: JetEvent.h:73
Track * AddTrack()
Add a new track to the list of tracks for this event.
Definition: JetEvent.cxx:113
TVector3 fVertex
Definition: JetEvent.h:67
void Reset(Option_t *option="")
Static function to reset all static objects for this event.
Definition: JetEvent.cxx:154
void Clear(Option_t *option="")
Definition: JetEvent.cxx:143
void Build(Int_t jetm=3, Int_t trackm=10, Int_t hitam=100, Int_t hitbm=10)
Build one event.
Definition: JetEvent.cxx:46
Definition: JetEvent.h:49
TRefArray fTracks
Definition: JetEvent.h:54
Double_t fPhi
Definition: JetEvent.h:53
Double_t fPt
Definition: JetEvent.h:52
An array of clone (identical) objects.
Definition: TClonesArray.h:32
virtual void Clear(Option_t *option="")
Clear the clones array.
friend class TClonesArray
Definition: TObject.h:213
static UInt_t GetObjectCount()
Return the current referenced object count fgNumber is incremented every time a new object is referen...
Definition: TProcessID.cxx:322
static void SetObjectCount(UInt_t number)
static function to set the current referenced object count fgNumber is incremented every time a new o...
Definition: TProcessID.cxx:430
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:263
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
void Add(TObject *obj)
Definition: TRefArray.h:80
void SetXYZ(Double_t x, Double_t y, Double_t z)
Definition: TVector3.h:227
Definition: JetEvent.h:30
Float_t fPx
Definition: JetEvent.h:33
Float_t fPy
Definition: JetEvent.h:34
Float_t fPz
Definition: JetEvent.h:35
Int_t fNhit
Definition: JetEvent.h:36
TRefArray fHits
Definition: JetEvent.h:37
void jets()
Definition: jets.C:38
constexpr Double_t Pi()
Definition: TMath.h:38
void tracks()
Definition: tracks.C:47