ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/OpenGLDisplayer.cc
Revision: 1.5
Committed: Wed Mar 19 13:57:30 2008 UTC (17 years, 1 month ago) by querten
Content type: text/plain
Branch: MAIN
Changes since 1.4: +0 -0 lines
Log Message:
Add the FROG Logo and Increase Speed

File Contents

# Content
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: OpenGLDisplayer.cc,v 1.2 2008/03/15 17:02:20 querten Exp $
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/Geometry.h"
68
69 using namespace edm;
70 using namespace std;
71
72 //
73 // class decleration
74 //
75
76 class OpenGLDisplayer : public edm::EDAnalyzer {
77 public:
78 explicit OpenGLDisplayer(const edm::ParameterSet&);
79 ~OpenGLDisplayer();
80
81
82 private:
83 virtual void beginJob(const edm::EventSetup& iSetup);
84 virtual void analyze (const edm::Event&, const edm::EventSetup&);
85 virtual void endJob ();
86
87
88 MySimEvents* MyEvents;
89 Geometry* Geom;
90
91
92 std::vector<std::string> SimHitSubdetectors;
93
94 std::string OutputFile;
95
96
97 // ----------member data ---------------------------
98 };
99
100 //
101 // constructors and destructor
102 //
103 OpenGLDisplayer::OpenGLDisplayer(const edm::ParameterSet& iConfig)
104 {
105 SimHitSubdetectors = iConfig.getParameter<std::vector<std::string> >("SimHitSubdetectors");
106
107 OutputFile = iConfig.getParameter<std::string >("OutputFile");
108 }
109
110
111 OpenGLDisplayer::~OpenGLDisplayer()
112 {
113 }
114
115 // ------------ method called once each job just before starting event loop ------------
116 void
117 OpenGLDisplayer::beginJob(const edm::EventSetup& iSetup)
118 {
119
120 MyEvents = new MySimEvents();
121 Geom = new Geometry();
122
123 edm::ESHandle<TrackerGeometry> tkGeom;
124 iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
125 vector<GeomDet*> Det = tkGeom->dets();
126
127 for(unsigned int i=0;i<Det.size();i++){
128 DetId Detid = Det[i]->geographicalId();
129 // int SubDet = Detid.subdetId();
130
131 GeomDet* DetUnit = Det[i];
132 // StripGeomDetUnit* DetUnit = dynamic_cast<StripGeomDetUnit*> (Det[i]);
133 if(!DetUnit)continue;
134
135 const BoundPlane plane = DetUnit->surface();
136 float width = DetUnit->surface().bounds().width();
137 float length = DetUnit->surface().bounds().length();
138 float thickness = DetUnit->surface().bounds().thickness();
139
140 Surface::GlobalPoint WidthVector = plane.toGlobal( LocalPoint(width/2, 0, 0) );
141 Surface::GlobalPoint LengthVector = plane.toGlobal( LocalPoint(0, length/2, 0) );
142 Surface::GlobalPoint ThickVector = plane.toGlobal( LocalPoint(0, 0, thickness/2) );
143
144
145 GlobalVector Pos = GlobalVector(DetUnit->position().basicVector());
146
147 Geom->Add_TrackerDet(Detid.rawId(),
148 Pos.x(), Pos.y(), Pos.z(),
149 WidthVector.x() -Pos.x(), WidthVector.y() -Pos.y(), WidthVector.z() -Pos.z(),
150 LengthVector.x()-Pos.x(), LengthVector.y()-Pos.y(), LengthVector.z()-Pos.z(),
151 ThickVector.x() -Pos.x(), ThickVector.y() -Pos.y(), ThickVector.z() -Pos.z());
152 }
153 Geom->Save("Tracker.geom");
154
155
156 }
157
158 // ------------ method called once each job just after ending the event loop ------------
159 void
160 OpenGLDisplayer::endJob() {
161
162 MyEvents->Save((char*) OutputFile.c_str());
163 MyEvents->Load((char*) OutputFile.c_str());
164 }
165
166
167
168 //
169 // member functions
170 //
171
172 // ------------ method called to for each event ------------
173 void
174 OpenGLDisplayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
175 {
176
177 edm::Handle<std::vector< SimTrack > > h_SimTracks;
178 iEvent.getByLabel("g4SimHits", h_SimTracks);
179 std::vector< SimTrack > SimTrackColl = *h_SimTracks.product();
180
181 edm::Handle<std::vector< SimVertex > > h_Vertex;
182 iEvent.getByLabel("g4SimHits", h_Vertex);
183 std::vector< SimVertex > VertexColl = *h_Vertex.product();
184
185
186
187 // access the tracker
188 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
189 iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
190 const TrackerGeometry& theTracker(*theTrackerGeometry);
191
192 // the DetUnits
193 TrackingGeometry::DetContainer theDetUnits = theTracker.dets();
194
195
196
197
198 // Save the data
199
200 MySimEvent* MyEvent = new MySimEvent;
201
202 for ( unsigned int a = 0; a < SimTrackColl.size(); ++a ) {
203 MySimTrack MysimTrack;
204 SimTrack simTrack =SimTrackColl[a];
205
206 MysimTrack.track_id =simTrack.trackId();
207 MysimTrack.Type =simTrack.type();
208 MysimTrack.parent_vertex=simTrack.vertIndex();
209 MysimTrack.Px =simTrack.momentum().x();
210 MysimTrack.Py =simTrack.momentum().y();
211 MysimTrack.Pz =simTrack.momentum().z();
212 MysimTrack.E =simTrack.momentum().e();
213 MysimTrack.charge =simTrack.charge();
214
215 MyEvent->MySimTrackCollection.push_back(MysimTrack);
216 }
217
218
219 for (unsigned int b = 0; b < VertexColl.size(); ++b ) {
220 MySimVertex MyVertex;
221 SimVertex Vertex = VertexColl[b];
222
223 MyVertex.parentTrack_id =Vertex.parentIndex ();
224 MyVertex.x =Vertex.position().x();
225 MyVertex.y =Vertex.position().y();
226 MyVertex.z =Vertex.position().z();
227
228 MyEvent->MySimVertexCollection.push_back(MyVertex);
229 }
230
231 for(unsigned int i=0; i<SimHitSubdetectors.size(); i++)
232 {
233 edm::Handle<std::vector< PSimHit > > h_Hits;
234 iEvent.getByLabel("g4SimHits",SimHitSubdetectors[i].c_str(), h_Hits);
235 std::vector< PSimHit > Hits = *h_Hits.product();
236
237 for(unsigned int h=0; h<Hits.size(); h++)
238 {
239 DetId theDetUnitId(Hits[h].detUnitId());
240 const GeomDet * theDet = theTracker.idToDet(theDetUnitId);
241
242 MyPSimHit Hit;
243 Hit.x = theDet->surface().toGlobal(Hits[h].localPosition()).x();
244 Hit.y = theDet->surface().toGlobal(Hits[h].localPosition()).y();
245 Hit.z = theDet->surface().toGlobal(Hits[h].localPosition()).z();
246 Hit.ProcessType = Hits[h].processType();
247 Hit.dEdX = Hits[h].energyLoss();
248
249 MyEvent->MyPSimHitCollection.push_back(Hit);
250
251 }
252 }
253
254 edm::Handle<std::vector< reco::Track > > h_Tracks;
255 iEvent.getByLabel("ctfWithMaterialTracks", h_Tracks);
256 std::vector< reco::Track > TrackColl = *h_Tracks.product();
257
258 for ( unsigned int t = 0; t < TrackColl.size(); ++t ) {
259 MyRecoTrack MyrecoTrack;
260 reco::Track recoTrack =TrackColl[t];
261
262 // MyrecoTrack.Hits = new MyRecoHit[MyrecoTrack.N];
263
264 for(unsigned int h=0;h<recoTrack.recHitsSize();h++){
265 TrackingRecHitRef h_it = recoTrack.recHit(h);
266 if(!h_it->isValid() )continue;
267 DetId detId = h_it->geographicalId();
268 const GeomDet * theDet = theTracker.idToDet(detId);
269 LocalPoint localPos = h_it->localPosition();
270
271 MyRecoHit hit;
272 hit.x = theDet->surface().toGlobal(localPos).x();
273 hit.y = theDet->surface().toGlobal(localPos).y();
274 hit.z = theDet->surface().toGlobal(localPos).z();
275 hit.DetId = detId.rawId();
276 hit.Charge = -1;
277 MyrecoTrack.Hits.push_back(hit);
278
279
280 // printf("%8.2f %8.2f %8.2f\n",theDet->surface().toGlobal(localPos).x(),theDet->surface().toGlobal(localPos).y(),theDet->surface().toGlobal(localPos).z());
281 }
282 MyEvent->MyRecoTrackCollection.push_back(MyrecoTrack);
283 }
284
285 MyEvents->Events.push_back(MyEvent);
286
287 }
288
289
290 //define this as a plug-in
291 DEFINE_FWK_MODULE(OpenGLDisplayer);
292
293