StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtIO.cc
1 /**********************************************************
2  *
3  * Here are defined the input/output stream operators for
4  * StHbtEvent and associated classes
5  *
6  *********************************************************/
7 
8 #ifndef StHbtIO_cc
9 #define StHbtIO_cc
10 
11 #include "StHbtMaker/Infrastructure/StHbtKink.hh"
12 #include "StHbtMaker/Infrastructure/StHbtV0.hh"
13 #include "StHbtMaker/Infrastructure/StHbtTrack.hh"
14 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
15 
16 #include <float.h> // these tell maximum values of types so we
17 #include <limits.h> // don't write the characters "inf" to our microDST
18 
19 
20 //------------------------- StHbtTrack -----------------------------------
21 ostream& operator<<(ostream& out, StHbtTrack& trk){
22  // sometimes ChiSqXY is infinity, so output largest number instead
23  float ChiSqXYtemp = (fabs(trk.mChiSqXY)>FLT_MAX) ? FLT_MAX : trk.mChiSqXY;
24 
25  return (
26  out
27  << trk.mTrackId << " "
28  << trk.mCharge << " "
29  << trk.mNHits << " "
30  << trk.mNHitsPoss << " "
31  << trk.mNSigmaElectron << " "
32  << trk.mNSigmaPion << " "
33  << trk.mNSigmaKaon << " "
34  << trk.mNSigmaProton << " "
35  << trk.mdEdx << " "
36  << trk.mDCAxy << " "
37  << trk.mDCAz << " "
38  << ChiSqXYtemp << " "
39  << trk.mChiSqZ << " "
40  << trk.mP.x() << " "
41  << trk.mP.y() << " "
42  << trk.mP.z() << " "
43  // now for the StPhysicalHelixD...
44  << trk.mHelix.curvature() << " "
45  << trk.mHelix.dipAngle() << " "
46  << trk.mHelix.phase() << " "
47  << trk.mHelix.origin().x() << " "
48  << trk.mHelix.origin().y() << " "
49  << trk.mHelix.origin().z() << " "
50  << trk.mHelix.h() << " "
51  << trk.mMap[0] << " "
52  << trk.mMap[1]
53  );
54 }
55 
56 istream& operator>>(istream& in, StHbtTrack& trk){
57  double x,y,z;
58  double curvature, dipAngle, phase; // for PhysicalHelix
59  double xorigin,yorigin,zorigin; // for PhysicalHelix
60  int h; // for PhysicalHelix
61  in
62  >> trk.mTrackId
63  >> trk.mCharge
64  >> trk.mNHits
65  >> trk.mNHitsPoss
66  >> trk.mNSigmaPion
67  >> trk.mNSigmaKaon
68  >> trk.mNSigmaProton
69  >> trk.mdEdx
70  >> trk.mDCAxy
71  >> trk.mDCAz
72  >> trk.mChiSqXY
73  >> trk.mChiSqZ
74  >> x
75  >> y
76  >> z
77  // now for the StPhysicalHelixD...
78  >> curvature
79  >> dipAngle
80  >> phase
81  >> xorigin
82  >> yorigin
83  >> zorigin
84  >> h
85  >> trk.mMap[0]
86  >> trk.mMap[1];
87  // set up P
88  trk.mP.setX(x);
89  trk.mP.setY(y);
90  trk.mP.setZ(z);
91  // Pt is derived
92  trk.mPt = ::sqrt(x*x+y*y);
93  // now set up the StPhysicalHelixD
94  StThreeVectorD origin(xorigin,yorigin,zorigin);
95  trk.mHelix.setParameters(curvature,dipAngle,phase,origin,h);
96  return in;
97 }
98 
99 //------------------------- StHbtV0 -----------------------------------
100 ostream& operator<<(ostream& out, StHbtV0& v0){
101 
102  return (out
103  << v0.mDecayLengthV0 << " " << v0.mDecayVertexV0.x() << " "
104  << v0.mDecayVertexV0.y() << " " << v0.mDecayVertexV0.z() << " "
105  << v0.mDcaV0Daughters << " " << v0.mDcaV0ToPrimVertex << " "
106  << v0.mDcaPosToPrimVertex <<" "<< v0.mDcaNegToPrimVertex << " "
107  << v0.mMomPos.x() << " " << v0.mMomPos.y() << " "
108  << v0.mMomPos.z() << " " << v0.mMomNeg.x() << " "
109  << v0.mMomNeg.y() << " " << v0.mMomNeg.z() << " "
110  << v0.mTrackTopologyMapPos[0] << " " << v0.mTrackTopologyMapPos[1] << " "
111  << v0.mTrackTopologyMapNeg[0] << " " << v0.mTrackTopologyMapNeg[1] << " "
112  << v0.mRapLambda << " " << v0.mRapK0Short << " "
113  << v0.mCTauLambda << " " << v0.mCTauK0Short << " "
114  << v0.mKeyNeg << " " << v0.mKeyPos );
115 }
116 
117 //------------------------- StHbtV0 -----------------------------------
118  istream& operator>>(istream& in, StHbtV0& v0){
119  in
120  >> v0.mDecayLengthV0 >> v0.mDecayVertexV0
121  >> v0.mDcaV0Daughters >> v0.mDcaV0ToPrimVertex
122  >> v0.mDcaPosToPrimVertex >> v0.mDcaNegToPrimVertex
123  >> v0.mMomPos >> v0.mMomNeg
124  >> v0.mTrackTopologyMapPos[0] >> v0.mTrackTopologyMapPos[1]
125  >> v0.mTrackTopologyMapNeg[0] >> v0.mTrackTopologyMapNeg[1]
126  >> v0.mRapLambda >> v0.mRapK0Short
127  >> v0.mCTauLambda >> v0.mCTauK0Short
128  >> v0.mKeyNeg >> v0.mKeyPos;
129  v0.UpdateV0();
130  return (in) ;
131 }
132 
133 //------------------------- StHbtEvent -----------------------------------
134 ostream& operator<<(ostream& out, StHbtEvent& ev){
135  out
136  << ev.mEventNumber << " " << ev.mRunNumber << " "
137  << ev.mCtbMultiplicity << " " << ev.mZdcAdc[0] << " "
138  << ev.mZdcAdc[1] << " " << ev.mTpcNhits << " "
139  << ev.mNumberOfTracks << " " << ev.mNumberOfGoodTracks << " "
140  << ev.mReactionPlane[0] << " " << ev.mReactionPlane[1] << " "
141  << ev.mPrimVertPos.x() << " " << ev.mPrimVertPos.y() << " "
142  << ev.mPrimVertPos.z() << " " << ev.mMagneticField << endl;
143  out << ev.mTrackCollection->size() << endl;;
144  StHbtTrack trk;
145  for (StHbtTrackIterator iter=ev.mTrackCollection->begin();
146  iter != ev.mTrackCollection->end(); iter++){
147  trk= **iter; // correct???
148  out << trk << endl; // don't forget the endl to seperate them...
149  }
150  // now we do the v0 collection...
151  out << ev.mV0Collection->size() << endl;;
152  StHbtV0 v0;
153  for (StHbtV0Iterator iterv0=ev.mV0Collection->begin();
154  iterv0 != ev.mV0Collection->end(); iterv0++){
155  v0 = **iterv0; // correct???
156  out << v0 << endl; // don't forget the endl to seperate them...
157  }
158 
159  out << endl; // blank-line delimiter between events
160  return out;
161 }
162 
163 istream& operator>>(istream& in, StHbtEvent& ev){
164 
165  double x,y,z;
166  in >> ev.mEventNumber;
167  if (in.eof()) {
168  cout << "Hit end of file " << endl;
169  return in;
170  }
171  in >> ev.mRunNumber
172  >> ev.mCtbMultiplicity
173  >> ev.mZdcAdc[0] >> ev.mZdcAdc[1]
174  >> ev.mTpcNhits >> ev.mNumberOfTracks
175  >> ev.mNumberOfGoodTracks >> ev.mReactionPlane[0]
176  >> ev.mReactionPlane[1] >> x
177  >> y >> z
178  >> ev.mMagneticField;
179  ev.mPrimVertPos.setX(x);
180  ev.mPrimVertPos.setY(y);
181  ev.mPrimVertPos.setZ(z);
182  //
183  // OK, time to read in Track and V0 collections
184  //
185  long NtracksInCollection;
186  in >> NtracksInCollection;
187  if (!(in.good())){
188  cout << "StHbtEvent input operator finds stream in bad state ! " << endl;
189  return in;
190  }
191  // ev.mTrackCollection = new StHbtTrackCollection; <-- NO!
192  // the TrackCollection is instantiated by constructor!!
193  //
194  // since this should *overwrite* any StHbtTracks in the
195  // StHbtTrackCollection, let's erase any that might be there
196  //
197  StHbtTrackIterator iter;
198  for (iter=ev.mTrackCollection->begin();iter!=ev.mTrackCollection->end();iter++){
199  delete *iter;
200  }
201  // ok, now we have gotten rid of the tracks themselves. Let's lose the pointers to those deleted tracks
202  ev.mTrackCollection->clear(); // if this doesn't work then just delete the collection and make a new one.
203 
204  for (int itrk=0; itrk<NtracksInCollection; itrk++){
205  StHbtTrack* trk = new StHbtTrack;
206  if ( !(in >> (*trk))){
207  cout << "StHbtEvent input operator finds stream in bad state during track read ! ";
208  cout << itrk << " of " << NtracksInCollection << " intended" << endl;
209  return in;
210  }
211  ev.mTrackCollection->push_back(trk); // ?ok?
212  //cout << " " << itrk;
213  }
214  // now we should do the v0 collection...
215 
216  long NV0sInCollection;
217  in >> NV0sInCollection;
218  if (!(in.good())){
219  cout << "StHbtEvent input operator finds stream in bad state ! " << endl;
220  return in;
221  }
222  // since this should *overwrite* any StHbtV0s in the
223  // StHbtV0Collection, let's erase any that might be there
224  //
225  StHbtV0Iterator iterv0;
226  for (iterv0=ev.mV0Collection->begin();iterv0!=ev.mV0Collection->end();iterv0++){
227  delete *iterv0;
228  }
229  // ok, now we have gotten rid of the v0s themselves. Let's lose the pointers to those deleted v0ss
230  ev.mV0Collection->clear(); // if this doesn't work then just delete the collection and make a new one.
231 
232  for (int iv0=0; iv0<NV0sInCollection; iv0++){
233  StHbtV0* v0 = new StHbtV0;
234  if ( !(in >> (*v0))){
235  cout << "StHbtEvent input operator finds stream in bad state during v0 read ! ";
236  cout << iv0 << " of " << NV0sInCollection << " intended" << endl;
237  return in;
238  }
239  ev.mV0Collection->push_back(v0); // ?ok?
240  //cout << " " << iv0;
241  }
242 
243  return in;
244 }
245 
246 //------------------------- StHbtKink -------------------------------
247 ostream& operator<<(ostream& out, StHbtKink& knk){
248  return (
249  out
250  << knk.mDcaParentDaughter << " "
251  << knk.mDcaDaughterPrimaryVertex << " "
252  << knk.mDcaParentPrimaryVertex << " "
253  << knk.mHitDistanceParentDaughter << " "
254  << knk.mHitDistanceParentVertex << " "
255  << knk.mDeltaEnergy[0] << " "
256  << knk.mDeltaEnergy[1] << " "
257  << knk.mDeltaEnergy[2] << " "
258  << knk.mDecayAngle << " "
259  << knk.mDecayAngleCM << " "
260  << knk.mDaughter << " "
261  << knk.mParent << " "
262  << knk.mPosition.x() << " "
263  << knk.mPosition.y() << " "
264  << knk.mPosition.z()
265  );
266 }
267 istream& operator>>(istream& in, StHbtKink& knk){
268  double x,y,z;
269  in
270  >> knk.mDcaParentDaughter
271  >> knk.mDcaDaughterPrimaryVertex
272  >> knk.mDcaParentPrimaryVertex
273  >> knk.mHitDistanceParentDaughter
274  >> knk.mHitDistanceParentVertex
275  >> knk.mDeltaEnergy[0]
276  >> knk.mDeltaEnergy[1]
277  >> knk.mDeltaEnergy[2]
278  >> knk.mDecayAngle
279  >> knk.mDecayAngleCM
280  >> knk.mDaughter
281  >> knk.mParent
282  >> x
283  >> y
284  >> z;
285  knk.mPosition.setX(x);
286  knk.mPosition.setY(y);
287  knk.mPosition.setZ(z);
288 
289  return in;
290 }
291 
292 
293 #endif
void setParameters(double c, double dip, double phase, const StThreeVector< double > &o, int h)
starting point
Definition: StHelix.cc:139
int h() const
y-center of circle in xy-plane
Definition: StHelix.hh:174
const StThreeVector< double > & origin() const
-sign(q*B);
Definition: StHelix.hh:224
double phase() const
1/R in xy-plane
Definition: StHelix.hh:180