ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/OpenGLDisplayer.cc
Revision: 1.11
Committed: Sun Mar 23 09:45:19 2008 UTC (17 years, 1 month ago) by querten
Content type: text/plain
Branch: MAIN
Changes since 1.10: +41 -12 lines
Log Message:
Fix BMP under Linux and HCAL Geom

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 "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
58
59 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
60 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
61 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
62 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
63 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
64 #include "SimDataFormats/Track/interface/SimTrack.h"
65 #include "SimDataFormats/Vertex/interface/SimVertex.h"
66
67 #include "DataFormats/Provenance/interface/BranchDescription.h"
68 #include "DataFormats/Provenance/interface/Provenance.h"
69 #include "DataFormats/Candidate/interface/Candidate.h"
70 #include "DataFormats/HepMCCandidate/interface/GenParticleCandidate.h"
71 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
72 #include "DataFormats/TrackReco/interface/Track.h"
73
74 #include "DataFormats/Math/interface/Point3D.h"
75 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
76 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
77
78 #include "Visualisation/OpenGLDisplayer/interface/SimEvent.h"
79 #include "Visualisation/OpenGLDisplayer/interface/Geometry.h"
80
81 using namespace edm;
82 using namespace std;
83
84 //
85 // class decleration
86 //
87
88 class OpenGLDisplayer : public edm::EDAnalyzer {
89 public:
90 explicit OpenGLDisplayer(const edm::ParameterSet&);
91 ~OpenGLDisplayer();
92
93
94 private:
95 virtual void beginJob(const edm::EventSetup& iSetup);
96 virtual void analyze (const edm::Event&, const edm::EventSetup&);
97 virtual void endJob ();
98
99
100 MySimEvents* MyEvents;
101 Geometry* Geom_Tracker;
102 Geometry* Geom_ECAL;
103 Geometry* Geom_HCAL;
104
105
106 std::vector<std::string> SimHitSubdetectors;
107
108 std::string OutputFile;
109
110
111 // ----------member data ---------------------------
112 };
113
114 //
115 // constructors and destructor
116 //
117 OpenGLDisplayer::OpenGLDisplayer(const edm::ParameterSet& iConfig)
118 {
119 SimHitSubdetectors = iConfig.getParameter<std::vector<std::string> >("SimHitSubdetectors");
120
121 OutputFile = iConfig.getParameter<std::string >("OutputFile");
122 }
123
124
125 OpenGLDisplayer::~OpenGLDisplayer()
126 {
127 }
128
129 // ------------ method called once each job just before starting event loop ------------
130 void
131 OpenGLDisplayer::beginJob(const edm::EventSetup& iSetup)
132 {
133 DetId Detid;
134 int SubDet;
135
136 MyEvents = new MySimEvents();
137 Geom_Tracker = new Geometry();
138 Geom_ECAL = new Geometry();
139 Geom_HCAL = new Geometry();
140
141
142 edm::ESHandle<TrackerGeometry> tkGeom;
143 iSetup.get<TrackerDigiGeometryRecord>().get( tkGeom );
144 vector<GeomDet*> TrackerDets = tkGeom->dets();
145
146 for(unsigned int i=0;i<TrackerDets.size();i++){
147 Detid = TrackerDets[i]->geographicalId();
148 // SubDet = Detid.subdetId();
149
150 GeomDet* DetUnit = TrackerDets[i];
151 if(!DetUnit)continue;
152 const BoundPlane plane = DetUnit->surface();
153 const TrapezoidalPlaneBounds* trapezoidalBounds( dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
154 const RectangularPlaneBounds* rectangularBounds( dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
155
156 float width = 0;
157 float length = 0;
158 float thickness = 0;
159 float TrapezoidalParam = 0;
160
161 if(trapezoidalBounds)
162 {
163 std::vector<float> const & parameters = (*trapezoidalBounds).parameters();
164 width = parameters[0]*2;
165 length = parameters[3]*2;
166 thickness = (*trapezoidalBounds).thickness();
167 TrapezoidalParam = parameters[1]/parameters[0];
168 }else if(rectangularBounds){
169 width = DetUnit->surface().bounds().width();
170 length = DetUnit->surface().bounds().length();
171 thickness = DetUnit->surface().bounds().thickness();
172 TrapezoidalParam = 1;
173 }
174
175 Surface::GlobalPoint WidthVector = plane.toGlobal( LocalPoint(width/2, 0, 0) );
176 Surface::GlobalPoint LengthVector = plane.toGlobal( LocalPoint(0, length/2, 0) );
177 Surface::GlobalPoint ThickVector = plane.toGlobal( LocalPoint(0, 0, thickness/2) );
178
179 GlobalVector Pos = GlobalVector(DetUnit->position().basicVector());
180
181 Geom_Tracker->Add_TrackerDet(Detid.rawId(), TrapezoidalParam,
182 Pos.x(), Pos.y(), Pos.z(),
183 WidthVector.x() -Pos.x(), WidthVector.y() -Pos.y(), WidthVector.z() -Pos.z(),
184 LengthVector.x()-Pos.x(), LengthVector.y()-Pos.y(), LengthVector.z()-Pos.z(),
185 ThickVector.x() -Pos.x(), ThickVector.y() -Pos.y(), ThickVector.z() -Pos.z());
186
187
188 }
189
190
191 // ### CALO GEOMETRY ###
192
193 edm::ESHandle<CaloGeometry> CaloGeom;
194 iSetup.get<IdealGeometryRecord>().get( CaloGeom );
195 const vector<DetId> CaloDets = CaloGeom->getValidDetIds();
196
197 for(unsigned int i=0;i<CaloDets.size();i++)
198 {
199 Detid = CaloDets[i];
200 SubDet = Detid.subdetId();
201
202 Geometry* Geom_temp = NULL;
203 if(Detid.det()==DetId::Ecal){
204 Geom_temp = Geom_ECAL;
205
206 if(SubDet<1 || SubDet>3){
207 printf("Don't Save EcalTriggerTower or EcalLaserPnDiode\n");
208 continue;
209 }
210 }else if(Detid.det()==DetId::Hcal){
211 Geom_temp = Geom_HCAL;
212
213 if(SubDet<1 || SubDet>4){
214 printf("Don't Save HcalEmpty, HcalTriggerTower, HcalOther\n");
215 continue;
216 }
217 }else{
218 continue;
219 }
220
221 const CaloCellGeometry* CellGeom = CaloGeom->getGeometry(Detid);
222 GlobalPoint CellPos = CellGeom->getPosition();
223 const CaloCellGeometry::CornersVec CellCorners = CellGeom->getCorners();
224
225 Geom_temp->Add_CaloDet(Detid.rawId(),
226 CellPos.x() , CellPos.y() , CellPos.z(),
227 CellCorners[0].x() , CellCorners[0].y() , CellCorners[0].z() ,
228 CellCorners[1].x() , CellCorners[1].y() , CellCorners[1].z() ,
229 CellCorners[2].x() , CellCorners[2].y() , CellCorners[2].z() ,
230 CellCorners[3].x() , CellCorners[3].y() , CellCorners[3].z() ,
231 CellCorners[4].x() , CellCorners[4].y() , CellCorners[4].z() ,
232 CellCorners[5].x() , CellCorners[5].y() , CellCorners[5].z() ,
233 CellCorners[6].x() , CellCorners[6].y() , CellCorners[6].z() ,
234 CellCorners[7].x() , CellCorners[7].y() , CellCorners[7].z() );
235 }
236
237 Geom_Tracker->Save("Tracker.geom");
238 Geom_ECAL->Save("ECAL.geom");
239 Geom_HCAL->Save("HCAL.geom");
240
241
242
243 }
244
245 // ------------ method called once each job just after ending the event loop ------------
246 void
247 OpenGLDisplayer::endJob() {
248
249 MyEvents->Save((char*) OutputFile.c_str());
250 MyEvents->Load((char*) OutputFile.c_str());
251 }
252
253
254
255 //
256 // member functions
257 //
258
259 // ------------ method called to for each event ------------
260 void
261 OpenGLDisplayer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
262 {
263
264 edm::Handle<std::vector< SimTrack > > h_SimTracks;
265 iEvent.getByLabel("g4SimHits", h_SimTracks);
266 std::vector< SimTrack > SimTrackColl = *h_SimTracks.product();
267
268 edm::Handle<std::vector< SimVertex > > h_Vertex;
269 iEvent.getByLabel("g4SimHits", h_Vertex);
270 std::vector< SimVertex > VertexColl = *h_Vertex.product();
271
272
273
274 // access the tracker
275 edm::ESHandle<TrackerGeometry> theTrackerGeometry;
276 iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
277 const TrackerGeometry& theTracker(*theTrackerGeometry);
278
279 // the DetUnits
280 TrackingGeometry::DetContainer theDetUnits = theTracker.dets();
281
282
283
284
285 // Save the data
286
287 MySimEvent* MyEvent = new MySimEvent;
288
289 for ( unsigned int a = 0; a < SimTrackColl.size(); ++a ) {
290 MySimTrack MysimTrack;
291 SimTrack simTrack =SimTrackColl[a];
292
293 MysimTrack.track_id =simTrack.trackId();
294 MysimTrack.Type =simTrack.type();
295 MysimTrack.parent_vertex=simTrack.vertIndex();
296 MysimTrack.Px =simTrack.momentum().x();
297 MysimTrack.Py =simTrack.momentum().y();
298 MysimTrack.Pz =simTrack.momentum().z();
299 MysimTrack.E =simTrack.momentum().e();
300 MysimTrack.charge =simTrack.charge();
301
302 MyEvent->MySimTrackCollection.push_back(MysimTrack);
303 }
304
305
306 for (unsigned int b = 0; b < VertexColl.size(); ++b ) {
307 MySimVertex MyVertex;
308 SimVertex Vertex = VertexColl[b];
309
310 MyVertex.parentTrack_id =Vertex.parentIndex ();
311 MyVertex.x =Vertex.position().x();
312 MyVertex.y =Vertex.position().y();
313 MyVertex.z =Vertex.position().z();
314
315 MyEvent->MySimVertexCollection.push_back(MyVertex);
316 }
317
318 for(unsigned int i=0; i<SimHitSubdetectors.size(); i++)
319 {
320 edm::Handle<std::vector< PSimHit > > h_Hits;
321 iEvent.getByLabel("g4SimHits",SimHitSubdetectors[i].c_str(), h_Hits);
322 std::vector< PSimHit > Hits = *h_Hits.product();
323
324 for(unsigned int h=0; h<Hits.size(); h++)
325 {
326 DetId theDetUnitId(Hits[h].detUnitId());
327 const GeomDet * theDet = theTracker.idToDet(theDetUnitId);
328
329 MyPSimHit Hit;
330 Hit.x = theDet->surface().toGlobal(Hits[h].localPosition()).x();
331 Hit.y = theDet->surface().toGlobal(Hits[h].localPosition()).y();
332 Hit.z = theDet->surface().toGlobal(Hits[h].localPosition()).z();
333 Hit.ProcessType = Hits[h].processType();
334 Hit.dEdX = Hits[h].energyLoss();
335
336 MyEvent->MyPSimHitCollection.push_back(Hit);
337
338 }
339 }
340
341 edm::Handle<std::vector< reco::Track > > h_Tracks;
342 iEvent.getByLabel("ctfWithMaterialTracks", h_Tracks);
343 std::vector< reco::Track > TrackColl = *h_Tracks.product();
344
345 for ( unsigned int t = 0; t < TrackColl.size(); ++t ) {
346 MyRecoTrack MyrecoTrack;
347 reco::Track recoTrack =TrackColl[t];
348
349 // MyrecoTrack.Hits = new MyRecoHit[MyrecoTrack.N];
350
351 for(unsigned int h=0;h<recoTrack.recHitsSize();h++){
352 TrackingRecHitRef h_it = recoTrack.recHit(h);
353 if(!h_it->isValid() )continue;
354 DetId detId = h_it->geographicalId();
355 const GeomDet * theDet = theTracker.idToDet(detId);
356 LocalPoint localPos = h_it->localPosition();
357
358 MyRecoHit hit;
359 hit.x = theDet->surface().toGlobal(localPos).x();
360 hit.y = theDet->surface().toGlobal(localPos).y();
361 hit.z = theDet->surface().toGlobal(localPos).z();
362 hit.DetId = detId.rawId();
363 hit.Charge = -1;
364 MyrecoTrack.Hits.push_back(hit);
365
366
367 // printf("%8.2f %8.2f %8.2f\n",theDet->surface().toGlobal(localPos).x(),theDet->surface().toGlobal(localPos).y(),theDet->surface().toGlobal(localPos).z());
368 }
369 MyEvent->MyRecoTrackCollection.push_back(MyrecoTrack);
370 }
371
372 MyEvents->Events.push_back(MyEvent);
373
374 }
375
376
377 //define this as a plug-in
378 DEFINE_FWK_MODULE(OpenGLDisplayer);
379
380