urqmd2u.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // urqmd2u reads UrQMD events from the ftn13 or ftn14 ascii files and
  3. // converts them to the UniGen format and saves on a root file.
  4. //
  5. // ftn14 contains snapshots at given times (event steps). The event steps
  6. // are converted to separate events.
  7. //
  8. // ftn13 contains the final snapshot and the freeze-out coordinates.
  9. // The freeze-out coordinates are used. The final snapshot coordinates
  10. // are discarded.
  11. //
  12. // D.Miskowiec, February 2006
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // C++ headers
  15. #include <iostream>
  16. #include <fstream>
  17. #include <iomanip>
  18. #include <map>
  19. // ROOT headers
  20. #include "TFile.h"
  21. #include "TTree.h"
  22. #include "TString.h"
  23. #include "TBranch.h"
  24. #include "TMath.h"
  25. #include "TClonesArray.h"
  26. // UniGen headers
  27. #include "URun.h"
  28. #include "UEvent.h"
  29. #include "UParticle.h"
  30. #include "UPIDConverter.h"
  31. #include "UArrays.h"
  32. using namespace std;
  33. TFile *fi;
  34. TTree *tr;
  35. TClonesArray *arrays[UArrays::NAllUArrays];
  36. //_________________
  37. void bomb(const char *myst) {
  38. cerr << "Error: " << myst << ", bombing" << endl;
  39. exit(-1);
  40. }
  41. //_________________
  42. int trapco(int ityp, int ichg) {
  43. // translate UrQMD pid code to pdg code
  44. /* UrQMD PIDs are in fact composite - a particle is fully defined by the
  45. type specifier (ityp), the charge (ichg) and in case of baryons, the
  46. third component isospin (iso3; ignored by us at present). For
  47. simplicity, our conversion tables collapse these into a single number
  48. as follows:
  49. - propagate the sign of ityp (particle-antiparticle distinction for
  50. baryons, strangeness-antistrangeness distinction for mesons) to that
  51. of the stored value;
  52. - shift the ichg range from -2..2 (UrQMD does not support nuclear
  53. fragments other than protons and neutrons so all particles it
  54. produces fall in this range) to 0..4 to make sure it doesn't
  55. interfere with the above;
  56. - multiply shifted charge by +/-1000 and add it to type. The latter
  57. is guaranteed to be smaller than 1000 (baryon types are one- or
  58. two-digit, meson types three-digit) so that way no ambiguities
  59. occur. */
  60. int id;
  61. if (ityp >= 0) id = 1000 * (ichg + 2) + ityp;
  62. else
  63. id = -1000 * (ichg + 2) + ityp;
  64. /* This will return 0 for unknown input values. */
  65. return UPIDConverter::Instance()->GetPDGCode(id, UPIDConverter::eUrQMD);
  66. }
  67. //_________________
  68. int main(int argc, char *argv[]) {
  69. ifstream in;
  70. char *inpfile;
  71. char *outfile;
  72. char c;
  73. int nevents;
  74. string dust;
  75. string version, comment;
  76. int filetype, eos, aproj, zproj, atarg, ztarg, nr;
  77. double beta, b, bmin, bmax, sigma, elab, plab, sqrts, time, dtime;
  78. if (argc != 4) {
  79. cout << "usage: " << argv[0] << " inpfile outfile nevents\n";
  80. cout << "example: " << argv[0] << " ftn14 ftn14.root 10\n";
  81. exit(0);
  82. }
  83. inpfile = argv[1];
  84. outfile = argv[2];
  85. nevents = atoi(argv[3]);
  86. int nout=0;
  87. in.open(inpfile);
  88. if (in.fail()) bomb("cannot open input file");
  89. fi = TFile::Open(outfile, "RECREATE", "UrQMD");
  90. fi->SetCompressionLevel(9);
  91. int bufsize = 65536;
  92. int split = 99;
  93. // Create and set out TTree
  94. tr = new TTree("events","UrQMD tree", split);
  95. tr->SetAutoSave(1000000);
  96. for (unsigned int i = 0; i < UArrays::NAllUArrays; i++) {
  97. // Create arrayss
  98. arrays[i] = new TClonesArray(UArrays::uArrayTypes[i],
  99. UArrays::uArraySizes[i]);
  100. // Set branch
  101. tr->Branch(UArrays::uArrayNames[i], &arrays[i], bufsize, split);
  102. }
  103. // event loop
  104. const int bunch = 10;
  105. int events_processed=0;
  106. for (int n=0; n<nevents; n++) {
  107. if ((n%bunch)==0) cout << "event " << setw(5) << n << endl;
  108. string line;
  109. in >> dust >> dust >> version >> dust >> dust;
  110. in >> dust >> filetype >> dust >> dust >> dust >> aproj >> zproj;
  111. in >> dust >> dust >> dust >> atarg >> ztarg;
  112. in >> dust >> dust >> dust >> beta >> dust >> dust;
  113. in >> dust >> b >> bmin >> bmax >> dust >> sigma;
  114. in >> dust >> eos >> dust >> elab >> dust >> sqrts >> dust >> plab;
  115. in >> dust >> nr >> dust >> dust >> dust;
  116. in >> dust >> dust >> time >> dust >> dtime;
  117. in.ignore(777,'\n'); // ignore the rest of the line
  118. cout << "version: " << version << " sqrts: " << sqrts << " dtime: " << dtime << endl;
  119. comment.clear();
  120. // read 4 lines of options and 6 lines of params
  121. for (int i=0; i<10; i++) {
  122. getline(in,line);
  123. comment.append(line);
  124. comment.append("\n");
  125. }
  126. in.ignore(777,'\n');
  127. // Let the new UEvent appear!
  128. UEvent *ev = new ((*(arrays[UArrays::Event]))[arrays[UArrays::Event]->GetEntries()]) UEvent();
  129. ev->Clear();
  130. ev->setEventNr(nr);
  131. ev->setB(b);
  132. ev->setPhi(0);
  133. ev->setNes((int) (time/dtime));
  134. events_processed++;
  135. int step_nr=0;
  136. char pee;
  137. while (1) { // loop over time slices
  138. int mult;
  139. double step_time;
  140. pee=in.peek();
  141. if (pee=='U') break;
  142. if (pee==EOF) break;
  143. in >> mult >> step_time;
  144. cout << "Number of particles in event: " << mult << endl;
  145. in.ignore(777,'\n'); // ignore the rest of the line
  146. getline(in,line);
  147. ev->setComment(line.data());
  148. for (int i=0; i<mult; i++) {
  149. cout << "Working on particle i: " << i;
  150. double t,x,y,z,e,px,py,pz;
  151. double weight = 1.0;
  152. int ityp, iso3, ichg, status, parent, parent_decay, mate;
  153. int decay, child[2];
  154. in >> t >> x >> y >> z;
  155. in >> e >> px >> py >> pz >> dust;
  156. in >> ityp >> iso3 >> ichg >> mate >> dust >> dust;
  157. if (filetype==13) { // freeze-out coordinates
  158. in >> t >> x >> y >> z;
  159. in >> e >> px >> py >> pz;
  160. }
  161. cout << "px: " << px << " py: " << py << " pz: " << pz << endl;
  162. if (in.fail()) bomb("while reading tracks");
  163. status=parent=parent_decay=decay=child[0]=child[1]=0;
  164. cout << "I am here 1" << endl;
  165. new ((*(arrays[UArrays::Particle]))[arrays[UArrays::Particle]->GetEntries()]) UParticle(i, trapco(ityp, ichg), status, parent,
  166. parent_decay, mate-1, decay, child,
  167. px, py, pz, e, x, y, z, t, weight);
  168. cout << "I am here 2" << endl;
  169. } // for (int i=0; i<mult; i++)
  170. do in.get(c); while (c!='\n');
  171. ev->setStepNr(step_nr++);
  172. ev->setStepT(step_time);
  173. nout += tr->Fill();
  174. }
  175. if (pee==EOF) break;
  176. }
  177. in.close();
  178. cout << events_processed << " events processed\n";
  179. // create the run object
  180. string generator = "UrQMD";
  181. generator.append(version);
  182. double m = 0.938271998;
  183. double ecm = sqrts/2; // energy per nucleon in cm
  184. double pcm = sqrt(ecm*ecm-m*m); // momentum per nucleon in cm
  185. double gamma = 1.0/sqrt(1-beta*beta);
  186. double pproj = gamma*(+pcm-beta*ecm);
  187. double ptarg = gamma*(-pcm-beta*ecm);
  188. new ((*(arrays[UArrays::Run]))[arrays[UArrays::Run]->GetEntries()]) URun(generator.data(), comment.data(),
  189. aproj, zproj, pproj,
  190. atarg, ztarg, ptarg,
  191. bmin, bmax, -1, 0, 0, sigma, events_processed);
  192. nout += tr->Fill();
  193. fi->Write();
  194. fi->Close();
  195. cout << "Total bytes were written: " << nout << endl;
  196. return 0;
  197. }