UParticle.cxx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // C++ headers
  2. #include <iostream>
  3. // UNI headers
  4. #include "UParticle.h"
  5. ClassImp(UParticle);
  6. //----------------
  7. UParticle::UParticle() : TObject(),
  8. fIndex(0), fPdg(0), fStatus(0), fParent(0), fParentDecay(0),
  9. fMate(0), fDecay(0), fChild{}, fPx(0), fPy(0), fPz(0),
  10. fX(0), fY(0), fZ(0), fT(0), fWeight(0) { // Default constructor
  11. /* empty */
  12. }
  13. //----------------
  14. UParticle::UParticle(Int_t index, Int_t pdg, Int_t status,
  15. Int_t parent, Int_t parentDecay,
  16. Int_t mate, Int_t decay, Int_t child[2],
  17. Double_t px, Double_t py, Double_t pz, Double_t e,
  18. Double_t x, Double_t y, Double_t z, Double_t t,
  19. Double_t weight) : TObject() {
  20. // Standard constructor
  21. fIndex = ( (index > std::numeric_limits<unsigned short>::max() ) ?
  22. std::numeric_limits<unsigned short>::max() : (UShort_t)index );
  23. fPdg = pdg;
  24. if ( status <= std::numeric_limits<char>::min() ) {
  25. fStatus = std::numeric_limits<char>::min();
  26. }
  27. else if ( status >= std::numeric_limits<char>::max() ) {
  28. fStatus = std::numeric_limits<char>::max();
  29. }
  30. else {
  31. fStatus = (Char_t)status;
  32. }
  33. fParent = ( ( parent > std::numeric_limits<unsigned short>::max() ) ?
  34. std::numeric_limits<unsigned short>::max() : (UShort_t)parent );
  35. fParentDecay = ( ( parentDecay > std::numeric_limits<unsigned short>::max() ) ?
  36. std::numeric_limits<unsigned short>::max() : (UShort_t)parentDecay );
  37. fMate = ( (mate > std::numeric_limits<unsigned short>::max() ) ?
  38. std::numeric_limits<unsigned short>::max() : (UShort_t)mate );
  39. fDecay = ( ( TMath::Abs(decay) > std::numeric_limits<short>::max() ) ?
  40. std::numeric_limits<short>::max() : (Short_t)decay );
  41. fChild[0] = ( (child[0] > std::numeric_limits<unsigned short>::max() ) ?
  42. std::numeric_limits<unsigned short>::max() : (UShort_t)child[0] );
  43. fChild[1] = ( (child[1] > std::numeric_limits<unsigned short>::max() ) ?
  44. std::numeric_limits<unsigned short>::max() : (UShort_t)child[1] );
  45. fPx = (Float_t)px;
  46. fPy = (Float_t)py;
  47. fPz = (Float_t)pz;
  48. fX = (Float_t)x;
  49. fY = (Float_t)y;
  50. fZ = (Float_t)z;
  51. fT = (Float_t)t;
  52. fWeight = (Float_t)weight;
  53. }
  54. //----------------
  55. UParticle::UParticle(Int_t index, Int_t pdg, Int_t status,
  56. Int_t parent, Int_t parentDecay,
  57. Int_t mate, Int_t decay, Int_t child[2],
  58. TLorentzVector mom, TLorentzVector pos,
  59. Double_t weight) : TObject() {
  60. // Standard constructor
  61. fIndex = ( (index > std::numeric_limits<unsigned short>::max() ) ?
  62. std::numeric_limits<unsigned short>::max() : (UShort_t)index );
  63. fPdg = pdg;
  64. if ( status <= std::numeric_limits<char>::min() ) {
  65. fStatus = std::numeric_limits<char>::min();
  66. }
  67. else if ( status >= std::numeric_limits<char>::max() ) {
  68. fStatus = std::numeric_limits<char>::max();
  69. }
  70. else {
  71. fStatus = (Char_t)status;
  72. }
  73. fParent = ( ( parent > std::numeric_limits<unsigned short>::max() ) ?
  74. std::numeric_limits<unsigned short>::max() : (UShort_t)parent );
  75. fParentDecay = ( ( parentDecay > std::numeric_limits<unsigned short>::max() ) ?
  76. std::numeric_limits<unsigned short>::max() : (UShort_t)parentDecay );
  77. fMate = ( (mate > std::numeric_limits<unsigned short>::max() ) ?
  78. std::numeric_limits<unsigned short>::max() : (UShort_t)mate );
  79. fDecay = ( ( TMath::Abs(decay) > std::numeric_limits<short>::max() ) ?
  80. std::numeric_limits<short>::max() : (Short_t)decay );
  81. fChild[0] = ( (child[0] > std::numeric_limits<unsigned short>::max() ) ?
  82. std::numeric_limits<unsigned short>::max() : (UShort_t)child[0] );
  83. fChild[1] = ( (child[1] > std::numeric_limits<unsigned short>::max() ) ?
  84. std::numeric_limits<unsigned short>::max() : (UShort_t)child[1] );
  85. fPx = (Float_t)mom.Px();
  86. fPy = (Float_t)mom.Py();
  87. fPz = (Float_t)mom.Pz();
  88. fX = (Float_t)pos.X();
  89. fY = (Float_t)pos.Y();
  90. fZ = (Float_t)pos.Z();
  91. fT = (Float_t)pos.T();
  92. fWeight = (Float_t)weight;
  93. }
  94. //----------------
  95. UParticle::UParticle(const UParticle& right) {
  96. // Copy constructor
  97. fIndex = right.fIndex;
  98. fPdg = right.fPdg;
  99. fStatus = right.fStatus;
  100. fParent = right.fParent;
  101. fParentDecay = right.fParentDecay;
  102. fMate = right.fMate;
  103. fDecay = right.fDecay;
  104. fChild[0] = right.fChild[0];
  105. fChild[1] = right.fChild[1];
  106. fPx = right.fPx;
  107. fPy = right.fPy;
  108. fPz = right.fPz;
  109. fX = right.fX;
  110. fY = right.fY;
  111. fZ = right.fZ;
  112. fT = right.fT;
  113. fWeight = right.fWeight;
  114. }
  115. //----------------
  116. const UParticle& UParticle::operator=(const UParticle& right) {
  117. // Assignment operator
  118. if( this != &right ) {
  119. fIndex = right.fIndex;
  120. fPdg = right.fPdg;
  121. fStatus = right.fStatus;
  122. fParent = right.fParent;
  123. fParentDecay = right.fParentDecay;
  124. fMate = right.fMate;
  125. fDecay = right.fDecay;
  126. fChild[0] = right.fChild[0];
  127. fChild[1] = right.fChild[1];
  128. fPx = right.fPx;
  129. fPy = right.fPy;
  130. fPz = right.fPz;
  131. fX = right.fX;
  132. fY = right.fY;
  133. fZ = right.fZ;
  134. fT = right.fT;
  135. fWeight = right.fWeight;
  136. }
  137. return (*this);
  138. }
  139. //----------------
  140. UParticle::UParticle(const TParticle &right) {
  141. // Copy constructor from the TParticle
  142. fIndex = 0;
  143. fPdg = right.GetPdgCode();
  144. fStatus = right.GetStatusCode();
  145. fParent = right.GetFirstMother();
  146. fParentDecay = 0;
  147. fMate = 0;
  148. fDecay = 0;
  149. fChild[0] = right.GetFirstDaughter();
  150. fChild[1] = right.GetLastDaughter();
  151. fPx = right.Px();
  152. fPy = right.Py();
  153. fPz = right.Pz();
  154. //fE = right.Energy();
  155. fX = right.Vx();
  156. fY = right.Vy();
  157. fZ = right.Vz();
  158. fT = right.T();
  159. fWeight = right.GetWeight();
  160. }
  161. //----------------
  162. const UParticle& UParticle::operator=(const TParticle &right) {
  163. // Assignment operator from the TParticle
  164. fIndex = 0;
  165. fPdg = right.GetPdgCode();
  166. fStatus = right.GetStatusCode();
  167. fParent = right.GetFirstMother();
  168. fParentDecay = 0;
  169. fMate = 0;
  170. fDecay = 0;
  171. fChild[0] = right.GetFirstDaughter();
  172. fChild[1] = right.GetLastDaughter();
  173. fPx = right.Px();
  174. fPy = right.Py();
  175. fPz = right.Pz();
  176. //fE = right.Energy();
  177. fX = right.Vx();
  178. fY = right.Vy();
  179. fZ = right.Vz();
  180. fT = right.T();
  181. fWeight = right.GetWeight();
  182. return (*this);
  183. }
  184. //----------------
  185. UParticle::~UParticle() { // Destructor
  186. /* empty */
  187. }
  188. //----------------
  189. const Bool_t UParticle::operator == (const UParticle& right) const {
  190. // If equal operator
  191. return (
  192. fIndex == right.fIndex &&
  193. fPdg == right.fPdg &&
  194. fStatus == right.fStatus &&
  195. fParent == right.fParent &&
  196. fParentDecay == right.fParentDecay &&
  197. fMate == right.fMate &&
  198. fDecay == right.fDecay &&
  199. fChild[0] == right.fChild[0] &&
  200. fChild[1] == right.fChild[1] &&
  201. ((TMath::Abs((fPx-right.fPx)/fPx)<0.0001) ||
  202. (TMath::Abs(fPx)<1e-16&&TMath::Abs(right.fPx)<1e-16)) &&
  203. ((TMath::Abs((fPy-right.fPy)/fPy)<0.0001) ||
  204. (TMath::Abs(fPy)<1e-16&&TMath::Abs(right.fPy)<1e-16)) &&
  205. ((TMath::Abs((fPz-right.fPz)/fPz)<0.0001) ||
  206. (TMath::Abs(fPz)<1e-16&&TMath::Abs(right.fPz)<1e-16)) &&
  207. ((TMath::Abs((fX-right.fX)/fX)<0.0001) ||
  208. (TMath::Abs(fX)<1e-16&&TMath::Abs(right.fX)<1e-16)) &&
  209. ((TMath::Abs((fY-right.fY)/fY)<0.0001) ||
  210. (TMath::Abs(fY)<1e-16&&TMath::Abs(right.fY)<1e-16)) &&
  211. ((TMath::Abs((fZ-right.fZ)/fZ)<0.0001) ||
  212. (TMath::Abs(fZ)<1e-16&&TMath::Abs(right.fZ)<1e-16)) &&
  213. ((TMath::Abs((fT-right.fT)/fT)<0.0001) ||
  214. (TMath::Abs(fT)<1e-16&&TMath::Abs(right.fT)<1e-16)) &&
  215. ((TMath::Abs((fWeight-right.fWeight)/fWeight)<0.0001) ||
  216. (TMath::Abs(fWeight)<1e-16&&TMath::Abs(right.fWeight)<1e-16))
  217. );
  218. }
  219. //----------------
  220. void UParticle::print(Option_t* option) {
  221. // Print the data members to the standard output
  222. std::cout << "------------------------------------------------" << std::endl
  223. << "-I- Particle -I-" << std::endl
  224. << "Index : " << fIndex << std::endl
  225. << "PDG code : " << fPdg << std::endl
  226. << "Status code : " << fStatus << std::endl
  227. << "Parent index : " << fParent << std::endl
  228. << "Parent decay index : " << fParentDecay << std::endl
  229. << "Last collision partner : " << fMate << std::endl
  230. << "Decay index : " << fDecay << std::endl
  231. << "First child index : " << fChild[0] << std::endl
  232. << "Last child index : " << fChild[1] << std::endl
  233. << "Momentum (px, py, pz) (GeV) : (" << fPx << ", " << fPy << ", " << fPz << ")" << std::endl
  234. // << "Energy (GeV) : " << fE << std::endl
  235. << "Position (x, y, z) (fm) : (" << fX << ", " << fY << ", " << fZ << ")" << std::endl
  236. << "Creation time (fm) : " << fT << std::endl
  237. << "Weight : " << fWeight << std::endl
  238. << "------------------------------------------------" << std::endl;
  239. }