LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
WienerFilterAna_module.cc
Go to the documentation of this file.
1 //
3 // WienerFilterAna class designed to calculate the optimum filter for an event
4 // (based strongly on CalWireAna)
5 // andrzej.szelc@yale.edu
6 //
7 //
9 
10 // C++ includes
11 #include <string>
12 #include <vector>
13 
14 // Framework includes
20 #include "art_root_io/TFileService.h"
22 #include "fhiclcpp/ParameterSet.h"
24 
25 // LArSoft includes
30 
31 // ROOT includes
32 #include <TH1.h>
33 
34 namespace detsim {
35 
38 
39  public:
40  explicit WienerFilterAna(fhicl::ParameterSet const& pset);
41 
43  void analyze(const art::Event& evt);
44  void beginJob();
45  void endJob();
46 
47  private:
48  std::string fDetSimModuleLabel; //< name of module that produced the digits
49 
50  TH1F* fCnoise[10][10][5];
51  TH1F* fCsignal[10][10][5];
52 
53  TH1F* fCnoise_av[10][10][5];
54  TH1F* fCsignal_av[10][10][5];
55 
56  TH1F* fFilter_av[10][10][5];
57 
58  TH1* ff;
59  TH1F* hh;
60  int fNBins;
61  }; // class WienerFilterAna
62 
63 } // End caldata namespace.
64 
65 namespace detsim {
66 
67  //-------------------------------------------------
69  : EDAnalyzer(pset), fDetSimModuleLabel(pset.get<std::string>("DetSimModuleLabel"))
70  {}
71 
72  //-------------------------------------------------
74  {
75  // get access to the TFile service
77 
79  int fNTicks = fFFT->FFTSize();
80  fNBins = fNTicks / 2 + 1;
81  auto const clock_data =
83  double samprate = sampling_rate(clock_data);
84  double sampfreq = 1. / samprate * 1e6; // in kHz
86  unsigned int fNPlanes = geo->Nplanes();
87  unsigned int fNCryostats = geo->Ncryostats();
88  unsigned int fNTPC = geo->NTPC();
89 
90  for (unsigned int icstat = 0; icstat < fNCryostats; icstat++) {
91  for (unsigned int itpc = 0; itpc < fNTPC; itpc++) {
92  for (unsigned int iplane = 0; iplane < fNPlanes; iplane++) {
93  fCnoise[icstat][itpc][iplane] =
94  tfs->make<TH1F>(Form("fft_noise_%d_%d_%d", icstat, itpc, iplane),
95  Form("fft_of_unfiltered_noise_%d_%d_%d", icstat, itpc, iplane),
96  fNBins,
97  0,
98  sampfreq / 2);
99 
100  fCsignal[icstat][itpc][iplane] = tfs->make<TH1F>(
101  Form("fft_signal_%d_%d_%d", icstat, itpc, iplane),
102  Form("fft_of_unfiltered_noise_and_signal_%d_%d_%d", icstat, itpc, iplane),
103  fNBins,
104  0,
105  sampfreq / 2);
106 
107  fCnoise_av[icstat][itpc][iplane] =
108  tfs->make<TH1F>(Form("fft_noise_%d_%d_%d_av", icstat, itpc, iplane),
109  Form("fft_of_unfiltered_noise_%d_%d_%d_av", icstat, itpc, iplane),
110  fNBins,
111  0,
112  sampfreq / 2);
113  fCsignal_av[icstat][itpc][iplane] = tfs->make<TH1F>(
114  Form("fft_signal_%d_%d_%d_av", icstat, itpc, iplane),
115  Form("fft_of_unfiltered_noise_and_signal_%d_%d_%d_av", icstat, itpc, iplane),
116  fNBins,
117  0,
118  sampfreq / 2);
119 
120  fFilter_av[icstat][itpc][iplane] =
121  tfs->make<TH1F>(Form("fft_filter_%d_%d_%d_av", icstat, itpc, iplane),
122  Form("fft_filter_%d_%d_%d_av", icstat, itpc, iplane),
123  fNBins,
124  0,
125  sampfreq / 2);
126  }
127  }
128  }
129 
130  //ff=tfs->make<TH1>(Form("fftwaveform"),Form("fftwaveform"),4096,0,4096);
131  hh = tfs->make<TH1F>(Form("waveform"), Form("waveform"), fNTicks, 0, fNTicks);
132 
133  return;
134  }
135 
136  //-------------------------------------------------
138  {
139 
141  unsigned int nplanes = geom->Nplanes();
142  unsigned int fNCryostats = geom->Ncryostats();
143  unsigned int fNTPC = geom->NTPC();
144 
145  // calculate filters
146 
147  for (unsigned int icstat = 0; icstat < fNCryostats; icstat++) {
148  for (unsigned int itpc = 0; itpc < fNTPC; itpc++) {
149  for (unsigned int pp = 0; pp < nplanes; pp++) {
150 
151  for (int ii = 1; ii < fCsignal_av[icstat][itpc][pp]->GetNbinsX(); ii++) {
152 
153  double diff = ((fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) *
154  fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) -
155  fCnoise_av[icstat][itpc][pp]->GetBinContent(ii) *
156  fCnoise_av[icstat][itpc][pp]->GetBinContent(ii)) >= 0) ?
157  fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) *
158  fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) -
159  fCnoise_av[icstat][itpc][pp]->GetBinContent(ii) *
160  fCnoise_av[icstat][itpc][pp]->GetBinContent(ii) :
161  0;
162 
163  if (fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) > 0)
164  fFilter_av[icstat][itpc][pp]->SetBinContent(
165  ii,
166  (double)((diff) / (fCsignal_av[icstat][itpc][pp]->GetBinContent(ii) *
167  fCsignal_av[icstat][itpc][pp]->GetBinContent(ii))));
168  else
169  fFilter_av[icstat][itpc][pp]->SetBinContent(ii, 0);
170 
171  } // end loop on Csignal
172  } // end loop on planes
173  } // end loop on TPCs
174  } // end loop on cryostats
175  }
176 
177  //-------------------------------------------------
179  {
180 
181  // loop over the raw digits and get the adc vector for each, then compress it and uncompress it
182 
184  evt.getByLabel(fDetSimModuleLabel, rdHandle);
185  mf::LogInfo("WienerFilterMicroBooNE") << " readout Wiener " << rdHandle->size() << std::endl;
186  // return;
187  if (!rdHandle->size()) return;
188  mf::LogInfo("WienerFilterMicroBooNE")
189  << "WienerFilterMicroBooNE:: rdHandle size is " << rdHandle->size();
190 
191  // Read in the digit List object(s).
192 
193  // Use the handle to get a particular (0th) element of collection.
195  for (unsigned int i = 0; i < rdHandle->size(); ++i) {
196  art::Ptr<raw::RawDigit> r(rdHandle, i);
197  rdvec.push_back(r);
198  // std::cout << " i, rdvec: "<<i <<" " << r->ADC(0) << " "<< rdvec[i]->ADC(0)<< std::endl;
199  }
200 
203 
204  for (unsigned int rd = 0; rd < rdvec.size(); ++rd) {
205 
206  std::vector<double> adc(fft->FFTSize());
207 
208  for (unsigned int t = 1; t < rdvec[rd]->Samples(); t++) {
209  adc[t - 1] = rdvec[rd]->ADC(t - 1);
210  hh->SetBinContent(t, rdvec[rd]->ADC(t));
211  }
212 
213  geo::WireID wireid = geom->ChannelToWire(rdvec[rd]->Channel())[0];
214 
215  // this is hardcoded for the time being. Should be automatized.
216  unsigned int plane = wireid.Plane;
217  unsigned int wire = wireid.Wire;
219  unsigned int cstat = wireid.Cryostat;
220  unsigned int tpc = wireid.TPC;
221  ff = hh->FFT(NULL, "MAG M");
222  if (wire >= 50 && wire < 250) {
223  for (int ii = 0; ii < fNBins; ii++) {
224  fCnoise_av[cstat][tpc][plane]->AddBinContent(ii, ff->GetBinContent(ii));
225  if (wire == 150) fCnoise[cstat][tpc][plane]->SetBinContent(ii, ff->GetBinContent(ii));
226  }
227  }
228  else if (wire >= 700 && wire < 900) {
229  for (int ii = 0; ii < fNBins; ii++) {
230  fCsignal_av[cstat][tpc][plane]->AddBinContent(ii, ff->GetBinContent(ii));
231  if (wire == 800) fCsignal[cstat][tpc][plane]->SetBinContent(ii, ff->GetBinContent(ii));
232  }
233  }
234 
235  //
236  } //end loop over rawDigits
237 
238  return;
239  } //end analyze method
240 
241 } //end namespace
242 
243 namespace detsim {
244 
246 
247 }
TRandom r
Definition: spectrum.C:23
unsigned int NTPC(CryostatID const &cryoid=cryostat_zero) const
Returns the total number of TPCs in the specified cryostat.
Definition: GeometryCore.h:686
std::vector< WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Detector simulation of raw signals on wires.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:211
STL namespace.
Definition of basic raw digits.
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
Definition: GeometryCore.h:430
int FFTSize() const
Definition: LArFFT.h:66
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Base class for creation of raw signals on wires.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
size_type size() const
Definition: PtrVector.h:302
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
TCEvent evt
Definition: DataStructs.cxx:8
void analyze(const art::Event &evt)
read/write access to event
WienerFilterAna(fhicl::ParameterSet const &pset)
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:399
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description