urqmd2u.cpp 6.5 KB

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