LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 #ifndef SIMWIREANA_H
10 #define SIMWIREANA_H
11 
12 // ROOT includes
13 #include <TMath.h>
14 #include <TH1F.h>
15 #include <TGraph.h>
16 #include <TFile.h>
17 
18 // C++ includes
19 #include <algorithm>
20 #include <sstream>
21 #include <fstream>
22 #include <bitset>
23 
24 // Framework includes
27 #include "fhiclcpp/ParameterSet.h"
33 
34 // LArSoft includes
35 #include "lardataobj/RawData/raw.h"
38 
39 #include "TComplex.h"
40 #include "TString.h"
41 #include "TGraph.h"
42 #include "TH2.h"
43 
45 
46 #include <vector>
47 #include <string>
48 
49 
51 namespace detsim {
52 
54  class SimWireAna : public art::EDAnalyzer {
55 
56  public:
57 
58  explicit SimWireAna(fhicl::ParameterSet const& pset);
59  virtual ~SimWireAna();
60 
62  void analyze (const art::Event& evt);
63  void beginJob();
64  void reconfigure(fhicl::ParameterSet const& p);
65 
66  private:
67 
68  std::string fDetSimModuleLabel;
69  TH1F* fDiffs;
70 
71  TH1F* fCompressErr;
72  TH1F* fCompressFactor;
74 
77 
78 
79  }; // class SimWire
80 
81 }
82 
83 namespace detsim{
84 
85  //-------------------------------------------------
87  : EDAnalyzer(pset)
88  {
89  this->reconfigure(pset);
90  }
91 
92  //-------------------------------------------------
94  {
95  }
96 
98  {
99  fDetSimModuleLabel = p.get< std::string >("DetSimModuleLabel");
100 
101  return;
102  }
103  //-------------------------------------------------
105  {
106  // get access to the TFile service
108 
109  fDiffs = tfs->make<TH1F>("One timestamp diffs", ";#Delta ADC;", 40, -19.5, 20.5);
110  fCompressErr = tfs->make<TH1F>("compressErr", ";Raw-Compressed;", 1000, -495.5, 500.5);
111  fCompressFactor = tfs->make<TH1F>("compressFactor", ";Compression;", 500, 0., 1.);
112 
113  fCompressErr2D = tfs->make<TH2F>("compressErr2D", ";Raw;Raw-Compressed", 100, -50., 50., 1000, -495.5, 500.5);
114  fRawVsCompress = tfs->make<TH2F>("rawVsCompress", ";Raw;Compressed", 100, -50., 50., 100, -50., 50.);
115 
116  return;
117 
118  }
119 
120  //-------------------------------------------------
122  {
123 
124  // loop over the raw digits and get the adc vector for each, then compress it and uncompress it
125 
127  evt.getByLabel(fDetSimModuleLabel,rdHandle);
128 
130  for(unsigned int i = 0; i < rdHandle->size(); ++i){
131  art::Ptr<raw::RawDigit> r(rdHandle,i);
132  rdvec.push_back(r);
133  }
134 
136  for(unsigned int rd = 0; rd < rdvec.size(); ++rd){
137 
138  std::vector<short> adc;
139  std::vector<short> uncompressed(rdvec[rd]->Samples());
140  for(unsigned int t = 1; t < rdvec[rd]->Samples(); ++t){
141  fDiffs->Fill(rdvec[rd]->ADC(t) - rdvec[rd]->ADC(t-1));
142  adc.push_back(rdvec[rd]->ADC(t-1));
143  }
144 
145  //get the last one for the adc vector
146  adc.push_back(rdvec[rd]->ADC(rdvec[rd]->Samples()-1));
147 
149 
150  fCompressFactor->Fill((1.*adc.size())/(1.*rdvec[rd]->Samples()));
151 
152  raw::Uncompress(adc, uncompressed, raw::kHuffman);
153 
154  if(uncompressed.size() != rdvec[rd]->Samples()){
155  cet::exception("WrongSizeUncompress")
156  << "uncompression does not produce same size vector as original: "
157  << "original = " << rdvec[rd]->Samples() << " uncompress = "
158  << uncompressed.size() << "\n";
159  }
160 
161  for(unsigned int t = 0; t < uncompressed.size(); ++t){
162  //std::cout << t << " " << rdFE->ADC(t) << " " << uncompressed[t] << std::endl;
163  if(uncompressed[t]-rdvec[rd]->ADC(t) > 1)
164  mf::LogWarning("SimWireAna") << "problem with event "
165  << " time " << t << " ADC " << rdvec[rd]->ADC(t)
166  << " uncompress " << uncompressed[t]
167  << " channel " << rdvec[rd]->Channel();
168 
169  fCompressErr->Fill(uncompressed[t]-rdvec[rd]->ADC(t));
170  fCompressErr2D->Fill(rdvec[rd]->ADC(t), uncompressed[t]-rdvec[rd]->ADC(t));
171  fRawVsCompress->Fill(rdvec[rd]->ADC(t), uncompressed[t]);
172  }
173  }//end loop over digits
174 
175  return;
176  }//end analyze method
177 
178 
179 }//end namespace
180 
181 namespace detsim{
182 
184 
185 }
186 
187 #endif // SIMWIREANA_H
Huffman Encoding.
Definition: RawTypes.h:10
Detector simulation of raw signals on wires.
Definition of basic raw digits.
TH1F * fDiffs
histogram of Raw tdc to tdc differences
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
Collect all the RawData header files together.
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::string fDetSimModuleLabel
name of module that produced the digits
void analyze(const art::Event &evt)
read/write access to event
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
size_type size() const
Definition: PtrVector.h:308
TH1F * fCompressFactor
compression factor
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
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:20
Base class for creation of raw signals on wires.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:756
void reconfigure(fhicl::ParameterSet const &p)
TH2F * fCompressErr2D
histogram of original tdc value vs compressesed value
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33