GUI/TFndEvd.cxx

00001 // @(#)fROOT/GUI:$Name:  $:$Id: TFndEvd.cxx,v 1.54 2007/10/08 12:38:57 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/07/31
00003 
00004 #include "TThread.h"
00005 
00006 #include "TFndDB.h"
00007 
00008 #include "TFndEvd.h"
00009 
00010 #include "TRandom.h"
00011 
00012 #include "TGeoTube.h"
00013 #include "TGeoShape.h"
00014 
00015 #include "TGLOutput.h"
00016 
00017 ClassImp(TFndEvdWireHit)
00018 
00019 //_______________________________
00020 TFndEvdWireHit::TFndEvdWireHit(E_EvtWireHitMode hit_mode):
00021   fLine(),fEdgeMarkers()
00022 {
00023   // default ctor will draw line and edge-markers
00024   // not documented and not protected
00025   // (internal use only!)
00026   
00027   f_hit_mode = hit_mode;
00028   if(hit_mode == K_EvtWHit_NoObject){
00029     Warning("TFndEvdWireHit","No geometric attribute will be constructed.");
00030     return;
00031   }
00032   
00033   // build line-hit
00034   if( hit_mode == K_EvtWHit_LineOnly || hit_mode == K_EvtWHit_Complete ) fLine = new TPolyLine3D(2);
00035   
00036   // build marler(s)-hit
00037   if( hit_mode != K_EvtWHit_LineOnly && hit_mode != K_EvtWHit_NoObject ){  
00038     Int_t nmarks = 0;
00039     if(hit_mode == K_EvtWHit_E_MarksOnly || hit_mode == K_EvtWHit_P_MarksOnly) nmarks = 1;
00040     else if(hit_mode == K_EvtWHit_MarksOnly || hit_mode == K_EvtWHit_Complete) nmarks = 2;
00041     
00042     fEdgeMarkers = new TPolyMarker3D(nmarks);
00043   }
00044 
00045 }
00046 
00047 //_______________________________
00048 TFndEvdWireHit::~TFndEvdWireHit(){
00049 
00050   delete fLine; fLine = 0;
00051   delete fEdgeMarkers; fEdgeMarkers = 0;  
00052 }
00053 
00054 //_______________________________
00055 void TFndEvdWireHit::SetAttributes(E_EvtWireHitAttr attr){
00056   // SetEdges mast have been called previousely
00057 
00058   if(fEdgeMarkers){
00059     fEdgeMarkers->SetMarkerStyle(3);
00060     fEdgeMarkers->SetMarkerSize(3);
00061   }
00062   
00063   switch(attr){
00064   case K_EvtWHit_Lmd:
00065     if(fLine){
00066       fLine->SetLineWidth(3);
00067       fLine->SetLineColor(3);
00068     }
00069     if(fEdgeMarkers) fEdgeMarkers->SetMarkerColor(2);
00070     break;
00071   case K_EvtWHit_Stb:
00072     if(fLine){
00073       fLine->SetLineWidth(3);
00074       fLine->SetLineColor(5);
00075     }
00076     if(fEdgeMarkers) fEdgeMarkers->SetMarkerColor(5);
00077     break;
00078   default:
00079     gROOT->Error("TFndEvdWireHit","BUG! attribute not accepted (%d)",(Int_t)(attr));
00080     gApplication->Terminate();
00081   }
00082 }
00083 
00084 //_______________________________
00085 void TFndEvdWireHit::DrawWireHit(Bool_t also_edges){
00086   
00087   //  if(!fLine && !fEdgeMarkers) Warning("DrawWireHit","Nothing to draw in memory.");
00088   if(fLine)  fLine->Draw("same");
00089   if(fEdgeMarkers && also_edges) fEdgeMarkers->Draw("same");
00090 }
00091 
00093 //                               TFndEvd                             //
00094 //                                                                   //
00095 // The FINUDA EVD (EVent-Display):                                   //
00096 //                                                                   //
00097 // ROOT GL-viewer is used for displaying the FINUDA geometry.        //
00098 // The complete API for the EVD handling is provided by this class   //
00099 //                                                                   //
00101  
00102 ClassImp(TFndEvd)
00103 
00104 TClonesArray *TFndEvd::fgTracks = 0;
00105 
00106 //_________________________
00107 TFndEvd::TFndEvd():
00108   fGLSAViewer(),
00109   fCurrentEvdView(),
00110   fPromptFrame(),fDisplayFrameGL(),
00111   fFndVertFrame(),fPromptWindowSize(),
00112   fDensSliderScale(),
00113   fRandomMode(kFALSE),
00114   fLmdWHits("TFndEvdWireHit",K_FinEvd_NmaxLines),
00115   fStbWHits("TFndEvdWireHit",K_FinEvd_NmaxLines),
00116   fMRS_TofHits(),fMRS_SilHits(),fMRS_LmdHits(),
00117   fCurRunType(),fCurRunNumber(),fCurEv(),
00118   fCurDataFile(),fCurEventTree(),fCurHdt(),
00119   fWireHitsMode(),
00120   fVerboseLevel(),fStructVis(),fReadyToDisplay(kFALSE),
00121   fTimer(),fUpdateInterval(10),fAutoUpdate(),fUseTracks(),fTracksArray(),
00122   fCurImage()
00123 {
00124   fVolHitsList.clear();
00125   for(Int_t i=0;i<(FIN_STB+1);i++){
00126     fWireHitsMode[i] = TFndEvdWireHit::K_EvtWHit_Complete;
00127   } 
00128   ResetMrsHits();
00129 
00130   fCurHdt = new TFndHdt();
00131 
00132   if (!fgTracks) fgTracks = new TClonesArray("TFndEvdTrack",10);
00133   fTracksArray = fgTracks;
00134 
00135 #ifdef FNDEVD_USE_PREAN
00136   fPreanRef = new TFndPrean();
00137 #endif
00138 
00139 }
00140 
00141 //_________________________
00142 TFndEvd::~TFndEvd(){
00143   
00144   RemoveAllHits();
00145   RemoveAllTracks();
00146   
00147   for(Int_t lay=0;lay<2;lay++){
00148     delete fMRS_TofHits[lay];
00149     for(Int_t i=0;i<2;i++){
00150       fMRS_SilHits[lay][i];
00151     }
00152   }
00153   
00154   delete fMRS_LmdHits;
00155   delete fCurHdt;
00156   
00157   delete fTimer;
00158   
00159 #ifdef _FND_OUTPUTS_USE_SUBDIR
00160   fPreanRef->CloseCurrentSourceFile();
00161 #endif
00162   
00163 }
00164 
00165 //_________________________
00166 Int_t TFndEvd::Open(const Int_t &dtak_num){
00167   // Load default geometry if not loaded
00168   // start EVD-GUI
00169   // display the detector
00170   //
00171   // return value:
00172   //              0: ok
00173   //             <0: error
00174   
00175   Int_t loadval = 0;
00176 
00177   if(!fPromptNode){
00178     switch(dtak_num){
00179     case 1:
00180       loadval = LoadGeometry("$FROOTSYS/geom/fin_spec_geom_2003.root");
00181       break;
00182     case 2:
00183       loadval = LoadGeometry("$FROOTSYS/geom/fin_spec_geom_2006.root");
00184       break;
00185     default:
00186       Warning("Open","Data-taking number \"%d\" not available.",dtak_num);
00187       TerminateFroot();
00188       return -1;
00189     }
00190   }
00191   else{
00192     Warning("Open","Geometry already loaded!!!");
00193     return -2;
00194   }
00195   
00196   if(loadval != 0) {
00197     Warning("Open","NO geometry loaded!!!");
00198     return -3;
00199   }
00200 
00201   ShowGeometry("",7);                
00202   fGLSAViewer = (TGLSAViewer *) fMainCanvas->GetViewer3D("ogl");
00203   //  fGLSAViewer = (TGLSAViewer *) fMainCanvas->GetViewer3D("pad");  
00204   fPromptFrame = fGLSAViewer->GetFrame();
00205   fMainCanvas->GetCanvasImp()->Iconify();
00206 
00207   //fGL_RenderArea = 
00208  
00209   // --- general view setting
00210   fGLSAViewer->SetResetCameraOnDoubleClick(kTRUE);
00211   fGLSAViewer->SetResetCamerasOnUpdate(kFALSE);
00212   fGLSAViewer->SetClearColor(42);
00213 
00214   return 0;
00215 }
00216 
00217 //_________________________
00218 void TFndEvd::ExecuteEvent(Int_t event, Int_t px, Int_t py){
00219   
00220   /*
00221     enum EEventType {
00222     kNoEvent       =  0,
00223     kButton1Down   =  1, kButton2Down   =  2, kButton3Down   =  3, kKeyDown  =  4,
00224     kButton1Up     = 11, kButton2Up     = 12, kButton3Up     = 13, kKeyUp    = 14,
00225     kButton1Motion = 21, kButton2Motion = 22, kButton3Motion = 23, kKeyPress = 24,
00226     kButton1Locate = 41, kButton2Locate = 42, kButton3Locate = 43,
00227     kMouseMotion   = 51, kMouseEnter    = 52, kMouseLeave    = 53,
00228     kButton1Double = 61, kButton2Double = 62, kButton3Double = 63
00229     
00230     enum EGEventType {
00231     kGKeyPress, kKeyRelease, kButtonPress, kButtonRelease,
00232     kMotionNotify, kEnterNotify, kLeaveNotify, kFocusIn, kFocusOut,
00233     kExpose, kConfigureNotify, kMapNotify, kUnmapNotify, kDestroyNotify,
00234     kClientMessage, kSelectionClear, kSelectionRequest, kSelectionNotify,
00235     kColormapNotify, kButtonDoubleClick, kOtherEvent
00236   */
00237   
00238   if(fVerboseLevel>1) Info("TFndEvd::ExecuteEvent","event: %d ; px: %d ; py: %d",event,px,py);
00239 }
00240 
00241 // Event_t
00242 //   EGEventType fType //of event (see EGEventTypes)
00243 //   Window_t fWindow //window reported event is relative to
00244 //   Time_t fTime //time event event occured in ms
00245 //   Int_t fX
00246 //   Int_t fY //pointer x, y coordinates in event window
00247 //   Int_t fXRoot
00248 //   Int_t fYRoot //coordinates relative to root
00249 //   UInt_t fCode //key or button code
00250 //   UInt_t fState //key or button mask
00251 //   UInt_t fWidth
00252 //   UInt_t fHeight //width and height of exposed area
00253 //   Int_t fCount //if non-zero, at least this many more exposes
00254 //   Bool_t fSendEvent //true if event came from SendEvent
00255 //   Handle_t fHandle //general resource handle (used for atoms or windows)
00256 //   Int_t fFormat //Next fields only used by kClientMessageEvent
00257 //   Long_t fUser[5] //5 longs can be used by client message events
00258 
00259 //_________________________
00260 void TFndEvd::PrintEvent_t(Event_t *ev){
00261 
00262   Printf(" ---------> Printing Event_t: <---------");
00263 }
00264 
00265 //_________________________
00266 Bool_t TFndEvd::HandleButton(Event_t *ev){
00267   
00268   Info("TFndEvd::HandleButton","Event: \"%d\"",ev->fType);
00269 }
00270 
00271 //_________________________
00272 Bool_t TFndEvd::HandleDoubleClick(Event_t *ev){
00273   
00274   Info("TFndEvd::HandleDoubleClick","Event: \"%d\"",ev->fType);
00275 }
00276 
00277 //_________________________
00278 Bool_t TFndEvd::HandleConfigureNotify(Event_t *ev){
00279   
00280   Info("TFndEvd::HandleConfigureNotify","Event: \"%d\"",ev->fType);
00281 }
00282 
00283 //_________________________
00284 Bool_t TFndEvd::HandleKey(Event_t *ev){
00285   
00286   Info("TFndEvd::HandleKey","Event: \"%d\"",ev->fType);
00287 }
00288 
00289 //_________________________
00290 Bool_t TFndEvd::HandleMotion(Event_t *ev){
00291   
00292   Info("TFndEvd::HandleMotion","Event: \"%d\"",ev->fType);
00293 }
00294 
00295 //_________________________
00296 Bool_t TFndEvd::HandleExpose(Event_t *ev){
00297   
00298   Info("TFndEvd::HandleExpose","Event: \"%d\"",ev->fType);
00299 }
00300 
00301 //_________________________
00302 void TFndEvd::SetLocalFont(TString font_str,TString font_fg_col,TString font_bg_col,TString u_col){
00303 
00304   fUFONT = gClient->GetFont(font_str);
00305   // graphics context changes
00306   GCValues_t valpFrame;
00307   valpFrame.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00308   gClient->GetColorByName(font_fg_col,valpFrame.fForeground);
00309   gClient->GetColorByName(font_bg_col,valpFrame.fBackground);
00310   valpFrame.fFillStyle = kFillSolid;
00311   valpFrame.fFont = fUFONT->GetFontHandle();
00312 
00313   valpFrame.fGraphicsExposures = kFALSE;
00314   fUGC = gClient->GetGC(&valpFrame, kTRUE);
00315 
00316   gClient->GetColorByName(u_col,fUColor);
00317 }
00318 
00319 //_________________________
00320 void TFndEvd::BuildUserActionsGUIGroups(){
00321   // Everything is built within the "*fFndVertFrame"
00322  
00324   // "Geometry" group frame //
00326   SetLocalFont("-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*","#0008a5","#c6c2c6","#7999d6");
00327 
00328   fGrpGuiManip = new TGGroupFrame(fFndVertFrame,"Display setting",kVerticalFrame,fUGC->GetGC(),fUFONT->GetFontStruct(),fUColor);
00329   fGrpGuiManip->SetTitlePos(TGGroupFrame::kCenter);
00330   fGrpGuiManip->SetLayoutBroken(kTRUE);
00331 
00332   // Toggle detector view
00333   fLableTogLayView = new TGLabel(fGrpGuiManip,"Toggle Layer view",fUGC->GetGC(),fUFONT->GetFontStruct());
00334   fLableTogLayView->SetTextJustify(36);
00335   fGrpGuiManip->AddFrame(fLableTogLayView, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00336   MoveResizeSafe(10,13,95,15,fLableTogLayView);
00337   
00338   fComboTogLayView = new TGComboBox(fGrpGuiManip,-1,kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
00339   fComboTogLayView->RemoveAll();
00340   MoveResizeSafe(10,27,95,20,fComboTogLayView);
00341   Int_t en_num = 0;
00342   for(Int_t i=(Int_t)FGEO_BEAM_PIPE;i<=(Int_t)FGEO_TOFONE;i++){
00343     if(i>=(Int_t)FGEO_STRAW_TUBES_1 && i<=(Int_t)FGEO_STRAW_TUBES_6) continue;
00344     fComboTogLayView->AddEntry(GetLayerName((EFndGeoLayers)i),i); en_num++; 
00345   }
00346   fComboTogLayView->Select(0);
00347   fComboTogLayView->SetHeight(fComboTogLayView->GetDefaultHeight());
00348   fGrpGuiManip->AddFrame(fComboTogLayView, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00349 
00350   // Select view
00351   fLableSelectView = new TGLabel(fGrpGuiManip,"View selection",fUGC->GetGC(),fUFONT->GetFontStruct());
00352   fLableSelectView->SetTextJustify(36);
00353   fGrpGuiManip->AddFrame(fLableSelectView, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00354   MoveResizeSafe(115,13,95,15,fLableSelectView);
00355 
00356   fComboSelectView = new TGComboBox(fGrpGuiManip,-1,kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
00357   fComboSelectView->RemoveAll();
00358   MoveResizeSafe(115,27,95,20,fComboSelectView);
00359   en_num = 0; // entry indexing must be independent on loop index
00360   for(Int_t i=(Int_t)FinEvdView_START;i<=(Int_t)FinEvdView_Orth_VERT;i++){
00361     fComboSelectView->AddEntry(GetViewName((EFndEvdView)i),i); en_num++; 
00362   }
00363   fComboSelectView->Select(0);
00364   fComboSelectView->SetHeight(fComboSelectView->GetDefaultHeight());
00365   fGrpGuiManip->AddFrame(fComboSelectView, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00366   
00367   // hit selection modes
00368   if((Int_t)E_EvdSelMod_SelSil_End > (Int_t)E_EvdSelMod_End){
00369     Warning("BuildUserActionsGUIGroups","E_EvdSelMod_SelSil_End > E_EvdSelMod_End: check your code!");
00370     TerminateFroot();
00371   }
00372 
00373   // --- oper-sel labels
00374   Int_t x_start = 10;
00375   Int_t x_step = 5;
00376   TString lbl_nam;
00377   for(Int_t d_id = (Int_t)E_EvdDet_Tofino; d_id <= (Int_t)E_EvdDet_Tofone; d_id++){
00378     lbl_nam = GetEvdDet( (E_EvdDets) d_id );
00379     Int_t x_w = 70;
00380     if(d_id != (Int_t)E_EvdDet_Tofino) x_w = 40;
00381     fLabelHitSelOper[d_id] = new TGLabel(fGrpGuiManip,lbl_nam.Data(),fUGC->GetGC(),fUFONT->GetFontStruct());
00382     fLabelHitSelOper[d_id]->SetTextJustify(36);
00383     fGrpGuiManip->AddFrame(fLabelHitSelOper[d_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00384     MoveResizeSafe(x_start,67,x_w,15,fLabelHitSelOper[d_id]);
00385     x_start += x_w;  
00386     x_start += x_step;  
00387   }
00388   
00389   // --- oper-sel combos
00390   x_start = 10;
00391   x_step = 5;
00392   
00393   for(Int_t d_id = (Int_t)E_EvdDet_Tofino; d_id <= (Int_t)E_EvdDet_Tofone; d_id++){
00394     Int_t x_w = 70;
00395     if(d_id != (Int_t)E_EvdDet_Tofino) x_w = 40;
00396     fComboHitSelOper[d_id] = new TGComboBox(fGrpGuiManip,-1,kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
00397     fComboHitSelOper[d_id]->RemoveAll();
00398     MoveResizeSafe(x_start,83,x_w,15,fComboHitSelOper[d_id]);
00399     for(Int_t oper = (Int_t)E_Evd_SelOper_AND_sel ; oper < (Int_t)E_Evd_SelOper_End ; oper++){
00400       fComboHitSelOper[d_id]->AddEntry(GetOperName( (E_EvdSelHitOper)oper ) ,oper);
00401     }
00402     fComboHitSelOper[d_id]->Select(0);
00403     fComboHitSelOper[d_id]->SetHeight(fComboHitSelOper[d_id]->GetDefaultHeight());
00404     fGrpGuiManip->AddFrame(fComboHitSelOper[d_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00405     x_start += x_w;  
00406     x_start += x_step;  
00407   }
00408 
00409   // --- list-boxes
00410   x_start = 10;
00411   x_step = 5;
00412   
00413   fListBox_SelMod[(Int_t)E_EvdDet_Tofino] = new TGListBox(fGrpGuiManip);
00414   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->SetMultipleSelections();
00415   for(Int_t en = (Int_t)E_EvdSelMod_AdcE ; en < (Int_t)E_EvdSelMod_End ; en++){
00416     fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->AddEntry(GetSelHitMode((E_EvdSelHitMode)en,kTRUE),en);
00417     
00418   }
00419   fGrpGuiManip->AddFrame(fListBox_SelMod[(Int_t)E_EvdDet_Tofino], new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00420   MoveResizeSafe(x_start,100,70,105,fListBox_SelMod[(Int_t)E_EvdDet_Tofino]);
00421   //---
00422   x_start += 70;  
00423   x_start += x_step;  
00424   for(Int_t i = (Int_t)E_EvdDet_Sil; i <= (Int_t)E_EvdDet_Tofone; i++){ // all but tofino
00425     fListBox_SelMod[i] = new TGListBox(fGrpGuiManip);
00426     fListBox_SelMod[i]->SetMultipleSelections();
00427 
00428     switch(i){ // entries depend on the detector
00429     case (Int_t)E_EvdDet_Sil:
00430       for(Int_t en = (Int_t)E_EvdSelMod_SelSil_Clean ; en < (Int_t)E_EvdSelMod_SelSil_End ; en++){
00431         fListBox_SelMod[i]->AddEntry(GetSelHitMode_Sil((E_EvdSelHitMode_Sil)en),en);
00432       }
00433       
00434       break;
00435     case (Int_t)E_EvdDet_Lmd:
00436       for(Int_t en = (Int_t)E_EvdSelMod_AdcE ; en <= (Int_t)E_EvdSelMod_TdcP_Low ; en++){
00437         fListBox_SelMod[i]->AddEntry(GetSelHitMode((E_EvdSelHitMode)en),en);
00438       }
00439       break;
00440     case (Int_t)E_EvdDet_Tofone:
00441       for(Int_t en = (Int_t)E_EvdSelMod_AdcE ; en <= (Int_t)E_EvdSelMod_Mt_Low ; en++){
00442         fListBox_SelMod[i]->AddEntry(GetSelHitMode((E_EvdSelHitMode)en),en);
00443       }
00444       break;
00445     default:
00446       Error("BuildUserActionsGUIGroups","detector %d not accepted...BUG!",i);
00447       TerminateFroot();
00448     }
00449 
00450     fGrpGuiManip->AddFrame(fListBox_SelMod[i], new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00451     MoveResizeSafe(x_start,100,40,105,fListBox_SelMod[i]);
00452     x_start += 40;  
00453     x_start += x_step;  
00454     
00455   }
00456 
00458   // "Run/Events" group frame   //
00460   SetLocalFont("-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*","#0008a5","#c6c2c6","#7999d6");
00461 
00462   fGrpEvtHandle = new TGGroupFrame(fFndVertFrame,"Event management",kVerticalFrame,fUGC->GetGC(),fUFONT->GetFontStruct(),fUColor);
00463   fGrpEvtHandle->SetTitlePos(TGGroupFrame::kCenter);
00464   fGrpEvtHandle->SetLayoutBroken(kTRUE);
00465 
00466   // Select data source type
00467   fLableFidaVer = new TGLabel(fGrpEvtHandle,"REC-v.",fUGC->GetGC(),fUFONT->GetFontStruct());
00468   fLableFidaVer->SetTextJustify(36);
00469   fGrpEvtHandle->AddFrame(fLableFidaVer, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00470   MoveResizeSafe(5,13,47,20,fLableFidaVer);
00471   
00472   fComboFidaVer = new TGComboBox(fGrpEvtHandle,-1,kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
00473 
00475   if(fComboFidaVer->GetNumberOfEntries() != 0) fComboFidaVer->RemoveAll();
00476   MoveResizeSafe(5,33,50,24,fComboFidaVer);
00477   
00478   for(Int_t i=(Int_t)(FIDAVER_521);i < (Int_t)(FIDAVER_END);i++) {
00479     fComboFidaVer->AddEntry(FidaVer_Name((E_FndFidaVersion)i),i);
00480   }  
00481   fComboFidaVer->Select(FIDAVER_603);
00483 
00484   //   fComboFidaVer->RemoveAll();
00485   //  for(Int_t i=(Int_t)FinEvdData_hdt;i<=(Int_t)FinEvdData_dst;i++) fComboFidaVer->AddEntry(GetDataSourceType((EFndEvdFileType)i),i);
00486   //  fComboFidaVer->Select((Int_t)(FinEvdData_hdt));
00487   //  fCurFidaVer = FinEvdData_hdt;
00488   fComboFidaVer->SetHeight(fComboFidaVer->GetDefaultHeight());
00489   fGrpEvtHandle->AddFrame(fComboFidaVer, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00490 
00491   // Select run type
00492   fLableSelectRunType = new TGLabel(fGrpEvtHandle,"Run type",fUGC->GetGC(),fUFONT->GetFontStruct());
00493   fLableSelectRunType->SetTextJustify(36);
00494   fGrpEvtHandle->AddFrame(fLableSelectRunType, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00495   MoveResizeSafe(57,13,45,20,fLableSelectRunType);
00496   
00497   fComboSelectRunType = new TGComboBox(fGrpEvtHandle,-1,kHorizontalFrame | kSunkenFrame | kDoubleBorder | kOwnBackground);
00498   fComboSelectRunType->RemoveAll();
00499   MoveResizeSafe(57,33,45,24,fComboSelectRunType);
00500   for(Int_t i=(Int_t)(RT_FINU);i<=(Int_t)(RT_ONLM);i++) fComboSelectRunType->AddEntry(RunType_Name(i),i);
00501   //  for (Int_t i=0; i<K_N_RUN_TYPES; i++) fComboSelectRunType->AddEntry(RunType_Name(i),i);
00502   fComboSelectRunType->Select(0);
00503   fCurRunType = RunType_Name(0);
00504   fComboSelectRunType->SetHeight(fComboSelectRunType->GetDefaultHeight());
00505   fGrpEvtHandle->AddFrame(fComboSelectRunType, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00506   
00507   // Select run number
00508   fLableSelectRunNumber = new TGLabel(fGrpEvtHandle,"Run num",fUGC->GetGC(),fUFONT->GetFontStruct());
00509   fLableSelectRunNumber->SetTextJustify(36);
00510   fGrpEvtHandle->AddFrame(fLableSelectRunNumber, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00511   MoveResizeSafe(107,13,50,20,fLableSelectRunNumber);
00512   
00513   fNumGuiSelectRunNumber = new TGNumberEntry(fGrpEvtHandle, (Double_t) 0,17,-1,(TGNumberFormat::EStyle) 0,(TGNumberFormat::EAttribute) 1);
00514   fGrpEvtHandle->AddFrame(fNumGuiSelectRunNumber, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00515   MoveResizeSafe(107,33,50,24,fNumGuiSelectRunNumber);
00516 
00517   // Select event number
00518   fLableSelectEventNumber = new TGLabel(fGrpEvtHandle,"Event",fUGC->GetGC(),fUFONT->GetFontStruct());
00519   fLableSelectEventNumber->SetTextJustify(36);
00520   fGrpEvtHandle->AddFrame(fLableSelectEventNumber, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00521   MoveResizeSafe(162,13,55,20,fLableSelectEventNumber);
00522   
00523   fNumGuiSelectEventNumber = new TGNumberEntry(fGrpEvtHandle, (Double_t) 0,17,-1,(TGNumberFormat::EStyle) 0,(TGNumberFormat::EAttribute) 1);
00524   fGrpEvtHandle->AddFrame(fNumGuiSelectEventNumber, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00525   MoveResizeSafe(162,33,55,24,fNumGuiSelectEventNumber);
00526 
00527   // handle reconstructed tracks
00528   fChkBox_UseTracks = new TGCheckButton(fGrpEvtHandle,"Tracks");
00529   fGrpEvtHandle->AddFrame(fChkBox_UseTracks, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00530   MoveResizeSafe(5,65,49,20, fChkBox_UseTracks);
00531 
00532   // handle auto-update
00533   fChkBox_Autoupdate = new TGCheckButton(fGrpEvtHandle,"Auto Update");
00534   fGrpEvtHandle->AddFrame(fChkBox_Autoupdate, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00535   MoveResizeSafe(107,65,80,20, fChkBox_Autoupdate);
00536 
00537   //
00538   fFndVertFrame->AddFrame(fGrpGuiManip, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
00539   fFndVertFrame->AddFrame(fGrpEvtHandle, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
00540   //
00541   // --- PLACEMENT
00542   MoveResizeSafe(5,0,fFndVFrameW-10.,205,fGrpGuiManip);
00543   MoveResizeSafe(5,210,fFndVFrameW-10.,95,fGrpEvtHandle);
00544 
00545   // --- SHOW
00546   fGrpGuiManip->MapSubwindows();
00547   fGrpEvtHandle->MapSubwindows();
00548   //
00549   fFndVertFrame->ShowFrame(fGrpGuiManip);
00550   fFndVertFrame->ShowFrame(fGrpEvtHandle);
00551 
00552 }
00553 
00554 //_________________________
00555 void TFndEvd::BuildInfoRegionGUIGroup(){
00556 
00557   SetLocalFont("-*-courier-bold-r-*-*-14-*-*-*-*-*-*-*","#000000","#c6c2c6","#797d9d");
00558   // "Info" group frame
00559   fGrpInfoRegion = new TGGroupFrame(fFndVertFrame,"EVD-info",kVerticalFrame,fUGC->GetGC(),fUFONT->GetFontStruct(),fUColor);
00560   fGrpInfoRegion->SetTitlePos(TGGroupFrame::kCenter);
00561   fGrpInfoRegion->SetLayoutBroken(kTRUE);
00562   
00563 
00564   fInfoEmbCanvas = new TRootEmbeddedCanvas(0,fGrpInfoRegion,100,80);
00565   fInfoCanvas = fInfoEmbCanvas->GetCanvas();
00566   fInfoCanvas->SetFillColor(0);
00567   fInfoCanvas->SetName("fInfoCanvas");
00568   fInfoCanvas->SetTitle("Info Canvas");
00569   fInfoCanvas->SetWindowSize(800,600);
00570 //   fInfoCanvas->SetFillColor(2);
00571 //   fInfoCanvas->Modified();
00572 //   fInfoCanvas->Update();
00573 
00574   fGrpInfoRegion->AddFrame(fInfoEmbCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00575   MoveResizeSafe(5,15,fFndVFrameW-20.,fFndVFrameW-20.,fInfoEmbCanvas);
00576   
00578   fTxtBut_StoreDisplay = new TGTextButton(fGrpInfoRegion,"Grab Display");
00579   fGrpInfoRegion->AddFrame(fTxtBut_StoreDisplay, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00580   MoveResizeSafe(5,230, 100,20,fTxtBut_StoreDisplay);
00581 
00582   fTxtBut_SaveDisplay = new TGTextButton(fGrpInfoRegion,"SAVE");
00583   fGrpInfoRegion->AddFrame(fTxtBut_SaveDisplay, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00584   MoveResizeSafe(115,230, 100,20,fTxtBut_SaveDisplay);
00586   
00587   //   // --- PLACEMENT and SHOW
00588   fGrpInfoRegion->SetLayoutManager(new TGVerticalLayout(fGrpInfoRegion));
00589   fFndVertFrame->AddFrame(fGrpInfoRegion, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00590   MoveResizeSafe(5,310,fFndVFrameW-10.,fFndVFrameW+47.,fGrpInfoRegion);
00591 
00592   fGrpInfoRegion->MapSubwindows();
00593   fFndVertFrame->ShowFrame(fGrpInfoRegion);
00594 }
00595 
00596 //_________________________
00597 void TFndEvd::BuildBottomControlsGUI(){
00598   // the value passed to geometry as minimum density
00599   // is the slider position divided by fDensSliderScale
00600 
00601   SetLocalFont("-*-courier-bold-r-*-*-10-*-*-*-*-*-*-*","#0008a5","#c6c2c6","#7999d6");
00602   // Label
00603   fLableMinDensity = new TGLabel(fFndHorFrame,"Threshold density setting (g/cm^3)",fUGC->GetGC(),fUFONT->GetFontStruct());
00604   fLableMinDensity->SetTextJustify(36);
00605   fFndHorFrame->AddFrame(fLableMinDensity, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00606   MoveResizeSafe(10,7,155,20,fLableMinDensity);
00607 
00608   // Slider
00609   fDensSliderScale = 1.e+3;
00610   fSliderMinDensity = new TGHSlider(fFndHorFrame,296,kSlider1 | kScaleBoth,-1,kHorizontalFrame,fUColor);
00611   fSliderMinDensity->SetRange(0,8000); // a density 8 is the maximum for FINUDA MC-geometry
00612   fSliderMinDensity->SetPosition(10);
00613   fSliderMinDensity->SetScale(1000);
00614   fFndHorFrame->AddFrame(fSliderMinDensity, new TGLayoutHints(kLHintsNormal));
00615   //  fSliderMinDensity->MoveResize(0,16,296,24);
00616   MoveResizeSafe(170,7,200,20,fSliderMinDensity);
00617 
00618   // Numeric indicator
00619   fNumMinDensity = new TGNumberEntry(fFndHorFrame, (Double_t) 0,17,-1,(TGNumberFormat::EStyle) 0,(TGNumberFormat::EAttribute) 1);
00620   fNumMinDensity->SetFormat(TGNumberFormat::kNESRealThree);
00621   fNumMinDensity->SetNumStyle(TGNumberFormat::kNESRealThree);
00622   fFndHorFrame->AddFrame(fNumMinDensity, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00623   MoveResizeSafe(380,7,50,20,fNumMinDensity);
00624 
00625   // --- verbose level setting
00626   fLableVerboseLev = new TGLabel(fFndHorFrame,"Verbose level",fUGC->GetGC(),fUFONT->GetFontStruct());
00627   fLableVerboseLev->SetTextJustify(36);
00628   fFndHorFrame->AddFrame(fLableVerboseLev, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00629   MoveResizeSafe(650,7,75,20,fLableVerboseLev);
00630 
00631 
00632   fNumVerboseLev = new TGNumberEntry(fFndHorFrame, (Double_t) 0,17,-1,(TGNumberFormat::EStyle) 0,(TGNumberFormat::EAttribute) 1);
00633   fFndHorFrame->AddFrame(fNumVerboseLev, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00634   MoveResizeSafe(730,7,30,20,fNumVerboseLev);
00635 
00636   // --- structure visibility setting
00637   fLableStructVis = new TGLabel(fFndHorFrame,"Struct. vis.",fUGC->GetGC(),fUFONT->GetFontStruct());
00638   fLableStructVis->SetTextJustify(36);
00639   fFndHorFrame->AddFrame(fLableStructVis, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00640   MoveResizeSafe(790,7,70,20,fLableStructVis);
00641   
00642   fNumStructVis = new TGNumberEntry(fFndHorFrame, (Double_t) 0,17,-1,(TGNumberFormat::EStyle) 0,(TGNumberFormat::EAttribute) 1, (TGNumberFormat::ELimit)(TGNumberEntry::kNELLimitMinMax),0,10);
00643   fFndHorFrame->AddFrame(fNumStructVis, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
00644   MoveResizeSafe(870,7,30,20,fNumStructVis);
00645 
00646 }
00647 
00648 //_________________________
00649 void TFndEvd::SetFndGlViewer(){
00650   // "fGLSAViewer" is diretly used (see 'fPromptFrame'):
00651   // - The window is changed
00652   // - Controls needed by FINUDA are added on the right
00653 
00654   SetLocalFont("-*-courier-bold-r-*-*-14-*-*-*-*-*-*-*","#000000","#c6c2c6","#797d9d");
00655 
00656   fPromptWindowSize[0] = 930;
00657   fPromptWindowSize[1] = 650;
00658 
00659   TGFrame *cc = fPromptFrame->GetFrameFromPoint(10,100);
00660   fDisplayFrameGL = (TGCompositeFrame *) cc->GetParent()->GetParent()->GetParent();
00661 
00663   //fDisplayFrameGL->SetLayoutBroken(kTRUE);
00664   //  fDisplayFrameGL->SetCleanup(kDeepCleanup);
00666 
00667   fFndVFrameW = 230;
00668   fFndVFrameH = 560;
00669 
00670   fFndVertFrame = new TGVerticalFrame(fDisplayFrameGL,10,10,kVerticalFrame);
00671   fFndVertFrame->SetLayoutBroken(kTRUE);
00672 
00673   fFndHorFrame = new TGHorizontalFrame(fPromptFrame,10,40,kHorizontalFrame,fUColor);  
00674   fFndHorFrame->SetLayoutBroken(kTRUE);
00675 
00676 
00677   // ADD frames (Fnd)
00678   fDisplayFrameGL->AddFrame(fFndVertFrame, new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2));
00679   fPromptFrame->AddFrame(fFndHorFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,2,2,2,2));
00680 
00681   BuildUserActionsGUIGroups();
00682   BuildInfoRegionGUIGroup();
00683   BuildBottomControlsGUI();
00684   
00685   MoveResizeSafe(100,0,fFndVFrameW,fFndVFrameH,fFndVertFrame);
00686 
00687   // --- SHOW added frames
00688   fFndVertFrame->MapSubwindows();
00689   fFndHorFrame->MapSubwindows();
00690 
00691   fDisplayFrameGL->ShowFrame(fFndVertFrame);
00692   fPromptFrame->ShowFrame(fFndHorFrame);
00694 
00695   // --- Set attributes for the main window
00696   MoveResizeSafe(30,100,fPromptWindowSize[0],fPromptWindowSize[1],fPromptFrame);
00697   fPromptFrame->SetWindowName("The FINUDA EVent-Display");
00698 
00699   fPromptFrame->Layout();
00700   fPromptFrame->MapWindow();
00701   gClient->NeedRedraw(fPromptFrame);
00702   gClient->ProcessEventsFor(fPromptFrame); 
00703   SelectEVDView(FinEvdView_START);
00704   
00705   fDetectorVisibililty[(Int_t)FGEO_BEAM_PIPE]   = kTRUE;
00706   fDetectorVisibililty[(Int_t)FGEO_TOFINO]      = kTRUE;
00707   fDetectorVisibililty[(Int_t)FGEO_ISIM]        = kTRUE;
00708   fDetectorVisibililty[(Int_t)FGEO_TARGETS]     = kTRUE;
00709   fDetectorVisibililty[(Int_t)FGEO_OSIM]        = kTRUE;
00710   fDetectorVisibililty[(Int_t)FGEO_INNER_LMD]   = kTRUE;
00711   fDetectorVisibililty[(Int_t)FGEO_OUTER_LMD]   = kTRUE;
00712   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES] = kTRUE;
00713   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_1] = kFALSE;
00714   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_2] = kFALSE;
00715   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_3] = kFALSE;
00716   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_4] = kFALSE;
00717   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_5] = kFALSE;
00718   fDetectorVisibililty[(Int_t)FGEO_STRAW_TUBES_6] = kFALSE;
00719   fDetectorVisibililty[(Int_t)FGEO_TOFONE] = kTRUE;
00720 
00721   //fDetectorVisibililty[i] = kTRUE; 
00722   
00723   // --- Add support for auto-update
00724   fTimer = new TTimer();  
00725   fTimer->Connect("Timeout()","TFndEvd",this,"AutoUpdate()");
00726   //  Connect(timer, "Timeout()", "myObjectClassName",myObject, "TimerDone()");                         
00727   fTimer->Start(fUpdateInterval*1000, kFALSE);   // kTRUE:single-shot ; kFALSE:repetitive          
00728   fTimer->TurnOff(); // handled by ToggleAutoUpdate() method
00729 
00730   // default value for transparency
00731   fNumMinDensity->SetNumber(0.001);
00732   SetDensitySlider(0); // needed in order to perform the display update
00733 }
00734 
00735 //_________________________
00736 Bool_t TFndEvd::MakeConnections(){
00737   Bool_t ok = kTRUE;
00738   
00739   ok = ok && fPromptFrame->Connect("CloseWindow()", "TFndEvd", this, "Close()");
00740   
00741   ok = ok && fGLSAViewer->Connect("ExecuteEvent(Int_t, Int_t, Int_t)", "TFndEvd", this, "ExecuteEvent(Int_t, Int_t, Int_t)");
00742   ok = ok && fGLSAViewer->Connect("HandleButton(Event_t*)", "TFndEvd", this, "HandleButton(Event_t*)");
00743   ok = ok && fGLSAViewer->Connect("HandleDoubleClick(Event_t*)", "TFndEvd", this, "HandleDoubleClick(Event_t*)");
00744   ok = ok && fGLSAViewer->Connect("HandleKey(Event_t*)", "TFndEvd", this, "HandleKey(Event_t*)");
00745   ok = ok && fGLSAViewer->Connect("HandleMotion(Event_t*)", "TFndEvd", this, "HandleMotion(Event_t*)");
00746   ok = ok && fGLSAViewer->Connect("HandleExpose(Event_t*)", "TFndEvd", this, "HandleExpose(Event_t*)");
00747   ok = ok && fGLSAViewer->Connect("HandleConfigureNotify(Event_t*)", "TFndEvd", this, "HandleConfigureNotify(Event_t*)");
00748 
00749 
00750   ok = ok && fSliderMinDensity->Connect("PositionChanged(Int_t)", "TFndEvd", this, "SetDensityThreshold(Int_t)");
00751   ok = ok && fSliderMinDensity->Connect("Released()", "TFndEvd", this, "UpdateEVD()");
00752   ok = ok && fNumMinDensity->Connect("ValueSet(Long_t)", "TFndEvd", this, "SetDensitySlider(Long_t)");
00753   ok = ok && fNumVerboseLev->Connect("ValueSet(Long_t)", "TFndEvd", this, "SetVerboseLevel(Long_t)");
00754   ok = ok && fNumStructVis->Connect("ValueSet(Long_t)", "TFndEvd", this, "SetStructVis(Long_t)");
00755   
00756   ok = ok && fComboTogLayView->Connect("Selected(Int_t)", "TFndEvd", this, "ToggleDetectorVisibility(Int_t)");
00757   ok = ok && fComboSelectView->Connect("Selected(Int_t)", "TFndEvd", this, "SelectEVDView(Int_t)");
00758 
00759   //
00760   ok = ok && fComboHitSelOper[(Int_t)E_EvdDet_Tofino]->Connect("Selected(Int_t)", "TFndEvd", this, "SetDetSelOper_TOFI(Int_t)");
00761   ok = ok && fComboHitSelOper[(Int_t)E_EvdDet_Sil]->Connect("Selected(Int_t)", "TFndEvd", this, "SetDetSelOper_SIL(Int_t)");
00762   ok = ok && fComboHitSelOper[(Int_t)E_EvdDet_Lmd]->Connect("Selected(Int_t)", "TFndEvd", this, "SetDetSelOper_LMD(Int_t)");
00763   ok = ok && fComboHitSelOper[(Int_t)E_EvdDet_Tofone]->Connect("Selected(Int_t)", "TFndEvd", this, "SetDetSelOper_TOFO(Int_t)");
00764 
00765   ok = ok && fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Connect("SelectionChanged()", "TFndEvd", this, "CheckConsiderSel_TOFI()");
00766   ok = ok && fListBox_SelMod[(Int_t)E_EvdDet_Sil]->Connect("SelectionChanged()", "TFndEvd", this, "CheckConsiderSel_SIL()");
00767   ok = ok && fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->Connect("SelectionChanged()", "TFndEvd", this, "CheckConsiderSel_LMD()");
00768   ok = ok && fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Connect("SelectionChanged()", "TFndEvd", this, "CheckConsiderSel_TOFO()");
00769 
00770   // --- set defaults for hit-selection list boxes
00771   SetDefaulHitSelection();  
00772   //
00773 
00774   //  ok = ok && fComboFidaVer->Connect("Selected(Int_t)", "TFndEvd", this, "SetFidaVer(Int_t)");
00775   ok = ok && fComboSelectRunType->Connect("Selected(Int_t)", "TFndEvd", this, "SetRunType(Int_t)");
00776   ok = ok && fNumGuiSelectRunNumber->Connect("ValueSet(Long_t)", "TFndEvd", this, "SetRunNumber(Long_t)");
00777 
00778   ok = ok && fNumGuiSelectEventNumber->Connect("ValueSet(Long_t)", "TGNumberEntry", fNumGuiSelectRunNumber, "ValueSet(Long_t)");
00779   ok = ok && fNumGuiSelectEventNumber->Connect("ValueSet(Long_t)", "TFndEvd", this, "SetEventNumber(Long_t)");
00780 
00781   ok = ok && fChkBox_UseTracks->Connect("Toggled(Bool_t)", "TFndEvd", this, "ToggleUseTracks(Bool_t)");
00782   ok = ok && fChkBox_Autoupdate->Connect("Toggled(Bool_t)", "TFndEvd", this, "ToggleAutoUpdate(Bool_t)");
00783   
00784   ok = ok && fTxtBut_StoreDisplay->Connect("Clicked()","TFndEvd",this,"StoreCurrentDisplay()");
00785   ok = ok && fTxtBut_SaveDisplay->Connect("Clicked()","TFndEvd",this,"SaveCurrentDisplay()");
00786 
00787   if(!ok) Warning("MakeConnections","At least one broken onnection found.");
00788   //
00789   fReadyToDisplay = kTRUE;
00790 
00791   fNumVerboseLev->SetNumber(1);
00792 
00793   if(ok) Printf("\n\n\n\n\n   --- --- --- Event-display ready --- --- --- \n\n");
00794 
00795   return ok;
00796 }
00797 
00798 //_________________________
00799 void TFndEvd::SetRunType(Int_t r_type){
00800   fCurRunType = RunType_Name(r_type); // combo has been filled in the same way
00801   Info("SetRunType","Selected run type : \"%s\"",fCurRunType.Data());    
00802 
00803   if( fComboSelectRunType->GetSelected() == (Int_t)(RT_ONLM) ){
00804     fChkBox_Autoupdate->SetState(kButtonDown,kTRUE);
00805     fChkBox_UseTracks->SetState(kButtonUp,kTRUE);
00806   }
00807   else{
00808     fChkBox_Autoupdate->SetState(kButtonUp,kTRUE);
00809     fChkBox_UseTracks->SetState(kButtonDown,kTRUE);
00810   }
00811 }
00812 
00813 //_________________________
00814 void TFndEvd::UpdateEVD(Bool_t reset_view){
00815 
00816   fMainCanvas->cd();
00817   gInterpreter->EndOfLineAction();
00818   if(reset_view)  SelectEVDView(fCurrentEvdView);
00819 }
00820 
00821 //_________________________
00822 void TFndEvd::ToggleUseTracks(Bool_t use_trk){
00823 
00824   if( fComboSelectRunType->GetSelected() == (Int_t)(RT_ONLM) ){
00825     fChkBox_UseTracks->SetState(kButtonUp,kTRUE);
00826   }
00827   
00828   fUseTracks = fChkBox_UseTracks->GetState();
00829   Info("ToggleUseTracks","Reconstructed tracks flag: %d",fUseTracks);
00830   DisplayEvent();
00831 
00832 }
00833 
00834 //_________________________
00835 void TFndEvd::ToggleAutoUpdate(Bool_t autoupd){
00836 
00837   fAutoUpdate = fChkBox_Autoupdate->GetState();
00838 
00839   if(fAutoUpdate) fTimer->TurnOn();
00840   else fTimer->TurnOff();
00841 
00842 }
00843 
00844 //_________________________
00845 void TFndEvd::AutoUpdate(){
00846   // perform an automatic update
00847   // (the event number will be incremented)
00848   
00849   if(!fCurEventTree || !fCurEventTree->GetEntries() ){
00850     Warning("AutoUpdate","Tree not available in this moment...");
00851     return;
00852   }
00853   
00854   Long_t cur_num = (Long_t) ( fNumGuiSelectEventNumber->GetNumber() );
00855   if( cur_num >= fCurEventTree->GetEntries() ) cur_num = 0;
00856   fNumGuiSelectEventNumber->SetNumber(cur_num+1);
00857   SetEventNumber((Long_t) ( fNumGuiSelectEventNumber->GetNumber() ) );
00858 }
00859 
00860 //_________________________
00861 void TFndEvd::SelectEVDView(EFndEvdView view_id){
00862   //   enum ECameraType { kCameraPerspXOZ, kCameraPerspYOZ, kCameraPerspXOY,
00863   //                       kCameraOrthoXOY, kCameraOrthoXOZ, kCameraOrthoZOY };
00864   //    enum ELight      { kLightFront =  0x00000001,
00865   //                       kLightTop   =  0x00000002,
00866   //                       kLightBottom = 0x00000004,
00867   //                       kLightLeft   = 0x00000008,
00868   //                       kLightRight  = 0x00000010,
00869   //                       kLightMask   = 0x0000001f };
00870   //    enum EAxesType  { kAxesNone, kAxesEdge, kAxesOrigin };
00871   
00872   if(fVerboseLevel>0) Info("TFndEvd::SelectEVDView","Changing view to \"%s\"",GetViewName(view_id).Data());
00873 
00874   Double_t CameraCenter[3] = {0.,0.,0.};
00875   
00876   switch(view_id){
00877   case FinEvdView_START:
00878     fGLSAViewer->SetPerspectiveCamera(TGLViewer::kCameraPerspXOZ,20,1000,CameraCenter,15,10);
00879     fGLSAViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
00880     break;
00881   case FinEvdView_Perp_VERT:
00882     fGLSAViewer->SetPerspectiveCamera(TGLViewer::kCameraPerspXOZ,25,100,CameraCenter,5,5);
00883     fGLSAViewer->SetCurrentCamera(TGLViewer::kCameraPerspXOZ);
00884     break;
00885   case FinEvdView_Orth_VERT:
00886     fGLSAViewer->SetOrthoCamera(TGLViewer::kCameraOrthoXOY,-100,100,10,10);
00887     fGLSAViewer->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
00888     break;
00889   default:
00890     Warning("SelectEVDView","The selected view is not supported (%d)",(Int_t)view_id);
00891     return;
00892   }
00893   
00894   // ---
00895   fCurrentEvdView = view_id; 
00896   fGLSAViewer->RequestDraw();
00897   fGLSAViewer->ExecuteEvent(0,0,0); 
00898   ExecuteEvent(0,0,0);
00899 }
00900 
00901 //_________________________
00902 void TFndEvd::SetDensitySlider(Long_t val){
00903   // used only to set the slider from
00904   // the number entry
00905 
00906   if(!gGeoManager){
00907     Warning("SetDensityThreshold","Geometry manager not defined.");
00908     return;
00909   }
00910 
00911   Double_t density = fNumMinDensity->GetNumber();
00912   if(fVerboseLevel >= 2) Printf("Geometry manager: density threshold set to %f  (visualization only)",density);
00913   Int_t pos = (Int_t)(density * fDensSliderScale);
00914   gGeoManager->SetVisDensity(density);
00915   fSliderMinDensity->SetPosition(pos);  
00916 
00917   UpdateEVD();
00918 
00919 }
00920 
00921 //_________________________
00922 void TFndEvd::SetDensityThreshold(Int_t pos){
00923 
00924   if(!gGeoManager){
00925     Warning("SetDensityThreshold","Geometry manager not defined.");
00926     return;
00927   }
00928   Double_t dens = (Double_t)pos / fDensSliderScale;
00929   gGeoManager->SetVisDensity(dens);
00930 
00931   fNumMinDensity->SetNumber(dens);
00932 
00933   if(fVerboseLevel >= 2) Printf("Geometry manager: density threshold set to %f  (visualization only)",dens);
00934 }
00935 
00936 //_________________________
00937 void TFndEvd::ToggleDetectorVisibility(Int_t det_id){
00938   // det_id: see TFndGeometry::EFndGeoLayers
00939 
00940   if(det_id <(Int_t)FGEO_BEAM_PIPE || det_id > (Int_t)FGEO_TOFONE){
00941     Error("ToggleDetectorVisibility","The selected detector id (%d) is not available",det_id);
00942     return;
00943   }
00944   if(!gGeoManager){
00945     Error("ToggleDetectorVisibility","Geometry manager not defined");
00946     return;
00947   }
00948   
00949 
00950   fDetectorVisibililty[det_id] = !fDetectorVisibililty[det_id];
00951   
00952   Int_t detailed = kFALSE;
00953   if(det_id ==(Int_t)FGEO_TOFINO || det_id ==(Int_t)FGEO_TOFONE) detailed = kTRUE;
00954   SetLayerVisibility(det_id, fDetectorVisibililty[det_id], detailed);
00955   SetHitsVisibility(det_id,fDetectorVisibililty[det_id]);
00956   gGeoManager->SetVisOption(1);
00957   UpdateEVD();
00958   if(fVerboseLevel >= 2) Printf("TFndEvd::ToggleDetectorVisibility ---> det: %d; vis: %d; detailed: %d",det_id,fDetectorVisibililty[det_id],detailed);
00959 }
00960 
00961 //_________________________
00962 Int_t TFndEvd::Close(){
00963  
00964   if(fVerboseLevel >= 3) Printf("TFndEvd::Close called");
00965   delete this;
00966   gApplication->Terminate();
00967 }
00968 
00969 //_________________________
00970 void TFndEvd::Test1() {
00971   Printf("Test1 called."); 
00972 }
00973 
00974 //_________________________
00975 void TFndEvd::Test1(Int_t par) {
00976   Printf("Test1 called with integer parameter \"%d\"",par); 
00977 }
00978 
00979 
00981 // Hits displaying (volumes are handled directly via gGeoManager) //
00983 //_______________________________________
00984 void TFndEvd::HitDetector(Int_t det, Int_t ch, Int_t mode,Bool_t refresh_display,Double_t mrs_x,Double_t mrs_y,Double_t mrs_z){
00985   // change the color of the hit channel (yellowif mode=FGEO_HIT_DETECTED)
00986   //
00987   //  det: (see "FROOT::EFndDaqDetectors")
00988   //
00989   //  ch: hit channel (numbering depends on the detector: as in the Database)
00990   //
00991   //  mode: 
00992   //        - FGEO_HIT_DETECTED: the complete channel is painted
00993   //        - FGEO_HIT_RECONSTRUCTED: a marker is drawn on the colored volume
00994   //
00995   // In order to change the color of hit channels hit volumes are cloned
00996   // and re-drawn (can not change the geometry building).
00997   //
00998   //     TGeoVolume *ClonedVolume = (TGeoVolume *) gGeoManager->GetTopVolume()->GetNode(0)->GetDaughter(1)->GetVolume()->Clone("NEWVOL");
00999   //     gGeoManager->GetTopVolume()->AddNode(ClonedVolume,1);
01000   //     ClonedVolume->SetLineColor(2);
01001   //     gGeoManager->ModifiedPad();
01002   //     gGeoManager->GetTopVolume()->RemoveNode(gGeoManager->GetTopVolume()->GetNode(1)); // removing afterwards
01003   //
01004   //  the fHitVols obj-array is used to store all cloned nodes
01005   //
01006   // A non-reconstructed STB hit is represented by adding a coloured line
01007   //  (not changing the colour of hit volume: too memory would be used)
01008   // The same thing happens for LMD: a line is painted to represent the hit wire
01009   // In the case of SIL (ISIM/OSIM) a simple marker is enough, since the 3D-position 
01010   //  evaluation does not need any event-reconstruction procedure.
01011   //  (still thinking about changing the colour of the hit chamber/ISIM/OSIM-module)
01012   //
01013   // Summarizing there are 3 kinds of not reconstructed hits:
01014   //   - Volumes hits (see fVolHitsList)
01015   //   - Lines hits (see fLmdWHits / fStbWHits) 
01016   //   - Marker hits (see fMRS_<det>Hits)
01017   //
01018   // In the future the reconstructed hit will be described by
01019   //   - dedicated markers
01020   //   - tracks (reconstructed)
01021 
01022   fMainCanvas->cd();
01023 
01024   SelectDetectorNode(det,ch);
01025   if(!fCurDetNode){
01026     Warning("HitDetector","No node found for the required selection (det = %d ; ch = %d)",det,ch);
01027     return;
01028   }
01029   gGeoManager->SetVisOption(1);
01030 
01031   Int_t HitColors[2];
01032   HitColors[(Int_t)FGEO_HIT_DETECTED] = 2; // red
01033   HitColors[(Int_t)FGEO_HIT_RECONSTRUCTED] = 5; // yellow
01034   
01035   TString hit_vname; // the cloned-volume name depends on the hit channel
01036   hit_vname.Form("hit_%d_%d",det,ch);
01037 
01038   TGeoVolume *DetVol;
01039   TGeoNode *OriNod;
01040   TGeoVolume *ClonedVolume;
01041   TGeoRotation *rot;
01042   
01043   Int_t lay = 0; // local slab id used for TOF(starting from zero)
01044   Int_t slab = ch; // local slab id used for TOF(starting from zero)
01045   Double_t rot_tof = 0;  
01046 
01047   Int_t cur_id = 0; // line(s) index
01048   TPolyLine3D *CurLine = 0;
01049   TFndEvdWireHit *CurLine1 = 0;
01050   Double_t loc_start[3] = {0.}; // used for drawing a line
01051   Double_t loc_stop[3]  = {0.}; // used for drawing a line
01052   Double_t mas_start[3] = {0.}; // used for drawing a line
01053   Double_t mas_stop[3]  = {0.}; // used for drawing a line
01054   Double_t half_length  = 0;  // used for drawing a line
01055   Double_t added_length = 0.5; // length added (to "half_length") to every line [provides front view visibility]
01056 
01057   Bool_t also_edg = kFALSE; // needed for wire-hits
01058   switch(det){
01059   case (Int_t) FIN_GTS:
01060     Warning("HitDetector","No geometry has been provided for GTS",det);
01061     return;
01062   case (Int_t) FIN_TOF:  
01063     // rotation matrix is set here "by hand" due to the way TOF volumes are built (Divided)
01064     TFndDB::Tof_ChNum_To_DetChan(ch,lay,slab);
01065     if(lay == E_FIN_INNER_LAYER) rot_tof = GetTofinoRotAngles(slab);
01066     else if(lay == E_FIN_OUTER_LAYER){
01067       rot_tof = GetTofoneRotAngles(slab);
01068     }
01069     else{
01070       Error("HitDetector","Wrong slab number for TOF (%d)",slab);
01071       return;
01072     }
01073     
01074     DetVol = fCurDetNode->GetVolume();
01075     if(fVerboseLevel >= 3) Printf(" ===> Building GeoHit for \"%s\", ch_id: %d",DetVol->GetName(),slab-1);
01076 
01077     OriNod = fCurDetNode->GetDaughter(slab-1);
01078     OriNod->SetVisibility(0);
01079     OriNod->VisibleDaughters(0);
01080     
01081     ClonedVolume =  (TGeoVolume *) OriNod->GetVolume()->Clone(hit_vname);
01082     
01083     rot = new TGeoRotation();
01084     rot->RotateZ(rot_tof);
01085     fPromptVolume->AddNodeOverlap(ClonedVolume,1,rot);
01086 
01087     // --- adding reconstructed position (MRS x,y,z)
01088     if(mode == (Int_t) FGEO_HIT_RECONSTRUCTED){
01089       fMRS_TofHits[lay-1]->SetPoint(fMRS_TofHits[lay-1]->GetLastPoint()+1,mrs_x,mrs_y,mrs_z);
01090       fMRS_TofHits[lay-1]->Draw("same");
01091     }
01092     
01093     break;
01094   case (Int_t) FIN_ISM:
01095     if(mode <0 || mode >1){
01096       Warning("HitDetector","mode %d not supported for SIL",mode);
01097       break;
01098     }
01099     fMRS_SilHits[0][mode]->SetPoint(fMRS_SilHits[0][mode]->GetLastPoint()+1,mrs_x,mrs_y,mrs_z);
01100     fMRS_SilHits[0][mode]->Draw("same");
01101     break;
01102   case (Int_t) FIN_OSM:
01103     if(mode <0 || mode >1){
01104       Warning("HitDetector","mode %d not supported for SIL",mode);
01105       break;
01106     }
01107     fMRS_SilHits[1][mode]->SetPoint(fMRS_SilHits[1][mode]->GetLastPoint()+1,mrs_x,mrs_y,mrs_z);
01108     fMRS_SilHits[1][mode]->Draw("same");
01109     break;
01110   case (Int_t) FIN_LMD:
01111     if(fWireHitsMode[FIN_LMD] == TFndEvdWireHit::K_EvtWHit_NoObject){
01112       // too many hits (GUI would need too much memory)
01113       break;
01114     }    
01115     cur_id = fLmdWHits.GetEntries();
01116     new (fLmdWHits[cur_id]) TFndEvdWireHit(fWireHitsMode[FIN_LMD]);
01117     // --- now draw a wire as a line (in MRS)
01118     half_length = (Double_t) (((TGeoTube *)(fCurDetNode->GetVolume()->GetShape()))->GetDZ());
01119     half_length += added_length;
01120     loc_start[0] = 0; loc_start[1] = 0; loc_start[2] = half_length; 
01121     loc_stop[0] = 0; loc_stop[1] = 0; loc_stop[2] = -half_length; // will reflect P-side 
01122     RefSys_LmdWireToMRS(ch,loc_start,mas_start);
01123     RefSys_LmdWireToMRS(ch,loc_stop,mas_stop);
01124     CurLine1 = (TFndEvdWireHit *)fLmdWHits[cur_id];
01125     CurLine1->SetEdges(mas_start[0],mas_start[1],mas_start[2],mas_stop[0],mas_stop[1],mas_stop[2]);
01126     CurLine1->SetAttributes( (TFndEvdWireHit::E_EvtWireHitAttr)TFndEvdWireHit::K_EvtWHit_Lmd );
01127     
01128     also_edg = (fNumMinDensity->GetNumber() == 0) ? kTRUE : kFALSE;
01129     for(Int_t i=0;i<fLmdWHits.GetEntries();i++) ((TFndEvdWireHit *)(fLmdWHits[i]))->DrawWireHit(also_edg);
01130 
01131     // --- adding reconstructed position (MRS x,y,z)
01132     if(mode == (Int_t) FGEO_HIT_RECONSTRUCTED){
01133       fMRS_LmdHits->SetPoint(fMRS_LmdHits->GetLastPoint()+1,mrs_x,mrs_y,mrs_z);
01134       fMRS_LmdHits->Draw("same");
01135     }
01136     break;
01137   case (Int_t) FIN_STB:
01138     if(fWireHitsMode[FIN_STB] == TFndEvdWireHit::K_EvtWHit_NoObject){
01139       // too many hits (GUI would need too much memory)
01140       break;
01141     }    
01142     cur_id = fStbWHits.GetEntries();
01143     new (fStbWHits[cur_id]) TFndEvdWireHit(fWireHitsMode[FIN_STB]);
01144     
01145     // --- now draw a wire as a line (in MRS)
01146     half_length = (Double_t) (((TGeoTube *)(fCurDetNode->GetVolume()->GetShape()))->GetDZ());
01147     half_length += added_length;
01148     loc_start[0] = 0; loc_start[1] = 0; loc_start[2] = half_length; 
01149     loc_stop[0] = 0; loc_stop[1] = 0; loc_stop[2] = -half_length;  // will reflect P-side 
01150     RefSys_StbWireToMRS(ch,loc_start,mas_start);
01151     RefSys_StbWireToMRS(ch,loc_stop,mas_stop);
01152     CurLine1 = (TFndEvdWireHit *)fStbWHits[cur_id];
01153     CurLine1->SetEdges(mas_start[0],mas_start[1],mas_start[2],mas_stop[0],mas_stop[1],mas_stop[2]);
01154     CurLine1->SetAttributes( (TFndEvdWireHit::E_EvtWireHitAttr)TFndEvdWireHit::K_EvtWHit_Stb );
01155     //     CurLine->SetPoint(0,mas_start[0],mas_start[1],mas_start[2]);
01156     //     CurLine->SetPoint(1,mas_stop[0],mas_stop[1],mas_stop[2]);
01157     //
01158     //     CurLine->SetLineColor(4);
01159     //     CurLine->SetLineStyle(1);
01160     //     CurLine->SetLineWidth(5);
01161     for(Int_t i=0;i<fStbWHits.GetEntries();i++) ((TFndEvdWireHit *)(fStbWHits[i]))->DrawWireHit();
01162     break;
01163   default:
01164     Warning("HitDetector","detector id \"%d\" not available",det);
01165     break;
01166   }
01167 
01168   // ---
01169   //  if(det == (Int_t)FIN_LMD || det == (Int_t)FIN_ISM || det == (Int_t)FIN_OSM || det == (Int_t)FIN_STB) return;
01170   if(det != (Int_t)FIN_TOF) return;
01171 
01172   ClonedVolume->SetLineColor(HitColors[(Int_t)mode]);
01173   ClonedVolume->SetVisibility(1);
01174   if(refresh_display) gGeoManager->ModifiedPad();
01175   
01176   FinEvdHit_t added_hit;
01177   added_hit.det = det;
01178   added_hit.ch = ch;
01179   //  Printf("==================> Pushing back: size before:%d",fVolHitsList.size());
01180   fVolHitsList.push_back(added_hit);
01181   //  Printf("==================> Pushing back: size after:%d",fVolHitsList.size());
01182   if(fVerboseLevel >= 2) Info("TFndGeometry::HitDetector","total number of hits: %d (%s)",fVolHitsList.size(),AcquiredDetName(det,FIN_D_MOD_SHORT).Data());
01183   
01184   //  ClonedVolume = 0;
01185 }
01186 
01187 
01188 //_______________________________________
01189 void TFndEvd::RemoveHit(Int_t det, Int_t ch,Bool_t refresh_display){
01190   // remove a specific hit (by hand)
01191   
01192   // Find volume in the list first
01193   if(fVolHitsList.empty()){
01194     Warning("RemoveHit","The list of volumes hits is empty");
01195     return;
01196   }
01197   Bool_t vfound = kFALSE;
01198   // get an iterator to the start of the numbers array
01199   std::vector<FinEvdHit_t>::iterator itNum = fVolHitsList.begin();
01200   for(; itNum < fVolHitsList.end(); itNum++){
01201     Int_t cur_id = (Int_t)(itNum - fVolHitsList.begin());
01202     if(fVolHitsList[cur_id].det==det && fVolHitsList[cur_id].ch==ch){  
01203       //    if(*itNum.det==det && *itNum.ch==ch){  
01204       vfound = kTRUE;
01205       //Printf("RemoveHit ------------> erasing: size before: %d",fVolHitsList.size());
01206       fVolHitsList.erase(itNum);
01207       //Printf("RemoveHit ------------> erasing: size after: %d",fVolHitsList.size());
01208     }
01209   }  
01210   if(!vfound){
01211     Printf("TFndGeometry::RemoveHit ---> Volume Hit not found for det: %d; ch: %d",det,ch);
01212     return;
01213   }
01214 
01215   // Now find the (cloned) coloured volume and remove it
01216   TString hit_vname; // the cloned-volume name depends on the hit channel
01217   hit_vname.Form("hit_%d_%d",det,ch);
01218 
01219   Int_t str_size = hit_vname.Sizeof()-1;
01220   
01221   TObjArray *nodes = fPromptNode->GetNodes();
01222   
01223   Int_t nfound = 0;
01224 
01225   for(Int_t i=0;i<nodes->GetEntries();i++){
01226     TString check_str = nodes->At(i)->GetName();
01227     check_str.Resize(str_size);
01228     if(fVerboseLevel >= 3) Printf("Removing \"%d\": chk=\"%s\" ; hit_vname=\"%s\".",i,check_str.Data(),hit_vname.Data());
01229     if(!hit_vname.CompareTo(check_str)){
01230       TGeoNodeMatrix *cur_nod = (TGeoNodeMatrix *)nodes->At(i);
01231       fPromptVolume->RemoveNode(cur_nod);
01232       nfound++;
01233     }
01234   }
01235   nodes->Compress();
01236   if(nfound>1 && fVerboseLevel >= 1 ) Warning("RemoveHit","%d nodes with the same found",nfound);
01237   
01238   // ---
01239   //  Now re-set standard visibility for the original node
01240   SelectDetectorNode(det,ch);
01241   if(!fCurDetNode){
01242     Warning("RemoveHit","No node found for the required selection (det = %d ; ch = %d)",det,ch);
01243     return;
01244   }
01245 
01246   TGeoNode *OriNod; // useful for setting visibility
01247   Int_t slab = -1;  // used for TOF
01248   
01249   switch(det){
01250   case (Int_t) FIN_GTS:
01251     break;
01252   case (Int_t) FIN_TOF:  
01253     if(ch>=1 && ch <=K_N_TOFINO_SLABS) slab = ch;
01254     else if(ch>=101 && ch <= 100 + K_N_TOFONE_SLABS) slab = ch-100;
01255     else{
01256       Error("RemoveHit","Wrong slab number for TOF (%d)",slab);
01257       return;
01258     }
01259     OriNod = fCurDetNode->GetDaughter(slab-1);
01260     OriNod->SetVisibility(1);
01261     OriNod->VisibleDaughters(1);
01262     break;
01263   case (Int_t) FIN_ISM:
01264     break;
01265   case (Int_t) FIN_OSM:
01266     break;
01267   case (Int_t) FIN_LMD:
01268     break;
01269   case (Int_t) FIN_STB:
01270     break;
01271   default:
01272     Warning("FindDetectorNode","detector id \"%d\" not available",det);
01273     return;
01274   }
01275   
01276   // ---
01277   if(refresh_display) gGeoManager->ModifiedPad();
01278 }
01279 
01280 //_______________________________________
01281 void TFndEvd::ResetMrsHits(){
01282 
01283   ResetMrsTofiHits();
01284   ResetMrsSilHits();
01285   ResetMrsLmdHits();
01286 }
01287 
01288 //_______________________________________
01289 void TFndEvd::ResetMrsTofiHits(){
01290   // this is a private method
01291   
01292   for(Int_t i=0;i<2;i++){
01293     delete fMRS_TofHits[i];
01294     fMRS_TofHits[i] = new TPolyMarker3D();    
01295     //    fMRS_TofHits[i]->SetMarkerStyle( (i==0) ? 8   :  2);
01296     fMRS_TofHits[i]->SetMarkerStyle(8);
01297     fMRS_TofHits[i]->SetMarkerSize ( (i==0) ? 0.7 : 13 );
01298     fMRS_TofHits[i]->SetMarkerColor( (i==0) ? 2   : 50 );
01299   }
01300   
01301 }
01302 //_______________________________________
01303 void TFndEvd::ResetMrsSilHits(Int_t layer,Bool_t recreate_it){
01304   // layer values:
01305   //              0: both
01306   //              1: ISIM
01307   //              2: OSIM
01308 
01309   Int_t start_lay = (layer ==0) ? 0 : layer-1;
01310   Int_t stop_lay  = (layer ==0) ? 1 : layer-1;
01311 
01312   for(Int_t lay=start_lay;lay<=stop_lay;lay++){
01313     for(Int_t i=0;i<2;i++){
01314       if(recreate_it){
01315         delete fMRS_SilHits[lay][i];
01316         fMRS_SilHits[lay][i] = new TPolyMarker3D();    
01317       }
01318       //      cout << "LAY: " << lay << " ; I: " << i << endl;  
01319       fMRS_SilHits[lay][i]->SetMarkerStyle(8);
01320       fMRS_SilHits[lay][i]->SetMarkerSize(0.5);
01321       fMRS_SilHits[lay][i]->SetMarkerColor( (i==0) ? 3 : 4);
01322     }
01323   }
01324 
01325 }
01326 
01327 //_______________________________________
01328 void TFndEvd::ResetMrsLmdHits(){
01329   // this is a private method
01330   
01331   delete fMRS_LmdHits;
01332   fMRS_LmdHits = new TPolyMarker3D();    
01333   fMRS_LmdHits->SetMarkerStyle(3);
01334   fMRS_LmdHits->SetMarkerSize(3);
01335   fMRS_LmdHits->SetMarkerColor(2);
01336 
01337 }
01338 
01339 //_______________________________________
01340 void TFndEvd::RemoveAllHits(Bool_t reset_default_view,Bool_t refresh_display){
01341   // remove all hit nodes first
01342   // and re-set the original view
01343   
01344   if(!fPromptNode) return;
01345   
01346   fLmdWHits.Delete();
01347   fStbWHits.Delete();
01348   //  
01349   ResetMrsHits();
01350 
01351   // now hits represented by coloured volumes
01352   if(!fVolHitsList.empty()){
01353     if(fVerboseLevel >= 3) Printf("TFndGeometry::RemoveAllHits ---> %d hits will be removed",fVolHitsList.size());
01354     while(fVolHitsList.size()>0){
01355       //Info("TFndGeometry::RemoveAllHits","Removing hit (det: %d ; ch: %d)",fVolHitsList[0].det,fVolHitsList[0].ch);
01356       RemoveHit(fVolHitsList[0].det,fVolHitsList[0].ch);
01357     } // size is reduced and the first hit os recursively removed
01358     if(!fVolHitsList.empty()){
01359       Warning("RemoveAllHits","Still %d (vol) hits present after removal: clearing list",fVolHitsList.size());
01360       fVolHitsList.clear();
01361     }
01362   }
01363 }
01364 
01365 //_______________________________________
01366 void TFndEvd::PrintHits(Bool_t Selected){
01367   // print all geometric hits
01368   /* 
01369  if(!fHitVols){
01370     Warning("PrintHits","No volume-hits array defined");
01371     return;
01372   }
01373   if(!fHitVols->GetEntries()){
01374     Warning("PrintHits","No volume-hits array defined");
01375     return;
01376   }
01377     
01378   for(Int_t i=0;i<fHitVols->GetEntries();i++){
01379     fHitVols->At(i)->Dump();
01380   }
01381   */
01382 }
01383 
01384 //_________________________
01385 void TFndEvd::SetHitsVisibility(Int_t det, Bool_t visible){
01386   //  enum EFndGeoLayers { FGEO_BEAM_PIPE = 0,                 // Beam-pipe beryllium part
01387   //                   FGEO_TOFINO,                        // TOFINO active part (scintillators)
01388   //                   FGEO_ISIM, FGEO_TARGETS, FGEO_OSIM, // Vertex region
01389   //                   FGEO_INNER_LMD, FGEO_OUTER_LMD,     // inner and outer layers of LMD
01390   //                   FGEO_STRAW_TUBES,                   // View region occupied by straw tubes (all layers)
01391   //                   FGEO_STRAW_TUBES_1,FGEO_STRAW_TUBES_2,FGEO_STRAW_TUBES_3, // every straw-tubes layer
01392   //                   FGEO_STRAW_TUBES_4,FGEO_STRAW_TUBES_5,FGEO_STRAW_TUBES_6, // (memory consuming!!!)
01393   //                   FGEO_TOFONE };                         // TOFONE active part (scintillators)
01394   
01395   switch(det){
01396   case FGEO_TOFINO:
01397     break;
01398   case FGEO_ISIM:
01399     if(visible) ResetMrsSilHits(1,kFALSE);
01400     else for(Int_t i=0;i<2;i++) fMRS_SilHits[0][i]->SetMarkerStyle(0);
01401     break;
01402   case FGEO_OSIM: 
01403     if(visible) ResetMrsSilHits(2,kFALSE);
01404     else for(Int_t i=0;i<2;i++) fMRS_SilHits[1][i]->SetMarkerStyle(0);
01405     break;
01406   default:
01407     return;
01408   }
01409   
01410 }
01411 
01412 
01414 // Event management //
01416 
01417 //_________________________
01418 void TFndEvd::DisplayRandomEvent(Bool_t keep_current_hits){
01419   // Display a RANDOM event on every detector (for testing and demonstrations)
01420   //
01421   // the keep_current_hits argument allows to superimpose this
01422   // event to the previous EVD-view
01423 
01424   //  enum EFndDaqDetectors { FIN_GTS = 0, FIN_TOF, FIN_ISM, FIN_OSM, FIN_LMD, FIN_STB }; // description of all acquired detectors
01425   //  enum EFndGeoHitMode { FGEO_HIT_DETECTED = 0, FGEO_HIT_RECONSTRUCTED };
01426 
01427   if(!keep_current_hits) RemoveAllHits();
01428   Double_t ch = 1;
01429   
01430   // TOFINO
01431   for(Int_t i=0;i<2;i++){
01432     if(i!=0) ch+=0.001;
01433     HitDetector(FIN_TOF, (Int_t)(gRandom->Uniform(ch,ch+5.999)),FGEO_HIT_DETECTED,kFALSE);
01434     ch+=5.999;
01435   }
01436 
01437   // TOFONE
01438   ch = 101.;
01439   for(Int_t i=0;i<6;i++){
01440     if(i!=0) ch+=0.001;
01441     HitDetector(FIN_TOF, (Int_t)(gRandom->Uniform(ch,ch+11.999)),FGEO_HIT_DETECTED,kFALSE);
01442     ch+=11.999;
01443   }
01444 
01445   // SIL
01446   for(Int_t lay_sil=1;lay_sil<=2;lay_sil++){
01447     for(Int_t i=0;i<10;i++){
01448     TFndHSilCluster *sil_clu = new TFndHSilCluster(lay_sil);
01449     Int_t module = 1;
01450     sil_clu->SetModNum((Int_t)(gRandom->Uniform(1,8.49)));
01451     Int_t gcl = (gRandom->Rndm() > 0.4) ? 1 : 0;
01452     Int_t idcl = (gRandom->Rndm() > 0.7) ? 1 : 0;
01453     sil_clu->SetGoodCl(gcl);
01454     sil_clu->SetIDCl(idcl);
01455     Double_t p_phi = gRandom->Uniform(-3.,3.);
01456     Double_t p_zet = gRandom->Uniform(-7.,7.);
01457     sil_clu->SetLocalPosition(0,p_phi,p_zet);
01458     sil_clu->EvalHit(); 
01459     Int_t channel = sil_clu->GetModNum();
01460     Int_t cur_mod = (sil_clu->GetIDCl()==0) ? 0 : 1;
01461     Double_t m_x = sil_clu->GetMain_X();
01462     Double_t m_y = sil_clu->GetMain_Y();
01463     Double_t m_z = sil_clu->GetMain_Z();
01464     HitDetector( (sil_clu->GetLayer()==E_FIN_INNER_LAYER) ? FIN_ISM: FIN_OSM,
01465                  channel,cur_mod,kFALSE,m_x,m_y,m_z);
01466     if(fVerboseLevel >= 1) Printf("     ---> Random display for SIL: lay = %d; mod: %d; pos:(%.1f,%.1f,%.1f,)",lay_sil,module,m_x,m_y,m_z);
01467     delete sil_clu;
01468     } // clusters loop
01469   } // layers loop
01470   
01471   // LMD
01472   for(Int_t l=1;l<=K_N_LMD_LAYERS;l++){
01473     for(Int_t c=1;c<=K_N_LMD_CHAMS_PER_LAYER;c++){
01474       Int_t nmaxwir = (Int_t)(K_N_LMD_INNER_WIRES + 0.49);
01475       if(l==2) nmaxwir = (Int_t)(K_N_LMD_OUTER_WIRES + 0.49);
01476       Int_t cur_wir = (Int_t)(gRandom->Uniform(0.51,nmaxwir));
01477       if(fVerboseLevel >= 2) Printf("Random display for LMD: layer: %d; chamber: %d; wire: %d.",l,c,cur_wir);
01478       ch = (Double_t)(TFndDB::Lmd_ChannelToDBNumbering(l,c,cur_wir));
01479       if(fVerboseLevel >= 1) Printf("     ---> Random display for LMD: ch = %.0f",ch);
01480       HitDetector(FIN_LMD,(Int_t)(ch),FGEO_HIT_DETECTED,kFALSE);      
01481     }  
01482   }
01483 
01484   // STB
01485   for(Int_t cr=1;cr<=K_N_STB_CROWNS;cr++){
01486     for(Int_t i=0;i<2;i++){ // fizex number of random hits / crown
01487       Int_t cur_tube = (Int_t)(gRandom->Uniform(0.51,K_N_STB_TUBES + 0.49));
01488       if(fVerboseLevel >= 2) Printf("Random display for STB: crown: %d; tube: %d.",cr,cur_tube);
01489       ch = (Double_t)(TFndDB::Stb_ChannelToDBNumbering(cr,cur_tube));
01490       if(fVerboseLevel >= 1) Printf("     ---> Random display for STB: ch = %.0f",ch);
01491       HitDetector(FIN_STB,(Int_t)(ch),FGEO_HIT_DETECTED,kFALSE);            
01492     }
01493   }
01494   // ---
01495   LoadRandomTracks(keep_current_hits);
01496   DisplayTracks();
01497   // ---
01498   UpdateEVD();
01499 }
01500 
01501 
01502 //_________________________
01503 Int_t TFndEvd::GetEvent(){
01504   // Depending on the data_type the relative root-file is searched into the
01505   //  dedicated directory (environmental variables are used)
01506   //
01507   // return value:
01508   //                 0 ok
01509   //                -1 requested data-type not available
01510   //                -2 file not found (or bad)
01511   //                -3 tree not found (or corrupted)
01512   
01513   TString run_path; 
01514 #if defined _FND_OUTPUTS_USE_SUBDIR
01515   Bool_t use_subdir = ( fComboSelectRunType->GetSelected() == (Int_t)(RT_ONLM) ) ? kFALSE: kTRUE;
01516   TString rname = BuildRunName(fCurRunType,fCurRunNumber,use_subdir);
01517 #else
01518   TString rname = BuildRunName(fCurRunType,fCurRunNumber);
01519 #endif
01520   TString tree_name;
01521   TString branch_name;
01522   run_path.Form("%s/%s.hdt.root",ExpandPathName("$FND_HDT").Data(),rname.Data());
01523   tree_name = "FIN_HDT_TREE";
01524   branch_name = "fndhdt";
01525     
01526   if(fVerboseLevel >= 2) Info("GetEvent","Looking for root-file \"%s\"",run_path.Data());
01527 
01528   if(!CheckFileExistence(run_path)){ // 1 if file exists
01529     if(fVerboseLevel >= 2) Warning("GetEvent","file \"%s\" not found",run_path.Data());
01530     return -2;
01531   }
01532   
01533   // --- hdt file management
01534   // close current file if not needed by this event (reload anyway in online mode)
01535   if( ( fCurDataFile && fComboSelectRunType->GetSelected() == (Int_t)(RT_ONLM) ) ||
01536       ( fCurDataFile && fCurDataFile->IsOpen() && run_path.CompareTo(fCurDataFile->GetName())!=0 )
01537       ) {
01538     Info("GetEvent","Closing and deleting previous file: \"%s\"",fCurDataFile->GetName());
01539     fCurDataFile->Close(); 
01540     delete fCurDataFile; 
01541     fCurDataFile = 0;
01542   }
01543   if(!fCurDataFile){
01544     fCurDataFile = new TFile(run_path,"OPEN");
01545     if(fCurDataFile && fCurDataFile->IsOpen()){
01546      if(fVerboseLevel >= 1) Info("GetEvent","New file opened: \"%s\"",fCurDataFile->GetName());
01547     }
01548     else{
01549       Warning("GetEvent","Problems while trying to open file \"%s\"",fCurDataFile->GetName());
01550       delete fCurDataFile; fCurDataFile = 0;
01551       return -2;
01552     }
01553     // --- hdt/dst tree management (any previous tree )
01554     fCurEventTree = (TTree *)fCurDataFile->Get(tree_name);
01555     if(!fCurEventTree) {
01556       Warning("GetEvent","Problems while getting \"%s\" tree from file \"%s\"",tree_name.Data(),fCurDataFile->GetName());
01557       delete fCurDataFile; fCurDataFile = 0;
01558       delete fCurEventTree; fCurEventTree = 0;
01559       return -3;
01560     }
01561 
01562     fCurEventTree->SetBranchAddress(branch_name,&fCurHdt,TFndHdt::Class(),kOther_t,kTRUE); // assign event branch
01563     //fCurEventTree->LoadBaskets();
01564 
01565     if( fComboSelectRunType->GetSelected() == (Int_t)(RT_ONLM) ) { // TO BE UNDERSTOOD!!!
01566       fCurEventTree->Show(1);
01567       fCurEventTree->Fill(); 
01568       fCurEventTree->Show(1);
01569     }
01570     
01571   }
01572   else{
01573     if(fVerboseLevel >= 1) Info("GetEvent","Keeping previous file: \"%s\"",fCurDataFile->GetName());
01574   }
01575   // ---
01576   Int_t tot_entries = fCurEventTree->GetEntries();
01577   if(fVerboseLevel >= 1) Printf("GetEvent ---> Total number of events: %d",tot_entries);
01578 
01579   if(fCurEv > tot_entries){
01580     fNumGuiSelectEventNumber->SetNumber(tot_entries);
01581     if(fVerboseLevel >= 1) Printf("maximum number of entries reached: %d",tot_entries);
01582     SetEventNumber(tot_entries);
01583   }
01584 
01585   fCurEventTree->GetEntry(fCurEv-1); // event number 1 is at entry number 0
01586   return 0;
01587 }
01588 
01589 //_________________________
01590 void TFndEvd::DisplayEvent(Bool_t keep_current_hits,Bool_t reload){
01591   // Read the content of current event and display it
01592   //
01593   // the keep_current_hits argument allows to superimpose this
01594   // event to the previous EVD-view
01595 
01596   if(!fReadyToDisplay){
01597     if(fVerboseLevel>0) Info("DisplayEvent","Waiting for EVD initialization to be completed");
01598     return;
01599   }
01600   if(fRandomMode == kTRUE){
01601     DisplayRandomEvent(keep_current_hits);
01602     return;
01603   }
01604   
01605   ClearInfoCanvas();
01606   fMainCanvas->cd();
01607 
01608   if(!keep_current_hits){
01609     RemoveAllHits();
01610     if(fVerboseLevel >= 2) Info("DisplayEvent","All previous hits removed");
01611   }
01612 
01613   Int_t channel = 0;  
01614   Int_t n_hits = 0; // temporary use: number of hits for every detector
01615   Int_t n_sel_hits = 0; // temporary use: number of selected hits (to be displayed)
01616   
01617   if(reload) {
01618     if (GetEvent() !=0){
01619       // ---
01620       LoadTracks(keep_current_hits);
01621       DisplayTracks();
01622       // ---
01623       UpdateEVD();
01624       return;
01625     }
01626   }
01627   if(!fCurHdt){
01628     Error("DisplayEvent","maybe you have just found a BUG!");
01629     return;
01630   }  
01631   //  fCurHdt->Dump();
01632   if(fVerboseLevel >= 1) fCurHdt->PrintHits(fVerboseLevel,fVerboseLevel,fVerboseLevel,fVerboseLevel,fVerboseLevel);
01633   //fCurHdt->PrintHits(0,3,0,0,0);
01634   if(fVerboseLevel >= 1) Printf("Displaying event: %d (run %d)",fCurHdt->GetEventNumber(),fCurHdt->GetRunNumber());
01635 
01636   // TOF
01637   n_hits = fCurHdt->GetNumberOfTofHits();
01638   TFndHTof *tof_hit = 0;
01639   for(Int_t i=0;i<n_hits;i++){
01640     tof_hit = fCurHdt->GetTofHit(i);
01641     channel = tof_hit->GetChannel();
01642     if( CheckTofHit(tof_hit) ){
01643       Int_t cur_mod = 0;
01644       Double_t m_x = 0;
01645       Double_t m_y = 0;
01646       Double_t m_z = 0;
01647       if(tof_hit->GetBothTdc() != TFndHit::E_HIT_BOTH_CH) cur_mod = (Int_t)FGEO_HIT_DETECTED;
01648       else{
01649         cur_mod = (Int_t)FGEO_HIT_RECONSTRUCTED;
01650         m_x = tof_hit->GetMain_X();
01651         m_y = tof_hit->GetMain_Y();
01652         m_z = tof_hit->GetMain_Z();
01653       }
01654       HitDetector(FIN_TOF,channel,cur_mod,kFALSE,m_x,m_y,m_z);          
01655     }
01656     if(fVerboseLevel >= 3) Printf("     ---> Tof hit added (hit_id = %d): channel = %d",i,channel);
01657   }
01658   tof_hit = 0; // owned by TFndHit
01659 
01660   // SIL
01661   n_hits = fCurHdt->GetNumberOfSilClusters();
01662   n_sel_hits = 0; // used for checking maximum number of hits to be displayed
01663   for(Int_t i=0;i<n_hits;i++) if(CheckSilHit(fCurHdt->GetSilCluster(i))) n_sel_hits++;
01664   
01665   TFndHSilCluster *sil_hit = 0;
01666   for(Int_t i=0;i<n_hits;i++){
01667     sil_hit = fCurHdt->GetSilCluster(i);
01668     //if(!sil_hit) continue;
01669     channel = sil_hit->GetModNum();
01670     if( CheckSilHit(sil_hit) ){
01671       Int_t cur_mod = (sil_hit->GetIDCl()==0) ? 0 : 1;
01672       Double_t m_x = sil_hit->GetMain_X();
01673       Double_t m_y = sil_hit->GetMain_Y();
01674       Double_t m_z = sil_hit->GetMain_Z();
01675       HitDetector( (sil_hit->GetLayer()==E_FIN_INNER_LAYER) ? FIN_ISM: FIN_OSM,
01676                    channel,cur_mod,kFALSE,m_x,m_y,m_z);
01677     }
01678   }
01679   SetHitsVisibility(FGEO_ISIM,fDetectorVisibililty[FGEO_ISIM]);
01680   SetHitsVisibility(FGEO_OSIM,fDetectorVisibililty[FGEO_OSIM]);
01681   sil_hit = 0;
01682   
01683   // LMD
01684   n_hits = fCurHdt->GetNumberOfLmdHits();
01685   n_sel_hits = 0; // used for checking maximum number of hits to be displayed
01686   for(Int_t i=0;i<n_hits;i++) if(CheckLmdHit(fCurHdt->GetLmdHit(i))) n_sel_hits++;
01687 
01688   fWireHitsMode[FIN_LMD] = TFndEvdWireHit::K_EvtWHit_Complete;
01689   if(n_sel_hits >  40 && n_sel_hits <= 272){
01690     Warning("DisplayEvent","Lines will not be displayed for LMD (number of -selected- hits: %d)",n_sel_hits);
01691     fWireHitsMode[FIN_LMD] = TFndEvdWireHit::K_EvtWHit_MarksOnly;
01692   }
01693   else if(n_sel_hits >   150 && n_sel_hits <= 272){
01694     Warning("DisplayEvent","E-side markers only will be displayed for LMD (number of -selected- hits: %d)",n_sel_hits);
01695     fWireHitsMode[FIN_LMD] = TFndEvdWireHit::K_EvtWHit_E_MarksOnly;
01696   }
01697   else if(n_sel_hits > 272){ // markers will be always displayed (limit set to the meximum number of hits)
01698     Warning("DisplayEvent","No hits will be displayed for LMD (too many -selected- hits: %d)",n_sel_hits);
01699     fWireHitsMode[FIN_LMD] = TFndEvdWireHit::K_EvtWHit_NoObject;
01700   }
01701   TFndHLmd *lmd_hit = 0;
01702   for(Int_t i=0;i<n_hits;i++){
01703     lmd_hit = fCurHdt->GetLmdHit(i);
01704     //    if(lmd_hit->GetAdcE() > 450 && lmd_hit->GetAdcE() > 450  && lmd_hit->GetTdcE() && lmd_hit->GetTdcP()){
01705     if(CheckLmdHit(lmd_hit)){
01706       channel = lmd_hit->GetChannel();
01707       Int_t cur_mod = 0;
01708       Double_t m_x = 0;
01709       Double_t m_y = 0;
01710       Double_t m_z = 0;
01711       if( lmd_hit->GetLocal_Z() == -1 )  cur_mod = (Int_t)FGEO_HIT_DETECTED;    
01712       else{
01713         cur_mod = (Int_t)FGEO_HIT_RECONSTRUCTED;  
01714         m_x = lmd_hit->GetMain_X();
01715         m_y = lmd_hit->GetMain_Y();
01716         m_z = lmd_hit->GetMain_Z();
01717       }
01718       HitDetector(FIN_LMD,channel,cur_mod,kFALSE,m_x,m_y,m_z);          
01719       if(fVerboseLevel >= 3) Printf("     ---> Lmd hit added (hit_id = %d): channel = %d",i,channel);
01720     }
01721   }
01722   lmd_hit = 0; // owned by TFndHit
01723   
01724   // STB
01725   n_hits = fCurHdt->GetNumberOfStbHits();
01726   n_sel_hits = 0;
01727   for(Int_t i=0;i<n_hits;i++) if(CheckStbHit(fCurHdt->GetStbHit(i))) n_sel_hits++;
01728   
01729   fWireHitsMode[FIN_STB] = TFndEvdWireHit::K_EvtWHit_Complete;
01730   fPromptVolume->FindNode("SSTR_1")->GetVolume()->SetLineColor(29);
01731   fPromptVolume->FindNode("TSTR_1")->GetVolume()->SetLineColor(30);
01732   //   if(n_sel_hits >   80 && n_sel_hits <= 101){
01733   //     Warning("DisplayEvent","Lines will not be displayed for STB (number of -selected- hits: %d)",n_sel_hits);
01734   //     fWireHitsMode[FIN_STB] = TFndEvdWireHit::K_EvtWHit_MarksOnly;
01735   //   }
01736   //   else
01737   if(n_sel_hits >   100 && n_sel_hits <= 1000){
01738     Warning("DisplayEvent","E-side markers only will be displayed for STB (number of -selected- hits: %d)",n_sel_hits);
01739     fWireHitsMode[FIN_STB] = TFndEvdWireHit::K_EvtWHit_E_MarksOnly;
01740   }
01741   else if(n_sel_hits > 1000){ // markers will be always displayed (limit set to the meximum number of hits)
01742     Warning("DisplayEvent","No hits will be displayed for STB (more than 1500 -selected- hits: %d)",n_sel_hits);
01743     fPromptVolume->FindNode("SSTR_1")->GetVolume()->SetLineColor(2);
01744     fPromptVolume->FindNode("TSTR_1")->GetVolume()->SetLineColor(2);
01745     fWireHitsMode[FIN_STB] = TFndEvdWireHit::K_EvtWHit_NoObject;
01746   }
01747   TFndHStb *stb_hit = 0;
01748   for(Int_t i=0;i<n_hits;i++){
01749     stb_hit = fCurHdt->GetStbHit(i);
01750     //    channel = (Int_t)(TFndDB::Stb_ChannelToDBNumbering(stb_hit->GetCrown(),stb_hit->GetTube()));
01751     channel = stb_hit->GetChannel();
01752     HitDetector(FIN_STB,channel,FGEO_HIT_DETECTED,kFALSE);          
01753     if(fVerboseLevel >= 3) Printf("     ---> Stb hit added (hit_id = %d): channel = %d",i,channel);
01754   }
01755   stb_hit = 0; // owned by TFndHit
01756 
01757   // ---
01758   LoadTracks(keep_current_hits);
01759   DisplayTracks();
01760   // ---
01761   UpdateEVD();
01762 }
01763 
01764 //_________________________
01765 Int_t TFndEvd::CheckTofHit(TFndHTof *hit){
01766   // check single hit before displaying it
01767   // return value:
01768   //               0: no-good
01769   //               1: low-th 
01770   //               2: high-th
01771 
01772   Int_t result = 0; // take care: in this method "result" is treated in a different way
01773   
01774   Bool_t is_ok = kTRUE;
01775   
01776   Int_t lay = hit->GetLayer();
01777   if(lay < (Int_t) E_FIN_INNER_LAYER || lay > (Int_t) E_FIN_OUTER_LAYER)
01778     { // MUST NEVER OCCUR
01779       Error("CheckTofHit","Layer %d not defined for TOF (BUG!)",lay); 
01780       TerminateFroot();
01781     }
01782   
01783   Bool_t is_adc_e = kFALSE;      if(hit->GetAdcE() > 0) is_adc_e = kTRUE;
01784   Bool_t is_adc_p = kFALSE;      if(hit->GetAdcP() > 0) is_adc_p = kTRUE;
01785   Bool_t is_tdc_e_low = kFALSE;  if(hit->GetLowTdcE() > 0) is_tdc_e_low = kTRUE;
01786   Bool_t is_tdc_p_low = kFALSE;  if(hit->GetLowTdcP() > 0) is_tdc_p_low = kTRUE;
01787   Bool_t is_mt_low = kFALSE;     if(hit->GetLowMeanTimer() > 0) is_mt_low = kTRUE;
01788   Bool_t is_tdc_e_high = kFALSE;  if(hit->GetHighTdcE() > 0) is_tdc_e_high = kTRUE;
01789   Bool_t is_tdc_p_high = kFALSE;  if(hit->GetHighTdcP() > 0) is_tdc_p_high = kTRUE;
01790   Bool_t is_mt_high = kFALSE;     if(hit->GetHighMeanTimer() > 0) is_mt_high = kTRUE;
01791   
01792   if(lay == (Int_t) E_FIN_INNER_LAYER){ // TOFINO
01793     switch ( fSelOperation[(Int_t)E_EvdDet_Tofino] ) { // "if" souuld be enough, but using switch allows further development
01794     case E_Evd_SelOper_AND_sel: 
01795       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_AdcE] ) is_ok = is_ok && is_adc_e;
01796       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_AdcP] ) is_ok = is_ok && is_adc_p;
01797       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcE_Low] ) is_ok = is_ok && is_tdc_e_low;
01798       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcP_Low] ) is_ok = is_ok && is_tdc_p_low;
01799       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_Mt_Low] ) is_ok = is_ok && is_mt_low;
01800       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcE_High] ) is_ok = is_ok && is_tdc_e_high;
01801       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcP_High] ) is_ok = is_ok && is_tdc_p_high;
01802       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_Mt_High] ) is_ok = is_ok && is_mt_high;
01803       break;
01804     case E_Evd_SelOper_AND_all: 
01805       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_AdcE] ) is_ok = is_ok && is_adc_e;
01806       else is_ok = is_ok && !is_adc_e;
01807       
01808       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_AdcP] ) is_ok = is_ok && is_adc_p;
01809       else is_ok = is_ok && !is_adc_p;
01810       
01811       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcE_Low] ) is_ok = is_ok && is_tdc_e_low;
01812       else is_ok = is_ok && !is_tdc_e_low;
01813       
01814       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcP_Low] ) is_ok = is_ok && is_tdc_p_low;
01815       else is_ok = is_ok && !is_tdc_p_low;
01816       
01817       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_Mt_Low] ) is_ok = is_ok && is_mt_low;
01818       else is_ok = is_ok && !is_mt_low;
01819       
01820       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcE_High] ) is_ok = is_ok && is_tdc_e_high;
01821       else is_ok = is_ok && !is_tdc_e_high;
01822       
01823       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_TdcP_High] ) is_ok = is_ok && is_tdc_p_high;
01824       else is_ok = is_ok && !is_tdc_p_high;
01825       
01826       if( fSelConsider[(Int_t)E_EvdDet_Tofino][(Int_t) E_EvdSelMod_Mt_High] ) is_ok = is_ok && is_mt_high;
01827       else is_ok = is_ok && !is_mt_high;
01828       
01829       break;
01830     default: 
01831       Warning("CheckTofHit","operation \"%d\" not supported",fSelOperation[(Int_t)E_EvdDet_Lmd]);
01832     }
01833     
01834   } // tofino completed
01835   else if(lay == (Int_t) E_FIN_OUTER_LAYER){ // TOFONE
01836     switch ( fSelOperation[(Int_t)E_EvdDet_Tofone] ) { // "if" souuld be enough, but using switch allows further development
01837     case E_Evd_SelOper_AND_sel: 
01838       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_AdcE] ) is_ok = is_ok && is_adc_e;
01839       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_AdcP] ) is_ok = is_ok && is_adc_p;
01840       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_TdcE_Low] ) is_ok = is_ok && is_tdc_e_low;
01841       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_TdcP_Low] ) is_ok = is_ok && is_tdc_p_low;
01842       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_Mt_Low] ) is_ok = is_ok && is_mt_low;
01843       break;
01844     case E_Evd_SelOper_AND_all: 
01845       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_AdcE] ) is_ok = is_ok && is_adc_e;
01846       else is_ok = is_ok && !is_adc_e;
01847       
01848       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_AdcP] ) is_ok = is_ok && is_adc_p;
01849       else is_ok = is_ok && !is_adc_p;
01850       
01851       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_TdcE_Low] ) is_ok = is_ok && is_tdc_e_low;
01852       else is_ok = is_ok && !is_tdc_e_low;
01853       
01854       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_TdcP_Low] ) is_ok = is_ok && is_tdc_p_low;
01855       else is_ok = is_ok && !is_tdc_p_low;
01856       
01857       if( fSelConsider[(Int_t)E_EvdDet_Tofone][(Int_t) E_EvdSelMod_Mt_Low] ) is_ok = is_ok && is_mt_low;
01858       else is_ok = is_ok && !is_mt_low;
01859       break;
01860     default: 
01861       Warning("CheckTofHit","operation \"%d\" not supported",fSelOperation[(Int_t)E_EvdDet_Lmd]);
01862     }    
01863   } // tofone completed
01864   
01865   
01866   // ---
01867   if(!is_ok) result = 0;
01868   else{
01869     result = 1;
01870     if(lay == (Int_t) E_FIN_INNER_LAYER  && is_tdc_e_high && is_tdc_p_high && is_mt_high) result = 2;
01871   }
01872   
01873   return result;
01874 }
01875 
01876 //_________________________
01877 Bool_t TFndEvd::CheckSilHit(TFndHSilCluster *hit){
01878   // NOTE: method to be controlled
01879 
01880   //  Bool_t result = kTRUE;
01881 
01882   Bool_t is_clean = kFALSE; if( hit->GetGoodCl() != 0 ) is_clean = kTRUE;
01883 
01884   return is_clean;
01885 }
01886 
01887 //_________________________
01888 Bool_t TFndEvd::CheckLmdHit(TFndHLmd *hit){
01889   // check single hit before displaying it
01890 
01891   //   E_EvdSelHitOper fSelOperation[(Int_t)E_EvdDet_End]; // operation to be performed (on selected hit modes)
01892   
01893   Bool_t result = kTRUE;
01894   
01895   Bool_t is_adc_e = kFALSE;  if(hit->GetAdcE() > 0) is_adc_e = kTRUE;
01896   Bool_t is_adc_p = kFALSE;  if(hit->GetAdcP() > 0) is_adc_p = kTRUE;
01897   Bool_t is_tdc_e = kFALSE;  if(hit->GetTdcE() > 0) is_tdc_e = kTRUE;
01898   Bool_t is_tdc_p = kFALSE;  if(hit->GetTdcP() > 0) is_tdc_p = kTRUE;
01899   
01900   switch ( fSelOperation[(Int_t)E_EvdDet_Lmd] ) { // "if" souuld be enough, but using switch allows further development
01901   case E_Evd_SelOper_AND_sel:
01902     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_AdcE] ) result = result && is_adc_e;
01903     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_AdcP] ) result = result && is_adc_p;
01904     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_TdcE_Low] ) result = result && is_tdc_e;
01905     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_TdcP_Low] ) result = result && is_tdc_p;
01906     break;
01907   case E_Evd_SelOper_AND_all:
01908     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_AdcE] ) result = result && is_adc_e;
01909     else result = result && !is_adc_e;
01910 
01911     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_AdcP] ) result = result && is_adc_p;
01912     else result = result && !is_adc_p;
01913 
01914     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_TdcE_Low] ) result = result && is_tdc_e;
01915     else result = result && !is_tdc_e;
01916 
01917     if( fSelConsider[(Int_t)E_EvdDet_Lmd][(Int_t) E_EvdSelMod_TdcP_Low] ) result = result && is_tdc_p;
01918     else result = result && !is_tdc_p;
01919     
01920     break;
01921   default:
01922     Warning("CheckLmdHit","operation \"%d\" not supported",fSelOperation[(Int_t)E_EvdDet_Lmd]);
01923   }
01924   
01925   
01926   return result;
01927 }
01928 
01929 //_________________________
01930 Bool_t TFndEvd::CheckStbHit(TFndHStb *hit){
01931   // check single hit before displaying it
01932   // still don't know what kind of check is required (if any)
01933 
01934   Bool_t result = kTRUE; // temporary forced to true
01935 
01936   return result;
01937 }
01938 
01939 
01943 //_________________________
01944 void TFndEvd::SetDefaulHitSelection(){
01945   
01946   fComboHitSelOper[(Int_t)E_EvdDet_Tofino]->Select( (Int_t)E_Evd_SelOper_AND_sel ,kTRUE);
01947   fComboHitSelOper[(Int_t)E_EvdDet_Sil]->Select( (Int_t)E_Evd_SelOper_AND_sel ,kTRUE);
01948   fComboHitSelOper[(Int_t)E_EvdDet_Lmd]->Select( (Int_t)E_Evd_SelOper_AND_sel ,kTRUE);
01949   fComboHitSelOper[(Int_t)E_EvdDet_Tofone]->Select( (Int_t)E_Evd_SelOper_AND_sel ,kTRUE);
01950 
01951   // ---
01952   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_AdcE , kFALSE);
01953   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_AdcP , kFALSE);
01954   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_TdcE_Low , kFALSE);
01955   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_TdcP_Low , kFALSE);
01956   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_Mt_Low , kTRUE);
01957   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_TdcE_High , kFALSE);
01958   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_TdcP_High , kFALSE);
01959   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->Select((Int_t)E_EvdSelMod_Mt_High , kFALSE);
01960   //
01961   fListBox_SelMod[(Int_t)E_EvdDet_Tofino]->SelectionChanged();
01962   // ---
01963   fListBox_SelMod[(Int_t)E_EvdDet_Sil]->Select((Int_t)E_EvdSelMod_SelSil_Clean , kTRUE);
01964   //
01965   fListBox_SelMod[(Int_t)E_EvdDet_Sil]->SelectionChanged();
01966   // ---
01967   fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->Select((Int_t)E_EvdSelMod_AdcE , kTRUE);
01968   fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->Select((Int_t)E_EvdSelMod_AdcP , kTRUE);
01969   fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->Select((Int_t)E_EvdSelMod_TdcE_Low , kTRUE);
01970   fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->Select((Int_t)E_EvdSelMod_TdcP_Low , kTRUE);
01971   //
01972   fListBox_SelMod[(Int_t)E_EvdDet_Lmd]->SelectionChanged();
01973   // ---
01974   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Select((Int_t)E_EvdSelMod_AdcE , kFALSE);
01975   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Select((Int_t)E_EvdSelMod_AdcP , kFALSE);
01976   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Select((Int_t)E_EvdSelMod_TdcE_Low , kFALSE);
01977   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Select((Int_t)E_EvdSelMod_TdcP_Low , kFALSE);
01978   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->Select((Int_t)E_EvdSelMod_Mt_Low , kTRUE);
01979   //
01980   fListBox_SelMod[(Int_t)E_EvdDet_Tofone]->SelectionChanged();
01981 
01982 }
01983 
01984 //_________________________
01985 void TFndEvd::CheckSingleSelOper(E_EvdDets det){
01986 
01987   Int_t cur_det = (Int_t) det;
01988   Int_t Selection = fComboHitSelOper[cur_det]->GetSelected();
01989 
01990   if(fVerboseLevel >= 2) Printf("CheckSingleSelOper called for %s: \"%s\"",GetEvdDet( det).Data(),GetOperName( (E_EvdSelHitOper) Selection).Data());
01991   
01992   fSelOperation[cur_det] = (E_EvdSelHitOper) Selection;
01993 }
01994 
01995 //_________________________
01996 void TFndEvd::PrintOperSel(E_EvdDets det){
01997   
01998   Printf("PrintOperSel called for %s: sel_id = %d",GetEvdDet( det).Data(),fSelOperation[(Int_t) det]);
01999 
02000 }
02001 
02002 //_________________________
02003 void TFndEvd::SetDetSelOper_TOFI(Int_t sel){
02004   
02005   CheckSingleSelOper(E_EvdDet_Tofino);
02006   DisplayEvent();
02007   PrintOperSel(E_EvdDet_Tofino);
02008 }
02009 
02010 //_________________________
02011 void TFndEvd::SetDetSelOper_SIL(Int_t sel){
02012   
02013   CheckSingleSelOper(E_EvdDet_Sil);
02014   DisplayEvent();
02015   PrintOperSel(E_EvdDet_Sil);
02016 }
02017 
02018 //_________________________
02019 void TFndEvd::SetDetSelOper_LMD(Int_t sel){
02020   
02021   CheckSingleSelOper(E_EvdDet_Lmd);
02022   DisplayEvent();
02023   PrintOperSel(E_EvdDet_Lmd);
02024 }
02025 
02026 //_________________________
02027 void TFndEvd::SetDetSelOper_TOFO(Int_t sel){
02028   
02029   CheckSingleSelOper(E_EvdDet_Tofone);
02030   DisplayEvent();
02031   PrintOperSel(E_EvdDet_Tofone);
02032 }
02033 
02035 //_________________________
02036 void TFndEvd::CheckSingleSelList(E_EvdDets det){
02037  
02038   Int_t cur_det = (Int_t) det;
02039 
02040   Bool_t is_tofi = kFALSE;
02041   if(det == E_EvdDet_Tofino)is_tofi = kTRUE;
02042   Bool_t is_sil = kFALSE;
02043   if(det == E_EvdDet_Sil)is_sil = kTRUE;
02044   
02045   for(Int_t mod = (Int_t)E_EvdSelMod_AdcE; mod < (Int_t)E_EvdSelMod_End; mod++){
02046     fSelConsider[cur_det][mod] = kFALSE;
02047   }
02048   
02049   
02050   if(fVerboseLevel >= 2) Printf("CheckSingleSelList called for %s",GetEvdDet( det).Data());
02051   
02052   TList *sel_list = new TList();
02053   fListBox_SelMod[cur_det]->GetSelectedEntries(sel_list);
02054   
02055   TGLBEntry *lb_entry = 0;
02056   for(Int_t index=0; index<sel_list->GetEntries(); index++){  
02057     lb_entry = (TGLBEntry *) ( sel_list->At(index) );
02058     //    lb_entry->Print();
02059     Int_t mod = lb_entry->EntryId();
02060     if(fVerboseLevel >= 3){
02061       if(is_sil) Printf(" ===> \"%s\" selected ",GetSelHitMode_Sil( (E_EvdSelHitMode_Sil)mod).Data() );
02062       else Printf(" ===> \"%s\" selected ",GetSelHitMode( (E_EvdSelHitMode)mod,is_tofi).Data() );
02063     }
02064     fSelConsider[cur_det][mod] = kTRUE;
02065   }
02066   if(fVerboseLevel >= 2) Printf("------------------------------");
02067   
02068 }
02069 
02070 //_________________________
02071 void TFndEvd::PrintConsiderSel(E_EvdDets det){
02072   
02073   Printf("PrintConsiderSel called for %s",GetEvdDet( det).Data());
02074   
02075   Int_t cur_det = (Int_t) det;
02076   
02077   Bool_t is_tofi = kFALSE;
02078   if(det == E_EvdDet_Tofino)is_tofi = kTRUE;
02079   Bool_t is_sil = kFALSE;
02080   if(det == E_EvdDet_Sil)is_sil = kTRUE;
02081   
02082   if(is_sil){
02083     for(Int_t mod = (Int_t)E_EvdSelMod_SelSil_Clean; mod < (Int_t)E_EvdSelMod_SelSil_End; mod++){
02084       Printf("=======> %s: %d",GetSelHitMode_Sil( (E_EvdSelHitMode_Sil)mod).Data(),fSelConsider[cur_det][mod]);
02085     }
02086   }
02087   else{
02088     for(Int_t mod = (Int_t)E_EvdSelMod_AdcE; mod < (Int_t)E_EvdSelMod_End; mod++){
02089       Printf("=======> %s: %d",GetSelHitMode( (E_EvdSelHitMode)mod,is_tofi).Data(),fSelConsider[cur_det][mod]);
02090     }
02091   }
02092 }
02093 
02094 //_________________________
02095 void TFndEvd::CheckConsiderSel_TOFI(){
02096   CheckSingleSelList(E_EvdDet_Tofino);
02097   DisplayEvent();
02098   if(fVerboseLevel >= 2) PrintConsiderSel(E_EvdDet_Tofino);
02099 }
02100 
02101 //_________________________
02102 void TFndEvd::CheckConsiderSel_SIL(){
02103   CheckSingleSelList(E_EvdDet_Sil);
02104   DisplayEvent();
02105   if(fVerboseLevel >= 2) PrintConsiderSel(E_EvdDet_Sil);
02106 }
02107 
02108 //_________________________
02109 void TFndEvd::CheckConsiderSel_LMD(){
02110   CheckSingleSelList(E_EvdDet_Lmd);
02111   DisplayEvent();
02112   if(fVerboseLevel >= 2) PrintConsiderSel(E_EvdDet_Lmd);
02113 }
02114 
02115 //_________________________
02116 void TFndEvd::CheckConsiderSel_TOFO(){
02117   CheckSingleSelList(E_EvdDet_Tofone);
02118   DisplayEvent();
02119   if(fVerboseLevel >= 2) PrintConsiderSel(E_EvdDet_Tofone);
02120 }
02121 
02123 // Reconstructed Information //
02124 // (pre-analysis trees used) //
02126 
02127 //_________________________
02128 void TFndEvd::DisplayTracks(){
02129   // Display into current canvas all tracks in memory
02130   
02131   for(Int_t i=0;i<fTracksArray->GetEntries();i++){
02132     ((TFndEvdTrack *)(fTracksArray->At(i) ) )->Draw();
02133   }
02134 
02135 #ifdef _FND_OUTPUTS_USE_SUBDIR
02136   fPreanRef->CloseCurrentSourceFile();
02137 #endif
02138   
02139 }
02140 
02141 //_________________________
02142 Int_t TFndEvd::LoadRecFile(){
02143   // return value:
02144   //               0: ok
02145   //              -1: error
02146 
02148 #if !defined FNDEVD_USE_PREAN
02149   Warning("LoadTracks","Can not load pre-analysis tracks (feature disabled)");
02150   return -1;
02151 #endif
02152   
02153   TString cpth = "$FND_PREAN_TREES/";
02154   cpth+=FidaVer_Name( (E_FndFidaVersion)(fComboFidaVer->GetSelected()) );
02155   TString start_pth=ExpandPathName(cpth);  
02156   TString fnam;
02157   
02158 #if defined _FND_OUTPUTS_USE_SUBDIR
02159   TString frunnam = BuildRunName(fCurRunType,fCurRunNumber,kTRUE);
02160 #else
02161   TString frunnam = BuildRunName(fCurRunType,fCurRunNumber);
02162 #endif
02163   
02164   fnam.Form("%s/%s.prean.root",
02165             start_pth.Data(),
02166             frunnam.Data() );
02167 
02168 
02169   if(fVerboseLevel >= 2) Printf("Pre-analysis interface is looking for file: \"%s\"",fnam.Data());
02170   
02171   if( fPreanRef->LoadTrees(fnam) != 0){
02172     if(fVerboseLevel >= 1) Printf("prean. not ready for file \"%s\"",fnam.Data());
02173     return -1;
02174   }
02175   
02176   if(fVerboseLevel >= 2) Printf("***************** file ok: \"%s\" *****************",fnam.Data());
02177 
02178   return 0;
02179 }
02180 
02181 //_________________________
02182 void TFndEvd::LoadTracks(Bool_t keep_current){
02183   // - look for required reconstructed run
02184   //    (depending on the current-selected reconstruction release)  
02185   // - find current event inside reconstructed-trees (HYPE-BHABHA)
02186   // - Build tracks array
02187   
02188   if(!fUseTracks){
02189     RemoveAllTracks();
02190     return;
02191   }
02192   if(!keep_current) RemoveAllTracks();
02193   
02194   if(LoadRecFile() != 0) return;
02195   // ---
02196 
02197 
02198   //   if(fPreanRef->fHypeTree) fPreanRef->fHypeTree->Print();
02199   //   if(fPreanRef->fBhabhaTree) fPreanRef->fBhabhaTree->Print();
02200   
02201   Int_t mode = -2; // -1; not-reconstructed ; 0: bhabha ; 1: hype
02202   Int_t ev_err = fPreanRef->GoToEvent(fCurEv,mode);
02203   if(ev_err!=0) return;
02204   
02205   Printf("Loading Tracks: ev_err= %d; mode= %d",ev_err,mode);
02206 
02207   TFndEvdTrack *cur_evd_trk = 0;
02208 
02209   TFndTrack *CurTrack = 0; // track of pre-analysis branch (from kaons)
02210 
02211   Double_t  x = 0;
02212   Double_t  y = 0;
02213   Double_t  z = 0;
02214   Int_t charge = 0;
02215   Double_t rad = 0;
02216   Double_t cx = 0; // dir-cos
02217   Double_t cy = 0;
02218   Double_t cz = 0;
02219   Double_t len = 0;
02220 
02221   // --- support for fitted and neutral tracks
02222   Double_t mom = 0;
02223   Double_t lam = 0;
02224   Double_t phi = 0;
02225   //  Double_t mom_transv = 0; // used while evaluating radius
02226 
02227   Bool_t is_fitted = kFALSE;
02228 
02229   Int_t ti = -1; // track index
02230   Int_t ntrks = -1; // number of associated tracks
02231   Float_t tof = -1; // Time Of Flight (ns)
02232 
02233   switch(mode){
02234   case 0: // bhabha (2 tracks expected)
02235     for(Int_t pi=FPh_BhaElec_id; pi<=FPh_BhaPosit_id; pi++){
02236       if(fPreanRef->fBhaMom[pi] != 0 ){     
02237         //
02238         x = (Double_t) ( fPreanRef->fBhaGeoFitPoint_X[pi] );
02239         y = (Double_t) ( fPreanRef->fBhaGeoFitPoint_Y[pi] );
02240         z = (Double_t) ( fPreanRef->fBhaGeoFitPoint_Z[pi] );
02241         charge = (Int_t)( fPreanRef->fForeseenSign[pi] );
02242         rad = (Double_t)( fPreanRef->fBhaGeoPRradius[pi] );
02243         cx = (Double_t) ( fPreanRef->fBhaGeoFitDirCos_X[pi] );
02244         cy = (Double_t) ( fPreanRef->fBhaGeoFitDirCos_Y[pi] );
02245         cz = (Double_t) ( fPreanRef->fBhaGeoFitDirCos_Z[pi] );
02246         len = (Double_t) ( fPreanRef->fBhaTrackLength[pi] );
02247         //
02248         if(rad < 0) continue;
02249         cur_evd_trk = AddTrack(0,0,1);
02250         cur_evd_trk->BuildHelix(x,y,z,charge,rad,cx,cy,cz,len);
02251         cur_evd_trk->SetPID( (pi==FPh_BhaElec_id) ? (Int_t)(FPh_PID_Electron) : (Int_t)(FPh_PID_Positron) );
02252       }
02253     }
02254     break;
02255   case 1: // hype (no limitation to the number of reconstructed tracks)
02256     for(Int_t Kid=0;Kid<2;Kid++){ // Kmin,Kplu (as defined in FIN_PHYS.h)
02257       ntrks = (Kid==0) ? fPreanRef->fTracks_Kmin->GetEntries() : fPreanRef->fTracks_Kplu->GetEntries() ;
02258       for(ti=0;ti<ntrks;ti++){
02259         CurTrack = (Kid==0) ?
02260           (TFndTrack *) ( (fPreanRef->fTracks_Kmin)->At(ti) ) :
02261           (TFndTrack *) ( (fPreanRef->fTracks_Kplu)->At(ti) ) ;
02262         // load pattern-recognition results
02263         charge = (Int_t)( CurTrack->fCharge);
02264         x   = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_X] );
02265         y   = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_Y] );
02266         z   = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_Z] );
02267         rad = (Double_t)( CurTrack->fPR_Helix[TFndTrack::E_Hel_R] );
02268         cx  = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_cosX] );
02269         cy  = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_cosY] );
02270         cz  = (Double_t)( CurTrack->fStart[TFndTrack::E_Trk_cosZ] );
02271         len = (Double_t)( CurTrack->fLength );
02272         //
02273         // in case of succesful load results from fit
02274         if(CurTrack->fFitErr == TFndTrack::E_Trk_Fit_Success ){
02275           is_fitted = kTRUE;
02276           mom = CurTrack->fSpecMom;
02277           //      mom = CurTrack->fFit_MomVert[TFndTrack::E_Hel_Mom];
02278           lam = CurTrack->fFit_MomVert[TFndTrack::E_Hel_Lam];
02279           phi = CurTrack->fFit_MomVert[TFndTrack::E_Hel_Phi];
02280           rad = TrackRad_FromMom(mom,lam,1);
02281         }
02282         cur_evd_trk = AddTrack(0,0,1);
02283         // track inspected: now store it
02284         if(charge != 0 ){
02285           CurTrack->PrintData(2);
02286           if(is_fitted){
02287             cout << "FITTED from K (id " << Kid << " )" << endl;
02288             //      cout << x << " " << y << " " << z << " ; " << phi << " " << lam << " ; " << len << endl;
02289             //      cur_evd_trk->BuildLine(x,y,z, phi,lam, len);
02290             cur_evd_trk->BuildHelix(x,y,z,charge,rad,TMath::RadToDeg() * phi,TMath::RadToDeg() * lam,len);
02291             cur_evd_trk->SetPID((Int_t)(CurTrack->fBackTrack[TFndTrack::E_Trk_Bcktrk_pid]));
02292           }
02293           else cur_evd_trk->BuildHelix(x,y,z,charge,rad,cx,cy,cz,len);
02294         }
02295         // neutral tracks still to be debugged (disabled for now...)
02296         
02297         if(charge == 0){
02298           x   = (Double_t)( fPreanRef->fHyp_K_StopPoint_X[Kid] );
02299           y   = (Double_t)( fPreanRef->fHyp_K_StopPoint_Y[Kid] );
02300           z   = (Double_t)( fPreanRef->fHyp_K_StopPoint_Z[Kid] );
02301           mom = CurTrack->fPR_MomVert[TFndTrack::E_Hel_Mom];
02302           lam = CurTrack->fPR_MomVert[TFndTrack::E_Hel_Lam];
02303           phi = CurTrack->fPR_MomVert[TFndTrack::E_Hel_Phi];
02304           tof = CurTrack->fTOF;
02305           if(x != 0 && y !=0 && z !=0 && mom != 0 && tof != 0){
02306             cout << "Neutral track from K (id " << Kid << " )" << endl;
02307             len = 137 / TMath::Cos(TMath::DegToRad() * lam);
02308             cout << x << " " << y << " " << z << " ; " << phi << " " << lam << " ; " << len << endl;
02309             cur_evd_trk->BuildLine(x,y,z, phi, lam, len);
02310           }
02311         } // neutral tracks to be debugged (still disabled...)
02312         
02313       } // tracks completed
02314 
02315 
02318       /*
02319       cur_evd_trk = AddTrack(0,0,1);
02320       Double_t kaonstx = fPreanRef->fHyp_PhiDecayPos[0];
02321       Double_t kaonsty = fPreanRef->fHyp_PhiDecayPos[1];
02322       Double_t kaonstz = fPreanRef->fHyp_PhiDecayPos[2];
02323       Double_t kaoncx = static_cast<Double_t>(fPreanRef->fHyp_K_Vert_Center_X[Kid]);
02324       Double_t kaoncy = static_cast<Double_t>(fPreanRef->fHyp_K_Vert_Center_Y[Kid]);
02325       Double_t kaoncz = 0;
02326       Double_t kaonr  = static_cast<Double_t>(fPreanRef->fHyp_K_Vert_Radius[Kid]);
02327       Int_t kaonchrg = ( Kid== (Int_t)(FPh_HypKmin_id) )? -1 : 1;
02328       // length and dircos to be determined...
02329       cur_evd_trk->BuildHelix(kaonstx,kaonsty,kaonstz,kaonchrg,kaonr,.5,.5,.5,10);
02330       */
02331 
02332     } // Kmin/Kplu completed
02333     //
02334     break;
02335   default: return;
02336   }
02337  
02338 }
02339 
02340 //_________________________
02341 void TFndEvd::LoadRandomTracks(Bool_t keep_current){
02342   // used to test the Event displaying (and for demo)
02343   
02344   if(!fUseTracks){
02345     RemoveAllTracks();
02346     return;
02347   }
02348   if(!keep_current) RemoveAllTracks();
02349   
02350   
02351   TFndEvdTrack *cur_evd_trk = 0;
02352   for(Int_t i=0;i<5;i++){
02353     Bool_t is_helix = (gRandom->Rndm() > 0.2) ? kTRUE : kFALSE;
02354     Double_t rnd_tmp = gRandom->Rndm();
02355     Int_t cur_pid = (rnd_tmp > 0.4) ? 11 : 14;
02356     if(rnd_tmp > 0.8) cur_pid = (rnd_tmp > 0.9) ? 13 : 1;
02357 
02358     Double_t pxhe = gRandom->Gaus(0,100);
02359     Double_t pyhe = gRandom->Gaus(2,20);
02360     Double_t pzhe = gRandom->Gaus(5,50);
02361     Double_t phiel = gRandom->Uniform(-70,70);
02362     Double_t lamel = gRandom->Uniform(-70,70);
02363     Double_t radius = gRandom->Gaus(120,30);
02364     Int_t charge = (gRandom->Rndm() > 0.35) ? -1 : +1;
02365     Double_t Lengthel = gRandom->Gaus(200,50);
02366     //
02367     Double_t pxli = gRandom->Uniform(-30,30);
02368     Double_t pyli = gRandom->Gaus(0,10);
02369     Double_t pzli = gRandom->Uniform(-70,70);
02370     Double_t phili = gRandom->Uniform(-70,70);
02371     Double_t lamli = gRandom->Uniform(-70,70);
02372     Double_t Lengthli = gRandom->Gaus(200,50);
02373     
02374     //
02375     cur_evd_trk = AddTrack(0,0,1);
02376     if(is_helix){ 
02377       cur_evd_trk->BuildHelix(pxhe,pyhe,pzhe, charge,radius, phiel, lamel, Lengthel);
02378     }
02379     else{ 
02380       cur_evd_trk->BuildLine(pxli,pyli,pzli, phili, lamli, Lengthli);
02381     }
02382     cur_evd_trk->SetPID(cur_pid);
02383   }
02384   cur_evd_trk = 0;
02385 
02386 }
02387 
02388 //_________________________
02389 TFndEvdTrack *TFndEvd::AddTrack(const Double_t &Bx,const Double_t &By,const Double_t &Bz){
02390 
02391   Int_t last_id = fTracksArray->GetEntries();
02392   
02393   TClonesArray &ctracks = *fTracksArray;
02394   TFndEvdTrack *th = new(ctracks[last_id]) TFndEvdTrack(Bx,By,Bz);
02395   if(fVerboseLevel >= 2) Printf("TFndEvd::AddTrack ---> Track added : B = (%.1f , %.1f , %.1f) ",Bx,By,Bz);
02396   return th;
02397   
02398 }
02399 
02400 //_________________________
02401 void TFndEvd::RemoveAllTracks(){
02402 
02403   if(fTracksArray) fTracksArray->Delete();
02404 }
02405 
02406 
02408 // Saving / Printing //
02410 
02411 //_________________________
02412 void TFndEvd::StoreCurrentDisplay(){
02413   
02414   SaveCurrentDisplay();
02415   ShowSavedDisplay();
02416   
02417 }
02418 
02419 //_________________________
02420 void TFndEvd::SaveCurrentDisplay(E_FndEvd_SaveMode mode,TString fnam){
02421   //   enum E_FndEvd_SaveMode {
02422   //     E_FndEvd_Save_HiddenTmp = 0, // recreate tmp hiddden file 
02423   //     E_FndEvd_Save_DefaultName = 1, // use a default name in cur-dir (and replace) 
02424   //     E_FndEvd_Save_CustomName = 2 // ask for file-name in cur-dir (and replace) 
02425   //   };
02426   
02427   fMainCanvas->cd();
02428   if( fnam.IsNull() ) fnam = ExpandPathName("$FND_WRK/evd.save.gif");
02429   // 
02430   //  gVirtualGL->CaptureViewer(fGLSAViewer, TGLOutput::kPDF_BSP, fnam.Data());
02431   //fMainCanvas->SaveAs(fnam);
02432 
02433   fGLSAViewer->ProcessFrameMessage(257,11,0);
02434   TString cmd;
02435   cmd.Form("mv %s %s", "viewer.gif",fnam.Data());
02436   gSystem->Exec(cmd);
02437   // save eps ======> msg: 257 parm1: 8
02438   // save pdf ======> msg: 257 parm1: 9
02439   // save png ======> msg: 257 parm1: 10
02440   // save gif ======> msg: 257 parm1: 11
02441   // save jpg ======> msg: 257 parm1: 12
02442   if(fVerboseLevel>0) Info("SaveCurrentDisplay","Display saved");
02443 
02444 } 
02445 
02446 //_________________________
02447 void TFndEvd::ShowSavedDisplay(TString filename){
02448   
02449   if(!fInfoCanvas){
02450     Warning("ShowSavedDisplay","InfoCanvas not defined: can not show pictures");
02451     return;
02452   }
02453   
02454   if( filename.IsNull() ) filename = ExpandPathName("$FND_WRK/evd.save.gif");
02455   //  if(filename.IsNull()) filename = "DiegoCammelloDajeCi.jpg";
02456   
02457   fCurImage = TImage::Open(filename);
02458   fInfoCanvas->cd();
02459   fCurImage->Draw();
02460   fInfoCanvas->Modified();
02461   fInfoCanvas->Update();
02462   // --- come back to main canvas
02463   fMainCanvas->cd();
02464 }
02465 
02466 //_________________________
02467 void TFndEvd::ClearInfoCanvas(){
02468   
02469   if(!fInfoCanvas){
02470     Warning("ClearInfoCanvas","InfoCanvas not defined: can not clear it");
02471     return;
02472   }
02473   fInfoCanvas->Clear();
02474 }

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