All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
icarus_tool::FieldResponse Class Reference
Inheritance diagram for icarus_tool::FieldResponse:
icarus_tool::IFieldResponse

Public Member Functions

 FieldResponse (const fhicl::ParameterSet &pset)
 
 ~FieldResponse ()
 
void configure (const fhicl::ParameterSet &) override
 
void setResponse (double, double, double) override
 
void outputHistograms (art::TFileDirectory &) const override
 
size_t getPlane () const override
 
size_t getResponseType () const override
 
size_t getNumBins () const override
 
double getBinCenter (int bin) const override
 
double getBinContent (int bin) const override
 
double getLowEdge () const override
 
double getHighEdge () const override
 
double getBinWidth () const override
 
double getTOffset () const override
 
double getIntegral () const override
 
double interpolate (double x) const override
 
const icarusutil::TimeVecgetResponseVec () const override
 
const icarusutil::FrequencyVecgetResponseFFTVec () const override
 

Private Member Functions

std::string numberToString (int number)
 
- Private Member Functions inherited from icarus_tool::IFieldResponse
virtual ~IFieldResponse () noexcept=default
 

Private Attributes

bool fIsValid
 
size_t fThisPlane
 
size_t fResponseType
 
geo::SigType_t fSignalType
 
std::string fFieldResponseFileName
 
std::string fFieldResponseFileVersion
 
std::string fFieldResponseHistName
 
double fFieldResponseAmplitude
 
double fTimeCorrectionFactor
 
TH1D * fFieldResponseHist
 
icarusutil::TimeVec fFieldResponseVec
 
icarusutil::FrequencyVec fFieldResponseFFTVec
 
double fT0Offset
 
std::unique_ptr
< icarus_signal_processing::ICARUSFFT
< double > > 
fFFT
 Object to handle thread safe FFT. More...
 

Detailed Description

Definition at line 27 of file FieldResponse_tool.cc.

Constructor & Destructor Documentation

icarus_tool::FieldResponse::FieldResponse ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 88 of file FieldResponse_tool.cc.

88  :
89  fIsValid(false), fSignalType(geo::kMysteryType), fFFT(nullptr)
90 {
91  configure(pset);
92 }
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
Who knows?
Definition: geo_types.h:147
void configure(const fhicl::ParameterSet &) override
icarus_tool::FieldResponse::~FieldResponse ( )
inline

Definition at line 32 of file FieldResponse_tool.cc.

32 {}

Member Function Documentation

void icarus_tool::FieldResponse::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 94 of file FieldResponse_tool.cc.

