LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <vector>
12 #include <string>
13 #include <algorithm>
14 #include <sstream>
15 #include <fstream>
16 #include <bitset>
17 // POSIX includes
18 extern "C" {
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 }
22 // Framework includes
26 #include "fhiclcpp/ParameterSet.h"
34 // Root Includes
35 #include "TMath.h"
36 #include "TGraph.h"
37 #include "TFile.h"
38 #include "TLine.h"
39 #include "TComplex.h"
40 #include "TString.h"
41 #include "TGraph.h"
42 #include "TH1.h"
43 #include "TVector3.h"
44 // LArSoft includes
49 
50 namespace geo { class Geometry; }
51 
53 namespace larg {
54 
57 
58  public:
59 
60  explicit LArSimChannelAna(fhicl::ParameterSet const& pset);
61  virtual ~LArSimChannelAna();
62 
64  void analyze (const art::Event& evt);
65  void beginJob(){};
66  void endJob();
67  void reconfigure(fhicl::ParameterSet const& p);
68 
69  // intilize the histograms
70  //
71  // Can't be done in Begin job because I want to use LArProperties
72  // which used the database, so I test and run on each
73  // event. Wasteful and silly, but at least it *works*.
74  void ensureHists();
75 
76  private:
77 
78  std::string fLArG4ModuleLabel;
79 
80  // Flag for initialization done, because we set up histograms the
81  // first time through beginRun() so that we can use the
82  // database...
83  bool initDone;
84 
85  TH1D * fChargeXpos;
86  TH1D * fChargeYpos;
87  TH1D * fChargeZpos;
88 
89  TH1D * fTDC;
90 
91  TH1D * fTDCsPerChannel;
93 
94  TH1D * fElectrons;
95  TH1D * fEnergy;
96 
98  TH1D * fEnergyPerTDC;
99 
102 
103 
104 
105  }; // class LArSimChannelAna
106 
107 
108  //-------------------------------------------------
109  LArSimChannelAna::LArSimChannelAna(fhicl::ParameterSet const& pset)
110  : EDAnalyzer(pset)
111  , initDone(false)
112  , fChargeXpos()
113  , fChargeYpos()
114  , fChargeZpos()
115  , fTDC()
116  , fTDCsPerChannel()
117  , fIDEsPerChannel()
118  , fElectrons()
119  , fEnergy()
120  , fElectronsPerTDC()
121  , fEnergyPerTDC()
122  , fElectronsPerIDE()
123  , fEnergyPerIDE()
124  {
125  this->reconfigure(pset);
126  }
127 
128  //-------------------------------------------------
130  {
131  }
132 
134  {
135  fLArG4ModuleLabel = p.get< std::string >("LArGeantModuleLabel");
136  return;
137  }
138  //-------------------------------------------------
140  if (initDone) return; // Bail if we've already done this.
141  initDone = true; // Insure that we bail later on
142 
143  // get access to the TFile service
145  // geometry data.
147  // detector specific properties
148  const detinfo::DetectorProperties* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
149 
150  // assumes all TPCs are the same
151  double width = 2 * geom->TPC(0).HalfWidth();
152  double halfHeight = geom->TPC(0).HalfHeight();
153  double length = geom->TPC(0).Length();
154 
155  // Assumes microboone dimensions. Ideally we'd fix this later...
156  fChargeXpos = tfs->make<TH1D>("hChargeXpos",
157  "X charge depositions;X (cm);Events",
158  101, 0.0, width);
159  fChargeYpos = tfs->make<TH1D>("hChargeYpos",
160  "Y charge depositions;Y (cm);Events",
161  101, -halfHeight, halfHeight);
162  fChargeZpos = tfs->make<TH1D>("hChargeZpos",
163  "Z charge depositions;Z (cm);Events",
164  101, 0.0, length);
165  fTDC = tfs->make<TH1D>("hTDC",
166  "Active TDC;TDCs;Events;",
167  detprop->NumberTimeSamples(), 0,
168  detprop->NumberTimeSamples());
169  fTDCsPerChannel =tfs->make<TH1D>("hTDCsPerChannel",
170  "TDCs per channel entry;# TDCs;Events",
171  128, 0, detprop->NumberTimeSamples());
172  fIDEsPerChannel =tfs->make<TH1D>("hIDEsPerChannel",
173  "IDE per channel entry;# IDEs;Events",
174  100,0,20000);
175  fElectrons =tfs->make<TH1D>("hElectrons",
176  "Electrons per channel;Electrons;Events",
177  100,0,2e7);
178  fEnergy =tfs->make<TH1D>("hEnergy",
179  "Energy per channel;energy;Events",
180  100,0,2500);
181  fElectronsPerIDE=tfs->make<TH1D>("hElectronsPerIDE",
182  "Electrons per IDE;Electrons;Events",
183  100,0,10000);
184  fEnergyPerIDE =tfs->make<TH1D>("hEnergyPerIDE",
185  "Energy per IDE;energy;Events",
186  100,0,50);
187  fElectronsPerTDC=tfs->make<TH1D>("hElectronsPerTDC",
188  "Electrons per TDC;Electrons;Events",
189  100,0,10000);
190  fEnergyPerTDC =tfs->make<TH1D>("hEnergyPerTDC",
191  "Energy per YDC;energy;Events",
192  100,0,50);
193  return;
194 
195  }
196 
197  //-------------------------------------------------
199 
200  //-------------------------------------------------
202  {
203 
204  if (evt.isRealData()) {
205  throw cet::exception("LArSimChannelAna") << "Not for use on Data yet...\n";
206  }
207 
208  ensureHists();
209 
211 
213  evt.getByLabel(fLArG4ModuleLabel,chanHandle);
214  const std::vector<sim::SimChannel>& scVec(*chanHandle);
215 
216  //++++++++++
217  // Loop over the Chnnels and fill histograms
218  //++++++++++
219  unsigned int totalIDEs = 0;
220  double totalElectrons = 0;
221  double totalEnergy = 0;
222  for (const auto& sc : scVec ) {
223  const auto & tdcidemap=sc.TDCIDEMap();
224  fTDCsPerChannel->Fill(tdcidemap.size());
225 
226  for (const auto& tdcide : tdcidemap) {
227  unsigned int tdc = tdcide.first;
228  const std::vector<sim::IDE>& ideVec = tdcide.second;
229  totalIDEs += ideVec.size();
230  double tdcElectrons=0;
231  double tdcEnergy=0;
232 
233  fTDC->Fill(tdc);
234 
235  for (const auto& ide : ideVec) {
236  totalElectrons += ide.numElectrons;
237  totalEnergy += ide.energy;
238  tdcElectrons += ide.numElectrons;
239  tdcEnergy += ide.energy;
240 
241  fChargeXpos->Fill(ide.x);
242  fChargeYpos->Fill(ide.y);
243  fChargeZpos->Fill(ide.z);
244  fElectronsPerIDE->Fill(ide.numElectrons);
245  fEnergyPerIDE->Fill(ide.energy);
246  }
247  fElectronsPerTDC->Fill(tdcElectrons);
248  fEnergyPerTDC->Fill(tdcEnergy);
249  }
250  }
251  fIDEsPerChannel->Fill(totalIDEs);
252  fElectrons->Fill(totalElectrons);
253  fEnergy->Fill(totalEnergy);
254  return;
255  }//end analyze method
256 
258 
259 } // end of hit namespace
260 
TH1D * fTDCsPerChannel
Number of TDCs with activity.
Detector simulation of raw signals on wires.
bool isRealData() const
Definition: Event.h:83
TH1D * fElectrons
Electrons in the whole channel entry.
TH1D * fChargeXpos
position of the MC Truth charge deposition
double Length() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:107
void reconfigure(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
virtual unsigned int NumberTimeSamples() const =0
TH1D * fChargeYpos
position of the MC Truth charge deposition
Base class for creation of raw signals on wires.
void analyze(const art::Event &evt)
read/write access to event
TH1D * fEnergy
Energy in the whole channel entry.
double HalfHeight() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:103
TH1D * fChargeZpos
position of the MC Truth charge deposition
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
TCEvent evt
Definition: DataStructs.cxx:5
TH1D * fTDC
Which TDCs have activity.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:99
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.