11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art_root_io/TFileService.h"
14 #include "cetlib/search_path.h"
29 void hist_to_vector(
const TH1D*
h, std::vector<double>& v)
32 int n = h->GetNbinsX();
34 for(
int i=0; i<
n; ++i)
35 v[i] = h->GetBinContent(i+1);
40 void vector_to_hist(
const std::vector<double>& v, TH1D* h)
44 int nbins = h->GetNbinsX();
45 int nfill = std::min(nvec, nbins);
46 h->SetBinContent(0, 0.);
47 for(
int i=0; i<nfill; ++i)
48 h->SetBinContent(i+1, v[i]);
49 for(
int i=nfill+1; i<=nbins+1; ++i)
50 h->SetBinContent(i, 0.);
55 void fill_delta(std::vector<double>& v,
int d)
58 assert(d >= 0 && d < n);
59 for(
int i=0; i<
n; ++i)
73 explicit FFTTest(fhicl::ParameterSet
const& pset);
114 art::ServiceHandle<art::TFileService>
tfs;
118 art::ServiceHandle<util::LArFFT> fFFT;
119 fNTicks = fFFT->FFTSize();
120 std::cout <<
"Number of ticks = " << fNTicks << std::endl;
124 fSimFile = pset.get<std::string>(
"simwire_file");
125 std::cout <<
"SimWire file = " << fSimFile << std::endl;
127 TFile fsim(fSimFile.c_str());
129 TH1D* hSimElect =
dynamic_cast<TH1D*
>(fsim.Get(
"daq/ElectronicsResponse"));
130 hist_to_vector(hSimElect, fSimElect);
131 fSimElect.resize(fNTicks, 0.);
132 fSimElectF.resize(fNTicks/2+1);
133 fFFT->DoFFT(fSimElect, fSimElectF);
135 TH1D* hSimColField =
dynamic_cast<TH1D*
>(fsim.Get(
"daq/CollectionFieldResponse"));
136 hist_to_vector(hSimColField, fSimColField);
137 fSimColField.resize(fNTicks, 0.);
138 fSimColFieldF.resize(fNTicks/2+1);
139 fFFT->DoFFT(fSimColField, fSimColFieldF);
141 TH1D* hSimIndField =
dynamic_cast<TH1D*
>(fsim.Get(
"daq/InductionFieldResponse"));
142 hist_to_vector(hSimIndField, fSimIndField);
143 fSimIndField.resize(fNTicks, 0.);
144 fSimIndFieldF.resize(fNTicks/2+1);
145 fFFT->DoFFT(fSimIndField, fSimIndFieldF);
147 TH1D* hSimColConv =
dynamic_cast<TH1D*
>(fsim.Get(
"daq/ConvolutedCollection"));
148 hist_to_vector(hSimColConv, fSimColConv);
149 fSimColConv.resize(fNTicks, 0.);
150 fSimColConvF.resize(fNTicks/2+1);
151 fFFT->DoFFT(fSimColConv, fSimColConvF);
153 TH1D* hSimIndConv =
dynamic_cast<TH1D*
>(fsim.Get(
"daq/ConvolutedInduction"));
154 hist_to_vector(hSimIndConv, fSimIndConv);
155 fSimIndConv.resize(fNTicks, 0.);
156 fSimIndConvF.resize(fNTicks/2+1);
157 fFFT->DoFFT(fSimIndConv, fSimIndConvF);
161 fhicl::ParameterSet calwire_pset = pset.get<fhicl::ParameterSet>(
"calwire");
162 cet::search_path sp(
"FW_SEARCH_PATH");
163 sp.find_file(calwire_pset.get<std::string>(
"ResponseFile"), fCalFile);
164 std::cout <<
"CalWire file = " << fCalFile << std::endl;
166 TFile fcal(fCalFile.c_str());
168 TH2D* respRe =
dynamic_cast<TH2D*
>(fcal.Get(
"sim/RespRe"));
169 TH2D* respIm =
dynamic_cast<TH2D*
>(fcal.Get(
"sim/RespIm"));
170 int nx = respRe->GetNbinsX();
171 int ny = respRe->GetNbinsY();
172 assert(nx == respIm->GetNbinsX());
173 assert(ny == respIm->GetNbinsY());
176 fColDeconvF.resize(ny);
177 fIndDeconvF.resize(ny);
179 for(
int i=0; i<ny; ++i) {
180 double ac = respRe->GetBinContent(2, i+1);
181 double bc = respIm->GetBinContent(2, i+1);
185 double ai = respRe->GetBinContent(1, i+1);
186 double bi = respIm->GetBinContent(1, i+1);
193 art::TFileDirectory dirc = tfs->mkdir(
"Collection",
"Collection");
194 int nhist = std::min(200, fNTicks);
198 std::vector<double> tinc(fNTicks, 0.);
199 fill_delta(tinc, nhist/2);
200 TH1D* hinc = dirc.make<TH1D>(
"input",
"Collection Input", nhist+1, -0.5, nhist+0.5);
201 vector_to_hist(tinc, hinc);
205 std::vector<double> telectc(tinc);
206 fFFT->Convolute(telectc, fSimElectF);
207 TH1D* helectc = dirc.make<TH1D>(
"elect",
"Collection Electronics", nhist+1, -0.5, nhist+0.5);
208 vector_to_hist(telectc, helectc);
212 std::vector<double> tfieldc(tinc);
213 fill_delta(tfieldc, nhist/2);
214 fFFT->Convolute(tfieldc, fSimColFieldF);
215 TH1D* hfieldc = dirc.make<TH1D>(
"field",
"Collection Field", nhist+1, -0.5, nhist+0.5);
216 vector_to_hist(tfieldc, hfieldc);
220 std::vector<double> tbothc(tfieldc);
221 fFFT->Convolute(tbothc, fSimElectF);
222 TH1D* hbothc = dirc.make<TH1D>(
"both",
"Collection Field+Electronics", nhist+1, -0.5, nhist+0.5);
223 vector_to_hist(tbothc, hbothc);
227 double shift = fFFT->PeakCorrelation(tbothc, tinc);
228 std::cout <<
"Collection shift = " << shift << std::endl;
229 std::vector<double> tshiftc(tbothc);
230 fFFT->ShiftData(tshiftc, shift);
231 TH1D* hshiftc = dirc.make<TH1D>(
"shift",
"Collection Field+Electronics+Shift", nhist+1, -0.5, nhist+0.5);
232 vector_to_hist(tshiftc, hshiftc);
236 std::vector<double> tconvc(tinc);
237 fFFT->Convolute(tconvc, fSimColConvF);
238 TH1D* hconvc = dirc.make<TH1D>(
"conv",
"Collection Response", nhist+1, -0.5, nhist+0.5);
239 vector_to_hist(tconvc, hconvc);
243 std::vector<double> tdeconvc(tconvc);
244 fFFT->Convolute(tdeconvc, fColDeconvF);
245 TH1D* hdeconvc = dirc.make<TH1D>(
"deconv",
"Collection Deconvoluted", nhist+1, -0.5, nhist+0.5);
246 vector_to_hist(tdeconvc, hdeconvc);
250 art::TFileDirectory diri = tfs->mkdir(
"Induction",
"Induction");
254 std::vector<double> tini(fNTicks, 0.);
255 fill_delta(tini, nhist/2);
256 TH1D* hini = diri.make<TH1D>(
"input",
"Induction Input", nhist+1, -0.5, nhist+0.5);
257 vector_to_hist(tini, hini);
261 std::vector<double> telecti(tini);
262 fFFT->Convolute(telecti, fSimElectF);
263 TH1D* helecti = diri.make<TH1D>(
"elect",
"Induction Electronics", nhist+1, -0.5, nhist+0.5);
264 vector_to_hist(telecti, helecti);
268 std::vector<double> tfieldi(tini);
269 fFFT->Convolute(tfieldi, fSimIndFieldF);
270 TH1D* hfieldi = diri.make<TH1D>(
"field",
"Induction Field", nhist+1, -0.5, nhist+0.5);
271 vector_to_hist(tfieldi, hfieldi);
275 std::vector<double> tbothi(tfieldi);
276 fFFT->Convolute(tbothi, fSimElectF);
277 TH1D* hbothi = diri.make<TH1D>(
"both",
"Induction Field+Electronics", nhist+1, -0.5, nhist+0.5);
278 vector_to_hist(tbothi, hbothi);
282 shift = fFFT->PeakCorrelation(tbothi, tini);
283 std::cout <<
"Induction shift = " << shift << std::endl;
284 std::vector<double> tshifti(tbothi);
285 fFFT->ShiftData(tshifti, shift);
286 TH1D* hshifti = diri.make<TH1D>(
"shift",
"Induction Field+Electronics+Shift", nhist+1, -0.5, nhist+0.5);
287 vector_to_hist(tshifti, hshifti);
291 std::vector<double> tconvi(tini);
292 fFFT->Convolute(tconvi, fSimIndConvF);
293 TH1D* hconvi = diri.make<TH1D>(
"conv",
"Induction Response", nhist+1, -0.5, nhist+0.5);
294 vector_to_hist(tconvi, hconvi);
298 std::vector<double> tdeconvi(tconvi);
299 fFFT->Convolute(tdeconvi, fIndDeconvF);
300 TH1D* hdeconvi = diri.make<TH1D>(
"deconv",
"Induction Deconvoluted", nhist+1, -0.5, nhist+0.5);
301 vector_to_hist(tdeconvi, hdeconvi);
std::vector< TComplex > fSimIndConvF
std::vector< TComplex > fSimElectF
void analyze(const art::Event &evt)
std::vector< TComplex > fIndDeconvF
std::vector< double > fSimColField
std::vector< TComplex > fColDeconvF
std::vector< double > fSimIndConv
FFTTest(fhicl::ParameterSet const &pset)
std::vector< double > fSimElect
std::vector< double > fSimIndField
std::vector< TComplex > fSimColFieldF
std::vector< double > fSimColConv
std::vector< TComplex > fSimColConvF
std::vector< TComplex > fSimIndFieldF
art::ServiceHandle< art::TFileService > tfs
process_name can override from command line with o or output caldata
BEGIN_PROLOG could also be cout