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

PmtPixels.cxx

Go to the documentation of this file.
00001 #include "PmtPixels.h"
00002 #include "Mint.h"
00003 #include <Midad/Util/Range.h>
00004 #include <Midad/Util/RangeControl.h>
00005 
00006 #include <CandDigit/CandDigitHandle.h>
00007 
00008 #include <TList.h>
00009 #include <TBox.h>
00010 
00011 #include <sigc++/class_slot.h>
00012 
00013 #include <iostream>
00014 using namespace std;
00015 
00016 // PmtPixels: main object
00017 PmtPixels::PmtPixels()
00018     : TPad("PmtPixels","Signals in the PMT",0,0,1,1)
00019     , fImp(0)
00020 {
00021     cerr << "PmtPixels()\n";
00022 }
00023 PmtPixels::PmtPixels(double x1, double y1, double x2, double y2)
00024     : TPad("PmtPixels","Signals in the PMT",x1,y1,x2,y2)
00025     , fImp(0)
00026 {
00027     cerr << "PmtPixels()\n";
00028 }
00029 
00030 PmtPixels::~PmtPixels()
00031 {
00032 }
00033 
00034 void PmtPixels::SetMint(Mint* mint)
00035 {
00036     fCon.disconnect();
00037     this->MintView::SetMint(mint);
00038     fCon = mint->digits_selected.connect
00039         (SigC::slot_class(*this,&PmtPixels::Refresh));
00040 }
00041 
00042 void PmtPixels::BuildImp()
00043 {
00044     // This build the implementation.  It is assumed that we only need
00045     // to build it once.
00046 
00047 
00048     Detector::Detector_t det_type = this->GetMint().GetDetector();
00049 
00050     switch (det_type) {
00051     case Detector::kNear:
00052         this->cd();
00053         fImp = new PmtPixelsMxx(8);
00054         break;
00055     case Detector::kFar:
00056         this->cd();
00057         fImp = new PmtPixelsMxx(4);
00058         break;
00059     default:
00060         delete fImp;
00061         fImp = 0;
00062         cerr << "PmtPixels::BuildImp() unknown detector type: " 
00063              << det_type << endl;
00064         break;
00065     }
00066 }
00067 
00068 void PmtPixels::Refresh()
00069 {
00070     if (!fImp) this->BuildImp();
00071     if (!fImp) return;
00072 
00073 
00074     const CandDigitHandle* cdh = this->GetMint().GetPickedDigit();
00075         
00076     if (!cdh) return;
00077 
00078     PlexPixelSpotId ppsid = 
00079         cdh->GetPlexSEIdAltL().GetBestItem().GetPixelSpotId();
00080 
00081     RangeDouble& rd = this->GetMint().GetChargeRange();
00082     double relval = rd.Relative(cdh->GetCharge());
00083 
00084     fImp->Clear();
00085     fImp->SetPixelSpot(ppsid,relval);
00086 
00087     this->TPad::Modified();
00088     this->TPad::Update();
00089 
00090     // get data from Mint and feed the imp.
00091 }
00092 
00093 
00094 
00095 // PmtSpot: one fiber
00096 PmtSpot::PmtSpot(int /*spot_num*/, double xc, double yc, double radius)
00097     : TEllipse(xc,yc,radius,radius)
00098 {
00099     this->TEllipse::SetFillStyle(1001);
00100     this->SetRelativeColor(0);
00101 }
00102 PmtSpot::~PmtSpot()
00103 {
00104 }
00105 
00106 void PmtSpot::SetRelativeColor(double relval)
00107 {
00108     static Rainbow rainbow;
00109     this->TEllipse::SetFillColor(rainbow.GetRelativeColor(relval));
00110 }
00111 
00112 
00113 // PmtPixel: one pixel = box + spots
00114 PmtPixel::PmtPixel(int /*pixel_num*/, double xc, double yc, double w, double h)
00115     : TBox(xc-0.5*w, yc-0.5*h, xc+0.5*w, yc+0.5*h)
00116 {
00117     double r = 0.5*(w+h);       // normally, expect w == h.
00118     r /= 6.0;                   // assume pmt pixel is 3 fibers wide
00119     
00120     const double dy = r*sqrt(3.0);
00121     
00122     this->push_back(new PmtSpot(1,xc+2*r, yc+dy,r));
00123     this->push_back(new PmtSpot(2,xc,     yc+dy,r));
00124     this->push_back(new PmtSpot(3,xc-2*r, yc+dy,r));
00125 
00126     this->push_back(new PmtSpot(4,xc+r,   yc,    r));
00127     this->push_back(new PmtSpot(5,xc-r,   yc,    r));
00128 
00129     this->push_back(new PmtSpot(6,xc+2*r, yc-dy,r));
00130     this->push_back(new PmtSpot(7,xc,     yc-dy,r));
00131     this->push_back(new PmtSpot(8,xc-2*r, yc-dy,r));
00132 }
00133 
00134 PmtPixel::~PmtPixel()
00135 {
00136     iterator it, done = this->end();
00137     for (it = this->begin(); it != done; ++it) {
00138         PmtSpot* ps = (*it);
00139         delete ps;
00140         (*it) = 0;
00141     }
00142 
00143 }
00144     
00145 void PmtPixel::Draw(Option_t* opt)
00146 {
00147     this->TBox::Draw(opt);
00148     this->TBox::SetFillStyle(0);
00149     this->TBox::SetLineColor(1);
00150     
00151     iterator it, done = this->end();
00152     for (it = this->begin(); it != done; ++it) {
00153         PmtSpot* ps = (*it);
00154         ps->Draw(opt);
00155     }
00156 }
00157 
00158 // Base class for the full PMT worth of pixels
00159 PmtPixelsMxx::PmtPixelsMxx(int pixels_wide /*=4*/)
00160 {
00161     int pixel_num = 0;
00162     // The width in some units
00163     const double real_width = 1.0;
00164     // border around each pixel
00165     const double d = 0.01*real_width; 
00166     // The width of one pixel
00167     const double w = (real_width - (2.0*pixels_wide)*d)/(pixels_wide);
00168 
00169     // indices origin is in upper right.  
00170     for (int yind = 0; yind < pixels_wide; ++yind) {
00171         double yc = (2*(pixels_wide-yind)-1)*(0.5*w+d);
00172 
00173         for (int xind = 0; xind < pixels_wide; ++xind) {
00174             double xc = (2*(pixels_wide-xind)-1)*(0.5*w+d);
00175 
00176             PmtPixel* pixel = new PmtPixel(pixel_num,xc,yc,w,w);
00177             this->push_back(pixel);
00178             pixel->Draw();
00179         }
00180     }
00181 
00182 }
00183 
00184 PmtPixelsMxx::~PmtPixelsMxx() 
00185 {
00186     iterator it, done = this->end();
00187     for (it = this->begin(); it != done; ++it) {
00188         PmtPixel* pp = (*it);
00189         delete pp;
00190         *it = 0;
00191     }
00192 }
00193 
00194 void PmtPixelsMxx::Clear()
00195 {
00196     iterator it, done = this->end();
00197     for (it = this->begin(); it != done; ++it) {
00198         PmtPixel* pp = *it;
00199         
00200         PmtPixel::iterator ppit, ppdone = pp->end();
00201         for (ppit = pp->begin(); ppit != ppdone; ++ppit) {
00202             PmtSpot* ps = *ppit;
00203             ps->SetRelativeColor(0);
00204         }
00205     }
00206 }
00207 
00208 void PmtPixelsMxx::SetPixelSpot(const PlexPixelSpotId& ppsid, double relval)
00209 {
00210     int pixel = ppsid.GetPixel();
00211     int spot = ppsid.GetSpot();
00212 
00213     (*(*this)[pixel])[spot]->SetRelativeColor(relval);
00214 }
00215 

Generated on Mon Nov 23 05:28:04 2009 for loon by  doxygen 1.3.9.1