CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Fireworks/Eve/plugins/DummyEvelyser.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Fireworks/Eve
00004 // Class  :     DummyEvelyser
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Matevz Tadel
00010 //         Created:  Mon Jun 28 18:17:47 CEST 2010
00011 // $Id: DummyEvelyser.cc,v 1.7 2010/07/15 13:02:04 matevz Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 #include "FWCore/Framework/interface/EDAnalyzer.h"
00019 #include "FWCore/Framework/interface/MakerMacros.h"
00020 
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/EventSetup.h"
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 #include "FWCore/Framework/interface/ESWatcher.h"
00027 
00028 #include "FWCore/ServiceRegistry/interface/Service.h"
00029 #include "Fireworks/Eve/interface/EveService.h"
00030 
00031 #include "Fireworks/Geometry/interface/DisplayGeomRecord.h"
00032 
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 
00035 #include "Fireworks/Tracks/interface/TrackUtils.h"
00036 
00037 #include "TEveManager.h"
00038 #include "TEveTrack.h"
00039 #include "TEveTrackPropagator.h"
00040 
00041 #include "TGeoManager.h"
00042 #include "TGeoMatrix.h"
00043 #include "TEveGeoNode.h"
00044 #include "TEveTrans.h"
00045 #include "TEveScene.h"
00046 #include "TGLScenePad.h"
00047 #include "TGLRnrCtx.h"
00048 
00049 class DummyEvelyser : public edm::EDAnalyzer
00050 {
00051 public:
00052   explicit DummyEvelyser(const edm::ParameterSet&);
00053   ~DummyEvelyser();
00054 
00055 protected:
00056    TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
00057 
00058    
00059 
00060 private:
00061    virtual void beginJob();
00062    virtual void endJob();
00063 
00064    virtual void beginRun(const edm::Run&, const edm::EventSetup&);
00065    virtual void endRun  (const edm::Run&, const edm::EventSetup&);
00066 
00067    virtual void analyze(const edm::Event&, const edm::EventSetup&);
00068 
00069    edm::Service<EveService>  m_eve;
00070 
00071    edm::InputTag  m_trackTags;
00072    TEveElement   *m_geomList;
00073    TEveTrackList *m_trackList;
00074 
00075    edm::ESWatcher<DisplayGeomRecord> m_geomWatcher;
00076    void remakeGeometry(const DisplayGeomRecord& dgRec);
00077 };
00078 
00079 DEFINE_FWK_MODULE(DummyEvelyser);
00080 
00081 
00082 //
00083 // constants, enums and typedefs
00084 //
00085 
00086 //
00087 // static data member definitions
00088 //
00089 
00090 //==============================================================================
00091 // constructors and destructor
00092 //==============================================================================
00093 
00094 DummyEvelyser::DummyEvelyser(const edm::ParameterSet& iConfig) :
00095    m_eve(),
00096    m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
00097    m_geomList(0),
00098    m_trackList(0),
00099    m_geomWatcher(this, &DummyEvelyser::remakeGeometry)
00100 {}
00101 
00102 DummyEvelyser::~DummyEvelyser()
00103 {}
00104 
00105 
00106 //==============================================================================
00107 // Protected helpers
00108 //==============================================================================
00109 
00110 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
00111 {
00112    if (! gGeoManager->cd(path))
00113    {
00114       Warning("make_node", "Path '%s' not found.", path.Data());
00115       return 0;
00116    }
00117 
00118    TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
00119    tn->SetVisLevel(vis_level);
00120    if (global_cs)
00121    {
00122       tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
00123    }
00124    m_geomList->AddElement(tn);
00125 
00126    return tn;
00127 }
00128 
00129 
00130 //==============================================================================
00131 // member functions
00132 //==============================================================================
00133 
00134 void DummyEvelyser::beginJob()
00135 {
00136    printf("DummyEvelyser::beginJob\n");
00137 
00138    if (m_eve)
00139    {
00140       // Make a track-list container we'll hold on until the end of the job.
00141       // This allows us to preserve settings done by user via GUI.
00142       m_trackList = new TEveTrackList("Tracks"); 
00143       m_trackList->SetMainColor(6);
00144       m_trackList->SetMarkerColor(kYellow);
00145       m_trackList->SetMarkerStyle(4);
00146       m_trackList->SetMarkerSize(0.5);
00147 
00148       m_trackList->IncDenyDestroy();
00149 
00150       TEveTrackPropagator *prop = m_trackList->GetPropagator();
00151       prop->SetStepper(TEveTrackPropagator::kRungeKutta);
00152       // Use simplified magnetic field provided by EveService.
00153       m_eve->setupFieldForPropagator(prop);
00154    }
00155 }
00156 
00157 void DummyEvelyser::endJob()
00158 {
00159    printf("DummyEvelyser::endJob\n");
00160 
00161    if (m_trackList)
00162    {
00163       m_trackList->DecDenyDestroy();
00164       m_trackList = 0;
00165    }
00166 }
00167 
00168 //------------------------------------------------------------------------------
00169 
00170 void DummyEvelyser::beginRun(const edm::Run&, const edm::EventSetup& iSetup)
00171 {
00172    printf("DummyEvelyser::beginRun\n");
00173 
00174    if (m_eve)
00175    {
00176       m_geomList = new TEveElementList("DummyEvelyzer Geom");
00177       m_eve->AddGlobalElement(m_geomList);
00178       m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
00179    }
00180 }
00181 
00182 void DummyEvelyser::endRun(const edm::Run&, const edm::EventSetup&)
00183 {
00184    printf("DummyEvelyser::endRun\n");
00185 }
00186 
00187 //------------------------------------------------------------------------------
00188 
00189 void DummyEvelyser::remakeGeometry(const DisplayGeomRecord& dgRec)
00190 {
00191    m_geomList->DestroyElements();
00192 
00193    edm::ESHandle<TGeoManager> geom;
00194    dgRec.get(geom);
00195    TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
00196 
00197    // To have a full one, all detectors in one top-node:
00198    // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
00199 
00200    make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", 1, kTRUE);
00201    make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1",   1, kTRUE);
00202    make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1",   1, kTRUE);
00203 }
00204 
00205 void DummyEvelyser::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00206 {
00207    printf("DummyEvelyser::analyze\n");
00208 
00209    if (m_eve)
00210    {
00211       // Remake geometry if it has changed.
00212       m_geomWatcher.check(iSetup);
00213 
00214 
00215       // Stripped down demo from Tracking twiki.
00216 
00217       using namespace edm;
00218 
00219       Handle<View<reco::Track> >  tracks;
00220       iEvent.getByLabel(m_trackTags, tracks);
00221 
00222       m_trackList->DestroyElements();
00223 
00224       // All top-level elements are removed from default event-store at
00225       // the end of each event.
00226       m_eve->AddElement(m_trackList);
00227 
00228       int cnt = 0;
00229       for (View<reco::Track>::const_iterator itTrack = tracks->begin();
00230            itTrack != tracks->end(); ++itTrack, ++cnt)
00231       {
00232          TEveTrack* trk = fireworks::prepareTrack(*itTrack, m_trackList->GetPropagator());
00233          trk->SetElementName (TString::Format("Track %d", cnt));
00234          trk->SetElementTitle(TString::Format("Track %d, pt=%.3f", cnt, itTrack->pt()));
00235          trk->MakeTrack();
00236          trk->SetAttLineAttMarker(m_trackList);
00237          m_trackList->AddElement(trk);
00238 
00239          // The display() function runs the GUI event-loop and shows
00240          // whatever has been registered so far to eve.
00241          // It returns when user presses the "Step" button (or "Continue" or
00242          // "Next Event").
00243          m_eve->display(std::string("DummyEvelyser::analyze done for:\n") + trk->GetName());
00244       }
00245    }
00246 }