CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DisplayGeom.cc
Go to the documentation of this file.
1 
5 
12 
15 
17 
19 
21 
22 #include "TEveManager.h"
23 #include "TEveTrack.h"
24 #include "TEveTrackPropagator.h"
25 
26 #include "TGeoManager.h"
27 #include "TGeoMatrix.h"
28 #include "TEveGeoNode.h"
29 #include "TEveTrans.h"
30 #include "TEveScene.h"
31 #include "TGLScenePad.h"
32 #include "TGLRnrCtx.h"
33 #include "TEvePointSet.h"
34 #include "TRandom.h"
35 #include "TEveUtil.h"
36 
37 // class decleration
38 //
39 
40 class DisplayGeom : public edm::EDAnalyzer {
41 
42 public:
43  explicit DisplayGeom(const edm::ParameterSet&);
44  ~DisplayGeom();
45 
46 protected:
47  TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
48 
49 
50 private:
51  virtual void beginJob() ;
52  virtual void analyze(const edm::Event&, const edm::EventSetup&);
53 
54  virtual void endJob() ;
55 
57 
58  TEveElement *m_geomList;
59 
60  int m_level;
61 
62  bool m_MF;
63 
65 
66  void remakeGeometry(const DisplayGeomRecord& dgRec);
67 
68 };
69 
71 
73  m_eve(),
74  m_geomList(0),
75  m_geomWatcher(this, &DisplayGeom::remakeGeometry)
76 {
77  m_level = iConfig.getUntrackedParameter<int>( "level", 2);
78  m_MF = iConfig.getUntrackedParameter<int>( "MF", false);
79 }
80 
81 
83 {
84 }
85 
86 
87 //==============================================================================
88 // Protected helpers
89 //==============================================================================
90 
91 TEveGeoTopNode* DisplayGeom::make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
92 {
93  if (! gGeoManager->cd(path))
94  {
95  Warning("make_node", "Path '%s' not found.", path.Data());
96  return 0;
97  }
98 
99  TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
100  tn->SetVisLevel(vis_level);
101  if (global_cs)
102  {
103  tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
104  }
105  m_geomList->AddElement(tn);
106 
107  return tn;
108 }
109 
110 
111 //==============================================================================
112 // member functions
113 //==============================================================================
114 
115 
116 void
118 {
119  if (m_eve)
120  {
121  // Remake geometry if it has changed.
122  m_geomWatcher.check(iSetup);
123 
124  // Add a test obj
125  if (!gRandom)
126  gRandom = new TRandom(0);
127  TRandom& r= *gRandom;
128 
129  Float_t s = 100;
130 
131  TEvePointSet* ps = new TEvePointSet();
132  ps->SetOwnIds(kTRUE);
133  for(Int_t i = 0; i< 100; i++)
134  {
135  ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
136  ps->SetPointId(new TNamed(Form("Point %d", i), ""));
137  }
138 
139  ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
140  ps->SetMarkerSize(r.Uniform(1, 2));
141  ps->SetMarkerStyle(4);
142  m_eve->AddElement(ps);
143  }
144 }
145 
146 // ------------ method called once each job just before starting event loop ------------
147 void
149 {
150  if (m_eve)
151  {
152  m_geomList = new TEveElementList("Display Geom");
154  m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
155  }
156 }
157 
158 // ------------ method called once each job just after ending the event loop ------------
159 void
161 }
162 
163 //------------------------------------------------------------------------------
165 {
166  m_geomList->DestroyElements();
167 
169  dgRec.get(geom);
170  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
171 
172  // To have a full one, all detectors in one top-node:
173  // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
174 
175  if (m_MF)
176  {
177  make_node("/cms:World_1", m_level, kTRUE);
178  }
179  else
180  {
181  make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", m_level, kTRUE);
182  make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1", m_level, kTRUE);
183  make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1", m_level, kTRUE);
184  }
185 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void endJob()
Definition: DisplayGeom.cc:160
void remakeGeometry(const DisplayGeomRecord &dgRec)
Definition: DisplayGeom.cc:164
DisplayGeom(const edm::ParameterSet &)
Definition: DisplayGeom.cc:72
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void beginJob()
Definition: DisplayGeom.cc:148
edm::Service< EveService > m_eve
Definition: DisplayGeom.cc:56
TEveGeoTopNode * make_node(const TString &path, Int_t vis_level, Bool_t global_cs)
Definition: DisplayGeom.cc:91
list path
Definition: scaleCards.py:51
int iEvent
Definition: GenABIO.cc:243
void get(HolderT &iHolder) const
TEveManager * getManager()
Definition: EveService.cc:263
T const * product() const
Definition: ESHandle.h:62
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
void AddElement(TEveElement *el)
Definition: EveService.cc:282
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
Definition: DisplayGeom.cc:64
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: DisplayGeom.cc:117
TEveElement * m_geomList
Definition: DisplayGeom.cc:58
void AddGlobalElement(TEveElement *el)
Definition: EveService.cc:287