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 
34 
36 
37 #include "TEveManager.h"
38 #include "TEveTrack.h"
39 #include "TEveTrackPropagator.h"
40 
41 #include "TGeoManager.h"
42 #include "TGeoMatrix.h"
43 #include "TEveGeoNode.h"
44 #include "TEveTrans.h"
45 #include "TEveScene.h"
46 #include "TGLScenePad.h"
47 #include "TGLRnrCtx.h"
48 
50 {
51 public:
52  explicit DummyEvelyser(const edm::ParameterSet&);
53  ~DummyEvelyser() override;
55 protected:
56  TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
57 
58 
59 
60 private:
61  void beginJob() override;
62  void endJob() override;
63 
64  void beginRun(const edm::Run&, const edm::EventSetup&) override;
65  void endRun (const edm::Run&, const edm::EventSetup&) override;
66 
67  void analyze(const edm::Event&, const edm::EventSetup&) override;
68 
70 
72  TEveElement *m_geomList;
73  TEveTrackList *m_trackList;
74 
76  void remakeGeometry(const DisplayGeomRecord& dgRec);
77 };
78 
80 
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //==============================================================================
91 // constructors and destructor
92 //==============================================================================
93 
95  m_eve(),
96  m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
100 {
101  trackCollectionToken_ = consumes<reco::TrackCollection >(m_trackTags);
102 }
103 
105 {}
106 
107 
108 //==============================================================================
109 // Protected helpers
110 //==============================================================================
111 
112 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs)
113 {
114  if (! gGeoManager->cd(path))
115  {
116  Warning("make_node", "Path '%s' not found.", path.Data());
117  return nullptr;
118  }
119 
120  TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
121  tn->SetVisLevel(vis_level);
122  if (global_cs)
123  {
124  tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
125  }
126  m_geomList->AddElement(tn);
127 
128  return tn;
129 }
130 
131 
132 //==============================================================================
133 // member functions
134 //==============================================================================
135 
137 {
138  printf("DummyEvelyser::beginJob\n");
139 
140  if (m_eve)
141  {
142  // Make a track-list container we'll hold on until the end of the job.
143  // This allows us to preserve settings done by user via GUI.
144  m_trackList = new TEveTrackList("Tracks");
145  m_trackList->SetMainColor(6);
146  m_trackList->SetMarkerColor(kYellow);
147  m_trackList->SetMarkerStyle(4);
148  m_trackList->SetMarkerSize(0.5);
149 
150  m_trackList->IncDenyDestroy();
151 
152  TEveTrackPropagator *prop = m_trackList->GetPropagator();
153  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
154  // Use simplified magnetic field provided by EveService.
156  }
157 }
158 
160 {
161  printf("DummyEvelyser::endJob\n");
162 
163  if (m_trackList)
164  {
165  m_trackList->DecDenyDestroy();
166  m_trackList = nullptr;
167  }
168 }
169 
170 //------------------------------------------------------------------------------
171 
173 {
174  printf("DummyEvelyser::beginRun\n");
175 
176  if (m_eve)
177  {
178  m_geomList = new TEveElementList("DummyEvelyzer Geom");
180  m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
181  }
182 }
183 
185 {
186  printf("DummyEvelyser::endRun\n");
187 }
188 
189 //------------------------------------------------------------------------------
190 
192 {
193  m_geomList->DestroyElements();
194 
196  dgRec.get(geom);
197  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
198 
199  // To have a full one, all detectors in one top-node:
200  // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
201 
202  make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", 1, kTRUE);
203  make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1", 1, kTRUE);
204  make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1", 1, kTRUE);
205 }
206 
208 {
209  printf("DummyEvelyser::analyze\n");
210 
212  iEvent.getByToken(trackCollectionToken_, trackHandle);
213  const reco::TrackCollection trackCollection = *(trackHandle.product());
214  if (!trackHandle.isValid()) {
215  edm::LogError("DummyEvelyser")
216  << "Error! Can't get Track collection "
217  << std::endl;
218  return;
219  }
220 
221  if (m_eve)
222  {
223  // Remake geometry if it has changed.
224  m_geomWatcher.check(iSetup);
225 
226  // Stripped down demo from Tracking twiki.
227 
228  using namespace edm;
229 
230  m_trackList->DestroyElements();
231 
232  // All top-level elements are removed from default event-store at
233  // the end of each event.
235 
236  int cnt = 0;
237 
238  for (auto itTrack = trackCollection.begin();
239  itTrack != trackCollection.end(); ++itTrack, ++cnt)
240  {
241  TEveTrack* trk = fireworks::prepareTrack(*itTrack, m_trackList->GetPropagator());
242  trk->SetElementName (TString::Format("Track %d", cnt));
243  trk->SetElementTitle(TString::Format("Track %d, pt=%.3f", cnt, itTrack->pt()));
244  trk->MakeTrack();
245 
246  trk->SetAttLineAttMarker(m_trackList);
247  m_trackList->AddElement(trk);
248  }
249 
250 
251  // The display() function runs the GUI event-loop and shows
252  // whatever has been registered so far to eve.
253  // It returns when user presses the "Step" button (or "Continue" or
254  // "Next Event").
255  m_eve->display(Form("DummyEvelyser::analyze done for %d tracks\n", m_trackList->NumChildren()) );
256  }
257 }
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
#define nullptr
TEveElement * m_geomList
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
DummyEvelyser(const edm::ParameterSet &)
void beginJob() override
int iEvent
Definition: GenABIO.cc:224
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
void endJob() override
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:74
void display(const std::string &info="")
Definition: EveService.cc:250
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
T const * product() const
Definition: Handle.h:74
TEveManager * getManager()
Definition: EveService.cc:269
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: EveService.cc:279
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
edm::InputTag m_trackTags
HLT enums.
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:45