CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/HLTrigger/btau/src/ConeIsolation.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    ConeIsolation
00004 // Class:      ConeIsolation
00005 // 
00013 //
00014 // Original Author:  Simone Gennai
00015 //      Created:  Thu Apr  6 09:56:23 CEST 2006
00016 // $Id: ConeIsolation.cc,v 1.1 2008/12/19 12:53:03 gennai Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "HLTrigger/btau/src/ConeIsolation.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "DataFormats/BTauReco/interface/JetTag.h"
00034 #include "DataFormats/TrackReco/interface/Track.h"
00035 #include "DataFormats/BTauReco/interface/IsolatedTauTagInfo.h"
00036 
00037 #include <DataFormats/VertexReco/interface/Vertex.h>
00038 #include <DataFormats/VertexReco/interface/VertexFwd.h>
00039 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00040 
00041 #include "FWCore/Framework/interface/EventSetup.h"
00042 #include "FWCore/Framework/interface/ESHandle.h"
00043 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00044 
00045 using namespace reco;
00046 using namespace edm;
00047 using namespace std;
00048 
00049 //
00050 // constructors and destructor
00051 //
00052 ConeIsolation::ConeIsolation(const edm::ParameterSet& iConfig)
00053 {
00054   jetTrackSrc = iConfig.getParameter<InputTag>("JetTrackSrc");
00055   vertexSrc = iConfig.getParameter<InputTag>("vertexSrc");
00056   usingVertex = iConfig.getParameter<bool>("useVertex");
00057   usingBeamSpot = iConfig.getParameter<bool>("useBeamSpot"); //If false the OfflinePrimaryVertex will be used.
00058   beamSpotProducer = iConfig.getParameter<edm::InputTag>("BeamSpotProducer");
00059   m_algo = new ConeIsolationAlgorithm(iConfig);
00060   
00061   produces<reco::JetTagCollection>(); 
00062    produces<reco::IsolatedTauTagInfoCollection>();       
00063 
00064 
00065 
00066 }
00067 
00068 
00069 ConeIsolation::~ConeIsolation()
00070 {
00071   delete m_algo;
00072 }
00073 
00074 
00075 
00076 //
00077 // member functions
00078 //
00079 // ------------ method called to produce the data  ------------
00080 void
00081 ConeIsolation::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00082 {
00083    using namespace edm;
00084    //Get jets with tracks
00085    Handle<reco::JetTracksAssociationCollection> jetTracksAssociation;
00086    iEvent.getByLabel(jetTrackSrc,jetTracksAssociation);
00087 
00088    std::auto_ptr<reco::JetTagCollection>             tagCollection;
00089    std::auto_ptr<reco::IsolatedTauTagInfoCollection> extCollection( new reco::IsolatedTauTagInfoCollection() );
00090 if (not jetTracksAssociation->empty()) {
00091      RefToBaseProd<reco::Jet> prod( jetTracksAssociation->begin()->first );
00092      tagCollection.reset( new reco::JetTagCollection(prod) );
00093    } else {
00094      tagCollection.reset( new reco::JetTagCollection() );
00095    }
00096 
00097    Vertex::Error e;
00098    e(0,0)=1;
00099    e(1,1)=1;
00100    e(2,2)=1;
00101    Vertex::Point p(0,0,-1000);
00102    Vertex myPVtmp(p,e);//Fake vertex to be used in case no vertex is found
00103    Vertex myPV;
00104 
00105    //Get pixel vertices
00106    Handle<reco::VertexCollection> vertices;
00107    iEvent.getByLabel(vertexSrc,vertices);
00108    const reco::VertexCollection vertCollection = *(vertices.product());
00109    //Check if there is the PV!!!!
00110    if(vertCollection.begin() != vertCollection.end())
00111      myPVtmp = *(vertCollection.begin());
00112 
00113    //In case the beam spot is used, the Z of the vertex still comes from the PV, while the (x,y) is taken from the beamspot
00114    reco::BeamSpot vertexBeamSpot;
00115    edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00116    
00117    if(usingBeamSpot)
00118      {
00119        //Create a new vertex with the information on x0 and Y0 from the beamspot, to be used in HLT.
00120        iEvent.getByLabel(beamSpotProducer,recoBeamSpotHandle);
00121        vertexBeamSpot = *recoBeamSpotHandle;
00122        Vertex::Point bspoint(vertexBeamSpot.x0(),vertexBeamSpot.y0(),myPVtmp.z());
00123        Vertex combinedVertex = Vertex(bspoint,myPVtmp.error(),myPVtmp.chi2(),myPVtmp.ndof(),myPVtmp.tracksSize());
00124        myPV = combinedVertex;
00125          }else{
00126            myPV = myPVtmp;
00127          }
00128 
00129 
00130    
00131    JetTracksAssociationCollection::const_iterator it = jetTracksAssociation->begin();
00132    for (unsigned int i = 0; i < jetTracksAssociation->size(); ++i)
00133      {
00134        pair<float,IsolatedTauTagInfo> myPair =m_algo->tag(edm::Ref<JetTracksAssociationCollection>(jetTracksAssociation,i),myPV); 
00135        tagCollection->setValue(i, myPair.first);
00136        extCollection->push_back(myPair.second);
00137      }
00138 
00139    iEvent.put(extCollection);
00140    iEvent.put(tagCollection);
00141 
00142 
00143 
00144 }
00145 
00146 //define this as a plug-in
00147 //DEFINE_FWK_MODULE(ConeIsolation);
00148