95 {
96  // Start by recovering the parameters
97  fThisPlane = pset.get< size_t >("Plane");
98  fResponseType = pset.get< size_t >("ResponseType");
99  fSignalType = pset.get< size_t >("SignalType") == 0 ? geo::kInduction : geo::kCollection;
100  fFieldResponseFileName = pset.get< std::string >("FieldResponseFileName");
101  fFieldResponseFileVersion = pset.get< std::string >("FieldResponseFileVersion");
102  fFieldResponseHistName = pset.get< std::string >("FieldResponseHistName");
103  fFieldResponseAmplitude = pset.get< double >("FieldResponseAmplitude");
104  fTimeCorrectionFactor = pset.get< double >("TimeCorrectionFactor");
105 
106  // Recover the input field response histogram
107 // std::string fileName = fFieldResponseFileName + "_vw" + numberToString(fThisPlane) + "_" + fFieldResponseFileVersion + ".root";
108  std::string fileName = fFieldResponseFileName + "_vw" + numberToString(fResponseType) + "_" + fFieldResponseFileVersion + ".root";
109 
110  std::string fullFileName;
111  cet::search_path searchPath("FW_SEARCH_PATH");
112 
113  std::cout << "************************** Field Response Plane " << fThisPlane << " type: " << fResponseType << " *****************************" << std::endl;
114  std::cout << "FileName: " << fullFileName << std::endl;
115 
116  if (!searchPath.find_file(fileName, fullFileName))
117  throw cet::exception("FieldResponse::configure") << "Can't find input file: '" << fileName << "'\n";
118 
119  TFile inputFile(fullFileName.c_str(), "READ");
120 
121  if (!inputFile.IsOpen())
122  throw cet::exception("FieldResponse::configure") << "Unable to open input file: " << fileName << std::endl;
123 
124 // std::string histName = fFieldResponseHistName + "_vw" + numberToString(fThisPlane) + "_" + fFieldResponseFileVersion + ".root";
125  std::string histName = fFieldResponseHistName + "_vw" + numberToString(fResponseType) + "_" + fFieldResponseFileVersion + ".root";
126 
127  std::cout << "HistFile: " << histName << std::endl;
128 
129  fFieldResponseHist = (TH1D*)((TH1D*)inputFile.Get(histName.c_str()))->Clone();
130 
131  fFieldResponseHist->SetDirectory(nullptr);
132 
133  inputFile.Close();
134 
135  // Calculation of the T0 offset depends on the signal type
136  int binOfInterest = fFieldResponseHist->GetMinimumBin();
137 
138  // For collection planes it is as simple as finding the maximum bin
139  if (fSignalType == geo::kCollection) binOfInterest = fFieldResponseHist->GetMaximumBin();
140 
141  // Do a backwards search to find the first positive bin
142  while(1)
143  {
144  // Did we go too far?
145  if (binOfInterest < 0)
146  {
147  std::cout << "Cannot find zero-point crossover for induction response! Plane:" << fThisPlane << ", signal type: " << fSignalType << ", response type: " << fResponseType << std::endl;
148  throw cet::exception("FieldResponse::configure") << "Cannot find zero-point crossover for induction response! Plane:" << fThisPlane << ", signal type: " << fSignalType << ", response type: " << fResponseType << std::endl;
149  }
150 
151  double content = fFieldResponseHist->GetBinContent(binOfInterest);
152 
153  if (content >= 0.) break;
154 
155  binOfInterest--;
156  }
157 
158  fT0Offset = -(fFieldResponseHist->GetXaxis()->GetBinCenter(binOfInterest) - fFieldResponseHist->GetXaxis()->GetBinCenter(1)) * fTimeCorrectionFactor;
159 
160  fIsValid = true;
161 
162  // Hoops to jump throught to find "correct" size for FFT
163  // Find the next power of 2 that is larger than the vector we have
164  size_t newVecSize(64);
165 
166  while(getNumBins() > newVecSize) newVecSize *= 2;
167 
168  // Check that we have initialized our FFT object
169  fFFT = std::make_unique<icarus_signal_processing::ICARUSFFT<double>>(newVecSize);
170 
171  double integral = getIntegral();
172 
173  std::cout << "--> Plane: " << fThisPlane << ", integral: " << integral << std::endl;
174 
175  return;
176 }
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
std::string numberToString(int number)
Signal from induction planes.
Definition: geo_types.h:145
size_t getNumBins() const override
BEGIN_PROLOG could also be cout
double getIntegral() const override
Signal from collection planes.
Definition: geo_types.h:146
double icarus_tool::FieldResponse::getBinCenter ( int  bin) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 312 of file FieldResponse_tool.cc.

313 {
314  if (!fIsValid)
315  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
316 
317  return fFieldResponseHist->GetBinCenter(bin);
318 }
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double icarus_tool::FieldResponse::getBinContent ( int  bin) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 320 of file FieldResponse_tool.cc.

321 {
322  if (!fIsValid)
323  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
324 
325  return fFieldResponseHist->GetBinContent(bin);
326 }
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double icarus_tool::FieldResponse::getBinWidth ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 338 of file FieldResponse_tool.cc.

339 {
340  if (!fIsValid)
341  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
342 
343  return fFieldResponseHist->GetBinWidth(1) * fTimeCorrectionFactor;
344 }
double icarus_tool::FieldResponse::getHighEdge ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 328 of file FieldResponse_tool.cc.

329 {
330  if (!fIsValid)
331  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
332 
333  size_t nBins = getNumBins();
334 
335  return fFieldResponseHist->GetBinCenter(nBins) + 0.5 * fFieldResponseHist->GetBinWidth(nBins);
336 }
size_t getNumBins() const override
double icarus_tool::FieldResponse::getIntegral ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 354 of file FieldResponse_tool.cc.

355 {
356  if (!fIsValid)
357  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
358 
359  return fFieldResponseHist->Integral();
360 }
double icarus_tool::FieldResponse::getLowEdge ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 304 of file FieldResponse_tool.cc.

305 {
306  if (!fIsValid)
307  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
308 
309  return fFieldResponseHist->GetBinCenter(1) - 0.5 * fFieldResponseHist->GetBinWidth(1);
310 }
size_t icarus_tool::FieldResponse::getNumBins ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 296 of file FieldResponse_tool.cc.

297 {
298  if (!fIsValid)
299  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
300 
301  return fFieldResponseHist->GetXaxis()->GetNbins();
302 }
size_t icarus_tool::FieldResponse::getPlane ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 280 of file FieldResponse_tool.cc.

