00001 #include "PulseEstimate.hh"
00002
00003 #include "TH1.h"
00004 #include "TH2.h"
00005
00006 #include <iostream>
00007
00008 PulseEstimate::PulseEstimate() : fPedestal(0), fPolarity(1), fOffset(0) {}
00009
00010 void PulseEstimate::Estimate(TH2* pulses, TH1* timing) {
00011
00012 if (pulses && pulses->GetEntries()) {
00013 int nPreSamples = 10;
00014
00015
00016 TH1* pulses_proj_ped = pulses->ProjectionY("_ped", 1, nPreSamples);
00017 TH1* pulses_proj_pol = pulses->ProjectionY("_pol");
00018
00019
00020
00021
00022 static const int nBinsIgnore = 5;
00023 int nbins = pulses_proj_ped->GetXaxis()->GetNbins();
00024 pulses_proj_ped->GetXaxis()->SetRange(nBinsIgnore, nbins - nBinsIgnore);
00025
00026 fPedestal = (int)pulses_proj_ped->GetBinCenter(pulses_proj_ped->GetMaximumBin());
00027
00028 pulses_proj_ped->GetXaxis()->SetRange();
00029
00030
00031 int min = 0, max = 0;
00032 bool min_found = false, max_found = false;
00033
00034 for (int i = nBinsIgnore; i <= nbins - nBinsIgnore; ++i) {
00035 if (!min_found && pulses_proj_pol->GetBinContent(i) > 0.) {
00036 min_found = true;
00037 min = i;
00038 }
00039 if (!max_found && pulses_proj_pol->GetBinContent(nbins - i) > 0.) {
00040 max_found = true;
00041 max = nbins - i;
00042 }
00043 if (min_found && max_found)
00044 break;
00045 }
00046 if (max - fPedestal > fPedestal - min)
00047 fPolarity = 1;
00048 else
00049 fPolarity = -1;
00050 } else {
00051
00052 std::cout << "PulseEstimate ERROR: Cannot estimate nonexistent or empty shapes histogram!" << std::endl;
00053 fPedestal = 0;
00054 fPolarity = 1;
00055 }
00056
00057
00058
00059 if (timing && timing->GetEntries()) {
00060 int nRebins = 0;
00061 static int min_time_correlation_height = 10;
00062 while (timing->GetBinContent(timing->GetMaximumBin()) < min_time_correlation_height && nRebins++ < 3)
00063 timing->Rebin();
00064 fOffset = timing->GetBinCenter(timing->GetMaximumBin());
00065 } else {
00066
00067 std::cout << "PulseEstimate ERROR: Cannot estimate nonexistent or empty timing histogram!" << std::endl;
00068 fOffset = 0;
00069 }
00070 }
00071
00072 int PulseEstimate::GetPedestal() const {
00073 return fPedestal;
00074 }
00075
00076 int PulseEstimate::GetPolarity() const {
00077 return fPolarity;
00078 }
00079
00080 int PulseEstimate::GetOffset() const {
00081 return fOffset;
00082 }