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

EventDisplay/GfxStrip.cxx

Go to the documentation of this file.
00001 #include "GfxStrip.h"
00002 #include "GfxStripList.h"
00003 #include "GfxStripListCfg.h"
00004 #include "ViewState.h"
00005 #include <Midad/Base/Mint.h>
00006 #include <Midad/Util/Util.h>
00007 #include "EVD.h"
00008 #include <UgliGeometry/UgliGeomHandle.h>
00009 #include <UgliGeometry/UgliStripHandle.h>
00010 
00011 #include <RecoBase/CandStripHandle.h>
00012 
00013 #include <TEllipse.h>
00014 #include <TBox.h>
00015 #include <TPad.h>
00016 
00017 #include <iostream>
00018 using namespace std;
00019 
00020 ClassImp(GfxStrip)
00021 
00022 #if 0
00023 GfxStrip::GfxStrip()
00024     : fStrip(0)
00025       ,fParent(0)
00026       ,fImp(0)
00027 {
00028 }
00029 #endif
00030 GfxStrip::GfxStrip(const CandStripHandle& csh, GfxStripList& parent)
00031     : fStrip(&csh)
00032       ,fParent(&parent)
00033       ,fImp(0)
00034 {
00035 }
00036 GfxStrip::GfxStrip(const GfxStrip& rhs)
00037     : TObject(),
00038       fStrip(rhs.fStrip), fParent(rhs.fParent), fImp(0)
00039 {
00040 }
00041 GfxStrip& GfxStrip::operator=(const GfxStrip& rhs)
00042 {
00043     if (this == &rhs) return *this;
00044     fStrip = rhs.fStrip;
00045     fParent = rhs.fParent;
00046     fImp = 0;
00047     return *this;
00048 }
00049 
00050 GfxStrip::~GfxStrip()
00051 {
00052     this->Clear();
00053 }
00054 
00055 void GfxStrip::Clear(const Option_t*)
00056 {
00057   if (fImp) delete fImp; fImp=0;
00058 }
00059 bool GfxStrip::GetRealCoords(double& cx, double& cy, double& dx, double& dy)
00060 {
00061     UgliGeomHandle ugh(*fStrip->GetVldContext());
00062     UgliStripHandle ush = ugh.GetStripHandle(fStrip->GetStripEndId());
00063     if (!ush.IsValid()) return false;
00064 
00065     cx = ush.GlobalPos(0).Z();
00066     cy = ush.GetTPos();
00067     dx = 1.5*ush.GetHalfThickness();
00068     dy = 1.5*ush.GetHalfWidth();
00069     return true;
00070 }
00071 bool GfxStrip::GetDiscreteCoords(double& cx, double& cy, double& dx, double& dy)
00072 {
00073     PlexStripEndId seid = fStrip->GetStripEndId();
00074     cx = seid.GetPlane();
00075     cy = seid.GetStrip();
00076     dx = 1.5;
00077     dy = 1.5;
00078     return true;
00079 }
00080 
00081 float GfxStrip::GetRelativeValue(GfxStripListCfg::MeasureScale_t ms)
00082 {
00083     if (ms == GfxStripListCfg::kCharge) {
00084         RangeDouble& qrange = fParent->GetMint().GetChargeRange();
00085         double den = qrange.Min() - qrange.Max();
00086         if (den > 0)
00087             return (fStrip->GetCharge() - qrange.Min()) / den;
00088     }
00089     else {                      // time
00090         RangeDouble& trange = fParent->GetMint().GetTimeRange();
00091         double den = trange.Max() - trange.Min();
00092         if (den > 0)
00093             return (fStrip->GetTime() - trange.Min()) / den;
00094     }
00095     return 1.0;
00096 }
00097 
00098 void GfxStrip::ModifyCoords(double& cx, double& cy, double& dx, double& dy)
00099 {
00100     int strip_sign = 0;
00101     StripEnd::StripEnd_t end = fStrip->GetStripEndId().GetEnd();
00102     if (end == StripEnd::kNegative) strip_sign = -1;
00103     if (end == StripEnd::kPositive) strip_sign = +1;
00104 
00105     GfxStripListCfg& cfg = fParent->GetCfg();
00106     
00107     // Scale down size of strip
00108     GfxStripListCfg::SizeBy_t sb = cfg.GetSizeBy();
00109     double size_scale = this->GetRelativeValue(cfg.GetSizeIs());
00110 
00111     size_scale *= cfg.GetSizeFactor();
00112 
00113     switch (sb) {
00114     case GfxStripListCfg::kFixed:
00115         // nothing
00116         break;
00117     case GfxStripListCfg::kLinear:
00118         dx *= size_scale;
00119         dy *= size_scale;
00120         break;
00121     case GfxStripListCfg::kLogLinear:
00122         dx *= logify_relative(size_scale);
00123         dy *= logify_relative(size_scale);
00124         break;
00125     case GfxStripListCfg::kLogArea:
00126         dx *= logify_relative(sqrt(size_scale));
00127         dy *= logify_relative(sqrt(size_scale));
00128         break;
00129     case GfxStripListCfg::kArea: default:
00130         dx *= sqrt(size_scale);
00131         dy *= sqrt(size_scale);
00132         break;
00133     }
00134 
00135     // modify for any odd shape
00136     GfxStripListCfg::StripEnd_t si = cfg.GetStripEnd();
00137     switch (si) {
00138     case GfxStripListCfg::kHalf:
00139         dy *= strip_sign * 0.5;
00140         cy += dy;
00141         break;
00142     case GfxStripListCfg::kBowTie:
00143         dx *= strip_sign * 0.5;
00144         dy *= strip_sign * 0.5;
00145         cx += dx;
00146         cy += dy;
00147         break;
00148     case GfxStripListCfg::kFull: 
00149         // fall through
00150     case GfxStripListCfg::kBit:
00151         // fall through
00152     default:
00153         // do nothing
00154         break;
00155     }    
00156 }
00157 
00158 bool GfxStrip::SetColor()
00159 {
00160   int fColor=fParent->GetStripColor(*fStrip);
00161   Bool_t ghost=false;
00162 
00163   if(fParent->GetEVD()->GetCandSlice()){
00164     TIter stripItr(fParent->GetEVD()->GetCandSlice()->GetDaughterIterator());
00165     while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
00166            (stripItr())){
00167       if(strip){
00168         CandStripHandle csh1 = *strip;
00169         CandStripHandle csh2 = *fStrip;
00170         if(csh1==csh2 ||  csh1.IsCloneOf(csh2)){
00171           ghost=true;
00172           break;
00173         }
00174       }
00175       
00176     } 
00177   }
00178   else if (fParent->GetEVD()->GetCandEvent()){
00179  
00180     ghost=true;
00181     TIter stripItr(fParent->GetEVD()->GetCandEvent()->GetDaughterIterator());
00182     while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
00183            (stripItr())){
00184       if(strip){
00185         CandStripHandle csh = *strip;
00186         if(*strip==*fStrip ||  fStrip->IsCloneOf(csh)){
00187           ghost=true;
00188           break;
00189         }
00190       }
00191     }
00192   }
00193   if(!ghost){
00194     fColor = fParent->GetStripColor(*fStrip);
00195     if(fStrip->GetCharge(CalDigitType::kPE)<5)fColor=10;
00196     if(fStrip->GetCharge(CalDigitType::kPE)<2)fColor=20;
00197 
00198   }
00199   else{
00200     fColor=fParent->GetEVD()->GetGhostColor();
00201   }
00202   if (!fColor) {
00203     return false;
00204   }
00205 
00206 
00207     TAttFill* att_fill = dynamic_cast<TAttFill*>(fImp);
00208     if (!att_fill) return false;
00209     att_fill->SetFillColor(fColor);
00210     TAttLine* att_line = dynamic_cast<TAttLine*>(fImp);
00211     if (!att_line) return false;
00212     att_line->SetLineColor(fColor);
00213     att_line->SetLineWidth(1);
00214     return true;
00215 }
00216 
00217 void GfxStrip::Configure()
00218 {
00219 
00220     // here we make our imp.
00221     if (fImp) { delete fImp; fImp = 0; }
00222 
00223     GfxStripListCfg& cfg = fParent->GetCfg();
00224 
00225     fCx = fCy = fDx = fDy = 0.0;
00226 
00227 
00228     switch (fParent->GetViewState()->GetSpatialMetric()) {
00229     case ViewState::metric_is_continuous:
00230         this->GetRealCoords(fCx,fCy,fDx,fDy);
00231         break;
00232     case ViewState::metric_is_discreet: default:
00233         this->GetDiscreteCoords(fCx,fCy,fDx,fDy);
00234         break;
00235     }
00236 
00237 
00238     double dx = fDx, dy = fDy;
00239     if (cfg.GetScaleIs() == GfxStripListCfg::kAbsolute) {
00240         fDx = 1.5;
00241         fDy = 6.0;
00242         this->ModifyCoords(fCx,fCy,fDx,fDy);
00243         this->RelToAbs(dx,dy);
00244     }
00245     else {
00246         this->ModifyCoords(fCx,fCy,fDx,fDy);
00247     }
00248     switch (cfg.GetShapeIs()) {
00249     case GfxStripListCfg::kEllipse: 
00250         fImp = new TEllipse(fCx,fCy,dx,dy);
00251         break;
00252     default:
00253         fImp = new TBox(fCx+dx,fCy+dy,fCx-dx,fCy-dy);
00254         break;
00255     }
00256 
00257     TAttFill* att_fill = dynamic_cast<TAttFill*>(fImp);
00258     if (att_fill) {
00259       att_fill->SetFillStyle(1001);
00260     } 
00261 
00262 //    cerr << "GfxStrip::Configure (" << cx << "," << cy << ")\n";
00263 
00264 }
00265 
00266 
00267 void GfxStrip::ExecuteEvent(int event, int px, int py)
00268 {
00269     fParent->ExecuteEvent(event,px,py,this);
00270 }
00271 void GfxStrip::Paint(Option_t* option)
00272 {
00273     if (!fImp) return;
00274 
00275     if (!this->SetColor()) return;
00276 
00277 
00278     GfxStripListCfg& cfg = fParent->GetCfg();
00279     if (cfg.GetScaleIs() == GfxStripListCfg::kAbsolute) {
00280         double dx, dy;
00281         this->RelToAbs(dx,dy);
00282 
00283         switch (cfg.GetShapeIs()) {
00284         case GfxStripListCfg::kEllipse: {
00285             TEllipse* el= dynamic_cast<TEllipse*>(fImp);
00286             el->SetR1(dx);
00287             el->SetR2(dy);
00288             el->Paint(option);
00289             break;
00290         }
00291         default:
00292             TBox* box = dynamic_cast<TBox*>(fImp);
00293             box->SetX1(fCx+dx);
00294             box->SetY1(fCy+dy);
00295             box->SetX2(fCx-dx);
00296             box->SetY2(fCy-dy);
00297             box->Paint();
00298             break;
00299         }
00300     }
00301     else {
00302         fImp->Paint(option);
00303     }
00304 }
00305 int GfxStrip::DistancetoPrimitive(int px, int py)
00306 {
00307     if (fImp) return fImp->DistancetoPrimitive(px,py);
00308     return 0xdead;
00309 }
00310 
00311 void GfxStrip::RelToAbs(double& dx, double& dy)
00312 {
00313     dx = gPad->AbsPixeltoX((int)fDx) - gPad->AbsPixeltoX(0);
00314     dy = gPad->AbsPixeltoY((int)fDy) - gPad->AbsPixeltoY(0);
00315 //    cerr << Form("dx=%f(%f)  dy=%f(%f)",fDx,dx,fDy,dy) << endl;
00316 }
00317 
00318 void GfxStrip::ConfigGui(void)
00319 {
00320     if (!fParent) return;
00321     GfxStripListCfg& cfg = fParent->GetCfg();
00322     cfg.GuiConfig();
00323 
00324 }

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