SimWireAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // SimWire class designed to simulate signal on a wire in the TPC
4 //
5 // katori@fnal.gov
6 //
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 // Framework includes
13 #include "fhiclcpp/ParameterSet.h"
16 #include "art_root_io/TFileService.h"
19 
20 // LArSoft includes
21 #include "lardataobj/RawData/raw.h"
23 
24 #include "TH2.h"
25 
26 #include <string>
27 
28 
29 ///Detector simulation of raw signals on wires
30 namespace detsim {
31 
32  /// Base class for creation of raw signals on wires.
33  class SimWireAna : public art::EDAnalyzer {
34 
35  public:
36 
37  explicit SimWireAna(fhicl::ParameterSet const& pset);
38 
39  /// read/write access to event
40  void analyze (const art::Event& evt);
41  void beginJob();
42 
43  private:
44 
45  std::string fDetSimModuleLabel;///< name of module that produced the digits
46  TH1F* fDiffs; ///< histogram of Raw tdc to tdc differences
47 
48  TH1F* fCompressErr; ///< histogram of difference between original
49  ///<tdc value and compressesed value
50  TH1F* fCompressFactor; ///< compression factor
51 
52  TH2F* fRawVsCompress; ///< histogram of original tdc value vs compressesed value
53  TH2F* fCompressErr2D; ///< histogram of original tdc value vs compressesed value
54 
55 
56  }; // class SimWire
57 
58 }
59 
60 namespace detsim{
61 
62  //-------------------------------------------------
64  : EDAnalyzer(pset)
65  , fDetSimModuleLabel{pset.get< std::string >("DetSimModuleLabel")}
66  {}
67 
68  //-------------------------------------------------
70  {
71  // get access to the TFile service
73 
74  fDiffs = tfs->make<TH1F>("One timestamp diffs", ";#Delta ADC;", 40, -19.5, 20.5);
75  fCompressErr = tfs->make<TH1F>("compressErr", ";Raw-Compressed;", 1000, -495.5, 500.5);
76  fCompressFactor = tfs->make<TH1F>("compressFactor", ";Compression;", 500, 0., 1.);
77 
78  fCompressErr2D = tfs->make<TH2F>("compressErr2D", ";Raw;Raw-Compressed", 100, -50., 50., 1000, -495.5, 500.5);
79  fRawVsCompress = tfs->make<TH2F>("rawVsCompress", ";Raw;Compressed", 100, -50., 50., 100, -50., 50.);
80 
81  return;
82 
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 
100  /// loop over all the raw digits
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 = "
123  << uncompressed.size() << "\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") << "problem with event "
130  << " time " << t << " ADC " << rdvec[rd]->ADC(t)
131  << " 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 
144 }//end namespace
145 
146 namespace detsim{
147 
149 
150 }
Huffman Encoding.
Definition: RawTypes.h:10
std::string string
Definition: nybbler.cc:12
Detector simulation of raw signals on wires.
int16_t adc
Definition: CRTFragment.hh:202
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
TH1F * fDiffs
histogram of Raw tdc to tdc differences
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
T get(std::string const &key) const
Definition: ParameterSet.h:271
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
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:7
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
TH2F * fCompressErr2D
histogram of original tdc value vs compressesed value
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33