TShieldCallbacks.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // -------------------------------------------------------------------------
  2. // ----- TShield source file -----
  3. // ----- Created by A. Timofeev -----
  4. // -------------------------------------------------------------------------
  5. #include "TShield.h"
  6. double TShield::GeoDistCallback(double x, double y, double z, double vx, double vy, double vz) {
  7. TShield *fShield = TShield::Instance();
  8. if (fShield->fGeometry != 0)
  9. return fShield->FindBoundary(x, y, z, vx, vy, vz);
  10. else {
  11. printf("TShield FATAL ERROR: TGeoManager not set\n");
  12. return -1;
  13. }
  14. }
  15. int TShield::GeoNextCallback(double x, double y, double z, double vx, double vy, double vz) {
  16. TShield *fShield = TShield::Instance();
  17. if (fShield->fGeometry != 0)
  18. return fShield->GetNextVolume(x, y, z, vx, vy, vz);
  19. else {
  20. printf("TShield FATAL ERROR: TGeoManager not set\n");
  21. return -1;
  22. }
  23. }
  24. void TShield::TreeCallback(shield_tree_node *node) {
  25. // anyway, all particles are always registered in the tree
  26. TShield::Instance()->AddTreeParticle(node); //Update fCurrentParticle and fill fTree
  27. switch (node->event) {
  28. case EVENT_FLYOUT:
  29. TShield::Instance()->AddFliedOutParticle(node);
  30. break;
  31. case EVENT_ABSORPTION:
  32. TShield::Instance()->AddAbsorbedParticle(node);
  33. break;
  34. default:
  35. break;
  36. }
  37. }
  38. void TShield::InitCallbacks() {
  39. shield_set_tree_callback(&TShield::TreeCallback);
  40. // shield_set_gcurzl_callback(&TShield::GeoDistCallback); //Disabled now
  41. shield_set_gnextz_callback(&TShield::GeoNextCallback);
  42. }
  43. void TShield::AddFliedOutParticle(shield_tree_node *node) {
  44. if (ParticlesNumFlyOut <= ParticlesNumFlyOutMax) {
  45. TClonesArray &a = *fParticlesFlyOut;
  46. new(a[ParticlesNumFlyOut]) TParticle(*fCurrentParticle);
  47. ParticlesNumFlyOut ++;
  48. } else {
  49. printf("TShield ERROR: TClonesArray fParticlesFlyOut overfull\n");
  50. }
  51. }
  52. void TShield::AddAbsorbedParticle(shield_tree_node *node) {
  53. if (ParticlesNumAbsorbed <= ParticlesNumAbsorbedMax) {
  54. TClonesArray &a = *fParticlesAbsorbed;
  55. new(a[ParticlesNumAbsorbed]) TParticle(*fCurrentParticle);
  56. ParticlesNumAbsorbed ++;
  57. } else {
  58. printf("TShield ERROR: TClonesArray fParticlesAbsorbed overfull\n");
  59. }
  60. }
  61. void TShield::AddTreeParticle(shield_tree_node *node) {
  62. new (fCurrentParticle) TParticle(node->pdg, node->event, 0, 0, 0, 0,
  63. node->px_z, node->py_z, node->pz_z, node->tz + node->weight,
  64. node->xz, node->yz, node->zz, 0);
  65. fTree->Fill();
  66. }
  67. double TShield::FindBoundary(double x, double y, double z, double vx, double vy, double vz) {
  68. //TGeoNode *node = fGeometry->FindNode(x, y, z);
  69. return 0; //line 45: Disabled now
  70. }
  71. int TShield::GetNextVolume(double x, double y, double z, double vx, double vy, double vz) {
  72. shield_clean_geometry();
  73. Geant4ShieldData geometryData = getDataAtPoint(fGeometry, x, y, z, vx, vy, vz);
  74. #ifdef _DEBUG
  75. printf("TShield::GetNextVolume(%f,%f,%f,%f,%f,%f);\n", x, y, z, vx, vy, vz);
  76. tgeanttoshield::printGeant4ShieldData(geometryData);
  77. #endif
  78. bool isOnlyOuterVacuum = true;
  79. for (UInt_t i = 0; i < geometryData.size(); i++) {
  80. int countBodies = geometryData.at(i).bodyVector.size();
  81. // at "23.2.4 Class template vector" says, that elements of a vector are stored contiguously.
  82. int *zones = &(geometryData.at(i).zoneVector[0]);
  83. SGeoBody *bodies = &(geometryData.at(i).bodyVector[0]);
  84. if (shield_add_zone(countBodies, zones, bodies, geometryData.at(i).medium) == -1) {
  85. printf("An error was accured");
  86. }
  87. isOnlyOuterVacuum = isOnlyOuterVacuum && (geometryData.at(i).medium.nType == 0);
  88. }
  89. shield_init_medium();
  90. shield_init_geometry();
  91. return (isOnlyOuterVacuum) ? 0 : 1;
  92. }