00001 #include "StripHist.h"
00002
00003 #include <TGraph.h>
00004 #include <TH1D.h>
00005
00006 using namespace std;
00007
00008 StripHist::StripHist(const char* name, const char* title)
00009 : fStrip(new TGraph)
00010 , fHist(new TH1D)
00011 , fStripRange(0)
00012 , fMaxStripEntries(0)
00013 , fYtitle("")
00014 {
00015 fStrip->SetName(Form("%s Strip Chart",name));
00016 fStrip->SetTitle(title);
00017 fHist->SetName(Form("%s Histogram",name));
00018 fHist->SetTitle(title);
00019 }
00020
00021 StripHist::StripHist(const char* name, const char* title,
00022 int nbin, double minbin, double maxbin)
00023 : fStrip(new TGraph)
00024 , fHist(new TH1D(Form("%s Histogram",name),title,nbin,minbin,maxbin))
00025 , fStripRange(0)
00026 , fMaxStripEntries(0)
00027 {
00028 fStrip->SetName(Form("%s Strip Chart",name));
00029 fStrip->SetTitle(title);
00030 }
00031
00032 void StripHist::SetLineColor(int color)
00033 {
00034 if(color >=0 && color <= 50) fStrip->SetLineColor(color);
00035 }
00036
00037 void StripHist::Draw(Option_t* option)
00038 {
00039 TVirtualPad* pad = gPad, *oldpad = gPad;
00040
00041 pad->Divide(1,2);
00042 pad->cd(1);
00043 fHist->Draw();
00044 pad->cd(2);
00045 fStrip->Draw(option);
00046 oldpad->cd();
00047 }
00048
00049 void StripHist::DrawStrip(Option_t* option)
00050 {
00051 TVirtualPad* pad = gPad, *oldpad = gPad;
00052
00053 pad->cd();
00054 fStrip->Draw(option);
00055 oldpad->cd();
00056 }
00057
00058 void StripHist::DrawHist(Option_t* option)
00059 {
00060 TVirtualPad* pad = gPad, *oldpad = gPad;
00061
00062 pad->cd();
00063 fHist->Draw(option);
00064 oldpad->cd();
00065 }
00066
00067 void StripHist::Fill(double x, double y, double histweight)
00068 {
00069 fHist->Fill(y,histweight);
00070
00071 if (fStripRange>0) {
00072 for (int n = fStrip->GetN();
00073 n > 2 && fStrip->GetX()[n-1]-fStrip->GetX()[0] > fStripRange;
00074 n = fStrip->GetN()) {
00075 fStrip->RemovePoint(0);
00076 }
00077 }
00078
00079 if (fMaxStripEntries) {
00080
00081 for (int n = fStrip->GetN(); n > fMaxStripEntries; n = fStrip->GetN()) {
00082 fStrip->RemovePoint(0);
00083 }
00084 }
00085
00086 fStrip->SetPoint(fStrip->GetN(),x,y);
00087
00088
00089
00090 TH1F* frame = fStrip->GetHistogram();
00091 TAxis* axis = frame->GetXaxis();
00092 axis->SetTimeDisplay(1);
00093 axis->SetTimeFormat("%b %d %H:%M:%S %Z");
00094 axis->SetNdivisions(202,false);
00095 axis->SetAxisColor(2);
00096 TH1F* frame2 = fStrip->GetHistogram();
00097 TAxis* axis2 = frame2->GetYaxis();
00098 axis2->SetTitle(fYtitle.c_str());
00099 axis2->CenterTitle();
00100
00101 }
00102
00103 void StripHist::SetGraphYTitle(const char* title)
00104 {
00105 fYtitle = title;
00106 }
00107
00108 void StripHist::SetStripRange(double range)
00109 {
00110 fStripRange = range;
00111 }
00112 void StripHist::SetMaxStripEntries(int max)
00113 {
00114 fMaxStripEntries = max;
00115 }
00116
00117 void StripHist::Reset()
00118 {
00119 fHist->Reset();
00120 for(int i=0; i<fStrip->GetN(); i++) {
00121 fStrip->RemovePoint(i);
00122 }
00123 }
00124
00125 double StripHist::GetMax()
00126 {
00127 if(fStrip->GetN() == 0) return 0.0;
00128 double max = 0.0, x = 0.0, y = 0.0;
00129 for(int i=0; i<fStrip->GetN(); i++) {
00130 fStrip->GetPoint(i, x, y);
00131 if(y > max) max = y;
00132 }
00133 return max;
00134 }
00135
00136 double StripHist::GetMin()
00137 {
00138 if(fStrip->GetN() == 0) return 0.0;
00139 double max = this->GetMax();
00140 double min = max, x = 0.0, y = 0.0;
00141 for(int i=0; i<fStrip->GetN(); i++) {
00142 fStrip->GetPoint(i, x, y);
00143 if(y < min) min = y;
00144 }
00145 return min;
00146 }
00147