00001 #include "InterpolatePulse.h"
00002
00003 #include <TH1D.h>
00004 #include <stdexcept>
00005 #include "TPulseIsland.h"
00006 #include "TSetupData.h"
00007 #include "SetupNavigator.h"
00008 #include <algorithm>
00009
00010 TH1D* functions::InterpolatePulse(
00011 const TPulseIsland* pulse, std::string histname,
00012 std::string histtitle, bool interpolate, int refine) {
00013
00014
00015 const std::string& bankname = pulse->GetBankName();
00016 const std::string detname = TSetupData::Instance()->GetDetectorName(bankname);
00017 const std::vector<int>& theSamples = pulse->GetSamples();
00018 int n_samples = theSamples.size();
00019 int n_bins = refine*n_samples;
00020
00021
00022 TH1D* hist = new TH1D(histname.c_str(), histtitle.c_str(), n_bins, 0, n_samples);
00023
00024 double pedestal_error = SetupNavigator::Instance()->GetNoise(detname);
00025
00026
00027
00028 for (int i = 0; i < n_bins; ++i) {
00029 int bin = i+1;
00030 int sample_number = i / refine;
00031 double remainder = i % refine;
00032 double sample_value;
00033
00034
00035 if (interpolate) {
00036 try {
00037 sample_value = theSamples.at(sample_number)
00038 + (remainder / refine)*(theSamples.at(sample_number+1)
00039 - theSamples.at(sample_number));
00040 }
00041 catch (const std::out_of_range& oor) {
00042 sample_value = theSamples.at(sample_number);
00043 }
00044 }
00045 else {
00046 sample_value = theSamples.at(sample_number);
00047 }
00048
00049
00050 hist->SetBinContent( bin, sample_value);
00051 hist->SetBinError( bin, pedestal_error);
00052 }
00053 hist->SetDirectory(0);
00054
00055 return hist;
00056 }
00057
00058 namespace{
00059 struct unique_n{
00060 int operator() () { return current+=step; }
00061 int current;
00062 const int step;
00063 unique_n(int b,int s):current(b),step(s){}
00064 };
00065 }
00066
00067 void functions::FillBinLabels(double* labels, int size, int start, int increment){
00068 unique_n uniq(start,increment);
00069 std::generate_n(labels,size, uniq);
00070 }