LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArSimChannelAna_module.cc
Go to the documentation of this file.
1 //
3 // \file LArSimChannelAna_module.cc
4 //
5 // \author dmckee@phys.ksu.edu
6 //
7 // \brief Build some histograms based on the som::SimChannels created
8 // \brief by LArVoxelReadout
10 // C++ std library includes
11 #include <string>
12 
13 // Framework includes
19 #include "art_root_io/TFileService.h"
20 #include "fhiclcpp/ParameterSet.h"
21 
22 // Root Includes
23 #include "TH1.h"
24 
25 // LArSoft includes
30 
32 namespace larg {
33 
36  public:
37  explicit LArSimChannelAna(fhicl::ParameterSet const& pset);
38 
39  private:
40  void analyze(const art::Event& evt) override;
41 
42  // initialize the histograms
43  //
44  // Can't be done in Begin job because I want to use LArProperties
45  // which used the database, so I test and run on each
46  // event. Wasteful and silly, but at least it *works*.
47  void ensureHists(unsigned int const nTimeSamples);
48 
49  std::string fLArG4ModuleLabel;
50 
51  // Flag for initialization done, because we set up histograms the
52  // first time through beginRun() so that we can use the
53  // database...
54  bool initDone;
55 
56  TH1D* fChargeXpos;
57  TH1D* fChargeYpos;
58  TH1D* fChargeZpos;
59 
60  TH1D* fTDC;
61 
64 
65  TH1D* fElectrons;
66  TH1D* fEnergy;
67 
70 
73 
74  }; // class LArSimChannelAna
75 
76  //-------------------------------------------------
78  : EDAnalyzer(pset)
79  , fLArG4ModuleLabel{pset.get<std::string>("LArGeantModuleLabel")}
80  , initDone(false)
81  , fChargeXpos()
82  , fChargeYpos()
83  , fChargeZpos()
84  , fTDC()
85  , fTDCsPerChannel()
86  , fIDEsPerChannel()
87  , fElectrons()
88  , fEnergy()
90  , fEnergyPerTDC()
92  , fEnergyPerIDE()
93  {}
94 
95  //-------------------------------------------------
96  void LArSimChannelAna::ensureHists(unsigned int const nTimeSamples)
97  {
98  if (initDone) return; // Bail if we've already done this.
99  initDone = true; // Insure that we bail later on
100 
101  // get access to the TFile service
103  // geometry data.
105 
106  // assumes all TPCs are the same
107  auto const& tpc = geom->TPC();
108  double width = 2 * tpc.HalfWidth();
109  double halfHeight = tpc.HalfHeight();
110  double length = tpc.Length();
111 
112  // Assumes microboone dimensions. Ideally we'd fix this later...
113  fChargeXpos =
114  tfs->make<TH1D>("hChargeXpos", "X charge depositions;X (cm);Events", 101, 0.0, width);
115  fChargeYpos = tfs->make<TH1D>(
116  "hChargeYpos", "Y charge depositions;Y (cm);Events", 101, -halfHeight, halfHeight);
117  fChargeZpos =
118  tfs->make<TH1D>("hChargeZpos", "Z charge depositions;Z (cm);Events", 101, 0.0, length);
119  fTDC = tfs->make<TH1D>("hTDC", "Active TDC;TDCs;Events;", nTimeSamples, 0, nTimeSamples);
120  fTDCsPerChannel = tfs->make<TH1D>(
121  "hTDCsPerChannel", "TDCs per channel entry;# TDCs;Events", 128, 0, nTimeSamples);
123  tfs->make<TH1D>("hIDEsPerChannel", "IDE per channel entry;# IDEs;Events", 100, 0, 20000);
124  fElectrons =
125  tfs->make<TH1D>("hElectrons", "Electrons per channel;Electrons;Events", 100, 0, 2e7);
126  fEnergy = tfs->make<TH1D>("hEnergy", "Energy per channel;energy;Events", 100, 0, 2500);
128  tfs->make<TH1D>("hElectronsPerIDE", "Electrons per IDE;Electrons;Events", 100, 0, 10000);
129  fEnergyPerIDE = tfs->make<TH1D>("hEnergyPerIDE", "Energy per IDE;energy;Events", 100, 0, 50);
131  tfs->make<TH1D>("hElectronsPerTDC", "Electrons per TDC;Electrons;Events", 100, 0, 10000);
132  fEnergyPerTDC = tfs->make<TH1D>("hEnergyPerTDC", "Energy per YDC;energy;Events", 100, 0, 50);
133  }
134 
135  //-------------------------------------------------
137  {
138  if (evt.isRealData()) {
139  throw cet::exception("LArSimChannelAna") << "Not for use on Data yet...\n";
140  }
141 
142  auto const detProp =
144  ensureHists(detProp.NumberTimeSamples());
145 
147 
148  auto const& scVec = *evt.getValidHandle<std::vector<sim::SimChannel>>(fLArG4ModuleLabel);
149 
150  //++++++++++
151  // Loop over the Chnnels and fill histograms
152  //++++++++++
153  unsigned int totalIDEs = 0;
154  double totalElectrons = 0;
155  double totalEnergy = 0;
156  for (const auto& sc : scVec) {
157  const auto& tdcidemap = sc.TDCIDEMap();
158  fTDCsPerChannel->Fill(tdcidemap.size());
159 
160  for (auto const& [tdc, ideVec] : tdcidemap) {
161  totalIDEs += ideVec.size();
162  double tdcElectrons = 0;
163  double tdcEnergy = 0;
164 
165  fTDC->Fill(tdc);
166 
167  for (const auto& ide : ideVec) {
168  totalElectrons += ide.numElectrons;
169  totalEnergy += ide.energy;
170  tdcElectrons += ide.numElectrons;
171  tdcEnergy += ide.energy;
172 
173  fChargeXpos->Fill(ide.x);
174  fChargeYpos->Fill(ide.y);
175  fChargeZpos->Fill(ide.z);
176  fElectronsPerIDE->Fill(ide.numElectrons);
177  fEnergyPerIDE->Fill(ide.energy);
178  }
179  fElectronsPerTDC->Fill(tdcElectrons);
180  fEnergyPerTDC->Fill(tdcEnergy);
181  }
182  }
183  fIDEsPerChannel->Fill(totalIDEs);
184  fElectrons->Fill(totalElectrons);
185  fEnergy->Fill(totalEnergy);
186  } //end analyze method
187 
189 
190 } // end of hit namespace
TH1D * fTDCsPerChannel
Number of TDCs with activity.
Detector simulation of raw signals on wires.
bool isRealData() const
Definition: Event.cc:53
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
TH1D * fElectrons
Electrons in the whole channel entry.
TH1D * fChargeXpos
position of the MC Truth charge deposition
void ensureHists(unsigned int const nTimeSamples)
TPCGeo const & TPC(TPCID const &tpcid=tpc_zero) const
Returns the specified TPC.
Definition: GeometryCore.h:722
LArSimChannelAna(fhicl::ParameterSet const &pset)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void analyze(const art::Event &evt) override
T get(std::string const &key) const
Definition: ParameterSet.h:314
TH1D * fChargeYpos
position of the MC Truth charge deposition
Base class for creation of raw signals on wires.
TH1D * fEnergy
Energy in the whole channel entry.
TH1D * fChargeZpos
position of the MC Truth charge deposition
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Float_t sc
Definition: plot.C:23
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TCEvent evt
Definition: DataStructs.cxx:8
TH1D * fTDC
Which TDCs have activity.
art framework interface to geometry description
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:96
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.