CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauJetCorrectorExample.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TauJetCorrectorExample
4 // Class: TauJetCorrectorExample
5 //
15 // system include files
16 #include <memory>
17 
18 // user include files
21 
24 
26 
27 // necessary objects:
35 
37 //#include "JetMETCorrections/TauJet/interface/JetCalibratorTauJet.h"
45 // basic cpp:
46 
47 // basic cpp:
48 #include <iostream>
49 #include <string>
50 // some root includes
51 #include <TFile.h>
52 #include <TH1D.h>
53 #include <TMath.h>
54 #include <TTree.h>
55 #include <TLorentzVector.h>
56 #include <TVector3.h>
57 
58 //
59 // class decleration
60 //
62 public:
65 
66 
67 private:
68  virtual void beginJob() ;
69  virtual void analyze(const edm::Event&, const edm::EventSetup&);
70  virtual void endJob() ;
71 
72  // ----------member data ---------------------------
73  std::string jetname;
74  std::string tauname;
75  std::string tauCorrectorname;
76 
77  int nEvt;// used to count the number of events
78  int njets;
79 
81 
82 };
83 
84 
85 //
86 // constants, enums and typedefs
87 //
88 
89 //
90 // static data member definitions
91 //
92 
93 //
94 // constructors and destructor
95 //
96 
97 using namespace reco;
98 
100  jetname(iConfig.getUntrackedParameter<std::string>("JetHandle","iterativeCone5CaloJets")),
101  tauname(iConfig.getUntrackedParameter<std::string>("TauHandle","coneIsolation")),
102  tauCorrectorname(iConfig.getUntrackedParameter<std::string>("tauCorrHandle", "TauJetCorrectorIcone5")),
103  nEvt(0), njets(0), taucorrector(0)
104 {
105  //now do what ever initialization is needed
106 
107 }
108 
109 
111 {
112 
113  // do anything here that needs to be done at desctruction time
114  // (e.g. close files, deallocate resources etc.)
115 
116 }
117 
118 
119 //
120 // member functions
121 //
122 
123 // ------------ method called to for each event ------------
124 void
126 {
128 
129  using namespace edm;
130 
131 #ifdef THIS_IS_AN_EVENT_EXAMPLE
133  iEvent.getByLabel("example",pIn);
134 #endif
135 
136 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
137  ESHandle<SetupData> pSetup;
138  iSetup.get<SetupRecord>().get(pSetup);
139 #endif
140  using namespace edm;
141 
142  // this analyzer produces a small root file with basic candidates and some MC information
143  // some additional print statements
144  ++nEvt;
145  if((nEvt%10==0 && nEvt<=100)||(nEvt%100==0 && nEvt>100))
146  std::cout << "reading event " << nEvt << std::endl;
147 
148  // get taus
150  iEvent.getByLabel(tauname,tauTagInfoHandle);
151  reco::IsolatedTauTagInfoCollection::const_iterator tau=tauTagInfoHandle->begin();
152 
153  //get tau jet corrector
154  //const JetCorrector* taucorrector = JetCorrector::getJetCorrector(tauCorrectorname, iSetup);
155 
156  // std::cout << "setting everything to 0 just before tau loop" << std::endl;
157  njets=0;
158 
159  std::cout << "starting tau loop" << std::endl;
160  for(tau=tauTagInfoHandle->begin();tau!=tauTagInfoHandle->end() && njets<10;++tau) {
161 
162  //Should check tau discriminator, but not done here
163 
164  double pt = tau->jet().get()->et();
165 
166  //correction returns correction factor which must then be applied to original ET
167  double scale = taucorrector->correction(tau->jet().get()->p4());
168  double ptcorr = tau->jet().get()->et() * scale;
169 
170  std::cout << "Tau jet: Original Et = " << pt << " Corrected Et = " << ptcorr << std::endl;
171 
172  ++njets;
173  }
174 
175 
176 }
177 
178 
179 
180 // ------------ method called once each job just before starting event loop ------------
181 void
182 //TauJetCorrectorExample::beginJob(const edm::EventSetup& iSetup)
184 {
185 
186 // taucorrector = const_cast<JetCorrector*>(JetCorrector::getJetCorrector(tauCorrectorname, iSetup));
187 
188 }
189 
190 // ------------ method called once each job just after ending the event loop ------------
191 void
193 }
194 
195 //define this as a plug-in
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:243
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const T & get() const
Definition: EventSetup.h:55
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:51
TauJetCorrectorExample(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121