281 {
282  if (!fIsValid)
283  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
284 
285  return fThisPlane;
286 }
const icarusutil::FrequencyVec& icarus_tool::FieldResponse::getResponseFFTVec ( ) const
inlineoverridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 51 of file FieldResponse_tool.cc.

51 {return fFieldResponseFFTVec;}
icarusutil::FrequencyVec fFieldResponseFFTVec
size_t icarus_tool::FieldResponse::getResponseType ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 288 of file FieldResponse_tool.cc.

289 {
290  if (!fIsValid)
291  throw cet::exception("FieldResponse::getResponseType") << "Attempting to access response info when tool is invalid state" << std::endl;
292 
293  return fResponseType;
294 }
const icarusutil::TimeVec& icarus_tool::FieldResponse::getResponseVec ( ) const
inlineoverridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 50 of file FieldResponse_tool.cc.

50 {return fFieldResponseVec;}
icarusutil::TimeVec fFieldResponseVec
double icarus_tool::FieldResponse::getTOffset ( ) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 346 of file FieldResponse_tool.cc.

347 {
348  if (!fIsValid)
349  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
350 
351  return fT0Offset;
352 }
double icarus_tool::FieldResponse::interpolate ( double  x) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 362 of file FieldResponse_tool.cc.

363 {
364  if (!fIsValid)
365  throw cet::exception("FieldResponse::getPlane") << "Attempting to access plane info when tool is invalid state" << std::endl;
366 
367  Double_t intVal = fFieldResponseHist->Interpolate(x);
368 
369  return intVal; //fFieldResponseHist->Interpolate(x);
370 }
process_name opflash particleana ie x
std::string icarus_tool::FieldResponse::numberToString ( int  number)
private

Definition at line 372 of file FieldResponse_tool.cc.

373 {
374  std::ostringstream string;
375 
376  string << std::setfill('0') << std::setw(2) << number;
377 
378  return string.str();
379 }
void icarus_tool::FieldResponse::outputHistograms ( art::TFileDirectory &  histDir) const
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 212 of file FieldResponse_tool.cc.

213 {
214  // It is assumed that the input TFileDirectory has been set up to group histograms into a common
215  // folder at the calling routine's level. Here we create one more level of indirection to keep
216  // histograms made by this tool separate.
217  art::TFileDirectory dir = histDir.mkdir(fFieldResponseHistName.c_str());
218 
219  TProfile* hist = dir.make<TProfile>(fFieldResponseHistName.c_str(), "Field Response; Time(us)", getNumBins(), getLowEdge(), getHighEdge());
220 
221  double binWidth = getBinWidth() / fTimeCorrectionFactor;
222 
223  std::vector<double> histResponseVec(getNumBins());
224 
225  for(size_t idx = 0; idx < getNumBins(); idx++)
226  {
227  double xBin = getLowEdge() + idx * binWidth;
228  double binVal = fFieldResponseHist->GetBinContent(idx);
229 
230  hist->Fill(xBin, binVal, 1.);
231  histResponseVec.at(idx) = binVal;
232  }
233 
234  // Grab some useful tools
235  icarus_signal_processing::WaveformTools<double> waveformTool;
236 
237  // Make a copy of the response vec
238  std::vector<double> smoothedResponseVec;
239 
240  // Run the triangulation smoothing
241  waveformTool.triangleSmooth(histResponseVec, smoothedResponseVec);
242 
243  // Now make histogram of this
244  std::string histName = "Smooth_" + fFieldResponseHistName;
245 
246  TProfile* smoothHist = dir.make<TProfile>(histName.c_str(), "Field Response; Time(us)", getNumBins(), getLowEdge(), getHighEdge());
247 
248  for(size_t idx = 0; idx < smoothedResponseVec.size(); idx++)
249  {
250  double xBin = getLowEdge() + idx * binWidth;
251 
252  smoothHist->Fill(xBin,smoothedResponseVec.at(idx), 1.);
253  }
254 
255  // Get the FFT of the response
256  size_t halfFFTDataSize(fFieldResponseFFTVec.size()/2);
257 
258  std::vector<double> powerVec(halfFFTDataSize);
259 
260  std::transform(fFieldResponseFFTVec.begin(), fFieldResponseFFTVec.begin() + halfFFTDataSize, powerVec.begin(), [](const auto& val){return std::abs(val);});
261 
262  // Now we can plot this...
263  double maxFreq = 0.5 / binWidth; // binWidth will be in us, maxFreq will be units of MHz
264  double freqWidth = maxFreq / powerVec.size();
265 
266  histName = "FFT_" + fFieldResponseHistName;
267 
268  TProfile* fftHist = dir.make<TProfile>(histName.c_str(), "Field Response FFT; Frequency(MHz)", powerVec.size(), 0., maxFreq);
269 
270  for(size_t idx = 0; idx < powerVec.size(); idx++)
271  {
272  double bin = (idx + 0.5) * freqWidth;
273 
274  fftHist->Fill(bin, powerVec.at(idx), 1.);
275  }
276 
277  return;
278 }
static constexpr Sample_t transform(Sample_t sample)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double getLowEdge() const override
T abs(T value)
double getHighEdge() const override
size_t getNumBins() const override
tuple dir
Definition: dropbox.py:28
double getBinWidth() const override
icarusutil::FrequencyVec fFieldResponseFFTVec
void icarus_tool::FieldResponse::setResponse ( double  weight,
double  correction3D,
double  timeScaleFctr 
)
overridevirtual

