CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoTauTag/RecoTau/plugins/PFRecoTauProducer.cc

Go to the documentation of this file.
00001 /* class PFRecoTauProducer
00002  * EDProducer of the PFTauCollection, starting from the PFTauTagInfoCollection, 
00003  * authors: Simone Gennai (simone.gennai@cern.ch), Ludovic Houchu (Ludovic.Houchu@cern.ch)
00004  */
00005 
00006 #include "DataFormats/TauReco/interface/PFTauTagInfo.h"
00007 #include "DataFormats/VertexReco/interface/Vertex.h"
00008 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00009 
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/Framework/interface/Frameworkfwd.h"
00015 #include "FWCore/Framework/interface/EDProducer.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 
00020 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00021 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00022 
00023 #include "RecoTauTag/RecoTau/interface/PFRecoTauAlgorithm.h"
00024 #include "RecoTauTag/RecoTau/interface/HPSPFRecoTauAlgorithm.h"
00025 
00026 #include "CLHEP/Random/RandGauss.h"
00027 
00028 #include <memory>
00029 
00030 using namespace reco;
00031 using namespace edm;
00032 using namespace std;
00033 
00034 class PFRecoTauProducer : public EDProducer {
00035  public:
00036   explicit PFRecoTauProducer(const edm::ParameterSet& iConfig);
00037   ~PFRecoTauProducer();
00038   virtual void produce(edm::Event&,const edm::EventSetup&);
00039  private:
00040   edm::InputTag PFTauTagInfoProducer_;
00041   edm::InputTag ElectronPreIDProducer_;
00042   edm::InputTag PVProducer_;
00043   std::string Algorithm_;
00044   double smearedPVsigmaX_;
00045   double smearedPVsigmaY_;
00046   double smearedPVsigmaZ_;
00047   double JetMinPt_;
00048   PFRecoTauAlgorithmBase* PFRecoTauAlgo_;
00049 
00050 };
00051 
00052 PFRecoTauProducer::PFRecoTauProducer(const edm::ParameterSet& iConfig){
00053   PFTauTagInfoProducer_   = iConfig.getParameter<edm::InputTag>("PFTauTagInfoProducer");
00054   ElectronPreIDProducer_  = iConfig.getParameter<edm::InputTag>("ElectronPreIDProducer");
00055   PVProducer_             = iConfig.getParameter<edm::InputTag>("PVProducer");
00056   Algorithm_              = iConfig.getParameter<std::string>("Algorithm");
00057   smearedPVsigmaX_        = iConfig.getParameter<double>("smearedPVsigmaX");
00058   smearedPVsigmaY_        = iConfig.getParameter<double>("smearedPVsigmaY");
00059   smearedPVsigmaZ_        = iConfig.getParameter<double>("smearedPVsigmaZ");    
00060   JetMinPt_               = iConfig.getParameter<double>("JetPtMin");
00061 
00062   if(Algorithm_ =="ConeBased") {
00063     PFRecoTauAlgo_=new PFRecoTauAlgorithm(iConfig);
00064   }
00065   else if(Algorithm_ =="HPS") {
00066     PFRecoTauAlgo_=new HPSPFRecoTauAlgorithm(iConfig);
00067   }
00068   else {    //Add inside out Algorithm here
00069 
00070     //If no Algorithm found throw exception
00071     throw cms::Exception("") << "Unknown Algorithkm" << std::endl;
00072   }
00073     
00074 
00075   produces<PFTauCollection>();      
00076 }
00077 PFRecoTauProducer::~PFRecoTauProducer(){
00078   delete PFRecoTauAlgo_;
00079 }
00080 
00081 void PFRecoTauProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){
00082   auto_ptr<PFTauCollection> resultPFTau(new PFTauCollection);
00083   
00084   edm::ESHandle<TransientTrackBuilder> myTransientTrackBuilder;
00085   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",myTransientTrackBuilder);
00086   PFRecoTauAlgo_->setTransientTrackBuilder(myTransientTrackBuilder.product());
00087 
00088   //edm::ESHandle<MagneticField> myMF;
00089   //iSetup.get<IdealMagneticFieldRecord>().get(myMF);
00090   //PFRecoTauAlgo_->setMagneticField(myMF.product());
00091 
00092   // Electron PreID tracks: Temporary until integrated to PFCandidate
00093   /*
00094   edm::Handle<PFRecTrackCollection> myPFelecTk; 
00095   iEvent.getByLabel(ElectronPreIDProducer_,myPFelecTk); 
00096   const PFRecTrackCollection theElecTkCollection=*(myPFelecTk.product()); 
00097   */
00098   // query a rec/sim PV
00099   edm::Handle<VertexCollection> thePVs;
00100   iEvent.getByLabel(PVProducer_,thePVs);
00101   const VertexCollection vertCollection=*(thePVs.product());
00102   Vertex thePV;
00103   if(vertCollection.size()) thePV=*(vertCollection.begin());
00104   else{
00105     Vertex::Error SimPVError;
00106     SimPVError(0,0)=smearedPVsigmaX_*smearedPVsigmaX_;
00107     SimPVError(1,1)=smearedPVsigmaY_*smearedPVsigmaY_;
00108     SimPVError(2,2)=smearedPVsigmaZ_*smearedPVsigmaZ_;
00109     Vertex::Point SimPVPoint(CLHEP::RandGauss::shoot(0.,smearedPVsigmaX_),  
00110                              CLHEP::RandGauss::shoot(0.,smearedPVsigmaY_),  
00111                              CLHEP::RandGauss::shoot(0.,smearedPVsigmaZ_));
00112     thePV=Vertex(SimPVPoint,SimPVError,1,1,1);    
00113   }
00114   
00115   edm::Handle<PFTauTagInfoCollection> thePFTauTagInfoCollection;
00116   iEvent.getByLabel(PFTauTagInfoProducer_,thePFTauTagInfoCollection);
00117   int iinfo=0;
00118   for(PFTauTagInfoCollection::const_iterator i_info=thePFTauTagInfoCollection->begin();i_info!=thePFTauTagInfoCollection->end();i_info++) { 
00119     if((*i_info).pfjetRef()->pt()>JetMinPt_){
00120       //        PFTau myPFTau=PFRecoTauAlgo_->buildPFTau(Ref<PFTauTagInfoCollection>(thePFTauTagInfoCollection,iinfo),thePV,theElecTkCollection);
00121         PFTau myPFTau=PFRecoTauAlgo_->buildPFTau(Ref<PFTauTagInfoCollection>(thePFTauTagInfoCollection,iinfo),thePV);
00122        resultPFTau->push_back(myPFTau);
00123     }
00124     ++iinfo;
00125   }
00126   iEvent.put(resultPFTau);
00127 }
00128 
00129 DEFINE_FWK_MODULE(PFRecoTauProducer);