LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
IonizationAndScintillation.cxx
Go to the documentation of this file.
1 
7 // lar includes
13 
14 // ROOT includes
15 #include "TH1F.h"
16 #include "TH2F.h"
17 
18 // Framework includes
20 #include "art_root_io/TFileService.h"
22 
23 // C/C++ standard libraries
24 #include <cassert>
25 
26 #include "CLHEP/Units/SystemOfUnits.h"
27 #include "Geant4/G4Step.hh"
28 
29 namespace larg4 {
30 
32 
33  //......................................................................
35  detinfo::DetectorPropertiesData const& detProp,
36  CLHEP::HepRandomEngine& engine)
37  {
38  if (!gInstance) gInstance = new IonizationAndScintillation(detProp, engine);
39  return gInstance;
40  }
41 
42  //......................................................................
44  {
45  // the instance must have been created already by CreateInstance()
46  assert(gInstance);
47  return gInstance;
48  }
49 
50  //......................................................................
51  // Constructor.
53  detinfo::DetectorPropertiesData const& detProp,
54  CLHEP::HepRandomEngine& engine)
55  : fEngine{engine}
56  {
59 
60  if (fISCalculator == "Separate")
61  fISCalc = std::make_unique<larg4::ISCalculationSeparate>();
62  else if (fISCalculator == "Correlated")
63  fISCalc = std::make_unique<larg4::ISCalculationCorrelated>(detProp);
64  else if (fISCalculator == "NEST")
65  fISCalc = std::make_unique<larg4::ISCalculationNEST>(fEngine);
66  else
67  mf::LogWarning("IonizationAndScintillation") << "No ISCalculation set, this can't be good.";
68 
69  // Reset the values for the electrons, photons, and energy to 0
70  // in the calculator
71  fISCalc->Reset();
72  //set the current track and step number values to bogus so that it will run the first reset:
73  fStepNumber = -1;
74  fTrkID = -1;
75 
76  // make the histograms
78  fElectronsPerStep = tfs->make<TH1F>("electronsPerStep", ";Electrons;Steps", 500, 0., 5000.);
79  fPhotonsPerStep = tfs->make<TH1F>("photonsPerStep", ";Photons;Steps", 500, 0., 5000.);
80  fEnergyPerStep = tfs->make<TH1F>("energyPerStep", ";Energy (MeV);Steps", 100, 0., 0.5);
81  fStepSize = tfs->make<TH1F>("stepSize", ";Step Size (CLHEP::cm);Steps", 500, 0., 0.2);
82  fElectronsPerLength = tfs->make<TH1F>(
83  "electronsPerLength", ";Electrons #times 10^{3}/CLHEP::cm;Steps", 1000, 0., 1000.);
84  fPhotonsPerLength = tfs->make<TH1F>(
85  "photonsPerLength", ";Photons #times 10^{3}/CLHEP::cm;Steps", 1000, 0., 1000.);
87  tfs->make<TH1F>("electronsPerEDep", ";Electrons #times 10^{3}/MeV;Steps", 1000, 0., 1000.);
89  tfs->make<TH1F>("photonsPerEDep", ";Photons #times 10^{3}/MeV;Steps", 1000, 0., 1000.);
90 
92  tfs->make<TH2F>("electronsVsPhotons", ";Photons;Electrons", 500, 0., 5000., 500, 0., 5000.);
93  }
94 
95  //......................................................................
96  void IonizationAndScintillation::Reset(const G4Step* step)
97  {
98 
99  if (fStepNumber == step->GetTrack()->GetCurrentStepNumber() &&
100  fTrkID == step->GetTrack()->GetTrackID())
101  return;
102 
103  fStepNumber = step->GetTrack()->GetCurrentStepNumber();
104  fTrkID = step->GetTrack()->GetTrackID();
105 
106  fStep = step;
107 
108  fISCalc->Reset();
109 
110  // check the material for this step and be sure it is LAr
111  if (step->GetTrack()->GetMaterial()->GetName() != "LAr") return;
112 
113  // double check that the energy deposit is non-zero
114  // then do the calculation if it is
115  if (step->GetTotalEnergyDeposit() > 0) {
116 
117  fISCalc->CalculateIonizationAndScintillation(fStep);
118 
119  MF_LOG_DEBUG("IonizationAndScintillation")
120  << "Step Size: " << fStep->GetStepLength() / CLHEP::cm
121  << "\nEnergy: " << fISCalc->EnergyDeposit()
122  << "\nElectrons: " << fISCalc->NumberIonizationElectrons()
123  << "\nPhotons: " << fISCalc->NumberScintillationPhotons();
124 
125  G4ThreeVector totstep = fStep->GetPostStepPoint()->GetPosition();
126  totstep -= fStep->GetPreStepPoint()->GetPosition();
127 
128  // Fill the histograms
129  fStepSize->Fill(totstep.mag() / CLHEP::cm);
130  fEnergyPerStep->Fill(fISCalc->EnergyDeposit());
131  fElectronsPerStep->Fill(fISCalc->NumberIonizationElectrons());
132  fPhotonsPerStep->Fill(fISCalc->NumberScintillationPhotons());
133  fElectronsVsPhotons->Fill(fISCalc->NumberScintillationPhotons(),
134  fISCalc->NumberIonizationElectrons());
135  double const stepSize = totstep.mag() / CLHEP::cm;
136  if (stepSize > 0.0) {
137  fElectronsPerLength->Fill(fISCalc->NumberIonizationElectrons() * 1.e-3 / stepSize);
138  fPhotonsPerLength->Fill(fISCalc->NumberScintillationPhotons() * 1.e-3 / stepSize);
139  }
140  double const energyDep = fISCalc->EnergyDeposit();
141  if (energyDep) {
142  fElectronsPerEDep->Fill(fISCalc->NumberIonizationElectrons() * 1.e-3 / energyDep);
143  fPhotonsPerEDep->Fill(fISCalc->NumberScintillationPhotons() * 1.e-3 / energyDep);
144  }
145 
146  } // end if the energy deposition is non-zero
147 
148  return;
149  }
150 
151 } // namespace
Store parameters for running LArG4.
const std::string & IonAndScintCalculator() const
TH1F * fPhotonsPerEDep
histogram of photons per MeV deposited
TH1F * fElectronsPerEDep
histogram of electrons per MeV deposited
Geant4 interface.
G4Step const * fStep
pointer to the current G4 step
TH1F * fElectronsPerLength
histogram of electrons per cm
std::unique_ptr< larg4::ISCalculation > fISCalc
Interface to algorithm class for a specific calculation of ionization electrons and scintillation pho...
CLHEP::HepRandomEngine & fEngine
random engine (needed for NEST)
static IonizationAndScintillation * Instance()
TH1F * fStepSize
histogram of the step sizes
TH1F * fElectronsPerStep
histogram of electrons per step
TH1F * fPhotonsPerStep
histogram of the photons per step
Singleton to access a unified treatment of ionization and scintillation in LAr.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
#define MF_LOG_DEBUG(id)
static IonizationAndScintillation * CreateInstance(detinfo::DetectorPropertiesData const &detProp, CLHEP::HepRandomEngine &engine)
TH1F * fEnergyPerStep
histogram of the energy deposited per step
TH1F * fPhotonsPerLength
histogram of photons per cm
TH2F * fElectronsVsPhotons
histogram of electrons vs photons per step
std::string fISCalculator
name of calculator to use, NEST or Separate
static IonizationAndScintillation * gInstance
IonizationAndScintillation(detinfo::DetectorPropertiesData const &detProp, CLHEP::HepRandomEngine &engine)