1 |
// -*- C++ -*-
|
2 |
//
|
3 |
// Package: OpenGLDisplayer
|
4 |
// Class: OpenGLDisplayer
|
5 |
//
|
6 |
/**\class OpenGLDisplayer OpenGLDisplayer.cc Visualisation/OpenGLDisplayer/src/OpenGLDisplayer.cc
|
7 |
|
8 |
Description: <one line class summary>
|
9 |
|
10 |
Implementation:
|
11 |
<Notes on implementation>
|
12 |
*/
|
13 |
//
|
14 |
// Original Author: Loic QUERTENMONT
|
15 |
// Created: Fri Oct 26 07:22:12 CEST 2007
|
16 |
// $Id$
|
17 |
//
|
18 |
//
|
19 |
|
20 |
|
21 |
// system include files
|
22 |
#include <memory>
|
23 |
|
24 |
// user include files
|
25 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
26 |
#include "FWCore/Framework/interface/EDAnalyzer.h"
|
27 |
|
28 |
#include "FWCore/Framework/interface/Event.h"
|
29 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
30 |
|
31 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
32 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
33 |
#include "FWCore/Framework/interface/ESHandle.h"
|
34 |
|
35 |
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
|
36 |
#include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
|
37 |
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
|
38 |
#include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
|
39 |
#include "Geometry/CommonTopologies/interface/PixelTopology.h"
|
40 |
#include "Geometry/CommonTopologies/interface/StripTopology.h"
|
41 |
#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
|
42 |
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
|
43 |
#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
|
44 |
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
|
45 |
#include "DataFormats/GeometrySurface/interface/BoundSurface.h"
|
46 |
#include "DataFormats/DetId/interface/DetId.h"
|
47 |
|
48 |
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
|
49 |
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
|
50 |
#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
|
51 |
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
|
52 |
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
|
53 |
#include "SimDataFormats/Track/interface/SimTrack.h"
|
54 |
#include "SimDataFormats/Vertex/interface/SimVertex.h"
|
55 |
|
56 |
#include "DataFormats/Provenance/interface/BranchDescription.h"
|
57 |
#include "DataFormats/Provenance/interface/Provenance.h"
|
58 |
#include "DataFormats/Candidate/interface/Candidate.h"
|
59 |
#include "DataFormats/HepMCCandidate/interface/GenParticleCandidate.h"
|
60 |
#include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
|
61 |
#include "DataFormats/TrackReco/interface/Track.h"
|
62 |
|
63 |
#include "DataFormats/Math/interface/Point3D.h"
|
64 |
|
65 |
|
66 |
#include "Visualisation/OpenGLDisplayer/interface/SimEvent.h"
|
67 |
//#include "Visualisation/OpenGLDisplayer/interface/SimEvent.cpp"
|
68 |
|
69 |
|
70 |
|
71 |
using namespace edm;
|
72 |
using namespace std;
|
73 |
|
74 |
//
|
75 |
// class decleration
|
76 |
//
|
77 |
|
78 |
class OpenGLDisplayer : public edm::EDAnalyzer {
|
79 |
public:
|
80 |
explicit OpenGLDisplayer(const edm::ParameterSet&);
|
81 |
~OpenGLDisplayer();
|
82 |
|
83 |
|
84 |
private:
|
85 |
virtual void beginJob(const edm::EventSetup&) ;
|
86 |
virtual void analyze(const edm::Event&, const edm::EventSetup&);
|
87 |
virtual void endJob() ;
|
88 |
|
89 |
|
90 |
MySimEvents* MyEvents;
|
91 |
|
92 |
|
93 |
std::vector<std::string> SimHitSubdetectors;
|
94 |
|
95 |
std::string OutputFile;
|
96 |
|
97 |
|
98 |
// ----------member data ---------------------------
|
99 |
};
|
100 |
|
101 |
//
|
102 |
// constructors and destructor
|
103 |
//
|
104 |
OpenGLDisplayer::OpenGLDisplayer(const edm::ParameterSet& iConfig)
|
105 |
{
|
106 |
SimHitSubdetectors = iConfig.getParameter<std::vector<std::string> >("SimHitSubdetectors");
|
107 |
|
108 |
OutputFile = iConfig.getParameter<std::string >("OutputFile");
|
109 |
}
|
110 |
|
111 |
|
112 |
OpenGLDisplayer::~OpenGLDisplayer()
|
113 |
{
|
114 |
}
|
115 |
|
116 |
// ------------ method called once each job just before starting event loop ------------
|
117 |
void
|
118 |
OpenGLDisplayer::beginJob(const edm::EventSetup&)
|
119 |
{
|
120 |
|
121 |
|
122 |
MyEvents = new MySimEvents();
|
123 |
|
124 |
}
|
125 |
|
126 |
// ------------ method called once each job just after ending the event loop ------------
|
127 |
void
|
128 |
OpenGLDisplayer::endJob() {
|
129 |
|
130 |
MyEvents->Save((char*) OutputFile.c_str());
|
131 |
MyEvents->Load((char*) OutputFile.c_str());
|
132 |
}
|
133 |
|
134 |
|
135 |
|
136 |
//
|
137 |
// member functions
|
138 |
//
|
139 |
|
140 |
// ------------ method called to for each event ------------
|
141 |
void
|
142 |
OpenGLDisplayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
|
143 |
{
|
144 |
|
145 |
edm::Handle<std::vector< SimTrack > > h_SimTracks;
|
146 |
iEvent.getByLabel("g4SimHits", h_SimTracks);
|
147 |
std::vector< SimTrack > SimTrackColl = *h_SimTracks.product();
|
148 |
|
149 |
edm::Handle<std::vector< SimVertex > > h_Vertex;
|
150 |
iEvent.getByLabel("g4SimHits", h_Vertex);
|
151 |
std::vector< SimVertex > VertexColl = *h_Vertex.product();
|
152 |
|
153 |
|
154 |
|
155 |
// access the tracker
|
156 |
edm::ESHandle<TrackerGeometry> theTrackerGeometry;
|
157 |
iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
|
158 |
const TrackerGeometry& theTracker(*theTrackerGeometry);
|
159 |
|
160 |
// the DetUnits
|
161 |
TrackingGeometry::DetContainer theDetUnits = theTracker.dets();
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
// Save the data
|
167 |
|
168 |
MySimEvent* MyEvent = new MySimEvent;
|
169 |
|
170 |
for ( unsigned int a = 0; a < SimTrackColl.size(); ++a ) {
|
171 |
MySimTrack MysimTrack;
|
172 |
SimTrack simTrack =SimTrackColl[a];
|
173 |
|
174 |
MysimTrack.track_id =simTrack.trackId();
|
175 |
MysimTrack.Type =simTrack.type();
|
176 |
MysimTrack.parent_vertex=simTrack.vertIndex();
|
177 |
MysimTrack.Px =simTrack.momentum().x();
|
178 |
MysimTrack.Py =simTrack.momentum().y();
|
179 |
MysimTrack.Pz =simTrack.momentum().z();
|
180 |
MysimTrack.E =simTrack.momentum().e();
|
181 |
MysimTrack.charge =simTrack.charge();
|
182 |
|
183 |
MyEvent->MySimTrackCollection.push_back(MysimTrack);
|
184 |
}
|
185 |
|
186 |
|
187 |
for (unsigned int b = 0; b < VertexColl.size(); ++b ) {
|
188 |
MySimVertex MyVertex;
|
189 |
SimVertex Vertex = VertexColl[b];
|
190 |
|
191 |
MyVertex.parentTrack_id =Vertex.parentIndex ();
|
192 |
MyVertex.x =Vertex.position().x();
|
193 |
MyVertex.y =Vertex.position().y();
|
194 |
MyVertex.z =Vertex.position().z();
|
195 |
|
196 |
MyEvent->MySimVertexCollection.push_back(MyVertex);
|
197 |
}
|
198 |
|
199 |
for(unsigned int i=0; i<SimHitSubdetectors.size(); i++)
|
200 |
{
|
201 |
edm::Handle<std::vector< PSimHit > > h_Hits;
|
202 |
iEvent.getByLabel("g4SimHits",SimHitSubdetectors[i].c_str(), h_Hits);
|
203 |
std::vector< PSimHit > Hits = *h_Hits.product();
|
204 |
|
205 |
for(unsigned int h=0; h<Hits.size(); h++)
|
206 |
{
|
207 |
DetId theDetUnitId(Hits[h].detUnitId());
|
208 |
const GeomDet * theDet = theTracker.idToDet(theDetUnitId);
|
209 |
|
210 |
MyPSimHit Hit;
|
211 |
Hit.x = theDet->surface().toGlobal(Hits[h].localPosition()).x();
|
212 |
Hit.y = theDet->surface().toGlobal(Hits[h].localPosition()).y();
|
213 |
Hit.z = theDet->surface().toGlobal(Hits[h].localPosition()).z();
|
214 |
Hit.ProcessType = Hits[h].processType();
|
215 |
Hit.dEdX = Hits[h].energyLoss();
|
216 |
|
217 |
MyEvent->MyPSimHitCollection.push_back(Hit);
|
218 |
|
219 |
}
|
220 |
}
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
edm::Handle<std::vector< reco::Track > > h_Tracks;
|
226 |
iEvent.getByLabel("ctfWithMaterialTracks", h_Tracks);
|
227 |
std::vector< reco::Track > TrackColl = *h_Tracks.product();
|
228 |
|
229 |
for ( unsigned int t = 0; t < TrackColl.size(); ++t ) {
|
230 |
MyRecoTrack MyrecoTrack;
|
231 |
reco::Track recoTrack =TrackColl[t];
|
232 |
|
233 |
MyrecoTrack.N = recoTrack.recHitsSize();
|
234 |
MyrecoTrack.Hits = new MyRecoHit[MyrecoTrack.N];
|
235 |
|
236 |
// for(int h=0;h<MyrecoTrack.N;h++){
|
237 |
// MyrecoTrack.Hits[h].x = 1;
|
238 |
// MyrecoTrack.Hits[h].y = 2;
|
239 |
// MyrecoTrack.Hits[h].z = 3;
|
240 |
// MyrecoTrack.Hits[h].DetId = 4;
|
241 |
// MyrecoTrack.Hits[h].Charge = 5;
|
242 |
// }
|
243 |
|
244 |
// unsigned int h=0;
|
245 |
// for(trackingRecHit_iterator h_it = recoTrack.recHitsBegin();h_it!=recoTrack.recHitsEnd();h_it++){
|
246 |
for(int h=0;h<MyrecoTrack.N;h++){
|
247 |
TrackingRecHitRef h_it = recoTrack.recHit(h);
|
248 |
if(!h_it->isValid() )continue;
|
249 |
DetId detId = h_it->geographicalId();
|
250 |
const GeomDet * theDet = theTracker.idToDet(detId);
|
251 |
LocalPoint localPos = h_it->localPosition();
|
252 |
|
253 |
MyrecoTrack.Hits[h].x = theDet->surface().toGlobal(localPos).x();
|
254 |
MyrecoTrack.Hits[h].y = theDet->surface().toGlobal(localPos).y();
|
255 |
MyrecoTrack.Hits[h].z = theDet->surface().toGlobal(localPos).z();
|
256 |
MyrecoTrack.Hits[h].DetId = detId.rawId();
|
257 |
MyrecoTrack.Hits[h].Charge = -1;
|
258 |
}
|
259 |
|
260 |
MyEvent->MyRecoTrackCollection.push_back(MyrecoTrack);
|
261 |
}
|
262 |
|
263 |
|
264 |
|
265 |
MyEvents->Events.push_back(MyEvent);
|
266 |
|
267 |
}
|
268 |
|
269 |
|
270 |
//define this as a plug-in
|
271 |
DEFINE_FWK_MODULE(OpenGLDisplayer);
|
272 |
|
273 |
|