CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoParticleFlow/PFTracking/plugins/PFConversionProducer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/plugins/PFConversionProducer.h"
00003 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFConversionFwd.h"
00005 #include "DataFormats/ParticleFlowReco/interface/PFConversion.h"
00006 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "MagneticField/Engine/interface/MagneticField.h"
00009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00010 #include "DataFormats/Common/interface/RefToBase.h"
00011 
00012 using namespace std;
00013 using namespace edm;
00014 PFConversionProducer::PFConversionProducer(const ParameterSet& iConfig):
00015   pfTransformer_(0)
00016 {
00017   produces<reco::PFRecTrackCollection>();
00018   produces<reco::PFConversionCollection>();
00019 
00020   pfConversionContainer_ = 
00021     iConfig.getParameter< InputTag >("conversionCollection");
00022 
00023 }
00024 
00025 PFConversionProducer::~PFConversionProducer()
00026 {
00027   delete pfTransformer_;
00028 }
00029 
00030 void
00031 PFConversionProducer::produce(Event& iEvent, const EventSetup& iSetup)
00032 {
00033 
00034   //create the empty collections 
00035   auto_ptr< reco::PFConversionCollection > 
00036     pfConversionColl (new reco::PFConversionCollection);
00037   auto_ptr< reco::PFRecTrackCollection > 
00038     pfRecTrackColl (new reco::PFRecTrackCollection);
00039   
00040   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
00041 
00042 
00043     
00044   Handle<reco::ConversionCollection> convCollH;
00045   iEvent.getByLabel(pfConversionContainer_, convCollH);
00046   const reco::ConversionCollection& convColl = *(convCollH.product());
00047 
00048   Handle<reco::TrackCollection> trackColl;
00049   iEvent.getByLabel(pfTrackContainer_, trackColl);
00050 
00051   int idx = 0;
00052 
00053   //  cout << "Size of Displaced Vertices " 
00054   //     <<  convColl.size() << endl;
00055 
00056   // loop on all NuclearInteraction 
00057   for( unsigned int icoll=0; icoll < convColl.size(); icoll++) {
00058     if ( !convColl[icoll].quality(reco::Conversion::generalTracksOnly) ) continue;
00059     std::vector<reco::PFRecTrackRef> pfRecTkcoll;
00060 
00061     std::vector<edm::RefToBase<reco::Track> > tracksRefColl = convColl[icoll].tracks();
00062 
00063     // convert the secondary tracks
00064     for(unsigned it = 0; it < tracksRefColl.size(); it++){
00065 
00066       reco::TrackRef trackRef = (tracksRefColl[it]).castTo<reco::TrackRef>();
00067 
00068       reco::PFRecTrack pfRecTrack( trackRef->charge(), 
00069                                    reco::PFRecTrack::KF, 
00070                                    trackRef.key(), 
00071                                    trackRef );
00072 
00073       // cout << pfRecTrack << endl;
00074 
00075       Trajectory FakeTraj;
00076       bool valid = pfTransformer_->addPoints( pfRecTrack, *trackRef, FakeTraj);
00077       if(valid) {
00078         pfRecTkcoll.push_back(reco::PFRecTrackRef( pfTrackRefProd, idx++));     
00079         pfRecTrackColl->push_back(pfRecTrack);
00080         //      cout << "after "<< pfRecTrack << endl;
00081           
00082       }
00083     }
00084     reco::ConversionRef niRef(convCollH, icoll);
00085     pfConversionColl->push_back( reco::PFConversion( niRef, pfRecTkcoll ));
00086   }
00087  
00088   iEvent.put(pfRecTrackColl);
00089   iEvent.put(pfConversionColl);
00090 }
00091 
00092 // ------------ method called once each job just before starting event loop  ------------
00093 void 
00094 PFConversionProducer::beginRun(edm::Run& run,
00095                                            const EventSetup& iSetup)
00096 {
00097   ESHandle<MagneticField> magneticField;
00098   iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00099   pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00100   pfTransformer_->OnlyProp();
00101 }
00102 
00103 // ------------ method called once each job just after ending the event loop  ------------
00104 void 
00105 PFConversionProducer::endRun() {
00106   delete pfTransformer_;
00107 }