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

Mint.cxx

Go to the documentation of this file.
00001 #include "Mint.h"
00002 #include "MCint.h"
00003 #include "PageDisplay.h"
00004 #include "PageDisplayConfig.h"
00005 
00006 #include <Midad/Gui/GuiMainWindow.h>
00007 #include <Midad/Gui/GuiButton.h>
00008 
00009 #include <JobControl/JobC.h>
00010 #include <CandData/CandHeader.h>
00011 #include <CandDigit/CandDigitListHandle.h>
00012 #include <RecoBase/CandStripHandle.h>
00013 #include <RecoBase/CandStripListHandle.h>
00014 #include <RecoBase/CandTrackListHandle.h>
00015 #include <RecoBase/CandShowerListHandle.h>
00016 #include <Plex/PlexSEIdAltL.h>
00017 #include <CandDigit/CandDigitHandle.h>
00018 
00019 #include <DataUtil/GetUgliGeomHandle.h>
00020 #include <DataUtil/GetCandidate.h>
00021 #include <DataUtil/GetCandHeader.h>
00022 #include <DataUtil/GetDetector.h>
00023 #include <DataUtil/CDL2STL.h>
00024 #include <Util/LoadMinosPDG.h>
00025 
00026 #include <TSystem.h>
00027 #include <TTimer.h>
00028 
00029 #include <sigc++/sigc++.h>
00030 #include <sigc++/class_slot.h>
00031 
00032 using namespace SigC;
00033 
00034 #include <vector>
00035 #include <iostream>
00036 using namespace std;
00037 
00038 Mint* gMint = 0;
00039 
00040 ClassImp(Mint)
00041 
00042 Mint::Mint(JobC& jc)
00043     : fJint(jc)
00044     , fMCint(0)
00045     , fFreeRunning(false)
00046     , fPause(0)
00047     , fTimer(0)
00048 {
00049     fTimeRange = manage(new Range<double>());
00050     fTimeExtrema = manage(new Range<double>());
00051     fChargeRange = manage(new Range<double>());
00052     fChargeExtrema = manage(new Range<double>());
00053     gMint = this;
00054     fMCint = new MCint(*this);
00055     fJint.mom_modified.connect(slot_class(*this,&Mint::NewMom));
00056 
00057     fCandidateLookup.UnLockValues();
00058     fCandidateLookup.Set("CandDigitList","");
00059     fCandidateLookup.Set("CandStripList","");
00060     fCandidateLookup.Set("CandTrackList","");
00061     fCandidateLookup.Set("CandShowerList","");
00062 
00063     // get the TDatabasePDG initialized and populated
00064     LoadMinosPDG();
00065 }
00066 
00067 Mint::~Mint() 
00068 {
00069 }
00070 
00071 JobC& Mint::GetJobC() const
00072 {
00073     return fJint.GetJobC();
00074 }
00075 MCint& Mint::GetMCint() const
00076 {
00077     return *fMCint;
00078 }
00079 PageDisplay* Mint::SpawnDisplay(int width, int height,
00080                                 const PageDisplayConfig* cfg)
00081 {
00082 
00083     GuiMainWindow* gmw = new GuiMainWindow(width-1,height-1);
00084     gmw->SetWindowName("Midad");
00085 
00086     PageDisplay* pd = new PageDisplay(*gmw,this);
00087     PageDisplayConfig default_pdc;
00088     if (!cfg) cfg = &default_pdc;
00089     pd->Init(*cfg);
00090     pd->close_window.connect(slot(*gmw,&GuiMainWindow::SendCloseMessage));
00091     fJint.mom_modified.connect(slot(*pd,&PageDisplay::ClearDisplay));
00092     fJint.mom_modified.connect(slot(*pd,&PageDisplay::UpdateDisplay));
00093                                     
00094     gmw->Add(*pd);
00095 
00096     gmw->ShowAll();
00097 //    gmw->SetMinSize();
00098     gmw->Resize(width,height);
00099     gmw->ConnectClose(true);     // delete
00100 
00101     fDisplays.push_back(pd);
00102 
00103     return pd;
00104 }
00105 PageDisplay* Mint::GetDisplay(int which /*=0*/)
00106 {
00107     int ndisps = fDisplays.size();
00108 
00109     if (which < 0 || which >= ndisps) {
00110         cerr << "Can't get display #" << which 
00111              << ", (have " << ndisps << ")\n";
00112         return 0;
00113     }
00114     return fDisplays[which];
00115 }
00116 
00117 class MyTimer : public TTimer {
00118 public:
00119 
00120     MyTimer(Mint* mint, Mint::MintMoveMeth_t move)
00121         : TTimer(), fMint(mint), fMove(move) {}
00122 
00123     virtual Bool_t Notify() {
00124         (fMint->*fMove)();
00125         delete this;
00126         return kTRUE;
00127     }
00128 private:
00129     Mint* fMint;
00130     Mint::MintMoveMeth_t fMove;
00131 
00132 };
00133 
00134 void Mint::DoMovement(Mint::MintMoveMeth_t move)
00135 {
00136     if (fFreeRunning) {
00137         for (unsigned int ind = 0; ind < fDisplays.size(); ++ind) 
00138             fDisplays[ind]->ProcessEvents();
00139 
00140         if (fFreeRunning) {     // still?
00141             if (fPause <= 0)  { (this->*move)(); }
00142             else { 
00143                 MyTimer* mt = new MyTimer(this,move); // launch timer
00144                 mt->Start(fPause, kTRUE);
00145             }
00146         }
00147     }
00148     
00149 }
00150 
00151 void Mint::Next()
00152 {
00153     fJint.Next();
00154     this->DoMovement(&Mint::Next);
00155 }
00156 void Mint::NextPass()
00157 {
00158     fJint.NextPass();
00159     this->DoMovement(&Mint::NextPass);
00160 }
00161 void Mint::Prev()
00162 {
00163     fJint.Prev();
00164     this->DoMovement(&Mint::Prev);
00165 }
00166 void Mint::GoTo(int run, int snarl)
00167 {
00168     fJint.GoTo(run,snarl);
00169 }
00170 
00171 void Mint::SetFreeRunning(bool tf)
00172 {
00173     fFreeRunning = tf;
00174     if (fFreeRunning) 
00175         cerr << "Will free run - click Next/Prev button\n";
00176     else
00177         cerr << "Free run stopped after next event\n";
00178 }
00179 
00180 void Mint::SetPause(Long_t ms)
00181 {
00182     fPause = ms;
00183     cerr << "SetPause(" << ms << ")\n";
00184 }
00185 
00186 
00187 void Mint::NewMom()
00188 {
00189     this->DumpMom();
00190 //    fSelectedDigits.clear();
00191     fPickedDigit = 0;
00192 //    this->UpdateStripRanges();
00193     this->UpdateDigitRanges();
00194     if (fMCint) fMCint->Update();
00195 }
00196     
00197 void Mint::DumpMom()
00198 {
00199     const MomNavigator* mom = fJint.GetMom();
00200     if (!mom) {
00201         cerr << "Mint::DumpMom: no MOM!\n";
00202         return;
00203     }
00204 
00205     CandRecord* crec = dynamic_cast<CandRecord*>
00206         (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00207     if (!crec) {
00208         cerr << "Mint::DumpMom: no CandRecord\n";
00209         return;
00210     }
00211 
00212     const TObjArray oa = crec->GetCandHandleList();
00213     int last = oa.GetLast();
00214     cerr << "Contents of PrimaryCandidateRecord:\n";
00215     for (int i = 0; i <= last; ++i) {
00216         TObject* o = oa.At(i);
00217         if (!o) continue;
00218         CandHandle* ch = dynamic_cast<CandHandle*>(o);
00219         if (!ch) {
00220             cerr << "\t" << o->ClassName() << " not a CandHandle\n";
00221             continue;
00222         }
00224 //        if (!ch->GetCandBase()) {
00225 //            cerr << "\t" << 0->ClassName() << " doesn't have a CandBase!!!\n";
00226 //            continue;
00227 //        }
00228         cerr << "\t" << o->ClassName() << "::" << o->GetName()<< endl;
00229     }
00230     
00231 }
00232 
00233 UgliGeomHandle Mint::GetUgliGeomHandle()
00234 {
00235     return DataUtil::GetUgliGeomHandle(&(this->GetJobC().Mom));
00236 }
00237 
00238 
00239 // For now, just hard code stuff.
00240 CandDigitListHandle* Mint::GetDigits() const
00241 {
00242     const char* name = 0;
00243     fCandidateLookup.Get("CandDigitList",name);
00244     return DataUtil::GetCandidate<CandDigitListHandle>
00245         (&(this->GetJobC().Mom),"CandDigitListHandle",name);
00246 }
00247 CandStripListHandle* Mint::GetStrips() const
00248 {
00249     const char* name = 0;
00250     fCandidateLookup.Get("CandStripList",name);
00251     return DataUtil::GetCandidate<CandStripListHandle>
00252         (&(this->GetJobC().Mom),"CandStripListHandle",name);
00253 }
00254 CandTrackListHandle* Mint::GetTracks() const
00255 {
00256     const char* name = 0;
00257     fCandidateLookup.Get("CandTrackList",name);
00258     return DataUtil::GetCandidate<CandTrackListHandle>
00259         (&(this->GetJobC().Mom),"CandTrackListHandle",name);
00260 }
00261 CandShowerListHandle* Mint::GetShowers() const
00262 {
00263     const char* name = 0;
00264     fCandidateLookup.Get("CandShowerList",name);
00265     return DataUtil::GetCandidate<CandShowerListHandle>
00266         (&(this->GetJobC().Mom),"CandShowerListHandle",name);
00267 }
00268 
00269 
00270 Detector::Detector_t Mint::GetDetector() const
00271 {
00272     Detector::Detector_t dt = 
00273         DataUtil::GetDetector(this->GetJobC().Mom);
00274     return dt;
00275 }
00276 
00277 void Mint::UpdateStripRanges()
00278 {
00279     Detector::Detector_t det = this->GetDetector();
00280     if (det == Detector::kUnknown) return;
00281 
00282     const CandStripListHandle* cslh = this->GetStrips();
00283     if (!cslh) return;
00284 
00285     vector<const CandStripHandle*> dv = 
00286         DataUtil::CDL2STLvector<CandStripHandle>(*cslh);
00287     int siz = dv.size();
00288     if (! siz) return;
00289 
00290     double tmin=0, tmax=0, qmin=0,qmax=0;
00291     bool first = true;
00292     for (int ind = 0; ind < siz; ++ind) {
00293         const CandStripHandle* csh = dv[ind];
00294         double t = csh->GetTime();
00295         double q = csh->GetCharge();
00296         if (first) {
00297             tmin = tmax = t;
00298             qmin = qmax = q;
00299             first=false;
00300             continue;
00301         }
00302         if (t < tmin) tmin = t;
00303         if (t > tmax) tmax = t;
00304         if (q < qmin) qmin = q;
00305         if (q > qmax) qmax = q;
00306     }
00307 
00308     if (!first) {
00309         // work around div by zero in TGDoubleSlider
00310         double eps = 1.0e-10;
00311         if (tmin == tmax) { tmin -= eps; tmax += eps; }
00312         if (qmin == qmax) { qmin -= eps; qmax += eps; }
00313 
00314         fTimeRange->Set(tmin,tmax);
00315         fTimeExtrema->Set(tmin,tmax);
00316         fChargeRange->Set(qmin,qmax);
00317         fChargeExtrema->Set(qmin,qmax);
00318     }
00319 }
00320 
00321 void Mint::UpdateDigitRanges()
00322 {
00323     Detector::Detector_t det = this->GetDetector();
00324     if (det == Detector::kUnknown) return;
00325 
00326     const CandDigitListHandle* cslh = this->GetDigits();
00327     if (!cslh) return;
00328 
00329     vector<const CandDigitHandle*> dv = 
00330         DataUtil::CDL2STLvector<CandDigitHandle>(*cslh);
00331     int siz = dv.size();
00332     if (! siz) return;
00333 
00334     double tmin=0, tmax=0, qmin=0,qmax=0;
00335     bool first = true;
00336 
00337     for (int ind = 0; ind < siz; ++ind) {
00338         const CandDigitHandle* csh = dv[ind];
00339         const PlexSEIdAltL& altl = csh->GetPlexSEIdAltL();
00340         PlaneView::PlaneView_t pv = altl.GetPlaneView();
00341         if (det != Detector::kCalib && 
00342            pv != PlaneView::kU && pv != PlaneView::kV) continue;
00343 
00344         altl.SetFirst();
00345         while (altl.IsValid()) {
00346           double t = altl.GetCurrentItem().GetTime();
00347           double q = altl.GetCurrentItem().GetPE();
00348           if (first) {
00349               tmin = tmax = t;
00350               qmin = qmax = q;
00351               first=false;
00352               continue;
00353           }
00354           if (t < tmin) tmin = t;
00355           if (t > tmax) tmax = t;
00356           if (q < qmin) qmin = q;
00357           if (q > qmax) qmax = q;
00358           altl.Next();
00359         }
00360     }
00361     // give some buffer at either end...
00362     tmax +=  0.02*(tmax - tmin);
00363     tmin += -0.02*(tmax - tmin);
00364     qmax +=  0.02*(qmax - qmin);
00365     qmin += -0.02*(qmax - qmin);
00366 
00367     // cerr << endl; 
00368     // cerr << " tmin, tmax = " << tmin << "  " << tmax << endl;
00369     // cerr << " qmin, qmax = " << qmin << "  " << qmax << endl;
00370     if (!first) {
00371         // work around div by zero in TGDoubleSlider
00372         double eps = 1.0e-8;
00373         if (tmin == tmax) { tmin -= eps; tmax += eps; }
00374         if (qmin == qmax) { qmin -= eps; qmax += eps; }
00375 
00376         fTimeRange->Set(tmin,tmax);
00377         fTimeExtrema->Set(tmin,tmax);
00378         fChargeRange->Set(qmin,qmax);
00379         fChargeExtrema->Set(qmin,qmax);
00380     }
00381 }
00382 
00383 
00384 void Mint::SetSelectedDigits(Mint::DigitVector_t dv)
00385 {
00386     fSelectedDigits = dv;
00387     digits_selected.emit();
00388 }
00389 Mint::DigitVector_t Mint::GetSelectedDigits(void) const
00390 {
00391     return fSelectedDigits;
00392 }
00393 void Mint::SetPickedDigit(const CandDigitHandle& cdh)
00394 {
00395     fPickedDigit = &cdh;
00396     digit_picked.emit();
00397 }
00398 void Mint::SetPickedDigit(const CandDigitHandle& cdh,
00399                           const PlexSEIdAltLItem& /*itm*/)
00400 {
00401     fPickedDigit = &cdh;
00402     digit_picked.emit();
00403 }
00404 const CandDigitHandle* Mint::GetPickedDigit() const
00405 {
00406     return fPickedDigit;
00407 }
00408 
00409 
00410 void Mint::SetSelectedStrips(Mint::StripVector_t dv)
00411 {
00412     fSelectedStrips = dv;
00413     strips_selected.emit();
00414 }
00415 Mint::StripVector_t Mint::GetSelectedStrips(void) const
00416 {
00417     return fSelectedStrips;
00418 }
00419 void Mint::SetPickedStrip(const CandStripHandle& cdh)
00420 {
00421     fPickedStrip = &cdh;
00422     strip_picked.emit();
00423 }
00424 const CandStripHandle* Mint::GetPickedStrip() const
00425 {
00426     return fPickedStrip;
00427 }
00428 

Generated on Mon Feb 15 11:07:01 2010 for loon by  doxygen 1.3.9.1