LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SimWireAna_module.cc
Go to the documentation of this file.
1 //
3 // SimWire class designed to simulate signal on a wire in the TPC
4 //
5 // katori@fnal.gov
6 //
7 //
9 
10 // Framework includes
16 #include "art_root_io/TFileService.h"
19 #include "fhiclcpp/ParameterSet.h"
21 
22 // LArSoft includes
24 #include "lardataobj/RawData/raw.h"
25 
26 #include "TH1.h"
27 #include "TH2.h"
28 
29 #include <string>
30 #include <vector>
31 
33 namespace detsim {
34 
36  class SimWireAna : public art::EDAnalyzer {
37 
38  public:
39  explicit SimWireAna(fhicl::ParameterSet const& pset);
40 
42  void analyze(const art::Event& evt);
43  void beginJob();
44 
45  private:
46  std::string fDetSimModuleLabel;
47  TH1F* fDiffs;
48 
49  TH1F* fCompressErr;
50  TH1F* fCompressFactor;
52 
55 
56  }; // class SimWire
57 
58 }
59 
60 namespace detsim {
61 
62  //-------------------------------------------------
64  : EDAnalyzer(pset), fDetSimModuleLabel{pset.get<std::string>("DetSimModuleLabel")}
65  {}
66 
67  //-------------------------------------------------
69  {
70  // get access to the TFile service
72 
73  fDiffs = tfs->make<TH1F>("One timestamp diffs", ";#Delta ADC;", 40, -19.5, 20.5);
74  fCompressErr = tfs->make<TH1F>("compressErr", ";Raw-Compressed;", 1000, -495.5, 500.5);
75  fCompressFactor = tfs->make<TH1F>("compressFactor", ";Compression;", 500, 0., 1.);
76 
78  tfs->make<TH2F>("compressErr2D", ";Raw;Raw-Compressed", 100, -50., 50., 1000, -495.5, 500.5);
80  tfs->make<TH2F>("rawVsCompress", ";Raw;Compressed", 100, -50., 50., 100, -50., 50.);
81 
82  return;
83  }
84 
85  //-------------------------------------------------
87  {
88 
89  // loop over the raw digits and get the adc vector for each, then compress it and uncompress it
90 
92  evt.getByLabel(fDetSimModuleLabel, rdHandle);
93 
95  for (unsigned int i = 0; i < rdHandle->size(); ++i) {
96  art::Ptr<raw::RawDigit> r(rdHandle, i);
97  rdvec.push_back(r);
98  }
99 
101  for (unsigned int rd = 0; rd < rdvec.size(); ++rd) {
102 
103  std::vector<short> adc;
104  std::vector<short> uncompressed(rdvec[rd]->Samples());
105  for (unsigned int t = 1; t < rdvec[rd]->Samples(); ++t) {
106  fDiffs->Fill(rdvec[rd]->ADC(t) - rdvec[rd]->ADC(t - 1));
107  adc.push_back(rdvec[rd]->ADC(t - 1));
108  }
109 
110  //get the last one for the adc vector
111  adc.push_back(rdvec[rd]->ADC(rdvec[rd]->Samples() - 1));
112 
114 
115  fCompressFactor->Fill((1. * adc.size()) / (1. * rdvec[rd]->Samples()));
116 
117  raw::Uncompress(adc, uncompressed, raw::kHuffman);
118 
119  if (uncompressed.size() != rdvec[rd]->Samples()) {
120  cet::exception("WrongSizeUncompress")
121  << "uncompression does not produce same size vector as original: "
122  << "original = " << rdvec[rd]->Samples() << " uncompress = " << uncompressed.size()
123  << "\n";
124  }
125 
126  for (unsigned int t = 0; t < uncompressed.size(); ++t) {
127  //std::cout << t << " " << rdFE->ADC(t) << " " << uncompressed[t] << std::endl;
128  if (uncompressed[t] - rdvec[rd]->ADC(t) > 1)
129  mf::LogWarning("SimWireAna")
130  << "problem with event "
131  << " time " << t << " ADC " << rdvec[rd]->ADC(t) << " uncompress " << uncompressed[t]
132  << " channel " << rdvec[rd]->Channel();
133 
134  fCompressErr->Fill(uncompressed[t] - rdvec[rd]->ADC(t));
135  fCompressErr2D->Fill(rdvec[rd]->ADC(t), uncompressed[t] - rdvec[rd]->ADC(t));
136  fRawVsCompress->Fill(rdvec[rd]->ADC(t), uncompressed[t]);
137  }
138  } //end loop over digits
139 
140  return;
141  } //end analyze method
142 
143 } //end namespace
144 
145 namespace detsim {
146 
148 
149 }
TRandom r
Definition: spectrum.C:23
Huffman Encoding.
Definition: RawTypes.h:10
Detector simulation of raw signals on wires.
Definition of basic raw digits.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
TH1F * fDiffs
histogram of Raw tdc to tdc differences
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::string fDetSimModuleLabel
name of module that produced the digits
void analyze(const art::Event &evt)
read/write access to event
size_type size() const
Definition: PtrVector.h:302
TH1F * fCompressFactor
compression factor
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
TH2F * fRawVsCompress
histogram of original tdc value vs compressesed value
SimWireAna(fhicl::ParameterSet const &pset)
void Compress(std::vector< short > &adc, raw::Compress_t compress)
Compresses a raw data buffer.
Definition: raw.cxx:19
Base class for creation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:8
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:744
TH2F * fCompressErr2D
histogram of original tdc value vs compressesed value
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33