ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ShallowTools/plugins/ShallowTrackClustersProducer.cc
Revision: 1.3
Committed: Thu Jun 11 16:09:16 2009 UTC (15 years, 10 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
Added ShallowSimTracksProducer (sans cfi)

File Contents

# User Rev Content
1 bbetchar 1.1 #include "UserCode/ShallowTools/interface/ShallowTrackClustersProducer.h"
2    
3     #include "UserCode/ShallowTools/interface/ShallowTools.h"
4    
5     #include "TrackingTools/PatternTools/interface/Trajectory.h"
6     #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
7     #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
8    
9     #include "MagneticField/Engine/interface/MagneticField.h"
10     #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
11     #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
12     #include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
13     #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
14     #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
15     #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
16     #include "Geometry/CommonTopologies/interface/StripTopology.h"
17     #include "FWCore/Framework/interface/ESHandle.h"
18 bbetchar 1.2 #include "boost/foreach.hpp"
19 bbetchar 1.1
20     ShallowTrackClustersProducer::ShallowTrackClustersProducer(const edm::ParameterSet& iConfig)
21     : theTracksLabel( iConfig.getParameter<edm::InputTag>("Tracks") ),
22     Suffix ( iConfig.getParameter<std::string>("Suffix") ),
23     Prefix ( iConfig.getParameter<std::string>("Prefix") )
24     {
25     produces <std::vector<unsigned int> > ( Prefix + "trackmulti" + Suffix );
26     produces <std::vector<int> > ( Prefix + "trackindex" + Suffix );
27     produces <std::vector<float> > ( Prefix + "localtheta" + Suffix );
28     produces <std::vector<float> > ( Prefix + "localphi" + Suffix );
29     produces <std::vector<float> > ( Prefix + "localpitch" + Suffix );
30     produces <std::vector<float> > ( Prefix + "localx" + Suffix );
31     produces <std::vector<float> > ( Prefix + "localy" + Suffix );
32     produces <std::vector<float> > ( Prefix + "localz" + Suffix );
33     produces <std::vector<float> > ( Prefix + "strip" + Suffix );
34     produces <std::vector<float> > ( Prefix + "globaltheta" + Suffix );
35     produces <std::vector<float> > ( Prefix + "globalphi" + Suffix );
36     produces <std::vector<float> > ( Prefix + "globalx" + Suffix );
37     produces <std::vector<float> > ( Prefix + "globaly" + Suffix );
38     produces <std::vector<float> > ( Prefix + "globalz" + Suffix );
39     produces <std::vector<float> > ( Prefix + "insidistance"+ Suffix );
40     produces <std::vector<float> > ( Prefix + "covered" + Suffix );
41     produces <std::vector<float> > ( Prefix + "projwidth" + Suffix );
42     produces <std::vector<float> > ( Prefix + "projlength" + Suffix );
43    
44     produces <std::vector<float> > ( Prefix + "rhlocalx" + Suffix );
45     produces <std::vector<float> > ( Prefix + "rhlocaly" + Suffix );
46     produces <std::vector<float> > ( Prefix + "rhlocalxerr" + Suffix );
47     produces <std::vector<float> > ( Prefix + "rhlocalyerr" + Suffix );
48     produces <std::vector<float> > ( Prefix + "rhglobalx" + Suffix );
49     produces <std::vector<float> > ( Prefix + "rhglobaly" + Suffix );
50     produces <std::vector<float> > ( Prefix + "rhglobalz" + Suffix );
51     produces <std::vector<float> > ( Prefix + "rhstrip" + Suffix );
52     produces <std::vector<float> > ( Prefix + "rhmerr" + Suffix );
53    
54     produces <std::vector<float> > ( Prefix + "driftx" + Suffix );
55     produces <std::vector<float> > ( Prefix + "drifty" + Suffix );
56     produces <std::vector<float> > ( Prefix + "driftz" + Suffix );
57     }
58    
59     void ShallowTrackClustersProducer::
60     produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
61     shallow::CLUSTERMAP clustermap = shallow::make_cluster_map(iEvent);
62    
63     int size = clustermap.size();
64     std::auto_ptr<std::vector<unsigned int> > trackmulti ( new std::vector<unsigned int>(size, 0) );
65     std::auto_ptr<std::vector<int> > trackindex ( new std::vector<int> (size, -1) );
66     std::auto_ptr<std::vector<float> > localtheta ( new std::vector<float> (size, -100) );
67     std::auto_ptr<std::vector<float> > localphi ( new std::vector<float> (size, -100) );
68     std::auto_ptr<std::vector<float> > localpitch ( new std::vector<float> (size, -100) );
69     std::auto_ptr<std::vector<float> > localx ( new std::vector<float> (size, -100) );
70     std::auto_ptr<std::vector<float> > localy ( new std::vector<float> (size, -100) );
71     std::auto_ptr<std::vector<float> > localz ( new std::vector<float> (size, -100) );
72     std::auto_ptr<std::vector<float> > strip ( new std::vector<float> (size, -100) );
73     std::auto_ptr<std::vector<float> > globaltheta ( new std::vector<float> (size, -100) );
74     std::auto_ptr<std::vector<float> > globalphi ( new std::vector<float> (size, -100) );
75     std::auto_ptr<std::vector<float> > globalx ( new std::vector<float> (size, -10000) );
76     std::auto_ptr<std::vector<float> > globaly ( new std::vector<float> (size, -10000) );
77     std::auto_ptr<std::vector<float> > globalz ( new std::vector<float> (size, -10000) );
78     std::auto_ptr<std::vector<float> > insidistance ( new std::vector<float> (size, -1) );
79     std::auto_ptr<std::vector<float> > projwidth ( new std::vector<float> (size, -1000) );
80     std::auto_ptr<std::vector<float> > covered ( new std::vector<float> (size, -1000) );
81     std::auto_ptr<std::vector<float> > projlength ( new std::vector<float> (size, -1000) );
82     std::auto_ptr<std::vector<float> > rhlocalx ( new std::vector<float>(size, -10000 ));
83     std::auto_ptr<std::vector<float> > rhlocaly ( new std::vector<float>(size, -10000 ));
84     std::auto_ptr<std::vector<float> > rhlocalxerr ( new std::vector<float>(size, -1 ));
85     std::auto_ptr<std::vector<float> > rhlocalyerr ( new std::vector<float>(size, -1 ));
86     std::auto_ptr<std::vector<float> > rhglobalx ( new std::vector<float>(size, -10000 ));
87     std::auto_ptr<std::vector<float> > rhglobaly ( new std::vector<float>(size, -10000 ));
88     std::auto_ptr<std::vector<float> > rhglobalz ( new std::vector<float>(size, -10000 ));
89     std::auto_ptr<std::vector<float> > rhstrip ( new std::vector<float>(size, -10000 ));
90     std::auto_ptr<std::vector<float> > rhmerr ( new std::vector<float>(size, -10000 ));
91     std::auto_ptr<std::vector<float> > driftx ( new std::vector<float>(size, -10000 ));
92     std::auto_ptr<std::vector<float> > drifty ( new std::vector<float>(size, -10000 ));
93     std::auto_ptr<std::vector<float> > driftz ( new std::vector<float>(size, -10000 ));
94    
95     edm::ESHandle<TrackerGeometry> theTrackerGeometry; iSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
96     edm::ESHandle<MagneticField> magfield; iSetup.get<IdealMagneticFieldRecord>().get(magfield);
97     edm::ESHandle<SiStripLorentzAngle> SiStripLorentzAngle; iSetup.get<SiStripLorentzAngleRcd>().get(SiStripLorentzAngle);
98    
99 bbetchar 1.3 edm::Handle<edm::View<reco::Track> > tracks; iEvent.getByLabel(theTracksLabel, tracks);
100 bbetchar 1.1 edm::Handle<TrajTrackAssociationCollection> associations; iEvent.getByLabel(theTracksLabel, associations);
101    
102     for( TrajTrackAssociationCollection::const_iterator association = associations->begin();
103     association != associations->end(); association++) {
104     const Trajectory* traj = association->key.get();
105     const reco::Track* track = association->val.get();
106    
107     BOOST_FOREACH( const TrajectoryMeasurement measurement, traj->measurements() ) {
108     const TrajectoryStateOnSurface tsos = measurement.updatedState();
109     const SiStripRecHit2D* hit = dynamic_cast<const SiStripRecHit2D*> ( measurement.recHit()->hit() );
110    
111     if(!hit) break;
112     shallow::CLUSTERMAP::const_iterator cluster = clustermap.find( std::make_pair(hit->geographicalId().rawId(), hit->cluster()->firstStrip() ));
113     if(cluster == clustermap.end() ) break;
114    
115     unsigned i = cluster->second;
116     if( 0 == (trackmulti->at(i))++ ) {
117     const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTrackerGeometry->idToDet( hit->geographicalId() ) );
118 bbetchar 1.2 LocalVector drift = shallow::drift( theStripDet, *magfield, *SiStripLorentzAngle);
119 bbetchar 1.1
120     trackindex->at(i) = shallow::findTrackIndex(tracks, track);
121     localtheta->at(i) = (theStripDet->toLocal(tsos.globalDirection())).theta();
122     localphi->at(i) = (theStripDet->toLocal(tsos.globalDirection())).phi();
123     localpitch->at(i) = (theStripDet->specificTopology()).localPitch(theStripDet->toLocal(tsos.globalPosition()));
124     localx->at(i) = (theStripDet->toLocal(tsos.globalPosition())).x();
125     localy->at(i) = (theStripDet->toLocal(tsos.globalPosition())).y();
126     localz->at(i) = (theStripDet->toLocal(tsos.globalPosition())).z();
127     strip->at(i) = (theStripDet->specificTopology()).strip(theStripDet->toLocal(tsos.globalPosition()));
128     globaltheta->at(i) = tsos.globalDirection().theta();
129     globalphi->at(i) = tsos.globalDirection().phi();
130     globalx->at(i) = tsos.globalPosition().x();
131     globaly->at(i) = tsos.globalPosition().y();
132     globalz->at(i) = tsos.globalPosition().z();
133     insidistance->at(i) = 1./fabs(cos(localtheta->at(i)));
134     projwidth->at(i) = tan(localtheta->at(i))*cos(localphi->at(i));
135 bbetchar 1.2 covered->at(i) = drift.z()/localpitch->at(i) * fabs(projwidth->at(i) - drift.x()/drift.z());
136 bbetchar 1.1 projlength->at(i) = tan(localtheta->at(i))*cos(localphi->at(i)) ;
137     rhlocalx->at(i) = hit->localPosition().x();
138     rhlocaly->at(i) = hit->localPosition().y();
139     rhlocalxerr->at(i) = sqrt(hit->localPositionError().xx());
140     rhlocalyerr->at(i) = sqrt(hit->localPositionError().yy());
141     rhglobalx->at(i) = theStripDet->toGlobal(hit->localPosition()).x();
142     rhglobaly->at(i) = theStripDet->toGlobal(hit->localPosition()).y();
143     rhglobalz->at(i) = theStripDet->toGlobal(hit->localPosition()).z();
144     rhstrip->at(i) = theStripDet->specificTopology().strip(hit->localPosition());
145     rhmerr->at(i) = sqrt(theStripDet->specificTopology().measurementError(hit->localPosition(), hit->localPositionError()).uu());
146 bbetchar 1.2 driftx->push_back(drift.x());
147     drifty->push_back(drift.y());
148     driftz->push_back(drift.z());
149 bbetchar 1.1 }
150     }
151     }
152    
153     iEvent.put(trackmulti, Prefix + "trackmulti" + Suffix );
154     iEvent.put(trackindex, Prefix + "trackindex" + Suffix );
155     iEvent.put(localtheta, Prefix + "localtheta" + Suffix );
156     iEvent.put(localphi, Prefix + "localphi" + Suffix );
157     iEvent.put(localpitch, Prefix + "localpitch" + Suffix );
158     iEvent.put(localx, Prefix + "localx" + Suffix );
159     iEvent.put(localy, Prefix + "localy" + Suffix );
160     iEvent.put(localz, Prefix + "localz" + Suffix );
161     iEvent.put(strip, Prefix + "strip" + Suffix );
162     iEvent.put(globaltheta, Prefix + "globaltheta" + Suffix );
163     iEvent.put(globalphi, Prefix + "globalphi" + Suffix );
164     iEvent.put(globalx, Prefix + "globalx" + Suffix );
165     iEvent.put(globaly, Prefix + "globaly" + Suffix );
166     iEvent.put(globalz, Prefix + "globalz" + Suffix );
167     iEvent.put(insidistance,Prefix + "insidistance"+ Suffix );
168     iEvent.put(covered, Prefix + "covered" + Suffix );
169     iEvent.put(projwidth, Prefix + "projwidth" + Suffix );
170     iEvent.put(projlength, Prefix + "projlength" + Suffix );
171     iEvent.put(rhlocalx, Prefix + "rhlocalx" + Suffix );
172     iEvent.put(rhlocaly, Prefix + "rhlocaly" + Suffix );
173     iEvent.put(rhlocalxerr, Prefix + "rhlocalxerr" + Suffix );
174     iEvent.put(rhlocalyerr, Prefix + "rhlocalyerr" + Suffix );
175     iEvent.put(rhglobalx, Prefix + "rhglobalx" + Suffix );
176     iEvent.put(rhglobaly, Prefix + "rhglobaly" + Suffix );
177     iEvent.put(rhglobalz, Prefix + "rhglobalz" + Suffix );
178     iEvent.put(rhstrip, Prefix + "rhstrip" + Suffix );
179     iEvent.put(rhmerr, Prefix + "rhmerr" + Suffix );
180     iEvent.put( driftx, Prefix + "driftx" );
181     iEvent.put( drifty, Prefix + "drifty" );
182     iEvent.put( driftz, Prefix + "driftz" );
183     }