StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtTTreeEvent.cxx
1 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
2 #include "StHbtMaker/Infrastructure/StHbtTTreeEvent.h"
3 #include "StHbtMaker/Infrastructure/StHbtTTreeTrack.h"
4 #include "StHbtMaker/Infrastructure/StHbtTTreeV0.h"
5 #include "StHbtMaker/Infrastructure/StHbtTTreeXi.h"
6 #include "StHbtMaker/Infrastructure/StHbtTTreeKink.h"
7 #include "StHbtMaker/Base/StHbtEventCut.h"
8 #include "StHbtMaker/Base/StHbtTrackCut.h"
9 #include "StHbtMaker/Base/StHbtV0Cut.h"
10 #include "StHbtMaker/Base/StHbtXiCut.h"
11 #include "StHbtMaker/Base/StHbtKinkCut.h"
12 
13 #include "StHbtMaker/Infrastructure/StHbtTrackCollection.hh"
14 #include "StHbtMaker/Infrastructure/StHbtV0Collection.hh"
15 #include "StHbtMaker/Infrastructure/StHbtXiCollection.hh"
16 #include "StHbtMaker/Infrastructure/StHbtKinkCollection.hh"
17 
18 #include "StExceptions.hh"
19 #include "StarClassLibrary/SystemOfUnits.h"
20 
21 ClassImp(StHbtTTreeEvent)
22 
23 int StHbtTTreeEvent::mDebug = 0;
24 TClonesArray *StHbtTTreeEvent::fgTracks = 0;
25 TClonesArray *StHbtTTreeEvent::fgV0s = 0;
26 TClonesArray *StHbtTTreeEvent::fgXis = 0;
27 TClonesArray *StHbtTTreeEvent::fgKinks = 0;
28 
29 //-----------------------------------------------------------------------
30 //-----------------------------------------------------------------------
31 //-----------------------------------------------------------------------
33  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent()" << endl;
34  initClonesArrays();
35 }
36 //-----------------------------------------------------------------------
37 //-----------------------------------------------------------------------
38 //-----------------------------------------------------------------------
39 StHbtTTreeEvent::~StHbtTTreeEvent(){
40  if (mDebug) cout << "StHbtTTreeEvent::~StHbtTTreeEvent()" << endl;
41  fgTracks->Clear("");
42  fgV0s->Clear("");
43  fgXis->Clear("");
44  fgKinks->Clear("");
45  mNtracks=0;
46  mNv0s=0;
47  mNxis=0;
48  mNkinks=0;
49 }
50 //-----------------------------------------------------------------------
51 //-----------------------------------------------------------------------
52 //-----------------------------------------------------------------------
53 void StHbtTTreeEvent::initClonesArrays(){
54  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays()" << endl;
55  /* *** array to hold tracks *** */
56  if (!fgTracks) {
57  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays() create fgTracks" << endl;
58  fgTracks = new TClonesArray("StHbtTTreeTrack", 4000);
59  mNtracks=0;
60  }
61  fTracks = fgTracks;
62  /* *** array to hold V0s *** */
63  if (!fgV0s) {
64  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays() create fgV0s" << endl;
65  fgV0s = new TClonesArray("StHbtTTreeV0", 4000);
66  mNv0s=0;
67  }
68  fV0s = fgV0s;
69  /* *** array to hold Xis *** */
70  if (!fgXis) {
71  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays() create fgXis" << endl;
72  fgXis = new TClonesArray("StHbtTTreeXi", 4000);
73  mNxis=0;
74  }
75  fXis = fgXis;
76  /* *** array to hold Kinks *** */
77  if (!fgKinks) {
78  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays() create fgKinks" << endl;
79  fgKinks = new TClonesArray("StHbtTTreeKink", 4000);
80  mNkinks=0;
81  }
82  fKinks = fgKinks;
83 
84  if (mDebug) cout << "StHbtTTreeEvent::initClonesArrays() leaving" << endl;
85 }
86 //-----------------------------------------------------------------------
87 //-----------------------------------------------------------------------
88 //-----------------------------------------------------------------------
89 StHbtTTreeEvent::StHbtTTreeEvent(const StHbtEvent* event, StHbtTrackCut* trackCut, StHbtV0Cut* v0Cut, StHbtXiCut* xiCut, StHbtKinkCut* kinkCut){
90  try {
91  initClonesArrays();
92  fillEventInfo(event);
93  }
94  catch (StException e) {
95  throw e;
96  }
97 
98  // loop over tracks
99  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->TrackCollection()->size() << " tracks" << endl;
100  for (StHbtTrackIterator iter=event->TrackCollection()->begin(); iter != event->TrackCollection()->end(); iter++){
101  if (!trackCut || trackCut->Pass(*iter)) addTrack(event,*iter);
102  }
103  // loop over v0s
104  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->V0Collection()->size() << " v0s" << endl;
105  for (StHbtV0Iterator iter=event->V0Collection()->begin(); iter != event->V0Collection()->end(); iter++){
106  if (!v0Cut || v0Cut->Pass(*iter)) addV0(event,*iter);
107  }
108  // loop over xis
109  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->XiCollection()->size() << " xis" << endl;
110  for (StHbtXiIterator iter=event->XiCollection()->begin(); iter != event->XiCollection()->end(); iter++){
111  if (!xiCut || xiCut->Pass(*iter)) addXi(event,*iter);
112  }
113  // loop over kinks
114  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->KinkCollection()->size() << " kinks" << endl;
115  for (StHbtKinkIterator iter=event->KinkCollection()->begin(); iter != event->KinkCollection()->end(); iter++){
116  if (!kinkCut || kinkCut->Pass(*iter)) addKink(event,*iter);
117  }
118 }
119 //-----------------------------------------------------------------------
120 //-----------------------------------------------------------------------
121 //-----------------------------------------------------------------------
122 void StHbtTTreeEvent::fill(const StHbtEvent* event, StHbtTrackCut* trackCut, StHbtV0Cut* v0Cut, StHbtXiCut* xiCut, StHbtKinkCut* kinkCut){
123  clear();
124  try {
125  fillEventInfo(event);
126  }
127  catch (StException e) {
128  throw e;
129  }
130  // loop over tracks
131  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->TrackCollection()->size() << " tracks" << endl;
132  for (StHbtTrackIterator iter=event->TrackCollection()->begin(); iter != event->TrackCollection()->end(); iter++){
133  if (!trackCut || trackCut->Pass(*iter)) addTrack(event,*iter);
134  }
135  // loop over v0s
136  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->V0Collection()->size() << " v0s" << endl;
137  for (StHbtV0Iterator iter=event->V0Collection()->begin(); iter != event->V0Collection()->end(); iter++){
138  if (!v0Cut || v0Cut->Pass(*iter)) addV0(event,*iter);
139  }
140  // loop over xis
141  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->XiCollection()->size() << " xis" << endl;
142  for (StHbtXiIterator iter=event->XiCollection()->begin(); iter != event->XiCollection()->end(); iter++){
143  if (!xiCut || xiCut->Pass(*iter)) addXi(event,*iter);
144  }
145  // loop over kinks
146  if (mDebug) cout << "StHbtTTreeEvent::StHbtTTreeEvent(...) - now fill " << event->KinkCollection()->size() << " kinks" << endl;
147  for (StHbtKinkIterator iter=event->KinkCollection()->begin(); iter != event->KinkCollection()->end(); iter++){
148  if (!kinkCut || kinkCut->Pass(*iter)) addKink(event,*iter);
149  }
150 }
151 //-----------------------------------------------------------------------
152 //-----------------------------------------------------------------------
153 //-----------------------------------------------------------------------
154 void StHbtTTreeEvent::fillEventInfo(const StHbtEvent* event){
155  if (mDebug) cout << "StHbtTTreeEvent::fillEventInfo(StEvent* event)" << endl;
156  if (!event)
157  throw StExceptionNullPointer("StHbtTTreeEvent::fillEventInfo(StHbtEvent* event) - event");
158  mEventNumber = event->mEventNumber;
159  mRunNumber = event->mRunNumber;
160  mTpcNhits = event->mTpcNhits;
161  mNumberOfTracks = event->mNumberOfTracks;
162  mNumberOfGoodTracks= event->mNumberOfGoodTracks;
163  mUncorrectedNumberOfPositivePrimaries = event->mUncorrectedNumberOfPositivePrimaries;
164  mUncorrectedNumberOfNegativePrimaries = event->mUncorrectedNumberOfNegativePrimaries;
165  mReactionPlane[0] = event->mReactionPlane[0];
166  mReactionPlane[1] = event->mReactionPlane[1];
167  mReactionPlanePtWgt[0] = event->mReactionPlanePtWgt[0];
168  mReactionPlanePtWgt[1] = event->mReactionPlanePtWgt[1];
169  mVertexX = event->mPrimVertPos.x();
170  mVertexY = event->mPrimVertPos.y();
171  mVertexZ = event->mPrimVertPos.z();
172  mCtbMultiplicity = event->mCtbMultiplicity;
173  mZdcAdc[0] = event->mZdcAdc[0];
174  mZdcAdc[1] = event->mZdcAdc[1];
175  mMagneticField = event->mMagneticField;
176  mTriggerWord = event->mTriggerWord;
177  mTriggerActionWord = event->mTriggerActionWord;
178  //for ( int i=0; i<4; i++) mL3TriggerAlgorithm[i] = event->mL3TriggerAlgorithm[i];
179  mL3TriggerAlgorithm = event->mL3TriggerAlgorithm[0];
180 
181  if (mDebug) cout << "StHbtTTreeEvent::fillEventInfo(StEvent* event) - leaving" << endl;
182 }
183 //-----------------------------------------------------------------------
184 //-----------------------------------------------------------------------
185 //-----------------------------------------------------------------------
186 void StHbtTTreeEvent::clear(){
187  if (mDebug) cout << "StHbtTTreeEvent::clear(...)" << endl;
188 // for (unsigned short i=0; i<mNtracks; i++) delete (StHbtTTreeTrack*)fTracks->UncheckedAt(i);
189 // for (unsigned short i=0; i<mNv0s; i++) delete (StHbtTTreeV0*)fV0s->UncheckedAt(i);
190 // for (unsigned short i=0; i<mNxis; i++) delete (StHbtTTreeXi*)fXis->UncheckedAt(i);
191 // for (unsigned short i=0; i<mNkinks; i++) delete (StHbtTTreeKink*)fKinks->UncheckedAt(i);
192 
193  fTracks->Clear();
194  fV0s->Clear();
195  fXis->Clear();
196  fKinks->Clear();
197 
198  mNtracks=0;
199  mNv0s=0;
200  mNxis=0;
201  mNkinks=0;
202 }
203 //---------------------------------------------------------------------
204 //---------------------------------------------------------------------
205 //---------------------------------------------------------------------
206 void StHbtTTreeEvent::addTrack(const StHbtEvent* event, const StHbtTrack* track) {
207  if (mDebug>1) cout << "StHbtTTreeEvent::addTrack(...) " << endl;
208  TClonesArray &tracks = *fTracks;
209  try{
210  new(tracks[mNtracks++]) StHbtTTreeTrack(event, track);
211  }
212  catch (StException e) {
213  if (mDebug>1) e.print();
214  }
215 }
216 //---------------------------------------------------------------------
217 //---------------------------------------------------------------------
218 //---------------------------------------------------------------------
219 void StHbtTTreeEvent::addV0(const StHbtEvent* event, const StHbtV0* v0) {
220  if (mDebug>1) cout << "StHbtTTreeEvent::addV0(...) " << endl;
221  TClonesArray &v0s = *fV0s;
222  try {
223  new(v0s[mNv0s++]) StHbtTTreeV0(event, v0);
224  }
225  catch (StException e) {
226  e.print();
227  }
228 }
229 //---------------------------------------------------------------------
230 //---------------------------------------------------------------------
231 //---------------------------------------------------------------------
232 void StHbtTTreeEvent::addXi(const StHbtEvent* event, const StHbtXi* xi) {
233  if (mDebug>1) cout << "StHbtTTreeEvent::addXi(...) " << endl;
234  TClonesArray &xis = *fXis;
235  try {
236  new(xis[mNxis++]) StHbtTTreeXi(event, xi);
237  }
238  catch (StException e) {
239  e.print();
240  }
241 }
242 //---------------------------------------------------------------------
243 //---------------------------------------------------------------------
244 //---------------------------------------------------------------------
245 void StHbtTTreeEvent::addKink(const StHbtEvent* event, const StHbtKink* kink) {
246  TClonesArray &kinks = *fKinks;
247  try {
248  new(kinks[mNkinks++]) StHbtTTreeKink(event, kink);
249  }
250  catch (StException e) {
251  e.print();
252  }
253 }
254 
255 
256 void StHbtTTreeEvent::SetMagneticField(double m) {mMagneticField=m;}
257 
258