CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoTauTag/RecoTau/plugins/CaloRecoTauProducer.cc

Go to the documentation of this file.
00001 /* class CaloRecoTauProducer
00002  * EDProducer of the CaloTauCollection, starting from the CaloTauTagInfoCollection, 
00003  * authors: Simone Gennai (simone.gennai@cern.ch), Ludovic Houchu (Ludovic.Houchu@cern.ch)
00004  */
00005 
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/Framework/interface/EDProducer.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DataFormats/TauReco/interface/CaloTauTagInfo.h"
00016 #include "DataFormats/VertexReco/interface/Vertex.h"
00017 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00018 
00019 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00020 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00021 
00022 #include "RecoTauTag/RecoTau/interface/CaloRecoTauAlgorithm.h"
00023 
00024 #include "DataFormats/DetId/interface/DetIdCollection.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 CaloRecoTauProducer : public EDProducer {
00035  public:
00036   explicit CaloRecoTauProducer(const edm::ParameterSet& iConfig);
00037   ~CaloRecoTauProducer();
00038   virtual void produce(edm::Event&,const edm::EventSetup&);
00039  private:
00040   edm::InputTag CaloRecoTauTagInfoProducer_;
00041   edm::InputTag PVProducer_;
00042   double smearedPVsigmaX_;
00043   double smearedPVsigmaY_;
00044   double smearedPVsigmaZ_;
00045   double JetMinPt_;
00046   CaloRecoTauAlgorithm* CaloRecoTauAlgo_;
00047 };
00048 
00049 CaloRecoTauProducer::CaloRecoTauProducer(const edm::ParameterSet& iConfig){
00050   CaloRecoTauTagInfoProducer_  = iConfig.getParameter<edm::InputTag>("CaloRecoTauTagInfoProducer");
00051   PVProducer_                  = iConfig.getParameter<edm::InputTag>("PVProducer");
00052   smearedPVsigmaX_             = iConfig.getParameter<double>("smearedPVsigmaX");
00053   smearedPVsigmaY_             = iConfig.getParameter<double>("smearedPVsigmaY");
00054   smearedPVsigmaZ_             = iConfig.getParameter<double>("smearedPVsigmaZ");       
00055   JetMinPt_                    = iConfig.getParameter<double>("JetPtMin");
00056   CaloRecoTauAlgo_=new CaloRecoTauAlgorithm(iConfig);
00057   produces<CaloTauCollection>();
00058   produces<DetIdCollection>();
00059 }
00060 CaloRecoTauProducer::~CaloRecoTauProducer(){
00061   delete CaloRecoTauAlgo_;
00062 }
00063   
00064 void CaloRecoTauProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetup){
00065 
00066   auto_ptr<CaloTauCollection> resultCaloTau(new CaloTauCollection);
00067   auto_ptr<DetIdCollection> selectedDetIds(new DetIdCollection);
00068  
00069   edm::ESHandle<TransientTrackBuilder> myTransientTrackBuilder;
00070   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",myTransientTrackBuilder);
00071   CaloRecoTauAlgo_->setTransientTrackBuilder(myTransientTrackBuilder.product());
00072   
00073   edm::ESHandle<MagneticField> myMF;
00074   iSetup.get<IdealMagneticFieldRecord>().get(myMF);
00075   CaloRecoTauAlgo_->setMagneticField(myMF.product());
00076     
00077   // query a rec/sim PV
00078   edm::Handle<VertexCollection> thePVs;
00079   iEvent.getByLabel(PVProducer_,thePVs);
00080   const VertexCollection vertCollection=*(thePVs.product());
00081   Vertex thePV;
00082   if(vertCollection.size()) thePV=*(vertCollection.begin());
00083   else{
00084     Vertex::Error SimPVError;
00085     SimPVError(0,0)=smearedPVsigmaX_*smearedPVsigmaX_;
00086     SimPVError(1,1)=smearedPVsigmaY_*smearedPVsigmaY_;
00087     SimPVError(2,2)=smearedPVsigmaZ_*smearedPVsigmaZ_;
00088     Vertex::Point SimPVPoint(CLHEP::RandGauss::shoot(0.,smearedPVsigmaX_),  
00089                              CLHEP::RandGauss::shoot(0.,smearedPVsigmaY_),  
00090                              CLHEP::RandGauss::shoot(0.,smearedPVsigmaZ_));
00091     thePV=Vertex(SimPVPoint,SimPVError,1,1,1);    
00092   }
00093   
00094   edm::Handle<CaloTauTagInfoCollection> theCaloTauTagInfoCollection;
00095   iEvent.getByLabel(CaloRecoTauTagInfoProducer_,theCaloTauTagInfoCollection);
00096   int iinfo=0;
00097   for(CaloTauTagInfoCollection::const_iterator i_info=theCaloTauTagInfoCollection->begin();i_info!=theCaloTauTagInfoCollection->end();i_info++) { 
00098     if(i_info->jetRef()->pt()>JetMinPt_){ 
00099       CaloTau myCaloTau=CaloRecoTauAlgo_->buildCaloTau(iEvent,iSetup,Ref<CaloTauTagInfoCollection>(theCaloTauTagInfoCollection,iinfo),thePV);
00100       resultCaloTau->push_back(myCaloTau);
00101     }
00102     ++iinfo;
00103   }
00104   for(unsigned int i =0;i<CaloRecoTauAlgo_->mySelectedDetId_.size();i++)
00105     selectedDetIds->push_back(CaloRecoTauAlgo_->mySelectedDetId_[i]);
00106 
00107 
00108    iEvent.put(resultCaloTau);
00109   iEvent.put(selectedDetIds);
00110 }
00111 DEFINE_FWK_MODULE(CaloRecoTauProducer);