EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicAsciiBoxGenerator.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicAsciiBoxGenerator.cxx
1 //
2 // AYK (ayk@bnl.gov), 2015/11/06
3 //
4 // A (temporary) hack to import HIJING ASCII files with the same interface
5 // calls which are provided with the EicBox Generator;
6 //
7 
8 #include <assert.h>
9 #include <stdlib.h>
10 
11 #include <TRandom.h>
12 #include <TMath.h>
13 #include <TDatabasePDG.h>
14 #include <TParticlePDG.h>
15 
16 #include <EicAsciiBoxGenerator.h>
17 
18 // ---------------------------------------------------------------------------------------
19 
21  mFstream(0), mPtMin(0.0), mPtMax(0.0), mRemainingTrackCounter(0)
22 {
23  if (fileName) {
24  char title[1024];
25 
26  // Open input stream, check title and skip few lines; FIXME: more checks needed!;
27  mFstream = new std::fstream(fileName);
28  mFstream->getline(title, 1024-1);
29  if (strcmp(title, " HIJING EVENT FILE")) {
30  printf("no HIJING file header line found!\n");
31  mFstream->close();
32  mFstream = 0;
33  } //if
34  //printf("%s\n", buffer); exit(0);
35  } //if
36 } // EicAsciiBoxGenerator::EicAsciiBoxGenerator()
37 
38 // ---------------------------------------------------------------------------------------
39 
41 {
42  //printf("Entering EicAsciiBoxGenerator::ReadEvent() ...\n");
43 
44  // The return value logic is to fail in case of no input sream at all, but keep
45  // returning kTRUE with no tracks in case input file is over;
46  if (!mFstream) return kFALSE;
47 
48  // Vertex; ignore the stuff in HIJING file for now; FIXME: make this
49  // behaviour configurable;
50  double vtx[3];
51  //for(unsigned iq=0; iq<3; iq++)
52  //vtx[iq] = mCoord[iq] + (mCoordSigma[iq] ? gRandom->Gaus(0.0, mCoordSigma[iq]) : 0.0);
53  //printf("%f %f\n", vtx[0], vtx[1]);
54  // FIXME: should unify with EicBoxGenerator call;
55  for(unsigned iq=0; iq<3; iq++) {
56  vtx[iq] = mCoord[iq] +
58  (mCoordSigma[iq] ? gRandom->Gaus(0.0, mCoordSigma[iq]) : 0.0) :
59  (mCoordRange[iq] ? gRandom->Uniform(-mCoordRange[iq]/2, mCoordRange[iq]/2) : 0.0));
60  } //for iq
61 
62  unsigned thisEventTrackCounter = 0;
63 
64  // FIXME: need to break if event list is over;
65  for( ; ; ) {
66  //printf(" Entering inf.loop with %5d remaining tracks ...\n", mRemainingTrackCounter);
68  // Skip few lines;
69  char buffer[1024];
70  for(unsigned iq=0; iq<5; iq++)
71  mFstream->getline(buffer, 1024-1);
72  if (IsOver()) return kTRUE;
73 
74  // Get track count; arrange the loop; FIXME: the code is very unsafe;
75  {
76  double d0;
77  unsigned i0, i1, i2;
78 
79  *mFstream >> i0 >> d0 >> i1 >> i2 >> mRemainingTrackCounter;
80  if (IsOver()) return kTRUE;
81  }
82  //printf(" Reading event header: %5d new tracks ...\n", mRemainingTrackCounter);
83 
84  //printf("%d\n", mRemainingTrackCounter);
85  // Skip this current line and the next one;
86  {
87  char buffer[1024];
88 
89  for(unsigned iq=0; iq<2; iq++)
90  mFstream->getline(buffer, 1024-1);
91  if (IsOver()) return kTRUE;
92  }
93  } //if
94 
95  // Loop though all tracks (or as many as requested);
96  for(unsigned tr=0; tr<mRemainingTrackCounter; tr++) {
97  int pdg;
98  double px, py, pz;
99  {
100  unsigned i0, i1, i2, i3, i4, i5;
101  double d0, d1, d2, d3, d4;
102  *mFstream >> i0 >> pdg >> i1 >> i2 >> i3 >> i4 >> i5 >> px >> py >> pz >> d0 >> d1 >> d2 >> d3 >> d4;
103  if (IsOver()) return kTRUE;
104  }
105  //printf("%4d -> %5d; %8.3f %8.3f %8.3f\n", tr, pdg, px, py, pz);
106 
107  // A hack to skip beam particle instance(s) which are a plenty in the
108  // file I have in hands;
109  if (!px && !py) continue;
110 
111  // Well, I guess for now I do not need neutrals?;
112  TDatabasePDG *pdgTable = TDatabasePDG::Instance(); assert(pdgTable);
113  TParticlePDG *particle = pdgTable->GetParticle(pdg);
114  if (!particle->Charge()) continue;
115  //printf("%4d -> %f\n", pdg, particle->Charge());
116 
117  // And the perform acceptance checks if EicBoxGenerator was configured so;
118  TVector3 p(px, py, pz);
119  // FIXME: do it better later (unify)?;
120  if (mPtMin || mPtMax) {
121  if (p.Pt() < mPtMin || p.Pt() > mPtMax) continue;
122  } //if
123  if (mPmin || mPmax) {
124  if (p.Mag() < mPmin || p.Mag() > mPmax) continue;
125  } //if
126  if (mThetaMin || mThetaMax) {
127  double thetaDeg = p.Theta()*180.0/TMath::Pi();
128  if (thetaDeg < mThetaMin || thetaDeg > mThetaMax) continue;
129  } //if
130  if (mPhiMin || mPhiMax) {
131  double phiDeg = p.Phi()*180.0/TMath::Pi();
132  if (phiDeg < mPhiMin || phiDeg > mPhiMax) continue;
133  } //if
134 
135  {
136  // FIXME: unify all these pieces of code in all generators;
137  TVector3 pvect = GetModifiedTrack(TVector3(px, py, pz));
138  //primGen->AddTrack(pdg, px, py, pz, vtx[0], vtx[1], vtx[2]);
139  primGen->AddTrack(pdg, pvect[0], pvect[1], pvect[2], vtx[0], vtx[1], vtx[2]);
140  }
141 
142  thisEventTrackCounter++;
143  //printf(" (tr=%5d): this event tr.counter --> %5d\n", tr, thisEventTrackCounter);
144  if (mMult && thisEventTrackCounter == mMult) {
145  mRemainingTrackCounter -= (tr+1);
146  //printf("Exiting track loop; %5d tracks remaining ...\n", mRemainingTrackCounter);
147  break;
148  } //if
149  } //for tr
150 
151  // Help the default logic (when all tracks in a given Hijing event are read in);
152  if (!mMult || (mMult && thisEventTrackCounter != mMult)) mRemainingTrackCounter = 0;
153 
154  // Get ready for the next event;
155  if (!mRemainingTrackCounter)
156  {
157  char buffer[1024];
158 
159  //printf("No more tracks, getting ready to the next event ...\n");
160  mFstream->getline(buffer, 1024-1);
161  if (IsOver()) return kTRUE;
162  } //if
163 
164  // In case of either default behaviour or mMult tracks spooled out:
165  // break out of the infinite loop;
166  if (!mMult || (mMult && thisEventTrackCounter == mMult)) break;
167  } //for inf
168 
169  return kTRUE;
170 } // EicAsciiBoxGenerator::ReadEvent()
171 
172 // ---------------------------------------------------------------------------------------
173