IonizationAndScintillation.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file IonizationAndScintillation.cxx
3 ///
4 /// \author brebel@fnal.gov
5 ////////////////////////////////////////////////////////////////////////
6 
7 // gar includes
11 
12 // ROOT includes
13 
14 // Framework includes
15 #include "cetlib_except/exception.h"
18 #include "art_root_io/TFileService.h"
19 #include "art_root_io/TFileDirectory.h"
20 
21 // C/C++ standard libraries
22 
23 namespace gar {
24  namespace rosim {
25 
27 
28  //......................................................................
30  fhicl::ParameterSet const& pset)
31  {
32  if(!gInstance) gInstance = new IonizationAndScintillation(engine);
33 
34  gInstance->reconfigure(pset);
35 
36  return gInstance;
37  }
38 
39  //......................................................................
41  {
42  // the instance must have been created already by CreateInstance()
43  if(!gInstance)
44  throw cet::exception("IonizationAndScintillation")
45  << "instance pointer is null, that is bad";
46 
47  return gInstance;
48  }
49 
50  //......................................................................
51  // Constructor.
53  : fISCalc (nullptr)
54  , fEnergyDeposit (nullptr)
55  , fStepSize (nullptr)
56  , fElectronsPerStep (nullptr)
57  , fPhotonsPerStep (nullptr)
58  , fEnergyPerStep (nullptr)
59  , fElectronsVsPhotons(nullptr)
60  , fEngine (engine)
61  {
62 
63  //set the current track and step number values to bogus so that it will run the first reset:
64  fStepNumber = -1;
65  fTrkID = -1;
66 
67  // make the histograms
69 
70  fElectronsPerStep = tfs->make<TH1F>("electronsPerStep", ";Electrons;Steps",
71  500, 0., 5000.);
72  fPhotonsPerStep = tfs->make<TH1F>("photonsPerStep", ";Photons;Steps",
73  500, 0., 5000.);
74  fEnergyPerStep = tfs->make<TH1F>("energyPerStep", ";Energy (MeV);Steps",
75  100, 0., 0.5);
76  fStepSize = tfs->make<TH1F>("stepSize", ";Step Size (CLHEP::cm);Steps",
77  500, 0., 0.2);
78  fElectronsPerLength = tfs->make<TH1F>("electronsPerLength", ";Electrons #times 10^{3}/CLHEP::cm;Steps",
79  1000, 0., 1000.);
80  fPhotonsPerLength = tfs->make<TH1F>("photonsPerLength", ";Photons #times 10^{3}/CLHEP::cm;Steps",
81  1000, 0., 1000.);
82  fElectronsPerEDep = tfs->make<TH1F>("electronsPerEDep", ";Electrons #times 10^{3}/MeV;Steps",
83  1000, 0., 1000.);
84  fPhotonsPerEDep = tfs->make<TH1F>("photonsPerEDep", ";Photons #times 10^{3}/MeV;Steps",
85  1000, 0., 1000.);
86 
87  fElectronsVsPhotons = tfs->make<TH2F>("electronsVsPhotons", ";Photons;Electrons",
88  500, 0., 5000., 500, 0., 5000.);
89 
90  return;
91  }
92 
93  //......................................................................
95  {
96  }
97 
98  //......................................................................
100  {
101  if(fISCalc){
102  delete fISCalc;
103  fISCalc = nullptr;
104  }
105 
106  auto calcName = pset.get<std::string>("ISCalcName");
107 
108  if(calcName.compare("NEST") == 0)
110  else if(calcName.compare("Separate") == 0)
112  else
113  MF_LOG_WARNING("IonizationAndScintillation")
114  << "No ISCalculation set, this can't be good.";
115 
116  // initialize the calculator
117  fISCalc->Initialize();
118 
119  return;
120  }
121 
122  //......................................................................
124  {
125 
126  // TODO fix these lines, ie figure out how to do this with EDeps
127  // ===
128  //if(fStepNumber == step->GetTrack()->GetCurrentStepNumber() &&
129  //fTrkID == step->GetTrack()->GetTrackID())
130  //return;
131 
132  //fStepNumber = step->GetTrack()->GetCurrentStepNumber();
133  //fTrkID = step->GetTrack()->GetTrackID();
134  // ===
135 
136  fEnergyDeposit = dep;
137 
138  // reset the calculator
139  fISCalc->Reset();
140 
141  // double check that the energy deposit is non-zero
142  // then do the calculation if it is
143  if( fEnergyDeposit->Energy() > 0 ){
144 
146 
147  MF_LOG_DEBUG("IonizationAndScintillation")
148  << "\nEnergy: " << fISCalc->EnergyDeposit()
149  << "\nElectrons: " << fISCalc->NumberIonizationElectrons()
150  << "\nPhotons: " << fISCalc->NumberScintillationPhotons();
151 
152  // Fill the histograms
160 
161  } // end if the energy deposition is non-zero
162 
163  return;
164  }
165 
166  } // namespace
167  } // gar
TH1F * fPhotonsPerEDep
histogram of photons per MeV deposited
static IonizationAndScintillation * gInstance
std::string string
Definition: nybbler.cc:12
void Reset(const gar::sdp::EnergyDeposit *dep)
float const & Energy() const
Definition: EnergyDeposit.h:42
const gar::sdp::EnergyDeposit * fEnergyDeposit
reference to the current energy deposit
virtual void Initialize()=0
virtual double EnergyDeposit() const =0
IonizationAndScintillation(CLHEP::HepRandomEngine &engine)
TH1F * fPhotonsPerLength
histogram of the photons per dX
TH1F * fPhotonsPerStep
histogram of the photons per step
TH1F * fStepSize
histogram of the step sizes
TH1F * fElectronsPerStep
histogram of electrons per step
T get(std::string const &key) const
Definition: ParameterSet.h:271
virtual void Reset()=0
static IonizationAndScintillation * CreateInstance(CLHEP::HepRandomEngine &engine, fhicl::ParameterSet const &pset)
static IonizationAndScintillation * Instance()
virtual int NumberIonizationElectrons() const =0
rosim::ISCalculation * fISCalc
produced by an energy deposition
General GArSoft Utilities.
TH1F * fEnergyPerStep
histogram of the energy deposited per step
TH1F * fElectronsPerEDep
histogram of electrons per MeV deposited
#define MF_LOG_DEBUG(id)
TH1F * fElectronsPerLength
histogram of electrons per dX
TH2F * fElectronsVsPhotons
histogram of electrons vs photons per step
virtual int NumberScintillationPhotons() const =0
#define MF_LOG_WARNING(category)
virtual void CalculateIonizationAndScintillation(const gar::sdp::EnergyDeposit *dep)=0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
CLHEP::HepRandomEngine & fEngine
random engine
void reconfigure(fhicl::ParameterSet const &pset)