All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IonizationAndScintillation.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file IonizationAndScintillation.cxx
3 ///
4 /// \author brebel@fnal.gov
5 ////////////////////////////////////////////////////////////////////////
6 
7 // lar includes
13 
14 // ROOT includes
15 #include "TH1F.h"
16 #include "TH2F.h"
17 
18 // Framework includes
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "art_root_io/TFileService.h"
21 #include "messagefacility/MessageLogger/MessageLogger.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  //......................................................................
36  CLHEP::HepRandomEngine& engine)
37  {
38  if (!gInstance) gInstance = new IonizationAndScintillation(detProp, engine);
39  return gInstance;
40  }
41 
42  //......................................................................
45  {
46  // the instance must have been created already by CreateInstance()
47  assert(gInstance);
48  return gInstance;
49  }
50 
51  //......................................................................
52  // Constructor.
55  CLHEP::HepRandomEngine& engine)
56  : fEngine{engine}
57  {
58  art::ServiceHandle<sim::LArG4Parameters const> lgp;
59  fISCalculator = lgp->IonAndScintCalculator();
60 
61  if (fISCalculator == "Separate")
62  fISCalc = std::make_unique<larg4::ISCalculationSeparate>();
63  else if (fISCalculator == "Correlated")
64  fISCalc = std::make_unique<larg4::ISCalculationCorrelated>(detProp);
65  else if (fISCalculator == "NEST")
66  fISCalc = std::make_unique<larg4::ISCalculationNEST>(fEngine);
67  else
68  mf::LogWarning("IonizationAndScintillation") << "No ISCalculation set, this can't be good.";
69 
70  // Reset the values for the electrons, photons, and energy to 0
71  // in the calculator
72  fISCalc->Reset();
73  //set the current track and step number values to bogus so that it will run the first reset:
74  fStepNumber = -1;
75  fTrkID = -1;
76 
77  // make the histograms
78  art::ServiceHandle<art::TFileService const> tfs;
79  fElectronsPerStep = tfs->make<TH1F>("electronsPerStep", ";Electrons;Steps", 500, 0., 5000.);
80  fPhotonsPerStep = tfs->make<TH1F>("photonsPerStep", ";Photons;Steps", 500, 0., 5000.);
81  fEnergyPerStep = tfs->make<TH1F>("energyPerStep", ";Energy (MeV);Steps", 100, 0., 0.5);
82  fStepSize = tfs->make<TH1F>("stepSize", ";Step Size (CLHEP::cm);Steps", 500, 0., 0.2);
83  fElectronsPerLength = tfs->make<TH1F>(
84  "electronsPerLength", ";Electrons #times 10^{3}/CLHEP::cm;Steps", 1000, 0., 1000.);
85  fPhotonsPerLength = tfs->make<TH1F>(
86  "photonsPerLength", ";Photons #times 10^{3}/CLHEP::cm;Steps", 1000, 0., 1000.);
87  fElectronsPerEDep =
88  tfs->make<TH1F>("electronsPerEDep", ";Electrons #times 10^{3}/MeV;Steps", 1000, 0., 1000.);
89  fPhotonsPerEDep =
90  tfs->make<TH1F>("photonsPerEDep", ";Photons #times 10^{3}/MeV;Steps", 1000, 0., 1000.);
91 
92  fElectronsVsPhotons =
93  tfs->make<TH2F>("electronsVsPhotons", ";Photons;Electrons", 500, 0., 5000., 500, 0., 5000.);
94  }
95 
96  //......................................................................
97  void
99  {
100 
101  if (fStepNumber == step->GetTrack()->GetCurrentStepNumber() &&
102  fTrkID == step->GetTrack()->GetTrackID())
103  return;
104 
105  fStepNumber = step->GetTrack()->GetCurrentStepNumber();
106  fTrkID = step->GetTrack()->GetTrackID();
107 
108  fStep = step;
109 
110  fISCalc->Reset();
111 
112  // check the material for this step and be sure it is LAr
113  if (step->GetTrack()->GetMaterial()->GetName() != "LAr") return;
114 
115  // double check that the energy deposit is non-zero
116  // then do the calculation if it is
117  if (step->GetTotalEnergyDeposit() > 0) {
118 
119  fISCalc->CalculateIonizationAndScintillation(fStep);
120 
121  MF_LOG_DEBUG("IonizationAndScintillation")
122  << "Step Size: " << fStep->GetStepLength() / CLHEP::cm
123  << "\nEnergy: " << fISCalc->EnergyDeposit()
124  << "\nElectrons: " << fISCalc->NumberIonizationElectrons()
125  << "\nPhotons: " << fISCalc->NumberScintillationPhotons();
126 
127  G4ThreeVector totstep = fStep->GetPostStepPoint()->GetPosition();
128  totstep -= fStep->GetPreStepPoint()->GetPosition();
129 
130  // Fill the histograms
131  fStepSize->Fill(totstep.mag() / CLHEP::cm);
132  fEnergyPerStep->Fill(fISCalc->EnergyDeposit());
133  fElectronsPerStep->Fill(fISCalc->NumberIonizationElectrons());
134  fPhotonsPerStep->Fill(fISCalc->NumberScintillationPhotons());
135  fElectronsVsPhotons->Fill(fISCalc->NumberScintillationPhotons(),
136  fISCalc->NumberIonizationElectrons());
137  double const stepSize = totstep.mag() / CLHEP::cm;
138  if (stepSize > 0.0) {
139  fElectronsPerLength->Fill(fISCalc->NumberIonizationElectrons() * 1.e-3 / stepSize);
140  fPhotonsPerLength->Fill(fISCalc->NumberScintillationPhotons() * 1.e-3 / stepSize);
141  }
142  double const energyDep = fISCalc->EnergyDeposit();
143  if (energyDep) {
144  fElectronsPerEDep->Fill(fISCalc->NumberIonizationElectrons() * 1.e-3 / energyDep);
145  fPhotonsPerEDep->Fill(fISCalc->NumberScintillationPhotons() * 1.e-3 / energyDep);
146  }
147 
148  } // end if the energy deposition is non-zero
149 
150  return;
151  }
152 
153 } // namespace
Store parameters for running LArG4.
TH1F * fPhotonsPerEDep
histogram of photons per MeV deposited
TH1F * fElectronsPerEDep
histogram of electrons per MeV deposited
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this,"HepJamesRandom","ISCalcAlg", pset,"SeedISCalcAlg"))
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...
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.
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
art::ServiceHandle< art::TFileService > tfs
TH2F * fElectronsVsPhotons
histogram of electrons vs photons per step
auto const detProp
static IonizationAndScintillation * gInstance
IonizationAndScintillation(detinfo::DetectorPropertiesData const &detProp, CLHEP::HepRandomEngine &engine)