Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

HistDisp.cxx

Go to the documentation of this file.
00001 #include "HistDisp.h"
00002 
00003 #include <DataUtil/GetDetectorBins.h>
00004 using namespace DataUtil;
00005 
00006 #include <TCanvas.h>
00007 #include <TH2D.h>
00008 #include <TView.h>
00009 #include <TProfile.h>
00010 
00011 #include <iostream>
00012 using namespace std;
00013 
00014 HistDisp::HistDisp(UgliGeomHandle ugh, TPad* pad)
00015 {
00016     int nzbins=0, nwbins=0;
00017     double zmin=0,zmax=0,wmin=0,wmax=0;
00018 
00019     GetDetectorBinsZ(ugh,nzbins,zmin,zmax);
00020     cerr << nzbins << " " << zmin << " " << zmax << endl;
00021 
00022     GetDetectorBinsUV(ugh,PlaneView::kU,nwbins,wmin,wmax);
00023     cerr << nwbins << " " << wmin << " " << wmax << endl;
00024     fHquz[0] = new TH2D("quz","Charge/strip in U vs. Z",
00025                         nzbins,zmin,zmax,nwbins,wmin,wmax);
00026 
00027     GetDetectorBinsUV(ugh,PlaneView::kV,nwbins,wmin,wmax);
00028     cerr << nwbins << " " << wmin << " " << wmax << endl;
00029     fHqvz[0] = new TH2D("qvz","Charge/strip in V vs. Z",
00030                         nzbins,zmin,zmax,nwbins,wmin,wmax);
00031 
00032     if (pad) fPad = pad;
00033     else fPad = new TCanvas("hdc","HistDisp Canvas",800,800);
00034     this->Init();
00035 }
00036 
00037 HistDisp::HistDisp(int nubins, double umin, double umax,
00038                    int nvbins, double vmin, double vmax, 
00039                    int nzbins, double zmin, double zmax)
00040 {
00041     fHquz[0] = new TH2D("quz","Charge in U vs. Z",
00042                         nzbins,zmin,zmax,nubins,umin,umax);
00043     fHquz[0]->SetXTitle("Z (meter)");
00044     fHquz[0]->SetYTitle("U (meter)");
00045     fHquz[0]->SetZTitle("Charge");
00046     fHquz[0]->SetStats(false);
00047 
00048     fHqvz[0] = new TH2D("qvz","Charge in V vs. Z",
00049                         nzbins,zmin,zmax,nvbins,vmin,vmax);
00050     fHqvz[0]->SetXTitle("Z (meter)");
00051     fHqvz[0]->SetYTitle("U (meter)");
00052     fHqvz[0]->SetZTitle("Charge");
00053     fHqvz[0]->SetStats(false);
00054 
00055     fPad = new TCanvas("hdc","HistDisp Canvas",800,800);
00056     this->Init();
00057 }
00058 
00059 void HistDisp::Init()
00060 {
00061     fPad->Divide(2,2);
00062     this->Clear();
00063 }
00064 
00065 HistDisp::~HistDisp()
00066 {
00067     if (fHquz[0]) delete fHquz[0]; fHquz[0]=0;
00068     if (fHqvz[0]) delete fHqvz[0]; fHqvz[0]=0;
00069 }
00070 
00071 
00072 void HistDisp::FillU(double u, double z, double q, double t)
00073 {
00074     t=0;                        // unused warning
00075     for (int ind=1;ind<=2; ++ind) fHquz[ind]->Fill(z,u,q);
00076 }
00077 void HistDisp::FillV(double v, double z, double q, double t)
00078 {
00079     t=0;                        // unused warning
00080     for (int ind=1;ind<=2; ++ind) fHqvz[ind]->Fill(z,v,q);
00081 }
00082 
00083 void HistDisp::Clear()
00084 {
00085     fPad->cd(1);
00086     fHquz[1] = (TH2D*)fHquz[0]->DrawCopy("lego2");
00087     fPad->cd(2);
00088     fHqvz[1] = (TH2D*)fHqvz[0]->DrawCopy("lego2");
00089     fPad->cd(3);
00090     fHquz[2] = (TH2D*)fHquz[0]->DrawCopy("colz");
00091     fPad->cd(4);
00092     fHqvz[2] = (TH2D*)fHqvz[0]->DrawCopy("colz");
00093 }
00094 
00095 void HistDisp::Update()
00096 {
00097     for (int ind=1; ind<=4; ++ind) fPad->cd(ind)->Modified();
00098     fPad->cd();
00099     fPad->Modified();
00100     fPad->Update();
00101 }
00102 
00103 void HistDisp::SetRotation(double deg_polar, double deg_azimuth)
00104 {
00105     for (int ind=1;ind<=2;++ind) {
00106         fPad->cd(ind);          // ROOT has 
00107         TVirtualPad* p = gPad;  // the weirdest 
00108         TView* v = p->GetView(); // fuckin API
00109         v->RotateView(deg_polar,deg_azimuth,p);
00110     }
00111 }
00112 
00113 
00114 static bool find_bounds(TH2D* h, int &min_bin, int &max_bin, bool isx)
00115 {
00116     min_bin=max_bin=0;
00117 
00118     TProfile* p = 0;
00119     if (isx) 
00120         p = h->ProfileX();
00121     else
00122         p = h->ProfileY();
00123 
00124     int bin=0, nbins = p->GetNbinsX();
00125 
00126     for(bin = 1; bin < nbins; ++bin) {
00127         if (0.0 != p->GetBinContent(bin)) break;
00128     }
00129     if (bin == nbins) return false;
00130     for( ; nbins > bin; --nbins) {
00131         if (0.0 != p->GetBinContent(nbins)) break;
00132     }
00133     if (bin == nbins) return false;
00134     min_bin = bin;
00135     max_bin = nbins;
00136     cerr << "["<<min_bin<<","<<max_bin<<"] isx? " << isx << endl;
00137     return true;
00138 }
00139 
00140 void HistDisp::AutoZoom()
00141 {
00142     int umin=0,umax=0,zumin=0,zumax=0;
00143     find_bounds(fHquz[1],umin,umax,false);
00144     find_bounds(fHquz[1],zumin,zumax,true);
00145 
00146     int vmin=0,vmax=0,zvmin=0,zvmax=0;
00147     find_bounds(fHqvz[1],vmin,vmax,false);
00148     find_bounds(fHqvz[1],zvmin,zvmax,true);
00149 
00150     int zmin=zumin, zmax=zumax;
00151     if (zvmin < zmin) zmin = zvmin;
00152     if (zvmax > zmax) zmax = zvmax;
00153 
00154     for (int ind=1; ind<=2; ++ind) {
00155         fHquz[ind]->GetYaxis()->SetRange(umin,umax);
00156         fHqvz[ind]->GetYaxis()->SetRange(vmin,vmax);
00157 
00158         fHquz[ind]->GetXaxis()->SetRange(zmin,zmax);
00159         fHqvz[ind]->GetXaxis()->SetRange(zmin,zmax);
00160     }
00161         
00162 }
00163 
00164 void HistDisp::Zoom(double umin, double umax,
00165                     double vmin, double vmax, 
00166                     double zmin, double zmax)
00167 {
00168     
00169 
00170     for (int ind=1; ind<=2; ++ind) {
00171         fHquz[ind]->SetAxisRange(umin,umax,"Y");
00172         fHqvz[ind]->SetAxisRange(vmin,vmax,"Y");
00173 
00174         fHquz[ind]->SetAxisRange(zmin,zmax,"X");
00175         fHqvz[ind]->SetAxisRange(zmin,zmax,"X");
00176     }
00177 }
00178 
00179 void HistDisp::Unzoom()
00180 {
00181     for (int ind=1; ind<=2; ++ind) {
00182         fHquz[ind]->GetYaxis()->SetRange(1,fHquz[ind]->GetNbinsY());
00183         fHqvz[ind]->GetYaxis()->SetRange(1,fHqvz[ind]->GetNbinsY());
00184 
00185         fHquz[ind]->GetXaxis()->SetRange(1,fHquz[ind]->GetNbinsX());
00186         fHqvz[ind]->GetXaxis()->SetRange(1,fHqvz[ind]->GetNbinsX());
00187     }
00188 }

Generated on Mon Feb 15 11:06:47 2010 for loon by  doxygen 1.3.9.1