All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
11 #include "art/Framework/Core/EDAnalyzer.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Services/Registry/ServiceHandle.h"
16 #include "art_root_io/TFileService.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "canvas/Persistency/Common/PtrVector.h"
19 #include "messagefacility/MessageLogger/MessageLogger.h"
20 #include "fhiclcpp/ParameterSet.h"
21 
22 // LArSoft includes
23 #include "lardataobj/RawData/raw.h"
25 
26 #include "TH1.h"
27 #include "TH2.h"
28 
29 #include <string>
30 #include <vector>
31 
32 ///Detector simulation of raw signals on wires
33 namespace detsim {
34 
35  /// Base class for creation of raw signals on wires.
36  class SimWireAna : public art::EDAnalyzer {
37 
38  public:
39 
40  explicit SimWireAna(fhicl::ParameterSet const& pset);
41 
42  /// read/write access to event
43  void analyze (const art::Event& evt);
44  void beginJob();
45 
46  private:
47 
48  std::string fDetSimModuleLabel;///< name of module that produced the digits
49  TH1F* fDiffs; ///< histogram of Raw tdc to tdc differences
50 
51  TH1F* fCompressErr; ///< histogram of difference between original
52  ///<tdc value and compressesed value
53  TH1F* fCompressFactor; ///< compression factor
54 
55  TH2F* fRawVsCompress; ///< histogram of original tdc value vs compressesed value
56  TH2F* fCompressErr2D; ///< histogram of original tdc value vs compressesed value
57 
58 
59  }; // class SimWire
60 
61 }
62 
63 namespace detsim{
64 
65  //-------------------------------------------------
66  SimWireAna::SimWireAna(fhicl::ParameterSet const& pset)
67  : EDAnalyzer(pset)
68  , fDetSimModuleLabel{pset.get< std::string >("DetSimModuleLabel")}
69  {}
70 
71  //-------------------------------------------------
73  {
74  // get access to the TFile service
75  art::ServiceHandle<art::TFileService const> tfs;
76 
77  fDiffs = tfs->make<TH1F>("One timestamp diffs", ";#Delta ADC;", 40, -19.5, 20.5);
78  fCompressErr = tfs->make<TH1F>("compressErr", ";Raw-Compressed;", 1000, -495.5, 500.5);
79  fCompressFactor = tfs->make<TH1F>("compressFactor", ";Compression;", 500, 0., 1.);
80 
81  fCompressErr2D = tfs->make<TH2F>("compressErr2D", ";Raw;Raw-Compressed", 100, -50., 50., 1000, -495.5, 500.5);
82  fRawVsCompress = tfs->make<TH2F>("rawVsCompress", ";Raw;Compressed", 100, -50., 50., 100, -50., 50.);
83 
84  return;
85 
86  }
87 
88  //-------------------------------------------------
89  void SimWireAna::analyze(const art::Event& evt)
90  {
91 
92  // loop over the raw digits and get the adc vector for each, then compress it and uncompress it
93 
94  art::Handle< std::vector<raw::RawDigit> > rdHandle;
95  evt.getByLabel(fDetSimModuleLabel,rdHandle);
96 
97  art::PtrVector<raw::RawDigit> rdvec;
98  for(unsigned int i = 0; i < rdHandle->size(); ++i){
99  art::Ptr<raw::RawDigit> r(rdHandle,i);
100  rdvec.push_back(r);
101  }
102 
103  /// loop over all the raw digits
104  for(unsigned int rd = 0; rd < rdvec.size(); ++rd){
105 
106  std::vector<short> adc;
107  std::vector<short> uncompressed(rdvec[rd]->Samples());
108  for(unsigned int t = 1; t < rdvec[rd]->Samples(); ++t){
109  fDiffs->Fill(rdvec[rd]->ADC(t) - rdvec[rd]->ADC(t-1));
110  adc.push_back(rdvec[rd]->ADC(t-1));
111  }
112 
113  //get the last one for the adc vector
114  adc.push_back(rdvec[rd]->ADC(rdvec[rd]->Samples()-1));
115 
117 
118  fCompressFactor->Fill((1.*adc.size())/(1.*rdvec[rd]->Samples()));
119 
120  raw::Uncompress(adc, uncompressed, raw::kHuffman);
121 
122  if(uncompressed.size() != rdvec[rd]->Samples()){
123  cet::exception("WrongSizeUncompress")
124  << "uncompression does not produce same size vector as original: "
125  << "original = " << rdvec[rd]->Samples() << " uncompress = "
126  << uncompressed.size() << "\n";
127  }
128 
129  for(unsigned int t = 0; t < uncompressed.size(); ++t){
130  //std::cout << t << " " << rdFE->ADC(t) << " " << uncompressed[t] << std::endl;
131  if(uncompressed[t]-rdvec[rd]->ADC(t) > 1)
132  mf::LogWarning("SimWireAna") << "problem with event "
133  << " time " << t << " ADC " << rdvec[rd]->ADC(t)
134  << " uncompress " << uncompressed[t]
135  << " channel " << rdvec[rd]->Channel();
136 
137  fCompressErr->Fill(uncompressed[t]-rdvec[rd]->ADC(t));
138  fCompressErr2D->Fill(rdvec[rd]->ADC(t), uncompressed[t]-rdvec[rd]->ADC(t));
139  fRawVsCompress->Fill(rdvec[rd]->ADC(t), uncompressed[t]);
140  }
141  }//end loop over digits
142 
143  return;
144  }//end analyze method
145 
146 
147 }//end namespace
148 
149 namespace detsim{
150 
151  DEFINE_ART_MODULE(SimWireAna)
152 
153 }
Huffman Encoding.
Definition: RawTypes.h:10
Definition of basic raw digits.
TH1F * fDiffs
histogram of Raw tdc to tdc differences
Collect all the RawData header files together.
std::string fDetSimModuleLabel
name of module that produced the digits
void analyze(const art::Event &evt)
read/write access to event
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.
art::ServiceHandle< art::TFileService > tfs
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:776
TH2F * fCompressErr2D
histogram of original tdc value vs compressesed value
esac echo uname r