Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • display/DelphesEventDisplay.cc

    r341014c rf53a4d2  
    1717 */
    1818
    19 #include <algorithm>
    2019#include <cassert>
    2120#include <iostream>
    2221#include <utility>
    23 
    24 #include "TAxis.h"
    25 #include "TCanvas.h"
    26 #include "TChain.h"
    27 #include "TClonesArray.h"
    28 #include "TEveArrow.h"
    29 #include "TEveBrowser.h"
    30 #include "TEveCalo.h"
     22#include <algorithm>
     23
     24#include "TGeoManager.h"
     25#include "TGeoVolume.h"
    3126#include "TEveElement.h"
    32 #include "TEveEventManager.h"
    33 #include "TEveGeoNode.h"
    3427#include "TEveJetCone.h"
    35 #include "TEveManager.h"
    3628#include "TEveTrack.h"
    3729#include "TEveTrackPropagator.h"
     30#include "TEveCalo.h"
     31#include "TEveManager.h"
     32#include "TEveGeoNode.h"
    3833#include "TEveTrans.h"
    3934#include "TEveViewer.h"
     35#include "TEveBrowser.h"
     36#include "TEveArrow.h"
     37#include "TMath.h"
     38#include "TSystem.h"
     39#include "TRootBrowser.h"
    4040#include "TGButton.h"
     41#include "TGTextEntry.h"
     42#include "TGProgressBar.h"
     43#include "TGNumberEntry.h"
     44#include "TRootEmbeddedCanvas.h"
     45#include "TClonesArray.h"
     46#include "TEveEventManager.h"
     47#include "TCanvas.h"
     48#include "TH1F.h"
     49#include "TAxis.h"
     50#include "TChain.h"
    4151#include "TGHtml.h"
    42 #include "TGNumberEntry.h"
    43 #include "TGProgressBar.h"
    4452#include "TGStatusBar.h"
    45 #include "TGTextEntry.h"
    46 #include "TGeoManager.h"
    47 #include "TGeoVolume.h"
    48 #include "TH1F.h"
    49 #include "TMath.h"
    50 #include "TRootBrowser.h"
    51 #include "TRootEmbeddedCanvas.h"
    52 #include "TSystem.h"
    53 
     53
     54#include "display/DelphesCaloData.h"
     55#include "display/DelphesBranchElement.h"
    5456#include "display/Delphes3DGeometry.h"
    55 #include "display/DelphesBranchElement.h"
    56 #include "display/DelphesCaloData.h"
     57#include "display/DelphesEventDisplay.h"
    5758#include "display/DelphesDisplay.h"
    58 #include "display/DelphesEventDisplay.h"
     59#include "display/Delphes3DGeometry.h"
    5960#include "display/DelphesHtmlSummary.h"
    6061#include "display/DelphesPlotSummary.h"
     
    6667DelphesEventDisplay::DelphesEventDisplay()
    6768{
    68   event_id_ = 0;
    69   tkRadius_ = 1.29;
    70   totRadius_ = 2.0;
    71   tkHalfLength_ = 3.0;
    72   muHalfLength_ = 6.0;
    73   bz_ = 3.8;
    74   chain_ = new TChain("Delphes");
    75   treeReader_ = 0;
    76   delphesDisplay_ = 0;
    77   etaAxis_ = 0;
    78   phiAxis_ = 0;
     69   event_id_ = 0;
     70   tkRadius_ = 1.29;
     71   totRadius_ = 2.0;
     72   tkHalfLength_ = 3.0;
     73   muHalfLength_ = 6.0;
     74   bz_ = 3.8;
     75   chain_ = new TChain("Delphes");
     76   treeReader_ = 0;
     77   delphesDisplay_ = 0;
     78   etaAxis_ = 0;
     79   phiAxis_ = 0;
    7980}
    8081
    8182DelphesEventDisplay::~DelphesEventDisplay()
    8283{
    83   delete chain_;
     84   delete chain_;
    8485}
    8586
    8687void DelphesEventDisplay::EventChanged(Int_t e)
    8788{
    88   if(e != event_id_)
    89   {
     89  if( e!= event_id_ ) {
    9090    event_id_ = e;
    91     Emit("EventChanged(Int_t)", e);
     91    Emit("EventChanged(Int_t)",e);
    9292    load_event();
    9393  }
    9494}
    9595
    96 DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry &det3D)
    97 {
    98   event_id_ = 0;
    99   tkRadius_ = 1.29;
    100   totRadius_ = 2.0;
    101   tkHalfLength_ = 3.0;
    102   bz_ = 3.8;
    103   chain_ = new TChain("Delphes");
    104   treeReader_ = 0;
    105   delphesDisplay_ = 0;
    106 
    107   // initialize the application
    108   TEveManager::Create(kTRUE, "IV");
    109   fStatusBar_ = gEve->GetBrowser()->GetStatusBar();
    110   TGeoManager *geom = gGeoManager;
    111 
    112   // build the detector
    113   tkRadius_ = det3D.getTrackerRadius();
    114   totRadius_ = det3D.getDetectorRadius();
    115   tkHalfLength_ = det3D.getTrackerHalfLength();
    116   muHalfLength_ = det3D.getDetectorHalfLength();
    117   bz_ = det3D.getBField();
    118   etaAxis_ = det3D.getCaloAxes().first;
    119   phiAxis_ = det3D.getCaloAxes().second;
    120   TGeoVolume *top = det3D.getDetector(false);
    121   geom->SetTopVolume(top);
    122   TEveElementList *geometry = new TEveElementList("Geometry");
    123   TObjArray *nodes = top->GetNodes();
    124   TIter itNodes(nodes);
    125   TGeoNode *nodeobj;
    126   TEveGeoTopNode *node;
    127   while((nodeobj = (TGeoNode *)itNodes.Next()))
    128   {
    129     node = new TEveGeoTopNode(gGeoManager, nodeobj);
    130     node->UseNodeTrans();
    131     geometry->AddElement(node);
    132   }
    133 
    134   // Create chain of root trees
    135   chain_->Add(inputFile);
    136 
    137   // Create object of class ExRootTreeReader
    138   fStatusBar_->SetText("Opening Delphes data file", 1);
    139   gSystem->ProcessEvents();
    140   treeReader_ = new ExRootTreeReader(chain_);
    141 
    142   // prepare data collections
    143   readConfig(configFile, elements_);
    144   for(std::vector<DelphesBranchBase *>::iterator element = elements_.begin(); element < elements_.end(); ++element)
    145   {
    146     DelphesBranchElement<TEveTrackList> *item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList> *>(*element);
    147     DelphesBranchElement<TEveElementList> *item_v2 = dynamic_cast<DelphesBranchElement<TEveElementList> *>(*element);
    148     if(item_v1) gEve->AddElement(item_v1->GetContainer());
    149     if(item_v2) gEve->AddElement(item_v2->GetContainer());
    150   }
    151 
    152   // viewers and scenes
    153   delphesDisplay_ = new DelphesDisplay;
    154   gEve->AddGlobalElement(geometry);
    155   delphesDisplay_->ImportGeomRPhi(geometry);
    156   delphesDisplay_->ImportGeomRhoZ(geometry);
    157   // find the first calo data and use that to initialize the calo display
    158   for(std::vector<DelphesBranchBase *>::iterator data = elements_.begin(); data < elements_.end(); ++data)
    159   {
    160     if(TString((*data)->GetType()) == "Tower")
    161     { // we could also use GetClassName()=="DelphesCaloData"
    162       DelphesCaloData *container = dynamic_cast<DelphesBranchElement<DelphesCaloData> *>((*data))->GetContainer();
    163       assert(container);
    164       TEveCalo3D *calo3d = new TEveCalo3D(container);
    165       calo3d->SetBarrelRadius(tkRadius_);
    166       calo3d->SetEndCapPos(tkHalfLength_);
    167       gEve->AddGlobalElement(calo3d);
    168       delphesDisplay_->ImportCaloRPhi(calo3d);
    169       delphesDisplay_->ImportCaloRhoZ(calo3d);
    170       TEveCaloLego *lego = new TEveCaloLego(container);
    171       lego->InitMainTrans();
    172       //    lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
    173       lego->RefMainTrans().SetScale(100, 100, TMath::Pi());
    174       lego->SetAutoRebin(kFALSE);
    175       lego->Set2DMode(TEveCaloLego::kValSizeOutline);
    176       delphesDisplay_->ImportCaloLego(lego);
    177       break;
    178     }
    179   }
    180 
    181   // the GUI: control panel, summary tab
    182   make_gui();
    183 
    184   //ready...
    185   fStatusBar_->SetText("Ready.", 1);
    186   gSystem->ProcessEvents();
    187   load_event();
    188   gEve->Redraw3D(kTRUE);
     96
     97DelphesEventDisplay::DelphesEventDisplay(const char *configFile, const char *inputFile, Delphes3DGeometry& det3D)
     98{
     99   event_id_ = 0;
     100   tkRadius_ = 1.29;
     101   totRadius_ = 2.0;
     102   tkHalfLength_ = 3.0;
     103   bz_ = 3.8;
     104   chain_ = new TChain("Delphes");
     105   treeReader_ = 0;
     106   delphesDisplay_ = 0;
     107
     108   // initialize the application
     109   TEveManager::Create(kTRUE, "IV");
     110   fStatusBar_ = gEve->GetBrowser()->GetStatusBar();
     111   TGeoManager *geom = gGeoManager;
     112
     113   // build the detector
     114   tkRadius_ = det3D.getTrackerRadius();
     115   totRadius_ = det3D.getDetectorRadius();
     116   tkHalfLength_ = det3D.getTrackerHalfLength();
     117   muHalfLength_ = det3D.getDetectorHalfLength();
     118   bz_ = det3D.getBField();
     119   etaAxis_ = det3D.getCaloAxes().first;
     120   phiAxis_ = det3D.getCaloAxes().second;
     121   TGeoVolume *top = det3D.getDetector(false);
     122   geom->SetTopVolume(top);
     123   TEveElementList *geometry = new TEveElementList("Geometry");
     124   TObjArray *nodes = top->GetNodes();
     125   TIter itNodes(nodes);
     126   TGeoNode *nodeobj;
     127   TEveGeoTopNode *node;
     128   while((nodeobj = (TGeoNode*)itNodes.Next())) {
     129     node = new TEveGeoTopNode(gGeoManager,nodeobj);
     130     node->UseNodeTrans();
     131     geometry->AddElement(node);
     132   }
     133
     134   // Create chain of root trees
     135   chain_->Add(inputFile);
     136
     137   // Create object of class ExRootTreeReader
     138   fStatusBar_->SetText("Opening Delphes data file", 1);
     139   gSystem->ProcessEvents();
     140   treeReader_ = new ExRootTreeReader(chain_);
     141
     142   // prepare data collections
     143   readConfig(configFile, elements_);
     144   for(std::vector<DelphesBranchBase *>::iterator element = elements_.begin(); element<elements_.end(); ++element) {
     145     DelphesBranchElement<TEveTrackList> *item_v1 = dynamic_cast<DelphesBranchElement<TEveTrackList>*>(*element);
     146     DelphesBranchElement<TEveElementList> *item_v2 = dynamic_cast<DelphesBranchElement<TEveElementList>*>(*element);
     147     if(item_v1) gEve->AddElement(item_v1->GetContainer());
     148     if(item_v2) gEve->AddElement(item_v2->GetContainer());
     149   }
     150
     151   // viewers and scenes
     152   delphesDisplay_ = new DelphesDisplay;
     153   gEve->AddGlobalElement(geometry);
     154   delphesDisplay_->ImportGeomRPhi(geometry);
     155   delphesDisplay_->ImportGeomRhoZ(geometry);
     156   // find the first calo data and use that to initialize the calo display
     157   for(std::vector<DelphesBranchBase *>::iterator data=elements_.begin();data<elements_.end();++data) {
     158     if(TString((*data)->GetType())=="Tower") { // we could also use GetClassName()=="DelphesCaloData"
     159       DelphesCaloData *container = dynamic_cast<DelphesBranchElement<DelphesCaloData>*>((*data))->GetContainer();
     160       assert(container);
     161       TEveCalo3D *calo3d = new TEveCalo3D(container);
     162       calo3d->SetBarrelRadius(tkRadius_);
     163       calo3d->SetEndCapPos(tkHalfLength_);
     164       gEve->AddGlobalElement(calo3d);
     165       delphesDisplay_->ImportCaloRPhi(calo3d);
     166       delphesDisplay_->ImportCaloRhoZ(calo3d);
     167       TEveCaloLego *lego = new TEveCaloLego(container);
     168       lego->InitMainTrans();
     169 //    lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
     170       lego->RefMainTrans().SetScale(100, 100, TMath::Pi());
     171       lego->SetAutoRebin(kFALSE);
     172       lego->Set2DMode(TEveCaloLego::kValSizeOutline);
     173       delphesDisplay_->ImportCaloLego(lego);
     174       break;
     175     }
     176   }
     177
     178   // the GUI: control panel, summary tab
     179   make_gui();
     180
     181   //ready...
     182   fStatusBar_->SetText("Ready.", 1);
     183   gSystem->ProcessEvents();
     184   load_event();
     185   gEve->Redraw3D(kTRUE);   
     186
    189187}
    190188
    191189// function that parses the config to extract the branches of interest and prepare containers
    192 void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase *> &elements)
    193 {
    194   ExRootConfReader *confReader = new ExRootConfReader;
    195   confReader->ReadFile(configFile);
    196   ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
    197   Int_t nBranches = branches.GetSize() / 3;
    198   DelphesBranchElement<TEveTrackList> *tlist;
    199   DelphesBranchElement<DelphesCaloData> *clist;
    200   DelphesBranchElement<TEveElementList> *elist;
    201   // first loop with all but tracks
    202   for(Int_t b = 0; b < nBranches; ++b)
    203   {
    204     TString input = branches[b * 3].GetString();
    205     TString name = branches[b * 3 + 1].GetString();
    206     TString className = branches[b * 3 + 2].GetString();
    207     if(className == "Tower")
    208     {
    209       if(input.Contains("eflow", TString::kIgnoreCase) || name.Contains("eflow", TString::kIgnoreCase)) continue; //no eflow
    210       clist = new DelphesBranchElement<DelphesCaloData>(name, treeReader_->UseBranch(name), kBlack);
    211       clist->GetContainer()->SetEtaBins(etaAxis_);
    212       clist->GetContainer()->SetPhiBins(phiAxis_);
    213       elements.push_back(clist);
    214     }
    215     else if(className == "Jet")
    216     {
    217       if(input.Contains("GenJetFinder"))
    218       {
    219         elist = new DelphesBranchElement<TEveElementList>(name, treeReader_->UseBranch(name), kCyan);
    220         elist->GetContainer()->SetRnrSelf(false);
    221         elist->GetContainer()->SetRnrChildren(false);
    222         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    223         elements.push_back(elist);
     190void DelphesEventDisplay::readConfig(const char *configFile, std::vector<DelphesBranchBase*>& elements) {
     191   ExRootConfReader *confReader = new ExRootConfReader;
     192   confReader->ReadFile(configFile);
     193   ExRootConfParam branches = confReader->GetParam("TreeWriter::Branch");
     194   Int_t nBranches = branches.GetSize()/3;
     195   DelphesBranchElement<TEveTrackList> *tlist;
     196   DelphesBranchElement<DelphesCaloData> *clist;
     197   DelphesBranchElement<TEveElementList> *elist;
     198   // first loop with all but tracks
     199   for(Int_t b = 0; b<nBranches; ++b) {
     200     TString input = branches[b*3].GetString();
     201     TString name = branches[b*3+1].GetString();
     202     TString className = branches[b*3+2].GetString();
     203     if(className=="Tower") {
     204       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
     205       clist = new DelphesBranchElement<DelphesCaloData>(name,treeReader_->UseBranch(name),kBlack);
     206       clist->GetContainer()->SetEtaBins(etaAxis_);
     207       clist->GetContainer()->SetPhiBins(phiAxis_);
     208       elements.push_back(clist);
     209     } else if(className=="Jet") {
     210       if(input.Contains("GenJetFinder")) {
     211         elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kCyan);
     212         elist->GetContainer()->SetRnrSelf(false);
     213         elist->GetContainer()->SetRnrChildren(false);
     214         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     215         elements.push_back(elist);
     216       } else {
     217         elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kYellow);
     218         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     219         elements.push_back(elist);
     220       }
     221     } else if(className=="Electron") {
     222       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kRed);
     223       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     224       elements.push_back(tlist);
     225     } else if(className=="Photon") {
     226       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kYellow);
     227       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     228       elements.push_back(tlist);
     229     } else if(className=="Muon") {
     230       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kGreen);
     231       tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
     232       elements.push_back(tlist);
     233     } else if(className=="MissingET") {
     234       elist = new DelphesBranchElement<TEveElementList>(name,treeReader_->UseBranch(name),kViolet);
     235       elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     236       elements.push_back(elist);
     237     } else if(className=="GenParticle") {
     238       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kCyan);
     239       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     240       tlist->GetContainer()->SetRnrSelf(false);
     241       tlist->GetContainer()->SetRnrChildren(false);
     242       elements.push_back(tlist);
     243     } else {
     244       continue;
     245     }
     246   }
     247   // second loop for tracks
     248   for(Int_t b = 0; b<nBranches; ++b) {
     249     TString input = branches[b*3].GetString();
     250     TString name = branches[b*3+1].GetString();
     251     TString className = branches[b*3+2].GetString();
     252     if(className=="Track") {
     253       if(input.Contains("eflow",TString::kIgnoreCase) || name.Contains("eflow",TString::kIgnoreCase)) continue; //no eflow
     254       tlist = new DelphesBranchElement<TEveTrackList>(name,treeReader_->UseBranch(name),kBlue);
     255       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
     256       elements.push_back(tlist);
     257     }
     258   }
     259}
     260
     261void DelphesEventDisplay::load_event()
     262{
     263   // Load event specified in global event_id_.
     264   // The contents of previous event are removed.
     265
     266   // safety
     267   if(event_id_ >= treeReader_->GetEntries() || event_id_<0 ) return;
     268
     269   // message
     270   fStatusBar_->SetText(Form("Loading event %d.", event_id_), 1);
     271   gSystem->ProcessEvents();
     272
     273   // clear the previous event
     274   gEve->GetViewers()->DeleteAnnotations();
     275   for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
     276     (*data)->Reset();
     277   }
     278
     279   // Load selected branches with data from specified event
     280   treeReader_->ReadEntry(event_id_);
     281   for(std::vector<DelphesBranchBase*>::iterator data=elements_.begin();data<elements_.end();++data) {
     282     (*data)->ReadBranch();
     283   }
     284
     285   // update display
     286   TEveElement *top = (TEveElement*)gEve->GetCurrentEvent();
     287   delphesDisplay_->DestroyEventRPhi();
     288   delphesDisplay_->ImportEventRPhi(top);
     289   delphesDisplay_->DestroyEventRhoZ();
     290   delphesDisplay_->ImportEventRhoZ(top);
     291   update_html_summary();
     292   plotSummary_->FillEvent();
     293   plotSummary_->Draw();
     294
     295   gEve->Redraw3D(kFALSE, kTRUE);
     296   fStatusBar_->SetText(Form("Loaded event %d.", event_id_), 1);
     297   gSystem->ProcessEvents();
     298}
     299
     300void DelphesEventDisplay::update_html_summary()
     301{
     302   // Update summary of current event.
     303
     304   TEveElement::List_i i;
     305   TEveElement::List_i j;
     306   Int_t k;
     307   TEveElement *el;
     308   DelphesHtmlObjTable *table;
     309   TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
     310   if (mgr) {
     311      htmlSummary_->Clear("D");
     312      for (i=mgr->BeginChildren(); i!=mgr->EndChildren(); ++i) {
     313         el = ((TEveElement*)(*i));
     314         if (el->IsA() == TEvePointSet::Class()) {
     315            TEvePointSet *ps = (TEvePointSet *)el;
     316            TString ename  = ps->GetElementName();
     317            TString etitle = ps->GetElementTitle();
     318            if (ename.First('\'') != kNPOS)
     319               ename.Remove(ename.First('\''));
     320            etitle.Remove(0, 2);
     321            Int_t nel = atoi(etitle.Data());
     322            table = htmlSummary_->AddTable(ename, 0, nel);
     323         }
     324         else if (el->IsA() == TEveTrackList::Class()) {
     325            TEveTrackList *tracks = (TEveTrackList *)el;
     326            TString ename  = tracks->GetElementName();
     327            if (ename.First('\'') != kNPOS)
     328               ename.Remove(ename.First('\''));
     329            table = htmlSummary_->AddTable(ename.Data(), 5,
     330                     tracks->NumChildren(), kTRUE, "first");
     331            table->SetLabel(0, "Momentum");
     332            table->SetLabel(1, "P_t");
     333            table->SetLabel(2, "Phi");
     334            table->SetLabel(3, "Theta");
     335            table->SetLabel(4, "Eta");
     336            k=0;
     337            for (j=tracks->BeginChildren(); j!=tracks->EndChildren(); ++j) {
     338               Float_t p     = ((TEveTrack*)(*j))->GetMomentum().Mag();
     339               table->SetValue(0, k, p);
     340               Float_t pt    = ((TEveTrack*)(*j))->GetMomentum().Perp();
     341               table->SetValue(1, k, pt);
     342               Float_t phi   = ((TEveTrack*)(*j))->GetMomentum().Phi();
     343               table->SetValue(2, k, phi);
     344               Float_t theta = ((TEveTrack*)(*j))->GetMomentum().Theta();
     345               table->SetValue(3, k, theta);
     346               Float_t eta   = theta>0.0005 && theta<3.1413 ? ((TEveTrack*)(*j))->GetMomentum().Eta() : 1e10;
     347               table->SetValue(4, k, eta);
     348               ++k;
     349            }
     350         }
    224351      }
    225       else
    226       {
    227         elist = new DelphesBranchElement<TEveElementList>(name, treeReader_->UseBranch(name), kYellow);
    228         elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    229         elements.push_back(elist);
    230       }
    231     }
    232     else if(className == "Electron")
    233     {
    234       tlist = new DelphesBranchElement<TEveTrackList>(name, treeReader_->UseBranch(name), kRed);
    235       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    236       elements.push_back(tlist);
    237     }
    238     else if(className == "Photon")
    239     {
    240       tlist = new DelphesBranchElement<TEveTrackList>(name, treeReader_->UseBranch(name), kYellow);
    241       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    242       elements.push_back(tlist);
    243     }
    244     else if(className == "Muon")
    245     {
    246       tlist = new DelphesBranchElement<TEveTrackList>(name, treeReader_->UseBranch(name), kGreen);
    247       tlist->SetTrackingVolume(totRadius_, muHalfLength_, bz_);
    248       elements.push_back(tlist);
    249     }
    250     else if(className == "MissingET")
    251     {
    252       elist = new DelphesBranchElement<TEveElementList>(name, treeReader_->UseBranch(name), kViolet);
    253       elist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    254       elements.push_back(elist);
    255     }
    256     else if(className == "GenParticle")
    257     {
    258       tlist = new DelphesBranchElement<TEveTrackList>(name, treeReader_->UseBranch(name), kCyan);
    259       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    260       tlist->GetContainer()->SetRnrSelf(false);
    261       tlist->GetContainer()->SetRnrChildren(false);
    262       elements.push_back(tlist);
    263     }
    264     else
    265     {
    266       continue;
    267     }
    268   }
    269   // second loop for tracks
    270   for(Int_t b = 0; b < nBranches; ++b)
    271   {
    272     TString input = branches[b * 3].GetString();
    273     TString name = branches[b * 3 + 1].GetString();
    274     TString className = branches[b * 3 + 2].GetString();
    275     if(className == "Track")
    276     {
    277       if(input.Contains("eflow", TString::kIgnoreCase) || name.Contains("eflow", TString::kIgnoreCase)) continue; //no eflow
    278       tlist = new DelphesBranchElement<TEveTrackList>(name, treeReader_->UseBranch(name), kBlue);
    279       tlist->SetTrackingVolume(tkRadius_, tkHalfLength_, bz_);
    280       elements.push_back(tlist);
    281     }
    282   }
    283 }
    284 
    285 void DelphesEventDisplay::load_event()
    286 {
    287   // Load event specified in global event_id_.
    288   // The contents of previous event are removed.
    289 
    290   // safety
    291   if(event_id_ >= treeReader_->GetEntries() || event_id_ < 0) return;
    292 
    293   // message
    294   fStatusBar_->SetText(Form("Loading event %d.", event_id_), 1);
    295   gSystem->ProcessEvents();
    296 
    297   // clear the previous event
    298   gEve->GetViewers()->DeleteAnnotations();
    299   for(std::vector<DelphesBranchBase *>::iterator data = elements_.begin(); data < elements_.end(); ++data)
    300   {
    301     (*data)->Reset();
    302   }
    303 
    304   // Load selected branches with data from specified event
    305   treeReader_->ReadEntry(event_id_);
    306   for(std::vector<DelphesBranchBase *>::iterator data = elements_.begin(); data < elements_.end(); ++data)
    307   {
    308     (*data)->ReadBranch();
    309   }
    310 
    311   // update display
    312   TEveElement *top = (TEveElement *)gEve->GetCurrentEvent();
    313   delphesDisplay_->DestroyEventRPhi();
    314   delphesDisplay_->ImportEventRPhi(top);
    315   delphesDisplay_->DestroyEventRhoZ();
    316   delphesDisplay_->ImportEventRhoZ(top);
    317   update_html_summary();
    318   plotSummary_->FillEvent();
    319   plotSummary_->Draw();
    320 
    321   gEve->Redraw3D(kFALSE, kTRUE);
    322   fStatusBar_->SetText(Form("Loaded event %d.", event_id_), 1);
    323   gSystem->ProcessEvents();
    324 }
    325 
    326 void DelphesEventDisplay::update_html_summary()
    327 {
    328   // Update summary of current event.
    329 
    330   TEveElement::List_i i;
    331   TEveElement::List_i j;
    332   Int_t k;
    333   TEveElement *el;
    334   DelphesHtmlObjTable *table;
    335   TEveEventManager *mgr = gEve ? gEve->GetCurrentEvent() : 0;
    336   if(mgr)
    337   {
    338     htmlSummary_->Clear("D");
    339     for(i = mgr->BeginChildren(); i != mgr->EndChildren(); ++i)
    340     {
    341       el = ((TEveElement *)(*i));
    342       if(el->IsA() == TEvePointSet::Class())
    343       {
    344         TEvePointSet *ps = (TEvePointSet *)el;
    345         TString ename = ps->GetElementName();
    346         TString etitle = ps->GetElementTitle();
    347         if(ename.First('\'') != kNPOS)
    348           ename.Remove(ename.First('\''));
    349         etitle.Remove(0, 2);
    350         Int_t nel = atoi(etitle.Data());
    351         table = htmlSummary_->AddTable(ename, 0, nel);
    352       }
    353       else if(el->IsA() == TEveTrackList::Class())
    354       {
    355         TEveTrackList *tracks = (TEveTrackList *)el;
    356         TString ename = tracks->GetElementName();
    357         if(ename.First('\'') != kNPOS)
    358           ename.Remove(ename.First('\''));
    359         table = htmlSummary_->AddTable(ename.Data(), 5,
    360           tracks->NumChildren(), kTRUE, "first");
    361         table->SetLabel(0, "Momentum");
    362         table->SetLabel(1, "P_t");
    363         table->SetLabel(2, "Phi");
    364         table->SetLabel(3, "Theta");
    365         table->SetLabel(4, "Eta");
    366         k = 0;
    367         for(j = tracks->BeginChildren(); j != tracks->EndChildren(); ++j)
    368         {
    369           Float_t p = ((TEveTrack *)(*j))->GetMomentum().Mag();
    370           table->SetValue(0, k, p);
    371           Float_t pt = ((TEveTrack *)(*j))->GetMomentum().Perp();
    372           table->SetValue(1, k, pt);
    373           Float_t phi = ((TEveTrack *)(*j))->GetMomentum().Phi();
    374           table->SetValue(2, k, phi);
    375           Float_t theta = ((TEveTrack *)(*j))->GetMomentum().Theta();
    376           table->SetValue(3, k, theta);
    377           Float_t eta = theta > 0.0005 && theta < 3.1413 ? ((TEveTrack *)(*j))->GetMomentum().Eta() : 1e10;
    378           table->SetValue(4, k, eta);
    379           ++k;
    380         }
    381       }
    382     }
    383     htmlSummary_->Build();
    384     gHtml_->Clear();
    385     gHtml_->ParseText((char *)htmlSummary_->Html().Data());
    386     gHtml_->Layout();
    387   }
     352      htmlSummary_->Build();
     353      gHtml_->Clear();
     354      gHtml_->ParseText((char*)htmlSummary_->Html().Data());
     355      gHtml_->Layout();
     356   }
     357 
    388358}
    389359
     
    394364void DelphesEventDisplay::make_gui()
    395365{
    396   // Create minimal GUI for event navigation.
    397 
    398   // add a tab on the left
    399   TEveBrowser *browser = gEve->GetBrowser();
    400   browser->SetWindowName("Delphes Event Display");
    401   browser->StartEmbedding(TRootBrowser::kLeft);
    402 
    403   // set the main title
    404   TGMainFrame *frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
    405   frmMain->SetWindowName("Delphes Event Display");
    406   frmMain->SetCleanup(kDeepCleanup);
    407 
    408   // build the navigation menu
    409   TString icondir;
    410   if(gSystem->Getenv("ROOTSYS"))
    411     icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
    412   if(!gSystem->OpenDirectory(icondir))
    413     icondir = Form("%s/icons/", (const char *)gSystem->GetFromPipe("root-config --etcdir"));
    414   TGGroupFrame *vf = new TGGroupFrame(frmMain, "Event navigation", kVerticalFrame | kFitWidth);
    415   {
    416     TGHorizontalFrame *hf = new TGHorizontalFrame(frmMain);
    417     {
    418       TGPictureButton *b = 0;
    419 
    420       b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoBack.gif"));
    421       hf->AddFrame(b, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 2, 10, 10));
    422       b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
    423 
    424       TGNumberEntry *numberEntry = new TGNumberEntry(hf, 0, 9, -1, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, treeReader_->GetEntries());
    425       hf->AddFrame(numberEntry, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 2, 0, 10, 10));
    426       this->Connect("EventChanged(Int_t)", "TGNumberEntry", numberEntry, "SetIntNumber(Long_t)");
    427       numberEntry->GetNumberEntry()->Connect("TextChanged(char*)", "DelphesEventDisplay", this, "PreSetEv(char*)");
    428       numberEntry->GetNumberEntry()->Connect("ReturnPressed()", "DelphesEventDisplay", this, "GoTo()");
    429 
    430       b = new TGPictureButton(hf, gClient->GetPicture(icondir + "GoForward.gif"));
    431       hf->AddFrame(b, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 2, 10, 10, 10));
    432       b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
    433     }
    434     vf->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
    435 
    436     TGHProgressBar *progress = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
    437     progress->SetMax(treeReader_->GetEntries());
    438     progress->ShowPosition(kTRUE, kFALSE, "Event %.0f");
    439     progress->SetBarColor("green");
    440     vf->AddFrame(progress, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
    441     this->Connect("EventChanged(Int_t)", "TGHProgressBar", progress, "SetPosition(Float_t)");
     366   // Create minimal GUI for event navigation.
     367
     368   // add a tab on the left
     369   TEveBrowser *browser = gEve->GetBrowser();
     370   browser->SetWindowName("Delphes Event Display");
     371   browser->StartEmbedding(TRootBrowser::kLeft);
     372
     373   // set the main title
     374   TGMainFrame *frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
     375   frmMain->SetWindowName("Delphes Event Display");
     376   frmMain->SetCleanup(kDeepCleanup);
     377
     378   // build the navigation menu
     379   TString icondir;
     380   if(gSystem->Getenv("ROOTSYS"))
     381     icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
     382   if(!gSystem->OpenDirectory(icondir))
     383     icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
     384   TGGroupFrame *vf = new TGGroupFrame(frmMain,"Event navigation",kVerticalFrame | kFitWidth );
     385   {
     386     TGHorizontalFrame *hf = new TGHorizontalFrame(frmMain);
     387     {
     388        TGPictureButton *b = 0;
     389
     390        b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
     391        hf->AddFrame(b, new TGLayoutHints(kLHintsLeft | kLHintsCenterY , 10, 2, 10, 10));
     392        b->Connect("Clicked()", "DelphesEventDisplay", this, "Bck()");
     393
     394        TGNumberEntry *numberEntry = new TGNumberEntry(hf,0,9,-1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, treeReader_->GetEntries());
     395        hf->AddFrame(numberEntry, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY , 2, 0, 10, 10));
     396        this->Connect("EventChanged(Int_t)","TGNumberEntry",numberEntry,"SetIntNumber(Long_t)");
     397        numberEntry->GetNumberEntry()->Connect("TextChanged(char*)", "DelphesEventDisplay", this, "PreSetEv(char*)");
     398        numberEntry->GetNumberEntry()->Connect("ReturnPressed()", "DelphesEventDisplay", this, "GoTo()");
     399       
     400        b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
     401        hf->AddFrame(b, new TGLayoutHints(kLHintsRight | kLHintsCenterY , 2, 10, 10, 10));
     402        b->Connect("Clicked()", "DelphesEventDisplay", this, "Fwd()");
     403 
     404     }
     405     vf->AddFrame(hf, new TGLayoutHints(kLHintsExpandX , 2, 2, 2, 2));
     406
     407     TGHProgressBar *progress = new TGHProgressBar(frmMain, TGProgressBar::kFancy, 100);
     408     progress->SetMax( treeReader_->GetEntries());
     409     progress->ShowPosition(kTRUE, kFALSE, "Event %.0f");
     410     progress->SetBarColor("green");
     411     vf->AddFrame(progress, new TGLayoutHints(kLHintsExpandX, 10, 10, 5, 5));
     412     this->Connect("EventChanged(Int_t)","TGHProgressBar",progress,"SetPosition(Float_t)");
     413   }
     414   frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX , 5, 5, 5, 5));
     415   vf = new TGGroupFrame(frmMain,"Batch operations",kVerticalFrame | kFitWidth );
     416   {
     417        TGTextButton *b = new TGTextButton(vf, "Initialize Summary Plots");
     418        vf->AddFrame(b, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsExpandX, 10, 10, 10, 10));
     419        b->Connect("Clicked()", "DelphesEventDisplay", this, "InitSummaryPlots()");
     420   }
     421   frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX , 5, 5, 5, 5));
     422
     423   frmMain->MapSubwindows();
     424   frmMain->Resize();
     425   frmMain->MapWindow();
     426   browser->StopEmbedding();
     427   browser->SetTabTitle("Event Control", 0);
     428
     429   // the summary tab
     430   htmlSummary_ = new DelphesHtmlSummary("Delphes Event Display Summary Table");
     431   TEveWindowSlot *slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
     432   gHtml_ = new TGHtml(0, 100, 100);
     433   TEveWindowFrame *wf = slot->MakeFrame(gHtml_);
     434   gHtml_->MapSubwindows();
     435   wf->SetElementName("Summary tables");
     436
     437   // plot tab
     438   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
     439   TEveWindowTab *tab = slot->MakeTab();
     440   tab->SetElementName("Summary plots");
     441   tab->SetShowTitleBar(kFALSE);
     442   plotSummary_ = new DelphesPlotSummary(tab);
     443   plotSummary_->Init(elements_);
     444   plotSummary_->Connect("Progress(Int_t)", "DelphesEventDisplay", this, "DisplayProgress(Int_t)");
     445
     446}
     447
     448void DelphesEventDisplay::Fwd() { 
     449  if (event_id_ < treeReader_->GetEntries() - 2) {
     450     EventChanged(event_id_+1);
     451  } else {
     452     printf("Already at last event.\n");
    442453  }
    443   frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
    444   vf = new TGGroupFrame(frmMain, "Batch operations", kVerticalFrame | kFitWidth);
    445   {
    446     TGTextButton *b = new TGTextButton(vf, "Initialize Summary Plots");
    447     vf->AddFrame(b, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsExpandX, 10, 10, 10, 10));
    448     b->Connect("Clicked()", "DelphesEventDisplay", this, "InitSummaryPlots()");
     454}
     455
     456void DelphesEventDisplay::Bck() {
     457  if (event_id_ > 0) {
     458     EventChanged(event_id_-1);
     459  } else {
     460     printf("Already at first event.\n");
    449461  }
    450   frmMain->AddFrame(vf, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
    451 
    452   frmMain->MapSubwindows();
    453   frmMain->Resize();
    454   frmMain->MapWindow();
    455   browser->StopEmbedding();
    456   browser->SetTabTitle("Event Control", 0);
    457 
    458   // the summary tab
    459   htmlSummary_ = new DelphesHtmlSummary("Delphes Event Display Summary Table");
    460   TEveWindowSlot *slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
    461   gHtml_ = new TGHtml(0, 100, 100);
    462   TEveWindowFrame *wf = slot->MakeFrame(gHtml_);
    463   gHtml_->MapSubwindows();
    464   wf->SetElementName("Summary tables");
    465 
    466   // plot tab
    467   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
    468   TEveWindowTab *tab = slot->MakeTab();
    469   tab->SetElementName("Summary plots");
    470   tab->SetShowTitleBar(kFALSE);
    471   plotSummary_ = new DelphesPlotSummary(tab);
    472   plotSummary_->Init(elements_);
    473   plotSummary_->Connect("Progress(Int_t)", "DelphesEventDisplay", this, "DisplayProgress(Int_t)");
    474 }
    475 
    476 void DelphesEventDisplay::Fwd()
    477 {
    478   if(event_id_ < treeReader_->GetEntries() - 2)
    479   {
    480     EventChanged(event_id_ + 1);
    481   }
    482   else
    483   {
    484     printf("Already at last event.\n");
    485   }
    486 }
    487 
    488 void DelphesEventDisplay::Bck()
    489 {
    490   if(event_id_ > 0)
    491   {
    492     EventChanged(event_id_ - 1);
    493   }
    494   else
    495   {
    496     printf("Already at first event.\n");
    497   }
    498 }
    499 
    500 void DelphesEventDisplay::PreSetEv(char *ev)
    501 {
     462}
     463
     464void DelphesEventDisplay::PreSetEv(char *ev) {
    502465  event_id_tmp_ = Int_t(atoi(ev));
    503466}
    504467
    505 void DelphesEventDisplay::GoTo()
    506 {
    507   if(event_id_tmp_ >= 0 && event_id_tmp_ < treeReader_->GetEntries() - 1)
    508   {
     468void DelphesEventDisplay::GoTo() {
     469  if (event_id_tmp_>=0 && event_id_tmp_ < treeReader_->GetEntries()-1) {
    509470    EventChanged(event_id_tmp_);
    510   }
    511   else
    512   {
     471  } else {
    513472    printf("Error: no such event.\n");
    514473  }
    515474}
    516475
    517 void DelphesEventDisplay::InitSummaryPlots()
    518 {
     476void DelphesEventDisplay::InitSummaryPlots() {
    519477  plotSummary_->FillSample(treeReader_, event_id_);
    520478  plotSummary_->FillEvent();
     
    522480}
    523481
    524 void DelphesEventDisplay::DisplayProgress(Int_t p)
    525 {
    526   fStatusBar_->SetText(Form("Processing... %d %%", p), 1);
     482void DelphesEventDisplay::DisplayProgress(Int_t p) {
     483  fStatusBar_->SetText(Form("Processing... %d %%",p), 1);
    527484  gSystem->ProcessEvents();
    528485}
Note: See TracChangeset for help on using the changeset viewer.