Fork me on GitHub

Changeset 7f66dc0 in git


Ignore:
Timestamp:
Oct 8, 2014, 5:39:21 PM (10 years ago)
Author:
Christophe Delaere <christophe.delaere@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
7513718
Parents:
164f032
Message:

integration of event display ongoing

Not functionnal so far. geometry.C still only displays the geometry in a
eve window.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/geometry.C

    r164f032 r7f66dc0  
    2020#include "TSystem.h"
    2121
     22/*
     23 * alice_esd.C : GUI complete
     24 * assembly.C: sauvegarde as shape-extract -> implement in the geometry class (read/write)
     25 * histobrowser.C: intégration d'histogrammes dans le display (on pourrait avoir Pt, eta, phi pour les principales collections)
     26 * also from alice_esd: summary html table
     27 *
     28 */
    2229using namespace std;
    2330
     31// Forward declarations.
     32class Delphes3DGeometry;
     33class ExRootTreeReader;
     34class DelphesCaloData;
     35class DelphesDisplay;
     36void make_gui();
     37void load_event();
     38void delphes_read();
     39
     40// Configuration and global variables.
     41Int_t event_id           = 0; // Current event id.
     42Double_t gRadius = 1.29;
     43Double_t gHalfLength = 3.0;
     44Double_t gBz = 3.8;
     45
     46TAxis *gEtaAxis = 0;
     47TAxis *gPhiAxis = 0;
     48
     49TChain gChain("Delphes");
     50
     51ExRootTreeReader *gTreeReader = 0;
     52
     53TClonesArray *gBranchTower = 0;
     54TClonesArray *gBranchTrack = 0;
     55TClonesArray *gBranchJet = 0;
     56
     57DelphesCaloData *gCaloData = 0;
     58TEveElementList *gJetList = 0;
     59TEveTrackList *gTrackList = 0;
     60
     61DelphesDisplay *gDelphesDisplay = 0;
     62
     63/******************************************************************************/
     64// Construction of the geometry
     65/******************************************************************************/
     66
    2467// TODO: asymmetric detector
     68
    2569class Delphes3DGeometry {
    2670   public:
     
    377421}
    378422
     423/******************************************************************************/
     424// Initialization and steering functions
     425/******************************************************************************/
     426
     427void delphes_event_display(const char *configFile, const char *inputFile)
     428{
     429   // to be the main function, initializes the application.
     430
     431  gSystem->Load("libDelphesDisplay");
     432
     433  TEveManager::Create(kTRUE, "IV");
     434
     435//------------------------------------ TODO: this should be moved to the geometry class
     436  ExRootConfParam param, paramEtaBins;
     437  Long_t i, j, size, sizeEtaBins;
     438  set< Double_t > etaSet;
     439  set< Double_t >::iterator itEtaSet;
     440
     441  Double_t *etaBins;
     442
     443  ExRootConfReader *confReader = new ExRootConfReader;
     444  confReader->ReadFile(configFile);
     445
     446  gRadius = confReader->GetDouble("ParticlePropagator::Radius", 1.0);
     447  gHalfLength = confReader->GetDouble("ParticlePropagator::HalfLength", 3.0);
     448  gBz = confReader->GetDouble("ParticlePropagator::Bz", 0.0);
     449
     450
     451  // read eta and phi bins
     452  param = confReader->GetParam("Calorimeter::EtaPhiBins");
     453  size = param.GetSize();
     454  etaSet.clear();
     455  for(i = 0; i < size/2; ++i)
     456  {
     457    paramEtaBins = param[i*2];
     458    sizeEtaBins = paramEtaBins.GetSize();
     459
     460    for(j = 0; j < sizeEtaBins; ++j)
     461    {
     462      etaSet.insert(paramEtaBins[j].GetDouble());
     463    }
     464  }
     465
     466  delete confReader;
     467
     468  etaBins = new Double_t[etaSet.size()];
     469  i = 0;
     470
     471  for(itEtaSet = etaSet.begin(); itEtaSet != etaSet.end(); ++itEtaSet)
     472  {
     473    etaBins[i] = *itEtaSet;
     474    ++i;
     475  }
     476
     477  gEtaAxis = new TAxis(etaSet.size() - 1, etaBins);
     478  gPhiAxis = new TAxis(72, -TMath::Pi(), TMath::Pi()); // note that this is fixed while #phibins could vary, also with eta, which doesn't seem possible in ROOT
     479//-----------------------------------------------------------------------
     480
     481  // Create chain of root trees
     482  gChain.Add(inputFile);
     483
     484  // Create object of class ExRootTreeReader
     485   printf("*** Opening Delphes data file ***\n");
     486  gTreeReader = new ExRootTreeReader(&gChain);
     487
     488  // Get pointers to branches
     489  //TODO make it configurable, for more objects (or can we guess from the config?)
     490  gBranchTower = gTreeReader->UseBranch("Tower");
     491  gBranchTrack = gTreeReader->UseBranch("Track");
     492  gBranchJet   = gTreeReader->UseBranch("Jet");
     493
     494// idea: for pf objects, we could use the TEveCompound to show track + cluster ??? (nice display but little meaning)
     495// for MET and SHT, show an arrow (tooltip = title)
     496// for electrons and muons, create additional track collections
     497// for photons, use TEveStraightLineSet
     498
     499/*
     500  add Branch Calorimeter/eflowTracks EFlowTrack Track
     501  add Branch Calorimeter/eflowPhotons EFlowPhoton Tower
     502  add Branch Calorimeter/eflowNeutralHadrons EFlowNeutralHadron Tower
     503
     504  add Branch GenJetFinder/jets GenJet Jet
     505
     506  add Branch UniqueObjectFinder/jets Jet Jet
     507
     508  add Branch UniqueObjectFinder/electrons Electron Electron
     509  add Branch UniqueObjectFinder/photons Photon Photon
     510  add Branch UniqueObjectFinder/muons Muon Muon
     511
     512  add Branch MissingET/momentum MissingET MissingET
     513  add Branch ScalarHT/energy ScalarHT ScalarHT
     514*/
     515
     516  // data
     517  gCaloData = new DelphesCaloData(2);
     518  gCaloData->RefSliceInfo(0).Setup("ECAL", 0.1, kRed);
     519  gCaloData->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
     520  gCaloData->SetEtaBins(gEtaAxis);
     521  gCaloData->SetPhiBins(gPhiAxis);
     522  gCaloData->IncDenyDestroy();
     523
     524  gJetList = new TEveElementList("Jets");
     525  gEve->AddElement(gJetList);
     526
     527  gTrackList = new TEveTrackList("Tracks");
     528  gTrackList->SetMainColor(kBlue);
     529  gTrackList->SetMarkerColor(kRed);
     530  gTrackList->SetMarkerStyle(kCircle);
     531  gTrackList->SetMarkerSize(0.5);
     532  gEve->AddElement(gTrackList);
     533
     534  TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
     535  trkProp->SetMagField(0.0, 0.0, -gBz);
     536  trkProp->SetMaxR(gRadius*100.0);
     537  trkProp->SetMaxZ(gHalfLength*100.0);
     538
     539  // viewers and scenes
     540
     541  TEveCalo3D *calo = new TEveCalo3D(gCaloData);
     542  calo->SetBarrelRadius(gRadius*100.0);  //TODO get it from geometry class
     543  calo->SetEndCapPos(gHalfLength*100.0); //TODO get it from geometry class
     544
     545  gStyle->SetPalette(1, 0);
     546  TEveCaloLego *lego = new TEveCaloLego(gCaloData);
     547  lego->InitMainTrans();
     548  lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
     549  lego->SetAutoRebin(kFALSE);
     550  lego->Set2DMode(TEveCaloLego::kValSizeOutline);
     551
     552  gDelphesDisplay = new DelphesDisplay;
     553  gEve->AddGlobalElement(geometry);
     554  gEve->AddGlobalElement(calo);
     555  gDelphesDisplay->ImportGeomRPhi(geometry);
     556  gDelphesDisplay->ImportCaloRPhi(calo);
     557  gDelphesDisplay->ImportGeomRhoZ(geometry);
     558  gDelphesDisplay->ImportCaloRhoZ(calo);
     559  gDelphesDisplay->ImportCaloLego(lego);
     560  gEve->Redraw3D(kTRUE);
     561
     562}
     563
     564//______________________________________________________________________________
     565void load_event()
     566{
     567   // Load event specified in global event_id.
     568   // The contents of previous event are removed.
     569
     570   printf("Loading event %d.\n", event_id);
     571
     572   gEve->GetViewers()->DeleteAnnotations();
     573
     574   if(gCaloData) gCaloData->ClearTowers();
     575   if(gJetList) gJetList->DestroyElements();
     576   if(gTrackList) gTrackList->DestroyElements();
     577
     578   delphes_read();
     579
     580   TEveElement* top = gEve->GetCurrentEvent();
     581   gDelphesDisplay->DestroyEventRPhi();
     582   gDelphesDisplay->ImportEventRPhi(top);
     583   gDelphesDisplay->DestroyEventRhoZ();
     584   gDelphesDisplay->ImportEventRhoZ(top);
     585
     586   //update_html_summary();
     587
     588   gEve->Redraw3D(kFALSE, kTRUE);
     589}
     590
     591void delphes_read()
     592{
     593
     594  TIter itTower(gBranchTower);
     595  TIter itTrack(gBranchTrack);
     596  TIter itJet(gBranchJet);
     597
     598  Tower *tower;
     599  Track *track;
     600  Jet *jet;
     601
     602  TEveJetCone *eveJetCone;
     603  TEveTrack *eveTrack;
     604
     605  Int_t counter;
     606
     607  TEveTrackPropagator *trkProp = gTrackList->GetPropagator();
     608  if(event >= gTreeReader->GetEntries()) return;
     609
     610  // Load selected branches with data from specified event
     611  gTreeReader->ReadEntry(event_id);
     612  // Loop over all towers
     613  itTower.Reset();
     614  while((tower = (Tower *) itTower.Next()))
     615  {
     616    gCaloData->AddTower(tower->Edges[0], tower->Edges[1], tower->Edges[2], tower->Edges[3]);
     617    gCaloData->FillSlice(0, tower->Eem);
     618    gCaloData->FillSlice(1, tower->Ehad);
     619  }
     620  gCaloData->DataChanged();
     621  // Loop over all tracks
     622  itTrack.Reset();
     623  counter = 0;
     624  while((track = (Track *) itTrack.Next()))
     625  {
     626    TParticle pb(track->PID, 1, 0, 0, 0, 0,
     627                 track->P4().Px(), track->P4().Py(),
     628                 track->P4().Pz(), track->P4().E(),
     629                 track->X, track->Y, track->Z, 0.0);
     630
     631    eveTrack = new TEveTrack(&pb, counter, trkProp);
     632    eveTrack->SetName(Form("%s [%d]", pb.GetName(), counter++));
     633    eveTrack->SetStdTitle();
     634    eveTrack->SetAttLineAttMarker(gTrackList);
     635
     636    switch(TMath::Abs(track->PID))
     637    {
     638      case 11:
     639        eveTrack->SetLineColor(kRed);
     640        break;
     641      case 13:
     642        eveTrack->SetLineColor(kGreen);
     643        break;
     644      default:
     645        eveTrack->SetLineColor(kBlue);
     646    }
     647    gTrackList->AddElement(eveTrack);
     648    eveTrack->MakeTrack();
     649  }
     650  // Loop over all jets
     651  itJet.Reset();
     652  counter = 0;
     653  while((jet = (Jet *) itJet.Next()))
     654  {
     655    eveJetCone = new TEveJetCone();
     656    eveJetCone->SetName(Form("jet [%d]", counter++));
     657    eveJetCone->SetMainTransparency(60);
     658    eveJetCone->SetLineColor(kYellow);
     659    eveJetCone->SetCylinder(gRadius*100.0 - 10, gHalfLength*100.0 - 10);
     660    eveJetCone->SetPickable(kTRUE);
     661    eveJetCone->AddEllipticCone(jet->Eta, jet->Phi, jet->DeltaEta, jet->DeltaPhi);
     662    gJetList->AddElement(eveJetCone);
     663  }
     664}
     665
     666
     667/******************************************************************************/
     668// GUI
     669/******************************************************************************/
     670
     671//______________________________________________________________________________
     672//
     673// EvNavHandler class is needed to connect GUI signals.
     674
     675class EvNavHandler
     676{     
     677public:
     678   void Fwd()
     679   { 
     680      if (event_id < tree->GetEntries() - 1) {
     681         ++event_id;
     682         load_event();
     683      } else {
     684         printf("Already at last event.\n");
     685      }
     686   }
     687   void Bck()
     688   {
     689      if (event_id > 0) {
     690         --event_id;
     691         load_event();
     692      } else {
     693         printf("Already at first event.\n");
     694      }
     695   }
     696};
     697
     698//______________________________________________________________________________
     699void make_gui()
     700{
     701   // Create minimal GUI for event navigation.
     702   // TODO: better GUI could be made based on the ch15 of the manual (Writing a GUI)
     703
     704   // add a tab on the left
     705   TEveBrowser* browser = gEve->GetBrowser();
     706   browser->StartEmbedding(TRootBrowser::kLeft);
     707
     708   // set the main title
     709   TGMainFrame* frmMain = new TGMainFrame(gClient->GetRoot(), 1000, 600);
     710   frmMain->SetWindowName("Delphes Event Display");
     711   frmMain->SetCleanup(kDeepCleanup);
     712
     713   // build the navigation menu
     714   TGHorizontalFrame* hf = new TGHorizontalFrame(frmMain);
     715   {
     716      TString icondir;
     717      if(gSystem->Getenv("ROOTSYS"))
     718        icondir = Form("%s/icons/", gSystem->Getenv("ROOTSYS"));
     719      if(!gSystem->OpenDirectory(icondir))
     720        icondir = Form("%s/icons/", (const char*)gSystem->GetFromPipe("root-config --etcdir") );
     721      TGPictureButton* b = 0;
     722      EvNavHandler    *fh = new EvNavHandler;
     723
     724      b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoBack.gif"));
     725      hf->AddFrame(b);
     726      b->Connect("Clicked()", "EvNavHandler", fh, "Bck()");
     727
     728      b = new TGPictureButton(hf, gClient->GetPicture(icondir+"GoForward.gif"));
     729      hf->AddFrame(b);
     730      b->Connect("Clicked()", "EvNavHandler", fh, "Fwd()");
     731   }
     732   frmMain->AddFrame(hf);
     733   frmMain->MapSubwindows();
     734   frmMain->Resize();
     735   frmMain->MapWindow();
     736   browser->StopEmbedding();
     737   browser->SetTabTitle("Event Control", 0);
     738}
     739
     740/******************************************************************************/
     741// MAIN
     742/******************************************************************************/
     743
    379744void geometry(const char* filename = "delphes_card_CMS.tcl", const char* ParticlePropagator="ParticlePropagator",
    380745                                                             const char* TrackingEfficiency="ChargedHadronTrackingEfficiency",
     
    402767   //file->Close();
    403768
    404    TEveManager::Create();
     769   TEveManager::Create(kTRUE, "IV");
     770
    405771
    406772   //TFile::SetCacheFileDir(".");
     
    451817   v->DoDraw();
    452818
    453 }
    454 
     819   make_gui();
     820   // load_event();
     821   // gEve->Redraw3D(kTRUE); // Reset camera after the first event has been shown.
     822}
     823
Note: See TracChangeset for help on using the changeset viewer.