StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructQJ.cxx
1 /**********************************************************************
2  *
3  * $Id: StEStructQJ.cxx,v 1.4 2012/11/16 21:23:19 prindle Exp $
4  *
5  * Author: Jeff Porter
6  *
7  **********************************************************************
8  *
9  * Description: EStructEventReader which reads Quing Juns format
10  *
11  **********************************************************************/
12 #include "StEStructQJ.h"
13 
14 #include "StEStructPool/AnalysisMaker/StEStructEventCuts.h"
15 #include "StEStructPool/AnalysisMaker/StEStructTrackCuts.h"
16 #include "StEStructPool/EventMaker/StEStructEvent.h"
17 #include "StEStructPool/EventMaker/StEStructTrack.h"
18 
19 StEStructQJ::StEStructQJ(char *fileList): meventCount(0), meventsToDo(0), mAmDone(false) {
20  fileListName = fileList;
21  fList = NULL;
22  inFile = NULL;
23 };
24 
25 StEStructQJ::StEStructQJ(char *fileList, int nevents, StEStructEventCuts* ecuts, StEStructTrackCuts* tcuts): meventCount(0), mAmDone(false){
26 
27  fileListName = fileList;
28  fList = NULL;
29  inFile = NULL;
30 
31  meventsToDo=nevents;
32  mECuts=ecuts;
33  mTCuts=tcuts;
34 
35 };
36 
37 bool StEStructQJ::hasGenerator() { return true; };
38 
39 
40 //-------------------------------------------------------------------------
41 void StEStructQJ::setSeed(int iseed) {
42  cout << " Calling srand48(" << iseed << ")" << endl;
43  srand48(iseed);
44 }
45 
46 //-------------------------------------------------------------------------
47 StEStructEvent* StEStructQJ::next() {
48 
49  if(meventCount==meventsToDo){
50  mAmDone=true;
51  return (StEStructEvent*)NULL;
52  }
53  return generateEvent();
54 }
55 
56 //--------------------------------------------------------------------------
57 StEStructEvent* StEStructQJ::generateEvent() {
58 
59  StEStructEvent* retVal=NULL;
60 
61  retVal = new StEStructEvent();
62 
63  fillTracks(retVal);
64  if (!mECuts->goodCentrality(retVal->Centrality())) {
65  delete retVal;
66  retVal=NULL;
67  } else {
68  retVal->FillChargeCollections();
69  }
70 
71  return retVal;
72 }
73 
74 //--------------------------------------------------------------------------
75 void StEStructQJ::fillTracks(StEStructEvent* estructEvent) {
76 
77  mnumTracks=0;
78  StEStructTrack* eTrack = new StEStructTrack();
79  int pid, totTracks;
80  double px, py, eta;
81 
82  if ((totTracks = getNumTracks()) < 0) {
83  mAmDone=true;
84  return;
85  }
86  int it = 0;
87  for(int i=0;i<totTracks;i++) {
88  it ++;
89  eTrack->SetInComplete();
90  *inFile >> px >> py >> eta >> pid;
91  if (inFile->eof()) {
92  delete estructEvent;
93  estructEvent = NULL;
94  return;
95  }
96 
97  double pt = sqrt( px*px + py*py );
98  double pz = sqrt( pt*pt + 0.139*0.139) * (exp(eta)-exp(-eta)) / 2;
99  double phi = atan2( py, px );
100 
101  bool useTrack = true;
102  useTrack = (mTCuts->goodEta(eta) && useTrack);
103  useTrack = (mTCuts->goodPhi(phi) && useTrack);
104 
105  if (pt<0.15) continue;
106 
107  mnumTracks++;
108  useTrack = (mTCuts->goodPt(pt) && useTrack);
109  float _r=pt/0.139;
110  float yt=log(sqrt(1+_r*_r)+_r);
111  useTrack = (mTCuts->goodYt(yt) && useTrack);
112  mTCuts->fillHistograms(useTrack);
113  if (!useTrack) continue;
114 
115  eTrack->SetBx(0);
116  eTrack->SetBy(0);
117  eTrack->SetBz(0);
118  eTrack->SetBxGlobal(0);
119  eTrack->SetByGlobal(0);
120  eTrack->SetBzGlobal(0);
121 
122  eTrack->SetPx(px);
123  eTrack->SetPy(py);
124  eTrack->SetPz(pz);
125  eTrack->SetEta(eta);
126  eTrack->SetPhi(phi);
127 
128  if (pid<0) {
129  eTrack->SetCharge(-1);
130  } else {
131  eTrack->SetCharge(1);
132  }
133  estructEvent->AddTrack(eTrack);
134  }
135  estructEvent->SetCentrality(impact);
136 
137  delete eTrack;
138  return;
139 }
140 
141 //--------------------------------------------------------------------------
142 int StEStructQJ::getNumTracks() {
143  int nTot, nAcc, i;
144  char buffer[1024];
145 
146  if (!fList) {
147 cout << "Opening file list " << fileListName << endl;
148  fList = new std::ifstream(fileListName);
149  }
150  if (!inFile) {
151  *fList >> buffer;
152  if (fList->eof()) {
153 cout << "Got to end of fileList. Returning -1. (Should end program)" << endl;
154  delete fList;
155  return -1;
156  }
157 cout << "About to open file " << buffer << endl;
158  inFile = new std::ifstream(buffer);
159  }
160  *inFile >> nTot >> nAcc >> impact >> i >> i >> i >> i >> i >> i >> i;
161  if (!inFile->eof()) {
162  return nAcc;
163  } else {
164 cout << "Read to end of file. Closing it and returning 0." << endl;
165 cout << "(Should allow us to go on to next file.)" << endl;
166  delete inFile;
167  inFile = NULL;
168  return 0;
169  }
170 }
171 
172 
173 
174 /**********************************************************************
175  *
176  * $Log: StEStructQJ.cxx,v $
177  * Revision 1.4 2012/11/16 21:23:19 prindle
178  * EventCuts and TrackCuts were moved to EventReader. Remove that code from
179  * these readers.
180  *
181  * Revision 1.3 2006/04/06 01:03:33 prindle
182  *
183  * Rationalization of centrality binning, as described in AnalysisMaker checkin.
184  *
185  * Revision 1.2 2006/02/22 22:05:39 prindle
186  * Removed all references to multRef (?)
187  *
188  * Revision 1.1 2004/03/02 21:50:58 prindle
189  *
190  * I forgot to cvs add my EventGenerator readers.
191  *
192  * Revision 1.2 2003/11/25 22:45:14 prindle
193  * Commiting changes so I can move code to rhic
194  *
195  * Revision 1.1 2003/11/21 23:48:00 prindle
196  * Include my toy event generator in cvs
197  *
198  *
199  *********************************************************************/