File indexing completed on 2024-04-06 12:11:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/InputTag.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/ESWatcher.h"
0026
0027 #include "FWCore/ServiceRegistry/interface/Service.h"
0028 #include "Fireworks/Eve/interface/EveService.h"
0029
0030 #include "Fireworks/Geometry/interface/DisplayGeomRecord.h"
0031
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034
0035 #include "Fireworks/Tracks/interface/TrackUtils.h"
0036
0037 #include "TEveManager.h"
0038 #include "TEveTrack.h"
0039 #include "TEveTrackPropagator.h"
0040
0041 #include "TGeoManager.h"
0042 #include "TGeoMatrix.h"
0043 #include "TEveGeoNode.h"
0044 #include "TEveTrans.h"
0045 #include "TEveScene.h"
0046 #include "TGLScenePad.h"
0047 #include "TGLRnrCtx.h"
0048
0049 class DummyEvelyser : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0050 public:
0051 explicit DummyEvelyser(const edm::ParameterSet&);
0052 ~DummyEvelyser() override;
0053
0054 protected:
0055 TEveGeoTopNode* make_node(const TString& path, Int_t vis_level, Bool_t global_cs);
0056
0057 private:
0058 void beginJob() override;
0059 void endJob() override;
0060
0061 void beginRun(const edm::Run&, const edm::EventSetup&) override;
0062 void endRun(const edm::Run&, const edm::EventSetup&) override;
0063
0064 void analyze(const edm::Event&, const edm::EventSetup&) override;
0065
0066 edm::Service<EveService> m_eve;
0067
0068 edm::InputTag m_trackTags;
0069 TEveElement* m_geomList;
0070 TEveTrackList* m_trackList;
0071
0072 edm::EDGetTokenT<reco::TrackCollection> trackCollectionToken_;
0073 const edm::ESGetToken<TGeoManager, DisplayGeomRecord> geomToken_;
0074 edm::ESWatcher<DisplayGeomRecord> m_geomWatcher;
0075 void remakeGeometry(const DisplayGeomRecord& dgRec);
0076 };
0077
0078 DEFINE_FWK_MODULE(DummyEvelyser);
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 DummyEvelyser::DummyEvelyser(const edm::ParameterSet& iConfig)
0093 : m_eve(),
0094 m_trackTags(iConfig.getUntrackedParameter<edm::InputTag>("tracks")),
0095 m_geomList(nullptr),
0096 m_trackList(nullptr),
0097 geomToken_(esConsumes()),
0098 m_geomWatcher(this, &DummyEvelyser::remakeGeometry) {
0099 trackCollectionToken_ = consumes<reco::TrackCollection>(m_trackTags);
0100 }
0101
0102 DummyEvelyser::~DummyEvelyser() {}
0103
0104
0105
0106
0107
0108 TEveGeoTopNode* DummyEvelyser::make_node(const TString& path, Int_t vis_level, Bool_t global_cs) {
0109 if (!gGeoManager->cd(path)) {
0110 Warning("make_node", "Path '%s' not found.", path.Data());
0111 return nullptr;
0112 }
0113
0114 TEveGeoTopNode* tn = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
0115 tn->SetVisLevel(vis_level);
0116 if (global_cs) {
0117 tn->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
0118 }
0119 m_geomList->AddElement(tn);
0120
0121 return tn;
0122 }
0123
0124
0125
0126
0127
0128 void DummyEvelyser::beginJob() {
0129 printf("DummyEvelyser::beginJob\n");
0130
0131 if (m_eve) {
0132
0133
0134 m_trackList = new TEveTrackList("Tracks");
0135 m_trackList->SetMainColor(6);
0136 m_trackList->SetMarkerColor(kYellow);
0137 m_trackList->SetMarkerStyle(4);
0138 m_trackList->SetMarkerSize(0.5);
0139
0140 m_trackList->IncDenyDestroy();
0141
0142 TEveTrackPropagator* prop = m_trackList->GetPropagator();
0143 prop->SetStepper(TEveTrackPropagator::kRungeKutta);
0144
0145 m_eve->setupFieldForPropagator(prop);
0146 }
0147 }
0148
0149 void DummyEvelyser::endJob() {
0150 printf("DummyEvelyser::endJob\n");
0151
0152 if (m_trackList) {
0153 m_trackList->DecDenyDestroy();
0154 m_trackList = nullptr;
0155 }
0156 }
0157
0158
0159
0160 void DummyEvelyser::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0161 printf("DummyEvelyser::beginRun\n");
0162
0163 if (m_eve) {
0164 m_geomList = new TEveElementList("DummyEvelyzer Geom");
0165 m_eve->AddGlobalElement(m_geomList);
0166 m_eve->getManager()->GetGlobalScene()->GetGLScene()->SetStyle(TGLRnrCtx::kWireFrame);
0167 }
0168 }
0169
0170 void DummyEvelyser::endRun(const edm::Run&, const edm::EventSetup&) { printf("DummyEvelyser::endRun\n"); }
0171
0172
0173
0174 void DummyEvelyser::remakeGeometry(const DisplayGeomRecord& dgRec) {
0175 m_geomList->DestroyElements();
0176
0177 TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(&dgRec.get(geomToken_)));
0178
0179
0180
0181
0182 make_node("/cms:World_1/cms:CMSE_1/tracker:Tracker_1", 1, kTRUE);
0183 make_node("/cms:World_1/cms:CMSE_1/caloBase:CALO_1", 1, kTRUE);
0184 make_node("/cms:World_1/cms:CMSE_1/muonBase:MUON_1", 1, kTRUE);
0185 }
0186
0187 void DummyEvelyser::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0188 printf("DummyEvelyser::analyze\n");
0189
0190 edm::Handle<reco::TrackCollection> trackHandle;
0191 iEvent.getByToken(trackCollectionToken_, trackHandle);
0192 const reco::TrackCollection trackCollection = *(trackHandle.product());
0193 if (!trackHandle.isValid()) {
0194 edm::LogError("DummyEvelyser") << "Error! Can't get Track collection " << std::endl;
0195 return;
0196 }
0197
0198 if (m_eve) {
0199
0200 m_geomWatcher.check(iSetup);
0201
0202
0203
0204 using namespace edm;
0205
0206 m_trackList->DestroyElements();
0207
0208
0209
0210 m_eve->AddElement(m_trackList);
0211
0212 int cnt = 0;
0213
0214 for (auto itTrack = trackCollection.begin(); itTrack != trackCollection.end(); ++itTrack, ++cnt) {
0215 TEveTrack* trk = fireworks::prepareTrack(*itTrack, m_trackList->GetPropagator());
0216 trk->SetElementName(TString::Format("Track %d", cnt));
0217 trk->SetElementTitle(TString::Format("Track %d, pt=%.3f", cnt, itTrack->pt()));
0218 trk->MakeTrack();
0219
0220 trk->SetAttLineAttMarker(m_trackList);
0221 m_trackList->AddElement(trk);
0222 }
0223
0224
0225
0226
0227
0228 m_eve->display(Form("DummyEvelyser::analyze done for %d tracks\n", m_trackList->NumChildren()));
0229 }
0230 }