CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Fireworks/Muons/plugins/FWMuonDetailView.cc

Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 //
00004 // Package:     Calo
00005 // Class  :     FWMuonDetailView
00006 // $Id: FWMuonDetailView.cc,v 1.27 2010/06/22 14:03:11 matevz Exp $
00007 //
00008 
00009 // ROOT includes
00010 #include "TLatex.h"
00011 #include "TEveCalo.h"
00012 #include "TEveStraightLineSet.h"
00013 #include "TEvePointSet.h"
00014 #include "TEveScene.h"
00015 #include "TEveViewer.h"
00016 #include "TGLViewer.h"
00017 #include "TCanvas.h"
00018 #include "TEveCaloLegoOverlay.h"
00019 #include "TRootEmbeddedCanvas.h"
00020 
00021 // Fireworks includes
00022 #include "Fireworks/Muons/plugins/FWMuonDetailView.h"
00023 #include "Fireworks/Calo/interface/FWECALDetailViewBuilder.h"
00024 #include "Fireworks/Core/interface/FWModelId.h"
00025 #include "Fireworks/Core/interface/FWEventItem.h"
00026 #include "Fireworks/Core/interface/FWColorManager.h"
00027 #include "Fireworks/Core/interface/FWGLEventHandler.h"
00028 
00029 #include "DataFormats/MuonReco/interface/Muon.h"
00030 //
00031 // constructors and destructor
00032 //
00033 FWMuonDetailView::FWMuonDetailView():
00034    m_data(0),
00035    m_builder(0)
00036 { 
00037 }
00038 
00039 FWMuonDetailView::~FWMuonDetailView()
00040 {
00041    m_eveViewer->GetGLViewer()->DeleteOverlayElements(TGLOverlayElement::kUser);
00042    if (m_data) m_data->DecDenyDestroy();
00043    delete m_builder;
00044 }
00045 
00046 //
00047 // member functions
00048 //
00049 void FWMuonDetailView::build(const FWModelId &id, const reco::Muon* iMuon)
00050 {
00051    if(0==iMuon) return;
00052 
00053    double eta = iMuon->eta();
00054    double phi = iMuon->phi();
00055    if ( iMuon->isEnergyValid() )
00056    {
00057       eta = iMuon->calEnergy().ecal_position.eta();
00058       phi = iMuon->calEnergy().ecal_position.phi();
00059    }
00060 
00061    m_builder = new FWECALDetailViewBuilder(id.item()->getEvent(), id.item()->getGeom(),
00062                                            eta, phi, 10);
00063  
00064    m_builder->showSuperClusters();
00065    if ( iMuon->isEnergyValid() ) {
00066       std::vector<DetId> ids;
00067       ids.push_back(iMuon->calEnergy().ecal_id);
00068       m_builder->setColor(kYellow,ids);
00069    }
00070 
00071    TEveCaloLego* lego = m_builder->build();
00072    m_data = lego->GetData();
00073    m_data->IncDenyDestroy();
00074    m_eveScene->AddElement(lego);
00075    addSceneInfo(iMuon, m_eveScene);
00076 
00077    // draw axis at the window corners
00078    TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
00079    overlay->SetShowPlane(kFALSE);
00080    overlay->SetShowPerspective(kFALSE);
00081    overlay->SetCaloLego(lego);
00082    overlay->SetShowScales(0); // temporary
00083    viewerGL()->AddOverlayElement(overlay);
00084 
00085    // set event handler and flip camera to top view at beginning
00086    viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
00087    FWGLEventHandler* eh =
00088       new FWGLEventHandler((TGWindow*)viewerGL()->GetGLWidget(), (TObject*)viewerGL(), lego);
00089    viewerGL()->SetEventHandler(eh);
00090 
00091    viewerGL()->ResetCamerasAfterNextUpdate();
00092    viewerGL()->UpdateScene(kFALSE);
00093    gEve->Redraw3D();
00094 
00095    setTextInfo(id, iMuon);
00096 }
00097 
00098 void
00099 FWMuonDetailView::setTextInfo(const FWModelId& id, const reco::Muon *muon)
00100 {
00101    m_infoCanvas->cd();
00102    double y0 = 0.95;
00103    double x0 = 0.02; 
00104 
00105    TLatex* latex = new TLatex(x0, y0, "");
00106    const double textsize(0.05);
00107    latex->SetTextSize(2*textsize);
00108 
00109    float_t x = x0;
00110    float   y = y0;
00111    float fontsize = latex->GetTextSize()*0.6;
00112 
00113    latex->DrawLatex(x, y, id.item()->modelName(id.index()).c_str() );
00114    y -= fontsize;
00115    latex->SetTextSize(textsize);
00116    fontsize = latex->GetTextSize()*0.6;
00117 
00118    latex->DrawLatex(x, y, Form(" p_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f",
00119                                muon->pt(), muon->eta(), muon->phi()) );
00120    y -= fontsize;
00121    // summary
00122    if (muon->charge() > 0)
00123       latex->DrawLatex(x, y, " charge = +1");
00124    else
00125       latex->DrawLatex(x, y, " charge = -1");
00126    y -= fontsize;
00127 
00128    if (muon->isEnergyValid() )
00129    {
00130       // delta phi/eta in
00131       latex->DrawLatex(x, y, "ECAL energy in:");
00132       y -= fontsize;
00133       latex->DrawLatex(x, y,  Form(" crossed crystalls = %.3f",
00134                                    muon->calEnergy().em) );
00135       y -= fontsize;
00136       latex->DrawLatex(x, y,  Form(" 3x3 crystall shape = %.3f",
00137                                    muon->calEnergy().emS9) );
00138       y -= fontsize;
00139       latex->DrawLatex(x, y,  Form(" 5x5 crystall shape = %.3f",
00140                                    muon->calEnergy().emS25) );
00141    }
00142    m_builder->makeLegend(0.02, y);
00143 }
00144 
00145 void
00146 FWMuonDetailView::addSceneInfo(const reco::Muon *i, TEveElementList* tList)
00147 {
00148    // muon direction at vertex
00149 
00150    bool barrel = fabs(i->eta())<1.5;
00151    if ( i->isEnergyValid() ) barrel = fabs(i->calEnergy().ecal_position.eta()) < 1.5;
00152 
00153    Double_t x(0), y(0);
00154    Double_t delta(0.01);
00155    TEveStraightLineSet *direction = new TEveStraightLineSet("Direction at vertex");
00156    direction->SetPickable(kTRUE);
00157    direction->SetTitle("Muon direction at vertex");
00158    direction->SetPickable(kTRUE);
00159    if (barrel) {
00160      x = i->eta();
00161      y = i->phi();
00162    }else{
00163      x = 310*fabs(tan(i->theta()))*cos(i->phi());
00164      y = 310*fabs(tan(i->theta()))*sin(i->phi());
00165    }
00166    direction->AddLine(x-delta,y-delta,0,x+delta,y+delta,0);
00167    direction->AddLine(x-delta,y+delta,0,x+delta,y-delta,0);
00168    direction->SetLineColor(kYellow);
00169    direction->SetDepthTest(kFALSE);
00170    tList->AddElement(direction);
00171 
00172    if (! i->isEnergyValid() ) return;
00173 
00174    // ecal position
00175    TEveStraightLineSet *ecalposition = new TEveStraightLineSet("ecal position");
00176    ecalposition->SetPickable(kTRUE);
00177    ecalposition->SetTitle("Muon position at ECAL surface");
00178    if ( barrel ) {
00179       x = i->calEnergy().ecal_position.eta();
00180       y = i->calEnergy().ecal_position.phi();
00181    } else {
00182       x = i->calEnergy().ecal_position.x();
00183       y = i->calEnergy().ecal_position.y();
00184    }
00185    ecalposition->AddLine(x-delta,y,0,x+delta,y,0);
00186    ecalposition->AddLine(x,y-delta,0,x,y+delta,0);
00187    ecalposition->AddLine(x,y,0-delta,x,y,0+delta);
00188    ecalposition->SetLineColor(kRed);
00189    ecalposition->SetLineWidth(2);
00190    ecalposition->SetDepthTest(kFALSE);
00191    tList->AddElement(ecalposition);
00192 
00193    // hcal position
00194    TEveStraightLineSet *hcalposition = new TEveStraightLineSet("hcal position");
00195    hcalposition->SetPickable(kTRUE);
00196    hcalposition->SetTitle("Muon position at HCAL surface");
00197    if ( barrel ) {
00198       x = i->calEnergy().hcal_position.eta();
00199       y = i->calEnergy().hcal_position.phi();
00200    } else {
00201       x = i->calEnergy().hcal_position.x();
00202       y = i->calEnergy().hcal_position.y();
00203    }
00204    hcalposition->AddLine(x-delta,y,0,x+delta,y,0);
00205    hcalposition->AddLine(x,y-delta,0,x,y+delta,0);
00206    hcalposition->AddLine(x,y,0-delta,x,y,0+delta);
00207    hcalposition->SetLineColor(kBlue);
00208    hcalposition->SetLineWidth(2);
00209    hcalposition->SetDepthTest(kFALSE);
00210    tList->AddElement(hcalposition);
00211 
00212    // draw a line connecting the two positions
00213    TEveStraightLineSet *lines = new TEveStraightLineSet("Muon trajectory in ECAL","Muon trajectory in ECAL");
00214    lines->SetPickable(kTRUE);
00215    if ( barrel ) {
00216       lines->AddLine(i->calEnergy().ecal_position.eta(),
00217                      i->calEnergy().ecal_position.phi(),
00218                      0,
00219                      i->calEnergy().hcal_position.eta(),
00220                      i->calEnergy().hcal_position.phi(),
00221                      0);
00222    } else {
00223       lines->AddLine(i->calEnergy().ecal_position.x(),
00224                      i->calEnergy().ecal_position.y(),
00225                      0,
00226                      i->calEnergy().hcal_position.x(),
00227                      i->calEnergy().hcal_position.y(),
00228                      0);
00229    }
00230    lines->SetLineColor(kRed);
00231    lines->SetDepthTest(kFALSE);
00232    tList->AddElement(lines);
00233 }
00234 
00235 
00236 REGISTER_FWDETAILVIEW(FWMuonDetailView,Muon);