CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Fireworks/Geometry/plugins/DisplayGeom.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/interface/Frameworkfwd.h"
00003 #include "FWCore/Framework/interface/EDAnalyzer.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/ESWatcher.h"
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "Fireworks/Eve/interface/EveService.h"
00015 
00016 #include "Fireworks/Geometry/interface/DisplayGeomRecord.h"
00017 
00018 #include "DataFormats/TrackReco/interface/Track.h"
00019 
00020 #include "Fireworks/Tracks/interface/TrackUtils.h"
00021 
00022 #include "TEveManager.h"
00023 #include "TEveTrack.h"
00024 #include "TEveTrackPropagator.h"
00025 
00026 #include "TGeoManager.h"
00027 #include "TGeoMatrix.h"
00028 #include "TEveGeoNode.h"
00029 #include "TEveTrans.h"
00030 #include "TEveScene.h"
00031 #include "TGLScenePad.h"
00032 #include "TGLRnrCtx.h"
00033 #include "TEvePointSet.h"
00034 #include "TRandom.h"
00035 #include "TEveUtil.h"
00036 
00037 // class decleration
00038 //
00039        
00040 class DisplayGeom : public edm::EDAnalyzer {
00041 
00042 public:
00043    explicit DisplayGeom(const edm::ParameterSet&);
00044    ~DisplayGeom();
00045 
00046 protected:
00047    TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
00048 
00049   
00050 private:
00051    virtual void beginJob() ;
00052    virtual void analyze(const edm::Event&, const edm::EventSetup&);
00053 
00054    virtual void endJob() ;
00055 
00056    edm::Service<EveService>  m_eve;
00057 
00058    TEveElement   *m_geomList;
00059 
00060    int m_level;
00061 
00062    bool m_MF;
00063 
00064    edm::ESWatcher<DisplayGeomRecord> m_geomWatcher;
00065 
00066    void remakeGeometry(const DisplayGeomRecord& dgRec);
00067 
00068 };
00069 
00070 DEFINE_FWK_MODULE(DisplayGeom);
00071 
00072 DisplayGeom::DisplayGeom(const edm::ParameterSet& iConfig):
00073    m_eve(),
00074    m_geomList(0),
00075    m_geomWatcher(this, &DisplayGeom::remakeGeometry)
00076 {
00077    m_level =  iConfig.getUntrackedParameter<int>( "level", 2);
00078    m_MF    =  iConfig.getUntrackedParameter<int>( "MF", false);
00079 }
00080 
00081 
00082 DisplayGeom::~DisplayGeom()
00083 {
00084 }
00085 
00086 
00087 //==============================================================================
00088 // Protected helpers
00089 //==============================================================================
00090 
00091 TEveGeoTopNode* DisplayGeom::make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
00092 {
00093    if (! gGeoManager->cd(path))
00094    {
00095       Warning("make_node", "Path '%s' not found.", path.Data());
00096       return 0;
00097    }
00098 
00099    TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
00100    tn->SetVisLevel(vis_level);
00101    if (global_cs)
00102    {
00103       tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
00104    }
00105    m_geomList->AddElement(tn);
00106 
00107    return tn;
00108 }
00109 
00110 
00111 //==============================================================================
00112 // member functions
00113 //==============================================================================
00114 
00115 
00116 void
00117 DisplayGeom::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00118 {
00119    if (m_eve)
00120    {
00121       // Remake geometry if it has changed.
00122       m_geomWatcher.check(iSetup);
00123 
00124       // Add a test obj
00125       if (!gRandom)
00126          gRandom = new TRandom(0);
00127       TRandom& r= *gRandom;
00128 
00129       Float_t s = 100;
00130 
00131       TEvePointSet* ps = new TEvePointSet();
00132       ps->SetOwnIds(kTRUE);
00133       for(Int_t i = 0; i< 100; i++)
00134       {
00135          ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
00136          ps->SetPointId(new TNamed(Form("Point %d", i), ""));
00137       }
00138 
00139       ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
00140       ps->SetMarkerSize(r.Uniform(1, 2));
00141       ps->SetMarkerStyle(4);
00142       m_eve->AddElement(ps);
00143    }
00144 }
00145 
00146 // ------------ method called once each job just before starting event loop  ------------
00147 void 
00148 DisplayGeom::beginJob()
00149 { 
00150    if (m_eve)
00151    {
00152       m_geomList = new TEveElementList("Display Geom");
00153       m_eve->AddGlobalElement(m_geomList);
00154       m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
00155    }
00156 }
00157 
00158 // ------------ method called once each job just after ending the event loop  ------------
00159 void 
00160 DisplayGeom::endJob() {
00161 }
00162 
00163 //------------------------------------------------------------------------------
00164 void DisplayGeom::remakeGeometry(const DisplayGeomRecord& dgRec)
00165 {
00166    m_geomList->DestroyElements();
00167 
00168    edm::ESHandle<TGeoManager> geom;
00169    dgRec.get(geom);
00170    TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
00171 
00172    // To have a full one, all detectors in one top-node:
00173    // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
00174 
00175    if (m_MF)
00176    {
00177       make_node("/cms:World_1", m_level, kTRUE);
00178    }
00179    else
00180    {
00181       make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", m_level, kTRUE);
00182       make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1",   m_level, kTRUE);
00183       make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1",   m_level, kTRUE);
00184    }
00185 }