Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
14 TClonesArray *JetEvent::fgJets = 0;
15 TClonesArray *JetEvent::fgTracks = 0;
16 TClonesArray *JetEvent::fgHitsA = 0;
17 TClonesArray *JetEvent::fgHitsB = 0;
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 
24 JetEvent::JetEvent()
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;
31  fTracks = fgTracks;
32  fHitsA = fgHitsA;
33  fHitsB = fgHitsB;
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 
38 JetEvent::~JetEvent()
39 {
40  Reset();
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 ///Build one event
45 
46 void 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 
102 Jet *JetEvent::AddJet()
103 {
104  TClonesArray &jets = *fJets;
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 
113 Track *JetEvent::AddTrack()
114 {
115  TClonesArray &tracks = *fTracks;
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 
124 Hit *JetEvent::AddHitA()
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 
134 Hit *JetEvent::AddHitB()
135 {
136  TClonesArray &hitsB = *fHitsB;
137  Hit *hit = new(hitsB[fNhitB++]) Hit();
138  return hit;
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 
143 void JetEvent::Clear(Option_t *option)
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 
154 void JetEvent::Reset(Option_t *)
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