CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1JetRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TNtuples
4 // Class: L1JetRecoTreeProducer
5 //
14 // system include files
15 #include <memory>
16 
17 // framework
26 
27 // cond formats
31 
32 // data formats
38 
39 
40 // ROOT output stuff
43 #include "TH1.h"
44 #include "TTree.h"
45 #include "TF1.h"
46 #include <TVector2.h>
47 
48 //local data formats
51 
52 //
53 // class declaration
54 //
55 
57 public:
60 
61 
62 private:
63  virtual void beginJob(void) ;
64  virtual void analyze(const edm::Event&, const edm::EventSetup&);
65  virtual void endJob();
66 
70 
72 
73 public:
76 
77 private:
78 
79  // output file
81 
82  // tree
83  TTree * tree_;
84 
85  // EDM input tags
87  // edm::EDGetTokenT<reco::CaloJetCollection> caloJetToken_;
88  // edm::EDGetTokenT<edm::ValueMap<reco::JetID> > caloJetIdToken_;
90 
92 
93 
94  // debug stuff
97  unsigned int maxCl_;
98  unsigned int maxJet_;
99  unsigned int maxVtx_;
100  unsigned int maxTrk_;
101 
104 
105 };
106 
107 
108 
110  pfJetsMissing_(false),
111  pfMetMissing_(false),
112  pfJetCorrMissing_(false)
113 {
114 
115  // caloJetToken_ = consumes<reco::CaloJetCollection>(iConfig.getUntrackedParameter("caloJetToken",edm::InputTag("ak4CaloJets")));
116  pfJetToken_ = consumes<reco::PFJetCollection>(iConfig.getUntrackedParameter("pfJetToken",edm::InputTag("ak4PFJetsCHS")));
117  // caloJetIdToken_ = consumes<edm::ValueMap<reco::JetID> >(iConfig.getUntrackedParameter("jetIdToken",edm::InputTag("ak4JetID")));
118  jecToken_ = consumes<reco::JetCorrector>(iConfig.getUntrackedParameter<edm::InputTag>("jecToken",edm::InputTag("ak4PFCHSL1FastL2L3ResidualCorrector")));
119 
120  pfMetToken_ = consumes<reco::PFMETCollection>(iConfig.getUntrackedParameter("pfMetToken",edm::InputTag("pfMet")));
121 
122  jetptThreshold_ = iConfig.getParameter<double> ("jetptThreshold");
123  maxJet_ = iConfig.getParameter<unsigned int>("maxJet");
124 
127 
128  // set up output
129  tree_=fs_->make<TTree>("JetRecoTree", "JetRecoTree");
130  tree_->Branch("Jet", "L1Analysis::L1AnalysisRecoJetDataFormat", &jet_data, 32000, 3);
131  tree_->Branch("Sums", "L1Analysis::L1AnalysisRecoMetDataFormat", &met_data, 32000, 3);
132 
133 }
134 
135 
137 {
138 
139  // do anything here that needs to be done at desctruction time
140  // (e.g. close files, deallocate resources etc.)
141 
142 }
143 
144 
145 //
146 // member functions
147 //
148 
149 // ------------ method called to for each event ------------
151 {
152 
153  jet_data->Reset();
154  met_data->Reset();
155 
156  // get jets
158  iEvent.getByToken(pfJetToken_, pfJets);
159 
160  //get sums
162  iEvent.getByToken(pfMetToken_, pfMet);
163 
164  // get jet ID
165  // edm::Handle<edm::ValueMap<reco::JetID> > jetsID;
166  //iEvent.getByLabel(jetIdTag_,jetsID);
167 
169  iEvent.getByToken(jecToken_, pfJetCorr);
170 
171 
172  if (pfJets.isValid()) {
173 
174  jet_data->nJets=0;
175 
176  doPFJets(pfJets);
177 
178  }
179  else {
180  if (!pfJetsMissing_) {edm::LogWarning("MissingProduct") << "PFJets not found. Branch will not be filled" << std::endl;}
181  pfJetsMissing_ = true;
182  }
183 
184  if (pfJetCorr.isValid()) {
185 
186  doPFJetCorr(pfJets,pfJetCorr);
187 
188  }
189  else {
190  if (!pfJetCorrMissing_) {edm::LogWarning("MissingProduct") << "Jet Corrector not found. Branch will not be filled" << std::endl;}
191  pfJetCorrMissing_ = true;
192  }
193 
194  if (pfMet.isValid()) {
195 
196  doPFMet(pfMet);
197 
198  }
199  else {
200  if (!pfMetMissing_) {edm::LogWarning("MissingProduct") << "PFMet not found. Branch will not be filled" << std::endl;}
201  pfMetMissing_ = true;
202  }
203 
204 
205  tree_->Fill();
206 
207 }
208 
209 
210 void
212 
213 
214  for( auto it=caloJets->begin();
215  it!=caloJets->end() && jet_data->nJets < maxJet_;
216  ++it) {
217 
218  jet_data->et.push_back(it->et());
219  jet_data->eta.push_back(it->eta());
220  jet_data->phi.push_back(it->phi());
221  jet_data->e.push_back(it->energy());
222  jet_data->isPF.push_back(false);
223 
224  jet_data->eEMF.push_back(it->emEnergyFraction());
225  jet_data->eEmEB.push_back(it->emEnergyInEB());
226  jet_data->eEmEE.push_back(it->emEnergyInEE());
227  jet_data->eEmHF.push_back(it->emEnergyInHF());
228  jet_data->eHadHB.push_back(it->hadEnergyInHB());
229  jet_data->eHadHE.push_back(it->hadEnergyInHE());
230  jet_data->eHadHO.push_back(it->hadEnergyInHO());
231  jet_data->eHadHF.push_back(it->hadEnergyInHF());
232  jet_data->eMaxEcalTow.push_back(it->maxEInEmTowers());
233  jet_data->eMaxHcalTow.push_back(it->maxEInHadTowers());
234  jet_data->towerArea.push_back(it->towersArea());
235 
236  jet_data->nJets++;
237 
238  }
239 
240 
241 }
242 
243 
244 void
246 
247  float mHx = 0;
248  float mHy = 0;
249 
250  met_data->Ht = 0;
251  met_data->mHt = -999.;
252  met_data->mHtPhi = -999.;
253 
254  for( auto it=pfJets->begin();
255  it!=pfJets->end() && jet_data->nJets < maxJet_;
256  ++it) {
257  jet_data->et.push_back(it->et());
258  jet_data->eta.push_back(it->eta());
259  jet_data->phi.push_back(it->phi());
260  jet_data->e.push_back(it->energy());
261  jet_data->isPF.push_back(true);
262 
263  jet_data->chef.push_back(it->chargedHadronEnergyFraction());
264  jet_data->nhef.push_back(it->neutralHadronEnergyFraction());
265  jet_data->pef.push_back(it->photonEnergyFraction());
266  jet_data->eef.push_back(it->electronEnergyFraction());
267  jet_data->mef.push_back(it->muonEnergyFraction());
268  jet_data->hfhef.push_back(it->HFHadronEnergyFraction());
269  jet_data->hfemef.push_back(it->HFEMEnergyFraction());
270  jet_data->chMult.push_back(it->chargedHadronMultiplicity());
271  jet_data->nhMult.push_back(it->neutralHadronMultiplicity());
272  jet_data->phMult.push_back(it->photonMultiplicity());
273  jet_data->elMult.push_back(it->electronMultiplicity());
274  jet_data->muMult.push_back(it->muonMultiplicity());
275  jet_data->hfhMult.push_back(it->HFHadronMultiplicity());
276  jet_data->hfemMult.push_back(it->HFEMMultiplicity());
277 
278  jet_data->cemef.push_back(it->chargedEmEnergyFraction());
279  jet_data->cmef.push_back(it->chargedMuEnergyFraction());
280  jet_data->nemef.push_back(it->neutralEmEnergyFraction());
281  jet_data->cMult.push_back(it->chargedMultiplicity());
282  jet_data->nMult.push_back(it->neutralMultiplicity());
283 
284  jet_data->nJets++;
285 
286 
287  if (it->pt()>jetptThreshold_){
288  mHx += -1.*it->px();
289  mHy += -1.*it->py();
290  met_data->Ht += it->pt();
291  }
292  }
293 
294  TVector2 *tv2 = new TVector2(mHx,mHy);
295  met_data->mHt = tv2->Mod();
296  met_data->mHtPhi = tv2->Phi();
297 
298 }
299 
300 
301 void
303 
304 
305  std::vector< std::pair<float,float> > corrJetEtsAndCorrs;
306 
307  //get jet correction and fill corrected jet ets and corrections
308  for( auto it=pfJets->begin(); it!=pfJets->end(); ++it)
309  {
310  float corr = pfJetCorr.product()->correction(*it);
311  std::pair<float,float> corrJetEtAndCorr(corr*it->et(),corr);
312  corrJetEtsAndCorrs.push_back(corrJetEtAndCorr);
313  }
314 
315  // sort corrected jet ets and correction factors
316  // by corrected jet et
317  std::sort(corrJetEtsAndCorrs.rbegin(),corrJetEtsAndCorrs.rend());
318 
319  //fill jet data array with sorted jet ets and corr factors
320  std::vector<std::pair<float,float> >::iterator it;
321  uint nJets = 0;
322 
323  for(it = corrJetEtsAndCorrs.begin(); it != corrJetEtsAndCorrs.end() && nJets < maxJet_; ++it){
324  jet_data->etCorr.push_back(it->first);
325  jet_data->corrFactor.push_back(it->second);
326  nJets++;
327  }
328 }
329 
330 void
332 
333  const reco::PFMETCollection *metCol = pfMet.product();
334  const reco::PFMET theMet = metCol->front();
335 
336  met_data->met = theMet.et();
337  met_data->metPhi = theMet.phi();
338  met_data->sumEt = theMet.sumEt();
339 
340 }
341 
342 
343 
344 // ------------ method called once each job just before starting event loop ------------
345 void
347 {
348 }
349 
350 // ------------ method called once each job just after ending the event loop ------------
351 void
353 }
354 
355 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void doPFMet(edm::Handle< reco::PFMETCollection > pfMet)
L1Analysis::L1AnalysisRecoMetDataFormat * met_data
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::Service< TFileService > fs_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void doPFJetCorr(edm::Handle< reco::PFJetCollection > pfJets, edm::Handle< reco::JetCorrector > pfJetCorr)
virtual double phi() const final
momentum azimuthal angle
void doPFJets(edm::Handle< reco::PFJetCollection > pfJets)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisRecoJetDataFormat * jet_data
int iEvent
Definition: GenABIO.cc:230
double sumEt() const
Definition: MET.h:56
edm::EDGetTokenT< reco::JetCorrector > jecToken_
tuple pfMet
____________________________________________________________________________||
Definition: PFMET_cfi.py:4
edm::EDGetTokenT< reco::PFJetCollection > pfJetToken_
bool isValid() const
Definition: HandleBase.h:75
virtual void analyze(const edm::Event &, const edm::EventSetup &)
JetCorrectorParameters corr
Definition: classes.h:5
edm::EDGetTokenT< reco::PFMETCollection > pfMetToken_
T const * product() const
Definition: Handle.h:81
L1JetRecoTreeProducer(const edm::ParameterSet &)
void doCaloJets(edm::Handle< reco::CaloJetCollection > caloJets)
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
virtual double et() const final
transverse energy
volatile std::atomic< bool > shutdown_flag false
tuple pfJets
Definition: pfJets_cff.py:8