ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/OpenGLDisplayer.cc
Revision: 1.16
Committed: Wed Apr 16 05:58:28 2008 UTC (17 years ago) by querten
Content type: text/plain
Branch: MAIN
Changes since 1.15: +3 -3 lines
Log Message:
Change default .geom name

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.15 2008/04/05 07:40:33 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 std::string OutputFile;
108
109 std::vector<InputTag> SimTrackProducers;
110 std::vector<InputTag> SimVertexProducers;
111 std::vector<InputTag> SimHitProducers;
112
113 std::vector<InputTag> TrackProducers;
114 std::vector<InputTag> EcalRecHitProducers;
115 std::vector<InputTag> HcalHBHERecHitProducers;
116 std::vector<InputTag> HcalHORecHitProducers;
117 std::vector<InputTag> HcalHFRecHitProducers;
118
119
120
121
122 // ----------member data ---------------------------
123 };
124
125 //
126 // constructors and destructor
127 //
128 OpenGLDisplayer::OpenGLDisplayer(const edm::ParameterSet& iConfig)
129 {
130 OutputFile = iConfig.getParameter<std::string >("OutputFile");
131
132 SimTrackProducers = iConfig.getParameter<std::vector<InputTag> >("SimTrackProducers");
133 SimVertexProducers = iConfig.getParameter<std::vector<InputTag> >("SimVertexProducers");
134 SimHitProducers = iConfig.getParameter<std::vector<InputTag> >("SimHitProducers");
135
136 TrackProducers = iConfig.getParameter<std::vector<InputTag> >("TrackProducers");
137 EcalRecHitProducers = iConfig.getParameter<std::vector<InputTag> >("EcalRecHitProducers");
138 HcalHBHERecHitProducers = iConfig.getParameter<std::vector<InputTag> >("HcalHBHERecHitProducers");
139 HcalHORecHitProducers = iConfig.getParameter<std::vector<InputTag> >("HcalHORecHitProducers");
140 HcalHFRecHitProducers = iConfig.getParameter<std::vector<InputTag> >("HcalHFRecHitProducers");
141
142 }
143
144
145 OpenGLDisplayer::~OpenGLDisplayer()
146 {
147 }
148
149 // ------------ method called once each job just before starting event loop ------------
150 void
151 OpenGLDisplayer::beginJob(const edm::EventSetup& iSetup)
152 {
153 DetId Detid;
154 int SubDet;
155
156 MyEvents = new MySimEvents();
157 Geom_Tracker = new Geometry();
158 Geom_ECAL = new Geometry();
159 Geom_HCAL = new Geometry();
160
161
162 edm::ESHandle<TrackerGeometry> tkGeom;
163 iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
164 vector<GeomDet*> TrackerDets = tkGeom->dets();
165
166 for(unsigned int i=0;i<TrackerDets.size();i++){
167 Detid = TrackerDets[i]->geographicalId();
168 // SubDet = Detid.subdetId();
169
170 GeomDet* DetUnit = TrackerDets[i];
171 if(!DetUnit)continue;
172 const BoundPlane plane = DetUnit->surface();
173 const TrapezoidalPlaneBounds* trapezoidalBounds( dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
174 const RectangularPlaneBounds* rectangularBounds( dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
175
176 float width = 0;
177 float length = 0;
178 float thickness = 0;
179 float TrapezoidalParam = 0;
180
181 if(trapezoidalBounds)
182 {
183 std::vector<float> const & parameters = (*trapezoidalBounds).parameters();
184 width = parameters[0]*2;
185 length = parameters[3]*2;
186 thickness = (*trapezoidalBounds).thickness();
187 TrapezoidalParam = parameters[1]/parameters[0];
188 }else if(rectangularBounds){
189 width = DetUnit->surface().bounds().width();
190 length = DetUnit->surface().bounds().length();
191 thickness = DetUnit->surface().bounds().thickness();
192 TrapezoidalParam = 1;
193 }
194
195 Surface::GlobalPoint WidthVector = plane.toGlobal( LocalPoint(width/2, 0, 0) );
196 Surface::GlobalPoint LengthVector = plane.toGlobal( LocalPoint(0, length/2, 0) );
197 Surface::GlobalPoint ThickVector = plane.toGlobal( LocalPoint(0, 0, thickness/2) );
198
199 GlobalVector Pos = GlobalVector(DetUnit->position().basicVector());
200
201 Geom_Tracker->Add_TrackerDet(Detid.rawId(), TrapezoidalParam,
202 Pos.x(), Pos.y(), Pos.z(),
203 WidthVector.x() -Pos.x(), WidthVector.y() -Pos.y(), WidthVector.z() -Pos.z(),
204 LengthVector.x()-Pos.x(), LengthVector.y()-Pos.y(), LengthVector.z()-Pos.z(),
205 ThickVector.x() -Pos.x(), ThickVector.y() -Pos.y(), ThickVector.z() -Pos.z());
206
207
208 }
209
210
211 // ### CALO GEOMETRY ###
212
213 edm::ESHandle<CaloGeometry> CaloGeom;
214 iSetup.get<IdealGeometryRecord>().get( CaloGeom );
215 const vector<DetId> CaloDets = CaloGeom->getValidDetIds();
216
217 for(unsigned int i=0;i<CaloDets.size();i++)
218 {
219 Detid = CaloDets[i];
220 SubDet = Detid.subdetId();
221
222 Geometry* Geom_temp = NULL;
223 if(Detid.det()==DetId::Ecal){
224 Geom_temp = Geom_ECAL;
225
226 if(SubDet<1 || SubDet>3){
227 printf("Don't Save EcalTriggerTower or EcalLaserPnDiode\n");
228 continue;
229 }
230 }else if(Detid.det()==DetId::Hcal){
231 Geom_temp = Geom_HCAL;
232
233 if(SubDet<1 || SubDet>4){
234 printf("Don't Save HcalEmpty, HcalTriggerTower, HcalOther\n");
235 continue;
236 }
237 }else{
238 continue;
239 }
240
241 const CaloCellGeometry* CellGeom = CaloGeom->getGeometry(Detid);
242 GlobalPoint CellPos = CellGeom->getPosition();
243 const CaloCellGeometry::CornersVec CellCorners = CellGeom->getCorners();
244
245 Geom_temp->Add_CaloDet(Detid.rawId(),
246 CellPos.x() , CellPos.y() , CellPos.z(),
247 CellCorners[0].x() , CellCorners[0].y() , CellCorners[0].z() ,
248 CellCorners[1].x() , CellCorners[1].y() , CellCorners[1].z() ,
249 CellCorners[2].x() , CellCorners[2].y() , CellCorners[2].z() ,
250 CellCorners[3].x() , CellCorners[3].y() , CellCorners[3].z() ,
251 CellCorners[4].x() , CellCorners[4].y() , CellCorners[4].z() ,
252 CellCorners[5].x() , CellCorners[5].y() , CellCorners[5].z() ,
253 CellCorners[6].x() , CellCorners[6].y() , CellCorners[6].z() ,
254 CellCorners[7].x() , CellCorners[7].y() , CellCorners[7].z() );
255 }
256
257 Geom_Tracker->Save("Tracker.geom");
258 Geom_ECAL->Save("Ecal.geom");
259 Geom_HCAL->Save("Hcal.geom");
260
261
262
263 }
264
265 // ------------ method called once each job just after ending the event loop ------------
266 void
267 OpenGLDisplayer::endJob() {
268
269 MyEvents->Save((char*) OutputFile.c_str());
270 // MyEvents->Load((char*) OutputFile.c_str());
271 }
272
273
274
275 //
276 // member functions
277 //
278
279 // ------------ method called to for each event ------------
280 void
281 OpenGLDisplayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
282 {
283 MySimEvent* MyEvent = new MySimEvent;
284
285
286
287 // access the tracker
288 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
289 iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
290 const TrackerGeometry& theTracker(*theTrackerGeometry);
291
292 // the DetUnits
293 TrackingGeometry::DetContainer theDetUnits = theTracker.dets();
294
295
296 // Save Data
297
298 for(unsigned int i=0;i<SimTrackProducers.size();i++){
299 edm::Handle<std::vector< SimTrack > > h_SimTracks;
300 iEvent.getByLabel(SimTrackProducers[i], h_SimTracks);
301 std::vector< SimTrack > SimTrackColl = *h_SimTracks.product();
302
303 MySimEvent* MyEvent = new MySimEvent;
304
305 for ( unsigned int a = 0; a < SimTrackColl.size(); ++a ) {
306 MySimTrack MysimTrack;
307 SimTrack simTrack =SimTrackColl[a];
308
309 MysimTrack.track_id =simTrack.trackId();
310 MysimTrack.Type =simTrack.type();
311 MysimTrack.parent_vertex=simTrack.vertIndex();
312 MysimTrack.Px =simTrack.momentum().x();
313 MysimTrack.Py =simTrack.momentum().y();
314 MysimTrack.Pz =simTrack.momentum().z();
315 MysimTrack.E =simTrack.momentum().e();
316 MysimTrack.charge =simTrack.charge();
317
318 MyEvent->MySimTrackCollection.push_back(MysimTrack);
319 }
320 }
321
322
323 for(unsigned int i=0;i<SimVertexProducers.size();i++){
324 edm::Handle<std::vector< SimVertex > > h_Vertex;
325 iEvent.getByLabel(SimVertexProducers[i], h_Vertex);
326 std::vector< SimVertex > VertexColl = *h_Vertex.product();
327
328 for (unsigned int b = 0; b < VertexColl.size(); ++b ) {
329 MySimVertex MyVertex;
330 SimVertex Vertex = VertexColl[b];
331
332 MyVertex.parentTrack_id =Vertex.parentIndex ();
333 MyVertex.x =Vertex.position().x();
334 MyVertex.y =Vertex.position().y();
335 MyVertex.z =Vertex.position().z();
336
337 MyEvent->MySimVertexCollection.push_back(MyVertex);
338 }
339 }
340
341 for(unsigned int i=0;i<SimHitProducers.size();i++){
342 edm::Handle<std::vector< PSimHit > > h_Hits;
343 iEvent.getByLabel(SimHitProducers[i], h_Hits);
344 std::vector< PSimHit > Hits = *h_Hits.product();
345
346 for(unsigned int h=0; h<Hits.size(); h++)
347 {
348 DetId theDetUnitId(Hits[h].detUnitId());
349 const GeomDet * theDet = theTracker.idToDet(theDetUnitId);
350
351 MyPSimHit Hit;
352 Hit.x = theDet->surface().toGlobal(Hits[h].localPosition()).x();
353 Hit.y = theDet->surface().toGlobal(Hits[h].localPosition()).y();
354 Hit.z = theDet->surface().toGlobal(Hits[h].localPosition()).z();
355 Hit.ProcessType = Hits[h].processType();
356 Hit.dEdX = Hits[h].energyLoss();
357
358 MyEvent->MyPSimHitCollection.push_back(Hit);
359 }
360 }
361
362
363 for(unsigned int i=0;i<TrackProducers.size();i++){
364 edm::Handle<std::vector< reco::Track > > h_Tracks;
365 iEvent.getByLabel(TrackProducers[i], h_Tracks);
366 std::vector< reco::Track > TrackColl = *h_Tracks.product();
367
368 for ( unsigned int t = 0; t < TrackColl.size(); ++t ) {
369 MyRecoTrack MyrecoTrack;
370 reco::Track recoTrack =TrackColl[t];
371
372 for(unsigned int h=0;h<recoTrack.recHitsSize();h++){
373 TrackingRecHitRef h_it = recoTrack.recHit(h);
374 if(!h_it->isValid() )continue;
375 DetId detId = h_it->geographicalId();
376 const GeomDet * theDet = theTracker.idToDet(detId);
377 LocalPoint localPos = h_it->localPosition();
378
379 MyRecoHit hit;
380 hit.x = theDet->surface().toGlobal(localPos).x();
381 hit.y = theDet->surface().toGlobal(localPos).y();
382 hit.z = theDet->surface().toGlobal(localPos).z();
383 hit.DetId = detId.rawId();
384 hit.Charge = -1;
385 MyrecoTrack.Hits.push_back(hit);
386 }
387 MyEvent->MyRecoTrackCollection.push_back(MyrecoTrack);
388 }
389 }
390
391
392 for(unsigned int i=0;i<EcalRecHitProducers.size();i++){
393 edm::Handle<EcalRecHitCollection > h_Ecal_RecHits;
394 iEvent.getByLabel(EcalRecHitProducers[i], h_Ecal_RecHits);
395 EcalRecHitCollection Ecal_RecHits = *h_Ecal_RecHits.product();
396
397 for(unsigned int eh=0;eh<Ecal_RecHits.size();eh++){
398 MyCaloHit temp_EcalHit;
399 temp_EcalHit.E = Ecal_RecHits[eh].energy();
400 temp_EcalHit.t = Ecal_RecHits[eh].time();
401 temp_EcalHit.DetId = (Ecal_RecHits[eh].detid()).rawId();
402
403 MyEvent->MyEcalCaloHitCollection.push_back(temp_EcalHit);
404 }
405 }
406
407
408 for(unsigned int i=0;i<HcalHBHERecHitProducers.size();i++){
409 edm::Handle<HBHERecHitCollection > h_HcalHBHE_RecHits;
410 iEvent.getByLabel(HcalHBHERecHitProducers[i], h_HcalHBHE_RecHits);
411 HBHERecHitCollection HcalHBHE_RecHits = *h_HcalHBHE_RecHits.product();
412
413 for(unsigned int hh=0;hh<HcalHBHE_RecHits.size();hh++){
414 MyCaloHit temp_HcalHBHEHit;
415 temp_HcalHBHEHit.E = HcalHBHE_RecHits[hh].energy();
416 temp_HcalHBHEHit.t = HcalHBHE_RecHits[hh].time();
417 temp_HcalHBHEHit.DetId = (HcalHBHE_RecHits[hh].detid()).rawId();
418
419 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHBHEHit);
420 }
421 }
422
423
424 for(unsigned int i=0;i<HcalHORecHitProducers.size();i++){
425 edm::Handle<HORecHitCollection > h_HcalHO_RecHits;
426 iEvent.getByLabel(HcalHORecHitProducers[i], h_HcalHO_RecHits);
427 HORecHitCollection HcalHO_RecHits = *h_HcalHO_RecHits.product();
428
429 for(unsigned int hh=0;hh<HcalHO_RecHits.size();hh++){
430 MyCaloHit temp_HcalHOHit;
431 temp_HcalHOHit.E = HcalHO_RecHits[hh].energy();
432 temp_HcalHOHit.t = HcalHO_RecHits[hh].time();
433 temp_HcalHOHit.DetId = (HcalHO_RecHits[hh].detid()).rawId();
434
435 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHOHit);
436 }
437 }
438
439
440 for(unsigned int i=0;i<HcalHFRecHitProducers.size();i++){
441 edm::Handle<HFRecHitCollection > h_HcalHF_RecHits;
442 iEvent.getByLabel(HcalHFRecHitProducers[i], h_HcalHF_RecHits);
443 HFRecHitCollection HcalHF_RecHits = *h_HcalHF_RecHits.product();
444
445 for(unsigned int hh=0;hh<HcalHF_RecHits.size();hh++){
446 MyCaloHit temp_HcalHFHit;
447 temp_HcalHFHit.E = HcalHF_RecHits[hh].energy();
448 temp_HcalHFHit.t = HcalHF_RecHits[hh].time();
449 temp_HcalHFHit.DetId = (HcalHF_RecHits[hh].detid()).rawId();
450
451 MyEvent->MyHcalCaloHitCollection.push_back(temp_HcalHFHit);
452 }
453 }
454
455 MyEvents->Events.push_back(MyEvent);
456 }
457
458
459 //define this as a plug-in
460 DEFINE_FWK_MODULE(OpenGLDisplayer);
461
462