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 public:
51  explicit DummyEvelyser(const edm::ParameterSet&);
52  ~DummyEvelyser() override;
54 
55 protected:
56  TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
57 
58 private:
59  void beginJob() override;
60  void endJob() override;
61 
62  void beginRun(const edm::Run&, const edm::EventSetup&) override;
63  void endRun(const edm::Run&, const edm::EventSetup&) override;
64 
65  void analyze(const edm::Event&, const edm::EventSetup&) override;
66 
68 
70  TEveElement* m_geomList;
71  TEveTrackList* m_trackList;
72 
74  void remakeGeometry(const DisplayGeomRecord& dgRec);
75 };
76 
78 
79 //
80 // constants, enums and typedefs
81 //
82 
83 //
84 // static data member definitions
85 //
86 
87 //==============================================================================
88 // constructors and destructor
89 //==============================================================================
90 
92  : m_eve(),
93  m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
94  m_geomList(nullptr),
95  m_trackList(nullptr),
96  m_geomWatcher(this, &DummyEvelyser::remakeGeometry) {
97  trackCollectionToken_ = consumes<reco::TrackCollection>(m_trackTags);
98 }
99 
101 
102 //==============================================================================
103 // Protected helpers
104 //==============================================================================
105 
106 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs) {
107  if (!gGeoManager->cd(path)) {
108  Warning("make_node", "Path '%s' not found.", path.Data());
109  return nullptr;
110  }
111 
112  TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
113  tn->SetVisLevel(vis_level);
114  if (global_cs) {
115  tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
116  }
117  m_geomList->AddElement(tn);
118 
119  return tn;
120 }
121 
122 //==============================================================================
123 // member functions
124 //==============================================================================
125 
127  printf("DummyEvelyser::beginJob\n");
128 
129  if (m_eve) {
130  // Make a track-list container we'll hold on until the end of the job.
131  // This allows us to preserve settings done by user via GUI.
132  m_trackList = new TEveTrackList("Tracks");
133  m_trackList->SetMainColor(6);
134  m_trackList->SetMarkerColor(kYellow);
135  m_trackList->SetMarkerStyle(4);
136  m_trackList->SetMarkerSize(0.5);
137 
138  m_trackList->IncDenyDestroy();
139 
140  TEveTrackPropagator* prop = m_trackList->GetPropagator();
141  prop->SetStepper(TEveTrackPropagator::kRungeKutta);
142  // Use simplified magnetic field provided by EveService.
144  }
145 }
146 
148  printf("DummyEvelyser::endJob\n");
149 
150  if (m_trackList) {
151  m_trackList->DecDenyDestroy();
152  m_trackList = nullptr;
153  }
154 }
155 
156 //------------------------------------------------------------------------------
157 
158 void DummyEvelyser::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
159  printf("DummyEvelyser::beginRun\n");
160 
161  if (m_eve) {
162  m_geomList = new TEveElementList("DummyEvelyzer Geom");
164  m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
165  }
166 }
167 
168 void DummyEvelyser::endRun(const edm::Run&, const edm::EventSetup&) { printf("DummyEvelyser::endRun\n"); }
169 
170 //------------------------------------------------------------------------------
171 
173  m_geomList->DestroyElements();
174 
176  dgRec.get(geom);
177  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
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 }
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
DummyEvelyser::m_trackList
TEveTrackList * m_trackList
Definition: DummyEvelyser.cc:71
DummyEvelyser::m_eve
edm::Service< EveService > m_eve
Definition: DummyEvelyser.cc:67
DummyEvelyser::DummyEvelyser
DummyEvelyser(const edm::ParameterSet &)
Definition: DummyEvelyser.cc:91
edm::Handle::product
T const * product() const
Definition: Handle.h:70
edm::ESWatcher< DisplayGeomRecord >
ESHandle.h
EveService::setupFieldForPropagator
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: EveService.cc:255
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
EveService::AddElement
void AddElement(TEveElement *el)
Definition: EveService.cc:261
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
DummyEvelyser::m_geomList
TEveElement * m_geomList
Definition: DummyEvelyser.cc:70
EveService::getManager
TEveManager * getManager()
Definition: EveService.cc:249
EDAnalyzer.h
edm::Handle< reco::TrackCollection >
TrackUtils.h
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
EveService::AddGlobalElement
void AddGlobalElement(TEveElement *el)
Definition: EveService.cc:263
DummyEvelyser::remakeGeometry
void remakeGeometry(const DisplayGeomRecord &dgRec)
Definition: DummyEvelyser.cc:172
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DummyEvelyser::trackCollectionToken_
edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
Definition: DummyEvelyser.cc:53
Service.h
DummyEvelyser::~DummyEvelyser
~DummyEvelyser() override
Definition: DummyEvelyser.cc:100
edm::ESHandle
Definition: DTSurvey.h:22
DummyEvelyser::endJob
void endJob() override
Definition: DummyEvelyser.cc:147
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
edm::ParameterSet
Definition: ParameterSet.h:47
duplicaterechits_cfi.trackCollection
trackCollection
Definition: duplicaterechits_cfi.py:4
Event.h
fireworks::prepareTrack
TEveTrack * prepareTrack(const reco::Track &track, TEveTrackPropagator *propagator, const std::vector< TEveVector > &extraRefPoints=std::vector< TEveVector >())
Definition: TrackUtils.cc:62
DummyEvelyser
Definition: DummyEvelyser.cc:49
edm::Service< EveService >
iEvent
int iEvent
Definition: GenABIO.cc:224
DummyEvelyser::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DummyEvelyser.cc:158
DummyEvelyser::m_geomWatcher
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
Definition: DummyEvelyser.cc:73
DummyEvelyser::beginJob
void beginJob() override
Definition: DummyEvelyser.cc:126
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EveService.h
InputTag.h
DummyEvelyser::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: DummyEvelyser.cc:168
DisplayGeomRecord.h
Frameworkfwd.h
ESWatcher.h
EventSetup.h
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ParameterSet.h
DummyEvelyser::m_trackTags
edm::InputTag m_trackTags
Definition: DummyEvelyser.cc:69
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
EveService::display
void display(const std::string &info="")
Definition: EveService.cc:232
edm::InputTag
Definition: InputTag.h:15
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
DummyEvelyser::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DummyEvelyser.cc:187
DummyEvelyser::make_node
TEveGeoTopNode * make_node(const TString &path, Int_t vis_level, Bool_t global_cs)
Definition: DummyEvelyser.cc:106
DisplayGeomRecord
Definition: DisplayGeomRecord.h:24