CMS 3D CMS Logo

DummyEvelyser.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Fireworks/Eve
4 // Class : DummyEvelyser
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Matevz Tadel
10 // Created: Mon Jun 28 18:17:47 CEST 2010
11 //
12 
13 // system include files
14 
15 // user include files
19 
26 
29 
31 
33 
35 
36 #include "TEveManager.h"
37 #include "TEveTrack.h"
38 #include "TEveTrackPropagator.h"
39 
40 #include "TGeoManager.h"
41 #include "TGeoMatrix.h"
42 #include "TEveGeoNode.h"
43 #include "TEveTrans.h"
44 #include "TEveScene.h"
45 #include "TGLScenePad.h"
46 #include "TGLRnrCtx.h"
47 
49 {
50 public:
51  explicit DummyEvelyser(const edm::ParameterSet&);
52  ~DummyEvelyser() override;
53 
54 protected:
55  TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
56 
57 
58 
59 private:
60  void beginJob() override;
61  void endJob() override;
62 
63  void beginRun(const edm::Run&, const edm::EventSetup&) override;
64  void endRun (const edm::Run&, const edm::EventSetup&) override;
65 
66  void analyze(const edm::Event&, const edm::EventSetup&) override;
67 
69 
71  TEveElement *m_geomList;
72  TEveTrackList *m_trackList;
73 
75  void remakeGeometry(const DisplayGeomRecord& dgRec);
76 };
77 
79 
80 
81 //
82 // constants, enums and typedefs
83 //
84 
85 //
86 // static data member definitions
87 //
88 
89 //==============================================================================
90 // constructors and destructor
91 //==============================================================================
92 
94  m_eve(),
95  m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
99 {}
100 
102 {}
103 
104 
105 //==============================================================================
106 // Protected helpers
107 //==============================================================================
108 
109 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
110 {
111  if (! gGeoManager->cd(path))
112  {
113  Warning("make_node", "Path '%s' not found.", path.Data());
114  return nullptr;
115  }
116 
117  TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
118  tn->SetVisLevel(vis_level);
119  if (global_cs)
120  {
121  tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
122  }
123  m_geomList->AddElement(tn);
124 
125  return tn;
126 }
127 
128 
129 //==============================================================================
130 // member functions
131 //==============================================================================
132 
134 {
135  printf("DummyEvelyser::beginJob\n");
136 
137  if (m_eve)
138  {
139  // Make a track-list container we'll hold on until the end of the job.
140  // This allows us to preserve settings done by user via GUI.
141  m_trackList = new TEveTrackList("Tracks");
142  m_trackList->SetMainColor(6);
143  m_trackList->SetMarkerColor(kYellow);
144  m_trackList->SetMarkerStyle(4);
145  m_trackList->SetMarkerSize(0.5);
146 
147  m_trackList->IncDenyDestroy();
148 
149  TEveTrackPropagator *prop = m_trackList->GetPropagator();
150  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
151  // Use simplified magnetic field provided by EveService.
153  }
154 }
155 
157 {
158  printf("DummyEvelyser::endJob\n");
159 
160  if (m_trackList)
161  {
162  m_trackList->DecDenyDestroy();
163  m_trackList = nullptr;
164  }
165 }
166 
167 //------------------------------------------------------------------------------
168 
170 {
171  printf("DummyEvelyser::beginRun\n");
172 
173  if (m_eve)
174  {
175  m_geomList = new TEveElementList("DummyEvelyzer Geom");
177  m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
178  }
179 }
180 
182 {
183  printf("DummyEvelyser::endRun\n");
184 }
185 
186 //------------------------------------------------------------------------------
187 
189 {
190  m_geomList->DestroyElements();
191 
193  dgRec.get(geom);
194  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
195 
196  // To have a full one, all detectors in one top-node:
197  // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
198 
199  make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", 1, kTRUE);
200  make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1", 1, kTRUE);
201  make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1", 1, kTRUE);
202 }
203 
205 {
206  printf("DummyEvelyser::analyze\n");
207 
208  if (m_eve)
209  {
210  // Remake geometry if it has changed.
211  m_geomWatcher.check(iSetup);
212 
213 
214  // Stripped down demo from Tracking twiki.
215 
216  using namespace edm;
217 
219  iEvent.getByLabel(m_trackTags, tracks);
220 
221  m_trackList->DestroyElements();
222 
223  // All top-level elements are removed from default event-store at
224  // the end of each event.
226 
227  int cnt = 0;
228  for (View<reco::Track>::const_iterator itTrack = tracks->begin();
229  itTrack != tracks->end(); ++itTrack, ++cnt)
230  {
231  TEveTrack* trk = fireworks::prepareTrack(*itTrack, m_trackList->GetPropagator());
232  trk->SetElementName (TString::Format("Track %d", cnt));
233  trk->SetElementTitle(TString::Format("Track %d, pt=%.3f", cnt, itTrack->pt()));
234  trk->MakeTrack();
235  trk->SetAttLineAttMarker(m_trackList);
236  m_trackList->AddElement(trk);
237 
238  // The display() function runs the GUI event-loop and shows
239  // whatever has been registered so far to eve.
240  // It returns when user presses the "Step" button (or "Continue" or
241  // "Next Event").
242  m_eve->display(std::string("DummyEvelyser::analyze done for:\n") + trk->GetName());
243  }
244  }
245 }
edm::Service< EveService > m_eve
void endRun(const edm::Run &, const edm::EventSetup &) override
TEveTrack * prepareTrack(const reco::Track &track, TEveTrackPropagator *propagator, const std::vector< TEveVector > &extraRefPoints=std::vector< TEveVector >())
Definition: TrackUtils.cc:63
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TEveElement * m_geomList
DummyEvelyser(const edm::ParameterSet &)
#define nullptr
void beginJob() override
int iEvent
Definition: GenABIO.cc:230
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
void endJob() override
void get(HolderT &iHolder) const
void beginRun(const edm::Run &, const edm::EventSetup &) override
void display(const std::string &info="")
Definition: EveService.cc:250
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
TEveGeoTopNode * make_node(const TString &path, Int_t vis_level, Bool_t global_cs)
~DummyEvelyser() override
void analyze(const edm::Event &, const edm::EventSetup &) override
TEveManager * getManager()
Definition: EveService.cc:269
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: EveService.cc:279
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::InputTag m_trackTags
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void AddElement(TEveElement *el)
Definition: EveService.cc:288
TEveTrackList * m_trackList
T const * product() const
Definition: ESHandle.h:86
void remakeGeometry(const DisplayGeomRecord &dgRec)
void AddGlobalElement(TEveElement *el)
Definition: EveService.cc:293
Definition: Run.h:43