TShield.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // -------------------------------------------------------------------------
  2. // ----- TShield source file -----
  3. // ----- Created by A. Timofeev -----
  4. // -------------------------------------------------------------------------
  5. #include "TShield.h"
  6. // class TShield implementation
  7. TShield *TShield::fInstance = 0;
  8. //______________________________________________________________________________
  9. TShield::TShieldClean::~TShieldClean() {
  10. // delete the unique copy of TShield
  11. // if exists
  12. if (TShield::fInstance)
  13. delete TShield::fInstance;
  14. }
  15. //______________________________________________________________________________
  16. ClassImp(TShield)
  17. //______________________________________________________________________________
  18. TShield::TShield(bool clean, int FlyOutMax, int AbsorbedMax):
  19. fGeometry(nullptr), fParticlesFlyOut(nullptr), fParticlesAbsorbed(nullptr),
  20. ParticlesNumFlyOutMax(FlyOutMax), ParticlesNumAbsorbedMax(AbsorbedMax),
  21. clearAtStart(clean), fTree(nullptr), fCurrentParticle(nullptr) {
  22. // Check if another instance of TShield already exists
  23. if (fInstance) {
  24. Fatal("TShield", "FATAL ERROR: Another instance of TShield class already exists");
  25. }
  26. fInstance = this;
  27. // create static cleaner
  28. static TShieldClean cleaner;
  29. SetAutoSeed();
  30. // Create arrays for particles storage
  31. fParticlesFlyOut = new TClonesArray("TParticle", ParticlesNumFlyOutMax);
  32. fParticlesAbsorbed = new TClonesArray("TParticle", ParticlesNumAbsorbedMax);
  33. fGeometry = 0;
  34. // init the random generator
  35. srand(time(0));
  36. // init callbacks for tree generation and geometry
  37. InitCallbacks();
  38. void *t = 0;
  39. fTree = new TTree("TShieldTree", "Particles from TShield");
  40. // fTree->Branch("particle", "TParticle", &fCurrentParticle); //Don't work, undefined symbol: _ZTI9TParticle
  41. TBranch *branch = fTree->Branch("Particle", "TParticle", &(t), 32000, 0);
  42. branch->SetAddress(&fCurrentParticle);
  43. fCurrentParticle = new TParticle();
  44. // Setting all default
  45. shield_set_defaults();
  46. ClearArrays();
  47. }
  48. TShield *TShield::Instance() {
  49. return fInstance ? fInstance : new TShield();
  50. }
  51. //______________________________________________________________________________
  52. TShield::~TShield() {
  53. // delete TClonesArray's
  54. delete fParticlesFlyOut;
  55. delete fParticlesAbsorbed;
  56. delete fTree;
  57. delete fCurrentParticle;
  58. // if deleted, clear the instance
  59. TShield::fInstance = 0;
  60. // useful if needed to create a new instance of TShield in future
  61. // actually TShield object should be automatically cleaned
  62. // but user can also delete it manually
  63. }
  64. //______________________________________________________________________________
  65. void TShield::GenerateEvent() {
  66. // Clean particles arrays
  67. if(clearAtStart){
  68. ClearArrays();
  69. }
  70. shield_clean_geometry();
  71. shield_run();
  72. }
  73. //______________________________________________________________________________
  74. void TShield::ClearArrays() {
  75. // Clean particles arrays
  76. fParticlesFlyOut->Clear();
  77. fParticlesAbsorbed->Clear();
  78. ParticlesNumFlyOut = 0;
  79. ParticlesNumAbsorbed = 0;
  80. fTree->Clear();
  81. }
  82. //______________________________________________________________________________
  83. void TShield::SetGeometry(TGeoManager *geom) {
  84. fGeometry = geom;
  85. }
  86. //______________________________________________________________________________
  87. void TShield::PrintGeometry() {
  88. printGeometry(fGeometry);
  89. }
  90. //______________________________________________________________________________
  91. TGeoManager *TShield::GetGeometry() {
  92. return fGeometry;
  93. }