00001 #include "EventNavigator.h"
00002 #include "TTemplateFitAnalysedPulse.h"
00003 #include "TPaveText.h"
00004 #include "TMarker.h"
00005 #include "TH1F.h"
00006 #include "Functions.h"
00007 #include "debug_tools.h"
00008
00009 TTemplateFitAnalysedPulse::TTemplateFitAnalysedPulse(
00010 const IDs::source& sourceID, const TPulseIslandID& parentID, const TPulseIsland* parentTPI):
00011 TAnalysedPulse(sourceID,parentID,parentTPI),
00012 fResidual(NULL), fHisto(NULL),fIsPileUpPulse(false),fOtherPulse(NULL){}
00013
00014 TTemplateFitAnalysedPulse::~TTemplateFitAnalysedPulse(){
00015
00016 }
00017
00018 void TTemplateFitAnalysedPulse::Draw(const TH1F* tpi_pulse)const{
00019 if(tpi_pulse) {
00020 std::string name=tpi_pulse->GetName();
00021 name+="_templateAP";
00022 TH1F* tap_pulse=(TH1F*)GetHisto()->Clone(name.c_str());
00023 tap_pulse->SetDirectory(TDirectory::CurrentDirectory());
00024
00025 TPaveText* text_b=new TPaveText(0.7,0.60,0.9,0.9,"NB NDC");
00026 text_b->AddText(Form("#chi^2 = %3.2g",GetChi2()));
00027 text_b->AddText(Form("Status = %d",GetFitStatus()));
00028 text_b->AddText(Form("Time = %g",GetTime()));
00029 text_b->AddText(Form("Ampl. = %g",GetAmplitude()));
00030 text_b->AddText(Form("NDoF = %d",GetNDoF()));
00031 text_b->SetFillColor(kWhite);
00032 text_b->SetBorderSize(1);
00033 tap_pulse->GetListOfFunctions()->Add(text_b);
00034
00035 TH1F* tap_pulse2=NULL;
00036 if(fOtherPulse && !fIsPileUpPulse){
00037 name+="2";
00038 tap_pulse2=(TH1F*)fOtherPulse->GetHisto()->Clone(name.c_str());
00039 tap_pulse2->SetDirectory(TDirectory::CurrentDirectory());
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 TH1F* residual=(TH1F*) tpi_pulse->Clone(Form("%s_residual",tpi_pulse->GetName()));
00049 TH1F* tap_rebinned=(TH1F*) tap_pulse->Rebin(GetTemplate()->GetRefineFactor(),Form("%s_rebin",tap_pulse->GetName()));
00050 residual->Add(tap_rebinned, -1./GetTemplate()->GetRefineFactor());
00051 if(tap_pulse2) {
00052 delete tap_rebinned;
00053 tap_rebinned=(TH1F*) tap_pulse2->Rebin(GetTemplate()->GetRefineFactor(),Form("%s_rebin",tap_pulse->GetName()));
00054 residual->Add(tap_rebinned, -1./GetTemplate()->GetRefineFactor());
00055 }
00056 double integral=residual->Integral(5,residual->GetNbinsX()-5);
00057 text_b->AddText(Form("Total residue = %g",integral));
00058 delete tap_rebinned;
00059
00060 }
00061 }
00062
00063 const TH1F* TTemplateFitAnalysedPulse::GetHisto()const{
00064 if(fHisto) return fHisto;
00065
00066 std::string name=Form("Pulse_%s_%4lld_%3d_templateAP",
00067 GetSource().Channel().str().c_str(),
00068 EventNavigator::Instance().EntryNo(),
00069 GetParentID());
00070 int num_samples=GetTPILength()*GetTemplate()->GetRefineFactor();
00071 TH1F* tap_pulse=new TH1F(name.c_str(), name.c_str(),num_samples,0,GetTPILength());
00072 for ( int i=0; i<num_samples; i++){
00073 double height=GetBinContent(i);
00074 tap_pulse->SetBinContent(i,height);
00075 }
00076 tap_pulse->SetDirectory(0);
00077
00078 fHisto=tap_pulse;
00079 return fHisto;
00080 }
00081
00082 double TTemplateFitAnalysedPulse::GetBinContent(int bin)const{
00083
00084 int tpl_bin=GetTime()-GetTemplate()->GetTime()/GetTemplate()->GetRefineFactor()+bin;
00085
00086 double sample=GetTemplate()->GetHisto()->GetBinContent(tpl_bin);
00087
00088 return sample*GetAmplitude() + GetPedestal();
00089 }
00090