ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ShallowTools/plugins/ShallowSimTracksProducer.cc
Revision: 1.3
Committed: Tue Sep 29 10:16:31 2009 UTC (15 years, 7 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -0 lines
Log Message:
updates for CMSSW_3_3_X

File Contents

# Content
1 #include "UserCode/ShallowTools/interface/ShallowSimTracksProducer.h"
2 #include "UserCode/ShallowTools/interface/ShallowTools.h"
3
4 #include "FWCore/Framework/interface/Event.h"
5 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
6 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
7 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByChi2.h"
8 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByHits.h"
9 #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
10
11 #include "FWCore/MessageLogger/interface/MessageLogger.h"
12
13 ShallowSimTracksProducer::ShallowSimTracksProducer(const edm::ParameterSet& conf)
14 : Prefix( conf.getParameter<std::string>("Prefix") ),
15 Suffix( conf.getParameter<std::string>("Suffix") ),
16 trackingParticles_tag( conf.getParameter<edm::InputTag>("TrackingParticles")),
17 associator_tag( conf.getParameter<edm::ESInputTag>("Associator")),
18 tracks_tag( conf.getParameter<edm::InputTag>("Tracks"))
19 {
20 produces <std::vector<unsigned> > ( Prefix + "multi" + Suffix );
21 produces <std::vector<int> > ( Prefix + "type" + Suffix );
22 produces <std::vector<float> > ( Prefix + "charge" + Suffix );
23 produces <std::vector<float> > ( Prefix + "momentum" + Suffix );
24 produces <std::vector<float> > ( Prefix + "pt" + Suffix );
25 produces <std::vector<double> > ( Prefix + "theta" + Suffix );
26 produces <std::vector<double> > ( Prefix + "phi" + Suffix );
27 produces <std::vector<double> > ( Prefix + "eta" + Suffix );
28 produces <std::vector<double> > ( Prefix + "qoverp" + Suffix );
29 produces <std::vector<double> > ( Prefix + "vx" + Suffix );
30 produces <std::vector<double> > ( Prefix + "vy" + Suffix );
31 produces <std::vector<double> > ( Prefix + "vz" + Suffix );
32 }
33
34
35 void ShallowSimTracksProducer::
36 produce(edm::Event& event, const edm::EventSetup& setup) {
37
38 edm::Handle<edm::View<reco::Track> > tracks ; event.getByLabel( tracks_tag, tracks);
39 edm::Handle<TrackingParticleCollection> trackingParticles ; event.getByLabel( trackingParticles_tag, trackingParticles );
40 edm::ESHandle<TrackAssociatorBase> associator ; setup.get<TrackAssociatorRecord>().get( associator_tag, associator);
41
42 unsigned size = tracks->size();
43 std::auto_ptr<std::vector<unsigned> > multi ( new std::vector<unsigned>(size, 0));
44 std::auto_ptr<std::vector<int> > type ( new std::vector<int> (size, 0));
45 std::auto_ptr<std::vector<float> > charge ( new std::vector<float> (size, 0));
46 std::auto_ptr<std::vector<float> > momentum ( new std::vector<float> (size, -1));
47 std::auto_ptr<std::vector<float> > pt ( new std::vector<float> (size, -1));
48 std::auto_ptr<std::vector<double> > theta ( new std::vector<double> (size,-1000));
49 std::auto_ptr<std::vector<double> > phi ( new std::vector<double> (size,-1000));
50 std::auto_ptr<std::vector<double> > eta ( new std::vector<double> (size,-1000));
51 std::auto_ptr<std::vector<double> > dxy ( new std::vector<double> (size,-1000));
52 std::auto_ptr<std::vector<double> > dsz ( new std::vector<double> (size,-1000));
53 std::auto_ptr<std::vector<double> > qoverp ( new std::vector<double> (size,-1000));
54 std::auto_ptr<std::vector<double> > vx ( new std::vector<double> (size,-1000));
55 std::auto_ptr<std::vector<double> > vy ( new std::vector<double> (size,-1000));
56 std::auto_ptr<std::vector<double> > vz ( new std::vector<double> (size,-1000));
57
58 reco::RecoToSimCollection associations = associator->associateRecoToSim( tracks, trackingParticles, &event );
59
60 for( reco::RecoToSimCollection::const_iterator association = associations.begin();
61 association != associations.end(); association++) {
62
63 const reco::Track* track = association->key.get();
64 const int matches = association->val.size();
65 if(matches>0) {
66 const TrackingParticle* tparticle = association->val[0].first.get();
67 unsigned i = shallow::findTrackIndex(tracks, track);
68
69 multi->at(i) = matches;
70 type->at(i) = tparticle->pdgId();
71 charge->at(i)= tparticle->charge();
72 momentum->at(i)=tparticle->p() ;
73 pt->at(i) = tparticle->pt() ;
74 theta->at(i) = tparticle->theta() ;
75 phi->at(i) = tparticle->phi() ;
76 eta->at(i) = tparticle->eta() ;
77 qoverp->at(i)= tparticle->charge()/tparticle->p();
78
79 const TrackingVertex* tvertex = tparticle->parentVertex().get();
80 vx->at(i) = tvertex->position().x();
81 vy->at(i) = tvertex->position().y();
82 vz->at(i) = tvertex->position().z();
83 }
84 }
85
86 event.put( multi ,Prefix + "multi" + Suffix );
87 event.put( type ,Prefix + "type" + Suffix );
88 event.put( charge ,Prefix + "charge" + Suffix );
89 event.put( momentum ,Prefix + "momentum" + Suffix );
90 event.put( pt ,Prefix + "pt" + Suffix );
91 event.put( theta ,Prefix + "theta" + Suffix );
92 event.put( phi ,Prefix + "phi" + Suffix );
93 event.put( eta ,Prefix + "eta" + Suffix );
94 event.put( qoverp ,Prefix + "qoverp" + Suffix );
95 event.put( vx ,Prefix + "vx" + Suffix );
96 event.put( vy ,Prefix + "vy" + Suffix );
97 event.put( vz ,Prefix + "vz" + Suffix );
98
99 }