Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:49

0001 
0002 // -*- C++ -*-
0003 //
0004 // Package:     Calo
0005 // Class  :     FWMuonDetailView
0006 //
0007 
0008 // ROOT includes
0009 #include "TLatex.h"
0010 #include "TEveCalo.h"
0011 #include "TEveStraightLineSet.h"
0012 #include "TEvePointSet.h"
0013 #include "TEveScene.h"
0014 #include "TEveViewer.h"
0015 #include "TGLViewer.h"
0016 #include "TCanvas.h"
0017 #include "TEveCaloLegoOverlay.h"
0018 #include "TRootEmbeddedCanvas.h"
0019 
0020 // Fireworks includes
0021 #include "Fireworks/Muons/plugins/FWMuonDetailView.h"
0022 #include "Fireworks/Calo/interface/FWECALDetailViewBuilder.h"
0023 #include "Fireworks/Core/interface/FWModelId.h"
0024 #include "Fireworks/Core/interface/FWEventItem.h"
0025 #include "Fireworks/Core/interface/FWColorManager.h"
0026 #include "Fireworks/Core/interface/FWGLEventHandler.h"
0027 
0028 #include "DataFormats/MuonReco/interface/Muon.h"
0029 //
0030 // constructors and destructor
0031 //
0032 FWMuonDetailView::FWMuonDetailView() : m_data(nullptr), m_builder(nullptr) {}
0033 
0034 FWMuonDetailView::~FWMuonDetailView() {
0035   m_eveViewer->GetGLViewer()->DeleteOverlayElements(TGLOverlayElement::kUser);
0036   if (m_data)
0037     m_data->DecDenyDestroy();
0038   delete m_builder;
0039 }
0040 
0041 //
0042 // member functions
0043 //
0044 void FWMuonDetailView::build(const FWModelId& id, const reco::Muon* iMuon) {
0045   if (nullptr == iMuon)
0046     return;
0047 
0048   double eta = iMuon->eta();
0049   double phi = iMuon->phi();
0050   if (iMuon->isEnergyValid()) {
0051     eta = iMuon->calEnergy().ecal_position.eta();
0052     phi = iMuon->calEnergy().ecal_position.phi();
0053   }
0054 
0055   m_builder = new FWECALDetailViewBuilder(id.item()->getEvent(), id.item()->getGeom(), eta, phi, 10);
0056 
0057   m_builder->showSuperClusters();
0058   if (iMuon->isEnergyValid()) {
0059     std::vector<DetId> ids;
0060     ids.push_back(iMuon->calEnergy().ecal_id);
0061     m_builder->setColor(kYellow, ids);
0062   }
0063 
0064   TEveCaloLego* lego = m_builder->build();
0065   m_data = lego->GetData();
0066   m_data->IncDenyDestroy();
0067   m_eveScene->AddElement(lego);
0068   addSceneInfo(iMuon, m_eveScene);
0069 
0070   // draw axis at the window corners
0071   TEveCaloLegoOverlay* overlay = new TEveCaloLegoOverlay();
0072   overlay->SetShowPlane(kFALSE);
0073   overlay->SetShowPerspective(kFALSE);
0074   overlay->SetCaloLego(lego);
0075   overlay->SetShowScales(false);  // temporary
0076   viewerGL()->AddOverlayElement(overlay);
0077 
0078   // set event handler and flip camera to top view at beginning
0079   viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
0080   FWGLEventHandler* eh = new FWGLEventHandler((TGWindow*)viewerGL()->GetGLWidget(), (TObject*)viewerGL(), lego);
0081   viewerGL()->SetEventHandler(eh);
0082 
0083   viewerGL()->ResetCamerasAfterNextUpdate();
0084   viewerGL()->UpdateScene(kFALSE);
0085   gEve->Redraw3D();
0086 
0087   setTextInfo(id, iMuon);
0088 }
0089 
0090 void FWMuonDetailView::setTextInfo(const FWModelId& id, const reco::Muon* muon) {
0091   m_infoCanvas->cd();
0092   double y0 = 0.95;
0093   double x0 = 0.02;
0094 
0095   TLatex* latex = new TLatex(x0, y0, "");
0096   const double textsize(0.05);
0097   latex->SetTextSize(2 * textsize);
0098 
0099   float_t x = x0;
0100   float y = y0;
0101   float fontsize = latex->GetTextSize() * 0.6;
0102 
0103   latex->DrawLatex(x, y, id.item()->modelName(id.index()).c_str());
0104   y -= fontsize;
0105   latex->SetTextSize(textsize);
0106   fontsize = latex->GetTextSize() * 0.6;
0107 
0108   latex->DrawLatex(
0109       x, y, Form(" p_{T} = %.1f GeV, #eta = %0.2f, #varphi = %0.2f", muon->pt(), muon->eta(), muon->phi()));
0110   y -= fontsize;
0111   // summary
0112   if (muon->charge() > 0)
0113     latex->DrawLatex(x, y, " charge = +1");
0114   else
0115     latex->DrawLatex(x, y, " charge = -1");
0116   y -= fontsize;
0117 
0118   if (muon->isEnergyValid()) {
0119     // delta phi/eta in
0120     latex->DrawLatex(x, y, "ECAL energy in:");
0121     y -= fontsize;
0122     latex->DrawLatex(x, y, Form(" crossed crystalls = %.3f", muon->calEnergy().em));
0123     y -= fontsize;
0124     latex->DrawLatex(x, y, Form(" 3x3 crystall shape = %.3f", muon->calEnergy().emS9));
0125     y -= fontsize;
0126     latex->DrawLatex(x, y, Form(" 5x5 crystall shape = %.3f", muon->calEnergy().emS25));
0127   }
0128   m_builder->makeLegend(0.02, y);
0129 }
0130 
0131 void FWMuonDetailView::addSceneInfo(const reco::Muon* i, TEveElementList* tList) {
0132   // muon direction at vertex
0133 
0134   bool barrel = fabs(i->eta()) < 1.5;
0135   if (i->isEnergyValid())
0136     barrel = fabs(i->calEnergy().ecal_position.eta()) < 1.5;
0137 
0138   Double_t x(0), y(0);
0139   Double_t delta(0.01);
0140   TEveStraightLineSet* direction = new TEveStraightLineSet("Direction at vertex");
0141   direction->SetPickable(kTRUE);
0142   direction->SetTitle("Muon direction at vertex");
0143   direction->SetPickable(kTRUE);
0144   if (barrel) {
0145     x = i->eta();
0146     y = i->phi();
0147   } else {
0148     x = 310 * fabs(tan(i->theta())) * cos(i->phi());
0149     y = 310 * fabs(tan(i->theta())) * sin(i->phi());
0150   }
0151   direction->AddLine(x - delta, y - delta, 0, x + delta, y + delta, 0);
0152   direction->AddLine(x - delta, y + delta, 0, x + delta, y - delta, 0);
0153   direction->SetLineColor(kYellow);
0154   direction->SetDepthTest(kFALSE);
0155   tList->AddElement(direction);
0156 
0157   if (!i->isEnergyValid())
0158     return;
0159 
0160   // ecal position
0161   TEveStraightLineSet* ecalposition = new TEveStraightLineSet("ecal position");
0162   ecalposition->SetPickable(kTRUE);
0163   ecalposition->SetTitle("Muon position at ECAL surface");
0164   if (barrel) {
0165     x = i->calEnergy().ecal_position.eta();
0166     y = i->calEnergy().ecal_position.phi();
0167   } else {
0168     x = i->calEnergy().ecal_position.x();
0169     y = i->calEnergy().ecal_position.y();
0170   }
0171   ecalposition->AddLine(x - delta, y, 0, x + delta, y, 0);
0172   ecalposition->AddLine(x, y - delta, 0, x, y + delta, 0);
0173   ecalposition->AddLine(x, y, 0 - delta, x, y, 0 + delta);
0174   ecalposition->SetLineColor(kRed);
0175   ecalposition->SetLineWidth(2);
0176   ecalposition->SetDepthTest(kFALSE);
0177   tList->AddElement(ecalposition);
0178 
0179   // hcal position
0180   TEveStraightLineSet* hcalposition = new TEveStraightLineSet("hcal position");
0181   hcalposition->SetPickable(kTRUE);
0182   hcalposition->SetTitle("Muon position at HCAL surface");
0183   if (barrel) {
0184     x = i->calEnergy().hcal_position.eta();
0185     y = i->calEnergy().hcal_position.phi();
0186   } else {
0187     x = i->calEnergy().hcal_position.x();
0188     y = i->calEnergy().hcal_position.y();
0189   }
0190   hcalposition->AddLine(x - delta, y, 0, x + delta, y, 0);
0191   hcalposition->AddLine(x, y - delta, 0, x, y + delta, 0);
0192   hcalposition->AddLine(x, y, 0 - delta, x, y, 0 + delta);
0193   hcalposition->SetLineColor(kBlue);
0194   hcalposition->SetLineWidth(2);
0195   hcalposition->SetDepthTest(kFALSE);
0196   tList->AddElement(hcalposition);
0197 
0198   // draw a line connecting the two positions
0199   TEveStraightLineSet* lines = new TEveStraightLineSet("Muon trajectory in ECAL", "Muon trajectory in ECAL");
0200   lines->SetPickable(kTRUE);
0201   if (barrel) {
0202     lines->AddLine(i->calEnergy().ecal_position.eta(),
0203                    i->calEnergy().ecal_position.phi(),
0204                    0,
0205                    i->calEnergy().hcal_position.eta(),
0206                    i->calEnergy().hcal_position.phi(),
0207                    0);
0208   } else {
0209     lines->AddLine(i->calEnergy().ecal_position.x(),
0210                    i->calEnergy().ecal_position.y(),
0211                    0,
0212                    i->calEnergy().hcal_position.x(),
0213                    i->calEnergy().hcal_position.y(),
0214                    0);
0215   }
0216   lines->SetLineColor(kRed);
0217   lines->SetDepthTest(kFALSE);
0218   tList->AddElement(lines);
0219 }
0220 
0221 REGISTER_FWDETAILVIEW(FWMuonDetailView, Muon);
0222 /*
0223 REGISTER_FWDETAILVIEW(FWMuonDetailView,Muon,reducedEGamma);
0224 REGISTER_FWDETAILVIEW(FWMuonDetailView,Muon,ecalRecHit);
0225 REGISTER_FWDETAILVIEW(FWMuonDetailView,Muon,reducedEcalRecHitsEB);
0226 */