GUI/TFndEvd.h

00001 // @(#)fROOT/GUI:$Name:  $:$Id: TFndEvd.h,v 1.28 2007/09/07 14:05:24 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/07/31
00003 
00004 #ifndef FROOT_TFndEvd
00005 #define FROOT_TFndEvd
00006 
00007 #ifndef ROOT_Gtypes
00008 #include "Gtypes.h"
00009 #endif
00010 
00011 #include "TInterpreter.h"
00012 // --- root GUI
00013 #include <TGWindow.h>
00014 #include <TGFrame.h>
00015 #include <TGFileDialog.h>
00016 #include <TGMenu.h>
00017 #include <TGButton.h>
00018 #include <TGClient.h>
00019 #include <TGTextEntry.h>
00020 #include <TGNumberEntry.h>
00021 #include <TGListBox.h>
00022 
00023 #include "TGLSAFrame.h"
00024 
00025 #include "TGLabel.h"
00026 #include "TRootEmbeddedCanvas.h"
00027 #include "TGSlider.h"
00028 
00029 #include "TGLSAViewer.h"
00030 
00031 #include "TPolyLine3D.h"
00032 #include "TClonesArray.h"
00033 #include "TPolyMarker3D.h"
00034 
00035 #include "TFile.h"
00036 #include "TTree.h"
00037 
00038 #include "TTimer.h"
00039 #include "TASImage.h"
00040 
00041 #include "TFndGeometry.h"
00042 #include "TFndHdt.h"
00043 #include "TFndEvdTrack.h"
00044 #include "FIN_PHYS.h"
00045 
00046 #ifdef FNDEVD_USE_PREAN
00047 #include "TFndPrean.h"
00048 #endif
00049 
00050 //#include "gif_lib.h"
00051 
00052 using namespace FIN_PHYS;
00053 
00054 class TFndEvdWireHit: public TObject {
00055  public:
00056   
00057   enum E_EvtWireHitAttr // used to set different attributes depending on the detector
00058     {
00059       K_EvtWHit_Lmd = 0,
00060       K_EvtWHit_Stb = 1 
00061     };
00062   enum E_EvtWireHitMode
00063     { 
00064       K_EvtWHit_NoObject = 0,
00065       K_EvtWHit_LineOnly,
00066       K_EvtWHit_E_MarksOnly,
00067       K_EvtWHit_P_MarksOnly,
00068       K_EvtWHit_MarksOnly,
00069       // 7 modes still free (for further developments)
00070       K_EvtWHit_Complete = 10
00071     };
00072   
00073  
00074 private:
00075   TPolyLine3D *fLine;
00076   TPolyMarker3D *fEdgeMarkers;
00077   E_EvtWireHitMode f_hit_mode;
00078 
00079  public:
00080     
00081   TFndEvdWireHit(E_EvtWireHitMode hit_mode=K_EvtWHit_Complete); // default ctor will draw line and edge-markers
00082   virtual ~TFndEvdWireHit();
00083   
00084   void SetAttributes(E_EvtWireHitAttr attr);
00085   void SetEdges(Double_t x1, Double_t y1, Double_t z1,Double_t x2, Double_t y2, Double_t z2)
00086     {
00087       if(fLine){
00088         fLine->SetPoint(FROOT::E_FIN_SIDE_E,x1,y1,z1);
00089         fLine->SetPoint(FROOT::E_FIN_SIDE_P,x2,y2,z2);
00090       }
00091       if(fEdgeMarkers){
00092         if (f_hit_mode != K_EvtWHit_P_MarksOnly) fEdgeMarkers->SetPoint(FROOT::E_FIN_SIDE_E,x1,y1,z1);
00093         if (f_hit_mode != K_EvtWHit_E_MarksOnly) fEdgeMarkers->SetPoint(FROOT::E_FIN_SIDE_P,x2,y2,z2);
00094       }
00095     }
00096   
00097   void DrawWireHit(Bool_t also_edges=kTRUE);
00098   
00099   ClassDef(TFndEvdWireHit,0)
00100 };
00101 
00103 //                                                                        //
00104 // TFndEvd                                                                //
00105 //                                                                        //
00106 //                                                                        //
00108 
00109 #include "Gui.h"
00110 using namespace Gui;
00111 
00112 class TFndEvd: public TFndGeometry {
00113 
00114  public:
00115   enum { K_FinEvd_NmaxLines = 1200 };
00116 
00117   enum EFndEvdView { FinEvdView_START = 0, 
00118                      FinEvdView_Perp_VERT,
00119                      FinEvdView_Orth_VERT
00120   };
00121   
00122   enum E_EvdDets { // local management of detectors
00123     E_EvdDet_Tofino = 0,
00124     E_EvdDet_Sil = 1,
00125     E_EvdDet_Lmd = 2,
00126     E_EvdDet_Tofone = 3,
00127     E_EvdDet_End = 4 // Not used: needed by arrays
00128   };
00129 
00130   enum E_EvdSelHitOper { // logic operation to be performed
00131     E_Evd_SelOper_AND_sel = 0, // will not consider not selected entries
00132     E_Evd_SelOper_AND_all = 1, // will consider not selected entries as "not"
00133     E_Evd_SelOper_End = 2 // Not used: needed by arrays
00134   };
00135 
00136 
00137   enum E_EvdSelHitMode_Sil {
00138     E_EvdSelMod_SelSil_Clean = 0,
00139     E_EvdSelMod_SelSil_End = 1
00140   };
00141 
00142   enum E_EvdSelHitMode {
00143     E_EvdSelMod_AdcE = 0,
00144     E_EvdSelMod_AdcP = 1,
00145     E_EvdSelMod_TdcE_Low = 2,
00146     E_EvdSelMod_TdcP_Low = 3,
00147     E_EvdSelMod_Mt_Low = 4,
00148     E_EvdSelMod_TdcE_High = 5, // TOFINO only
00149     E_EvdSelMod_TdcP_High = 6, // TOFINO only
00150     E_EvdSelMod_Mt_High = 7,   // TOFINO only
00151     E_EvdSelMod_End = 8     // Not used: needed by arrays
00152   };
00153 
00154   TString GetEvdDet(E_EvdDets det){
00155     switch(det){
00156     case E_EvdDet_Tofino: return "TOFI";
00157     case E_EvdDet_Sil: return "SIL";
00158     case E_EvdDet_Lmd: return "LMD";
00159     case E_EvdDet_Tofone: return "TOFO";
00160     default: Warning("GetEvdDet","detector not defined (%d)",det); return "";
00161     }
00162   }
00163   
00164   TString GetOperName(E_EvdSelHitOper oper){
00165     switch(oper){
00166     case E_Evd_SelOper_AND_sel: return "sel";
00167     case E_Evd_SelOper_AND_all: return "all";
00168     default: Warning("GetOperName","operation not defined (%d)",oper); return "";
00169     }  
00170   }
00171 
00172   TString GetSelHitMode_Sil(E_EvdSelHitMode_Sil mode){
00173     switch(mode){
00174     case E_EvdSelMod_SelSil_Clean: return "Clean";
00175     default: Warning("GetSelHitMode_Sil","mode not defined (%d)",mode); return "";
00176     }
00177   }
00178   
00179 
00180   TString GetSelHitMode(E_EvdSelHitMode mode,Bool_t is_tofino=kFALSE){
00181     switch(mode){
00182     case E_EvdSelMod_AdcE: return "adc E";
00183     case E_EvdSelMod_AdcP: return "adc P";
00184     case E_EvdSelMod_TdcE_Low: if(is_tofino) return "tdc E (low)" ; else return "tdc E" ;
00185     case E_EvdSelMod_TdcP_Low: if(is_tofino) return "tdc P (low)" ; else return "tdc P" ;
00186     case E_EvdSelMod_Mt_Low:   if(is_tofino) return "Mt (low)"    ; else return "MT" ;
00187     case E_EvdSelMod_TdcE_High: if(is_tofino) return "tdc E (high)" ; else return "" ;
00188     case E_EvdSelMod_TdcP_High: if(is_tofino) return "tdc P (high)" ; else return "" ;
00189     case E_EvdSelMod_Mt_High:   if(is_tofino) return "Mt (high)"    ; else return "" ;
00190     default: Warning("GetSelHitMode","mode not defined (%d)",mode); return "";
00191     }
00192   }
00193   
00194   
00195   TString GetViewName(EFndEvdView view)
00196     {
00197       switch(view){
00198       case FinEvdView_START: return "Default (START)";
00199       case FinEvdView_Perp_VERT: return "Vert (Perp)";
00200       case FinEvdView_Orth_VERT: return "Vert (Ortho)";
00201       default: return 0;
00202       }
00203     }
00204   
00205  protected:
00206   TGLSAViewer *fGLSAViewer;
00207   EFndEvdView fCurrentEvdView;
00208 
00209   Bool_t fDetectorVisibililty[(const Int_t)FGEO_TOFONE];
00210   //----------
00211   
00212   // GUI management
00213   TGLSAFrame *fPromptFrame; 
00214   TGCompositeFrame *fDisplayFrameGL;
00215   TGFont *fUFONT;    // will reflect user font changes
00216   TGGC   *fUGC;      // will reflect user GC changes
00217   ULong_t fUColor;   // will reflect user color changes  
00218 
00219 
00220   TGVerticalFrame *fFndVertFrame;
00221   Double_t fFndVFrameW;
00222   Double_t fFndVFrameH;
00223   Double_t fPromptWindowSize[2]; // width, height
00224 
00225   // GEOMETRY manipulation frame
00226   TGGroupFrame *fGrpGuiManip;
00227   TGLabel *fLableTogLayView;
00228   TGComboBox *fComboTogLayView;
00229 
00230   TGLabel *fLableSelectView;
00231   TGComboBox *fComboSelectView;
00232   // Hit selection //
00233   TGLabel *fLabelHitSelOper[(Int_t)E_EvdDet_End];
00234   TGComboBox *fComboHitSelOper[(Int_t)E_EvdDet_End];
00235   TGListBox *fListBox_SelMod[(Int_t)E_EvdDet_End];
00236 
00237   // event handling frame
00238   TGGroupFrame *fGrpEvtHandle;
00239   TGLabel *fLableFidaVer;
00240   TGComboBox *fComboFidaVer;
00241 
00242   TGLabel *fLableSelectRunType;
00243   TGComboBox *fComboSelectRunType;
00244 
00245   TGLabel *fLableSelectRunNumber;
00246   TGNumberEntry *fNumGuiSelectRunNumber;
00247 
00248   TGLabel *fLableSelectEventNumber;
00249   TGNumberEntry *fNumGuiSelectEventNumber;
00250 
00251   TGCheckButton *fChkBox_Autoupdate;
00252   TGCheckButton *fChkBox_UseTracks; // look for reconstructed tracks if enabled
00253 
00254   // information region frame
00255   TGGroupFrame *fGrpInfoRegion;
00256   TGLRenderArea *fGLInfoRegArea;
00257   TRootEmbeddedCanvas *fInfoEmbCanvas;
00258   TCanvas *fInfoCanvas;
00259 
00260   TGTextButton *fTxtBut_SaveDisplay;  // used to save current display (picture) to file
00261   TGTextButton *fTxtBut_StoreDisplay; // used to store current diplay into the Info Canvas
00262 
00263   // Bottom horizontal frame
00264   TGHorizontalFrame *fFndHorFrame; // horizontal frame (bottom)
00265 
00266   TGLabel *fLableMinDensity;
00267   TGHSlider *fSliderMinDensity;
00268   TGNumberEntry *fNumMinDensity;
00269   Double_t fDensSliderScale;
00270 
00271   TGLabel *fLableVerboseLev;
00272   TGNumberEntry *fNumVerboseLev;
00273 
00274   TGLabel *fLableStructVis;
00275   TGNumberEntry *fNumStructVis;
00276 
00278   // Hits displaying (volumes are handled directly via gGeoManager) //
00280   Bool_t fRandomMode; // default value: false
00281 
00282   std::vector<FinEvdHit_t> fVolHitsList;
00283   
00284   TClonesArray fLmdWHits; // lines for representing the hits wire
00285   TClonesArray fStbWHits;      // lines for representing the hits wire */
00286   TPolyMarker3D *fMRS_TofHits[2]; // markers for evaluated hit position (on tofino slabs)
00287   TPolyMarker3D *fMRS_SilHits[2][2]; // markeers for hit position [layer][normal,high-energy] (on sil modules)
00288   TPolyMarker3D *fMRS_LmdHits; // markers for evaluated hit position (on lmd wires)
00289 
00291   // Event management //
00293   // - "HDT" are used for displaying hits
00294   // - reconstructed tracks are taken from
00295   //   pre-analysis trees (see below: Reconstructed Information)
00296 
00297   TString fCurRunType;
00298   Int_t fCurRunNumber;
00299   Int_t fCurEv;
00300   
00301   TFile *fCurDataFile; // hdt.root or dst.root
00302   TTree *fCurEventTree; // tree contained in hdt.root("F") or dst.root("E")
00303   TFndHdt *fCurHdt; // current hdt event (must not be deleted)
00304   
00305   TFndEvdWireHit::E_EvtWireHitMode fWireHitsMode[FIN_STB+1];
00306 
00307   Int_t fVerboseLevel; // 0: no std-out messages; default value: 1
00308   Int_t fStructVis; // 0: no structure (default)
00309   Bool_t fReadyToDisplay;
00310 
00312   // Automatic update management //
00314   TTimer *fTimer;
00315   Int_t fUpdateInterval; // time interval for update (seconds): default is 15
00316   Bool_t fAutoUpdate; // true (default) if autoupdate is set
00317 
00319   // Hit selection //
00321 
00322   // --- Sil is treated as others, but with a different enum!
00323   E_EvdSelHitOper fSelOperation[(Int_t)E_EvdDet_End]; // operation to be performed (on selected hit modes)
00324   Bool_t fSelConsider[(Int_t)E_EvdDet_End][(Int_t)E_EvdSelMod_End]; // true for hit selection mode to be considered
00325 
00327   // Reconstructed Information //
00328   // (pre-analysis trees used) //
00330   Bool_t fUseTracks;  // true (not the default) if UseTracks is set
00331   TClonesArray *fTracksArray;  
00332   
00333 #ifdef FNDEVD_USE_PREAN
00334   TFndPrean *fPreanRef; // reference for pre-analysis format interface
00335 #endif
00336 
00337  public:
00338   static TClonesArray *fgTracks;
00339   
00340  protected:
00342   // Saving / Printing //
00344   TImage *fCurImage; // image in memory (for displaying purposes)
00345   
00346  public:
00347   
00348   TFndEvd();
00349   ~TFndEvd();
00350 
00351   // --- Connection methods to interface ROOT-defined actions
00352   virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
00353   void PrintEvent_t(Event_t *ev);
00354   Bool_t HandleButton(Event_t *ev);
00355   Bool_t HandleDoubleClick(Event_t *ev);
00356   Bool_t HandleConfigureNotify(Event_t *ev);
00357   Bool_t HandleKey(Event_t *ev);
00358   Bool_t HandleMotion(Event_t *ev);
00359   Bool_t HandleExpose(Event_t *ev);
00360   // ---
00361 
00362   Int_t Open(const Int_t &dtak_num);
00363   void  UpdateEVD() { UpdateEVD(kFALSE); } // needed by GUI connection
00364   void  UpdateEVD(Bool_t reset_view); // needed by GUI connection
00365   Int_t Close();
00366 
00367   void ToggleAutoUpdate(Bool_t autoupd);
00368   void AutoUpdate(); // perform an automatic update
00369 
00370   TGLSAViewer *GetGLSAViewer() { return fGLSAViewer;  }
00371   TGLSAFrame  *GetGLSAFrame()  { return fPromptFrame; }
00372 
00373   void SelectEVDView(EFndEvdView view_id);
00374   void SelectEVDView(Int_t view_id){ SelectEVDView((EFndEvdView)view_id); } // needed by GUI connection
00375   
00376   // called by GUI elements (mouse actions)
00377   void SetDensityThreshold(Int_t pos);
00378   void SetDensitySlider(Long_t val);
00379   void ToggleDetectorVisibility(Int_t det_id); // det_id: see TFndGeometry::EFndGeoLayers
00380 
00381 
00382   // following methods could become private:
00383   void SetLocalFont(TString font_str,TString font_fg_col,TString font_bg_col,TString u_col);
00384 
00385   void BuildUserActionsGUIGroups();
00386   void BuildInfoRegionGUIGroup();
00387   void BuildBottomControlsGUI();
00388   void SetFndGlViewer();
00389 
00390   Bool_t MakeConnections();
00391 
00392   void Test1();
00393   void Test1(Int_t par);
00394 
00396   // Hits displaying (volumes are handled directly via gGeoManager) //
00398   void HitDetector(Int_t det, Int_t ch, Int_t mode=FGEO_HIT_DETECTED,Bool_t refresh_display=kTRUE,Double_t mrs_x=0,Double_t mrs_y=0,Double_t mrs_z=0);
00399   void RemoveHit(Int_t det, Int_t ch,Bool_t refresh_display=kTRUE); // remove a specific hit
00400   void RemoveAllHits(Bool_t reset_default_view=kFALSE,Bool_t refresh_display=kTRUE);
00401  
00402   void ResetMrsHits();
00403  
00404   void PrintHits(Bool_t Selected=kTRUE); // default will print only selected hits
00405   void SetVerboseLevel(Long_t v_lev) {
00406     fVerboseLevel = (Int_t)( fNumVerboseLev->GetNumber() ); 
00407     Info("SetVerboseLevel","Verbose level set to: %d",fVerboseLevel);
00408   }
00409   void SetStructVis(Long_t v_lev) {
00410     fStructVis = (Int_t)( fNumStructVis->GetNumber() );
00411     Bool_t vis = (fStructVis>0)? kTRUE : kFALSE;
00412     SetStructureVisibility(vis,fStructVis);
00413     UpdateEVD();
00414     Info("SetStructVis","Structure visibility set to: %d",fStructVis);
00415   }
00417   // Event management //
00419   void SetRandomMode(const Bool_t &rndm_mode) { fRandomMode = rndm_mode; }
00420   
00421   void DisplayEvent(Bool_t keep_current_hits=kFALSE,Bool_t reload=kFALSE);
00422   void DisplayRandomEvent(Bool_t keep_current_hits); // used to test the Event displaying (and for demo)
00423   
00424   void SetRunType(Int_t r_type);
00425   
00426   void SetRunNumber(Long_t evt_num){
00427     fCurRunNumber = (Int_t) fNumGuiSelectRunNumber->GetNumber();
00428     if(fVerboseLevel >= 1) Info("SetRunNumber","Selected run : \"%d\"",fCurRunNumber);    
00429   }
00430 
00431   void SetEventNumber(Long_t evt_num){
00432     fCurEv = (Int_t) fNumGuiSelectEventNumber->GetNumber();
00433     if(fVerboseLevel >= 1) Info("SetEventNumber","Selected event : \"%d\"",fCurEv);    
00434     DisplayEvent(kFALSE,kTRUE);
00435   }
00436   
00437   Int_t GetEvent();
00438 
00440   // Hit selection //
00442  private:
00443   void SetDefaulHitSelection();
00444   Int_t CheckTofHit(TFndHTof *hit); // 0:no-good; 1:low-th ; 2:high-th
00445   Bool_t CheckSilHit(TFndHSilCluster *hit); // check single hit before displaying it
00446   Bool_t CheckLmdHit(TFndHLmd *hit); // check single hit before displaying it
00447   Bool_t CheckStbHit(TFndHStb *hit); // check single hit before displaying it
00448 
00449   void ResetMrsTofiHits();
00450   void ResetMrsSilHits(Int_t layer=0,Bool_t recreate_it=kTRUE); // zero will reset both
00451   void ResetMrsLmdHits();
00452   void SetHitsVisibility(Int_t det, Bool_t visible);
00453 
00454  public:
00455 
00456   void CheckSingleSelOper(E_EvdDets det);
00457 
00458   void SetDetSelOper_TOFI(Int_t sel);
00459   void SetDetSelOper_SIL(Int_t sel);
00460   void SetDetSelOper_LMD(Int_t sel);
00461   void SetDetSelOper_TOFO(Int_t sel);
00462 
00463   void PrintOperSel(E_EvdDets det);
00464   void SetOperSel(E_EvdDets det,E_EvdSelHitOper Selection)
00465     {
00466       fSelOperation[(Int_t) det] = Selection;
00467     }
00468   //
00469   void CheckSingleSelList(E_EvdDets det);
00470 
00471   void CheckConsiderSel_TOFI();
00472   void CheckConsiderSel_SIL();
00473   void CheckConsiderSel_LMD();
00474   void CheckConsiderSel_TOFO();
00475 
00476   void PrintConsiderSel(E_EvdDets det);
00477   void SetConsiderSel(E_EvdDets det,E_EvdSelHitMode mode, Bool_t val)
00478     { // true for hit selection mode to be considered
00479       fSelConsider[det][mode] = val;
00480     }
00481 
00483   // Reconstructed Information //
00484   // (pre-analysis trees used) //
00486   void ToggleUseTracks(Bool_t use_trk);
00487  protected:
00488   Int_t LoadRecFile();
00489   void LoadTracks(Bool_t keep_current);
00490   void LoadRandomTracks(Bool_t keep_current);
00491  public:
00492   void DisplayTracks();
00493   void RemoveAllTracks();
00494 
00495   TClonesArray *GetTracksArray() { return fTracksArray; }
00496   Int_t GetNumberOfTracks() const { return fTracksArray->GetEntries(); }
00497   TFndEvdTrack *GetTrack(Int_t track_id)    { return ((TFndEvdTrack*) fTracksArray->At(track_id)); }
00498   TFndEvdTrack *AddTrack(const Double_t &Bx,const Double_t &By,const Double_t &Bz);
00499 
00501   // Saving / Printing //
00503   enum E_FndEvd_SaveMode {
00504     E_FndEvd_Save_HiddenTmp = 0, // recreate tmp hiddden file 
00505     E_FndEvd_Save_DefaultName = 1, // use a default name in cur-dir (and replace) 
00506     E_FndEvd_Save_CustomName = 2 // ask for file-name in cur-dir (and replace) 
00507   };
00508   
00509   void StoreCurrentDisplay();  
00510   void SaveCurrentDisplay(E_FndEvd_SaveMode mode=E_FndEvd_Save_HiddenTmp,TString fnam="");  
00511   void ShowSavedDisplay(TString filename="");
00512   void ClearInfoCanvas();
00513 
00514   ClassDef(TFndEvd,0)
00515 };
00516     
00517 #endif // FROOT_TFndEvd

Generated on Tue Oct 16 15:40:46 2007 by  doxygen 1.5.2