ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/OpenGLDisplayer.cc
Revision: 1.13
Committed: Tue Mar 25 13:12:31 2008 UTC (17 years, 1 month ago) by querten
Content type: text/plain
Branch: MAIN
CVS Tags: Version_0_2
Changes since 1.12: +0 -0 lines
Log Message:
Move to Version 0.2

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.11 2008/03/23 09:45:19 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 "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"
49 #include "Geometry/Records/interface/IdealGeometryRecord.h"
50 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
51 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
52 #include "Geometry/EcalBarrelAlgo/interface/EcalBarrelGeometry.h"
53 #include "Geometry/EcalEndcapAlgo/interface/EcalEndcapGeometry.h"
54 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
55 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
56
57 #include "DataFormats/CaloRecHit/interface/CaloRecHit.h"
58 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
59 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
60
61 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
62 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
63 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
64 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
65 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
66 #include "SimDataFormats/Track/interface/SimTrack.h"
67 #include "SimDataFormats/Vertex/interface/SimVertex.h"
68
69 #include "DataFormats/Provenance/interface/BranchDescription.h"
70 #include "DataFormats/Provenance/interface/Provenance.h"
71 #include "DataFormats/Candidate/interface/Candidate.h"
72 #include "DataFormats/HepMCCandidate/interface/GenParticleCandidate.h"
73 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
74 #include "DataFormats/TrackReco/interface/Track.h"
75
76 #include "DataFormats/Math/interface/Point3D.h"
77 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
78 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
79
80 #include "Visualisation/OpenGLDisplayer/interface/SimEvent.h"
81 #include "Visualisation/OpenGLDisplayer/interface/Geometry.h"
82
83 using namespace edm;
84 using namespace std;
85
86 //
87 // class decleration
88 //
89
90 class OpenGLDisplayer : public edm::EDAnalyzer {
91 public:
92 explicit OpenGLDisplayer(const edm::ParameterSet&);
93 ~OpenGLDisplayer();
94
95
96 private:
97 virtual void beginJob(const edm::EventSetup& iSetup);
98 virtual void analyze (const edm::Event&, const edm::EventSetup&);
99 virtual void endJob ();
100
101
102 MySimEvents* MyEvents;
103 Geometry* Geom_Tracker;
104 Geometry* Geom_ECAL;
105 Geometry* Geom_HCAL;
106
107
108 std::vector<std::string> SimHitSubdetectors;
109
110 std::string OutputFile;
111
112
113 // ----------member data ---------------------------
114 };
115
116 //
117 // constructors and destructor
118 //
119 OpenGLDisplayer::OpenGLDisplayer(const edm::ParameterSet& iConfig)
120 {
121 SimHitSubdetectors = iConfig.getParameter<std::vector<std::string> >("SimHitSubdetectors");
122
123 OutputFile = iConfig.getParameter<std::string >("OutputFile");
124 }
125
126
127 OpenGLDisplayer::~OpenGLDisplayer()
128 {
129 }
130
131 // ------------ method called once each job just before starting event loop ------------
132 void
133 OpenGLDisplayer::beginJob(const edm::EventSetup& iSetup)
134 {
135 DetId Detid;
136 int SubDet;
137
138 MyEvents = new MySimEvents();
139 Geom_Tracker = new Geometry();
140 Geom_ECAL = new Geometry();
141 Geom_HCAL = new Geometry();
142
143
144 edm::ESHandle<TrackerGeometry> tkGeom;
145 iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
146 vector<GeomDet*> TrackerDets = tkGeom->dets();
147
148 for(unsigned int i=0;i<TrackerDets.size();i++){
149 Detid = TrackerDets[i]->geographicalId();
150 // SubDet = Detid.subdetId();
151
152 GeomDet* DetUnit = TrackerDets[i];
153 if(!DetUnit)continue;
154 const BoundPlane plane = DetUnit->surface();
155 const TrapezoidalPlaneBounds* trapezoidalBounds( dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
156 const RectangularPlaneBounds* rectangularBounds( dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
157
158 float width = 0;
159 float length = 0;
160 float thickness = 0;
161 float TrapezoidalParam = 0;
162
163 if(trapezoidalBounds)
164 {
165 std::vector<float> const & parameters = (*trapezoidalBounds).parameters();
166 width = parameters[0]*2;
167 length = parameters[3]*2;
168 thickness = (*trapezoidalBounds).thickness();
169 TrapezoidalParam = parameters[1]/parameters[0];
170 }else if(rectangularBounds){
171 width = DetUnit->surface().bounds().width();
172 length = DetUnit->surface().bounds().length();
173 thickness = DetUnit->surface().bounds().thickness();
174 TrapezoidalParam = 1;
175 }
176
177 Surface::GlobalPoint WidthVector = plane.toGlobal( LocalPoint(width/2, 0, 0) );
178 Surface::GlobalPoint LengthVector = plane.toGlobal( LocalPoint(0, length/2, 0) );
179 Surface::GlobalPoint ThickVector = plane.toGlobal( LocalPoint(0, 0, thickness/2) );
180
181 GlobalVector Pos = GlobalVector(DetUnit->position().basicVector());
182
183 Geom_Tracker->Add_TrackerDet(Detid.rawId(), TrapezoidalParam,
184 Pos.x(), Pos.y(), Pos.z(),
185 WidthVector.x() -Pos.x(), WidthVector.y() -Pos.y(), WidthVector.z() -Pos.z(),
186 LengthVector.x()-Pos.x(), LengthVector.y()-Pos.y(), LengthVector.z()-Pos.z(),
187 ThickVector.x() -Pos.x(), ThickVector.y() -Pos.y(), ThickVector.z() -Pos.z());
188
189
190 }
191
192
193 // ### CALO GEOMETRY ###
194
195 edm::ESHandle<CaloGeometry> CaloGeom;
196 iSetup.get<IdealGeometryRecord>().get( CaloGeom );
197 const vector<DetId> CaloDets = CaloGeom->getValidDetIds();
198
199 for(unsigned int i=0;i<CaloDets.size();i++)
200 {
201 Detid = CaloDets[i];
202 SubDet = Detid.subdetId();
203
204 Geometry* Geom_temp = NULL;
205 if(Detid.det()==DetId::Ecal){
206 Geom_temp = Geom_ECAL;
207
208 if(SubDet<1 || SubDet>3){
209 printf("Don't Save EcalTriggerTower or EcalLaserPnDiode\n");
210 continue;
211 }
212 }else if(Detid.det()==DetId::Hcal){
213 Geom_temp = Geom_HCAL;
214
215 if(SubDet<1 || SubDet>4){
216 printf("Don't Save HcalEmpty, HcalTriggerTower, HcalOther\n");
217 continue;
218 }
219 }else{
220 continue;
221 }
222
223 const CaloCellGeometry* CellGeom = CaloGeom->getGeometry(Detid);
224 GlobalPoint CellPos = CellGeom->getPosition();
225 const CaloCellGeometry::CornersVec CellCorners = CellGeom->getCorners();
226
227 Geom_temp->Add_CaloDet(Detid.rawId(),
228 CellPos.x() , CellPos.y() , CellPos.z(),
229 CellCorners[0].x() , CellCorners[0].y() , CellCorners[0].z() ,
230 CellCorners[1].x() , CellCorners[1].y() , CellCorners[1].z() ,
231 CellCorners[2].x() , CellCorners[2].y() , CellCorners[2].z() ,
232 CellCorners[3].x() , CellCorners[3].y() , CellCorners[3].z() ,
233 CellCorners[4].x() , CellCorners[4].y() , CellCorners[4].z() ,
234 CellCorners[5].x() , CellCorners[5].y() , CellCorners[5].z() ,
235 CellCorners[6].x() , CellCorners[6].y() , CellCorners[6].z() ,
236 CellCorners[7].x() , CellCorners[7].y() , CellCorners[7].z() );
237 }
238
239 Geom_Tracker->Save("Tracker.geom");
240 Geom_ECAL->Save("ECAL.geom");
241 Geom_HCAL->Save("HCAL.geom");
242
243
244
245 }
246
247 // ------------ method called once each job just after ending the event loop ------------
248 void
249 OpenGLDisplayer::endJob() {
250
251 MyEvents->Save((char*) OutputFile.c_str());
252 // MyEvents->Load((char*) OutputFile.c_str());
253 }
254
255
256
257 //
258 // member functions
259 //
260
261 // ------------ method called to for each event ------------
262 void
263 OpenGLDisplayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
264 {
265
266 edm::Handle<std::vector< SimTrack > > h_SimTracks;
267 iEvent.getByLabel("g4SimHits", h_SimTracks);
268 std::vector< SimTrack > SimTrackColl = *h_SimTracks.product();
269
270 edm::Handle<std::vector< SimVertex > > h_Vertex;
271 iEvent.getByLabel("g4SimHits", h_Vertex);
272 std::vector< SimVertex > VertexColl = *h_Vertex.product();
273
274
275
276 // access the tracker
277 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
278 iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
279 const TrackerGeometry& theTracker(*theTrackerGeometry);
280
281 // the DetUnits
282 TrackingGeometry::DetContainer theDetUnits = theTracker.dets();
283
284
285
286
287 // Save the data
288
289 MySimEvent* MyEvent = new MySimEvent;
290
291 for ( unsigned int a = 0; a < SimTrackColl.size(); ++a ) {
292 MySimTrack MysimTrack;
293 SimTrack simTrack =SimTrackColl[a];
294
295 MysimTrack.track_id =simTrack.trackId();
296 MysimTrack.Type =simTrack.type();
297 MysimTrack.parent_vertex=simTrack.vertIndex();
298 MysimTrack.Px =simTrack.momentum().x();
299 MysimTrack.Py =simTrack.momentum().y();
300 MysimTrack.Pz =simTrack.momentum().z();
301 MysimTrack.E =simTrack.momentum().e();
302 MysimTrack.charge =simTrack.charge();
303
304 MyEvent->MySimTrackCollection.push_back(MysimTrack);
305 }
306
307
308 for (unsigned int b = 0; b < VertexColl.size(); ++b ) {
309 MySimVertex MyVertex;
310 SimVertex Vertex = VertexColl[b];
311
312 MyVertex.parentTrack_id =Vertex.parentIndex ();
313 MyVertex.x =Vertex.position().x();
314 MyVertex.y =Vertex.position().y();
315 MyVertex.z =Vertex.position().z();
316
317 MyEvent->MySimVertexCollection.push_back(MyVertex);
318 }
319
320 for(unsigned int i=0; i<SimHitSubdetectors.size(); i++)
321 {
322 edm::Handle<std::vector< PSimHit > > h_Hits;
323 iEvent.getByLabel("g4SimHits",SimHitSubdetectors[i].c_str(), h_Hits);
324 std::vector< PSimHit > Hits = *h_Hits.product();
325
326 for(unsigned int h=0; h<Hits.size(); h++)
327 {
328 DetId theDetUnitId(Hits[h].detUnitId());
329 const GeomDet * theDet = theTracker.idToDet(theDetUnitId);
330
331 MyPSimHit Hit;
332 Hit.x = theDet->surface().toGlobal(Hits[h].localPosition()).x();
333 Hit.y = theDet->surface().toGlobal(Hits[h].localPosition()).y();
334 Hit.z = theDet->surface().toGlobal(Hits[h].localPosition()).z();
335 Hit.ProcessType = Hits[h].processType();
336 Hit.dEdX = Hits[h].energyLoss();
337
338 MyEvent->MyPSimHitCollection.push_back(Hit);
339
340 }
341 }
342
343 edm::Handle<std::vector< reco::Track > > h_Tracks;
344 iEvent.getByLabel("ctfWithMaterialTracks", h_Tracks);
345 std::vector< reco::Track > TrackColl = *h_Tracks.product();
346
347 for ( unsigned int t = 0; t < TrackColl.size(); ++t ) {
348 MyRecoTrack MyrecoTrack;
349 reco::Track recoTrack =TrackColl[t];
350
351 // MyrecoTrack.Hits = new MyRecoHit[MyrecoTrack.N];
352
353 for(unsigned int h=0;h<recoTrack.recHitsSize();h++){
354 TrackingRecHitRef h_it = recoTrack.recHit(h);
355 if(!h_it->isValid() )continue;
356 DetId detId = h_it->geographicalId();
357 const GeomDet * theDet = theTracker.idToDet(detId);
358 LocalPoint localPos = h_it->localPosition();
359
360 MyRecoHit hit;
361 hit.x = theDet->surface().toGlobal(localPos).x();
362 hit.y = theDet->surface().toGlobal(localPos).y();
363 hit.z = theDet->surface().toGlobal(localPos).z();
364 hit.DetId = detId.rawId();
365 hit.Charge = -1;
366 MyrecoTrack.Hits.push_back(hit);
367
368
369 // printf("%8.2f %8.2f %8.2f\n",theDet->surface().toGlobal(localPos).x(),theDet->surface().toGlobal(localPos).y(),theDet->surface().toGlobal(localPos).z());
370 }
371 MyEvent->MyRecoTrackCollection.push_back(MyrecoTrack);
372 }
373
374
375
376 edm::Handle<EcalRecHitCollection > h_EcalEB_RecHits;
377 iEvent.getByLabel("ecalRecHit","EcalRecHitsEB", h_EcalEB_RecHits);
378 EcalRecHitCollection EcalEB_RecHits = *h_EcalEB_RecHits.product();
379
380 for(unsigned int eh=0;eh<EcalEB_RecHits.size();eh++){
381 MyCaloHit temp_EcalEBHit;
382 temp_EcalEBHit.E = EcalEB_RecHits[eh].energy();
383 temp_EcalEBHit.t = EcalEB_RecHits[eh].time();
384 temp_EcalEBHit.DetId = (EcalEB_RecHits[eh].detid()).rawId();
385
386 MyEvent->MyEcalCaloHitCollection.push_back(temp_EcalEBHit);
387 }
388
389
390 edm::Handle<EcalRecHitCollection > h_EcalEE_RecHits;
391 iEvent.getByLabel("ecalRecHit","EcalRecHitsEE", h_EcalEE_RecHits);
392 EcalRecHitCollection EcalEE_RecHits = *h_EcalEE_RecHits.product();
393
394 for(unsigned int eh=0;eh<EcalEE_RecHits.size();eh++){
395 MyCaloHit temp_EcalEEHit;
396 temp_EcalEEHit.E = EcalEE_RecHits[eh].energy();
397 temp_EcalEEHit.t = EcalEE_RecHits[eh].time();
398 temp_EcalEEHit.DetId = (EcalEE_RecHits[eh].detid()).rawId();
399
400 MyEvent->MyEcalCaloHitCollection.push_back(temp_EcalEEHit);
401 }
402
403
404 edm::Handle<EcalRecHitCollection > h_EcalES_RecHits;
405 iEvent.getByLabel("ecalPreshowerRecHit","EcalRecHitsES", h_EcalES_RecHits);
406 EcalRecHitCollection EcalES_RecHits = *h_EcalES_RecHits.product();
407
408 for(unsigned int eh=0;eh<EcalES_RecHits.size();eh++){
409 MyCaloHit temp_EcalESHit;
410 temp_EcalESHit.E = EcalES_RecHits[eh].energy();
411 temp_EcalESHit.t = EcalES_RecHits[eh].time();
412 temp_EcalESHit.DetId = (EcalES_RecHits[eh].detid()).rawId();
413
414 MyEvent->MyEcalCaloHitCollection.push_back(temp_EcalESHit);
415 }
416
417
418
419 edm::Handle<HBHERecHitCollection > h_HcalHBHE_RecHits;
420 iEvent.getByLabel("hbhereco", h_HcalHBHE_RecHits);
421 HBHERecHitCollection HcalHBHE_RecHits = *h_HcalHBHE_RecHits.product();
422
423 for(unsigned int hh=0;hh<HcalHBHE_RecHits.size();hh++){
424 MyCaloHit temp_HcalHBHEHit;
425 temp_HcalHBHEHit.E = HcalHBHE_RecHits[hh].energy();
426 temp_HcalHBHEHit.t = HcalHBHE_RecHits[hh].time();
427 temp_HcalHBHEHit.DetId = (HcalHBHE_RecHits[hh].detid()).rawId();
428
429 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHBHEHit);
430 }
431
432
433 edm::Handle<HORecHitCollection > h_HcalHO_RecHits;
434 iEvent.getByLabel("horeco", h_HcalHO_RecHits);
435 HORecHitCollection HcalHO_RecHits = *h_HcalHO_RecHits.product();
436
437 for(unsigned int hh=0;hh<HcalHO_RecHits.size();hh++){
438 MyCaloHit temp_HcalHOHit;
439 temp_HcalHOHit.E = HcalHO_RecHits[hh].energy();
440 temp_HcalHOHit.t = HcalHO_RecHits[hh].time();
441 temp_HcalHOHit.DetId = (HcalHO_RecHits[hh].detid()).rawId();
442
443 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHOHit);
444 }
445
446 edm::Handle<HFRecHitCollection > h_HcalHF_RecHits;
447 iEvent.getByLabel("hfreco", h_HcalHF_RecHits);
448 HFRecHitCollection HcalHF_RecHits = *h_HcalHF_RecHits.product();
449
450 for(unsigned int hh=0;hh<HcalHF_RecHits.size();hh++){
451 MyCaloHit temp_HcalHFHit;
452 temp_HcalHFHit.E = HcalHF_RecHits[hh].energy();
453 temp_HcalHFHit.t = HcalHF_RecHits[hh].time();
454 temp_HcalHFHit.DetId = (HcalHF_RecHits[hh].detid()).rawId();
455
456 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHFHit);
457 }
458
459
460
461
462
463
464
465
466
467
468
469 MyEvents->Events.push_back(MyEvent);
470
471 }
472
473
474 //define this as a plug-in
475 DEFINE_FWK_MODULE(OpenGLDisplayer);
476
477