CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoParticleFlow/PFTracking/plugins/PFNuclearProducer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/interface/PFNuclearProducer.h"
00003 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFNuclearInteraction.h"
00005 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "MagneticField/Engine/interface/MagneticField.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 using namespace std;
00010 using namespace edm;
00011 PFNuclearProducer::PFNuclearProducer(const ParameterSet& iConfig):
00012   pfTransformer_(0)
00013 {
00014   produces<reco::PFRecTrackCollection>();
00015   produces<reco::PFNuclearInteractionCollection>();
00016 
00017   nuclearContainers_ = 
00018     iConfig.getParameter< vector < InputTag > >("nuclearColList");
00019   likelihoodCut_
00020      = iConfig.getParameter<double>("likelihoodCut");
00021 }
00022 
00023 PFNuclearProducer::~PFNuclearProducer()
00024 {
00025   delete pfTransformer_;
00026 }
00027 
00028 void
00029 PFNuclearProducer::produce(Event& iEvent, const EventSetup& iSetup)
00030 {
00031   typedef reco::NuclearInteraction::trackRef_iterator trackRef_iterator;
00032 
00033   //create the empty collections 
00034   auto_ptr< reco::PFNuclearInteractionCollection > 
00035     pfNuclearColl (new reco::PFNuclearInteractionCollection);
00036   auto_ptr< reco::PFRecTrackCollection > 
00037     pfNuclearRecTrackColl (new reco::PFRecTrackCollection);
00038   
00039   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
00040   int hid=0;
00041 
00042   // loop on the nuclear interaction collections
00043   for (unsigned int istr=0; istr<nuclearContainers_.size();istr++){
00044     
00045     Handle<reco::NuclearInteractionCollection> nuclCollH;
00046     iEvent.getByLabel(nuclearContainers_[istr], nuclCollH);
00047     const reco::NuclearInteractionCollection& nuclColl = *(nuclCollH.product());
00048 
00049     // loop on all NuclearInteraction 
00050     for( unsigned int icoll=0; icoll < nuclColl.size(); icoll++) {
00051 
00052       if( nuclColl[icoll].likelihood() < likelihoodCut_) continue;
00053 
00054       reco::PFRecTrackRefVector pfRecTkcoll;
00055 
00056       // convert the secondary tracks
00057       for(trackRef_iterator it = nuclColl[icoll].secondaryTracks_begin(); it!=nuclColl[icoll].secondaryTracks_end(); it++){
00058         reco::PFRecTrack pftrack( (*it)->charge(), 
00059                                 reco::PFRecTrack::KF, 
00060                                 it->key(), (reco::TrackRef)((*it).castTo<reco::TrackRef>()) );
00061         Trajectory FakeTraj;
00062         bool valid = pfTransformer_->addPoints( pftrack, **it, FakeTraj);
00063         if(valid) {
00064           pfRecTkcoll.push_back(reco::PFRecTrackRef( pfTrackRefProd, hid++ ));  
00065           pfNuclearRecTrackColl->push_back(pftrack);
00066         }
00067       }
00068       reco::NuclearInteractionRef niRef(nuclCollH, icoll);
00069       pfNuclearColl->push_back( reco::PFNuclearInteraction( niRef, pfRecTkcoll ));
00070     }
00071   }
00072   iEvent.put(pfNuclearRecTrackColl);
00073   iEvent.put(pfNuclearColl);
00074 }
00075 
00076 // ------------ method called once each job just before starting event loop  ------------
00077 void 
00078 PFNuclearProducer::beginRun(edm::Run& run,
00079                             const EventSetup& iSetup)
00080 {
00081   ESHandle<MagneticField> magneticField;
00082   iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00083   pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00084   pfTransformer_->OnlyProp();
00085 }
00086 
00087 // ------------ method called once each job just after ending the event loop  ------------
00088 void 
00089 PFNuclearProducer::endRun() {
00090   delete pfTransformer_;
00091 }