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

EVD.cxx

Go to the documentation of this file.
00001 #include "EVD.h"
00002 #include "GfxProxy.h"
00003 #include "GfxCfg.h"
00004 #include "ViewState.h"
00005 #include "EVDObject.h"
00006 
00007 #include "TLatex.h"
00008 #include <TBox.h>
00009 #include <TStyle.h>
00010 #include <Midad/Base/PageProxy.h>
00011 #include <Midad/Base/PageDisplay.h>
00012 #include <Midad/Base/DigitText.h>
00013 #include <Midad/Base/ZoomPad.h>
00014 #include <Midad/Base/ColorAxis.h>
00015 #include <Midad/Base/RangeAxis.h>
00016 #include <Midad/Base/Mint.h>
00017 #include <Midad/Base/GfxButton.h>
00018 
00019 #include <Midad/Util/RangeControl.h>
00020 #include <Midad/Util/CompositeRange.h>
00021 #include "DataUtil/GetRunSnarlEvent.h"
00022 #include <MinosObjectMap/MomNavigator.h>
00023 #include <Record/SimSnarlRecord.h>
00024 #include <Record/SimSnarlHeader.h>
00025 #include <RawData/RawDaqSnarlHeader.h>
00026 #include <TParticle.h>
00027 #include <TClonesArray.h>
00028 #include "Conventions/StripEnd.h"
00029 
00030 #include <REROOT_Classes/REROOT_NeuVtx.h>
00031 #include <REROOT_Classes/REROOT_NeuKin.h>
00032 #include <Validity/VldContext.h>
00033 #include <Validity/VldTimeStamp.h>
00034 
00035 #include <Midad/Gui/GuiBox.h>
00036 #include <Midad/Gui/GuiCanvas.h>
00037 #include <Midad/Gui/GuiSlider.h>
00038 #include <Midad/Gui/GuiButton.h>
00039 #include <Midad/Gui/GuiTab.h>
00040 #include <Midad/Gui/GuiMainWindow.h>
00041 #include <Midad/Gui/GuiTextView.h>
00042 #include <Midad/Gui/GuiTree.h>
00043 #include <Midad/Gui/GuiScrolled.h>
00044 #include "TG3DLine.h"
00045 #include "TGTextEntry.h"
00046 #include "TGButton.h"
00047 
00048 #include <RecoBase/CandSliceListHandle.h>
00049 #include <CandDigit/CandDigitHandle.h>
00050 #include <CandDigit/CandDigitListHandle.h>
00051 #include <CandTrackSR/CandTrackSRHandle.h>
00052 #include <CandFitTrackSR/CandFitTrackSRHandle.h>
00053 #include <RecoBase/CandTrackListHandle.h>
00054 #include <RecoBase/CandFitTrackHandle.h>
00055 #include <RecoBase/CandTrackHandle.h>
00056 #include <RecoBase/CandShowerHandle.h>
00057 #include <RecoBase/CandShowerListHandle.h>
00058 #include <RecoBase/CandStripHandle.h>
00059 #include <RecoBase/CandStripListHandle.h>
00060 #include <RecoBase/CandEventListHandle.h>
00061 #include <RecoBase/CandEventHandle.h>
00062 
00063 #include <CalDetPID/CandCalDetPIDHandle.h>
00064 
00065 #include <JobControl/JobC.h>
00066 #include <Conventions/Munits.h>
00067 #include <Midad/Base/SteelOutline.h>
00068 #include <TCanvas.h>
00069 #include "DisplayOptions.h"
00070 #include <DataUtil/TruthHelper.h>
00071 #include <TH1F.h>
00072 
00073 #include <UgliGeometry/UgliGeomHandle.h>
00074 #include <UgliGeometry/UgliStripHandle.h>
00075 #include <DataUtil/GetCandidate.h>
00076 
00077 #include <Plex/PlexSEIdAltL.h>
00078 #include <Plex/PlexSEIdAltLItem.h>
00079 #include <Plex/PlexStripEndId.h>
00080 #include <DataUtil/CDL2STL.h>
00081 #include <sigc++/sigc++.h>
00082 #include <sigc++/class_slot.h>
00083 
00084 ClassImp(EVD)
00085 
00086 using namespace SigC;
00087 using namespace DisplaySetup;
00088 
00089 static PageProxy<EVD> gsEVDProxy("MINOS Event Display");
00090 
00091 EVD::EVD()
00092   : fPageDisplay(0)
00093     , fMint(0)
00094     , fRecoText(0)
00095     , fMCText(0)
00096     , fMCTree(0)
00097     , fDigitText(0)
00098     , fMCtextbox(0)
00099     , fRecotextbox(0) 
00100     , fMCTreetextbox(0) 
00101     , fDigittextbox(0)
00102     , fMCTreescroll(0)
00103     , fTextBox(0)  
00104     , fMCbut(0)
00105     , fRecobut(0)
00106     , fMCTreebut(0)
00107     , fDigitbut(0)
00108     , fZoomHistory(0)
00109     , fCompositeRange(0)
00110     , fSlice(-1)
00111     , fNumSlices(-1)
00112     , fEvent(-1)
00113     , fNumEvents(-1)
00114     , fSnarl(-1)
00115     , fGhostColor(kGhostColor)
00116     , fClear(false)
00117     , fDrawAll(true)
00118     , fDrawGhosts(false)
00119     , fLastButtonType(0)
00120     , fTimeZoom(false)
00121 {
00122     fZoomHistory = manage(new UndoHistory);
00123     fCompositeRange = manage(new CompositeRange<double>);
00124 }
00125 
00126 EVD::~EVD()
00127 {
00128 }
00129 
00130 TObject* EVD::Init(Mint* mint, PageDisplay* pd, GuiBox& box)
00131 {
00132 
00133  
00134 
00135   this->CanvasPage::Init(mint,pd,box);
00136   fMint = mint;
00137   fPageDisplay = pd;
00138 
00139   fChargeRange= new RangeDouble(0.0,1.0);
00140   
00141   /* 
00142      The 3 views displayed are UZ [0], VZ [1], and XY [2].  The ViewState
00143      holds the state variables that determine whether non-demuxed digits are
00144      displayed, whether color represents time or charge, etc.  Refer to
00145      ViewState.h for the complete state list.
00146   */
00147   fViewState[0] = manage(new ViewState);
00148   fViewState[1] = manage(new ViewState);
00149   fViewState[2] = manage(new ViewState); 
00150 
00151   BuildMenus();
00152   BuildButtons();
00153   
00154   /* 
00155      Build ranges.  There are 5 spatial controls, for the one for the z axis 
00156      in the U and V vs Z views, and one each for U, V, X, and Y.  There is
00157      also a time range, which controls the range of times displayed, 
00158      and which is controled by the slider control at the bottom of the window  
00159   */
00160 
00161   RangeDouble*  spatial_range[5];
00162   for (int i=0; i<6; ++i) 
00163     {
00164       spatial_range[i] = manage(new RangeDouble(0,1));
00165       fSpatialControl[i] = new RangeControl<double>(fZoomHistory,
00166                                                     spatial_range[i]);
00167     }
00168   fRClist.push_back(fPageDisplay->GetTimeSlider().GetSignals().released.connect
00169                       (slot_class(*this,&EVD::UpdateTime)));
00170  
00171   TCanvas& canvas = this->GetCanvas();
00172   canvas.SetFillColor(38);
00173 
00174   Int_t colNum=9;
00175   Int_t palette[9]={10,6,9,4,7,8,3,5,2};
00176   gStyle->SetPalette(colNum,palette);
00177   
00178   /* 
00179      Build U/V vs Z views.  We must define a pad for each, and set the 
00180      location of the rangeaxis and color_range controls.  The color ranges
00181      have an associated button, which determines whether color represents
00182      pulse height or time.  The color ranges are active, meaning that the 
00183      display will response to selection of  a range on the color palette.
00184   */
00185   
00186   fPad[0] = new ZoomPad("U View", "U View", kZviewXmin,kUZviewYmin, 
00187                         kZviewXmax,kZviewYmax);
00188   fPad[1] = new ZoomPad("V View", "V View", kZviewXmin,kZviewYmin,
00189                         kZviewXmax,kVZviewYmax);
00190   
00191   fRangeAxis[0] = new RangeAxis(kZviewXRUV,kUZviewYmin, 
00192                                 kZviewXRUV,kZviewYmax);
00193   fRangeAxis[1] = new RangeAxis(kZviewXRUV,kZviewYmin, 
00194                                 kZviewXRUV,kVZviewYmax);
00195   fRangeAxis[2] = new RangeAxis(kZviewXmin,kZviewYRZ,
00196                                 kZviewXmax,kZviewYRZ);
00197   
00198   for (int i = 0; i < 3; ++i) 
00199     {
00200       fRangeAxis[i]->UseRange(spatial_range[i]);
00201       fRangeAxis[i]->SetLabelSize(0.4*fRangeAxis[i]->GetLabelSize());
00202     }
00203   
00204   fRangeAxis[0]->SetTitle("U");
00205   fRangeAxis[1]->SetTitle("V");
00206   fRangeAxis[0]->SetTitleSize(0.02);
00207   fRangeAxis[1]->SetTitleSize(0.02);
00208   fRangeAxis[0]->SetTitleOffset(0.5);
00209   fRangeAxis[1]->SetTitleOffset(0.5);
00210   
00211   RangeDouble* color_range[2];
00212   for (int i = 0; i<2; ++i) 
00213     {
00214       color_range[i] = manage(new RangeDouble(0,1));
00215       fColorControl[i] = new RangeControl<double>(fZoomHistory,
00216                                                   color_range[i]);//leak
00217       
00218       fPad[i]->UseCurRangeX(spatial_range[2]);
00219       
00220       /*
00221         Connects selection event to SelectionZoom method.  Selecting
00222         a region  in either the UZ or VZ views will result in zooming
00223         in on that region.  The zoom all button is used to zoom back
00224         out.
00225       */
00226 
00227       fPad[i]->selection.connect(bind(slot_class(*this,&EVD::SelectionZoom),fPad[i]));
00228     }
00229   
00230   
00231   fPad[0]->UseCurRangeY(spatial_range[0]);
00232   fPad[1]->UseCurRangeY(spatial_range[1]);
00233   
00234   fColorAxis[0] = new ColorAxis(50,0.05, color_range[0], 
00235                                 kZviewColorFrameXmax-0.1,kZviewColorFrameYmin, 
00236                                 kZviewColorFrameXmax-0.1,kZviewColorFrameYmax,
00237                                 505,"+L");
00238   fColorAxis[1] = new ColorAxis(50,0.05, color_range[1], 
00239                                 kZviewColorFrameXmax,kZviewColorFrameYmin, 
00240                                 kZviewColorFrameXmax,kZviewColorFrameYmax,
00241                                 505,"+L");
00242   
00243   fColorButton[0] = manage(new GfxButton("UZ Time",
00244                                          kZviewColorFrameXmax-0.15,
00245                                          kZviewColorFrameYmax+0.01,
00246                                          kZviewColorFrameXmax-0.1,
00247                                          kZviewColorFrameYmax+0.04));
00248   fColorButton[1] = manage(new GfxButton("VZ Time",
00249                                          kZviewColorFrameXmax-0.05,
00250                                          kZviewColorFrameYmax+0.01,
00251                                          kZviewColorFrameXmax,
00252                                          kZviewColorFrameYmax+0.04));
00253   
00254     for(int i = 0; i<2; ++i) 
00255       {
00256       fColorAxis[i]->SetLabelSize(0.25*fColorAxis[i]->GetLabelSize());
00257       fColorButton[i]->SetTextSize(0.5);
00258       fColorAxis[i]->SetScale(Munits::ns);
00259       RangeDouble& sel = fColorAxis[i]->GetSelectionRange();
00260 
00261       /* connect selecton of range on color axis to the RangeControl::Apply
00262          method.  This method determines whether a charge or time sub-range
00263          is being requested, and triggers a screen redraw with the appropriate
00264          subrange.
00265       */
00266       
00267       sel.modified.connect(bind(slot(*(fColorControl[i]),
00268                                      &RangeControl<double>::Apply),&sel));
00269       sel.modified.connect(slot_class(*this,&EVD::UpdateCanvas));
00270 
00271       /*
00272         Clicking on a color button toggles between charge and time color
00273         semantics
00274       */
00275       
00276       fColorButton[i]->clicked.connect(slot(*fViewState[i],
00277                                             &ViewState::ToggleColorSemantic));       }
00278 
00279 
00280     fViewState[0]->color_semantic.connect(bind(slot_class(*this,&EVD::ColorSemanticHandler),0));    
00281     //    fViewState[0]->show_multiplex.connect(slot_class(*this,&EVD::Update));
00282     //     fViewState[0]->spatial_metric.connect(slot_class(*this,&EVD::Update));
00283 
00284     fViewState[1]->color_semantic.connect(bind(slot_class(*this,&EVD::ColorSemanticHandler),1));
00285     fViewState[1]->show_multiplex.connect(slot_class(*this,&EVD::Update));
00286     //    fViewState[1]->spatial_metric.connect(slot_class(*this,&EVD::Update));
00287 
00288 
00289     for (int i=0; i<3; ++i) 
00290       {
00291         RangeDouble& s = fRangeAxis[i]->GetSelectionRange();
00292         s.modified.connect(bind(slot(*(fSpatialControl[i]),
00293                                      &RangeControl<double>::Apply),&s));       
00294         fRClist.push_back(spatial_range[i]->modified.connect(slot_class(*this,&EVD::UpdateCanvas)));
00295       }
00296     
00297 
00298     /* now build XY view, in fashion similar to above */    
00299 
00300     fPad[2] = new ZoomPad("XY View", "XY View", 
00301                           kXYviewXmin,kXYviewYmin,
00302                           kXYviewXmax,kXYviewYmax);
00303     
00304     fRangeAxis[3] = new RangeAxis(kXYviewXR,kXYviewYmin,
00305                                   kXYviewXR,kXYviewYmax);
00306     fRangeAxis[4] = new RangeAxis(kXYviewXmin,kXYviewYR, 
00307                                   kXYviewXmax,kXYviewYR);
00308 
00309     for (int i = 3; i < 5; ++i) 
00310       {
00311         fRangeAxis[i]->UseRange(spatial_range[i]);
00312         fRangeAxis[i]->SetLabelSize(0.3*fRangeAxis[i]->GetLabelSize());
00313         
00314       }
00315 
00316     fRangeAxis[3]->SetTitle("Y");
00317     fRangeAxis[4]->SetTitle("X");
00318     fRangeAxis[3]->SetTitleSize(0.02);
00319     fRangeAxis[4]->SetTitleSize(0.02);
00320     fRangeAxis[3]->SetTitleOffset(0.5);
00321     fRangeAxis[4]->SetTitleOffset(0.5);
00322     
00323     fPad[2]->UseCurRangeX(spatial_range[3]);
00324     fPad[2]->selection.connect(bind(slot_class(*this,&EVD::SelectionZoom),fPad[2]));
00325     fPad[2]->UseCurRangeY(spatial_range[4]);
00326     fViewState[2]->color_semantic.connect(bind(slot_class(*this,&EVD::ColorSemanticHandler),1));
00327  
00328     
00329     for (int i=3; i<5; ++i) 
00330       {
00331         RangeDouble& s = fRangeAxis[i]->GetSelectionRange();
00332         s.modified.connect(bind(slot(*(fSpatialControl[i]),
00333                                      &RangeControl<double>::Apply), &s));
00334         
00335         fRClist.push_back(spatial_range[i]->modified.connect
00336                           (slot_class(*this,&EVD::UpdateCanvas)));
00337       }
00338 
00339     
00340     /* the text pad shows a summary of reconstruction,  and MC if appropriate */
00341     TextPad = new TPad("Summary","Summary",0.42,0.01,0.97,0.24);
00342     TextPad->SetFillColor(17);
00343     
00344     /* draw pads on the canvas, tweaking the drawing options for visual
00345        impact
00346     */
00347 
00348     canvas.cd();
00349     fPad[0]->SetBorderSize(1);
00350     fPad[1]->SetBorderSize(1);
00351     fPad[2]->SetBorderSize(1);
00352 
00353     fPad[0]->SetBorderMode(1);
00354     fPad[1]->SetBorderMode(1);
00355     fPad[2]->SetBorderMode(1);
00356 
00357     fColorButton[0]->SetFillColor(2);
00358     fColorButton[1]->SetFillColor(2);
00359 
00360     fPad[0]->SetFillColor(1);
00361     fPad[1]->SetFillColor(1);
00362     fPad[2]->SetFillColor(1);
00363   
00364     fPad[0]->Draw();
00365     fPad[1]->Draw();
00366     fPad[2]->Draw();
00367     TextPad->Draw();
00368 
00369     //create the user histograms
00370 
00371     fUserHist = new UserHist(fMint);
00372 
00373     // update the reconstruction/MC summary pad.
00374     
00375     TextPad->cd();
00376     UpdateSummary();
00377     
00378     canvas.cd();
00379     InitChargeHists(canvas);
00380     fRangeAxis[0]->Draw();
00381     fRangeAxis[1]->Draw();
00382     fRangeAxis[2]->Draw();
00383     fRangeAxis[3]->Draw();
00384     fRangeAxis[4]->Draw();
00385 
00386     fColorAxis[0]->Draw();
00387     fColorAxis[1]->Draw();
00388     fColorAxis[0]->PaintPalette();
00389     fColorButton[0]->Draw();
00390     fColorButton[1]->Draw();
00391 
00392     /* 
00393        Activate all Gfx objects. By default, the digitlist, tracklist, and
00394        showerlist are displayed. One can select or deselect object 
00395        visibility in the 'Objects' menu
00396     */
00397 
00398     const char* default_gfx[] = {
00399       "DigitList",
00400       "StripList",
00401       "TrackList",
00402       "ShowerList",
00403       "MCVecList",
00404       0
00405     };
00406     
00407     for (int ind=0; default_gfx[ind]; ++ind) this->AddGfx(default_gfx[ind]);
00408     
00409     BuildGfxMenu();
00410     Clear();
00411     Update();
00412 
00413     return new EVDObject(this); // small leak   
00414 }
00415 
00416 static void toggle_mux(GuiMenu* menu,
00417                        GuiMenu::GuiMenuList::iterator mit,
00418                        ViewState* view_state)
00419 
00420   /* called by options menu entry.  Toggles between display modes in which
00421      all digits are shown, and only the best strip end alternative is shown.
00422   */
00423 {
00424     
00425     bool show_mux = view_state->ShowMultiplex();
00426     menu->CheckEntry(mit,show_mux);
00427 }
00428 
00429 
00430 void EVD::BuildMenus(void)
00431 {
00432     GuiMenuBar& mb = fPageDisplay->GetMenuBar();
00433 
00434     mb.RemoveMenu("Zoom");
00435     mb.RemoveMenu("Pages");
00436     
00437     GuiMenu* options_menu = manage(new GuiMenu);
00438     mb.AddMenu(*options_menu,"Options");
00439 
00440     GuiMenu::GuiMenuList::iterator mit;
00441 
00442     // Whether to show multiplexing or not
00443     const char* mux_labels =      "Show AllMultiplex Digits";
00444     mit = options_menu->Add(mux_labels);
00445     for (int ind = 0; ind < 3; ++ind) {
00446         ViewState* vs = fViewState[ind];
00447         options_menu->CheckEntry(mit,vs->ShowMultiplex());
00448        (*mit)->Connect(slot(*vs,&ViewState::ToggleMultiplex));
00449         vs->show_multiplex.connect(bind(bind(bind(slot(toggle_mux),vs),mit),options_menu));
00450     }
00451 
00452     // Real or discrete coords.
00453     mit = options_menu->Add("Use Strip/Plane Coord.s");
00454     (*mit)->Connect(bind(slot_class(*this,&EVD::ToggleRealCoords),options_menu,mit));
00455     fViewState[2]->SetSpatialMetric(ViewState::metric_is_continuous);
00456 
00457   // Zoom to time window in slice or event view.
00458     mit = options_menu->Add("Zoom to Slice/Event Time Window");
00459     (*mit)->Connect(bind(slot_class(*this,&EVD::ToggleTimeZoom),options_menu,mit));
00460     fTimeZoom=false;
00461 
00462     mit = options_menu->Add("Display Settings");
00463     fDisplayOptions = new DisplayOptions(*fPageDisplay, *this);
00464     (*mit)->Connect(bind(slot_class(*fDisplayOptions,&DisplayOptions::OpenDialog),options_menu,mit));
00465 
00466 
00467     options_menu->Add(0);
00468  
00469 }
00470 
00471 
00472 void EVD::BuildGfxMenu()
00473 {
00474 
00475   GuiMenuBar& mb = fPageDisplay->GetMenuBar();
00476 
00477   list<const char*> gfx_names = GfxProxyBase::GetRegisteredNames();
00478   list<const char*>::iterator it, done = gfx_names.end();
00479   
00480   GuiMenu* pm = manage(new GuiMenu);
00481   mb.AddMenu(*pm,"Objects");
00482   
00483   NamedFactory& nf = NamedFactory::Instance("Gfx");
00484   for (it = gfx_names.begin(); it != done; ++it) {
00485     const char* name = *it;
00486     GfxProxyBase* gpb = dynamic_cast<GfxProxyBase*>(nf.GetProxy(name));
00487     if (!gpb) {
00488       cerr << "Failed to get GfxProxy for " << name << endl;
00489       continue;
00490     }
00491     GuiMenu * gfx_menu = gpb->MakeMenu(this);
00492     if (! gfx_menu) continue;
00493     gfx_menu = manage(gfx_menu);
00494     pm->Add(name, *gfx_menu);
00495     
00496   }  
00497 }
00498 
00499 void EVD::BuildButtons()
00500 {
00501 
00502   GuiBox * gb = fPageDisplay->GetButtonBox();
00503  
00504   TGHorizontal3DLine * BigSep = new  TGHorizontal3DLine(gb,1,100); 
00505   TGHorizontal3DLine * Sep = new  TGHorizontal3DLine(gb,1,20);
00506 
00507   // add next/prev slice buttons
00508 
00509   fNextSlicebut = fPageDisplay->AddButton("Next Slice ");
00510   fNextSlicebut->clicked.connect(slot_class(*this,&EVD::NextSlice));
00511 
00512   fNextSlicebut = fPageDisplay->AddButton("Prev Slice ");
00513   fNextSlicebut->clicked.connect(slot_class(*this,&EVD::PrevSlice));
00514 
00515 
00516   // lots of work to add a space at the top of the button box
00517 
00518   TGFrameElement *nw = new TGFrameElement;
00519   nw->fFrame  = BigSep;
00520   TGLayoutHints * hint = new TGLayoutHints(kLHintsTop);  
00521   nw->fLayout = hint;
00522   nw->fState  = 1;
00523   gb->GetList()->AddFirst(nw);
00524 
00525   // this adds a space after the next/prev buttons
00526 
00527   gb->AddFrame(Sep);
00528  // add next/prev event buttons
00529 
00530   fNextEventbut = fPageDisplay->AddButton("Next Event ");
00531   fNextEventbut->clicked.connect(slot_class(*this,&EVD::NextEvent));
00532 
00533   fNextEventbut = fPageDisplay->AddButton("Prev Event ");
00534   fNextEventbut->clicked.connect(slot_class(*this,&EVD::PrevEvent));
00535  gb->AddFrame(Sep);
00536 
00537   // these are the user defined buttons
00538 
00539  
00540   fRecobut = fPageDisplay->AddButton("Reco Data");
00541   fRecobut->clicked.connect(slot_class(*this,&EVD::Recotext));
00542   
00543   fMCbut = fPageDisplay->AddButton("NeuKin");
00544   fMCbut->clicked.connect(slot_class(*this,&EVD::MCtext));
00545   
00546   fMCTreebut = fPageDisplay->AddButton("StdHep Tree");
00547   fMCTreebut->clicked.connect(slot_class(*this,&EVD::MCTreetext));
00548   
00549   fDigitbut = fPageDisplay->AddButton("Digit Data");
00550   fDigitbut->clicked.connect(slot_class(*this,&EVD::Digittext));
00551  
00552   gb->AddFrame(Sep);
00553 
00554   GuiTextButton * zoombut = fPageDisplay->AddButton("Zoom All");
00555   zoombut->clicked.connect(slot_class(*fPageDisplay,&PageDisplay::FullZoom));
00556   
00557   GuiTextButton * zoomredobut = fPageDisplay->AddButton("Zoom Redo");
00558   zoomredobut->clicked.connect(slot_class(*fPageDisplay,&PageDisplay::Rezoom));
00559 
00560   GuiTextButton * zoomundobut=  fPageDisplay->AddButton("Zoom Undo");
00561   zoomundobut->clicked.connect(slot_class(*fPageDisplay,&PageDisplay::Unzoom)); 
00562   gb->AddFrame(Sep); 
00563   GuiTextButton * printbut=  fPageDisplay->AddButton("Print");
00564   printbut->clicked.connect(slot_class(*this,&EVD::PrintCanvas));
00565 }
00566 
00567 void EVD::ToggleRealCoords(GuiMenu* menu, GuiMenu::GuiMenuList::iterator mit)
00568 {
00569   // toggles between real XYZ coords and strip/plane.
00570 
00571     bool is_strip = ! menu->IsEntryChecked(mit);
00572     menu->CheckEntry(mit,is_strip);
00573 
00574     for (int ind = 0; ind < 2; ++ind) {
00575         fViewState[ind]->SetSpatialMetric(is_strip ? 
00576                                           ViewState::metric_is_discreet : 
00577                                           ViewState::metric_is_continuous);
00578     }    
00579     fViewState[2]->SetSpatialMetric( ViewState::metric_is_continuous);
00580 
00581     fPad[0]->Clear();
00582     fPad[1]->Clear();
00583     fPad[2]->Clear();
00584     fClear=true;
00585     this->FullZoom();
00586     this->Update();
00587 
00588 }
00589 
00590 void EVD::ToggleTimeZoom(GuiMenu* menu, GuiMenu::GuiMenuList::iterator mit)
00591 {
00592   // toggles whether you zoom to time window in slice/event view.
00593 
00594     fTimeZoom = ! menu->IsEntryChecked(mit);
00595     menu->CheckEntry(mit,fTimeZoom);
00596     this->Update();
00597 
00598 }
00599 
00600 void EVD::AddGfx(const char* gfx_name)
00601 {
00602 
00603   /* 
00604      Adds a graphics object  to each of the the three views.  Currently,
00605      the XY view does not support the display of CandDigits or CandStrips,
00606      only tracks, showers, and MC vectors.
00607   */
00608 
00609     GfxProxyBase* gpb = dynamic_cast<GfxProxyBase*>
00610         (NamedFactory::Instance("Gfx").GetProxy(gfx_name));
00611     if (!gpb) {
00612         cerr << "Failed to get " << gfx_name << " proxy\n";
00613         return;
00614     }
00615 
00616     GraphicsView::GraphicsView_t view[3];
00617     PlaneView::PlaneView_t pview[3];
00618   
00619     view[0]=GraphicsView::kUZ;
00620     view[1]=GraphicsView::kVZ;
00621     view[2]=GraphicsView::kXY;
00622     pview[0]=PlaneView::kU;
00623     pview[1]=PlaneView::kV;
00624     pview[2]=PlaneView::kV;
00625   
00626     TVirtualPad* old_pad = gPad;
00627     for (int ind = 0; ind < 3; ++ind) 
00628       {
00629         if(view[ind]==GraphicsView::kUZ || view[ind]==GraphicsView::kVZ ||
00630            gfx_name=="DigitList" || 
00631            gfx_name=="TrackList" || 
00632            gfx_name=="ShowerList" || 
00633            gfx_name=="MCVecList" )
00634           {
00635             fPad[ind]->cd();
00636             GfxBase* gfx_base = gpb->Create();
00637             if (!gfx_base) {
00638               cerr << "Failed to create " << gfx_name << endl;
00639               break;
00640             }    
00641             gfx_base->text_info.connect(slot_class(*fPageDisplay,
00642                                                    &PageDisplay::StatusBar));
00643             gfx_base->SetGraphicsView(view[ind]);
00644             gfx_base->SetPlaneView(pview[ind]);
00645             gfx_base->SetViewState(fViewState[ind]);
00646             gfx_base->SetPad(fPad[ind]);
00647             //      gfx_base->GetCfg().modified_signal.connect(slot_class(*this,&EVD::UpdateCanvas));
00648             gfx_base->Init(*fPageDisplay,*this);
00649             
00650             fGfxList[gfx_base] = GfxInfo(view[ind]);
00651           }
00652       }
00653     gPad = old_pad;
00654     this->Update();
00655 }
00656 
00657 void EVD::InitView(GraphicsView::GraphicsView_t view)
00658 {
00659  
00660   Int_t ind=2;
00661   if(view==GraphicsView::kUZ )ind=0;
00662   if(view==GraphicsView::kVZ )ind=1;
00663   if(view==GraphicsView::kUV )ind=2;
00664   if(view==GraphicsView::kXY )ind=2;
00665   fPad[ind]->cd();
00666 
00667   const char* hard_coded_default_gfx[] = {
00668     "DigitList",
00669     "StripList",
00670     "TrackList",
00671     "ShowerList",
00672     "MCVecList",
00673     0
00674   };
00675 
00676   for (int ind=0; hard_coded_default_gfx[ind]; ++ind) 
00677     {
00678       const char* gfx_name = hard_coded_default_gfx[ind];
00679       this->AddGfx(gfx_name);
00680     }
00681 }
00682 
00683 
00684 void EVD::Clear()
00685 {
00686     fZoomHistory->Clear();
00687     BlockRanges(true);
00688     fClear=true;
00689     FullZoom();
00690     BlockRanges(false);
00691 }
00692 
00693 void EVD::FullZoom()
00694 {
00695   if (!fMint) return;
00696   if (fMint->GetDetector() == Detector::kUnknown) return;
00697   BlockRanges(true);
00698   UgliGeomHandle ugh = fMint->GetUgliGeomHandle();
00699   if (! ugh.IsValid()) 
00700     {
00701       cerr << "EVD::FullZoom: no valid geometry\n";
00702       return;
00703     }
00704   
00705   if (fViewState[0]->GetSpatialMetric() == ViewState::metric_is_discreet) 
00706     {
00707       vector<UgliScintPlnHandle> usphv = ugh.GetScintPlnHandleVector();
00708       vector<UgliScintPlnHandle>::reverse_iterator rit, rdone = usphv.rend();
00709       
00710       for (rit = usphv.rbegin(); rit != rdone; ++rit) 
00711         {
00712           if (! rit->GetPlexPlaneId().IsVetoShield()) break;
00713         }
00714       if (rit == rdone)
00715         {
00716           cerr << "EVD::FullZoom: WTF, can't get last plane!\n";
00717           return;
00718         }
00719       
00720       double first_plane,last_plane;
00721       if(GetDisplayOptions()->AutoScaleExtents()){
00722         first_plane = usphv[0].GetPlaneNumber()-10; 
00723         last_plane = rit->GetPlaneNumber()+10;
00724       }
00725       else{
00726         first_plane=GetDisplayOptions()->ZMin()/0.06;
00727         last_plane=GetDisplayOptions()->ZMax()/0.06;  
00728       }
00729       int n_strips = usphv[0].NumberOfStrips();
00730       
00731       fPad[0]->Range(first_plane,-10,last_plane,n_strips+10);
00732       fPad[1]->Range(first_plane,-10,last_plane,n_strips+10);
00733       
00734       float xmin, xmax, ymin,ymax;      
00735       ugh.GetTransverseExtent(PlaneView::kU,xmin,xmax);
00736       ugh.GetTransverseExtent(PlaneView::kV,ymin,ymax);
00737      
00738       if(fMint->GetDetector() == Detector::kFar){      
00739         fPad[2]->Range(xmin-2,ymin-2,xmax+2,ymax+2);
00740       }
00741       else if (fMint->GetDetector() == Detector::kNear){
00742         fPad[2]->Range(xmin-.442,ymin-1.0,xmax+1.5578,ymax+1.0);
00743       }
00744       else{
00745         fPad[2]->Range(xmin-1.0,ymin-1,xmax+1.0,ymax+1);
00746       }
00747     }
00748   else 
00749     {
00750       float umin, umax, zmin, zmax, vmin,vmax;
00751       float xmin, xmax, ymin, ymax;
00752       
00753       
00754       ugh.GetTransverseExtent(PlaneView::kU,umin,umax);
00755       ugh.GetTransverseExtent(PlaneView::kV,vmin,vmax);
00756       if(GetDisplayOptions()->AutoScaleExtents()){
00757         ugh.GetZExtent(zmin,zmax);
00758       }
00759       else{
00760         zmin=GetDisplayOptions()->ZMin();
00761         zmax=GetDisplayOptions()->ZMax();
00762         if((zmax-zmin)<0.25) zmax=zmin+0.25;
00763       }
00764       if(fMint->GetDetector() == Detector::kFar){
00765          zmax+=1;
00766          zmin-=1;
00767          umin-=0.5;
00768          vmin-=0.5;
00769          umax+=0.5;
00770          vmax+=0.5;
00771          xmin=umin;
00772          xmax=umax;
00773          ymin=umin;
00774          ymax=umax;
00775        }
00776        else if (fMint->GetDetector() == Detector::kNear){
00777          zmax+=0.2;
00778          zmin-=0.2;
00779          umin-=0.2;
00780          vmin-=0.2;
00781          umax+=0.2;
00782          vmax+=0.2;
00783          Float_t xoffset=0.5578;
00784          xmin=umin+xoffset;
00785          xmax=umax+xoffset;
00786          ymin=umin;
00787          ymax=umax;
00788        }
00789        else{
00790          zmin-=0.2;
00791          umin-=0.2;
00792          vmin-=0.2;
00793          umax+=0.2;
00794          vmax+=0.2;
00795          xmin=umin;
00796          xmax=umax;
00797          ymin=umin;
00798          ymax=umax;
00799        }   
00800        fPad[0]->Range(zmin,umin,zmax,umax);     
00801        fPad[1]->Range(zmin,vmin,zmax,vmax);
00802        fPad[2]->Range(xmin,ymin,xmax,ymax);
00803 
00804     }
00805   if(!fClear)Update();
00806   BlockRanges(false);
00807 }
00808 
00809 void EVD::BlockRanges(bool tf)
00810 {
00811   for (unsigned int ind = 0; ind < fRClist.size(); ++ind) 
00812     fRClist[ind].block(tf);
00813 }
00814 
00815 void EVD::NextSlice(){
00816   fLastButtonType=1;
00817   if(!fMint)return;
00818   fEvent=-1;
00819   const MomNavigator * mom = fMint->GetJint().GetMom();
00820   if (!mom) {
00821     return;
00822   }
00823   fNumSlices=GetNumSlices();
00824   if(fNumSlices>=0){
00825     fSlice++;
00826     if(fSlice>=fNumSlices){
00827       fMint->Next(); 
00828       fSlice=0;
00829       fCandSlice=ReadCandSlice();
00830       return;
00831     }
00832     fCandSlice=ReadCandSlice();
00833     Update();
00834   }
00835   else{
00836     fMint->Next(); 
00837     return;
00838   }
00839 }
00840 
00841 void EVD::PrevSlice(){
00842   fLastButtonType=1;
00843   if(!fMint)return;
00844   const MomNavigator * mom = fMint->GetJint().GetMom();
00845   if (!mom) {
00846     return ;
00847   }
00848   fEvent=-1;
00849   fNumSlices= GetNumSlices();
00850   if(fNumSlices>=0){
00851     fSlice--;
00852     if(fSlice<0){
00853       fMint->Prev(); 
00854       fSlice=0;
00855       fCandSlice=ReadCandSlice();
00856       return;
00857     }
00858     fCandSlice=ReadCandSlice();
00859     Update();
00860   }
00861   else{
00862     fMint->Prev(); 
00863     return;
00864   }
00865 
00866 }
00867 
00868 void EVD::NextEvent(){
00869   fLastButtonType=2;
00870   if(!fMint)return;
00871   const MomNavigator * mom = fMint->GetJint().GetMom();
00872   if (!mom) {
00873     return;
00874   }
00875   fNumEvents=GetNumEvents();
00876  
00877   if(fNumEvents>0){
00878     fEvent++;
00879     if(fEvent>=fNumEvents){
00880       fMint->Next();
00881       fSlice=0;
00882       fCandEvent=ReadCandEvent();
00883       return;
00884     }
00885     fCandEvent=ReadCandEvent();  
00886     Update();
00887   }
00888   else{
00889     fMint->Next(); 
00890     return;
00891   }
00892 }
00893 
00894 void EVD::PrevEvent(){
00895   fLastButtonType=2;
00896   if(!fMint)return;
00897   const MomNavigator * mom = fMint->GetJint().GetMom();
00898   if (!mom) {
00899     return ;
00900   }
00901   fNumEvents=GetNumEvents();
00902   if(fNumEvents>=0){
00903     fEvent--;
00904     if(fEvent<=0){
00905       fMint->Prev();
00906       fEvent=0;
00907       fCandEvent=ReadCandEvent();
00908       return;
00909     }
00910     fCandEvent=ReadCandEvent();
00911     Update();
00912   }
00913   else{
00914     fMint->Prev(); 
00915     return;
00916   }
00917 }
00918 
00919 Int_t EVD::GetNumSlices(){
00920 
00921   const MomNavigator * mom = fMint->GetJint().GetMom();
00922   if (!mom) {
00923     return -1;
00924   }
00925   CandRecord* crec = dynamic_cast<CandRecord*>
00926     (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00927   if (!crec) {
00928     return -1;
00929   }
00930   CandSliceListHandle * slicelist = dynamic_cast<CandSliceListHandle*>(crec->FindCandHandle("CandSliceListHandle"));
00931 
00932   if(!slicelist)return -1;
00933   return slicelist->GetNDaughters();
00934 }
00935 
00936 Int_t EVD::GetNumEvents(){
00937   const MomNavigator * mom = fMint->GetJint().GetMom();
00938   if (!mom) return -1;
00939   CandRecord* crec = dynamic_cast<CandRecord*>
00940     (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00941   if (!crec) return -1;
00942   CandEventListHandle * eventlist = dynamic_cast<CandEventListHandle*>(crec->FindCandHandle("CandEventListHandle"));
00943   if(!eventlist)return -1;
00944   return eventlist->GetNDaughters();
00945 }
00946 
00947 CandEventHandle *  EVD::ReadCandEvent(){
00948   const MomNavigator * mom = fMint->GetJint().GetMom();
00949   if (!mom) return 0;
00950   CandRecord* crec = dynamic_cast<CandRecord*>
00951     (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00952   if (!crec)  return 0;
00953   CandEventListHandle * eventlist = dynamic_cast<CandEventListHandle*>(crec->FindCandHandle("CandEventListHandle"));
00954   if( !eventlist)return 0;
00955   CandEventHandleItr eventItr(eventlist->GetDaughterIterator());
00956   Int_t nEvent=0;  
00957   while (CandEventHandle *event = eventItr() ) {
00958     if(nEvent==fEvent){
00959       return event;
00960     }
00961     nEvent++;
00962   }
00963   return 0;
00964 }
00965 
00966 CandSliceHandle *  EVD::ReadCandSlice(){
00967   const MomNavigator * mom = fMint->GetJint().GetMom();
00968   if (!mom)  return 0;
00969   CandRecord* crec = dynamic_cast<CandRecord*>
00970     (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00971   if (!crec) return 0;
00972   CandSliceListHandle * slicelist = dynamic_cast<CandSliceListHandle*>(crec->FindCandHandle("CandSliceListHandle"));
00973   if( !slicelist)return 0;
00974   CandSliceHandleItr sliceItr(slicelist->GetDaughterIterator());
00975   Int_t nSlice=0;  
00976   while (CandSliceHandle *slice = sliceItr() ) {
00977     if(nSlice==fSlice)return slice;
00978     nSlice++;
00979   }
00980   return 0;
00981 }
00982 
00983 
00984 void EVD::Update()
00985 {
00986   if (!fMint) return;
00987 
00988   fPad[0]->SetEditable(true);
00989   fPad[0]->Clear();
00990   fPad[1]->SetEditable(true);
00991   fPad[1]->Clear();
00992   fPad[2]->SetEditable(true);
00993   fPad[2]->Clear();
00994   
00995   int run=0, snarl=0, event=0;
00996   DataUtil::GetRunSnarlEvent(&(fMint->GetJobC().Mom), run, snarl, event);
00997   if(fLastButtonType==1){
00998     fCandSlice=ReadCandSlice();
00999     fCandEvent=0;
01000   }
01001   else if (fLastButtonType==2){
01002     fCandEvent=ReadCandEvent();
01003     fCandSlice=0;
01004   }
01005   else{
01006     fCandEvent=0;
01007     fCandSlice=0;
01008   }
01009   fNumSlices=GetNumSlices();
01010   fNumEvents=GetNumEvents();
01011 
01012   // on new snarl, reset slice counter and CandSlice - this will cause 
01013   // full color display of entire snarl.
01014 
01015   if(snarl!=fSnarl){
01016     if(fNumSlices>1){
01017       fSlice=-1;
01018       fCandSlice=0;
01019       fEvent=-1;
01020       fCandEvent=0;     
01021     }
01022     else{
01023       fSlice=0;
01024       fEvent=0;
01025       fCandSlice=ReadCandSlice();
01026       fCandEvent=ReadCandEvent();
01027     }
01028     fSnarl=snarl;
01029     RangeDouble& r = fMint->GetTimeRange();
01030     fUserHist->GetAltTimeHist()->SetTotTimeRange(r); 
01031   }
01032 
01033   // for far detector, suppress display of pre-trigger time interval
01034   if(fTimeZoom  && (fCandSlice || fCandEvent)){
01035     ZoomTimetoSlice();
01036   }
01037   else if(fMint->GetDetector() == Detector::kFar){
01038     if((fMint->GetTimeRange().Max()-fMint->GetTimeRange().Min())*1e9>1500){
01039       fMint->GetTimeRange().Set(fMint->GetTimeRange().Max()-1500e-9,fMint->GetTimeRange().Max());
01040     }
01041   }
01042   
01043   SetChargeRange();
01044   ColorSemanticHandler(0);
01045   ColorSemanticHandler(1);
01046   
01047   UpdateView(GraphicsView::kUZ);
01048   UpdateView(GraphicsView::kVZ);
01049   UpdateView(GraphicsView::kXY);
01050 
01051   fUserHist->Refresh(GetDisplayOptions()->UserHist());
01052 
01053   UpdateSummary();
01054   
01055   if(fRecoText) fRecoText->Update(fMint);
01056   if(fMCText) fMCText->Update(fMint);   
01057   if(fMCTree) fMCTree->Update(fMint); 
01058    
01059   UpdateCanvas(); 
01060 }
01061 
01062 void EVD::ZoomTimetoSlice(){
01063   Double_t minTime= fMint->GetTimeRange().Min();
01064   Double_t maxTime= fMint->GetTimeRange().Max();
01065 
01066   Double_t newminTime=1e9;
01067   Double_t newmaxTime=-1e9;
01068   if(fCandSlice){
01069     TIter stripItr(fCandSlice->GetDaughterIterator());  
01070     while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
01071            (stripItr())) {
01072       if(strip->GetTime()<newminTime) newminTime=strip->GetTime();
01073 
01074       if(strip->GetTime()>newmaxTime) newmaxTime=strip->GetTime();
01075     }
01076     newminTime -=50e-9;
01077     newmaxTime +=20e-9;
01078     
01079     if(newminTime<newmaxTime && (newminTime!=minTime || newmaxTime!=maxTime)){
01080       fMint->GetTimeRange().Set(newminTime,newmaxTime);
01081     }
01082   }
01083   else if(fCandEvent){
01084     TIter stripItr(fCandEvent->GetDaughterIterator());  
01085     while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
01086            (stripItr())) {
01087       if(strip->GetTime()<newminTime) newminTime=strip->GetTime();
01088       if(strip->GetTime()>newmaxTime) newmaxTime=strip->GetTime();
01089     }
01090     newminTime -=50e-9;
01091     newmaxTime +=20e-9;
01092     
01093     if(newminTime<newmaxTime&& (newminTime!=minTime || newmaxTime!=maxTime)){
01094       fMint->GetTimeRange().Set(newminTime,newmaxTime);
01095     }
01096   }  
01097 }
01098 
01099 
01100 void EVD::UpdateTime()
01101 {
01102   if (!fMint) return;
01103   fPad[0]->SetEditable(true);
01104   fPad[1]->SetEditable(true);
01105   fPad[2]->SetEditable(true);
01106 
01107   int run=0, snarl=0, event=0;
01108   DataUtil::GetRunSnarlEvent(&(fMint->GetJobC().Mom), run, snarl, event);
01109   if(snarl!=fSnarl){
01110     return;
01111    }
01112 
01113   if(fViewState[0]->GetColorSemantic()==ViewState::color_is_time){
01114     ColorSemanticHandler(0);
01115   }
01116   if(fViewState[1]->GetColorSemantic()==ViewState::color_is_time){
01117     ColorSemanticHandler(1);
01118   }
01119 
01120   if(fLastButtonType!=2)fCandEvent=0;
01121   
01122   UpdateView(GraphicsView::kUZ);
01123   UpdateView(GraphicsView::kVZ);
01124   UpdateView(GraphicsView::kXY);
01125    
01126   UpdateCanvas(); 
01127 
01128   fCandSlice=ReadCandSlice();
01129   fCandEvent=ReadCandEvent();
01130 }
01131 
01132 void EVD::UpdateCanvas()
01133 {
01134 
01135   /* 
01136      Sets all pads as modified, and redraws the charge histograms and Gfx
01137      objects. Called as a result of hiding or unhiding 
01138      a Gfx object, from UpdateTime when the time window is modified, and 
01139      from Update on a new event. 
01140   */
01141   fClear=false;
01142   fPad[0]->SetEditable(true);
01143   fPad[1]->SetEditable(true);
01144   fPad[2]->SetEditable(true);  
01145 
01146   fPad[0]->Modified();
01147   fPad[1]->Modified();
01148   fPad[2]->Modified();
01149 
01150   chargepad[0]->Modified();
01151   chargepad[1]->Modified();
01152   chargepad[2]->Modified();
01153  
01154   UpdateChargeHists(GraphicsView::kUZ);
01155   UpdateChargeHists(GraphicsView::kVZ);
01156   
01157   UpdateGfxObjects(GraphicsView::kUZ);
01158   UpdateGfxObjects(GraphicsView::kVZ);
01159   UpdateGfxObjects(GraphicsView::kXY);
01160  
01161   GetCanvas().Modified();
01162   GetCanvas().Update();
01163 
01164   fPad[0]->SetEditable(false);
01165   fPad[1]->SetEditable(false);
01166   fPad[2]->SetEditable(false);
01167 
01168 }
01169 
01170 int EVD::ViewIndex(GraphicsView::GraphicsView_t view)
01171 {
01172   if(view==GraphicsView::kUZ)return 0;
01173   if(view==GraphicsView::kVZ)return 1;
01174   if(view==GraphicsView::kUV)return 2;
01175   if(view==GraphicsView::kXY)return 2;
01176   return 2;
01177 }
01178 
01179 void EVD::UpdateGfxObjects(GraphicsView::GraphicsView_t view)
01180 {
01181   Int_t ind=ViewIndex(view);
01182   fPad[ind]->cd(); 
01183   GfxList::iterator it, done = fGfxList.end();
01184   if(fSlice>=0 && fNumSlices>1){
01185     fDrawAll=false;
01186     fDrawGhosts=true;
01187     for (it = fGfxList.begin(); it != done; ++it) {
01188       if (it->second.graphicsview_type == view) {
01189         it->first->Configure(*fMint);
01190         it->first->Draw();
01191       }
01192     }
01193     fDrawGhosts=false;
01194     for (it = fGfxList.begin(); it != done; ++it) {
01195       if (it->second.graphicsview_type == view) {
01196         //      it->first->Configure(*fMint);
01197         it->first->Draw();
01198       }
01199     }
01200   }
01201   else{
01202     fDrawAll=true;
01203     for (it = fGfxList.begin(); it != done; ++it) {
01204       if (it->second.graphicsview_type == view) {
01205         it->first->Configure(*fMint);
01206         it->first->Draw();
01207       }
01208     }
01209   }
01210 }
01211 
01212 void UpdateColorButtonTitle(){
01213 }
01214 
01215 void EVD::UpdateView(GraphicsView::GraphicsView_t view)
01216 {
01217 
01218   Int_t ind=ViewIndex(view);
01219 
01220   fPad[ind]->cd();
01221 
01222   if (!fMint) return;
01223   if(fViewState[ind]->GetColorSemantic()==ViewState::color_is_charge){
01224     if(GetDisplayOptions()->ChargeType()==CalDigitType::kNone){
01225       fColorButton[0]->SetTitle("UZ ADC");      
01226       fColorButton[1]->SetTitle("VZ ADC");
01227     }
01228     if(GetDisplayOptions()->ChargeType()==CalDigitType::kPE){
01229       fColorButton[0]->SetTitle("UZ PE");      
01230       fColorButton[1]->SetTitle("VZ PE");
01231     }
01232     if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigLin){
01233       fColorButton[0]->SetTitle("UZ SigLin");      
01234       fColorButton[1]->SetTitle("VZ SigLin");
01235     }
01236     else if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigCorr){
01237       fColorButton[0]->SetTitle("UZ SigCor");      
01238       fColorButton[1]->SetTitle("VZ SigCor");
01239     }
01240   } 
01241  
01242   if (fMint->GetDetector() == Detector::kUnknown) return;
01243   UgliGeomHandle ugh = fMint->GetUgliGeomHandle();
01244   if (! ugh.IsValid()) {
01245     cerr << "EVD::UpdateView: no valid geometry\n";
01246     return;
01247   }
01248     
01249   if (fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_discreet) 
01250     {
01251       vector<UgliScintPlnHandle> usphv = ugh.GetScintPlnHandleVector();
01252       vector<UgliScintPlnHandle>::reverse_iterator rit, rdone = usphv.rend();
01253       
01254       for (rit = usphv.rbegin(); rit != rdone; ++rit) {
01255 
01256         if (! rit->GetPlexPlaneId().IsVetoShield()) break;
01257       }
01258       if (rit == rdone) 
01259         {
01260           cerr << "EVD::FullZoom: WTF, can't get last plane!\n";
01261           return;
01262         }
01263       
01264       int first_plane = usphv[0].GetPlaneNumber();
01265       int last_plane = rit->GetPlaneNumber();
01266       int mid_plane=248;
01267       if(fMint->GetDetector() == Detector::kNear)mid_plane=121;
01268       else if(fMint->GetDetector() == Detector::kCalDet)mid_plane=0;
01269 
01270       
01271       if(view==GraphicsView::kUZ || view==GraphicsView::kVZ)
01272         {
01273           int n_strips = usphv[0].NumberOfStrips();
01274           
01275           Double_t xDet[7]={first_plane,last_plane,last_plane,
01276                             first_plane,first_plane,mid_plane,mid_plane};
01277           Double_t yDet[7]={0,0,n_strips,n_strips,0,0,n_strips};
01278           
01279           Det[ind] = new TPolyLine(7,xDet,yDet);        
01280           Det[ind]->SetLineColor(10);
01281           Det[ind]->SetLineWidth(2);
01282           Det[ind]->SetFillStyle(0);
01283           Det[ind]->Draw(); 
01284         }
01285     }
01286   else 
01287     {
01288       float tmin, tmax, zmin, zmax;
01289       ugh.GetZExtent(zmin,zmax);
01290       
01291       if(ind==0){
01292         ugh.GetTransverseExtent(PlaneView::kU,tmin,tmax);
01293       }
01294       else{
01295         ugh.GetTransverseExtent(PlaneView::kV,tmin,tmax);
01296       }
01297       
01298       
01299       if(view==GraphicsView::kUZ || view==GraphicsView::kVZ){     
01300         if(fMint->GetDetector() == Detector::kFar)
01301           {
01302             
01303             Float_t spacing=5.94*Munits::cm;
01304             Float_t SM1zEnd=spacing*248;
01305             Float_t SM2zStart=SM1zEnd+125.*Munits::cm;
01306             
01307             Double_t xSM1[5]={zmin,SM1zEnd,SM1zEnd,zmin,zmin};
01308             Double_t ySM1[5]={tmin,tmin,tmax,tmax,tmin};
01309             
01310             SM1[ind] = new TPolyLine(5,xSM1,ySM1);
01311             SM1[ind]->SetLineColor(10);
01312             SM1[ind]->SetLineWidth(2);
01313             SM1[ind]->SetFillStyle(0);
01314             SM1[ind]->Draw();
01315             
01316             Double_t xSM2[5]={SM2zStart,zmax,zmax,SM2zStart,SM2zStart};
01317             Double_t ySM2[5]={tmin,tmin,tmax,tmax,tmin};
01318             
01319             SM2[ind] = new TPolyLine(5,xSM2,ySM2);      
01320             
01321             SM2[ind]->SetLineColor(10);
01322             SM2[ind]->SetLineWidth(2);
01323             SM2[ind]->SetFillStyle(0);
01324             SM2[ind]->Draw();
01325           }
01326         else
01327           {
01328             Double_t xDet[5]={zmin,zmax,zmax,zmin,zmin};
01329             Double_t yDet[5]={tmin,tmin,tmax,tmax,tmin};
01330             
01331             Det[ind] = new TPolyLine(5,xDet,yDet);
01332             Det[ind]->SetLineColor(10);
01333             Det[ind]->SetLineWidth(2);
01334             Det[ind]->SetFillStyle(0);
01335             Det[ind]->Draw();
01336           }
01337       }
01338       else{
01339         Outline = new SteelOutline((fMint->GetDetector()));
01340         Outline->Draw();
01341         
01342         if(fMint->GetDetector()==Detector::kFar  && GetDisplayOptions()->DrawVS())DrawVS();
01343       }
01344     }
01345 }
01346     
01347 
01348 void EVD::SelectionZoom(ZoomPad* zp)
01349 {
01350   fCompositeRange->push_back(fPad[0]->GetCurRange().x);
01351   fCompositeRange->push_back(fPad[0]->GetCurRange().y);
01352   fCompositeRange->push_back(fPad[1]->GetCurRange().x);
01353   fCompositeRange->push_back(fPad[1]->GetCurRange().y);
01354   fZoomHistory->Store(*fCompositeRange);
01355 
01356   BlockRanges(true);
01357   zp->ApplySelectionToZoom();
01358   UpdateCanvas();
01359   BlockRanges(false);
01360 }
01361 
01362 void EVD::Unzoom()
01363 {
01364   BlockRanges(true);
01365   fZoomHistory->Undo();
01366   this->UpdateCanvas();
01367   BlockRanges(false);
01368 }
01369 void EVD::Rezoom()
01370 {
01371   BlockRanges(true);
01372   fZoomHistory->Redo();
01373   this->UpdateCanvas();
01374   BlockRanges(false);
01375 
01376 }
01377 RangeControl<double> EVD::GetColorRangeControl(PlaneView::PlaneView_t view)
01378 {
01379   int iview = 0;
01380   if (view == PlaneView::kV) iview = 1;
01381   return *fColorControl[iview];
01382 }
01383 void EVD::ColorSemanticHandler(int which)
01384 {
01385 
01386   if (which < 0 || which > 2) return;
01387   
01388   GfxButton* but = fColorButton[which];
01389   
01390   RangeDouble& cr = fColorAxis[which]->GetRange();
01391   
01392   switch (fViewState[which]->GetColorSemantic()) {
01393   case ViewState::color_is_charge:
01394     if(GetDisplayOptions()->ChargeType()==CalDigitType::kNone){
01395       if(which==0){
01396         but->SetTitle("UZ ADC"); 
01397       }
01398       else{     
01399         but->SetTitle("VZ ADC");
01400       }
01401     }
01402     if(GetDisplayOptions()->ChargeType()==CalDigitType::kPE){
01403       if(which==0){
01404         but->SetTitle("UZ PE"); 
01405       }
01406       else{     
01407         but->SetTitle("VZ PE");
01408       }
01409     }
01410     if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigLin){
01411       if(which==0){
01412         but->SetTitle("UZ SigLin"); 
01413       }
01414       else{     
01415         but->SetTitle("VZ SigLin");
01416       }
01417     }
01418     else if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigCorr){
01419       if(which==0){
01420         but->SetTitle("UZ SigCor"); 
01421       }
01422       else{     
01423         but->SetTitle("VZ SigCor");
01424       }
01425     }
01426 
01427     fColorAxis[which]->SetScale(1.0);
01428     if(!GetDisplayOptions()->AutoScaleCharge()){
01429       BlockRanges(true);
01430       cr.SetMax(GetDisplayOptions()->ChargeMax());
01431       cr.SetMin(GetDisplayOptions()->ChargeMin());
01432       BlockRanges(false);
01433       }
01434       else{
01435         if(fChargeRange)cr.SetFrom(*fChargeRange);
01436       } 
01437     break;
01438   case ViewState::color_is_time:
01439     but->SetTitle("time");
01440     fColorAxis[which]->SetScale(Munits::ns);
01441     cr.SetFrom(fMint->GetTimeRange());   
01442     break;
01443   default:
01444     break;
01445   }
01446   fPad[which]->Modified();
01447   this->GetCanvas().Modified();
01448   but->Modified();
01449 }
01450 
01451 ViewState* EVD::GetViewState(PlaneView::PlaneView_t view)
01452 {
01453   int iview = 0;
01454   if (view == PlaneView::kV) iview = 1;
01455   return fViewState[iview];
01456 }
01457 
01458 void EVD::redo() {
01459   this->UpdateCanvas();
01460 }
01461 
01462 
01463 void EVD::InitChargeHists(TCanvas& canvas)
01464 {
01465 
01466   /* build histograms display PE vs position along sides of views.
01467      all PEs are placed in the ChargeHists, while only charge associated
01468      with reconstructed showers and tracks will be place in the
01469      RecoChargeHists. Charge vs Z or plane is held in chargehist[0], vs U
01470      is in [1], and vs V is in [2]
01471   */
01472 
01473   chargepad[0] = new TPad( "Charge v Z", "Charge v Z", 
01474                            kZviewXmin,kZviewYmax, 
01475                            kZviewXmax,kZviewYmax+0.04); 
01476   chargepad[0]->SetFillColor(23);  
01477 
01478   chargepad[2] = new TPad( "Charge v strip", "Charge v strip", 
01479                            kZviewXmax,kZviewYmin,
01480                            kZviewXmax+0.04,kVZviewYmax);
01481   chargepad[2]->SetFillColor(23);  
01482 
01483   chargepad[1] = new TPad( "Charge u strip", "Charge u strip", 
01484                            kZviewXmax,kUZviewYmin,
01485                            kZviewXmax+0.04,kZviewYmax);
01486   chargepad[1]->SetFillColor(23);  
01487 
01488   fChargeHist[0]= new TH1F("chargevZ","",100,0.,1.); 
01489   fChargeHist[1]= new TH1F("chargevU","",100,0.,1.); 
01490   fChargeHist[2]= new TH1F("chargevV","",100,0.,1.);
01491   
01492   fRecoChargeHist[0] = new THStack("RecochargevZ","RecochargevZ");
01493   fRecoChargeHist[1] = new THStack("RecochargevU","RecochargevU");
01494   fRecoChargeHist[2] = new THStack("RecochargevV","RecochargevV");
01495 
01496   fShwRecoChargeHist[0]= new TH1F("ShwRecochargevZ","",100,0.,1.); 
01497   fShwRecoChargeHist[1]= new TH1F("ShwRecochargevU","",100,0.,1.); 
01498   fShwRecoChargeHist[2]= new TH1F("ShwRecochargevV","",100,0.,1.);
01499 
01500   fTrkRecoChargeHist[0]= new TH1F("TrkRecochargevZ","",100,0.,1.); 
01501   fTrkRecoChargeHist[1]= new TH1F("TrkRecochargevU","",100,0.,1.); 
01502   fTrkRecoChargeHist[2]= new TH1F("TrkRecochargevV","",100,0.,1.);
01503 
01504   int i;
01505   for(i=0;i<3;i++)
01506     {  
01507       chargepad[i]->SetGridx(0);
01508       chargepad[i]->SetGridy(0);
01509       chargepad[i]->SetLeftMargin(0);
01510       chargepad[i]->SetRightMargin(0);
01511       chargepad[i]->SetTopMargin(0);
01512       chargepad[i]->SetBottomMargin(0);
01513       chargepad[i]->SetBorderSize(0);
01514       chargepad[i]->SetBorderMode(1);
01515       chargepad[i]->SetTicks(0,0);
01516       chargepad[i]->SetFillStyle(1001);
01517       chargepad[i]->SetLineWidth(1);
01518       chargepad[i]->SetFrameFillColor(0);
01519       canvas.cd();
01520       chargepad[i]->Draw();  
01521       chargepad[i]->cd();
01522       fChargeHist[i]->SetTickLength(0,"Y"); 
01523       fChargeHist[i]->SetStats(kFALSE);   
01524       fChargeHist[i]->SetLineColor(1);
01525       fChargeHist[i]->SetLineWidth(1);
01526      
01527       fShwRecoChargeHist[i]->SetTickLength(0,"Y");
01528       fShwRecoChargeHist[i]->SetStats(kFALSE);      
01529       fShwRecoChargeHist[i]->SetFillColor(2);
01530       fShwRecoChargeHist[i]->SetLineColor(1);
01531       fShwRecoChargeHist[i]->SetLineWidth(1);
01532       fTrkRecoChargeHist[i]->SetTickLength(0,"Y");
01533       fTrkRecoChargeHist[i]->SetStats(kFALSE);      
01534       fTrkRecoChargeHist[i]->SetFillColor(9);
01535       fTrkRecoChargeHist[i]->SetLineColor(1);
01536       fTrkRecoChargeHist[i]->SetLineWidth(1);
01537       fRecoChargeHist[i]->Add(fTrkRecoChargeHist[i]);
01538       fRecoChargeHist[i]->Add(fShwRecoChargeHist[i]);
01539 
01540       if(i==0) 
01541         {
01542           fChargeHist[i]->Draw("bar hist");
01543           fRecoChargeHist[i]->Draw("bar hist same");
01544 
01545         }
01546       else
01547         {
01548           fChargeHist[i]->Draw("hbar hist");
01549           fRecoChargeHist[i]->Draw("hbar hist same");
01550         }
01551 
01552  }
01553   canvas.cd();
01554 }
01555 
01556 
01557 void EVD::UpdateChargeHists(GraphicsView::GraphicsView_t view)  
01558 {
01559   /* Fill histograms displaying PE vs position along sides of views.
01560      all PEs are placed in the ChargeHists, while only charge associated
01561      with reconstructed showers and tracks will be place in the
01562      RecoChargeHists. Charge vs Z or plane is held in chargehist[0], vs U
01563      is in [1], and vs V is in [2]
01564   */
01565   
01566  // set index based on graphics view
01567 
01568   Int_t ind=2;
01569   if(view==GraphicsView::kUZ)ind=0;
01570   if(view==GraphicsView::kVZ)ind=1;
01571   if(view==GraphicsView::kUV)ind=2;
01572   if(view==GraphicsView::kXY)ind=2;
01573   fPad[ind]->cd();    
01574   if (!fMint)return;
01575 
01576   // set bins in charge histograms based on view scales
01577 
01578   Detector::Detector_t det = fMint->GetDetector();
01579   float zmin = fRangeAxis[2]->GetRange().Min();
01580   float zmax = fRangeAxis[2]->GetRange().Max();
01581   float umin = fRangeAxis[0]->GetRange().Min();
01582   float umax = fRangeAxis[0]->GetRange().Max();
01583   float vmin = fRangeAxis[1]->GetRange().Min();
01584   float vmax = fRangeAxis[1]->GetRange().Max();
01585   int nbinsz = (int)(zmax-zmin+1);
01586   int nbinsu = (int)(umax-umin+1);
01587   int nbinsv = (int)(vmax-vmin+1);
01588   
01589   if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous)
01590     {
01591       nbinsz=(int)((zmax-zmin)/0.06);
01592       nbinsu=(int)((umax-umin)/0.06);
01593       nbinsv=(int)((vmax-vmin)/0.06);
01594     }
01595   
01596   if(view==GraphicsView::kUZ)
01597     {
01598       fChargeHist[0]->Reset("ICE");
01599       fChargeHist[1]->Reset("ICE");
01600       fShwRecoChargeHist[0]->Reset("ICE");
01601       fShwRecoChargeHist[1]->Reset("ICE");
01602       fTrkRecoChargeHist[0]->Reset("ICE");
01603       fTrkRecoChargeHist[1]->Reset("ICE");
01604 
01605       fChargeHist[0]->SetBins(nbinsz,zmin,zmax);
01606       fChargeHist[1]->SetBins(nbinsu,umin,umax);
01607       fShwRecoChargeHist[0]->SetBins(nbinsz,zmin,zmax);
01608       fShwRecoChargeHist[1]->SetBins(nbinsu,umin,umax);
01609       fTrkRecoChargeHist[0]->SetBins(nbinsz,zmin,zmax);
01610       fTrkRecoChargeHist[1]->SetBins(nbinsu,umin,umax);
01611 
01612     }
01613   else if(view==GraphicsView::kVZ)
01614     {
01615       fChargeHist[2]->Reset("ICE");
01616       fChargeHist[2]->SetBins(nbinsv,vmin,vmax);        
01617       fShwRecoChargeHist[2]->Reset("ICE");
01618       fShwRecoChargeHist[2]->SetBins(nbinsv,vmin,vmax); 
01619       fTrkRecoChargeHist[2]->Reset("ICE");
01620       fTrkRecoChargeHist[2]->SetBins(nbinsv,vmin,vmax); 
01621     }
01622 
01623 
01624   CandRecord* candrec = dynamic_cast<CandRecord*>
01625     (fMint->GetJobC().Mom.GetFragment("CandRecord", "PrimaryCandidateRecord"));    if (!candrec) return ;
01626   
01627   if(fCandSlice){
01628     TIter stripItr(fCandSlice->GetDaughterIterator());  
01629     while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
01630            (stripItr())) {
01631       PlaneView::PlaneView_t pv = strip->GetPlaneView();
01632       double q = strip->GetCharge(CalDigitType::kPE);
01633       if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous){
01634         if (view==GraphicsView::kUZ && 
01635             (pv == PlaneView::kU || 
01636              (det == Detector::kCalib && pv == PlaneView::kX))) 
01637           {
01638             fChargeHist[0]->Fill( strip->GetZPos(),q);
01639             fChargeHist[1]->Fill( strip->GetTPos(),q);
01640           }
01641         else if (view==GraphicsView::kVZ && 
01642                  (pv == PlaneView::kV || 
01643                   (det == Detector::kCalib && pv ==PlaneView::kY)))
01644           {
01645             fChargeHist[0]->Fill( strip->GetZPos(),q);
01646             fChargeHist[2]->Fill( strip->GetTPos(),q);
01647           } 
01648       }
01649       else{
01650         if (view==GraphicsView::kUZ && 
01651             (pv == PlaneView::kU || 
01652              (det == Detector::kCalib && pv == PlaneView::kX))) 
01653           {
01654             fChargeHist[0]->Fill( strip->GetPlane(),q);
01655             fChargeHist[1]->Fill( strip->GetStrip(),q);
01656           }
01657         else if (view==GraphicsView::kVZ && 
01658                  (pv == PlaneView::kV || 
01659                   (det == Detector::kCalib && pv ==PlaneView::kY)))
01660           {
01661             fChargeHist[0]->Fill( strip->GetPlane(),q);
01662             fChargeHist[2]->Fill( strip->GetStrip(),q);
01663           } 
01664       }
01665     }
01666   }
01667   else if( fCandEvent){
01668     TIter stripItr(fCandEvent->GetDaughterIterator());
01669    while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
01670            (stripItr())) {
01671       PlaneView::PlaneView_t pv = strip->GetPlaneView();
01672       double q = strip->GetCharge(CalDigitType::kPE);
01673       if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous){
01674         if (view==GraphicsView::kUZ && 
01675             (pv == PlaneView::kU || 
01676              (det == Detector::kCalib && pv == PlaneView::kX))) 
01677           {
01678             fChargeHist[0]->Fill( strip->GetZPos(),q);
01679             fChargeHist[1]->Fill( strip->GetTPos(),q);
01680           }
01681         else if (view==GraphicsView::kVZ && 
01682                  (pv == PlaneView::kV || 
01683                   (det == Detector::kCalib && pv ==PlaneView::kY)))
01684           {
01685             fChargeHist[0]->Fill( strip->GetZPos(),q);
01686             fChargeHist[2]->Fill( strip->GetTPos(),q);
01687           } 
01688       }
01689       else{
01690         if (view==GraphicsView::kUZ && 
01691             (pv == PlaneView::kU || 
01692              (det == Detector::kCalib && pv == PlaneView::kX))) 
01693           {
01694             fChargeHist[0]->Fill( strip->GetPlane(),q);
01695             fChargeHist[1]->Fill( strip->GetStrip(),q);
01696           }
01697         else if (view==GraphicsView::kVZ && 
01698                  (pv == PlaneView::kV || 
01699                   (det == Detector::kCalib && pv ==PlaneView::kY)))
01700           {
01701             fChargeHist[0]->Fill( strip->GetPlane(),q);
01702             fChargeHist[2]->Fill( strip->GetStrip(),q);
01703           } 
01704       }
01705     }  
01706   }    
01707   else{
01708     const CandDigitListHandle* cslh = fMint->GetDigits();
01709     if (!cslh) return;
01710     vector<const CandDigitHandle*> dv = 
01711       DataUtil::CDL2STLvector<CandDigitHandle>(*cslh);
01712     int siz = dv.size();
01713     //  if (! siz) return; 
01714     for (int ncd = 0; ncd < siz; ++ncd) {
01715       const CandDigitHandle* cdh = dv[ncd];
01716       const PlexSEIdAltL& altl = cdh->GetPlexSEIdAltL();
01717       double q = altl.GetBestItem().GetPE(); 
01718       PlaneView::PlaneView_t pv = altl.GetPlaneView();
01719       
01720       if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous)
01721         {
01722           UgliGeomHandle ugh(*cdh->GetVldContext());
01723           UgliStripHandle ush;
01724           if(altl.GetSize()>0){
01725             ush = ugh.GetStripHandle(altl.GetBestItem().GetSEId());
01726             if (ush.IsValid()){
01727               if (view==GraphicsView::kUZ && 
01728                   (pv == PlaneView::kU || 
01729                    (det == Detector::kCalib && pv == PlaneView::kX))) 
01730                 {
01731                   
01732                   fChargeHist[0]->Fill( ush.GlobalPos(0).Z(),q);
01733                   fChargeHist[1]->Fill( ush.GetTPos(),q);
01734                 }
01735               else if (view==GraphicsView::kVZ && 
01736                        (pv == PlaneView::kV || 
01737                         (det == Detector::kCalib && pv ==PlaneView::kY)))
01738                 {
01739                   
01740                   fChargeHist[0]->Fill( ush.GlobalPos(0).Z(),q);
01741                   fChargeHist[2]->Fill( ush.GetTPos(),q);
01742                 } 
01743             }
01744           }
01745         }
01746       else
01747         {
01748           if(altl.GetSize()>0){
01749             PlexStripEndId seid;
01750             seid = altl.GetBestItem().GetSEId();
01751             if (view==GraphicsView::kUZ && 
01752                 (pv == PlaneView::kU || 
01753                  (det == Detector::kCalib && pv ==PlaneView::kX))) 
01754               {
01755                 fChargeHist[0]->Fill( seid.GetPlane(),q);
01756                 fChargeHist[1]->Fill( seid.GetStrip(),q);
01757               }
01758             else if (view==GraphicsView::kVZ && 
01759                      (pv == PlaneView::kV || 
01760                       (det == Detector::kCalib && pv ==PlaneView::kY)))
01761               {
01762                 
01763                 fChargeHist[0]->Fill( seid.GetPlane(),q);
01764                 fChargeHist[2]->Fill( seid.GetStrip(),q);
01765               }
01766           }
01767         }    
01768     }
01769   }
01770 
01771   // loop over candtracks, filling histograms with strip PEs
01772 
01773     const CandTrackListHandle* tracklisthandle=fMint->GetTracks(); 
01774   //  const CandTrackListHandle* tracklisthandle = dynamic_cast<CandTrackListHandle*>(candrec->FindCandHandle("CandTrackCamListHandle","CandTrackSRList"));
01775   if (tracklisthandle) 
01776     {
01777       TIter trackItr(tracklisthandle->GetDaughterIterator());
01778       while (CandTrackHandle *track = dynamic_cast<CandTrackHandle*>
01779              (trackItr())) 
01780         {
01781         
01782           CandTrackHandle * usetrack =track;
01783           Bool_t usethis=false;
01784           if(!fCandSlice && !fCandEvent){
01785             usethis=true;
01786           }
01787           else if(fCandSlice){
01788             CandSliceHandle slc1 =  *(track->GetCandSlice());
01789             CandSliceHandle slc2= *(fCandSlice);
01790             if(slc1==slc2 || slc1.IsCloneOf(slc2))usethis=true;
01791           }
01792           else if (fCandEvent){
01793             for( Int_t itrack=0;itrack<=fCandEvent->GetLastTrack();itrack++){
01794               const CandFitTrackHandle * evtrack = dynamic_cast<const CandFitTrackHandle*>(fCandEvent->GetTrack(itrack));
01795               CandTrackHandle * findtrack=evtrack->GetFinderTrack();
01796               if(findtrack){
01797                 if (*findtrack==*track){
01798                   usethis=true;
01799                   break;
01800                 }
01801               }
01802               if(track->InheritsFrom("CandFitTrackHandle") && dynamic_cast<CandFitTrackHandle*>(track)->GetFinderTrack()){
01803                 if(*evtrack == *(dynamic_cast<CandFitTrackHandle*>(track)->GetFinderTrack())){
01804                   usetrack = dynamic_cast<CandFitTrackHandle*>(track)->GetFinderTrack();           
01805                   usethis=true;
01806                   break;
01807                 }
01808               }
01809             }
01810           }
01811           if(usethis){ 
01812             TIter titr(usetrack->GetDaughterIterator());
01813             while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) 
01814               {
01815                 double q = csh->GetCharge(CalDigitType::kPE); 
01816                 PlaneView::PlaneView_t pv = csh->GetPlaneView();    
01817                 if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous)
01818                   {
01819                     
01820                     if (view==GraphicsView::kUZ && 
01821                         (pv == PlaneView::kU || 
01822                          (det == Detector::kCalib && pv == PlaneView::kX))) 
01823                       { 
01824                         fTrkRecoChargeHist[0]->Fill( csh->GetZPos(),q);
01825                         fTrkRecoChargeHist[1]->Fill( csh->GetTPos(),q);
01826                       }
01827                     else if (view==GraphicsView::kVZ && 
01828                              (pv == PlaneView::kV || 
01829                               (det == Detector::kCalib && pv ==PlaneView::kY)))
01830                       {               
01831                         fTrkRecoChargeHist[0]->Fill( csh->GetZPos(),q);
01832                         fTrkRecoChargeHist[2]->Fill( csh->GetTPos(),q);
01833                       } 
01834                   }
01835                 else
01836                   {
01837                     if (view==GraphicsView::kUZ && 
01838                         (pv == PlaneView::kU || 
01839                          (det == Detector::kCalib && pv ==PlaneView::kX))) 
01840                       {
01841                         fTrkRecoChargeHist[0]->Fill( csh->GetPlane(),q);
01842                         fTrkRecoChargeHist[1]->Fill( csh->GetStrip(),q);
01843                       }
01844                     else if (view==GraphicsView::kVZ && 
01845                              (pv == PlaneView::kV || 
01846                               (det == Detector::kCalib && pv ==PlaneView::kY)))
01847                       {
01848                         fTrkRecoChargeHist[0]->Fill( csh->GetPlane(),q);
01849                         fTrkRecoChargeHist[2]->Fill( csh->GetStrip(),q);
01850                       }
01851                   }        
01852               }
01853           }
01854         }
01855     }
01856 
01857   // loop over candshowers, filling histograms with strip PEs
01858   
01859 
01860   const CandShowerListHandle* showerlisthandle = fMint->GetShowers();
01861   if (showerlisthandle) 
01862     {
01863       TIter showerItr(showerlisthandle->GetDaughterIterator());
01864       while (CandShowerHandle *shower = dynamic_cast<CandShowerHandle*>
01865              (showerItr())) 
01866         {
01867           Bool_t usethis=false;
01868           if(!fCandSlice && !fCandEvent){
01869             usethis=true;
01870           }
01871           else if(fCandSlice){     
01872             CandSliceHandle slc1 =  *(shower->GetCandSlice());
01873             CandSliceHandle slc2 = *(fCandSlice);
01874             //      cout << fCandSlice << " " << shower->GetCandSlice() << " " << fCandSlice->GetUidInt() << " " << shower->GetCandSlice()->GetUidInt() << endl;
01875             if(slc1==slc2 || slc1.IsCloneOf(slc2))usethis=true;
01876           }
01877           else if (fCandEvent){
01878             for( Int_t ishower=0;ishower<=fCandEvent->GetLastShower();ishower++){
01879               const CandShowerHandle *evshower = dynamic_cast<const CandShowerHandle *>(fCandEvent->GetShower(ishower));
01880               if (*evshower==*shower){
01881                 usethis=true;
01882                 break;
01883               }
01884             }
01885           }
01886           if(usethis){
01887             TIter titr(shower->GetDaughterIterator());
01888             while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) 
01889               {
01890                 double q = csh->GetCharge(CalDigitType::kPE);
01891                 PlaneView::PlaneView_t pv = csh->GetPlaneView();    
01892                 if(fViewState[ind]->GetSpatialMetric() == ViewState::metric_is_continuous)
01893                   {
01894                     
01895                     if (view==GraphicsView::kUZ && 
01896                         (pv == PlaneView::kU || 
01897                          (det == Detector::kCalib && pv == PlaneView::kX))) 
01898                       {
01899                         fShwRecoChargeHist[0]->Fill( csh->GetZPos(),q);
01900                         fShwRecoChargeHist[1]->Fill( csh->GetTPos(),q);
01901                       }
01902                     else if (view==GraphicsView::kVZ && 
01903                              (pv == PlaneView::kV || 
01904                               (det == Detector::kCalib && pv ==PlaneView::kY)))
01905                       {
01906                         fShwRecoChargeHist[0]->Fill( csh->GetZPos(),q);
01907                         fShwRecoChargeHist[2]->Fill( csh->GetTPos(),q);
01908                       } 
01909                   }
01910                 else
01911                   {
01912                     if (view==GraphicsView::kUZ && 
01913                         (pv == PlaneView::kU || 
01914                          (det == Detector::kCalib && pv ==PlaneView::kX))) 
01915                       { 
01916                         fShwRecoChargeHist[0]->Fill( csh->GetPlane(),q);
01917                         fShwRecoChargeHist[1]->Fill( csh->GetStrip(),q);
01918                       }
01919                     else if (view==GraphicsView::kVZ && 
01920                              (pv == PlaneView::kV || 
01921                               (det == Detector::kCalib && pv ==PlaneView::kY)))
01922                       {
01923                         fShwRecoChargeHist[0]->Fill( csh->GetPlane(),q);
01924                         fShwRecoChargeHist[2]->Fill( csh->GetStrip(),q);
01925                       }
01926                   }        
01927               } 
01928           }
01929         }
01930     }
01931   // redraw histograms 
01932   if(view==GraphicsView::kUZ)
01933     {      
01934       chargepad[1]->cd();
01935       fChargeHist[1]->Draw("hbar hist");
01936       fRecoChargeHist[1]->RecursiveRemove(fTrkRecoChargeHist[1]);
01937       fRecoChargeHist[1]->RecursiveRemove(fShwRecoChargeHist[1]); 
01938       fRecoChargeHist[1]->Add(fTrkRecoChargeHist[1]);
01939       fRecoChargeHist[1]->Add(fShwRecoChargeHist[1]); 
01940       fRecoChargeHist[1]->Draw("hbar hist same");  
01941  
01942      }
01943   else if(view==GraphicsView::kVZ)
01944     {
01945       chargepad[0]->cd();
01946       fChargeHist[0]->Draw("bar hist");
01947       fRecoChargeHist[0]->RecursiveRemove(fTrkRecoChargeHist[0]);
01948       fRecoChargeHist[0]->RecursiveRemove(fShwRecoChargeHist[0]); 
01949       fRecoChargeHist[0]->Add(fTrkRecoChargeHist[0]);
01950       fRecoChargeHist[0]->Add(fShwRecoChargeHist[0]); 
01951       fRecoChargeHist[0]->Draw("bar hist same");
01952 
01953       chargepad[2]->cd();
01954       fChargeHist[2]->Draw("hbar hist");
01955       fRecoChargeHist[2]->RecursiveRemove(fTrkRecoChargeHist[2]);
01956       fRecoChargeHist[2]->RecursiveRemove(fShwRecoChargeHist[2]); 
01957 
01958       fRecoChargeHist[2]->Add(fTrkRecoChargeHist[2]);
01959       fRecoChargeHist[2]->Add(fShwRecoChargeHist[2]); 
01960       fRecoChargeHist[2]->Draw("hbar hist same");     
01961     }
01962 }
01963 
01964 template<class TYPE> void killer(TYPE* obj) {delete obj; }
01965 
01966 void EVD::MCtext()
01967  
01968 {
01969   // write out NeuKine to a text box.
01970   // if the textbox is not currently visible, build it, and set to full width   
01971   if(!fTextBox){
01972     fTextBox = manage(new GuiBox(*fPageDisplay,kHorizontalFrame));
01973     fTextBox->SetHeight(200);
01974     fPageDisplay->SetWidth(fPageDisplay->GetWidth());
01975     fTextBox->SetWidth(fPageDisplay->GetWidth());
01976     fTextBox->SetLayoutHints(kLHintsTop || kLHintsLeft || kLHintsExpandX);
01977     fPageDisplay->Add(*fTextBox);
01978   } 
01979 
01980   // If the NeuKine data is already being viewed, we want to kill it.
01981   // Otherwise, create a new text view for this.
01982 
01983   if(fMCtextbox){
01984     fMCtextbox->Resize(1,1);
01985     fTextBox->Remove(*fMCtextbox);
01986     fMCtextbox=0;
01987     fMCbut->SetDown(false);
01988     fMCText=0;
01989   }
01990   else{ 
01991     fMCtextbox = manage(new GuiTextView(*fTextBox,1,1)); 
01992     fTextBox->Add(*fMCtextbox);
01993     fMCbut->SetDown(true);
01994     fMCText = manage(new MCText(fMCtextbox));
01995     fTextBox->SetHeight(200);
01996     fTextBox->SetWidth(fPageDisplay->GetWidth());
01997     fMCtextbox ->AddLine(" MC Kinematics ");
01998     fMCText->Update(fMint);
01999   }
02000 
02001   // If none of the text views are open at this point (we've just killed
02002   // the last), then remove the text box from the bottom of the display. 
02003 
02004   if(!fMCtextbox && !fRecotextbox && !fMCTreescroll && !fDigittextbox){
02005    fTextBox->Resize(1,1);
02006    fPageDisplay->Remove(*fTextBox);
02007    fPageDisplay->SetWidth(fPageDisplay->GetWidth());
02008    fTextBox=0;
02009   }
02010 
02011   //  refresh the main window.
02012   
02013   GuiMainWindow* mw = fPageDisplay->GetTab()->GetMainWindow();
02014   assert(mw);
02015   mw->ShowAll();
02016   mw->ConnectClose();
02017 }
02018 
02019 void EVD::MCTreetext()
02020  
02021 {
02022 
02023   // write out StdHep tree to a text box.
02024 
02025   // if the textbox is not currently visible, build it, and set to full width   
02026 
02027   if(!fTextBox)
02028     {
02029       fTextBox = manage(new GuiBox(*fPageDisplay,kHorizontalFrame));
02030       fTextBox->SetHeight(200);
02031       fTextBox->SetWidth(fPageDisplay->GetWidth());
02032       fTextBox->SetLayoutHints(kLHintsTop || kLHintsLeft || kLHintsExpandX);
02033       fPageDisplay->Add(*fTextBox);
02034     } 
02035 
02036   // If the StdHep is already being viewed, we want to kill it.
02037   // Otherwise, create a new text view and scroll tree for this.
02038 
02039   if(fMCTreescroll)
02040     {
02041       fMCTreescroll->Resize(1,1);
02042       fTextBox->Remove(*fMCTreescroll);
02043       fMCTreescroll=0;
02044       fMCTreebut->SetDown(false);
02045       fMCTree=0;
02046     }
02047   else
02048     { 
02049       fMCTreescroll = manage(new GuiScrolled(*fTextBox)); 
02050       fTextBox->Add(*fMCTreescroll);  
02051       GuiTree* gt = manage(new GuiTree(*fMCTreescroll->GetViewPort()));
02052       fMCTreescroll->Add(*gt);
02053       gt->SetCanvas(fMCTreescroll);
02054       fMCTree = manage(new MCTree(gt));
02055       fMCTreebut->SetDown(true);
02056       fTextBox->SetHeight(200);
02057       fTextBox->SetWidth(fPageDisplay->GetWidth());
02058       fMCTree->Update(fMint);
02059     }
02060 
02061   // If none of the text views are open at this point (we've just killed
02062   // the last), then remove the text box from the bottom of the display. 
02063 
02064   if(!fMCTreescroll && !fRecotextbox && !fMCtextbox && !fDigittextbox)
02065     {
02066       fTextBox->Resize(1,1);
02067       fPageDisplay->Remove(*fTextBox);
02068       fTextBox=0;
02069     }
02070   GuiMainWindow* mw = fPageDisplay->GetTab()->GetMainWindow();
02071   assert(mw);
02072   mw->ShowAll();
02073   mw->ConnectClose();
02074 }
02075 
02076 void EVD::Digittext()
02077  
02078 {
02079   if(!fTextBox)
02080     {
02081     fTextBox = manage(new GuiBox(*fPageDisplay,kHorizontalFrame));
02082     fTextBox->SetHeight(200);
02083     fTextBox->SetWidth(fPageDisplay->GetWidth());
02084     fTextBox->SetLayoutHints(kLHintsTop || kLHintsLeft || kLHintsExpandX);
02085     fPageDisplay->Add(*fTextBox);
02086     } 
02087   if(fDigittextbox)
02088     {
02089       fDigittextbox->Resize(1,1);
02090       fTextBox->Remove(*fDigittextbox);
02091       fDigittextbox=0;
02092       fDigitbut->SetDown(false);
02093       fDigitText=0;
02094     }
02095   else
02096     { 
02097       fDigittextbox = manage(new GuiTextView(*fTextBox,1,1)); 
02098       fTextBox->Add(*fDigittextbox);
02099       fDigitbut->SetDown(true);
02100       fDigitText = new DigitText(fDigittextbox); 
02101       fTextBox->SetHeight(200);
02102       fTextBox->SetWidth(fPageDisplay->GetWidth());
02103       fDigittextbox ->AddLine("Digitization Detail ");
02104     }
02105   if(!fMCtextbox && !fRecotextbox && !fMCTreescroll && !fDigittextbox)
02106     {
02107       fTextBox->Resize(1,1);
02108       fPageDisplay->Remove(*fTextBox);
02109       fTextBox=0;
02110     }
02111 
02112   GuiMainWindow* mw = fPageDisplay->GetTab()->GetMainWindow();
02113   assert(mw);
02114   mw->ShowAll();
02115   mw->ConnectClose();
02116 }
02117 
02118 void EVD::Recotext()
02119 {    
02120  // write out Reco dump to a text box.
02121 
02122   // if the textbox is not currently visible, build it, and set to full width 
02123 
02124   if(!fTextBox)
02125     {
02126       fTextBox = manage(new GuiBox(*fPageDisplay,kHorizontalFrame));
02127       fTextBox->SetHeight(200);
02128       fTextBox->SetWidth(fPageDisplay->GetWidth());
02129       fTextBox->SetLayoutHints(kLHintsTop || kLHintsLeft || kLHintsExpandX);
02130       fPageDisplay->Add(*fTextBox);
02131     } 
02132 
02133   // If the Reco dump is already being viewed, we want to kill it.
02134   // Otherwise, create a new text view for it.
02135 
02136   if(fRecotextbox)
02137     {
02138       fRecotextbox->Resize(1,1);
02139       fTextBox->Remove(*fRecotextbox);
02140       fRecotextbox=0;
02141       fRecobut->SetDown(false);
02142       fRecoText=0;                  
02143     }
02144   else
02145     { 
02146       fRecotextbox = manage(new GuiTextView(*fTextBox,1,1)); 
02147       FontStruct_t myfont = gClient->GetFontByName("-adobe-helvetica-medium-r-*-*-14-*-*-*-*-*-iso8859-1");
02148       fRecotextbox->SetFont(myfont);
02149       
02150       fTextBox->Add(*fRecotextbox);
02151       fRecobut->SetDown(true);
02152       fRecoText = new RecoText(fRecotextbox);
02153       fRecoText->Update(fMint);
02154     }
02155 
02156   // If none of the text views are open at this point (we've just killed
02157   // the last), then remove the text box from the bottom of the display. 
02158 
02159 
02160   if(!fMCtextbox && !fRecotextbox && ! fMCTreescroll && !fDigittextbox)
02161     {
02162       fTextBox->Resize(1,1);
02163       fPageDisplay->Remove(*fTextBox);
02164       fTextBox=0;
02165     }
02166   GuiMainWindow* mw = fPageDisplay->GetTab()->GetMainWindow();
02167   assert(mw);
02168   mw->ShowAll();
02169   mw->ConnectClose();
02170 }
02171 
02172 
02173 void EVD::UpdateSummary()
02174 {
02175 
02176   /* Here we write to the summary pad a short summary of the reconstruction
02177      results.  If there is a SimSnarlRecord available, we assume that this
02178      is MC data, and write out some NeuKine summary stuff. 
02179   */
02180 
02181 
02182   if(!fMint) return;
02183   
02184  float textsize=0.08;
02185   TextPad->cd();
02186   TextPad->Clear();
02187 
02188   CandRecord* candrec = dynamic_cast<CandRecord*>
02189     (fMint->GetJobC().Mom.GetFragment("CandRecord", "PrimaryCandidateRecord")); 
02190 
02191   if (candrec==0) {
02192     return ;
02193   }
02194 
02195   
02196   Int_t bestNeu=-1;
02197   Bool_t simulation = false;
02198   SimSnarlRecord *ssr = 
02199     dynamic_cast<SimSnarlRecord*>(fMint->GetJobC().Mom.GetFragment("SimSnarlRecord"));
02200   if (ssr) simulation=true; 
02201 
02202   // highlight text box color if in spill
02203   RawDaqSnarlHeader *rdsh=   
02204     dynamic_cast<RawDaqSnarlHeader*>(fMint->GetJobC().Mom.GetFragment("RawDaqSnarlHeader"));
02205   if (rdsh){
02206     // check header for spill flag
02207     if((rdsh->GetTrigSrc()==0x20000 && fMint->GetDetector() == Detector::kFar) ||(rdsh->GetTrigSrc()==0x10000 && fMint->GetDetector() == Detector::kNear)){
02208       TextPad->SetFillColor(2);
02209     }     
02210     else{
02211       TextPad->SetFillColor(17);
02212     }
02213   }
02214   
02215   TruthHelper truthHelp(&(fMint->GetJobC().Mom));
02216   int nLine=1;
02217   int run=0, snarl=0, event=0;
02218   DataUtil::GetRunSnarlEvent(&(fMint->GetJobC().Mom), run, snarl, event);
02219   
02220   int nTracks=0;
02221   int nShowers=0;
02222   int nEvents=0;
02223 
02224   CandTrackHandle * primtrack=0; 
02225   CandShowerHandle * primshw=0;
02226   CandShowerListHandle* showerlisthandle=0;
02227   CandTrackListHandle* tracklisthandle=0;
02228   /*
02229   if(fLastButtonType==2){
02230     fEvent++;
02231     fCandEvent=ReadCandEvent();
02232     fEvent--;
02233   }
02234   */
02235   Bool_t usefinder=false;
02236   if(fCandEvent){
02237     CandEventListHandle* eventlisthandle =
02238       dynamic_cast<CandEventListHandle*>
02239       (candrec->FindCandHandle("CandEventListHandle"));
02240     if (eventlisthandle) {
02241       TIter eventItr(eventlisthandle->GetDaughterIterator());
02242       while (CandEventHandle *event = dynamic_cast<CandEventHandle*>
02243              (eventItr())) {
02244         nEvents++;
02245         if(fCandEvent==event){ 
02246           primtrack=event->GetPrimaryTrack();
02247           if(primtrack){
02248             if(primtrack->GetNDaughters()==0 && 
02249                primtrack->InheritsFrom("CandFitTrackHandle") &&  
02250                dynamic_cast<CandFitTrackHandle*>(primtrack)->GetFinderTrack()){
02251               primtrack = dynamic_cast<CandFitTrackHandle*>(primtrack)->GetFinderTrack();
02252               usefinder=true;
02253             }
02254           }
02255           primshw=event->GetPrimaryShower();
02256           nTracks=event->GetLastTrack()+1;
02257           nShowers=event->GetLastShower()+1;
02258         }
02259       }
02260     } 
02261   }
02262   else{
02263     tracklisthandle = fMint->GetTracks();
02264     if (tracklisthandle){   
02265       Float_t maxscore=-1e6;
02266       TIter trackItr(tracklisthandle->GetDaughterIterator());
02267       while (CandTrackHandle *track = dynamic_cast<CandTrackHandle*>
02268              (trackItr())){
02269         if(track){
02270           CandSliceHandle slc1 =  *(track->GetCandSlice());
02271           CandSliceHandle slc2;
02272           if(fCandSlice)slc2=*(fCandSlice);
02273           if(slc1==slc2 || !fCandSlice || slc1.IsCloneOf(slc2)){
02274             if(track->GetNDaughters()==0 && 
02275                track->InheritsFrom("CandFitTrackHandle") &&  
02276                dynamic_cast<CandFitTrackHandle*>(track)->GetFinderTrack()){
02277               track = dynamic_cast<CandFitTrackHandle*>(track)->GetFinderTrack();
02278               usefinder=true;
02279             }       
02280             nTracks++;
02281             if(TMath::Abs(track->GetScore())>=maxscore){
02282               maxscore=track->GetScore();
02283               primtrack=track;
02284             }
02285           }
02286         }
02287       }
02288     }
02289     showerlisthandle = fMint->GetShowers();
02290     if (showerlisthandle) {
02291       TIter showerItr(showerlisthandle->GetDaughterIterator());
02292       while (CandShowerHandle *shower = dynamic_cast<CandShowerHandle*>
02293              (showerItr())){
02294         if(shower){
02295           CandSliceHandle slc1 =  *(shower->GetCandSlice());
02296           CandSliceHandle slc2;
02297           if(fCandSlice)slc2=*(fCandSlice);
02298           if(slc1==slc2 || !fCandSlice || slc1.IsCloneOf(slc2)){
02299             nShowers++;
02300           }
02301         }
02302       }
02303     }
02304   }
02305  
02306 
02307  
02308 
02309   char * cline = new char[80];
02310 
02311   if(fNumSlices>0){
02312     if(fSlice>=0 || fEvent>=0){
02313       if(fCandEvent){
02314         sprintf(cline,"Run: %d    Snarl:  %d    Slice:  %d of %d   Event: %d of %d",run,snarl,fSlice+1,fNumSlices,fEvent+1,fNumEvents);
02315       }
02316       else{
02317         sprintf(cline,"Run: %d    Snarl:  %d    Slice:  %d of %d   All %d Events",run,snarl,fSlice+1,fNumSlices,fNumEvents);
02318       }
02319     }
02320     else{
02321       sprintf(cline,"Run: %d        Snarl:  %d        All  %d Slices",run,snarl,fNumSlices);
02322     }
02323   }
02324   else{
02325     sprintf(cline,"Run: %d        Snarl:  %d        No Slice Found",run,snarl);
02326   }
02327   Int_t ntline=0;
02328   cline[79]=0;
02329   tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02330   nLine+=2;
02331   tline[ntline]->SetTextFont(62);
02332   tline[ntline]->SetTextSize(textsize);
02333   tline[ntline]->Draw();
02334   ntline++;
02335 
02336   sprintf(cline,"Reconstruction Summary");
02337   cline[79]=0;
02338   tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02339   nLine++;
02340   tline[ntline]->SetTextFont(52);
02341   tline[ntline]->SetTextSize(textsize);
02342   tline[ntline]->Draw();
02343   ntline++;
02344 
02345   sprintf(cline,"# Tracks:  %d        # Showers: %d",nTracks,nShowers);
02346   cline[79]=0;
02347   tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02348   nLine+=2;
02349   tline[ntline]->SetTextFont(42);
02350   tline[ntline]->SetTextSize(textsize);
02351   tline[ntline]->Draw();
02352   ntline++;
02353   if(fNumSlices>0 && fSlice<0 && fEvent<0) return;   // looking at all slices in overlay
02354 
02355   if(primtrack){
02356     CandFitTrackHandle *fittrack = 0;
02357     CandFitTrackSRHandle *fittracksr = 0;
02358     float P = primtrack->GetMomentum();
02359     if (primtrack->InheritsFrom("CandFitTrackHandle")) {
02360       fittrack = dynamic_cast<CandFitTrackHandle*>(primtrack);
02361     }
02362     if (primtrack->InheritsFrom("CandFitTrackSRHandle")) {
02363       fittracksr = dynamic_cast<CandFitTrackSRHandle*>(primtrack);
02364     }
02365     float length=primtrack->GetdS();
02366     float vtxX = (primtrack->GetVtxU()-primtrack->GetVtxV())/TMath::Sqrt(2.);
02367     float vtxY = (primtrack->GetVtxU()+primtrack->GetVtxV())/TMath::Sqrt(2.);
02368     float vtxZ = primtrack->GetVtxZ();
02369     float cosTheta = -(primtrack->GetDirCosU()+primtrack->GetDirCosV())/TMath::Sqrt(2.);
02370     
02371     float Pfit=0;
02372     float chi2=0;
02373     Int_t pass=0;
02374     if(fittrack){
02375       Pfit= fittrack->GetMomentumCurve()*fittrack->GetEMCharge();
02376       chi2= fittrack->GetChi2();
02377       P = fittrack->GetMomentumRange();
02378       pass=fittrack->GetPass();
02379     }
02380     Float_t purity = 0.0;
02381     Float_t completeSlice=0.0;
02382     Float_t completeAll=0.0;
02383    
02384     if(simulation){
02385       CandTrackHandle trk = *primtrack;
02386       Int_t bestTrack = truthHelp.GetBestTrackIdMatch(trk);
02387       bestNeu = truthHelp.GetNeuId(bestTrack);
02388       purity = truthHelp.TrackPurity(trk,bestTrack);
02389       completeAll = truthHelp.TrackCompleteness(trk);   
02390       CandSliceHandle slc;
02391       if(fCandEvent){
02392         slc = * fCandEvent->GetCandSlice();
02393       }
02394       else if(fCandSlice){
02395         slc = * fCandSlice;
02396       }
02397       else if(fNumSlices==1){
02398         slc = * trk.GetCandSlice();
02399       }
02400       if(fCandSlice || fCandEvent || fNumSlices==1){  
02401         completeSlice = truthHelp.TrackCompleteness(trk,slc);
02402         
02403       }
02404     }
02405     if(!usefinder){
02406       sprintf(cline,
02407               "Primary Track>  Len:%5.1f Range E:%5.1f GeV Fit P:%5.1f GeV",
02408               length,
02409               P,
02410               Pfit
02411               );
02412     }
02413     else{
02414       sprintf(cline,
02415               "(Finder) Primary Track>  Len:%5.1f Range E:%5.1f GeV",
02416               length,
02417               P
02418               );
02419     }
02420  
02421     cline[79]=0;
02422     tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02423     nLine++;
02424     tline[ntline]->SetTextFont(42);
02425     tline[ntline]->SetTextSize(textsize);
02426     tline[ntline]->Draw();
02427     ntline++;
02428     if(simulation){
02429       sprintf(cline,
02430               " Purity:%5.2f Compl.(Slice):%5.2f Compl.(All):%5.2f Pass:%1d",
02431             purity,completeSlice,completeAll,pass);
02432     }
02433     else{
02434       sprintf(cline,
02435             "   Vertex: (%3.1f,%3.1f,%3.1f) cos#theta: %3.2f Pass: %1d",
02436             vtxX, vtxY, vtxZ, cosTheta, pass);
02437     }
02438     cline[79] = 0;
02439     tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02440     nLine++;
02441     tline[ntline]->SetTextFont(42);
02442     tline[ntline]->SetTextSize(textsize);
02443     tline[ntline]->Draw();
02444     ntline++;
02445   }
02446   float PEs=0;
02447   float Gev=0;
02448   Float_t purity=0;
02449   Float_t completeSlice=0.0;
02450   Float_t completeAll=0.0;
02451   if(primshw){
02452     PEs = primshw->GetCharge(CalStripType::kPE);
02453     Gev = primshw->GetEnergy();
02454     if(simulation){
02455       CandShowerHandle shw= *primshw;
02456       Int_t neuId=  truthHelp.GetBestShowerNeuMatch(shw);
02457       if(bestNeu==-1) bestNeu=neuId;
02458       purity =  truthHelp.ShowerPurity(shw, neuId);
02459       completeAll = truthHelp.ShowerCompleteness(shw); 
02460       CandSliceHandle slc;
02461       if(fCandEvent){
02462         slc = * fCandEvent->GetCandSlice();
02463       }
02464       else if(fCandSlice){
02465         slc = * fCandSlice;
02466       }
02467       if(fCandSlice || fCandEvent){
02468         completeSlice = truthHelp.ShowerCompleteness(shw,slc);
02469 
02470       }
02471     }
02472   }
02473   else if( showerlisthandle){
02474     
02475     TIter showerItr(showerlisthandle->GetDaughterIterator());
02476     nShowers=showerlisthandle->GetNDaughters();
02477     while (CandShowerHandle *shower = dynamic_cast<CandShowerHandle*>
02478            (showerItr())){
02479       if(shower){
02480         CandSliceHandle slc1 =  *(shower->GetCandSlice());
02481         CandSliceHandle slc2;
02482         if(fCandSlice)slc2= *(fCandSlice);
02483         if(slc1==slc2 || !fCandSlice || slc1.IsCloneOf(slc2)){
02484           if(shower->GetEnergy()>Gev){
02485             PEs = shower->GetCharge(CalStripType::kPE);
02486             Gev = shower->GetEnergy();
02487             if(simulation){
02488               CandShowerHandle shw= *shower;
02489               Int_t neuId=  truthHelp.GetBestShowerNeuMatch(shw);
02490               if(bestNeu==-1) bestNeu=neuId;
02491               purity =  truthHelp.ShowerPurity(shw, neuId);
02492               completeAll = truthHelp.ShowerCompleteness(shw);
02493               CandSliceHandle slc;
02494               if(fCandEvent){
02495                 slc = * fCandEvent->GetCandSlice();
02496               }
02497               else if(fCandSlice){
02498                 slc = * fCandSlice;
02499               }
02500               else if (fNumSlices==1){
02501                 slc = * shw.GetCandSlice();
02502               }
02503               if(fCandSlice || fCandEvent || fNumSlices==1){          
02504                 completeSlice = truthHelp.ShowerCompleteness(shw,slc);
02505               }
02506             }
02507           }  
02508         }
02509       }
02510     }
02511   }  
02512   sprintf(cline,"Primary Shower> PEs:%6.1f  Energy:%6.2f GeV",
02513           PEs,
02514           Gev
02515           );   
02516   cline[79]=0;
02517   tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02518   nLine++;
02519   tline[ntline]->SetTextFont(42);
02520   tline[ntline]->SetTextSize(textsize);
02521   tline[ntline]->Draw();
02522   ntline++;
02523   if(simulation){
02524     sprintf(cline,
02525             "   Purity:%5.2f   Complete(Slice):%5.2f   Complete(All):%5.2f",
02526             purity,completeSlice,completeAll);
02527     cline[79]=0;
02528     tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02529     nLine++;
02530     tline[ntline]->SetTextFont(42);
02531     tline[ntline]->SetTextSize(textsize);
02532     tline[ntline]->Draw();
02533     ntline++;
02534   }
02535   
02536   nLine++;
02537   const MomNavigator* mom = fMint->GetJint().GetMom();
02538   if(mom)
02539     {
02540       if (simulation) 
02541         {
02542           sprintf(cline,"Monte Carlo Event. Generator Summary");
02543           tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02544           nLine++;
02545           tline[ntline]->SetTextFont(52);
02546           tline[ntline]->SetTextSize(textsize);
02547           tline[ntline]->Draw();
02548           ntline++;
02549          
02550           const REROOT_NeuKin* kin = 
02551             dynamic_cast<const REROOT_NeuKin*>
02552             (ssr->FindComponent("REROOT_NeuKin"));
02553           (ssr->FindComponent("TClonesArray","StdHep"));
02554        
02555           if(fCandEvent) bestNeu=truthHelp.GetBestEventNeuMatch(*fCandEvent);
02556           if(bestNeu!=-1){
02557             sprintf(cline,"Pnu=%6.2f  Eshwr=%6.2f  Pmu=%6.2f Pmu2=%6.2f  Pmu2Eele=%6.2f",   
02558                     truthHelp.GetP4Neu(bestNeu)[3],
02559                     truthHelp.GetP4Shw(bestNeu)[3],
02560                     truthHelp.GetP4Mu1(bestNeu)[3],
02561                     truthHelp.GetP4Mu2(bestNeu)[3],
02562                     truthHelp.GetP4El1(bestNeu)[3]);
02563           }
02564           else if(kin){
02565             sprintf(cline,"Pnu=%6.2f  Eshwr=%6.2f  Pmu=%6.2f  Eele=%6.2f",   
02566                     kin->P4Neu()[3],
02567                     kin->P4Shw()[3],
02568                     kin->P4Mu1()[3],
02569                     kin->P4El1()[3]);
02570           }
02571           cline[79]=0;      
02572           tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02573           nLine+=2;
02574           tline[ntline]->SetTextFont(42);
02575           tline[ntline]->SetTextSize(textsize);
02576           tline[ntline]->Draw();
02577           ntline++;
02578         }
02579     }
02580   
02581   CandCalDetPIDHandle * PIDh = DataUtil::GetCandidate<CandCalDetPIDHandle>
02582     (&(fMint->GetJobC().Mom),"CandCalDetPIDHandle");
02583   if(PIDh){
02584     sprintf(cline,"CalDet Particle ID Summary");
02585     tline[ntline] = new TText(textsize,1-nLine*textsize,cline);
02586     nLine++;
02587     tline[ntline]->SetTextFont(52);
02588     tline[ntline]->SetTextSize(textsize);
02589     tline[ntline]->Draw();
02590     ntline++;
02591     const char * c1 = PIDh->AsString().c_str();
02592     tline[ntline] = new TText(textsize,1-nLine*textsize,c1);
02593     nLine++;
02594     tline[ntline]->SetTextFont(42);
02595     tline[ntline]->SetTextSize(textsize);
02596     tline[ntline]->Draw();
02597     ntline++;
02598   }
02599   
02600     
02601 }
02602 
02603 
02604 void EVD::PrintCanvas(){
02605 
02606   if(!fMint) return;
02607   int run=0, snarl=0, event=0;
02608   DataUtil::GetRunSnarlEvent(&(fMint->GetJobC().Mom), run, snarl, event);
02609   char * cline = new char[80];
02610   sprintf(cline,"Run%dSnarl%d.ps",run,snarl);
02611   TCanvas& canvas = this->GetCanvas();
02612   canvas.Print(cline);
02613 
02614 }
02615 
02616 void EVD::SetChargeRange(){
02617   
02618   if(!fMint) return;
02619   if(GetDisplayOptions()->AutoScaleCharge()){
02620     
02621     Detector::Detector_t det = fMint->GetDetector();
02622     if (det == Detector::kUnknown) return;
02623     
02624     const CandDigitListHandle* cslh = fMint->GetDigits();
02625     if (!cslh) return;
02626     
02627     vector<const CandDigitHandle*> dv = 
02628       DataUtil::CDL2STLvector<CandDigitHandle>(*cslh);
02629     int siz = dv.size();
02630     if (! siz) return;
02631     
02632     double tmin=0, tmax=0, qmin=0,qmax=0;
02633     bool first = true;
02634     
02635     for (int ind = 0; ind < siz; ++ind) {
02636       const CandDigitHandle* csh = dv[ind];
02637       const PlexSEIdAltL& altl = csh->GetPlexSEIdAltL();
02638       PlaneView::PlaneView_t pv = altl.GetPlaneView();
02639       if (det != Detector::kCalib && 
02640           pv != PlaneView::kU && pv != PlaneView::kV) continue;
02641       
02642       altl.SetFirst();
02643       while (altl.IsValid()) {
02644         double q =csh->GetCharge();
02645         if(GetDisplayOptions()->ChargeType()==CalDigitType::kPE)
02646           q=altl.GetCurrentItem().GetPE();
02647         else if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigLin)
02648           q=altl.GetCurrentItem().GetSigLin();
02649         else if(GetDisplayOptions()->ChargeType()==CalDigitType::kSigCorr)
02650           q=altl.GetCurrentItem().GetSigCorr();
02651         
02652         if (first) {
02653           qmin = qmax = q;
02654           first=false;
02655           continue;
02656         }
02657         if (q < qmin) qmin = q;
02658         if (q > qmax) qmax = q;
02659         altl.Next();
02660       }
02661     }
02662     // give some buffer at either end...
02663     qmax +=  0.02*(qmax - qmin);
02664     qmin += -0.02*(qmax - qmin);
02665     
02666     
02667     if (!first) {
02668       
02669       double eps = 1.0e-10;
02670       if (tmin == tmax) { tmin -= eps; tmax += eps; }
02671       if (qmin == qmax) { qmin -= eps; qmax += eps; }
02672       
02673       fChargeRange->Set(qmin,qmax);
02674     }
02675   }
02676 }
02677 
02678 
02679 
02680 void EVD::DrawVS(){
02681 
02682   if (!fMint) return;
02683   if (fMint->GetDetector() != Detector::kFar) return;
02684   UgliGeomHandle ugh = fMint->GetUgliGeomHandle();
02685   if (! ugh.IsValid()) return;
02686   
02687   vector<UgliScintPlnHandle> usphv = ugh.GetScintPlnHandleVector();
02688   vector<UgliScintPlnHandle>::reverse_iterator rit, rdone = usphv.rend();
02689   VS = new TList;
02690   VS->SetOwner();
02691   float cx,cy; 
02692   StripEnd::StripEnd_t two_sided[] = { StripEnd::kEast,
02693                                        StripEnd::kWest };
02694   StripEnd::StripEnd_t *side_list = two_sided;
02695    
02696   for (rit = usphv.rbegin(); rit != rdone; ++rit) {
02697     if (! rit->GetPlexPlaneId().IsVetoShield()) break;
02698     int nstrips = rit->NumberOfStrips();
02699     for (int istrip=0; istrip < nstrips; istrip++) {
02700       PlexStripEndId oneend(rit->GetPlexPlaneId(),istrip,side_list[0]);
02701       UgliStripHandle ush = ugh.GetStripHandle(oneend);
02702       TVector3 stripxyz0(ush.GlobalPos(-ush.GetHalfLength()));
02703       TVector3 stripxyz1(ush.GlobalPos(ush.GetHalfLength()));
02704       cx = 0.5*(stripxyz0[0]+stripxyz1[0]);
02705       cy = 0.5*(stripxyz0[1]+stripxyz1[1]);     
02706       Double_t dy[5] = {-ush.GetHalfThickness(),
02707                         -ush.GetHalfThickness(),
02708                         +ush.GetHalfThickness(),
02709                         +ush.GetHalfThickness(),
02710                         -ush.GetHalfThickness()};
02711       Double_t dx[5] = {-ush.GetHalfWidth(),
02712                         +ush.GetHalfWidth(),
02713                         +ush.GetHalfWidth(),
02714                         -ush.GetHalfWidth(),
02715                         -ush.GetHalfWidth()};
02716       if(rit->GetPlaneView()==PlaneView::kVSWallOnEdge){
02717         for (int id=0;id<6;id++){
02718           double tmp=dy[id];
02719           dy[id]=dx[id];
02720           dx[id]=tmp;
02721         }
02722       }
02723       Double_t rot=0.9;
02724       if(rit->GetPlaneView()==PlaneView::kVSTopEastSlant){
02725         double newdx;
02726         double newdy;
02727         for (int id=0;id<6;id++){
02728           newdx=dx[id]*cos(-rot)+dy[id]*sin(-rot);
02729           newdy=-dx[id]*sin(-rot)+dy[id]*cos(-rot);
02730           dx[id]=newdx;
02731           dy[id]=newdy;
02732         }
02733       }
02734       if(rit->GetPlaneView()==PlaneView::kVSTopWestSlant){
02735         double newdx;
02736         double newdy;
02737         for (int id=0;id<6;id++){
02738           newdx=dx[id]*cos(rot)+dy[id]*sin(rot);
02739           newdy=-dx[id]*sin(rot)+dy[id]*cos(rot);
02740           dx[id]=newdx;
02741           dy[id]=newdy;
02742         }
02743 
02744       }
02745       Double_t xbox[5]={cx+dx[0],cx+dx[1],cx+dx[2],cx+dx[3],cx+dx[4]};
02746       Double_t ybox[5]={cy+dy[0],cy+dy[1],cy+dy[2],cy+dy[3],cy+dy[4]};
02747       TPolyLine * VSstrip = new TPolyLine(5,xbox,ybox);
02748       VS->Add(VSstrip);
02749     }
02750   }
02751   VS->Draw();
02752 }

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