RootShower.cxx

Go to the documentation of this file.
00001 // Author: Bertrand Bellenot   22/08/02
00002 
00003 /*************************************************************************
00004  * Copyright (C) 1995-2002, Bertrand Bellenot.                           *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see the LICENSE file.                         *
00008  *************************************************************************/
00009 
00010 #include <time.h>
00011 #include <Riostream.h>
00012 #include <string>
00013 
00014 #include <TROOT.h>
00015 #include <TStyle.h>
00016 #include <TRint.h>
00017 #include <TVirtualX.h>
00018 #include <TEnv.h>
00019 #include <KeySymbols.h>
00020 
00021 #include <TFile.h>
00022 #include <TTree.h>
00023 #include <TFrame.h>
00024 #include <TH1.h>
00025 #include <TF1.h>
00026 
00027 #include <TGMenu.h>
00028 #include <TGFileDialog.h>
00029 #include <TGTextEdit.h>
00030 #include <TGToolTip.h>
00031 #include <TG3DLine.h>
00032 #include <TRootEmbeddedCanvas.h>
00033 #include <TCanvas.h>
00034 #include <TRandom.h>
00035 #include <TSystem.h>
00036 #include <TRootHelpDialog.h>
00037 #include <TGStatusBar.h>
00038 #include <TBrowser.h>
00039 #include <TParticle.h>
00040 #include <TContextMenu.h>
00041 #include "RootShower.h"
00042 #include "MyParticle.h"
00043 #include "GTitleFrame.h"
00044 #include "GButtonFrame.h"
00045 #include "RSMsgBox.h"
00046 #include "RSAbout.h"
00047 #include "SettingsDlg.h"
00048 #include "RSHelpText.h"
00049 #include "MyEvent.h"
00050 
00051 #include <TGeoManager.h>
00052 #include <TView.h>
00053 #include <TGToolBar.h>
00054 #include <TGSplitter.h>
00055 #include <TColor.h>
00056 #include <TGLViewer.h>
00057 #include <THtml.h>
00058 
00059 #ifndef _CONSTANTS_H_
00060 #include "constants.h"
00061 #endif
00062 
00063 enum RootShowerMessageTypes {
00064    M_FILE_OPEN,
00065    M_FILE_SAVEAS,
00066    M_FILE_HTML,
00067    M_FILE_EXIT,
00068    M_EVENT_NEXT,
00069    M_EVENT_SELECT,
00070    M_INTERRUPT_SIMUL,
00071    M_ZOOM_PLUS,
00072    M_ZOOM_MOINS,
00073    M_ZOOM_PLUS2,
00074    M_ZOOM_MOINS2,
00075 
00076    M_SHOW_PROCESS,
00077    M_ANIMATE_GIF,
00078    M_SETTINGS_DLG,
00079    M_SETTINGS_SAVE,
00080    M_SHOW_INFOS,
00081    M_SHOW_3D,
00082    M_SHOW_TRACK,
00083 
00084    M_VIEW_TOOLBAR,
00085    M_INSPECT_BROWSER,
00086 
00087    M_HELP_PHYSICS,
00088    M_HELP_SIMULATION,
00089    M_HELP_LICENSE,
00090    M_HELP_ABOUT
00091 };
00092 
00093 const char *xpm_names[] = {
00094    "open.xpm",
00095    "save.xpm",
00096    "",
00097    "settings.xpm",
00098    "",
00099    "infos.xpm",
00100    "view3d.xpm",
00101    "",
00102    "browser.xpm",
00103    "",
00104    "manual.xpm",
00105    "help.xpm",
00106    "license.xpm",
00107    "about.xpm",
00108    "",
00109    "quit.xpm",
00110    0
00111 };
00112 
00113 ToolBarData_t tb_data[] = {
00114    { "", "Open Root event file",     kFALSE, M_FILE_OPEN,        NULL },
00115    { "", "Save event in Root file",  kFALSE, M_FILE_SAVEAS,      NULL },
00116    { "",              0,             0,      -1,                 NULL },
00117    { "", "Event settings",           kFALSE, M_SETTINGS_DLG,     NULL },
00118    { "",              0,             0,      -1,                 NULL },
00119    { "", "Infos on current event",   kFALSE, M_SHOW_INFOS,       NULL },
00120    { "", "Open 3D viewer",           kFALSE, M_SHOW_3D,          NULL },
00121    { "",              0,             0,      -1,                 NULL },
00122    { "", "Start Root browser",       kFALSE, M_INSPECT_BROWSER,  NULL },
00123    { "",              0,             0,      -1,                 NULL },
00124    { "", "Physics recalls",          kFALSE, M_HELP_PHYSICS,     NULL },
00125    { "", "RootShower help",          kFALSE, M_HELP_SIMULATION,  NULL },
00126    { "", "Display license",          kFALSE, M_HELP_LICENSE,     NULL },
00127    { "", "About RootShower",         kFALSE, M_HELP_ABOUT,       NULL },
00128    { "",              0,             0,      -1,                 NULL },
00129    { "", "Exit Application",         kFALSE, M_FILE_EXIT,        NULL },
00130    { NULL,            NULL,          0,      0,                  NULL }
00131 };
00132 
00133 RootShower      *gRootShower;
00134 Int_t            gColIndex;
00135 TGListTree      *gEventListTree; // event selection TGListTree
00136 TGListTreeItem  *gBaseLTI;
00137 TGListTreeItem  *gTmpLTI;
00138 TGListTreeItem  *gLTI[MAX_PARTICLE];
00139 
00140 const TGPicture *bpic, *bspic;
00141 const TGPicture *lpic, *lspic;
00142 
00143 const Char_t *filetypes[] = {
00144    "ROOT files",    "*.root",
00145    "ROOT macros",   "*.C",
00146    "GIF  files",    "*.gif",
00147    "PS   files",    "*.ps",
00148    "EPS  files",    "*.eps",
00149    "All files",     "*",
00150    0,               0
00151 };
00152 
00153 enum EGeometrySettingsDialogMessageTypes {
00154    kM_BUTTON_OK,
00155    kM_BUTTON_CANCEL,
00156    kM_COMBOBOX_CHANNELID,
00157    kM_COMBOBOX_TDC
00158 };
00159 
00160 
00161 ////////////////////////////////////////////////////////////////////////////////
00162 class TGToolButton : public TGPictureButton {
00163 
00164 private:
00165    Pixel_t fBgndColor;
00166 
00167 protected:
00168    void  DoRedraw();
00169 
00170 public:
00171    virtual ~TGToolButton() { }
00172    TGToolButton(const TGWindow *p, const TGPicture *pic, Int_t id = -1) :
00173          TGPictureButton(p, pic, id) {
00174       fBgndColor = GetDefaultFrameBackground();
00175       ChangeOptions(GetOptions() & ~kRaisedFrame);
00176    }
00177 
00178    Bool_t   IsDown() const { return (fOptions & kSunkenFrame); }
00179    void     SetState(EButtonState state, Bool_t emit = kTRUE);
00180    Bool_t   HandleButton(Event_t *event);
00181    Bool_t   HandleCrossing(Event_t *event);
00182    void     SetBackgroundColor(Pixel_t bgnd) { fBgndColor = bgnd; TGFrame::SetBackgroundColor(bgnd); }
00183 };
00184 
00185 //______________________________________________________________________________
00186 void TGToolButton::DoRedraw()
00187 {
00188    // Redraw tool button.
00189 
00190    int x = (fWidth - fTWidth) >> 1;
00191    int y = (fHeight - fTHeight) >> 1;
00192    UInt_t w = GetWidth() - 1;
00193    UInt_t h = GetHeight()- 1;
00194 
00195    TGFrame::SetBackgroundColor(fBgndColor);
00196 
00197    TGFrame::DoRedraw();
00198    if (fState == kButtonDown || fState == kButtonEngaged) {
00199       ++x; ++y;
00200       w--; h--;
00201    }
00202 
00203    const TGPicture *pic = fPic;
00204    if (fState == kButtonDisabled) {
00205       if (!fPicD) CreateDisabledPicture();
00206       pic = fPicD ? fPicD : fPic;
00207    }
00208    if (fBgndColor == 0xaaaaff) {
00209       //x--; y--;
00210       gVirtualX->DrawRectangle(fId, TGFrame::GetShadowGC()(), 0, 0, w, h);
00211    }
00212    pic->Draw(fId, fNormGC, x, y);
00213 }
00214 
00215 //______________________________________________________________________________
00216 Bool_t TGToolButton::HandleButton(Event_t *event)
00217 {
00218    // Handle mouse button event.
00219    
00220    Bool_t ret = TGButton::HandleButton(event);
00221    if (event->fType == kButtonRelease) {
00222       fBgndColor = GetDefaultFrameBackground();
00223    }
00224    DoRedraw();
00225    return ret;
00226 }
00227 
00228 //______________________________________________________________________________
00229 Bool_t TGToolButton::HandleCrossing(Event_t *event)
00230 {
00231    // Handle crossing events.
00232 
00233    if (fTip) {
00234       if (event->fType == kEnterNotify) {
00235          fTip->Reset();
00236       } else {
00237          fTip->Hide();
00238       }
00239    }
00240 
00241    if ((event->fType == kEnterNotify) && (fState != kButtonDisabled)) {
00242       fBgndColor = 0xaaaaff;
00243    } else {
00244       fBgndColor = GetDefaultFrameBackground();
00245    }
00246    if (event->fType == kLeaveNotify) {
00247       fBgndColor = GetDefaultFrameBackground();
00248       if (fState != kButtonDisabled && fState != kButtonEngaged)
00249          SetState(kButtonUp, kFALSE);
00250    }
00251    DoRedraw();
00252 
00253    return kTRUE;
00254 }
00255 
00256 //______________________________________________________________________________
00257 void TGToolButton::SetState(EButtonState state, Bool_t emit)
00258 {
00259    // Set state of tool bar button and emit a signal according 
00260    // to passed arguments.
00261 
00262    Bool_t was = !IsDown();
00263 
00264    if (state != fState) {
00265       switch (state) {
00266          case kButtonEngaged:
00267          case kButtonDown:
00268             fOptions &= ~kRaisedFrame;
00269             fOptions |= kSunkenFrame;
00270             break;
00271          case kButtonDisabled:
00272          case kButtonUp:
00273             fOptions &= ~kRaisedFrame;
00274             fOptions &= ~kSunkenFrame;
00275             break;
00276       }
00277       fState = state;
00278       DoRedraw();
00279       if (emit) EmitSignals(was);
00280    }
00281 }
00282 
00283 //_________________________________________________
00284 // RootShower
00285 //
00286 
00287 Int_t RootShower::fgDefaultXPosition = 20;
00288 Int_t RootShower::fgDefaultYPosition = 20;
00289 
00290 
00291 //______________________________________________________________________________
00292 RootShower::RootShower(const TGWindow *p, UInt_t w, UInt_t h):
00293   TGMainFrame(p, w, h)
00294 {
00295    // Create (the) Event Display.
00296    //
00297    // p = pointer to GMainFrame (not owner)
00298    // w = width of RootShower frame
00299    // h = width of RootShower frame
00300 
00301    fOk                 = kFALSE;
00302    fModified           = kFALSE;
00303    fSettingsModified   = kFALSE;
00304    fIsRunning          = kFALSE;
00305    fShowProcess        = kFALSE;
00306    fCreateGIFs         = kFALSE;
00307    fTimer              = 0;
00308    fPicIndex           = 1;
00309 
00310    fRootShowerEnv = new TEnv(".rootshowerrc");
00311 
00312    fFirstParticle = fRootShowerEnv->GetValue("RootShower.fFirstParticle", PHOTON);
00313    fE0            = fRootShowerEnv->GetValue("RootShower.fE0", 10.0);
00314    fB             = fRootShowerEnv->GetValue("RootShower.fB", 20.000);
00315    fPicNumber     = fRootShowerEnv->GetValue("RootShower.fPicNumber", 24);
00316    fPicDelay      = fRootShowerEnv->GetValue("RootShower.fPicDelay", 100);
00317    fPicReset      = fRootShowerEnv->GetValue("RootShower.fPicReset", 1);
00318 
00319    fEventNr = 0;
00320    fNRun    = 0;
00321 
00322    bpic = gClient->GetPicture("branch_t.xpm");
00323    bspic = gClient->GetPicture("branch_t.xpm");
00324 
00325    lpic = gClient->GetPicture("leaf_t.xpm");
00326    lspic = gClient->GetPicture("leaf_t.xpm");
00327 
00328    // Create menubar and popup menus.
00329    MakeMenuBarFrame();
00330 
00331    //---- toolbar
00332 
00333    int spacing = 8;
00334    fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame | kRaisedFrame);
00335    for (int i = 0; xpm_names[i]; i++) {
00336       TString iconname(gProgPath);
00337 #ifdef R__WIN32
00338       iconname += "\\icons\\";
00339 #else
00340       iconname += "/icons/";
00341 #endif
00342       iconname += xpm_names[i];
00343       tb_data[i].fPixmap = iconname.Data();
00344       if (strlen(xpm_names[i]) == 0) {
00345          fToolBar->AddFrame(new TGVertical3DLine(fToolBar), new TGLayoutHints(kLHintsExpandY, 4, 4));
00346          continue;
00347       }
00348       const TGPicture *pic = fClient->GetPicture(tb_data[i].fPixmap);
00349       TGToolButton *pb = new TGToolButton(fToolBar, pic, tb_data[i].fId);
00350       pb->SetToolTipText(tb_data[i].fTipText);
00351       tb_data[i].fButton = pb;
00352 
00353       fToolBar->AddButton(this, pb, spacing);
00354       spacing = 0;
00355    }
00356    AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
00357    fToolBar->GetButton(M_SHOW_3D)->SetState(kButtonDisabled);
00358    fToolBar->GetButton(M_FILE_SAVEAS)->SetState(kButtonDisabled);
00359     
00360    // Layout hints
00361    fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 0, 0);
00362    fL2 = new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 0, 0, 0, 0);
00363    fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
00364                            0, 0, 0, 0);
00365    fL4 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY, 5, 5, 2, 2);
00366    fL5 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
00367                            2, 2, 2, 2);
00368    fL6 = new TGLayoutHints(kLHintsBottom| kLHintsExpandX, 0, 0, 0, 0);
00369    fL7 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY,
00370                            5, 5, 2, 2);
00371    fL8 = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 0, 0);
00372 
00373    // CREATE TITLE FRAME
00374    fTitleFrame = new GTitleFrame(this, "ROOT Shower Monte Carlo", "Event Display", 100, 100);
00375    AddFrame(fTitleFrame, fL2);
00376 
00377    // CREATE MAIN FRAME
00378    fMainFrame = new TGCompositeFrame(this, 100, 100, kHorizontalFrame | kRaisedFrame);
00379 
00380    TGVerticalFrame *fV1 = new TGVerticalFrame(fMainFrame, 150, 10, kSunkenFrame | kFixedWidth);
00381    TGVerticalFrame *fV2 = new TGVerticalFrame(fMainFrame, 10, 10, kSunkenFrame);
00382 
00383    TGLayoutHints *lo;
00384 
00385    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY,2,0,2,2);
00386    fMainFrame->AddFrame(fV1, lo);
00387 
00388    TGVSplitter *splitter = new TGVSplitter(fMainFrame, 5);
00389    splitter->SetFrame(fV1, kTRUE);
00390    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0 ,0, 0);
00391    fMainFrame->AddFrame(splitter, lo);
00392 
00393    lo = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY,0,2,2,2);
00394    fMainFrame->AddFrame(fV2, lo);
00395 
00396 
00397    // Create Selection frame (i.e. with buttons and geometry selection widgets)
00398    fSelectionFrame = new TGCompositeFrame(fV1, 100, 100, kVerticalFrame);
00399    // create button frame
00400    fButtonFrame = new GButtonFrame (fSelectionFrame, this, M_EVENT_NEXT,
00401                                     M_EVENT_SELECT, M_INTERRUPT_SIMUL);
00402    lo = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 5, 1, 2);
00403    fSelectionFrame->AddFrame(fButtonFrame, lo);
00404 
00405    fTreeView = new TGCanvas(fSelectionFrame, 150, 10, kSunkenFrame | kDoubleBorder);
00406    fEventListTree = new TGListTree(fTreeView->GetViewPort(), 10, 10, kHorizontalFrame);
00407    gEventListTree = fEventListTree;
00408    fEventListTree->SetCanvas(fTreeView);
00409    fEventListTree->Associate(this);
00410    BuildEventTree();
00411    fTreeView->SetContainer(fEventListTree);
00412    fSelectionFrame->AddFrame(fTreeView, fL5);
00413 
00414    lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
00415    fV1->AddFrame(fSelectionFrame, lo);
00416 
00417    fContextMenu = new TContextMenu("RSContextMenu");
00418     
00419    //__________________________________________________________________________________
00420 
00421    // Create Display frame
00422    fDisplayFrame = new TGTab(fV2, 580, 360);
00423 
00424    // Create Display Canvas Tab (where the actual main event is displayed)
00425    TGCompositeFrame *tFrame = fDisplayFrame->AddTab("Main Event (Shower)");
00426 
00427    // Create Layout hints
00428    fZoomButtonsLayout = new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 5, 2, 2, 2);
00429 
00430    fHFrame = new TGHorizontalFrame(tFrame,0,0,0);
00431    tFrame->AddFrame(fHFrame, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5));
00432    // Create Zoom Buttons
00433    fZoomPlusButton = new TGTextButton(fHFrame, "&Zoom Forward", M_ZOOM_PLUS);
00434    fZoomPlusButton->Associate(this);
00435    fZoomPlusButton->SetToolTipText("Zoom forward event view");
00436    fHFrame->AddFrame(fZoomPlusButton, fZoomButtonsLayout);
00437    fZoomMoinsButton = new TGTextButton(fHFrame, "Zoom &Backward", M_ZOOM_MOINS);
00438    fZoomMoinsButton->Associate(this);
00439    fZoomMoinsButton->SetToolTipText("Zoom backward event view");
00440    fHFrame->AddFrame(fZoomMoinsButton, fZoomButtonsLayout);
00441 
00442    fEmbeddedCanvas = new TRootEmbeddedCanvas("fEmbeddedCanvas", tFrame, 580, 360);
00443    tFrame->AddFrame(fEmbeddedCanvas, fL5);
00444    fEmbeddedCanvas->GetCanvas()->SetBorderMode(0);
00445    fCA = fEmbeddedCanvas->GetCanvas();
00446    fCA->SetFillColor(1);
00447 
00448    // Create Display Canvas Tab (where the selected event is displayed)
00449    TGCompositeFrame *tFrame2 = fDisplayFrame->AddTab("Selected Track");
00450 
00451    fHFrame2 = new TGHorizontalFrame(tFrame2,0,0,0);
00452    tFrame2->AddFrame(fHFrame2, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5));
00453    // Create Zoom Buttons
00454    fZoomPlusButton2 = new TGTextButton(fHFrame2, "&Zoom Forward", M_ZOOM_PLUS2);
00455    fZoomPlusButton2->Associate(this);
00456    fZoomPlusButton2->SetToolTipText("Zoom forward event view");
00457    fHFrame2->AddFrame(fZoomPlusButton2, fZoomButtonsLayout);
00458    fZoomMoinsButton2 = new TGTextButton(fHFrame2, "Zoom &Backward", M_ZOOM_MOINS2);
00459    fZoomMoinsButton2->Associate(this);
00460    fZoomMoinsButton2->SetToolTipText("Zoom backward event view");
00461    fHFrame2->AddFrame(fZoomMoinsButton2, fZoomButtonsLayout);
00462 
00463    fEmbeddedCanvas2 = new TRootEmbeddedCanvas("fEmbeddedCanvas2", tFrame2, 580, 360);
00464    tFrame2->AddFrame(fEmbeddedCanvas2, fL5);
00465    fEmbeddedCanvas2->GetCanvas()->SetBorderMode(0);
00466    fCB = fEmbeddedCanvas2->GetCanvas();
00467    fCB->SetFillColor(1);
00468 
00469    // Create Display Canvas Tab (where the histogram is displayed)
00470    TGCompositeFrame *tFrame3 = fDisplayFrame->AddTab("Statistics");
00471 
00472    fEmbeddedCanvas3 = new TRootEmbeddedCanvas("fEmbeddedCanvas3", tFrame3, 580, 360);
00473    tFrame3->AddFrame(fEmbeddedCanvas3, fL5);
00474    fEmbeddedCanvas3->GetCanvas()->SetBorderMode(0);
00475    fCC = fEmbeddedCanvas3->GetCanvas();
00476    fCC->SetFillColor(10);
00477    fCC->cd();
00478    fPadC = new TPad("fPadC","Histogram",0.0,0.0,1.0,1.0,10,3,1);
00479    fPadC->SetFillColor(10);
00480    fPadC->SetBorderMode(0);
00481    fPadC->SetBorderSize(0);
00482    fPadC->Draw();
00483    // Creation of histogram for particle's energy loss
00484    fHisto_dEdX = new TH1F("Statistics","Energy loss for each particle",100,0,0.025); // Max at 25 MeV
00485    fHisto_dEdX->SetFillColor(38);
00486    fHisto_dEdX->SetStats(kTRUE);
00487    fHisto_dEdX->SetXTitle("Energy Loss [GeV]");
00488    fHisto_dEdX->SetLabelFont(42,"X");
00489    fHisto_dEdX->SetLabelSize(0.03f, "X");
00490    fHisto_dEdX->GetXaxis()->SetTitleFont(42);
00491    fHisto_dEdX->SetYTitle("Number");
00492    fHisto_dEdX->SetLabelFont(42,"Y");
00493    fHisto_dEdX->SetLabelSize(0.03f, "Y");
00494    fHisto_dEdX->GetYaxis()->SetTitleFont(42);
00495 
00496    fCC->Update();
00497 
00498    // Create text display Tab
00499    tFrame = fDisplayFrame->AddTab("PDG Table");
00500    fTextView = new TGTextEdit(tFrame, 300, 100, kSunkenFrame | kDoubleBorder);
00501    tFrame->AddFrame(fTextView, fL5);
00502    TString pdgFilename = gSystem->Getenv("ROOTSYS");
00503    pdgFilename.Append("/etc/pdg_table.txt");
00504 
00505    fTextView->LoadFile(pdgFilename);
00506 
00507    lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
00508    fV2->AddFrame(fDisplayFrame, lo);
00509 
00510    AddFrame(fMainFrame, lo);
00511 
00512    // Create status bar
00513    Int_t parts[] = {45, 45, 10};
00514    fStatusBar = new TGStatusBar(this, 50, 10, kHorizontalFrame);
00515    fStatusBar->SetParts(parts, 3);
00516    AddFrame(fStatusBar, fL6);
00517    fStatusBar->SetText("Waiting to start simulation...",0);
00518 
00519    // Finish RootShower for display...
00520    SetWindowName("Root Shower Event Display");
00521    SetIconName("Root Shower Event Display");
00522    MapSubwindows();
00523    Resize(GetDefaultSize()); // this is used here to init layout algoritme
00524    MapWindow();
00525    fEvent = new MyEvent();
00526    fEvent->GetDetector()->Init();
00527    fEvent->Init(0, fFirstParticle, fE0, fB);
00528    Initialize(1);
00529    gROOT->GetListOfBrowsables()->Add(fEvent,"RootShower Event");
00530    gSystem->Load("libTreeViewer");
00531    AddInput(kKeyPressMask | kKeyReleaseMask);
00532    gVirtualX->SetInputFocus(GetId());
00533    gRootShower = this;
00534 }
00535 
00536 
00537 //______________________________________________________________________________
00538 void RootShower::MakeMenuBarFrame()
00539 {
00540    // Create menubar and popup menus.
00541 
00542    // layout hint items
00543    fMenuBarLayout = new TGLayoutHints(kLHintsTop| kLHintsLeft | kLHintsExpandX,
00544                                       0, 0, 0, 0);
00545    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00546    fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00547 
00548    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame | kRaisedFrame);
00549 
00550    // file popup menu
00551    fMenuFile = new TGPopupMenu(gClient->GetRoot());
00552    fMenuFile->AddEntry("&Open...\tCtrl+O", M_FILE_OPEN);
00553    fMenuFile->AddEntry("S&ave as...\tCtrl+A", M_FILE_SAVEAS);
00554    fMenuFile->AddEntry("&Close", -1);
00555    fMenuFile->AddSeparator();
00556    fMenuFile->AddEntry("&Print", -1);
00557    fMenuFile->AddEntry("P&rint setup...", -1);
00558    fMenuFile->AddSeparator();
00559    fMenuFile->AddEntry("E&xit\tCtrl+Q", M_FILE_EXIT);
00560    fMenuFile->DisableEntry(M_FILE_SAVEAS);
00561    fMenuFile->Associate(this);
00562 
00563    fMenuEvent = new TGPopupMenu(gClient->GetRoot());
00564    fMenuEvent->AddLabel("Simulation Settings...");
00565    fMenuEvent->AddSeparator();
00566    fMenuEvent->AddEntry("&Settings...", M_SETTINGS_DLG);
00567    fMenuEvent->AddEntry("Save &Parameters", M_SETTINGS_SAVE);
00568    fMenuEvent->AddEntry("Show &Process", M_SHOW_PROCESS);
00569    fMenuEvent->AddEntry("Animated &GIF", M_ANIMATE_GIF);
00570    fMenuEvent->AddEntry("&Infos...\tCtrl+I", M_SHOW_INFOS);
00571    fMenuEvent->AddSeparator();
00572    fMenuEvent->AddEntry("&3D View", M_SHOW_3D);
00573    fMenuEvent->AddEntry("&Show Selected  Track", M_SHOW_TRACK);
00574    fMenuEvent->DisableEntry(M_SHOW_INFOS);
00575    fMenuEvent->DisableEntry(M_SHOW_3D);
00576    fMenuEvent->DisableEntry(M_SHOW_TRACK);
00577 
00578    fMenuEvent->DisableEntry(M_SHOW_PROCESS);
00579    fMenuEvent->DisableEntry(M_ANIMATE_GIF);
00580 
00581    fMenuEvent->Associate(this);
00582 
00583    fMenuTools = new TGPopupMenu(gClient->GetRoot());
00584    fMenuTools->AddLabel("Simulation Tools...");
00585    fMenuTools->AddSeparator();
00586    fMenuTools->AddEntry("Start &Browser\tCtrl+B", M_INSPECT_BROWSER);
00587    fMenuTools->AddEntry("&Create Html Doc", M_FILE_HTML);
00588    fMenuTools->Associate(this);
00589 
00590    fMenuView = new TGPopupMenu(gClient->GetRoot());
00591    fMenuView->AddEntry("&Toolbar", M_VIEW_TOOLBAR);
00592    fMenuView->Associate(this);
00593    fMenuView->CheckEntry(M_VIEW_TOOLBAR);
00594 
00595    fMenuHelp = new TGPopupMenu(gClient->GetRoot());
00596    fMenuHelp->AddEntry("&Physics", M_HELP_PHYSICS);
00597    fMenuHelp->AddEntry("&Simulation", M_HELP_SIMULATION);
00598    fMenuHelp->AddSeparator();
00599    fMenuHelp->AddEntry("&License...", M_HELP_LICENSE);
00600    fMenuHelp->AddEntry("&About...", M_HELP_ABOUT);
00601    fMenuHelp->Associate(this);
00602 
00603    fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
00604    fMenuBar->AddPopup("&Event", fMenuEvent, fMenuBarItemLayout);
00605    fMenuBar->AddPopup("&Tools", fMenuTools, fMenuBarItemLayout);
00606    fMenuBar->AddPopup("&View", fMenuView, fMenuBarItemLayout);
00607    fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
00608 
00609    AddFrame(fMenuBar, fMenuBarLayout);
00610 }
00611 
00612 
00613 //______________________________________________________________________________
00614 void RootShower::CloseMenuBarFrame()
00615 {
00616    // Destroy menubar and popup menus.
00617 
00618    delete fMenuHelp;
00619    delete fMenuEvent;
00620    delete fMenuTools;
00621    delete fMenuFile;
00622 
00623    delete fMenuBarItemLayout;
00624    delete fMenuBarHelpLayout;
00625    delete fMenuBar;
00626    delete fMenuBarLayout;
00627 }
00628 
00629 //______________________________________________________________________________
00630 void RootShower::ShowToolBar(Bool_t show)
00631 {
00632    // Show or hide toolbar.
00633 
00634    if (show) {
00635       ShowFrame(fToolBar);
00636       fMenuView->CheckEntry(M_VIEW_TOOLBAR);
00637    } else {
00638       HideFrame(fToolBar);
00639       fMenuView->UnCheckEntry(M_VIEW_TOOLBAR);
00640    }
00641 }
00642 
00643 //______________________________________________________________________________
00644 RootShower::~RootShower()
00645 {
00646    // Destroy RootShower object. Delete all created widgets
00647    // GUI MEMBERS
00648 
00649    CloseMenuBarFrame();
00650 
00651    delete fContextMenu;
00652    delete fZoomPlusButton2;
00653    delete fZoomMoinsButton2;
00654    delete fZoomPlusButton;
00655    delete fZoomMoinsButton;
00656    delete fHFrame;
00657    delete fHFrame2;
00658    delete fZoomButtonsLayout;
00659 
00660    delete fEmbeddedCanvas;
00661    delete fTextView;
00662    delete fDisplayFrame;
00663    delete fEventListTree;
00664    delete fTreeView;
00665    delete fButtonFrame;
00666    delete fSelectionFrame;
00667    delete fMainFrame;
00668    delete fTitleFrame;
00669 
00670    delete fL8;
00671    delete fL7;
00672    delete fL6;
00673    delete fL5;
00674    delete fL4;
00675    delete fL3;
00676    delete fL2;
00677    delete fL1;
00678 }
00679 
00680 //______________________________________________________________________________
00681 void RootShower::setDefaultPosition(Int_t x, Int_t y)
00682 {
00683    // Set the default position on the screen of new RootShower instances.
00684 
00685    fgDefaultXPosition = x;
00686    fgDefaultYPosition = y;
00687 }
00688 
00689 //______________________________________________________________________________
00690 void RootShower::Layout()
00691 {
00692    // Apply layout on the main frame.
00693 
00694    TGMainFrame::Layout();
00695 }
00696 
00697 
00698 //______________________________________________________________________________
00699 void RootShower::CloseWindow()
00700 {
00701    // Got close message for this RootShower. The EventDislay and the
00702    // application will be terminated.
00703 
00704    if (fModified) {
00705       new RootShowerMsgBox(gClient->GetRoot(),this, 400, 200);
00706       if ( fOk ) {
00707          fRootShowerEnv->SetValue("RootShower.fFirstParticle",fFirstParticle);
00708          fRootShowerEnv->SetValue("RootShower.fE0",fE0);
00709          fRootShowerEnv->SetValue("RootShower.fB",fB);
00710          fRootShowerEnv->SaveLevel(kEnvLocal);
00711          cout << " Saving stuff .... " << endl;
00712 #ifdef R__WIN32
00713          gSystem->Exec("del .rootshowerrc");
00714          gSystem->Rename(".rootshowerrc.new",".rootshowerrc");
00715 #endif
00716       }
00717    }
00718    cout << "Terminating RootShower" << endl;
00719    DeleteWindow();
00720    gApplication->Terminate(0);
00721 }
00722 
00723 //______________________________________________________________________________
00724 Bool_t RootShower::HandleConfigureNotify(Event_t *event)
00725 {
00726    // This event is generated when the frame is resized.
00727 
00728    TGFrame* f = (TGFrame*)this;
00729    if ((event->fWidth != f->GetWidth()) || (event->fHeight != f->GetHeight())) {
00730       UInt_t w = event->fWidth;
00731       UInt_t h = event->fHeight;
00732       f->Resize(w,h);
00733       f->Layout();
00734    }
00735    return kTRUE;
00736 }
00737 
00738 //______________________________________________________________________________
00739 Bool_t RootShower::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00740 {
00741    // Handle messages send to the RootShower object.
00742 
00743    Window_t wdummy;
00744    int ax, ay;
00745    TRootHelpDialog *hd;
00746    TGListTreeItem *item;
00747    TGFileInfo fi;
00748    Char_t  strtmp[250];
00749 
00750    switch (GET_MSG(msg)) {
00751 
00752       case kC_COMMAND:
00753 
00754          switch (GET_SUBMSG(msg)) {
00755 
00756             case kCM_BUTTON:
00757             case kCM_MENU:
00758                switch (parm1) {
00759 
00760                   case M_EVENT_NEXT:
00761                      if (fDisplayFrame->GetCurrent() != 0)
00762                         fDisplayFrame->SetTab(0);
00763                      Initialize(0);
00764                      fStatusBar->SetText("Simulation running, please wait...",0);
00765                      fButtonFrame->SetState(GButtonFrame::kNoneActive);
00766                      fMenuEvent->DisableEntry(M_SETTINGS_DLG);
00767                      OnShowerProduce();
00768                      fEventListTree->ClearViewPort();
00769                      fClient->NeedRedraw(fEventListTree);
00770                      fButtonFrame->SetState(GButtonFrame::kAllActive);
00771                      fMenuEvent->EnableEntry(M_SETTINGS_DLG);
00772                      sprintf(strtmp,"Done - Total particles : %d - Waiting for next simulation",
00773                              fEvent->GetTotal());
00774                      fStatusBar->SetText(strtmp,0);
00775                      break;
00776                   case M_EVENT_SELECT:
00777                      if (fDisplayFrame->GetCurrent() != 1)
00778                         fDisplayFrame->SetTab(1);
00779                      if ((item = fEventListTree->GetSelected()) != 0)
00780                         OnShowSelected(item);
00781                      break;
00782                   case M_INTERRUPT_SIMUL:
00783                      Interrupt();
00784                      break;
00785 
00786                   case M_ZOOM_PLUS:
00787                      fCA->cd();
00788                      fCA->GetView()->ZoomView(0, 1.25);
00789                      fCA->Modified();
00790                      fCA->Update();
00791                      break;
00792 
00793                   case M_ZOOM_MOINS:
00794                      fCA->cd();
00795                      fCA->GetView()->UnzoomView(0, 1.25);
00796                      fCA->Modified();
00797                      fCA->Update();
00798                      break;
00799 
00800                   case M_ZOOM_PLUS2:
00801                      fCB->cd();
00802                      fCB->GetView()->ZoomView(0, 1.25);
00803                      fCB->Modified();
00804                      fCB->Update();
00805                      break;
00806 
00807                   case M_ZOOM_MOINS2:
00808                      fCB->cd();
00809                      fCB->GetView()->UnzoomView(0, 1.25);
00810                      fCB->Modified();
00811                      fCB->Update();
00812                      break;
00813 
00814                   case M_FILE_OPEN:
00815                      if (fIsRunning) break;
00816                      fi.fFileTypes = filetypes;
00817                      new TGFileDialog(fClient->GetRoot(), this, kFDOpen,&fi);
00818                      if (!fi.fFilename) return kTRUE;
00819                      OnOpenFile(fi.fFilename);
00820                      break;
00821 
00822                   case M_FILE_HTML:
00823                      {
00824                         THtml html;
00825                         html.SetInputDir(gProgPath);
00826                         html.MakeClass("MyParticle");
00827                         html.MakeClass("MyDetector");
00828                         html.MakeClass("EventHeader");
00829                         html.MakeClass("MyEvent");
00830                         html.MakeIndex();
00831                      }
00832                      break;
00833 
00834                   case M_FILE_SAVEAS:
00835                      if (fIsRunning) break;
00836                      fi.fFileTypes = filetypes;
00837                      new TGFileDialog(fClient->GetRoot(), this, kFDSave,&fi);
00838                      if (!fi.fFilename) return kTRUE;
00839                      OnSaveFile(fi.fFilename);
00840                      break;
00841 
00842                   case M_FILE_EXIT:
00843                      CloseWindow();   // this also terminates theApp
00844                      break;
00845 
00846                   case M_SHOW_PROCESS:
00847                      if (fShowProcess) {
00848                         fMenuEvent->UnCheckEntry(M_SHOW_PROCESS);
00849                         fShowProcess = kFALSE;
00850                      }
00851                      else {
00852                         fMenuEvent->CheckEntry(M_SHOW_PROCESS);
00853                         fShowProcess = kTRUE;
00854                      }
00855                      break;
00856 
00857                   case M_ANIMATE_GIF:
00858                      if (fCreateGIFs) {
00859                         fMenuEvent->UnCheckEntry(M_ANIMATE_GIF);
00860                         fCreateGIFs = kFALSE;
00861                      }
00862                      else {
00863                         fMenuEvent->CheckEntry(M_ANIMATE_GIF);
00864                         fCreateGIFs = kTRUE;
00865                      }
00866                      break;
00867 
00868                   case M_SETTINGS_DLG:
00869                      if (fIsRunning) break;
00870                      new SettingsDialog(fClient->GetRoot(), this, 400, 200);
00871                      if (fSettingsModified) {
00872                         fEvent->Init(0, fFirstParticle, fE0, fB);
00873                         Initialize(0);
00874                         gRootShower->Modified();
00875                         gRootShower->SettingsModified(kFALSE);
00876                      }
00877                      break;
00878 
00879                   case M_SETTINGS_SAVE:
00880                      fRootShowerEnv->SetValue("RootShower.fFirstParticle",fFirstParticle);
00881                      fRootShowerEnv->SetValue("RootShower.fE0",fE0);
00882                      fRootShowerEnv->SetValue("RootShower.fB",fB);
00883                      fRootShowerEnv->SaveLevel(kEnvLocal);
00884 #ifdef R__WIN32
00885                      gSystem->Exec("del .rootshowerrc");
00886                      gSystem->Rename(".rootshowerrc.new",".rootshowerrc");
00887 #endif
00888                      gRootShower->Modified(kFALSE);
00889                      break;
00890 
00891                   case M_SHOW_INFOS:
00892                      if (fIsRunning) break;
00893                      ShowInfos();
00894                      break;
00895 
00896                   case M_INSPECT_BROWSER:
00897                      new TBrowser;
00898                      break;
00899 
00900                   case M_VIEW_TOOLBAR:
00901                      if (fMenuView->IsEntryChecked(M_VIEW_TOOLBAR))
00902                         ShowToolBar(kFALSE);
00903                      else
00904                         ShowToolBar();
00905                      break;
00906 
00907                   case M_HELP_PHYSICS:
00908 #ifdef R__WIN32
00909                      sprintf(strtmp, "start winhlp32 %s\\Physics.hlp",gProgPath);
00910                      gSystem->Exec(strtmp);
00911 #else
00912                      sprintf(strtmp, "Help on Physics");
00913                      hd = new TRootHelpDialog(this, strtmp, 620, 350);
00914                      hd->SetText(gPhysicsHelpText);
00915                      gVirtualX->TranslateCoordinates(GetId(), GetParent()->GetId(),
00916                                                      (Int_t)(GetWidth() - 620) >> 1,
00917                                                      (Int_t)(GetHeight() - 350) >> 1,
00918                                                      ax, ay, wdummy);
00919                      hd->Move(ax, ay);
00920                      hd->Popup();
00921                      fClient->WaitFor(hd);
00922 #endif
00923                      break;
00924 
00925                   case M_HELP_SIMULATION:
00926                      sprintf(strtmp, "Help on Simulation");
00927                      hd = new TRootHelpDialog(this, strtmp, 620, 350);
00928                      hd->SetText(gSimulationHelpText);
00929                      gVirtualX->TranslateCoordinates(GetId(), GetParent()->GetId(),
00930                                                      (Int_t)(GetWidth() - 620) >> 1,
00931                                                      (Int_t)(GetHeight() - 350) >> 1,
00932                                                      ax, ay, wdummy);
00933                      hd->Move(ax, ay);
00934                      hd->Popup();
00935                      fClient->WaitFor(hd);
00936                      break;
00937 
00938                   case M_HELP_LICENSE:
00939                      sprintf(strtmp, "RootShower License");
00940                      hd = new TRootHelpDialog(this, strtmp, 640, 380);
00941                      hd->SetText(gHelpLicense);
00942                      gVirtualX->TranslateCoordinates(GetId(), GetParent()->GetId(),
00943                                                     (Int_t)(GetWidth() - 640) >> 1,
00944                                                     (Int_t)(GetHeight() - 380) >> 1,
00945                                                     ax, ay, wdummy);
00946                      hd->Move(ax, ay);
00947                      hd->Popup();
00948                      fClient->WaitFor(hd);
00949                      break;
00950 
00951                   case M_HELP_ABOUT:
00952                      new RootShowerAbout(gClient->GetRoot(),this, 400, 200);
00953                      break;
00954 
00955                   case M_SHOW_3D:
00956                      {
00957                         if (fIsRunning) break;
00958                         fCA->cd();
00959                         TVirtualViewer3D *viewer3D = fCA->GetViewer3D("ogl");
00960                         TGLViewer *glviewer = (TGLViewer *)viewer3D;
00961                         glviewer->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
00962                         glviewer->CurrentCamera().RotateRad(0.0, TMath::Pi());
00963                         glviewer->CurrentCamera().Dolly(-100, 0, 0);
00964                      }
00965                      break;
00966 
00967                   case M_SHOW_TRACK:
00968                      if (fIsRunning) break;
00969                      if (fDisplayFrame->GetCurrent() != 1)
00970                         fDisplayFrame->SetTab(1);
00971                      if ((item = fEventListTree->GetSelected()) != 0)
00972                         OnShowSelected(item);
00973                      break;
00974 
00975 
00976                } // switch parm1
00977                break; // M_MENU
00978 
00979             } // switch submsg
00980             break; // case kC_COMMAND
00981 
00982          case kC_LISTTREE:
00983 
00984             switch (GET_SUBMSG(msg)) {
00985 
00986                case kCT_ITEMDBLCLICK:
00987                   if (parm1 == kButton1) {
00988                      if (fEventListTree->GetSelected()) {
00989                         fEventListTree->ClearViewPort();
00990                         fClient->NeedRedraw(fEventListTree);
00991                      }
00992                   }
00993                   break;
00994                     
00995                case kCT_ITEMCLICK:
00996                   if (parm1 == kButton3) {
00997                      if (fEventListTree->GetSelected()) {
00998                         Int_t x = (Int_t)(parm2 & 0xffff);
00999                         Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
01000                         Clicked(fEventListTree->GetSelected(), x, y);
01001                      }
01002                   }
01003                   break;
01004 
01005             } // switch submsg
01006             break; // case kC_LISTTREE
01007    } // switch msg
01008 
01009    return kTRUE;
01010 }
01011 
01012 
01013 //______________________________________________________________________________
01014 TGListTreeItem* RootShower::AddToTree(const char *name)
01015 {
01016    // Add item to the TGListTree of the event display. It will be connected
01017    // to the current TGListTreeItem (i.e. fCurEventListItem)
01018 
01019    TGListTreeItem *e = 0;
01020    e = fEventListTree->AddItem(fCurListItem, name);
01021    return e;
01022 }
01023 
01024 //______________________________________________________________________________
01025 void RootShower::BuildEventTree()
01026 {
01027    // Add recursively stations and layers (and cells) in TGListTree.
01028 
01029    fCurListItem = 0;
01030    TGListTreeItem *eventLTItem = AddToTree("Event");
01031    fCurListItem = eventLTItem;
01032    gBaseLTI = eventLTItem;
01033 }
01034 
01035 //______________________________________________________________________________
01036 void RootShower::Initialize(Int_t set_angles)
01037 {
01038    // Initialize RootShower display.
01039 
01040    Interrupt(kFALSE);
01041    fEventListTree->DeleteChildren(fCurListItem);
01042    fEventListTree->ClearViewPort();
01043    fClient->NeedRedraw(fEventListTree);
01044 
01045    fCB->cd();
01046    fCB->SetFillColor(1);
01047    fCB->Clear();
01048    gGeoManager->GetTopVolume()->Draw();
01049    fCB->GetView()->SetPerspective();
01050    if (set_angles)
01051       fCB->GetView()->SideView();
01052    gGeoManager->GetTopVolume()->Draw();
01053    fCB->cd();
01054    fCB->Update();
01055 
01056    fCA->cd();
01057    fCA->SetFillColor(1);
01058    fCA->Clear();
01059    gGeoManager->GetTopVolume()->Draw();
01060    fCA->GetView()->SetPerspective();
01061    if (set_angles)
01062       fCA->GetView()->SideView();
01063    gGeoManager->GetTopVolume()->Draw();
01064    fCA->cd();
01065    fCA->Update();
01066    fStatusBar->SetText("",1);
01067 }
01068 
01069 //______________________________________________________________________________
01070 void RootShower::Produce()
01071 {
01072    // Produce (generate) one event.
01073 
01074    Int_t     local_num,local_last,local_end;
01075    Int_t     old_num;
01076    Bool_t    first_pass;
01077    Char_t    strtmp[80];
01078 
01079    // Check if some Event parameters have changed
01080    if ((fEvent->GetHeader()->GetDate() != fEventTime) ||
01081        (fEvent->GetHeader()->GetPrimary() != fFirstParticle) ||
01082        (fEvent->GetHeader()->GetEnergy() != fE0) ||
01083        (fEvent->GetB() != fB)) {
01084       fEventNr++;
01085       fNRun = 0;
01086    }
01087    fEvent->SetHeader(fEventNr, fNRun++, fEventTime, fFirstParticle, fE0);
01088    fEvent->Init(0, fFirstParticle, fE0, fB);
01089 
01090    fMenuFile->DisableEntry(M_FILE_SAVEAS);
01091    fMenuEvent->DisableEntry(M_SHOW_3D);
01092    fToolBar->GetButton(M_SHOW_3D)->SetState(kButtonDisabled);
01093    fToolBar->GetButton(M_FILE_SAVEAS)->SetState(kButtonDisabled);
01094    Interrupt(kFALSE);
01095    first_pass = kTRUE;
01096    old_num = -1;
01097    // loop events until user interrupt or until all particles are dead
01098    while ((!IsInterrupted()) && (fEvent->GetNAlives() > 0)) {
01099       if (first_pass && fEvent->GetTotal() > 1) {
01100          fEventListTree->OpenItem(gBaseLTI);
01101          fEventListTree->OpenItem(gLTI[0]);
01102          fEventListTree->ClearViewPort();
01103          fClient->NeedRedraw(fEventListTree);
01104          first_pass = kFALSE;
01105       }
01106       if (fEvent->GetTotal() > old_num) {
01107          sprintf(strtmp,"Simulation running, particles : %4d, please wait...",fEvent->GetTotal());
01108          old_num = fEvent->GetTotal();
01109          fStatusBar->SetText(strtmp,0);
01110          // Update display here to not slow down too much...
01111          gSystem->ProcessEvents();
01112       }
01113       local_last = fEvent->GetLast();
01114       local_num = 0;
01115       local_end = kFALSE;
01116       while ((!IsInterrupted()) && (local_end == kFALSE) && (local_num < (local_last + 1))) {
01117          // Update display here if fast machine...
01118          if (fEvent->GetParticle(local_num)->GetStatus() != DEAD) {
01119             gSystem->ProcessEvents();
01120             if (fEvent->Action(local_num) == DEAD)
01121                local_end = kTRUE;
01122             if (fEvent->GetParticle(local_num)->GetStatus() == CREATED)
01123                fEvent->GetParticle(local_num)->SetStatus(ALIVE);
01124          }
01125          local_num ++;
01126       }
01127    }
01128    fMenuEvent->EnableEntry(M_SHOW_INFOS);
01129    if (!IsInterrupted()) {
01130       fMenuEvent->EnableEntry(M_SHOW_3D);
01131       fToolBar->GetButton(M_SHOW_3D)->SetState(kButtonUp);
01132       fToolBar->GetButton(M_FILE_SAVEAS)->SetState(kButtonUp);
01133       fMenuFile->EnableEntry(M_FILE_SAVEAS);
01134    }
01135 }
01136 
01137 //______________________________________________________________________________
01138 void RootShower::OnShowerProduce()
01139 {
01140    // Initialize and generate one event.
01141 
01142    Int_t i, j, gifindex;
01143    fStatusBar->SetText("",1);
01144 
01145    SetWindowName("Root Shower Event Display");
01146 
01147    // animation logo handling
01148    if (fPicReset > 0) fPicIndex = 1;
01149    // animation timer
01150    if (!fTimer) fTimer = new TTimer(this, fPicDelay);
01151    fTimer->Reset();
01152    fTimer->TurnOn();
01153    fEventTime.Set();
01154 
01155    fIsRunning = kTRUE;
01156    fHisto_dEdX->Reset();
01157    Produce();
01158    Interrupt(kFALSE);
01159    gifindex = 0;
01160    for (i=0;i<=fEvent->GetTotal();i++) {
01161       gSystem->ProcessEvents();  // handle GUI events
01162       if (IsInterrupted()) break;
01163       // if particle has no child, represent it by a leaf,
01164       // otherwise by a branch
01165       if (fEvent->GetParticle(i)->GetChildId(0) == 0) {
01166          lpic = gClient->GetPicture("leaf_t.xpm");
01167          lspic = gClient->GetPicture("leaf_t.xpm");
01168          gLTI[i]->SetPictures(lpic, lspic);
01169       }
01170       else {
01171          bpic = gClient->GetPicture("branch_t.xpm");
01172          bspic = gClient->GetPicture("branch_t.xpm");
01173          gLTI[i]->SetPictures(bpic, bspic);
01174       }
01175       // Show only charged and massive particles...
01176       if ((fEvent->GetParticle(i)->GetPdgCode() != PHOTON) &&
01177           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_E) &&
01178           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_MUON) &&
01179           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_TAU) &&
01180           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_E) &&
01181           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_MUON) &&
01182           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_TAU) ) {
01183          // Fill histogram for particle's energy loss
01184          fHisto_dEdX->Fill(fEvent->GetParticle(i)->GetELoss());
01185          for (j=0;j<fEvent->GetParticle(i)->GetNTracks();j++)
01186             fEvent->GetParticle(i)->GetTrack(j)->Draw();
01187          // show track by track if "show process" has been choosen
01188          // into the menu
01189          if (fShowProcess) {
01190             fCA->Modified();
01191             fCA->Update();
01192             // create one gif image by step if "Animated GIF"
01193             // has been choosen into the menu
01194             if (fCreateGIFs) {
01195                fCA->SaveAs("RSEvent.gif+");
01196             }
01197          }
01198       }
01199    }
01200    AppendPad();
01201    fCA->GetView()->SetPerspective();
01202    fCA->cd();
01203    fCA->Modified();
01204    fCA->Update();
01205    fPadC->cd();
01206    // do not fit if not enough particles
01207    if (fHisto_dEdX->GetEntries() > 10) {
01208       fHisto_dEdX->Fit("landau","L");
01209       TF1 *f1 = fHisto_dEdX->GetFunction("landau");
01210       //delete fit function is fit is a non sense
01211       if (f1 && f1->GetNDF() > 0) {
01212          f1->SetLineColor(kRed);
01213          f1->SetLineWidth(1);
01214       } else {
01215          delete f1;
01216       }
01217    }
01218    fHisto_dEdX->Draw();
01219    fPadC->Modified();
01220    fPadC->Update();
01221    fCC->Update();
01222    fPadC->cd();
01223    fPadC->SetFillColor(16);
01224    fPadC->GetFrame()->SetFillColor(10);
01225    fPadC->Draw();
01226    fPadC->Update();
01227 
01228    // Open first list tree items
01229    fEventListTree->OpenItem(gBaseLTI);
01230    fEventListTree->OpenItem(gLTI[0]);
01231    fTimer->TurnOff();
01232    fIsRunning = kFALSE;
01233    if (fPicReset > 0)
01234       fTitleFrame->ChangeRightLogo(1);
01235 }
01236 
01237 //______________________________________________________________________________
01238 void RootShower::HighLight(TGListTreeItem * /*item*/)
01239 {
01240    // No comment...
01241 
01242 }
01243 
01244 //______________________________________________________________________________
01245 void RootShower::OnShowSelected(TGListTreeItem *item)
01246 {
01247    // Shows track which has been selected into the list tree
01248 
01249    Int_t i, j, retval;
01250 
01251    fCB->cd();
01252    fCB->SetFillColor(1);
01253    fCB->SetBorderMode(0);
01254    fCB->SetBorderSize(0);
01255    fCB->Clear();
01256    fCB->cd();
01257    // draw geometry
01258    gGeoManager->GetTopVolume()->Draw();
01259    fCB->GetView()->SetPerspective();
01260    fCB->cd();
01261    fCB->Update();
01262    retval = -1;
01263    for (i=0;i<=fEvent->GetTotal();i++) {
01264       if (gLTI[i] == item) {
01265          retval = i;
01266          break;
01267       }
01268    }
01269    if ((retval > -1) &&
01270        (fEvent->GetParticle(i)->GetPdgCode() != PHOTON) &&
01271        (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_E) &&
01272        (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_MUON) &&
01273        (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_TAU) &&
01274        (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_E) &&
01275        (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_MUON) &&
01276        (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_TAU) ) {
01277       for (j=0;j<fEvent->GetParticle(retval)->GetNTracks();j++)
01278          fEvent->GetParticle(retval)->GetTrack(j)->Draw();
01279    }
01280    fCB->GetView()->SetPerspective();
01281    fCB->cd();
01282    fCB->Modified();
01283    fCB->Update();
01284 }
01285 
01286 //______________________________________________________________________________
01287 void RootShower::OnOpenFile(const Char_t *filename)
01288 {
01289    // Opens a root file into which a previous event has been saved.
01290 
01291    char   strtmp[256];
01292    Int_t  i,j;
01293    TFile *f = new TFile(filename);
01294    TTree *tree;
01295    TBranch *branch;
01296    fStatusBar->SetText("",1);
01297 
01298    fEvent->Init(0, fFirstParticle, fE0, fB);
01299    fHisto_dEdX->Reset();
01300    tree = (TTree *)f->Get("RootShower");
01301    if (tree == NULL) return;
01302    branch = tree->GetBranch("Event");
01303    branch->SetAddress(&fEvent);
01304    tree->GetEntry(0, 1);
01305    f->Close();
01306 
01307    // take back detector dimensions for selection geometry
01308    gGeoManager->Import(filename, "detector");
01309    Initialize(1);
01310 
01311    for (i=0;i<=fEvent->GetTotal();i++) {
01312       gTmpLTI = fEventListTree->AddItem(gBaseLTI, fEvent->GetParticle(i)->GetName());
01313       gTmpLTI->SetUserData(fEvent->GetParticle(i));
01314       sprintf(strtmp,"%1.2f GeV",fEvent->GetParticle(i)->Energy());
01315       fEventListTree->SetToolTipItem(gTmpLTI, strtmp);
01316       gLTI[i] = gTmpLTI;
01317 
01318       if (fEvent->GetParticle(i)->GetChildId(0) == 0) {
01319          lpic = gClient->GetPicture("leaf_t.xpm");
01320          lspic = gClient->GetPicture("leaf_t.xpm");
01321          gLTI[i]->SetPictures(lpic, lspic);
01322       }
01323       else {
01324          bpic = gClient->GetPicture("branch_t.xpm");
01325          bspic = gClient->GetPicture("branch_t.xpm");
01326          gLTI[i]->SetPictures(bpic, bspic);
01327       }
01328 
01329       if ((fEvent->GetParticle(i)->GetPdgCode() != PHOTON) &&
01330           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_E) &&
01331           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_MUON) &&
01332           (fEvent->GetParticle(i)->GetPdgCode() != NEUTRINO_TAU) &&
01333           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_E) &&
01334           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_MUON) &&
01335           (fEvent->GetParticle(i)->GetPdgCode() != ANTINEUTRINO_TAU) ) {
01336          // Fill histogram for particle's energy loss
01337          fHisto_dEdX->Fill(fEvent->GetParticle(i)->GetELoss());
01338          for (j=0;j<fEvent->GetParticle(i)->GetNTracks();j++)
01339            fEvent->GetParticle(i)->GetTrack(j)->Draw();
01340       }
01341    }
01342    // Reparent each list tree item regarding the
01343    // corresponding particle relations
01344    for (i=1;i<=fEvent->GetTotal();i++) {
01345       fEventListTree->Reparent(gLTI[i],
01346             gLTI[fEvent->GetParticle(i)->GetFirstMother()]);
01347    }
01348    fEventListTree->OpenItem(gBaseLTI);
01349    fEventListTree->OpenItem(gLTI[0]);
01350    fEventListTree->ClearViewPort();
01351    fClient->NeedRedraw(fEventListTree);
01352    AppendPad();
01353 
01354    sprintf(strtmp,"Done - Total particles : %d - Waiting for next simulation",
01355                    fEvent->GetTotal());
01356    fStatusBar->SetText(strtmp,0);
01357    fPadC->cd();
01358    // do not fit if not enough particles
01359    if (fHisto_dEdX->GetEntries() > 10) {
01360       fHisto_dEdX->Fit("landau","L");
01361       TF1 *f1 = fHisto_dEdX->GetFunction("landau");
01362       //delete fit function is fit is a non sense
01363       if (f1 && f1->GetNDF() > 0) {
01364          f1->SetLineColor(kRed);
01365          f1->SetLineWidth(1);
01366       } else {
01367          delete f1;
01368       }
01369    }
01370    fHisto_dEdX->Draw();
01371    fPadC->Modified();
01372    fPadC->Update();
01373    fCC->Update();
01374    fPadC->cd();
01375    fPadC->SetFillColor(16);
01376    fPadC->GetFrame()->SetFillColor(10);
01377    fPadC->Draw();
01378    fPadC->Update();
01379 
01380    fCA->cd();
01381    fCA->Modified();
01382    fCA->Update();
01383    fMenuEvent->EnableEntry(M_SHOW_INFOS);
01384    fMenuEvent->EnableEntry(M_SHOW_3D);
01385    fToolBar->GetButton(M_SHOW_3D)->SetState(kButtonUp);
01386    fToolBar->GetButton(M_FILE_SAVEAS)->SetState(kButtonUp);
01387    fMenuFile->EnableEntry(M_FILE_SAVEAS);
01388    fButtonFrame->SetState(GButtonFrame::kAllActive);
01389    sprintf(strtmp,"Root Shower Event Display - %s",filename);
01390    SetWindowName(strtmp);
01391 }
01392 
01393 //______________________________________________________________________________
01394 void RootShower::OnSaveFile(const Char_t *filename)
01395 {
01396    // Saves current event into a Root file
01397 
01398    TFile *hfile;
01399    char  strtmp[256];
01400    gGeoManager->Export(filename, "detector");
01401    hfile = new TFile(filename,"UPDATE","Root Shower file");
01402    hfile->SetCompressionLevel(9);
01403    TTree *hTree = new TTree("RootShower","Root Shower tree");
01404    hTree->Branch("Event", "MyEvent", &fEvent, 8000, 2);
01405    hTree->Fill();  //fill the tree
01406    hTree->Write();
01407    hTree->Print();
01408    hfile->Close();
01409    sprintf(strtmp,"Root Shower Event Display - %s",filename);
01410    SetWindowName(strtmp);
01411 }
01412 
01413 //______________________________________________________________________________
01414 void RootShower::ShowInfos()
01415 {
01416    // Gives infos on current event
01417 
01418    Window_t wdummy;
01419    int ax, ay;
01420    TRootHelpDialog *hd;
01421    Char_t str[32];
01422    Char_t Msg[500];
01423    Double_t dimx,dimy,dimz;
01424 
01425    fEvent->GetDetector()->GetDimensions(&dimx, &dimy, &dimz);
01426 
01427    sprintf(Msg, "  Some information about the current shower\n");
01428    sprintf(Msg, "%s  Dimensions of the target\n", Msg);
01429    sprintf(Msg, "%s  X .................... : %1.2e [cm]    \n", Msg, dimx);
01430    sprintf(Msg, "%s  Y .................... : %1.2e [cm]    \n", Msg, dimy);
01431    sprintf(Msg, "%s  Z .................... : %1.2e [cm]    \n", Msg, dimz);
01432    sprintf(Msg, "%s  Magnetic field ....... : %1.2e [kGauss]\n", Msg,
01433            fEvent->GetB());
01434    sprintf(Msg, "%s  Initial particle ..... : %s \n", Msg,
01435            fEvent->GetParticle(0)->GetName());
01436    sprintf(Msg, "%s  Initial energy ....... : %1.2e [GeV] \n", Msg,
01437            fEvent->GetHeader()->GetEnergy());
01438    sprintf(Msg, "%s  Total Energy loss .... : %1.2e [GeV]", Msg,
01439            fEvent->GetDetector()->GetTotalELoss());
01440 
01441    sprintf(str, "Infos on current shower");
01442    hd = new TRootHelpDialog(this, str, 420, 155);
01443    hd->SetText(Msg);
01444    gVirtualX->TranslateCoordinates( GetId(), GetParent()->GetId(),
01445               (Int_t)(GetWidth() - 420) >> 1,(Int_t)(GetHeight() - 155) >> 1,
01446               ax, ay, wdummy);
01447    hd->Move(ax, ay);
01448    hd->Popup();
01449    fClient->WaitFor(hd);
01450 }
01451 
01452 //______________________________________________________________________________
01453 Bool_t RootShower::HandleKey(Event_t *event)
01454 {
01455    // Handle keyboard events.
01456 
01457    char   input[10];
01458    Int_t  n;
01459    UInt_t keysym;
01460 
01461    if (event->fType == kGKeyPress) {
01462       gVirtualX->LookupString(event, input, sizeof(input), keysym);
01463       n = strlen(input);
01464 
01465       switch ((EKeySym)keysym) {   // ignore these keys
01466          case kKey_Shift:
01467          case kKey_Control:
01468          case kKey_Meta:
01469          case kKey_Alt:
01470          case kKey_CapsLock:
01471          case kKey_NumLock:
01472          case kKey_ScrollLock:
01473             return kTRUE;
01474          case kKey_F1:
01475             SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01476                         M_HELP_SIMULATION, 0);
01477             return kTRUE;
01478          default:
01479             break;
01480       }
01481       if (event->fState & kKeyControlMask) {   // Cntrl key modifier pressed
01482          switch ((EKeySym)keysym & ~0x20) {   // treat upper and lower the same
01483             case kKey_A:
01484                SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01485                            M_FILE_SAVEAS, 0);
01486                return kTRUE;
01487             case kKey_B:
01488                SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01489                            M_INSPECT_BROWSER, 0);
01490                return kTRUE;
01491             case kKey_I:
01492                SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01493                            M_SHOW_INFOS, 0);
01494                return kTRUE;
01495             case kKey_O:
01496                SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01497                            M_FILE_OPEN, 0);
01498                return kTRUE;
01499             case kKey_Q:
01500                SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
01501                            M_FILE_EXIT, 0);
01502                return kTRUE;
01503             default:
01504                break;
01505          }
01506       }
01507    }
01508    return TGMainFrame::HandleKey(event);
01509 }
01510 
01511 //______________________________________________________________________________
01512 Bool_t RootShower::HandleTimer(TTimer *)
01513 {
01514    // Logo animation timer handling.
01515 
01516    if (fPicIndex > fPicNumber) fPicIndex = 1;
01517    fTitleFrame->ChangeRightLogo(fPicIndex);
01518    fPicIndex++;
01519    fTimer->Reset();
01520    return kTRUE;
01521 }
01522 
01523 //______________________________________________________________________________
01524 Int_t RootShower::DistancetoPrimitive(Int_t px, Int_t py)
01525 {
01526    // Compute distance from point px,py to objects in event
01527 
01528    Int_t i, j;
01529    Int_t dist = 9999;
01530 
01531    if (fEvent->GetTotal() <= 0) return 0;
01532    // Browse every track and get related particle infos.
01533    for (i=0;i<fEvent->GetTotal();i++) {
01534       for (j=0;j<fEvent->GetParticle(i)->GetNTracks();j++) {
01535          dist = fEvent->GetParticle(i)->GetTrack(j)->DistancetoPrimitive(px, py);
01536          if (dist < 2) {
01537             gPad->SetSelected((TObject*)fEvent->GetParticle(i));
01538             fStatusBar->SetText(fEvent->GetParticle(i)->GetObjectInfo(px, py),1);
01539             gPad->SetCursor(kPointer);
01540             return 0;
01541          }
01542       }
01543    }
01544    gPad->SetSelected((TObject*)gPad->GetView());
01545    return gPad->GetView()->DistancetoPrimitive(px,py);
01546 }
01547 
01548 //______________________________________________________________________________
01549 void RootShower::Clicked(TGListTreeItem *item, Int_t x, Int_t y)
01550 {
01551    // Process mouse clicks in TGListTree.
01552 
01553    MyParticle *part = (MyParticle *) item->GetUserData();
01554    if (part) {
01555       fContextMenu->Popup(x, y, part);
01556    }
01557    fEventListTree->ClearViewPort();
01558 }
01559 
01560 //______________________________________________________________________________
01561 int main(int argc, char **argv)
01562 {
01563    // Main (entry point).
01564 
01565    Bool_t rint = kFALSE;
01566    for (int i = 0; i < argc; i++) {
01567       if (!strcmp(argv[i], "-d")) rint = kTRUE;
01568       if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-?")) {
01569          printf("Usage: %s [-d] [-h | -?]\n", argv[0]);
01570          printf("  -d:     debug and inspect mode via ROOT prompt\n");
01571          printf("  -h, -?: this message\n");
01572          return 0;
01573       }
01574    }
01575 
01576    gEnv->SetValue("Gui.BackgroundColor", "#e1e2ed");
01577    gEnv->SetValue("Gui.SelectBackgroundColor", "#aaaaff");
01578    gEnv->SetValue("Gui.SelectForegroundColor", "black");
01579    
01580    TApplication *theApp;
01581    if (rint)
01582       theApp = new TRint("App", &argc, argv);
01583    else
01584       theApp = new TApplication("App", &argc, argv);
01585 
01586    gStyle->SetOptStat(1111);
01587    gStyle->SetOptFit(1111);
01588    gStyle->SetStatFont(42);
01589 
01590    gRandom->SetSeed( (UInt_t)time( NULL ) );
01591    const Int_t NRGBs = 5;
01592    Double_t Stops[NRGBs] = { 0.00, 0.50, 0.75, 0.875, 1.00 };
01593    Double_t Red[NRGBs] = { 1.00, 1.00, 1.00, 1.00, 1.00 };
01594    Double_t Green[NRGBs] = { 1.00, 0.75, 0.50, 0.25, 0.00 };
01595    Double_t Blue[NRGBs] = { 0.00, 0.00, 0.00, 0.00, 0.00 };
01596    gColIndex = TColor::CreateGradientColorTable(NRGBs, Stops, Red, Green, Blue, 17);
01597 
01598    // Create RootShower
01599    RootShower theShower(gClient->GetRoot(), 400, 200);
01600 
01601    // run ROOT application
01602    theApp->Run();
01603 
01604    // pro forma, never reached
01605    delete theApp;
01606 
01607    return 0;
01608 }

Generated on Tue Jul 5 15:15:13 2011 for ROOT_528-00b_version by  doxygen 1.5.1