/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/root/gui/EventDisplay.cpp

Go to the documentation of this file.
00001 #include <gui/EventDisplay.hh> 
00002 #include <string>
00003 
00004 
00005 #include "root/CaloRun.hh"
00006 #include "root/CaloEvent.hh"
00007 #include "root/CaloHit.hh"
00008 #include "root/MTEvent.hh"
00009 #include "root/MTChannel.hh"
00010 #include "xml/XMLTool.hh"
00011 #include "tools/Toolbox.hh"
00012 #include "Chamber.hh"
00013 #include "DiracChamber1.hh"
00014 #include "GassiplexChamber1.hh"
00015 #include "GassiplexChamber4.hh"
00016 #include "Hardroc1Chamber.hh"
00017 #include "MicroException.hh"
00018 #include "Log.hh"
00019 #include "Toolbox.hh"
00020 
00021 
00022 #include <TGResourcePool.h>
00023 #include <TView.h>
00024 #include "TExec.h"
00025 #include <TGSlider.h>
00026 #include <TG3DLine.h>
00027 #include <TGToolBar.h>
00028 
00029 
00030 
00031 
00032 #include "TGSplitter.h"
00033 #include "TGFileDialog.h"
00034 #include <TGClient.h>
00035 #include <TRootCanvas.h>
00036 #include <TGMenu.h>
00037 #include <TGStatusBar.h>
00038 #include <TGButton.h>
00039 #include <TColor.h>
00040 #include <TGLabel.h>
00041 #include <TGNumberEntry.h>
00042 
00043 #include <TROOT.h>
00044 #include <TRint.h>
00045 #include <TKey.h>
00046 #include <TCanvas.h>
00047 #include <TTree.h>
00048 #include <TFile.h>
00049 #include <TSystem.h>
00050 #include <TGeoManager.h>
00051 #include <TGeoMatrix.h>
00052  #include <RQ_OBJECT.h>
00053 #include <iostream>
00054 #include <sstream>
00055 
00056 #include <string>
00057 
00058 
00059 #include <TRootEmbeddedCanvas.h>
00060 #include <TGListBox.h>
00061 #include <TList.h>
00062 
00063 #include "TRootHelpDialog.h"
00064 
00065 
00066 #define CALOEVENT 1
00067 #define MTEVENT 2
00068 
00069 
00070 using namespace std;
00071 
00072 
00073 ClassImp(EventDisplay)
00074 
00075 std::vector<EventDisplay*> EventDisplay::frames;
00076 
00077 
00078 const char *xpm_names[] = {
00079    "open.png",
00080    "openxml.png",
00081    "",
00082    "previous.png",
00083    "next.png",
00084    "",
00085    "zoom.png",
00086    "unzoom.png",
00087    "",
00088    "colorhits.png",
00089    "onlymicromegas.png",
00090    "showchamber.png",
00091    "",
00092    "exit.png",
00093    0
00094 };
00095 
00096 
00097 enum RootShowerMessageTypes {
00098    M_FILE_EVENT_OPEN,
00099    M_FILE_XML_OPEN,
00100    M_EVENT_PREV,
00101    M_EVENT_NEXT,
00102    M_EVENT_SELECT,
00103    M_ZOOM_PLUS,
00104    M_ZOOM_MOINS,
00105    M_SHOW_CHAMBER,
00106    M_COLOR_MICROMEGAS_HIT,
00107    M_ONLY_MICROMEGAS,
00108    M_FILE_EXIT,
00109 };
00110 
00111 
00112 ToolBarData_t tb_data[] = {
00113    { "", "Open Root event file",     kFALSE, M_FILE_EVENT_OPEN,  NULL },
00114    { "", "Open XML Steer file",      kFALSE, M_FILE_XML_OPEN,    NULL },
00115    { "",              0,             0,      -1,                 NULL },
00116    { "", "Previous event",           kFALSE, M_EVENT_PREV,       NULL },
00117    { "", "Next event",               kFALSE, M_EVENT_NEXT,       NULL },
00118    { "",              0,             0,      -1,                 NULL },
00119    { "", "Zoom",                     kFALSE, M_ZOOM_PLUS,        NULL },
00120    { "", "Unzoom",                   kFALSE, M_ZOOM_MOINS,       NULL },
00121    { "",  0            ,             0,      -1,                 NULL },
00122    { "", "Use different color for micromegas hits",kFALSE, M_COLOR_MICROMEGAS_HIT,  NULL },
00123    { "", "Show only micromegas hits",kFALSE, M_ONLY_MICROMEGAS,  NULL },
00124    { "", "Show chambers",            kFALSE, M_SHOW_CHAMBER,     NULL },
00125    { "",  0            ,             0,      -1,                 NULL },
00126    { "", "Exit Application",         kFALSE, M_FILE_EXIT,        NULL },
00127    { NULL,NULL            ,          0,      0,                  NULL }
00128 };
00129 
00130 const char *dnd_types[] = {
00131    "ROOT files",    "*.root",
00132     0,               0
00133 };
00134 
00135 const char *filetypes[] = { "All files",     "*",
00136                             "ROOT files",    "*.root",
00137                             0,               0 };
00138 
00139 
00140 
00141 EventDisplay::EventDisplay(std::string &rootfileName, std::string &xmlfileName, const TGWindow *p, UInt_t w, UInt_t h)
00142    : TGMainFrame(p, w, h,kMainFrame | kVerticalFrame), eventNum(-1), steername(xmlfileName) , c1(NULL), detector(NULL),  eventType(UNDEFINED)
00143      , hitMicromegas(false), onlyMicromegas(false),drawChamber(false), world(NULL), dtHist(NULL) ,dtCan(NULL), deltaTMax(NULL), deltaTMin(NULL)
00144 {
00145   file = new TFile(rootfileName.c_str(),"READONLY");
00146   this->Init(w,h);
00147   fillTreeInfo(*file);
00148   fStatusBar->SetText(rootfileName.c_str(),1);
00149   buildDetector();
00150   frames.push_back(this);
00151 }
00152 
00153 EventDisplay::EventDisplay(std::string &rootfileName, const TGWindow *p, UInt_t w, UInt_t h)
00154    : TGMainFrame(p, w, h,kMainFrame | kVerticalFrame), eventNum(-1), c1(NULL), eventType(UNDEFINED), detector(NULL),   steername("")
00155     , hitMicromegas(false) , onlyMicromegas(false),drawChamber(false), world(NULL), dtHist(NULL) ,dtCan(NULL), deltaTMax(NULL), deltaTMin(NULL)
00156 {
00157   file = new TFile(rootfileName.c_str(),"READONLY");
00158   this->Init(w,h);
00159   fillTreeInfo(*file);
00160   fStatusBar->SetText(rootfileName.c_str(),1);
00161   frames.push_back(this);
00162 }
00163 
00164 
00165 EventDisplay::EventDisplay(const TGWindow *p, UInt_t w, UInt_t h)
00166     : TGMainFrame(p, w, h,kMainFrame | kVerticalFrame), eventNum(-1) , file(NULL), steername("") , c1(NULL) , detector(NULL)  
00167      , hitMicromegas(false), onlyMicromegas(false),drawChamber(false), world(NULL), dtHist(NULL) ,dtCan(NULL), deltaTMax(NULL), deltaTMin(NULL)
00168 {
00169   this->Init(w,h);
00170   frames.push_back(this);
00171 }
00172     
00173 void EventDisplay::Init(UInt_t width,UInt_t height)
00174 {
00175   gSystem->Load("libGeom");
00176 
00177   // construct Menu Bar
00178   fMenuBar = new TGMenuBar(this, 35, 10, kHorizontalFrame);
00179   fMenuFile = new TGPopupMenu(gClient->GetRoot());
00180 
00181   fMenuFile->AddEntry(" &Open Event file...", M_FILE_EVENT_OPEN, 0, gClient->GetPicture("bld_open.png"));
00182   fMenuFile->AddEntry(" &Open XML steer file...", M_FILE_XML_OPEN,0,gClient->GetPicture("bld_open.png"));
00183   fMenuFile->AddEntry(" &Exit ...", M_FILE_EXIT);
00184 
00185   fMenuFile->Connect("Activated(Int_t)", "EventDisplay", this,
00186                       "HandleMenu(int)");
00187 
00188   fMenuBar->AddPopup("&File", fMenuFile, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0, 4, 0, 0));
00189 
00190   this->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 5));
00191 
00192    // Create menubar and popup menus.
00193 
00194  // layout hint items
00195    TGLayoutHints *fMenuBarLayout = new TGLayoutHints(kLHintsTop| kLHintsLeft | kLHintsExpandX,
00196                                       0, 0, 0, 0);
00197    TGLayoutHints *fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00198    TGLayoutHints *fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00199 
00200    TGMenuBar *fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame | kRaisedFrame);
00201 
00202    //---- toolbar
00203    int spacing = 12;
00204    fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame | kRaisedFrame);
00205    for (int i = 0; xpm_names[i]; i++) {
00206       TString iconname(gProgPath);
00207       iconname += "/icons/";
00208       iconname += xpm_names[i];
00209       tb_data[i].fPixmap = iconname.Data();
00210       if (strlen(xpm_names[i]) == 0) {
00211          fToolBar->AddFrame(new TGVertical3DLine(fToolBar), new TGLayoutHints(kLHintsExpandY, 4, 4));
00212          continue;
00213       }
00214       const TGPicture *pic = fClient->GetPicture(tb_data[i].fPixmap);
00215       TGPictureButton *pb = new TGPictureButton(fToolBar, pic, tb_data[i].fId);
00216       pb->SetToolTipText(tb_data[i].fTipText);
00217       tb_data[i].fButton = pb;
00218 
00219       fToolBar->AddButton(this, pb, spacing);
00220    //   spacing = 0;
00221    }
00222    AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
00223    fToolBar->GetButton(M_ONLY_MICROMEGAS)->SetState(kButtonDisabled);
00224    fToolBar->GetButton(M_SHOW_CHAMBER)->SetState(kButtonDisabled);
00225    fToolBar->GetButton(M_COLOR_MICROMEGAS_HIT)->SetState(kButtonDisabled);
00226 
00227 
00228 // main frame Management
00229   this->SetMWMHints(kMWMDecorAll,
00230                 kMWMFuncAll,
00231                 kMWMInputModeless);
00232   this->MapSubwindows();
00233 
00234   this->Resize(this->GetDefaultSize());
00235   this->MapWindow();
00236   this->Resize(width,height);
00237 
00238 // Event Control
00239   // Construct event information  prev and next button
00240   TGHorizontalFrame *controls = new TGHorizontalFrame(this);
00241   AddFrame(controls, new TGLayoutHints(kLHintsExpandX));
00242 
00243   TGLabel *fLbEvent = new TGLabel(controls, "Event number");
00244   LbEventNum = new TGNumberEntryField(controls);
00245   LbEventNum->SetIntNumber(-1);
00246 
00247   controls->AddFrame(fLbEvent, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 2, 2, 2));
00248   controls->AddFrame(LbEventNum, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 5, 2, 2, 2));
00249   LbEventNum->Connect(" ReturnPressed()", "EventDisplay", this, "SetEventNum()");
00250   
00251 // DeltaT Control
00252   ULong_t ucolor;        // will reflect user color changes
00253   gClient->GetColorByName("#ccccff",ucolor);
00254 
00255   // horizontal frame
00256   TGVerticalFrame *dtFrame = new TGVerticalFrame(this,240,120,kVerticalFrame | kSunkenFrame | kRaisedFrame ,ucolor);
00257   this->AddFrame(dtFrame, new TGLayoutHints(kLHintsExpandX ));
00258   
00259 
00260   TGLabel *deltaTLabel = new TGLabel(dtFrame, "DeltaT");
00261   deltaTLabel->SetBackgroundColor(ucolor);
00262   deltaTLabel->SetForegroundColor(kBlack);
00263   dtFrame->AddFrame(deltaTLabel, new TGLayoutHints(kLHintsCenterX));
00264 
00265 
00266   TGHorizontalFrame *dtBottomFrame = new TGHorizontalFrame(dtFrame,1,1,kHorizontalFrame| kSunkenFrame ,ucolor);
00267   dtFrame->AddFrame(dtBottomFrame, new TGLayoutHints(kLHintsExpandX));
00268 
00269   slider = new TGDoubleHSlider(dtBottomFrame, 200, kScaleNo, 10,
00270                                    kHorizontalFrame,
00271                                    GetDefaultFrameBackground(),
00272                                    kFALSE, kFALSE);
00273   slider->SetBackgroundColor(ucolor);
00274   slider->Connect("PositionChanged()", "EventDisplay",
00275                       this, "DoSlider()");
00276 
00277   slider->Connect("Released()", "EventDisplay",
00278                       this, "SliderReleased()");
00279 
00280   slider->SetRange(0,1);
00281   slider->SetPosition(0,1);
00282 
00283 
00284   deltaTMin = new TGNumberEntryField(dtBottomFrame);
00285   deltaTMin-> SetBackgroundColor(ucolor);
00286   deltaTMin-> SetForegroundColor(kBlack);
00287   deltaTMin->SetState(true);
00288   deltaTMin->Connect(" ReturnPressed()", "EventDisplay", this, "SetSliderRange()");
00289 
00290 
00291   dtBottomFrame->AddFrame(deltaTMin, new TGLayoutHints(kLHintsLeft));
00292   dtBottomFrame->AddFrame(slider, new TGLayoutHints(kLHintsExpandX));
00293 
00294 
00295   deltaTMax = new TGNumberEntryField(dtBottomFrame);
00296   deltaTMax-> SetBackgroundColor(ucolor);
00297   deltaTMax-> SetForegroundColor(kBlack);
00298   deltaTMax->Connect(" ReturnPressed()", "EventDisplay", this, "SetSliderRange()");
00299 
00300   dtBottomFrame->AddFrame(deltaTMax, new TGLayoutHints(kLHintsRight));
00301   deltaTMax->SetState(true);
00302 
00303 
00304   TGLabel *fooLabel = new TGLabel(dtFrame, "    ");
00305   fooLabel->SetBackgroundColor(ucolor);
00306   fooLabel->SetForegroundColor(kBlack);
00307   dtFrame->AddFrame(fooLabel, new TGLayoutHints(kLHintsCenterX));
00308 
00309 
00310 
00311   // EventDisplay
00312   // Display Option Frame
00313   mainFrame = new TGVerticalFrame(this,240,120,kHorizontalFrame | kSunkenFrame | kRaisedFrame );
00314   this->AddFrame(mainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kSunkenFrame | kRaisedFrame));
00315 
00316   TGCompositeFrame *canvasZone = new TGCompositeFrame(mainFrame,1,1, kHorizontalFrame | kRaisedFrame);
00317 
00318 
00319   TGHorizontalFrame *fV1 = new TGHorizontalFrame(canvasZone, 800, 1  ,kSunkenFrame | kFixedWidth );
00320   TGHorizontalFrame *fV2 = new TGHorizontalFrame(canvasZone, 1, 1,kSunkenFrame);
00321 
00322 
00323   canvasZone->AddFrame(fV1,  new TGLayoutHints( kLHintsLeft   | kLHintsExpandY,2,0,2,2));
00324 
00325   TGVSplitter *splitter = new TGVSplitter(canvasZone, 10);
00326   splitter->SetFrame(fV1, kTRUE);
00327   canvasZone->AddFrame(splitter,  new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 0, 0 ,0, 0));
00328   canvasZone->AddFrame(fV2,  new TGLayoutHints( kLHintsRight | kLHintsExpandX  |kLHintsExpandY,0,2,2,2));
00329 
00330 
00331   // 3D View
00332   gCanvas = new TGCanvas(fV2,1,1); 
00333   TGViewPort *viewPort = gCanvas->GetViewPort();
00334 
00335   TGCompositeFrame *compositeFrame = new TGCompositeFrame(viewPort,1,1 );
00336 
00337   TRootEmbeddedCanvas *rootEmbeddedCanvas = new TRootEmbeddedCanvas(0,compositeFrame,1100,900);
00338   c1 = rootEmbeddedCanvas->GetCanvas();
00339 
00340   gCanvas->SetContainer(compositeFrame);
00341 
00342   c1->SetFillColor(kBlack);
00343   compositeFrame->AddFrame(rootEmbeddedCanvas, new TGLayoutHints( kLHintsExpandX ));
00344 
00345   viewPort->AddFrame(compositeFrame);
00346   fV2->AddFrame(gCanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,0,0,0,0));
00347   //fV2->AddFrame(gCanvas);
00348 
00349   // DT Histogram
00350   TGCompositeFrame *compositeFrameDt = new TGCompositeFrame(fV1,1,1 );
00351 
00352   TRootEmbeddedCanvas *embeddedCanvasDt = new TRootEmbeddedCanvas(0,compositeFrameDt,800,600);
00353   dtCan = embeddedCanvasDt->GetCanvas();
00354 
00355   compositeFrameDt->AddFrame(embeddedCanvasDt, new TGLayoutHints(kLHintsExpandX ));
00356   fV1->AddFrame(compositeFrameDt, new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX | kLHintsExpandY ,0,0,0,0));
00357 
00358   mainFrame->AddFrame(canvasZone, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00359 
00360 
00361 
00362  // Create status bar
00363    Int_t parts[] = {25, 60,15};
00364    fStatusBar = new TGStatusBar(this, 50, 10, kHorizontalFrame);
00365    fStatusBar->SetParts(parts, 3);
00366    this->AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom| kLHintsExpandX, 0, 0, 0, 0));
00367    fStatusBar->SetText("Waiting to read event ...",0);
00368 
00369   MapSubwindows();
00370   SetWindowName("Micromegas LAPP Event Viewer");
00371   SetIconName("Micromegas LAPP Event Viewer");
00372   Layout();
00373   MapWindow();
00374   
00375 
00376 }
00377 
00378 EventDisplay::~EventDisplay()
00379 {
00380 }
00381 
00382 
00383 
00384 //______________________________________________________________________________
00385 void EventDisplay::SliderReleased()
00386 {
00387  this->Display(true);
00388 }
00389 //______________________________________________________________________________
00390 void EventDisplay::DoSlider()
00391 {
00392  deltaTMin->SetNumber(slider->GetMinPosition());
00393 
00394  deltaTMax->SetNumber(slider->GetMaxPosition());
00395 }
00396 //______________________________________________________________________________
00397 void EventDisplay::SetSliderRange()
00398 {
00399     if ( deltaTMin->GetIntNumber() < 0 ) { deltaTMin->SetNumber(0 ); }
00400     else if ( deltaTMax->GetIntNumber() < 0 ) { deltaTMax->SetNumber(0 ); }
00401     slider->SetPosition(deltaTMin->GetIntNumber(),deltaTMax->GetIntNumber());
00402     this->Display(true);
00403 }
00404 //______________________________________________________________________________
00405 void EventDisplay::UnZoom()
00406 {
00407 
00408   c1->cd();
00409   c1->GetView()->UnzoomView(0, 1.25);
00410   c1->Modified();
00411   c1->Update();
00412 
00413 }
00414 //______________________________________________________________________________
00415 void EventDisplay::Zoom()
00416 {
00417   c1->cd();
00418   c1->GetView()->ZoomView(0, 1.25);
00419   c1->Modified();
00420   c1->Update();
00421   
00422 }
00423 //______________________________________________________________________________
00424 void EventDisplay::SetEventNum()
00425 {
00426   if ( file == NULL ) { return ; }
00427   if ( LbEventNum->GetIntNumber() >= 0)
00428   {
00429     eventNum = LbEventNum->GetIntNumber();
00430     adjustSlider();
00431     this->Display(true);
00432   }
00433 }
00434 
00435 //______________________________________________________________________________
00436 void EventDisplay::ShowChamberClick()
00437 {
00438     gSystem->ProcessEvents();
00439     this->Display(true);
00440 }
00441 
00442 //______________________________________________________________________________
00443 void EventDisplay::PrevEvent()
00444 {
00445   if ( file == NULL ) { return ; }
00446   if ( eventNum == 0 ) eventNum = 1; 
00447   eventNum--;
00448 
00449   LbEventNum->SetIntNumber(eventNum);
00450   adjustSlider();
00451   this->Display(true);
00452 }
00453 
00454 //______________________________________________________________________________
00455 void EventDisplay::NextEvent()
00456 {
00457   if ( file == NULL ) { return ; }
00458   eventNum++;
00459   LbEventNum->SetIntNumber(eventNum);
00460   adjustSlider();
00461   this->Display(true);
00462 }
00463 
00464 //______________________________________________________________________________
00465 void EventDisplay::adjustSlider()
00466 {
00467   UInt_t min = 0;
00468   UInt_t max = 0xffffffff;
00469   slider->SetRange(min, max);
00470   deltaTMin->SetNumber(min);
00471 
00472   deltaTMax->SetNumber(max);
00473   slider->SetPosition(min,max);
00474   TTree *tree =  NULL;
00475   TBranch *branch= NULL;
00476   Int_t nbEvent = 0;
00477 
00478 
00479   TreeInfo_t* info = getTreeInfo(eventNum);
00480   
00481   if ( info->type == CALOEVENT )
00482   {
00483     CaloEvent* caloEvt = new CaloEvent();
00484     tree = info->tree;
00485     branch= tree->GetBranch("CaloEvent");
00486     branch->SetAddress(&caloEvt);
00487     tree->GetEntry(this->eventNum-info->min);
00488 
00489     Int_t NC=caloEvt->GetNHits();
00490     UInt_t min = 0xffffffff;
00491     UInt_t max = 0;
00492 
00493     for(int i=0;i<NC  ;i++)
00494     {
00495       CaloHit* caloChannel = (CaloHit*)caloEvt->GetHits()->UncheckedAt(i);
00496       UInt_t dt= caloChannel->GetDeltaT();
00497       if ( dt < min ) { min = dt; }
00498       if ( dt > max ) { max = dt; }
00499     }
00500 
00501     slider->SetRange(min, max);
00502     deltaTMin->SetNumber(min);
00503 
00504     deltaTMax->SetNumber(max);
00505     slider->SetPosition(min-1,max+1);
00506     delete caloEvt;
00507   }
00508   else
00509   {
00510     MTEvent* mtEvt = new MTEvent();
00511     tree = info->tree;
00512     branch= tree->GetBranch("MTEvent");
00513     branch->SetAddress(&mtEvt);
00514     tree->GetEntry(this->eventNum-info->min);
00515 
00516     Int_t NC=mtEvt->GetNchannel();
00517     UInt_t min = 0xffffffff;
00518     UInt_t max = 0;
00519 
00520     for(int i=0;i<NC  ;i++)
00521     {
00522       MTChannel* caloChannel = (MTChannel*)mtEvt->GetChannels()->UncheckedAt(i);
00523       UInt_t t2 = caloChannel->GetBcIdDif();
00524       UInt_t t3 = caloChannel->GetBcIdHit();
00525       UInt_t dt = t2 - t3;
00526 
00527       
00528       if ( dt < min ) { min = dt; }
00529       if ( dt > max ) { max = dt; }
00530     }
00531 
00532     slider->SetRange(min, max);
00533     deltaTMin->SetNumber(min);
00534     deltaTMax->SetNumber(max);
00535     slider->SetPosition(min,max); 
00536    
00537 
00538     delete mtEvt;
00539   }
00540 }
00541 
00542 
00543 
00544 //______________________________________________________________________________
00545 
00546 Bool_t EventDisplay::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
00547 
00548 {
00549    Window_t wdummy;
00550    int ax, ay;
00551    TRootHelpDialog *hd;
00552    //TGListTreeItem *item;
00553    TGFileInfo fi;
00554    Char_t  strtmp[250];
00555 
00556     // Process events generated by the buttons in the frame.
00557     switch (GET_MSG(msg)) {
00558 
00559         case kC_COMMAND:
00560 
00561             switch (GET_SUBMSG(msg)) {
00562               case kCM_BUTTON:
00563                   switch (parm1) {
00564                   
00565                   case   M_FILE_EVENT_OPEN:
00566                     OpenFile();
00567                   break;
00568                   case   M_FILE_XML_OPEN:
00569                     OpenXMLFile();
00570                   break;
00571                   case   M_EVENT_PREV:
00572                     PrevEvent();
00573                   break;
00574                   case   M_EVENT_NEXT:
00575                     NextEvent();
00576                   break;
00577                   case   M_EVENT_SELECT:
00578                   SetEventNum();
00579                   break;
00580                   case   M_ZOOM_PLUS:
00581                     Zoom();
00582                   break;
00583                   case   M_ZOOM_MOINS:
00584                     UnZoom();
00585                   break;
00586                   case   M_SHOW_CHAMBER:
00587                      drawChamber = !drawChamber;
00588                      fToolBar->GetButton(M_SHOW_CHAMBER)->SetDown(drawChamber);
00589                      ShowChamberClick();
00590                   break;
00591                   case   M_COLOR_MICROMEGAS_HIT:
00592                     hitMicromegas = !hitMicromegas; 
00593                     fToolBar->GetButton(M_COLOR_MICROMEGAS_HIT)->SetDown(hitMicromegas);
00594                     ShowChamberClick();
00595                   break;
00596                   case   M_ONLY_MICROMEGAS:
00597                     onlyMicromegas = !onlyMicromegas; 
00598                     fToolBar->GetButton(M_ONLY_MICROMEGAS)->SetDown(onlyMicromegas);
00599                     ShowChamberClick();
00600                   break;
00601                   case   M_FILE_EXIT:
00602                     CloseWindow();
00603                   break;
00604                   }
00605                      break;
00606 
00607 
00608                 default:
00609                     break;
00610             }
00611         default:
00612             break;
00613     }
00614     return kTRUE;
00615 }
00616 
00617 
00618 
00619 //______________________________________________________________________________
00620 void EventDisplay::Display( bool updateDt)
00621 {
00622   if ( file == NULL ) { return ; }
00623   if ( file->IsZombie()) {
00624     exit(-1);
00625   }
00626 
00627   if ( world ) { world->ClearNodes(); }
00628   frame =new TGeoManager("Frame","mM event displayer");
00629   mat = new TGeoMaterial("SomeMaterial",1,1,1);
00630   med = new TGeoMedium("SomeMedium",1,mat);
00631   world = frame->MakeBox("World", med, 1, 1, 1); // x, y , z size unit cm
00632 
00633 
00634   
00635 
00636   if (detector != NULL &&  drawChamber &&  steername.compare("") != 0)
00637   {
00638     ChamberMap_t chambers = detector->getChambers();
00639     for ( ChamberMap_t::const_iterator iter = chambers.begin(); iter!=chambers.end(); iter++)
00640     {
00641       Chamber *chamber = (*iter).second;
00642       TGeoVolume *pad = frame->MakeBox("1" ,med,chamber->getYLength(),chamber->getXLength(),9600 );
00643       unsigned int color = 17;
00644 
00645       if ( chamber->getType().find("MICROROC")  != string::npos )
00646       { color = 7 ; }
00647         
00648       world->AddNode(pad,1,new TGeoTranslation(chamber->getX(),chamber->getY(),chamber->getZ()));
00649       pad->SetLineColor(color);
00650     }
00651   }
00652   
00653     TreeInfo_t* info = getTreeInfo(eventNum);
00654     if ( info != NULL ) 
00655     {
00656       if ( info->type == CALOEVENT ) 
00657       {
00658         this->DisplayCaloEvent(updateDt);
00659       }
00660       else if  ( info->type == MTEVENT )  
00661       {
00662         this->DisplayMTEvent(updateDt);
00663       }
00664     }
00665 }
00666 
00667 //__________________________________________________________________________________________________________________
00668 void EventDisplay::DisplayCaloEvent(bool updateDT)
00669 {
00670   if ( updateDT )
00671   {
00672     if ( dtHist != NULL ) { delete dtHist ;}
00673     dtHist = new TH1I("dt", "dt", deltaTMax->GetNumber()-deltaTMin->GetNumber()+2, deltaTMin->GetNumber()-1,deltaTMax->GetNumber()+1);
00674     TExec *ex = new TExec("ex","EventDisplay::zoomC1()");
00675     dtHist->GetListOfFunctions()->Add(ex);
00676   }
00677 
00678   CaloEvent *caloEvt = NULL;
00679  // TKey *key;
00680   int padNumber = 0;
00681   UInt_t curEvent = 0;
00682 
00683   TTree *tree =  NULL;
00684   TBranch *branch= NULL;
00685   Int_t nbEvent = 0;
00686 
00687   caloEvt = new CaloEvent();
00688   TreeInfo_t* info = getTreeInfo(eventNum);
00689   if ( info != NULL )
00690   {
00691     tree = info->tree;
00692     branch= tree->GetBranch("CaloEvent");
00693     branch->SetAddress(&caloEvt);
00694   }
00695   else { return; }
00696     
00697     
00698   tree->GetEntry(this->eventNum-info->min);
00699   string foo = "EventId ";
00700   Toolbox::addIntToString(foo, this->eventNum-info->min);
00701   fStatusBar->SetText(foo.c_str(),2);
00702 
00703   Int_t NC=caloEvt->GetNHits();
00704   frame->SetMaxVisNodes(NC+100);
00705 
00706   float x,y,z;
00707   UInt_t drawHits = 0;
00708   for(int i=0;i<NC  ;i++)
00709   {
00710     if ( padNumber < 169300)
00711     {
00712       CaloHit* caloChannel = NULL;
00713       //the only known way to get the information from the channels number i
00714       caloChannel = (CaloHit*)caloEvt->GetHits()->UncheckedAt(i);
00715   
00716     
00717       Int_t dt= caloChannel->GetDeltaT();
00718 
00719       bool chamberMicromegas = false;
00720 
00721       
00722 
00723       if (onlyMicromegas && !this->IsMicromegas(caloChannel->GetLayer())  )  {continue;}
00724       if (  dt < deltaTMin->GetNumber() || dt> deltaTMax->GetNumber() )
00725       { 
00726         continue; 
00727         
00728       }
00729     
00730       drawHits++;
00731  
00732       if ( updateDT ) dtHist->Fill(dt);
00733       float xLength = 9600 ;  //micron 
00734       float yLength = 9600 ;  //micron
00735       float zLength = 2000;     //micron
00736       // ChannelPad name
00737       string padID="";
00738       stringstream currentpad;// (stringstream::in | stringstream::out);
00739       padNumber++;
00740       currentpad<<padNumber;
00741       padID="pad_"+currentpad.str();
00742 
00743       TGeoVolume *pad = frame->MakeBox(padID.c_str(),med,yLength/2,xLength/2,zLength/2 );
00744       x=caloChannel->GetX();//*10000 ;
00745       y=caloChannel->GetY();//*10000 ;
00746       z=caloChannel->GetZ();//*10000 ;
00747       //set now the color of the pad
00748       int color;
00749       int colors[3] = {kBlue,kGreen,kRed};
00750       if ( hitMicromegas && !this->IsMicromegas(caloChannel->GetLayer()))
00751       {   
00752         colors[0] = 31; 
00753         colors[1] = 41; 
00754         colors[2] = 44; }
00755       stringstream ch;
00756       ch<<i;
00757 
00758       color = colors[caloChannel->GetThreshold()-1];
00759 
00760       ostringstream ox,oy,oz;
00761       ox << x; oy << y; oz <<z ;
00762       {
00763         world->AddNode(pad,1,new TGeoTranslation(x,y,z));
00764       }
00765       pad->SetLineColor(color);
00766       pad->SetFillColor(color);
00767       pad->SetFillStyle(4100);
00768       Char_t  strtmp[250];
00769       sprintf(strtmp,"Hits reading : %4d, please wait...",i);
00770       // Update display here to not slow down too much...
00771       gSystem->ProcessEvents();
00772       fStatusBar->SetText(strtmp,0);
00773 
00774     }
00775     else
00776     {
00777       break;
00778     }
00779   }
00780   string str = "Done: "; 
00781   Toolbox::addIntToString(str, drawHits);
00782   str = str + "  hits / " ;
00783   Toolbox::addIntToString(str, caloEvt->GetNHits());
00784   fStatusBar->SetText(str.c_str(),0);
00785 
00786 
00787   frame->SetTopVolume(world);
00788   
00789   frame->CloseGeometry();
00790   dtCan->cd();
00791   if ( updateDT ) dtHist->Draw();
00792   c1->cd();
00793   world->Draw();
00794   c1->Update();
00795   if ( updateDT &&  dtCan ) dtCan->Update();
00796   delete caloEvt;
00797 
00798 }
00799 //______________________________________________________________________________________________________________________________________
00800 void EventDisplay::DisplayMTEvent(bool updateDT)
00801 {
00802   if ( updateDT )
00803   {
00804     if ( dtHist != NULL ) { delete dtHist; }
00805     dtHist = new TH1I("dt", "dt", deltaTMax->GetNumber()-deltaTMin->GetNumber()+2, deltaTMin->GetNumber()-1,deltaTMax->GetNumber()+1);
00806 
00807     TExec *ex = new TExec("ex","EventDisplay::zoomC1()");
00808     dtHist->GetListOfFunctions()->Add(ex);
00809   }
00810 
00811 
00812   MTEvent *mtEvt = NULL;
00813   int padNumber = 0;
00814   UInt_t curEvent = 0;
00815 
00816   TTree *tree =  NULL;
00817   TBranch *branch= NULL;
00818   Int_t nbEvent = 0;
00819 
00820   mtEvt = new MTEvent();
00821   TreeInfo_t* info = getTreeInfo(eventNum);
00822   if ( info != NULL )
00823   {
00824     tree = info->tree;
00825     branch= tree->GetBranch("MTEvent");
00826     branch->SetAddress(&mtEvt);
00827   }
00828   else { return; }
00829 
00830   tree->GetEntry(this->eventNum-info->min);
00831 
00832   Int_t NC = mtEvt->GetNchannel();
00833   //NC = 3000;
00834   frame->SetMaxVisNodes(NC+100);
00835 
00836   UInt_t minSlider = deltaTMin->GetNumber();
00837   UInt_t maxSlider = deltaTMax->GetNumber();
00838 
00839 
00840   map<string,TGeoVolume*> pads;
00841   map<string,int> padsDigitalValue;
00842   float x,y,z;
00843   TGeoTranslation *tr = NULL;
00844   UInt_t  drawHits = 0;
00845   for(int i=0;i<NC  ;i++)
00846   {
00847     //if ( padNumber < 169300)
00848     {
00849       MTChannel* mtChannel=NULL;
00850       //the only known way to get the information from the channels number i
00851       mtChannel = (MTChannel*)mtEvt->GetChannels()->UncheckedAt(i);
00852       
00853       UInt_t t2 = mtChannel->GetBcIdDif();
00854       UInt_t t3 = mtChannel->GetBcIdHit();
00855       UInt_t dt = t2 - t3;
00856       if (onlyMicromegas && !this->IsMicromegas(mtChannel->GetChamberId())  )  {continue;}
00857       if (  dt < minSlider || dt > maxSlider ) {  continue; }
00858       drawHits++;
00859 
00860       if ( updateDT ) dtHist->Fill(dt);
00861       float xLength = 9600 ;  //micron 
00862       float yLength = 9600 ;  //micron
00863       float zLength = 2000;   //micron
00864       // ChannelPad name
00865       string padID="";
00866       stringstream currentpad;// (stringstream::in | stringstream::out);
00867       padNumber++;
00868       currentpad<<padNumber;
00869       padID="pad_"+currentpad.str();
00870 
00871       x=mtChannel->GetX();//*10000 ;
00872       y=mtChannel->GetY();//*10000 ;
00873       z=mtChannel->GetZ();//*10000 ;
00874 
00875       ostringstream ox,oy,oz;
00876       ox << x; oy << y; oz <<z ;
00877       string key = "x[" + ox.str() + "]y[" + oy.str() + "]z[" + oz.str() +"]" ;
00878       TGeoVolume *pad = NULL;
00879 
00880       int color;
00881       int colors[3] = {kBlue,kGreen,kRed};
00882       if ( hitMicromegas && !this->IsMicromegas(mtChannel->GetChamberId()))
00883       { colors[0] = colors[1] = colors[2] = kGray; }
00884 
00885       if ( pads.find(key) == pads.end())
00886       {
00887          pad = frame->MakeBox(padID.c_str(),med,yLength/2,xLength/2,zLength/2 );
00888          pads.insert(make_pair(key,pad));
00889          tr = new TGeoTranslation(x,y,z);
00890          world->AddNode(pad,1,tr);
00891          //set now the color of the pad
00892          
00893       //   padsDigitalValue.insert(make_pair(key,colors[mtChannel->GetDigitalValue()-1]));
00894          padsDigitalValue.insert(make_pair(key,mtChannel->GetDigitalValue()-1));
00895 
00896          color = colors[mtChannel->GetDigitalValue()-1];
00897 
00898       }
00899       else {
00900         pad = pads.find(key)->second ;
00901         int oldDigitalValue = padsDigitalValue.find(key)->second;
00902         int digitalValue = 0;
00903         if ( mtChannel->GetDigitalValue() > oldDigitalValue )
00904         {
00905           digitalValue =  mtChannel->GetDigitalValue() ;
00906         }
00907         else
00908         {
00909           digitalValue = oldDigitalValue;
00910         }
00911         color = colors[digitalValue-1]; 
00912       }
00913 
00914 
00915         Char_t  strtmp[250];
00916         sprintf(strtmp,"Hits reading : %4d, please wait...",i);
00917         fStatusBar->SetText(strtmp,0);
00918         // Update display here to not slow down too much...
00919         gSystem->ProcessEvents();
00920 
00921 
00922 
00923         stringstream ch;
00924         ch<<i;
00925 
00926         if ( pad ) 
00927         {
00928           pad->SetLineColor(color);
00929           pad->SetFillColor(color);
00930           pad->SetFillStyle(4100);
00931         }
00932         else { cout << "Pad not found[" << key << "]" << endl; return ; }
00933     }
00934   }
00935   cout << " number of pad["<< padNumber <<  "]" << endl;
00936   
00937   string str = "Done: ";
00938   Toolbox::addIntToString(str, drawHits);
00939   str = str + "  hits / " ;
00940   Toolbox::addIntToString(str, mtEvt->GetNchannel());
00941   fStatusBar->SetText(str.c_str(),0);
00942 
00943 
00944 
00945 
00946   frame->SetTopVolume(world);
00947 
00948   if ( !frame->IsClosed() ) frame->CloseGeometry();
00949   dtCan->cd();
00950   if ( updateDT ) dtHist->Draw();
00951   c1->cd();
00952   world->Draw();
00953   if ( updateDT ) dtCan->Update();
00954   c1->Update();
00955   
00956   delete mtEvt;
00957 }
00958 
00959 //______________________________________________________________________________
00960 void EventDisplay::HandleMenu(int menu_id)
00961 {
00962    // Handle menu events.
00963 
00964    switch (menu_id) {
00965       case M_FILE_EXIT:
00966          // close the window and quit application
00967         CloseWindow();
00968          gApplication->Terminate(0);
00969          break;
00970       case M_FILE_EVENT_OPEN:
00971         OpenFile();
00972         break;
00973       case M_FILE_XML_OPEN:
00974         OpenXMLFile();
00975         break;
00976    }
00977 }
00978 
00979 //______________________________________________________________________________
00980 void EventDisplay::fillTreeInfo(const TFile &file)
00981 {
00982   treeInfos.clear();
00983   
00984   TIter nextkey(file.GetListOfKeys());
00985   TKey *key;
00986   UInt_t nbEvent = 0;
00987   while (key = (TKey*)nextkey()) 
00988   {
00989     TreeInfo_t *foo = new TreeInfo_t();
00990 
00991     TTree *tree = (TTree*)key->ReadObj();
00992     foo->min=nbEvent;
00993     foo->max=foo->min+tree->GetEntries()-1;
00994     nbEvent = foo->max+1;
00995     foo->tree = tree;
00996     if ( tree->FindBranch("CaloEvent")!= NULL)
00997     {
00998       foo->type = CALOEVENT;
00999     }
01000     else if ( tree->FindBranch("MTEvent")!= NULL)
01001     {
01002       foo->type = MTEVENT;
01003     }
01004 
01005     treeInfos.push_back(foo);
01006   }
01007 
01008 }
01009  
01010 //______________________________________________________________________________
01011 TreeInfo_t* EventDisplay::getTreeInfo(UInt_t eventNum)
01012 {
01013   
01014   
01015   std::vector<TreeInfo_t*>::const_iterator iter;
01016 
01017   for( iter = treeInfos.begin(); iter != treeInfos.end(); iter++)
01018   {
01019     TreeInfo_t* info= *iter;
01020     if ( eventNum >= info->min && eventNum <= info->max )
01021     {
01022       return info;
01023     }
01024   }
01025   return NULL;
01026 }
01027 
01028 //______________________________________________________________________________
01029 bool EventDisplay::IsMicromegas(UInt_t chamberId)
01030 {
01031     Chamber *chamber = NULL;
01032     if ( detector != NULL )
01033     {
01034       chamber = &(detector->getChamberById(chamberId));
01035       if ( chamber != NULL  )
01036       {
01037          if ( chamber->getType().find("MICROROC")  != string::npos )
01038         {
01039             return true;
01040         }
01041       }
01042     }
01043   return false;
01044 }
01045 
01046 
01047 //______________________________________________________________________________
01048 bool EventDisplay::buildDetector()
01049 {
01050   if (steername.compare("") !=0 )
01051   {
01052     XMLTool xml;
01053     SteerDesc steerDesc;
01054     xml.parse(steerDesc, steername); // parse steer file and fill steerDesc
01055     detector = new Detector();
01056 
01057     UInt_t nbChamber= detector->build(steerDesc);
01058 
01059     if ( nbChamber == 0 || nbChamber!= steerDesc.chambers.size() )
01060     {
01061        fToolBar->GetButton(M_ONLY_MICROMEGAS)->SetState(kButtonDisabled);
01062        fToolBar->GetButton(M_SHOW_CHAMBER)->SetState(kButtonDisabled);
01063        fToolBar->GetButton(M_COLOR_MICROMEGAS_HIT)->SetState(kButtonDisabled);
01064       return false;
01065     }
01066     fToolBar->GetButton(M_ONLY_MICROMEGAS)->SetState(kButtonUp);
01067     fToolBar->GetButton(M_SHOW_CHAMBER)->SetState(kButtonUp);
01068     fToolBar->GetButton(M_COLOR_MICROMEGAS_HIT)->SetState(kButtonUp);
01069   }
01070 
01071 return true;
01072 }
01073 
01074 
01075 //______________________________________________________________________________
01076 void EventDisplay::OpenFile()
01077 {
01078    TRootHelpDialog *hd;
01079    static TString dir(".");
01080    TGFileInfo fi;
01081    fi.fFileTypes = dnd_types;
01082    fi.fIniDir    = StrDup(dir);
01083 
01084          fi.fFileTypes = filetypes;
01085            new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
01086            if ( fi.fFilename != NULL )
01087            {
01088             string *full;
01089             full  = new string(fi.fFilename);
01090             if ( file != NULL )
01091             {
01092               std::vector<TreeInfo_t*>::const_iterator iter;
01093               for( iter = treeInfos.begin(); iter != treeInfos.end(); iter++)
01094               {
01095                 TreeInfo_t* info= *iter;
01096                 {
01097                   delete info;
01098                 }
01099               }
01100               treeInfos.clear();
01101               delete dtHist;
01102               dtHist = NULL;
01103               file->Close();
01104               delete file;
01105               eventNum = 0;
01106               LbEventNum->SetIntNumber(eventNum);
01107             }
01108 
01109 
01110             file = new TFile(full->c_str(),"READONLY");
01111             fStatusBar->SetText(full->c_str(),1);
01112             fillTreeInfo(*file);
01113         }
01114 
01115  }
01116 
01117 //______________________________________________________________________________
01118 void EventDisplay::OpenXMLFile()
01119 {
01120    TRootHelpDialog *hd;
01121    static TString dir(".");
01122    TGFileInfo fi;
01123    fi.fFileTypes = dnd_types;
01124    fi.fIniDir    = StrDup(dir);
01125            fi.fFileTypes = filetypes;
01126            new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &fi);
01127            if ( fi.fFilename != NULL )
01128             {
01129               steername  = fi.fFilename;
01130               buildDetector();
01131             }
01132 }
01133 
01134 //______________________________________________________________________________
01135 Bool_t EventDisplay::HandleConfigureNotify(Event_t *event)
01136 {
01137    // This event is generated when the frame is resized.
01138 
01139    TGFrame* f = (TGFrame*)this;
01140    if ((event->fWidth != f->GetWidth()) || (event->fHeight != f->GetHeight())) {
01141       UInt_t w = event->fWidth;
01142       UInt_t h = event->fHeight;
01143       f->Resize(w,h);
01144       f->Layout();
01145    }
01146    return kTRUE;
01147 }
01148 
01149 
01150 //______________________________________________________________________________
01151 void EventDisplay::processZoom(void)
01152 {
01153 
01154   if ( deltaTMin->GetNumber() != dtCan->GetUxmin() || deltaTMax->GetNumber() != dtCan->GetUxmax() )
01155   { 
01156     
01157     if ( dtCan->GetUxmin() < 0 )
01158     {
01159       deltaTMin->SetNumber(0);
01160     }
01161     else
01162     {
01163       deltaTMin->SetNumber(dtCan->GetUxmin());
01164     }
01165 
01166     deltaTMax->SetNumber(dtCan->GetUxmax());
01167     this->Display(false);
01168   }
01169 }
01170 
01171 //______________________________________________________________________________
01172 void EventDisplay::zoomC1(void)
01173 {
01174 
01175   for ( std::vector<EventDisplay*>::const_iterator iter = frames.begin() ; iter != frames.end(); iter++)
01176   {
01177     
01178     (*iter)->processZoom();
01179   }
01180 }
01181 

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7