UEvent.cxx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include <iostream>
  2. using namespace std;
  3. #include "TObject.h"
  4. #include "TString.h"
  5. #include "TClonesArray.h"
  6. #include "UParticle.h"
  7. #include "UEvent.h"
  8. //____________________________________________________________________
  9. //
  10. // UEvent
  11. //
  12. // Class for event description. Contains the particle array
  13. //
  14. //--------------------------------------------------------------------
  15. UEvent::UEvent()
  16. {
  17. // Default constructor
  18. fEventNr = 0;
  19. fB = fPhi = 0.;
  20. fNes = 1;
  21. fStepNr = 0;
  22. fStepT = 0.;
  23. fNpa = 0;
  24. fComment = "";
  25. fName = "Unigen";
  26. fParticles = new TClonesArray("UParticle", 100);
  27. }
  28. //--------------------------------------------------------------------
  29. //--------------------------------------------------------------------
  30. UEvent::UEvent(const UEvent& right)
  31. {
  32. // Copy constructor
  33. fEventNr = right.fEventNr;
  34. fB = right.fB;
  35. fPhi = right.fPhi;
  36. fNes = right.fNes;
  37. fStepNr = right.fStepNr;
  38. fStepT = right.fStepT;
  39. fComment = right.fComment;
  40. fNpa = right.fNpa;
  41. fName = right.fName;
  42. fParticles = new TClonesArray("UParticle", 100);
  43. UParticle* p;
  44. for(Int_t i = 0; i < fNpa; i++) {
  45. p = (UParticle*) right.fParticles->At(i);
  46. new ((*fParticles)[i]) UParticle(*p);
  47. }
  48. }
  49. //--------------------------------------------------------------------
  50. //--------------------------------------------------------------------
  51. UEvent::~UEvent()
  52. {
  53. // Destructor
  54. Clear();
  55. delete fParticles;
  56. }
  57. //--------------------------------------------------------------------
  58. //--------------------------------------------------------------------
  59. void UEvent::Print(Option_t* option)
  60. {
  61. // Print data members to the standard output
  62. cout << "---------------------------------------------" << endl
  63. << "-I- Event -I-" << endl
  64. << "Event number : " << fEventNr << endl
  65. << "Impact parameter (fm) : " << fB << endl
  66. << "Reaction plane angle (rad) : " << fPhi << endl
  67. << "Number of time steps : " << fNes << endl
  68. << "Time step number : " << fStepNr << endl
  69. << "Time of the time step (fm) : " << fStepT << endl
  70. << "Number of particles : " << fNpa << endl
  71. << "Comment :\n" << fComment << endl;
  72. TString opt = option;
  73. if(opt.Contains("all")) {
  74. UParticle* particle;
  75. for(Int_t iPa = 0; iPa < fNpa; iPa++) {
  76. particle = (UParticle*) fParticles->At(iPa);
  77. particle->Print(option);
  78. }
  79. }
  80. cout << "---------------------------------------------" << endl;
  81. }
  82. //--------------------------------------------------------------------
  83. //--------------------------------------------------------------------
  84. UParticle* UEvent::GetParticle(Int_t index) const
  85. {
  86. // Get pointer to the particle.
  87. // index - index of the particle
  88. if(index < 0) {
  89. return NULL;
  90. }
  91. if(index >= fNpa) {
  92. return NULL;
  93. }
  94. return ((UParticle*) fParticles->At(index));
  95. }
  96. //--------------------------------------------------------------------
  97. //--------------------------------------------------------------------
  98. void UEvent::AddParticle(Int_t index, Int_t pdg, Int_t status,
  99. Int_t parent, Int_t parentDecay,
  100. Int_t mate, Int_t decay, Int_t child[2],
  101. Double_t px, Double_t py, Double_t pz, Double_t e,
  102. Double_t x, Double_t y, Double_t z, Double_t t,
  103. Double_t weight)
  104. {
  105. // Add particle to the array
  106. new ((*fParticles)[fNpa]) UParticle(index, pdg, status, parent,
  107. parentDecay, mate, decay, child,
  108. px, py, pz, e, x, y, z, t, weight);
  109. fNpa += 1;
  110. }
  111. //--------------------------------------------------------------------
  112. //--------------------------------------------------------------------
  113. void UEvent::AddParticle(Int_t index, Int_t pdg, Int_t status,
  114. Int_t parent, Int_t parentDecay,
  115. Int_t mate, Int_t decay, Int_t child[2],
  116. TLorentzVector mom, TLorentzVector pos,
  117. Double_t weight)
  118. {
  119. // Add particle to the array
  120. new ((*fParticles)[fNpa]) UParticle(index, pdg, status, parent,
  121. parentDecay, mate, decay, child,
  122. mom, pos, weight);
  123. fNpa += 1;
  124. }
  125. //--------------------------------------------------------------------
  126. //--------------------------------------------------------------------
  127. void UEvent::AddParticle(const UParticle& particle)
  128. {
  129. // Add particle to the array
  130. new ((*fParticles)[fNpa]) UParticle(particle);
  131. fNpa += 1;
  132. }
  133. //--------------------------------------------------------------------
  134. UEvent UEvent::operator =(const UEvent& right) {
  135. if(this!=&right){
  136. fEventNr = right.fEventNr;
  137. fB = right.fB;
  138. fPhi = right.fPhi;
  139. fNes = right.fNes;
  140. fStepNr = right.fStepNr;
  141. fStepT = right.fStepT;
  142. fComment = right.fComment;
  143. fNpa = right.fNpa;
  144. fName = right.fName;
  145. fParticles->Clear();
  146. UParticle* p;
  147. for(Int_t i = 0; i < fNpa; i++) {
  148. p = (UParticle*) right.fParticles->At(i);
  149. new ((*fParticles)[i]) UParticle(*p);
  150. }
  151. }
  152. return *this;
  153. }
  154. //--------------------------------------------------------------------
  155. //--------------------------------------------------------------------
  156. void UEvent::SetParameters(Int_t eventNr, Double_t b, Double_t phi, Int_t nes,
  157. Int_t stepNr, Double_t stepT, const char* comment)
  158. {
  159. // Set the event parameters
  160. fEventNr = eventNr;
  161. fB = b;
  162. fPhi = phi;
  163. fNes = nes;
  164. fStepNr = stepNr;
  165. fStepT = stepT;
  166. fComment = comment;
  167. }
  168. //--------------------------------------------------------------------
  169. //--------------------------------------------------------------------
  170. void UEvent::Clear()
  171. {
  172. // Remove the particles from the array and reset counter
  173. fParticles->Clear();
  174. fNpa = 0;
  175. }
  176. //--------------------------------------------------------------------
  177. //--------------------------------------------------------------------
  178. void UEvent::RemoveAt(Int_t i)
  179. {
  180. // Remove one particle from the array.
  181. // i - index of the particle.
  182. // Array is automaticaly compressed afterwards, mind the indexing
  183. fParticles->RemoveAt(i);
  184. fParticles->Compress();
  185. }
  186. //--------------------------------------------------------------------
  187. ClassImp(UEvent);