00001 #include "TTemplateConvolveAnalysedPulse.h"
00002 #include "TLine.h"
00003 #include "InterpolatePulse.h"
00004 #include <algorithm>
00005 #include "debug_tools.h"
00006 #include <TF1.h>
00007 #include <TPaveText.h>
00008 #include "EventNavigator.h"
00009
00010 TTemplateConvolveAnalysedPulse::TTemplateConvolveAnalysedPulse():TAnalysedPulse(),
00011 fNPeaks(0), fPeakRank(0), fIntegralRatio(0){}
00012
00013 TTemplateConvolveAnalysedPulse::TTemplateConvolveAnalysedPulse(
00014 const IDs::source& sourceID, const TPulseIslandID& parentID, const TPulseIsland* parentTPI):
00015 TAnalysedPulse(sourceID,parentID,parentTPI),
00016 fNPeaks(0), fPeakRank(0), fIntegralRatio(0)
00017 {}
00018
00019 TTemplateConvolveAnalysedPulse::~TTemplateConvolveAnalysedPulse(){
00020 }
00021
00022 void TTemplateConvolveAnalysedPulse::Draw(const TH1F* tpi_pulse)const{
00023
00024
00025 if(!tpi_pulse) return;
00026
00027 std::string name(tpi_pulse->GetName());
00028
00030 TH1F* energy_hist=functions::VectorToHist(fEnergySamples,name+"_energy","Convolution with template");
00031
00033 TH1F* time_hist=functions::VectorToHist(fTimeSamples,name+"_time","First derivative of convolution with template");
00034
00035
00036 int polarity=EventNavigator::GetSetupRecord().GetPolarity(GetSource().Channel());
00037 double bottom= GetPedestal() - (polarity>0?0:GetAmplitude());
00038 double top= GetPedestal() + (polarity>0?GetAmplitude():0);
00039 TLine* line=new TLine(GetTime(), bottom, GetTime(), top);
00040 line->SetLineColor(kRed);
00041 tpi_pulse->GetListOfFunctions()->Add(line->Clone());
00042
00043 line->SetX1(fTimeOffset);
00044 line->SetX2(fTimeOffset);
00045 line->SetY1(0);
00046 line->SetY2(fAmplitudeScale);
00047
00048 energy_hist->GetListOfFunctions()->Add(line);
00049 time_hist->GetListOfFunctions()->Add(line->Clone());
00050
00051 TPaveText* text_b=new TPaveText(0.7,0.60,0.9,0.9,"NB NDC");
00052 text_b->AddText(Form("A = %g",GetAmplitude()));
00053 text_b->AddText(Form("t = %g",GetTime()));
00054 text_b->AddText(Form("a = %g",fQuad));
00055 text_b->AddText(Form("b = %g",fLinear));
00056 text_b->AddText(Form("c = %g",fConstant));
00057 text_b->SetFillColor(kWhite);
00058 text_b->SetBorderSize(1);
00059 energy_hist->GetListOfFunctions()->Add(text_b);
00060
00061 TF1* fit=new TF1("Fit","[0]*(x-[3])**2+[1]*(x-[3])+[2]", 0 , energy_hist->GetNbinsX());
00062 fit->SetParameter(0,fQuad);
00063 fit->SetParameter(1,fLinear);
00064 fit->SetParameter(2,fConstant);
00065 fit->SetParameter(3,fTimeOffset );
00066 energy_hist->GetListOfFunctions()->Add(fit);
00067 energy_hist->Write();
00068 time_hist->Write();
00069
00070
00071
00072 }