StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructAscii.cxx
1 /**********************************************************************
2  *
3  * StEStructAscii.cxx
4  *
5  * Author: msd
6  *
7  **********************************************************************
8  *
9  * Description:
10  *
11  **********************************************************************/
12 #include "StEStructAscii.h"
13 #include "StEStructPool/AnalysisMaker/StEStructEventCuts.h"
14 #include "StEStructPool/AnalysisMaker/StEStructTrackCuts.h"
15 #include "StEStructPool/EventMaker/StEStructEvent.h"
16 #include "StEStructPool/EventMaker/StEStructTrack.h"
17 #include "TLorentzVector.h"
18 
19 StEStructAscii::StEStructAscii(): meventCount(0), meventsToDo(0), mAmDone(false) {};
20 
21 StEStructAscii::StEStructAscii(int nevents, char* infile, StEStructEventCuts* ecuts, StEStructTrackCuts* tcuts): meventCount(0), mAmDone(false){
22 
23  meventsToDo=nevents;
24  mECuts=ecuts;
25  mTCuts=tcuts;
26 
27  cout << "Opening ASCII file " << infile << endl;
28  in.open(infile);
29  mlineNumber = 0;
30 
31  if (!in) cout << " *** WARNING: Error reading file " << infile << endl;
32 
33 };
34 
35 bool StEStructAscii::hasInputFile() { return (in.good()) ? true : false ; };
36 
37 //-------------------------------------------------------------------------
38 StEStructEvent* StEStructAscii::next() {
39 
40  if( (!in.good()&&meventCount>0) || ((meventsToDo>0)&&(meventCount==meventsToDo)) || in.eof() ){ // quit on read error, event limit, or eof
41  mAmDone=true;
42  in.close(); // Close the ifstream when finished
43  cout << "Done. Quitting after " << meventCount << " events." << endl;
44  return (StEStructEvent*)NULL;
45  }
46  return generateEvent();
47 }
48 
49 //--------------------------------------------------------------------------
50 StEStructEvent* StEStructAscii::generateEvent(){
51 
52  StEStructEvent* retVal=NULL;
53 
54  retVal = new StEStructEvent();
55 
56  fillTracks(retVal);
57 
58  /*
59  bool useEvent=mECuts->goodCentrality((float)mnumTracks);
60  if(!useEvent){
61  cout << "Cutting event with " << mnumTracks << " tracks." << endl;
62  delete retVal;
63  retVal=NULL;
64  } else {
65  retVal->FillChargeCollections();
66  meventCount++;
67  }
68  mECuts->fillHistogram(mECuts->centralityName(),(float)mnumTracks,useEvent);
69  */
70 
71  retVal->FillChargeCollections();
72  retVal->SetEventID(meventCount);
73  retVal->SetVertex(0,0,0);
74  retVal->SetBField(0);
75 
76  meventCount++;
77 
78  return retVal;
79 }
80 
81 //--------------------------------------------------------------------------
82 void StEStructAscii::fillTracks(StEStructEvent* estructEvent){
83 
84  mnumTracks=0;
85 
86  float pt, eta, phi;
87 
88 
89  int numParticles, charge;
90  in >> numParticles; // Read # of particles in this event
91  mlineNumber++; // Increment line number
92  if (in.eof()) { // Do some error checking
93  cout << "Found EOF" << endl;
94  return;
95  }
96  if (!in.good()) {
97  cout << "WARNING: Read error at line" << mlineNumber << endl;
98  return;
99  }
100  //cout << "Reading " << numParticles << " particles" << endl; // ***TEST***
101 
102  estructEvent->SetCentrality(numParticles);
103 
104  StEStructTrack* eTrack= new StEStructTrack();
105 
106  for(int i=0;i<numParticles;i++){ // Loop over particles
107  eTrack->SetInComplete();
108 
109  // Making new format: pt, eta, phi, charge
110  in >> pt >> eta >> phi >> charge;
111  mlineNumber+=1;
112  if (!in.good()) { // Check for error
113  cout << "WARNING: Read error near line" << mlineNumber << endl;
114  return;
115  }
116 
117  TLorentzVector track; // for finding components
118  track.SetPtEtaPhiM(pt, eta, phi, 0.14);
119 
120  eTrack->SetPx(track.Px());
121  eTrack->SetPy(track.Py());
122  eTrack->SetPz(track.Pz());
123  eTrack->SetEta(eta);
124  eTrack->SetPhi(phi);
125  eTrack->SetCharge(charge);
126 
127  // Not doing any track or event cuts, but lets fill some cut hists
128  bool useTrack=true;
129  useTrack = (mTCuts->goodCharge(charge) && useTrack);
130  useTrack = (mTCuts->goodEta(eta) && useTrack);
131  useTrack = (mTCuts->goodPhi(phi) && useTrack);
132  useTrack = (mTCuts->goodPt(pt) && useTrack);
133  mTCuts->fillHistograms(true);
134 
135  //cout << "Adding track:\t" << pt<<"\t"<< eta << "\t" << phi << "\t" << charge << endl;
136  estructEvent->AddTrack(eTrack);
137  } // for
138 
139  delete eTrack;
140  return;
141 
142 }
143 
144 
145 
146 
147 /**********************************************************************
148  *
149  * $Log: StEStructAscii.cxx,v $
150  * Revision 1.5 2012/11/16 21:23:18 prindle
151  * EventCuts and TrackCuts were moved to EventReader. Remove that code from
152  * these readers.
153  *
154  * Revision 1.4 2007/01/26 17:19:33 msd
155  * Total rewrite. Now uses simple input text file format of pt,eta,phi for each particle.
156  *
157  * Revision 1.3 2006/02/22 22:05:33 prindle
158  * Removed all references to multRef (?)
159  *
160  * Revision 1.2 2005/09/14 17:18:38 msd
161  * Setting numEvents to 0 now does all events in file
162  *
163  * Revision 1.1 2004/06/28 19:54:54 msd
164  * Initial check-in
165  *
166  * Revision 1.1
167  *
168  *
169  *
170  *********************************************************************/