Facebook
From Wilk, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 278
  1. //
  2. // ********************************************************************
  3. // * License and Disclaimer                                           *
  4. // *                                                                  *
  5. // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6. // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7. // * conditions of the Geant4 Software License,  included in the file *
  8. // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9. // * include a list of copyright holders.                             *
  10. // *                                                                  *
  11. // * Neither the authors of this software system, nor their employing *
  12. // * institutes,nor the agencies providing financial support for this *
  13. // * work  make  any representation or  warranty, express or implied, *
  14. // * regarding  this  software system or assume any liability for its *
  15. // * use.  Please see the license in the file  LICENSE  and URL above *
  16. // * for the full disclaimer and the limitation of liability.         *
  17. // *                                                                  *
  18. // * This  code  implementation is the result of  the  scientific and *
  19. // * technical work of the GEANT4 collaboration.                      *
  20. // * By using,  copying,  modifying or  distributing the software (or *
  21. // * any work based  on the software)  you  agree  to acknowledge its *
  22. // * use  in  resulting  scientific  publications,  and indicate your *
  23. // * acceptance of all terms of the Geant4 Software license.          *
  24. // ********************************************************************
  25. //
  26. // Hadrontherapy advanced example for Geant4
  27. // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
  28.  
  29. #ifndef HADRONTHERAPYANALYSISMANAGER_HH
  30. #define HADRONTHERAPYANALYSISMANAGER_HH 1
  31.  
  32. #include "globals.hh"
  33.  
  34.  
  35. #ifdef G4ANALYSIS_USE_ROOT ///< If analysis is done directly with ROOT
  36. #include "TROOT.h"
  37. #include "TFile.h"
  38. #include "TNtuple.h"
  39. #include "TH1F.h"
  40. #endif
  41. /**
  42.  * Messenger class for analysis-settings for HadronTherapyAnalysisManager
  43.  */
  44. class HadrontherapyAnalysisFileMessenger;
  45.  
  46. /**
  47.  * A class for connecting the simulation to an analysis package.
  48.  */
  49. class HadrontherapyAnalysisManager
  50. {
  51. private:
  52.   /**
  53.    * Analysis manager is a singleton object (there is only one instance).
  54.    * The pointer to this object is available through the use of the method GetInstance();
  55.    *
  56.    * @see GetInstance
  57.    */
  58.   HadrontherapyAnalysisManager();
  59.        
  60. public:
  61.   ~HadrontherapyAnalysisManager();
  62.        
  63.   /**
  64.    * Get the pointer to the analysis manager.
  65.    */
  66.   static HadrontherapyAnalysisManager* GetInstance();
  67.  
  68. #ifdef G4ANALYSIS_USE_ROOT
  69.   /**
  70.    * Clear analysis manager heap.
  71.    */
  72.   void Clear();
  73.   /**
  74.    * Check if TFile is there!
  75.    */
  76.   G4bool IsTheTFile();
  77.   /**
  78.    * Book the histograms and ntuples in an AIDA or ROOT file.
  79.    */
  80.   void book();
  81.   /**
  82.    * Set name for the analysis file .root (used by macro)
  83.    */
  84.   void SetAnalysisFileName(G4String);
  85.        
  86.   /**
  87.    * Fill the ntuple with the energy deposit in the phantom
  88.    */
  89.   void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId,
  90.                          G4double energyDeposit);
  91.        
  92.   void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom
  93.        
  94.   void SecondaryProtonEnergyDeposit(G4int slice, G4double energy);
  95.   ///< Fill 1D histogram with the energy deposit of secondary protons
  96.        
  97.   void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy);
  98.   ///< Fill 1D histogram with the energy deposit of secondary neutrons
  99.        
  100.   void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy);
  101.   ///< Fill 1D histogram with the energy deposit of secondary alpha particles
  102.        
  103.   void SecondaryGammaEnergyDeposit(G4int slice, G4double energy);
  104.   ///< Fill 1D histogram with the energy deposit of secondary gamma
  105.        
  106.   void SecondaryElectronEnergyDeposit(G4int slice, G4double energy);
  107.   ///< Fill 1D histogram with the energy deposit of secondary electrons
  108.        
  109.   void SecondaryTritonEnergyDeposit(G4int slice, G4double energy);
  110.   ///< Fill 1D histogram with the energy deposit of secondary tritons
  111.        
  112.   void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy);
  113.   ///< Fill 1D histogram with the energy deposit of secondary deuterons
  114.        
  115.   void SecondaryPionEnergyDeposit(G4int slice, G4double energy);
  116.   ///< Fill 1D histogram with the energy deposit of secondary pions
  117.        
  118.   void electronEnergyDistribution(G4double secondaryParticleKineticEnergy);
  119.   ///< Energy distribution of secondary electrons originated in the phantom
  120.        
  121.   void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy);
  122.   ///< Energy distribution of secondary gamma originated in the phantom
  123.        
  124.   void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy);
  125.   ///< Energy distribution of secondary deuterons originated in the phantom
  126.        
  127.   void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy);
  128.   ///< Energy distribution of secondary tritons originated in the phantom
  129.        
  130.   void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy);
  131.   ///< Energy distribution of secondary alpha originated in the phantom
  132.        
  133.   void heliumEnergy(G4double secondaryParticleKineticEnergy);
  134.   ///< Energy distribution of the helium (He3 and alpha) particles after the phantom
  135.        
  136.   void hydrogenEnergy(G4double secondaryParticleKineticEnergy);
  137.   ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom
  138.        
  139.   //Kinetic energy by voxel, mass number A and atomic number Z.
  140.   void FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy);
  141.        
  142.   //Kinetic energy by voxel, mass number A and atomic number Z of only primary particles
  143.   void FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy);
  144.        
  145.   ///< Energy by voxel, mass number A and atomic number Z.
  146.   void FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence);
  147.        
  148.   void FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ);
  149.   ///< Energy ntuple
  150.        
  151.  // void FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD);
  152.   ///< let ntuple
  153.   void FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letD);
  154.   void genericIonInformation(G4int, G4double, G4int, G4double);
  155.        
  156.   void ThintargetBeamDisp(G4double,G4double);
  157.        
  158.   void startNewEvent();
  159.   ///< Tell the analysis manager that a new event is starting
  160.        
  161.   void setGeometryMetaData(G4double, G4double, G4double);
  162.   ///< from the detector construction information about the geometry can be written as metadata
  163.        
  164.   void setBeamMetaData(G4double, G4double);
  165.   ///< metadata about the beam can be written this way
  166.        
  167.   void flush();
  168.   ///< Close the .hbk file with the histograms and the ntuples
  169. private:
  170.   TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) {
  171.     TH1F *histo = new TH1F(name, title, bins, xmin, xmax);
  172.     histo->SetLineWidth(2);
  173.     return histo;
  174.   }
  175.        
  176. private:
  177. #endif
  178.   static HadrontherapyAnalysisManager* instance;
  179.   HadrontherapyAnalysisFileMessenger* fMess;
  180. #ifdef G4ANALYSIS_USE_ROOT
  181.   G4String analysisFileName;
  182.   TFile *theTFile;
  183.   TH1F *histo1;
  184.   TH1F *histo2;
  185.   TH1F *histo3;
  186.   TH1F *histo4;
  187.   TH1F *histo5;
  188.   TH1F *histo6;
  189.   TH1F *histo7;
  190.   TH1F *histo8;
  191.   TH1F *histo9;
  192.   TH1F *histo10;
  193.   TH1F *histo11;
  194.   TH1F *histo12;
  195.   TH1F *histo13;
  196.   TH1F *histo14;
  197.   TH1F *histo15;
  198.   TH1F *histo16;
  199.        
  200.   TNtuple *kinFragNtuple;
  201.   TNtuple *kineticEnergyPrimaryNtuple;
  202.  
  203.   // ntuple containing the fluence of all the particle in any voxel
  204.   TNtuple *doseFragNtuple;
  205.  
  206.   // ntuple containing the fluence of all the particle in any voxel
  207.   TNtuple *fluenceFragNtuple;
  208.        
  209.   // ntuple containing the fluence of all the particle in any voxel
  210.   TNtuple *letFragNtuple;
  211.  
  212.   TNtuple *theROOTNtuple;
  213.   TNtuple *theROOTIonTuple;
  214.   TNtuple *fragmentNtuple; // fragments
  215.   TNtuple *metaData;
  216.   G4long eventCounter;      // Simulation metadata
  217.   G4double detectorDistance;
  218.   G4double phantomDepth;
  219.   G4double beamEnergy;
  220.   G4double energyError;
  221.   G4double phantomCenterDistance;
  222. #endif
  223. };
  224. #endif
  225.  
  226.  
  227.  
  228.