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

File Contents

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