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 
49 class DummyEvelyser : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
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 private:
58  void beginJob() override;
59  void endJob() override;
60 
61  void beginRun(const edm::Run&, const edm::EventSetup&) override;
62  void endRun(const edm::Run&, const edm::EventSetup&) override;
63 
64  void analyze(const edm::Event&, const edm::EventSetup&) override;
65 
67 
69  TEveElement* m_geomList;
70  TEveTrackList* m_trackList;
71 
75  void remakeGeometry(const DisplayGeomRecord& dgRec);
76 };
77 
79 
80 //
81 // constants, enums and typedefs
82 //
83 
84 //
85 // static data member definitions
86 //
87 
88 //==============================================================================
89 // constructors and destructor
90 //==============================================================================
91 
93  : m_eve(),
94  m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
95  m_geomList(nullptr),
96  m_trackList(nullptr),
97  geomToken_(esConsumes()),
98  m_geomWatcher(this, &DummyEvelyser::remakeGeometry) {
99  trackCollectionToken_ = consumes<reco::TrackCollection>(m_trackTags);
100 }
101 
103 
104 //==============================================================================
105 // Protected helpers
106 //==============================================================================
107 
108 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs) {
109  if (!gGeoManager->cd(path)) {
110  Warning("make_node", "Path '%s' not found.", path.Data());
111  return nullptr;
112  }
113 
114  TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
115  tn->SetVisLevel(vis_level);
116  if (global_cs) {
117  tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
118  }
119  m_geomList->AddElement(tn);
120 
121  return tn;
122 }
123 
124 //==============================================================================
125 // member functions
126 //==============================================================================
127 
129  printf("DummyEvelyser::beginJob\n");
130 
131  if (m_eve) {
132  // Make a track-list container we'll hold on until the end of the job.
133  // This allows us to preserve settings done by user via GUI.
134  m_trackList = new TEveTrackList("Tracks");
135  m_trackList->SetMainColor(6);
136  m_trackList->SetMarkerColor(kYellow);
137  m_trackList->SetMarkerStyle(4);
138  m_trackList->SetMarkerSize(0.5);
139 
140  m_trackList->IncDenyDestroy();
141 
142  TEveTrackPropagator* prop = m_trackList->GetPropagator();
143  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
144  // Use simplified magnetic field provided by EveService.
146  }
147 }
148 
150  printf("DummyEvelyser::endJob\n");
151 
152  if (m_trackList) {
153  m_trackList->DecDenyDestroy();
154  m_trackList = nullptr;
155  }
156 }
157 
158 //------------------------------------------------------------------------------
159 
160 void DummyEvelyser::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
161  printf("DummyEvelyser::beginRun\n");
162 
163  if (m_eve) {
164  m_geomList = new TEveElementList("DummyEvelyzer Geom");
166  m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
167  }
168 }
169 
170 void DummyEvelyser::endRun(const edm::Run&, const edm::EventSetup&) { printf("DummyEvelyser::endRun\n"); }
171 
172 //------------------------------------------------------------------------------
173 
175  m_geomList->DestroyElements();
176 
177  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(&dgRec.get(geomToken_)));
178 
179  // To have a full one, all detectors in one top-node:
180  // make_node("/cms:World_1/cms:CMSE_1", 4, kTRUE);
181 
182  make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", 1, kTRUE);
183  make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1", 1, kTRUE);
184  make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1", 1, kTRUE);
185 }
186 
188  printf("DummyEvelyser::analyze\n");
189 
191  iEvent.getByToken(trackCollectionToken_, trackHandle);
192  const reco::TrackCollection trackCollection = *(trackHandle.product());
193  if (!trackHandle.isValid()) {
194  edm::LogError("DummyEvelyser") << "Error! Can't get Track collection " << std::endl;
195  return;
196  }
197 
198  if (m_eve) {
199  // Remake geometry if it has changed.
200  m_geomWatcher.check(iSetup);
201 
202  // Stripped down demo from Tracking twiki.
203 
204  using namespace edm;
205 
206  m_trackList->DestroyElements();
207 
208  // All top-level elements are removed from default event-store at
209  // the end of each event.
211 
212  int cnt = 0;
213 
214  for (auto itTrack = trackCollection.begin(); itTrack != trackCollection.end(); ++itTrack, ++cnt) {
215  TEveTrack* trk = fireworks::prepareTrack(*itTrack, m_trackList->GetPropagator());
216  trk->SetElementName(TString::Format("Track %d", cnt));
217  trk->SetElementTitle(TString::Format("Track %d, pt=%.3f", cnt, itTrack->pt()));
218  trk->MakeTrack();
219 
220  trk->SetAttLineAttMarker(m_trackList);
221  m_trackList->AddElement(trk);
222  }
223 
224  // The display() function runs the GUI event-loop and shows
225  // whatever has been registered so far to eve.
226  // It returns when user presses the "Step" button (or "Continue" or
227  // "Next Event").
228  m_eve->display(Form("DummyEvelyser::analyze done for %d tracks\n", m_trackList->NumChildren()));
229  }
230 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
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:62
T const * product() const
Definition: Handle.h:70
TEveElement * m_geomList
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
DummyEvelyser(const edm::ParameterSet &)
Log< level::Error, false > LogError
void beginJob() override
int iEvent
Definition: GenABIO.cc:224
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
void endJob() override
const edm::ESGetToken< TGeoManager, DisplayGeomRecord > geomToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginRun(const edm::Run &, const edm::EventSetup &) override
void display(const std::string &info="")
Definition: EveService.cc:232
trackCollection
Definition: JetHT_cfg.py:50
edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
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:249
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: EveService.cc:255
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
bool isValid() const
Definition: HandleBase.h:70
edm::InputTag m_trackTags
HLT enums.
void AddElement(TEveElement *el)
Definition: EveService.cc:261
TEveTrackList * m_trackList
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
void remakeGeometry(const DisplayGeomRecord &dgRec)
void AddGlobalElement(TEveElement *el)
Definition: EveService.cc:263
Definition: Run.h:45