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() override ;
69  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
70  virtual void endJob() override ;
71 
72  // ----------member data ---------------------------
73 #ifdef THIS_IS_AN_EVENT_EXAMPLE
74  edm::EDGetTokenT<ExampleData> exampletoken;
75 #endif
79 
80  int nEvt;// used to count the number of events
81  int njets;
82 
83 };
84 
85 
86 //
87 // constants, enums and typedefs
88 //
89 
90 //
91 // static data member definitions
92 //
93 
94 //
95 // constructors and destructor
96 //
97 
98 using namespace reco;
99 
101 #ifdef THIS_IS_AN_EVENT_EXAMPLE
102  exampletoken(consumes<ExampleData>(edm::InputTag("example"))),
103 #endif
104  jetname(iConfig.getUntrackedParameter<std::string>("JetHandle","iterativeCone5CaloJets")),
105  tautoken(consumes<reco::IsolatedTauTagInfoCollection>(edm::InputTag(iConfig.getUntrackedParameter<std::string>("TauHandle","coneIsolation")))),
106  tauCorrectortoken(consumes<reco::JetCorrector>(iConfig.getUntrackedParameter<std::string>("tauCorrHandle", "TauJetCorrectorIcone5"))),
107  nEvt(0), njets(0)
108 {
109  //now do what ever initialization is needed
110 
111 }
112 
113 
115 {
116 
117  // do anything here that needs to be done at desctruction time
118  // (e.g. close files, deallocate resources etc.)
119 
120 }
121 
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called to for each event ------------
128 void
130 {
131  using namespace edm;
132 
133  Handle<reco::JetCorrector> taucorrector;
134  iEvent.getByToken(tauCorrectortoken, taucorrector);
135 
136 #ifdef THIS_IS_AN_EVENT_EXAMPLE
138  iEvent.getByToken(exampletoken,pIn);
139 #endif
140 
141 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
142  ESHandle<SetupData> pSetup;
143  iSetup.get<SetupRecord>().get(pSetup);
144 #endif
145 
146  // this analyzer produces a small root file with basic candidates and some MC information
147  // some additional print statements
148  ++nEvt;
149  if((nEvt%10==0 && nEvt<=100)||(nEvt%100==0 && nEvt>100))
150  std::cout << "reading event " << nEvt << std::endl;
151 
152  // get taus
154  iEvent.getByToken(tautoken,tauTagInfoHandle);
155  reco::IsolatedTauTagInfoCollection::const_iterator tau=tauTagInfoHandle->begin();
156 
157  // std::cout << "setting everything to 0 just before tau loop" << std::endl;
158  njets=0;
159 
160  std::cout << "starting tau loop" << std::endl;
161  for(tau=tauTagInfoHandle->begin();tau!=tauTagInfoHandle->end() && njets<10;++tau) {
162 
163  //Should check tau discriminator, but not done here
164 
165  double pt = tau->jet().get()->et();
166 
167  //correction returns correction factor which must then be applied to original ET
168  double scale = taucorrector->correction(tau->jet().get()->p4());
169  double ptcorr = tau->jet().get()->et() * scale;
170 
171  std::cout << "Tau jet: Original Et = " << pt << " Corrected Et = " << ptcorr << std::endl;
172 
173  ++njets;
174  }
175 
176 
177 }
178 
179 
180 
181 // ------------ method called once each job just before starting event loop ------------
182 void
183 //TauJetCorrectorExample::beginJob(const edm::EventSetup& iSetup)
185 {
186 }
187 
188 // ------------ method called once each job just after ending the event loop ------------
189 void
191 }
192 
193 //define this as a plug-in
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::JetCorrector > tauCorrectortoken
virtual void endJob() override
int iEvent
Definition: GenABIO.cc:230
std::vector< IsolatedTauTagInfo > IsolatedTauTagInfoCollection
edm::EDGetTokenT< reco::IsolatedTauTagInfoCollection > tautoken
const T & get() const
Definition: EventSetup.h:56
TauJetCorrectorExample(const edm::ParameterSet &)
virtual void beginJob() override
tuple cout
Definition: gather_cfg.py:121