Implements icarus_tool::IFieldResponse.

Definition at line 178 of file FieldResponse_tool.cc.

179 {
180  // This sets the field response in the time domain
181  double timeFactor = correction3D * timeScaleFctr;
182  size_t numBins = getNumBins();
183  size_t nResponseBins = numBins * timeFactor;
184 
185  fFieldResponseVec.resize(nResponseBins);
186 
187  double x0 = getBinCenter(1);
188  double deltaX = fFieldResponseHist->GetBinWidth(1); // This gets returned in us
189 
190  for(size_t bin = 1; bin <= nResponseBins; bin++)
191  {
192  double xVal = x0 + deltaX * (bin-1) / timeFactor;
193 
195  }
196 
197  // Find the next power of 2 that is larger than the vector we have
198  size_t newVecSize(64);
199 
200  while(fFieldResponseVec.size() > newVecSize) newVecSize *= 2;
201 
202  // Resize and pad with zeroes
203  fFieldResponseVec.resize(newVecSize,0.);
204 
205  fFieldResponseFFTVec.resize(newVecSize);
206 
208 
209  return;
210 }
double interpolate(double x) const override
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double > > fFFT
Object to handle thread safe FFT.
icarusutil::TimeVec fFieldResponseVec
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
double getBinCenter(int bin) const override
size_t getNumBins() const override
icarusutil::FrequencyVec fFieldResponseFFTVec

Member Data Documentation

std::unique_ptr<icarus_signal_processing::ICARUSFFT<double> > icarus_tool::FieldResponse::fFFT
private

Object to handle thread safe FFT.

Definition at line 83 of file FieldResponse_tool.cc.

double icarus_tool::FieldResponse::fFieldResponseAmplitude
private

Definition at line 67 of file FieldResponse_tool.cc.

icarusutil::FrequencyVec icarus_tool::FieldResponse::fFieldResponseFFTVec
private

Definition at line 77 of file FieldResponse_tool.cc.

std::string icarus_tool::FieldResponse::fFieldResponseFileName
private

Definition at line 64 of file FieldResponse_tool.cc.

std::string icarus_tool::FieldResponse::fFieldResponseFileVersion
private

Definition at line 65 of file FieldResponse_tool.cc.

TH1D* icarus_tool::FieldResponse::fFieldResponseHist
private

Definition at line 71 of file FieldResponse_tool.cc.

std::string icarus_tool::FieldResponse::fFieldResponseHistName
private

Definition at line 66 of file FieldResponse_tool.cc.

icarusutil::TimeVec icarus_tool::FieldResponse::fFieldResponseVec
private

Definition at line 74 of file FieldResponse_tool.cc.

bool icarus_tool::FieldResponse::fIsValid
private

Definition at line 58 of file FieldResponse_tool.cc.

size_t icarus_tool::FieldResponse::fResponseType
private

Definition at line 62 of file FieldResponse_tool.cc.

geo::SigType_t icarus_tool::FieldResponse::fSignalType
private

Definition at line 63 of file FieldResponse_tool.cc.

double icarus_tool::FieldResponse::fT0Offset
private

Definition at line 80 of file FieldResponse_tool.cc.

size_t icarus_tool::FieldResponse::fThisPlane
private

Definition at line 61 of file FieldResponse_tool.cc.

double icarus_tool::FieldResponse::fTimeCorrectionFactor
private

Definition at line 68 of file FieldResponse_tool.cc.


The documentation for this class was generated from the following file: