CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/JetMETCorrections/TauJet/plugins/TauJetCorrectorExample.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TauJetCorrectorExample
00004 // Class:      TauJetCorrectorExample
00005 // 
00015 // system include files
00016 #include <memory>
00017 
00018 // user include files
00019 #include "FWCore/Framework/interface/Frameworkfwd.h"
00020 #include "FWCore/Framework/interface/EDAnalyzer.h"
00021 
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024 
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 
00027 // necessary objects:
00028 #include "FWCore/Framework/interface/ESHandle.h"
00029 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00030 #include "DataFormats/JetReco/interface/CaloJet.h"
00035 
00036 #include "JetMETCorrections/TauJet/interface/TauJetCorrector.h"
00037 //#include "JetMETCorrections/TauJet/interface/JetCalibratorTauJet.h"
00038 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00039 #include "DataFormats/TrackReco/interface/Track.h"
00040 #include "DataFormats/BTauReco/interface/IsolatedTauTagInfo.h"
00041 #include "DataFormats/JetReco/interface/Jet.h"
00042 #include <DataFormats/Common/interface/RefVector.h>
00043 #include <DataFormats/Common/interface/RefVectorIterator.h>
00044 #include <DataFormats/Common/interface/Ref.h>
00045 // basic cpp:
00046 
00047 // basic cpp:
00048 #include <iostream>
00049 #include <string>
00050 // some root includes
00051 #include <TFile.h>
00052 #include <TH1D.h>
00053 #include <TMath.h>
00054 #include <TTree.h>
00055 #include <TLorentzVector.h>
00056 #include <TVector3.h>
00057 
00058 //
00059 // class decleration
00060 //
00061 class TauJetCorrectorExample : public edm::EDAnalyzer {
00062 public:
00063   explicit TauJetCorrectorExample(const edm::ParameterSet&);
00064   ~TauJetCorrectorExample();
00065   
00066   
00067 private:
00068   virtual void beginJob() ;
00069   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00070   virtual void endJob() ;
00071   
00072   // ----------member data ---------------------------
00073   std::string jetname;
00074   std::string tauname;
00075   std::string tauCorrectorname;
00076   
00077   int nEvt;// used to count the number of events
00078   int njets;
00079   
00080   JetCorrector* taucorrector; 
00081 
00082 };
00083 
00084 
00085 //
00086 // constants, enums and typedefs
00087 //
00088 
00089 //
00090 // static data member definitions
00091 //
00092 
00093 //
00094 // constructors and destructor
00095 //
00096 
00097 using namespace reco;
00098 
00099 TauJetCorrectorExample::TauJetCorrectorExample(const edm::ParameterSet& iConfig):
00100   jetname(iConfig.getUntrackedParameter<std::string>("JetHandle","iterativeCone5CaloJets")),
00101   tauname(iConfig.getUntrackedParameter<std::string>("TauHandle","coneIsolation")),
00102   tauCorrectorname(iConfig.getUntrackedParameter<std::string>("tauCorrHandle", "TauJetCorrectorIcone5")),
00103   nEvt(0), njets(0), taucorrector(0)
00104 {
00105   //now do what ever initialization is needed
00106 
00107 }
00108 
00109 
00110 TauJetCorrectorExample::~TauJetCorrectorExample()
00111 {
00112  
00113   // do anything here that needs to be done at desctruction time
00114   // (e.g. close files, deallocate resources etc.)
00115 
00116 }
00117 
00118 
00119 //
00120 // member functions
00121 //
00122 
00123 // ------------ method called to for each event  ------------
00124 void
00125 TauJetCorrectorExample::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00126 {
00127   taucorrector = const_cast<JetCorrector*>(JetCorrector::getJetCorrector(tauCorrectorname, iSetup));
00128 
00129   using namespace edm;
00130   
00131 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00132   Handle<ExampleData> pIn;
00133   iEvent.getByLabel("example",pIn);
00134 #endif
00135    
00136 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00137   ESHandle<SetupData> pSetup;
00138   iSetup.get<SetupRecord>().get(pSetup);
00139 #endif
00140   using namespace edm;
00141 
00142   // this analyzer produces a small root file with basic candidates and some MC information
00143   // some additional print statements
00144   ++nEvt;
00145   if((nEvt%10==0 && nEvt<=100)||(nEvt%100==0 && nEvt>100))
00146     std::cout << "reading event " << nEvt << std::endl;
00147 
00148   // get taus
00149   Handle<reco::IsolatedTauTagInfoCollection> tauTagInfoHandle;
00150   iEvent.getByLabel(tauname,tauTagInfoHandle);
00151   reco::IsolatedTauTagInfoCollection::const_iterator tau=tauTagInfoHandle->begin();
00152   
00153   //get tau jet corrector
00154   //const JetCorrector* taucorrector = JetCorrector::getJetCorrector(tauCorrectorname, iSetup);
00155 
00156   //  std::cout << "setting everything to 0 just before tau loop" << std::endl;
00157   njets=0;
00158 
00159     std::cout << "starting tau loop" << std::endl;
00160     for(tau=tauTagInfoHandle->begin();tau!=tauTagInfoHandle->end() && njets<10;++tau) {
00161 
00162         //Should check tau discriminator, but not done here
00163 
00164                 double pt = tau->jet().get()->et();
00165         
00166                 //correction returns correction factor which must then be applied to original ET
00167                 double scale = taucorrector->correction(tau->jet().get()->p4());
00168                 double ptcorr = tau->jet().get()->et() * scale;
00169        
00170                 std::cout << "Tau jet: Original Et = " << pt << " Corrected Et = " << ptcorr << std::endl;
00171 
00172                 ++njets;
00173         }
00174 
00175 
00176 }
00177 
00178 
00179 
00180 // ------------ method called once each job just before starting event loop  ------------
00181 void 
00182 //TauJetCorrectorExample::beginJob(const edm::EventSetup& iSetup)
00183 TauJetCorrectorExample::beginJob()
00184 {
00185         
00186 //      taucorrector = const_cast<JetCorrector*>(JetCorrector::getJetCorrector(tauCorrectorname, iSetup));
00187         
00188 }
00189 
00190 // ------------ method called once each job just after ending the event loop  ------------
00191 void 
00192 TauJetCorrectorExample::endJob() { 
00193 }
00194 
00195 //define this as a plug-in
00196 DEFINE_FWK_MODULE(TauJetCorrectorExample);