CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoParticleFlow/PFTracking/plugins/PFV0Producer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/plugins/PFV0Producer.h"
00003 #include "DataFormats/ParticleFlowReco/interface/PFV0.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
00005 #include "DataFormats/ParticleFlowReco/interface/PFV0Fwd.h"
00006 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00007 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00008 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "MagneticField/Engine/interface/MagneticField.h"
00011 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00012 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
00013 
00014 using namespace std;
00015 using namespace edm;
00016 using namespace reco;
00017 PFV0Producer::PFV0Producer(const ParameterSet& iConfig):
00018   pfTransformer_(0)
00019 {
00020 
00021   produces<reco::PFV0Collection>();
00022   produces<reco::PFRecTrackCollection>();
00023 
00024   V0list_ = 
00025     iConfig.getParameter< vector < InputTag > >("V0List");
00026 }
00027 
00028 PFV0Producer::~PFV0Producer()
00029 {
00030   delete pfTransformer_;
00031 }
00032 
00033 void
00034 PFV0Producer::produce(Event& iEvent, const EventSetup& iSetup)
00035 {
00036   LogDebug("PFV0Producer")<<"START event: "<<iEvent.id().event()
00037                           <<" in run "<<iEvent.id().run();
00038   //create the empty collections 
00039   auto_ptr< PFV0Collection > pfV0Coll (new PFV0Collection);
00040 
00041   auto_ptr<reco::PFRecTrackCollection> pfV0RecTrackColl(new reco::PFRecTrackCollection);
00042 
00043 
00044   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
00045   int idx = 0;
00046 
00047   for (unsigned int il=0; il<V0list_.size(); il++){
00048     Handle<VertexCompositeCandidateCollection> V0coll;
00049     iEvent.getByLabel(V0list_[il],V0coll);
00050     LogDebug("PFV0Producer")<<V0list_[il]<<" contains "<<V0coll->size()<<" V0 candidates ";
00051     for (unsigned int iv=0;iv<V0coll->size();iv++){
00052       VertexCompositeCandidateRef V0(V0coll, iv);
00053       vector<TrackRef> Tracks;
00054       vector<PFRecTrackRef> PFTracks;
00055       for( unsigned int ndx = 0; ndx < V0->numberOfDaughters(); ndx++ ) {
00056         
00057         Tracks.push_back( (dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track() );
00058         TrackRef trackRef = (dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track();
00059 
00060         reco::PFRecTrack pfRecTrack( trackRef->charge(), 
00061                                    reco::PFRecTrack::KF, 
00062                                    trackRef.key(), 
00063                                    trackRef );
00064 
00065 
00066         Trajectory FakeTraj;
00067         bool valid = pfTransformer_->addPoints( pfRecTrack, *trackRef, FakeTraj);
00068         if(valid) {
00069           PFTracks.push_back(reco::PFRecTrackRef( pfTrackRefProd, idx++));
00070           pfV0RecTrackColl->push_back(pfRecTrack);
00071           
00072         }
00073       }
00074       if ((PFTracks.size()==2)&&(Tracks.size()==2)){
00075         pfV0Coll->push_back(PFV0(V0,PFTracks,Tracks));
00076       }
00077         
00078       
00079 
00080     }
00081   }
00082   
00083   
00084   iEvent.put(pfV0Coll);
00085   iEvent.put(pfV0RecTrackColl);
00086 }
00087 
00088 // ------------ method called once each job just before starting event loop  ------------
00089 void 
00090 PFV0Producer::beginRun(const edm::Run& run,
00091                                            const EventSetup& iSetup)
00092 {
00093   ESHandle<MagneticField> magneticField;
00094   iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00095   pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00096   pfTransformer_->OnlyProp();
00097 }
00098 
00099 
00100 // ------------ method called once each job just after ending the event loop  ------------
00101 void 
00102 PFV0Producer::endRun(const edm::Run& run,
00103                      const EventSetup& iSetup) {
00104   delete pfTransformer_;
00105   pfTransformer_=nullptr;
00106 }