CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibTracker/SiStripCommon/plugins/ShallowSimTracksProducer.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/ShallowSimTracksProducer.h"
00002 #include "CalibTracker/SiStripCommon/interface/ShallowTools.h"
00003 
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00006 #include "SimTracker/Records/interface/TrackAssociatorRecord.h"
00007 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByChi2.h"
00008 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByHits.h"
00009 #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 ShallowSimTracksProducer::ShallowSimTracksProducer(const edm::ParameterSet& conf) 
00014   : Prefix( conf.getParameter<std::string>("Prefix") ),
00015     Suffix( conf.getParameter<std::string>("Suffix") ),
00016     trackingParticles_tag( conf.getParameter<edm::InputTag>("TrackingParticles")),
00017     associator_tag( conf.getParameter<edm::ESInputTag>("Associator")),
00018     tracks_tag( conf.getParameter<edm::InputTag>("Tracks"))
00019 {
00020   produces <std::vector<unsigned> >     ( Prefix + "multi"      + Suffix );
00021   produces <std::vector<int> >          ( Prefix + "type"      + Suffix );
00022   produces <std::vector<float> >        ( Prefix + "charge"    + Suffix );
00023   produces <std::vector<float> >        ( Prefix + "momentum"  + Suffix );
00024   produces <std::vector<float> >        ( Prefix + "pt"        + Suffix );
00025   produces <std::vector<double> >       ( Prefix + "theta"     + Suffix );
00026   produces <std::vector<double> >       ( Prefix + "phi"       + Suffix );
00027   produces <std::vector<double> >       ( Prefix + "eta"       + Suffix );
00028   produces <std::vector<double> >       ( Prefix + "qoverp"    + Suffix );
00029   produces <std::vector<double> >       ( Prefix + "vx"        + Suffix );
00030   produces <std::vector<double> >       ( Prefix + "vy"        + Suffix );
00031   produces <std::vector<double> >       ( Prefix + "vz"        + Suffix );
00032 }
00033 
00034 
00035 void ShallowSimTracksProducer::
00036 produce(edm::Event& event, const edm::EventSetup& setup) {
00037 
00038   edm::Handle<edm::View<reco::Track> >                tracks ;   event.getByLabel( tracks_tag, tracks);
00039   edm::Handle<TrackingParticleCollection>  trackingParticles ;   event.getByLabel( trackingParticles_tag, trackingParticles );  
00040   edm::ESHandle<TrackAssociatorBase>              associator ;   setup.get<TrackAssociatorRecord>().get( associator_tag, associator);
00041 
00042   unsigned size = tracks->size();
00043   std::auto_ptr<std::vector<unsigned> > multi        ( new std::vector<unsigned>(size,    0));
00044   std::auto_ptr<std::vector<int> >      type         ( new std::vector<int>     (size,    0));
00045   std::auto_ptr<std::vector<float> >    charge       ( new std::vector<float>   (size,    0));
00046   std::auto_ptr<std::vector<float> >    momentum     ( new std::vector<float>   (size,   -1));
00047   std::auto_ptr<std::vector<float> >    pt           ( new std::vector<float>   (size,   -1));
00048   std::auto_ptr<std::vector<double> >   theta        ( new std::vector<double>  (size,-1000));
00049   std::auto_ptr<std::vector<double> >   phi          ( new std::vector<double>  (size,-1000));
00050   std::auto_ptr<std::vector<double> >   eta          ( new std::vector<double>  (size,-1000));
00051   std::auto_ptr<std::vector<double> >   dxy          ( new std::vector<double>  (size,-1000));
00052   std::auto_ptr<std::vector<double> >   dsz          ( new std::vector<double>  (size,-1000));
00053   std::auto_ptr<std::vector<double> >   qoverp       ( new std::vector<double>  (size,-1000));
00054   std::auto_ptr<std::vector<double> >   vx           ( new std::vector<double>  (size,-1000));
00055   std::auto_ptr<std::vector<double> >   vy           ( new std::vector<double>  (size,-1000));
00056   std::auto_ptr<std::vector<double> >   vz           ( new std::vector<double>  (size,-1000));
00057 
00058   reco::RecoToSimCollection associations = associator->associateRecoToSim( tracks, trackingParticles, &event );
00059   
00060   for( reco::RecoToSimCollection::const_iterator association = associations.begin(); 
00061        association != associations.end(); association++) {
00062 
00063     const reco::Track* track = association->key.get();
00064     const int matches        = association->val.size();
00065     if(matches>0) {
00066       const TrackingParticle* tparticle = association->val[0].first.get();
00067       unsigned i = shallow::findTrackIndex(tracks, track);
00068 
00069       multi->at(i) = matches;
00070       type->at(i)  = tparticle->pdgId();
00071       charge->at(i)= tparticle->charge();
00072       momentum->at(i)=tparticle->p() ;
00073       pt->at(i) = tparticle->pt()    ;
00074       theta->at(i) = tparticle->theta() ;
00075       phi->at(i)   = tparticle->phi()   ;
00076       eta->at(i)   = tparticle->eta()   ;
00077       qoverp->at(i)= tparticle->charge()/tparticle->p();
00078 
00079       const TrackingVertex* tvertex = tparticle->parentVertex().get();
00080       vx->at(i) = tvertex->position().x();
00081       vy->at(i) = tvertex->position().y();
00082       vz->at(i) = tvertex->position().z();
00083     }
00084   }
00085   
00086   event.put(  multi    ,Prefix + "multi"     + Suffix );
00087   event.put(  type     ,Prefix + "type"      + Suffix );
00088   event.put(  charge   ,Prefix + "charge"    + Suffix );
00089   event.put(  momentum ,Prefix + "momentum"  + Suffix );
00090   event.put(  pt       ,Prefix + "pt"        + Suffix );
00091   event.put(  theta    ,Prefix + "theta"     + Suffix );
00092   event.put(  phi      ,Prefix + "phi"       + Suffix );
00093   event.put(  eta      ,Prefix + "eta"       + Suffix );
00094   event.put(  qoverp   ,Prefix + "qoverp"    + Suffix );
00095   event.put(  vx       ,Prefix + "vx"        + Suffix );
00096   event.put(  vy       ,Prefix + "vy"        + Suffix );
00097   event.put(  vz       ,Prefix + "vz"        + Suffix );
00098   
00099 }