AlcapDAQ  1
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 "TRandom.h"
11 #include "JetEvent.h"
12 
17 
18 TClonesArray *JetEvent::fgJets = 0;
19 TClonesArray *JetEvent::fgTracks = 0;
20 TClonesArray *JetEvent::fgHitsA = 0;
21 TClonesArray *JetEvent::fgHitsB = 0;
22 
23 //______________________________________________________________________________
25 {
26  // Create a JetEvent object.
27  // When the constructor is invoked for the first time, the class static
28  // variables fgxxx are 0 and the TClonesArray fgxxx are created.
29 
30  if (!fgTracks) fgTracks = new TClonesArray("Track", 100);
31  if (!fgJets) fgJets = new TClonesArray("Jet", 10);
32  if (!fgHitsA) fgHitsA = new TClonesArray("Hit", 10000);
33  if (!fgHitsB) fgHitsB = new TClonesArray("Hit", 1000);
34  fJets = fgJets;
35  fTracks = fgTracks;
36  fHitsA = fgHitsA;
37  fHitsB = fgHitsB;
38 }
39 
40 //______________________________________________________________________________
42 {
43  Reset();
44 }
45 
46 //______________________________________________________________________________
47 void JetEvent::Build(Int_t jetm, Int_t trackm, Int_t hitam, Int_t hitbm) {
48  //Build one event
49 
50  //Save current Object count
51  Int_t ObjectNumber = TProcessID::GetObjectCount();
52  Clear();
53 
54  Hit *hit;
55  Track *track;
56  Jet *jet;
57  fNjet = fNtrack = fNhitA = fNhitB = 0;
58 
59  fVertex.SetXYZ(gRandom->Gaus(0,0.1),
60  gRandom->Gaus(0,0.2),
61  gRandom->Gaus(0,10));
62 
63  Int_t njets = (Int_t)gRandom->Gaus(jetm,1); if (njets < 1) njets = 1;
64  for (Int_t j=0;j<njets;j++) {
65  jet = AddJet();
66  jet->fPt = gRandom->Gaus(0,10);
67  jet->fPhi = 2*TMath::Pi()*gRandom->Rndm();
68  Int_t ntracks = (Int_t)gRandom->Gaus(trackm,3); if (ntracks < 1) ntracks = 1;
69  for (Int_t t=0;t<ntracks;t++) {
70  track = AddTrack();
71  track->fPx = gRandom->Gaus(0,1);
72  track->fPy = gRandom->Gaus(0,1);
73  track->fPz = gRandom->Gaus(0,5);
74  jet->fTracks.Add(track);
75  Int_t nhitsA = (Int_t)gRandom->Gaus(hitam,5);
76  for (Int_t ha=0;ha<nhitsA;ha++) {
77  hit = AddHitA();
78  hit->fX = 10000*j + 100*t +ha;
79  hit->fY = 10000*j + 100*t +ha+0.1;
80  hit->fZ = 10000*j + 100*t +ha+0.2;
81  track->fHits.Add(hit);
82  }
83  Int_t nhitsB = (Int_t)gRandom->Gaus(hitbm,2);
84  for (Int_t hb=0;hb<nhitsB;hb++) {
85  hit = AddHitB();
86  hit->fX = 20000*j + 100*t +hb+0.3;
87  hit->fY = 20000*j + 100*t +hb+0.4;
88  hit->fZ = 20000*j + 100*t +hb+0.5;
89  track->fHits.Add(hit);
90  }
91  track->fNhit = nhitsA + nhitsB;
92  }
93  }
94  //Restore Object count
95  //To save space in the table keeping track of all referenced objects
96  //we assume that our events do not address each other. We reset the
97  //object count to what it was at the beginning of the event.
98  TProcessID::SetObjectCount(ObjectNumber);
99 }
100 
101 
102 //______________________________________________________________________________
104 {
105  // Add a new Jet to the list of tracks for this event.
106 
107  TClonesArray &jets = *fJets;
108  Jet *jet = new(jets[fNjet++]) Jet();
109  return jet;
110 }
111 
112 
113 //______________________________________________________________________________
115 {
116  // Add a new track to the list of tracks for this event.
117 
118  TClonesArray &tracks = *fTracks;
119  Track *track = new(tracks[fNtrack++]) Track();
120  return track;
121 }
122 
123 
124 //______________________________________________________________________________
126 {
127  // Add a new hit to the list of hits in detector A
128 
129  TClonesArray &hitsA = *fHitsA;
130  Hit *hit = new(hitsA[fNhitA++]) Hit();
131  return hit;
132 }
133 
134 //______________________________________________________________________________
136 {
137  // Add a new hit to the list of hits in detector B
138 
139  TClonesArray &hitsB = *fHitsB;
140  Hit *hit = new(hitsB[fNhitB++]) Hit();
141  return hit;
142 }
143 
144 //______________________________________________________________________________
145 void JetEvent::Clear(Option_t *option)
146 {
147  fJets->Clear(option);
148  fTracks->Clear(option);
149  fHitsA->Clear(option);
150  fHitsB->Clear(option);
151 }
152 
153 //______________________________________________________________________________
154 void JetEvent::Reset(Option_t *)
155 {
156 // Static function to reset all static objects for this event
157 
158  delete fgJets; fgJets = 0;
159  delete fgTracks; fgTracks = 0;
160  delete fgHitsA; fgHitsA = 0;
161  delete fgHitsB; fgHitsB = 0;
162 }
163 
164 
165 
166 
167 
168