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

EventDisplay/GfxStripList.cxx

Go to the documentation of this file.
00001 #include "GfxStripList.h"
00002 #include "GfxStripListCfg.h"
00003 #include "GfxProxy.h"
00004 #include "GfxStripListMenu.h"
00005 #include "EVD.h"
00006 #include "ViewState.h"
00007 #include <TClonesArray.h>
00008 #include <Record/RecArrayAllocator.h>
00009 #include <Midad/Base/PageDisplay.h>
00010 #include <Midad/Base/Mint.h>
00011 #include <Midad/Base/Rainbow.h>
00012 #include <Midad/Base/DigitText.h>
00013 #include <Midad/Util/Range.h>
00014 #include <Midad/Gui/GuiSlider.h>
00015 #include <JobControl/JobC.h>
00016 #include <DataUtil/TruthHelper.h>
00017 #include <Record/SimSnarlRecord.h>
00018 #include <Record/SimSnarlHeader.h>
00019 //#include <Midad/Util/Util.h>
00020 
00021 #include <Conventions/Munits.h>
00022 
00023 #include <DataUtil/CDL2STL.h>
00024 using namespace DataUtil;
00025 
00026 #include <RecoBase/CandStripHandle.h>
00027 #include <RecoBase/CandStripListHandle.h>
00028 
00029 #include <MessageService/MsgService.h>
00030 CVSID("$Id: GfxStripList.cxx,v 1.10 2007/03/01 17:18:35 rhatcher Exp $");
00031 
00032 #include <Buttons.h> // part of ROOT
00033 
00034 #include <sigc++/sigc++.h>
00035 #include <sigc++/class_slot.h>
00036 using namespace SigC;
00037 
00038 #include <iostream>
00039 #include <string>
00040 using namespace std;
00041 
00042 
00043 GfxProxy<GfxStripList> 
00044 gsGfxStripListProxy("StripList", new GfxStripListMenu());
00045 
00046 
00051 GfxStripList::GfxStripList()
00052     : fCfg(0)
00053     , fColorRange(0)
00054     , fEVD(0)
00055     , fMint(0)
00056     , fHideStrips(false)
00057 {
00058     fCfg = new GfxStripListCfg();
00059     fCfg->modified_signal.connect
00060         (slot_class(*this,&GfxStripList::ReConfigure));
00061         RecArrayAllocator& a = RecArrayAllocator::Instance();
00062       fStripsCA = a.GetArray("GfxStrip");
00063 }
00064 
00065 GfxStripList::~GfxStripList()
00066 {
00067    RecArrayAllocator& a = RecArrayAllocator::Instance();
00068    if (fStripsCA) { a.ReleaseArray(fStripsCA); fStripsCA = 0; }
00069 }
00070 
00071 void GfxStripList::Init(PageDisplay& pd, EVD& mp)
00072 {
00073     fColorRange = &mp.GetColorRangeControl(this->GetPlaneView()).GetRange();
00074     ViewState* vs = this->GetViewState();
00075     vs->color_semantic.connect(slot_class(*this,&GfxStripList::ReConfigure));
00076     vs->spatial_metric.connect(slot_class(*this,&GfxStripList::ReConfigure));
00077     fPageDisplay = &pd;
00078     fEVD = &mp;
00079 }
00080 
00081 static bool select_strip(const CandStripHandle* csh, 
00082                          PlaneView::PlaneView_t view,
00083                          RangeDouble* time_range)
00084 {
00085   bool retval=false;
00086   if (!csh) return retval;
00087  
00088   if((csh->GetPlaneView() == view) && time_range->InRange(csh->GetTime()))retval=true;
00089   /* 
00090  if(cs){
00091     if(!cs->FindDaughter(csh))retval=false;
00092   }
00093   */
00094   return retval;
00095 }
00096 
00097 void GfxStripList::Configure(Mint& mint)
00098 {
00099     fMint = &mint;
00100     this->ClearStripList();
00101     if (fHideStrips) return;
00102     const CandStripListHandle* cslh = mint.GetStrips();
00103     if (!cslh) { 
00104       MSG("EVD",Msg::kVerbose) << "No CandStripList\n";
00105         return;
00106     }
00107 
00108     RangeDouble& time_range = 
00109         fPageDisplay->GetTimeSlider().GetRangeCtrl().GetRange();
00110  
00111     Mint::StripVector_t sv = CDL2STLvector<CandStripHandle>(*cslh);
00112 
00113     Mint::StripVector_t::iterator it, first = sv.begin(), middle, last = sv.end();
00114     Slot1<bool,const CandStripHandle*> s =
00115         bind(slot(select_strip),this->GetPlaneView(), &time_range);
00116     middle = std::partition(first,last,s);   
00117 
00118     for (it = first; it != middle; ++it) {
00119     
00120       bool addstrip=true;
00121       if(addstrip){
00122         int last = fStripsCA->GetLast()+1;
00123         new ((*fStripsCA)[last]) GfxStrip(**it,*this);     
00124         GfxStrip* gs = dynamic_cast<GfxStrip*>(fStripsCA->UncheckedAt(last));
00125         fStrips.push_back( gs);
00126       }
00127     }
00128     this->ReConfigure();
00129 }
00130 
00131 void GfxStripList::ReConfigure(void)
00132 {
00133     if (!fMint) return;
00134 
00135     if (fHideStrips) return;
00136 
00137     // configure all GfxStrips
00138     GfxStripVector_t::iterator it, done = fStrips.end();
00139     for (it = fStrips.begin(); it != done; ++it) (*it)->Configure();
00140 }
00141 
00142 void GfxStripList::Draw(Option_t *option)
00143 {
00145     GfxStripVector_t::iterator it, done = fStrips.end();
00146     for (it = fStrips.begin(); it != done; ++it) {
00147       if(GetEVD()->GetDrawAll() || GetEVD()->GetDrawGhosts()  || (*it)->GetColor()!=GetEVD()->GetGhostColor() ){
00148         (*it)->Draw(option);
00149       }
00150     }
00151 }
00152 
00153 
00154 // Private methods:
00155 void GfxStripList::ClearStripList()
00156 {
00157     fStrips.clear();
00158     fStripsCA->Clear("C");
00159 }
00160 
00161 void GfxStripList::ExecuteEvent(int event, int /*px */, int /*py*/, GfxStrip* gfx_strip)
00162 {
00163     switch (event) {
00164     case kMouseEnter: {
00165         const CandStripHandle& csh = gfx_strip->GetStrip();
00166         PlexStripEndId seid = csh.GetStripEndId();
00167         const char* s;
00168         SimSnarlRecord *ssr = 
00169           dynamic_cast<SimSnarlRecord*>(fMint->GetJobC().Mom.GetFragment("SimSnarlRecord"));
00170         if (ssr){
00171           TruthHelper truthHelp(&(fMint->GetJobC().Mom));
00172           s = Form("Strip:   (%s)  %d digit%s, plane=%d, demux charge=%.1f, t0=%.1f ns, <t>=%.1f ns,  Best NeuKin index match:%d", 
00173                                seid.AsString(),
00174                                csh.GetNDigit(), 
00175                                csh.GetNDigit() == 1 ? "" : "s",
00176                                csh.GetPlane(),
00177                                csh.GetCharge(), 
00178                                csh.GetBegTime()/Munits::ns, 
00179                                csh.GetTime()/Munits::ns,
00180                                truthHelp.GetBestNeuMatch(csh));
00181 
00182         }
00183         else{
00184           s = Form("Strip: %d digit%s, plane=%d, demux charge=%.1f, t0=%.1f ns, <t>=%.1f ns (%s)",
00185                                csh.GetNDigit(), csh.GetNDigit() == 1 ? "" : "s",
00186                                csh.GetPlane(),
00187                                csh.GetCharge(), csh.GetBegTime()/Munits::ns, 
00188                                csh.GetTime()/Munits::ns, seid.AsString());
00189         }
00190         text_info.emit(s);
00191 
00192         vector<const CandDigitHandle*> dv = CDL2STLvector<CandDigitHandle>(csh);
00193         int siz = dv.size();
00194         if (!siz) break;
00195 
00196         DigitText* dt = fPageDisplay->GetDigitText();
00197         if (dt) {
00198             dt->Clear();
00199             for (int ind=0; ind < siz; ++ind)
00200                 dt->AddCandDigitText(*dv[ind]);
00201         }
00202          DigitText* JAMdt = fEVD->GetDigitText();
00203         if (JAMdt) {
00204             JAMdt->Clear();
00205             for (int ind=0; ind < siz; ++ind)
00206                 JAMdt->AddCandDigitText(*dv[ind]);
00207         }
00208       if (fMint) {
00209             fMint->SetPickedStrip(csh);
00210             fMint->SetSelectedDigits(dv);
00211         }
00212         
00213         break;
00214     }
00215     default: // nothing
00216         break;
00217     }
00218 }
00219 
00220 bool GfxStripList::StripMasked(const CandStripHandle& csh) const
00221 {
00222     if (!fColorRange) return false;
00223 
00224     double val=0;
00225     switch (this->GetViewState()->GetColorSemantic()) {
00226     case ViewState::color_is_time:
00227         val = csh.GetTime();
00228         break;
00229     case ViewState::color_is_charge:
00230         val = csh.GetCharge();
00231         break;
00232     default:
00233         return false;
00234         break;
00235     }
00236 
00237     bool ret = fColorRange->InRange(val);
00238     return !ret;
00239 }
00240 
00241 int GfxStripList::GetStripColor(const CandStripHandle& csh) const
00242 {
00243     if (!fColorRange) return false;
00244 
00245     static Rainbow rainbow;
00246 
00247     if (this->StripMasked(csh)) return 0;
00248 
00249     double val=0;
00250     switch (this->GetViewState()->GetColorSemantic()) {
00251     case ViewState::color_is_time:
00252         val = csh.GetTime();
00253         break;
00254     case ViewState::color_is_charge:
00255         val = csh.GetCharge();
00256         break;
00257     default:
00258         return 0;
00259         break;
00260     }
00261     return rainbow.GetRelativeColor(fColorRange->Relative(val));
00262 }
00263 void GfxStripList::HideStrips(bool hide)
00264 {
00265     fHideStrips = hide;
00266     this->ReConfigure();
00267     if(GetGraphicsView()==GraphicsView::kVZ)fEVD->UpdateCanvas();
00268 }

Generated on Sat Nov 21 22:46:17 2009 for loon by  doxygen 1.3.9.1