ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FastOpenGlDisplayer/src/OpenGLDisplayer.cc
Revision: 1.8
Committed: Fri Mar 21 08:41:36 2008 UTC (17 years, 1 month ago) by querten
Content type: text/plain
Branch: MAIN
Changes since 1.7: +2 -3 lines
Log Message:
Fix TrackerGeometry in Endcap

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