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  bool jetId(const reco::PFJet& jet);
74 
75 public:
78 
79 private:
80 
81  // output file
83 
84  // tree
85  TTree * tree_;
86 
87  // EDM input tags
89  // edm::EDGetTokenT<reco::CaloJetCollection> caloJetToken_;
90  // edm::EDGetTokenT<edm::ValueMap<reco::JetID> > caloJetIdToken_;
92 
94 
95 
96  // debug stuff
99  double jetetaMax_;
100  unsigned int maxCl_;
101  unsigned int maxJet_;
102  unsigned int maxVtx_;
103  unsigned int maxTrk_;
104 
107 
108 };
109 
110 
111 
113  pfJetsMissing_(false),
114  pfMetMissing_(false),
115  pfJetCorrMissing_(false)
116 {
117 
118  // caloJetToken_ = consumes<reco::CaloJetCollection>(iConfig.getUntrackedParameter("caloJetToken",edm::InputTag("ak4CaloJets")));
119  pfJetToken_ = consumes<reco::PFJetCollection>(iConfig.getUntrackedParameter("pfJetToken",edm::InputTag("ak4PFJetsCHS")));
120  // caloJetIdToken_ = consumes<edm::ValueMap<reco::JetID> >(iConfig.getUntrackedParameter("jetIdToken",edm::InputTag("ak4JetID")));
121  jecToken_ = consumes<reco::JetCorrector>(iConfig.getUntrackedParameter<edm::InputTag>("jecToken",edm::InputTag("ak4PFCHSL1FastL2L3ResidualCorrector")));
122 
123  pfMetToken_ = consumes<reco::PFMETCollection>(iConfig.getUntrackedParameter("pfMetToken",edm::InputTag("pfMet")));
124 
125  jetptThreshold_ = iConfig.getParameter<double> ("jetptThreshold");
126  jetetaMax_ = iConfig.getParameter<double> ("jetetaMax");
127  maxJet_ = iConfig.getParameter<unsigned int>("maxJet");
128 
131 
132  // set up output
133  tree_=fs_->make<TTree>("JetRecoTree", "JetRecoTree");
134  tree_->Branch("Jet", "L1Analysis::L1AnalysisRecoJetDataFormat", &jet_data, 32000, 3);
135  tree_->Branch("Sums", "L1Analysis::L1AnalysisRecoMetDataFormat", &met_data, 32000, 3);
136 
137 }
138 
139 
141 {
142 
143  // do anything here that needs to be done at desctruction time
144  // (e.g. close files, deallocate resources etc.)
145 
146 }
147 
148 
149 //
150 // member functions
151 //
152 
153 // ------------ method called to for each event ------------
155 {
156 
157  jet_data->Reset();
158  met_data->Reset();
159 
160  // get jets
162  iEvent.getByToken(pfJetToken_, pfJets);
163 
164  //get sums
166  iEvent.getByToken(pfMetToken_, pfMet);
167 
168  // get jet ID
169  // edm::Handle<edm::ValueMap<reco::JetID> > jetsID;
170  //iEvent.getByLabel(jetIdTag_,jetsID);
171 
173  iEvent.getByToken(jecToken_, pfJetCorr);
174 
175 
176  if (pfJets.isValid()) {
177 
178  jet_data->nJets=0;
179 
180  doPFJets(pfJets);
181 
182  }
183  else {
184  if (!pfJetsMissing_) {edm::LogWarning("MissingProduct") << "PFJets not found. Branch will not be filled" << std::endl;}
185  pfJetsMissing_ = true;
186  }
187 
188  if (pfJetCorr.isValid()) {
189 
190  doPFJetCorr(pfJets,pfJetCorr);
191 
192  }
193  else {
194  if (!pfJetCorrMissing_) {edm::LogWarning("MissingProduct") << "Jet Corrector not found. Branch will not be filled" << std::endl;}
195  pfJetCorrMissing_ = true;
196  }
197 
198  if (pfMet.isValid()) {
199 
200  doPFMet(pfMet);
201 
202  }
203  else {
204  if (!pfMetMissing_) {edm::LogWarning("MissingProduct") << "PFMet not found. Branch will not be filled" << std::endl;}
205  pfMetMissing_ = true;
206  }
207 
208 
209  tree_->Fill();
210 
211 }
212 
213 
214 void
216 
217 
218  for( auto it=caloJets->begin();
219  it!=caloJets->end() && jet_data->nJets < maxJet_;
220  ++it) {
221 
222  jet_data->et.push_back(it->et());
223  jet_data->eta.push_back(it->eta());
224  jet_data->phi.push_back(it->phi());
225  jet_data->e.push_back(it->energy());
226  jet_data->isPF.push_back(false);
227 
228  jet_data->eEMF.push_back(it->emEnergyFraction());
229  jet_data->eEmEB.push_back(it->emEnergyInEB());
230  jet_data->eEmEE.push_back(it->emEnergyInEE());
231  jet_data->eEmHF.push_back(it->emEnergyInHF());
232  jet_data->eHadHB.push_back(it->hadEnergyInHB());
233  jet_data->eHadHE.push_back(it->hadEnergyInHE());
234  jet_data->eHadHO.push_back(it->hadEnergyInHO());
235  jet_data->eHadHF.push_back(it->hadEnergyInHF());
236  jet_data->eMaxEcalTow.push_back(it->maxEInEmTowers());
237  jet_data->eMaxHcalTow.push_back(it->maxEInHadTowers());
238  jet_data->towerArea.push_back(it->towersArea());
239 
240  jet_data->nJets++;
241 
242  }
243 
244 
245 }
246 
247 
248 void
250 
251 
252  for( auto it=pfJets->begin();
253  it!=pfJets->end() && jet_data->nJets < maxJet_;
254  ++it) {
255  jet_data->et.push_back(it->et());
256  jet_data->eta.push_back(it->eta());
257  jet_data->phi.push_back(it->phi());
258  jet_data->e.push_back(it->energy());
259  jet_data->isPF.push_back(true);
260 
261  jet_data->chef.push_back(it->chargedHadronEnergyFraction());
262  jet_data->nhef.push_back(it->neutralHadronEnergyFraction());
263  jet_data->pef.push_back(it->photonEnergyFraction());
264  jet_data->eef.push_back(it->electronEnergyFraction());
265  jet_data->mef.push_back(it->muonEnergyFraction());
266  jet_data->hfhef.push_back(it->HFHadronEnergyFraction());
267  jet_data->hfemef.push_back(it->HFEMEnergyFraction());
268  jet_data->chMult.push_back(it->chargedHadronMultiplicity());
269  jet_data->nhMult.push_back(it->neutralHadronMultiplicity());
270  jet_data->phMult.push_back(it->photonMultiplicity());
271  jet_data->elMult.push_back(it->electronMultiplicity());
272  jet_data->muMult.push_back(it->muonMultiplicity());
273  jet_data->hfhMult.push_back(it->HFHadronMultiplicity());
274  jet_data->hfemMult.push_back(it->HFEMMultiplicity());
275 
276  jet_data->cemef.push_back(it->chargedEmEnergyFraction());
277  jet_data->cmef.push_back(it->chargedMuEnergyFraction());
278  jet_data->nemef.push_back(it->neutralEmEnergyFraction());
279  jet_data->cMult.push_back(it->chargedMultiplicity());
280  jet_data->nMult.push_back(it->neutralMultiplicity());
281 
282  jet_data->nJets++;
283 
284  }
285 
286 }
287 
288 
289 void
291 
292 
293  float corrFactor = 1.;
294  uint nJets = 0;
295 
296  float mHx = 0;
297  float mHy = 0;
298 
299  met_data->Ht = 0;
300  met_data->mHt = -999.;
301  met_data->mHtPhi = -999.;
302 
303 
304  for( auto it=pfJets->begin();
305  it!=pfJets->end() && nJets < maxJet_;
306  ++it) {
307 
308  corrFactor = pfJetCorr.product()->correction(*it);
309 
310  jet_data->etCorr.push_back(it->et()*corrFactor);
311  jet_data->corrFactor.push_back(corrFactor);
312 
313  nJets++;
314 
315  if (it->pt()*corrFactor > jetptThreshold_ && fabs(it->eta())<jetetaMax_) {
316  mHx += -1.*it->px()*corrFactor;
317  mHy += -1.*it->py()*corrFactor;
318  met_data->Ht += it->pt()*corrFactor;
319  }
320 
321  }
322 
323  TVector2 *tv2 = new TVector2(mHx,mHy);
324  met_data->mHt = tv2->Mod();
325  met_data->mHtPhi = tv2->Phi();
326 
327  // std::vector< std::pair<float,float> > corrJetEtsAndCorrs;
328 
329  // //get jet correction and fill corrected jet ets and corrections
330  // for( auto it=pfJets->begin(); it!=pfJets->end(); ++it)
331  // {
332  // float corr = pfJetCorr.product()->correction(*it);
333  // std::pair<float,float> corrJetEtAndCorr(corr*it->et(),corr);
334  // corrJetEtsAndCorrs.push_back(corrJetEtAndCorr);
335  // }
336 
337  // // sort corrected jet ets and correction factors
338  // // by corrected jet et
339  // std::sort(corrJetEtsAndCorrs.rbegin(),corrJetEtsAndCorrs.rend());
340 
341  // //fill jet data array with sorted jet ets and corr factors
342  // std::vector<std::pair<float,float> >::iterator it;
343  // uint nJets = 0;
344 
345  // for(it = corrJetEtsAndCorrs.begin(); it != corrJetEtsAndCorrs.end() && nJets < maxJet_; ++it){
346  // jet_data->etCorr.push_back(it->first);
347  // jet_data->corrFactor.push_back(it->second);
348  // nJets++
349  // }
350 
351 }
352 
353 void
355 
356  const reco::PFMETCollection *metCol = pfMet.product();
357  const reco::PFMET theMet = metCol->front();
358 
359  met_data->met = theMet.et();
360  met_data->metPhi = theMet.phi();
361  met_data->sumEt = theMet.sumEt();
362 
363 }
364 
365 
366 bool
368 
369  bool tmp = true;
370 
371  tmp &= jet.neutralHadronEnergyFraction() < 0.9 ;
372  tmp &= jet.neutralEmEnergyFraction() < 0.9 ;
373  tmp &= (jet.chargedMultiplicity() + jet.neutralMultiplicity()) > 1 ;
374  tmp &= jet.muonEnergyFraction() < 0.8 ;
375  if (fabs(jet.eta()) < 2.4) {
376  tmp &= jet.chargedHadronEnergyFraction() > 0.0 ;
377  tmp &= jet.chargedMultiplicity() > 0 ;
378  tmp &= jet.chargedEmEnergyFraction() < 0.9 ;
379  }
380  if (fabs(jet.eta()) > 3.0) {
381  tmp &= jet.neutralEmEnergyFraction() < 0.9 ;
382  tmp &= jet.neutralMultiplicity() > 10 ;
383  }
384 
385  // our custom selection
386  tmp &= jet.muonMultiplicity() == 0;
387  tmp &= jet.electronMultiplicity() == 0;
388 
389  return tmp;
390 
391 }
392 
393 
394 // ------------ method called once each job just before starting event loop ------------
395 void
397 {
398 }
399 
400 // ------------ method called once each job just after ending the event loop ------------
401 void
403 }
404 
405 //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
float chargedHadronEnergyFraction() const
chargedHadronEnergyFraction
Definition: PFJet.h:100
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
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:155
Jets made from PFObjects.
Definition: PFJet.h:21
L1Analysis::L1AnalysisRecoJetDataFormat * jet_data
float neutralEmEnergyFraction() const
neutralEmEnergyFraction
Definition: PFJet.h:152
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
float neutralHadronEnergyFraction() const
neutralHadronEnergyFraction
Definition: PFJet.h:104
edm::EDGetTokenT< reco::PFJetCollection > pfJetToken_
bool isValid() const
Definition: HandleBase.h:75
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int neutralMultiplicity() const
neutralMultiplicity
Definition: PFJet.h:157
edm::EDGetTokenT< reco::PFMETCollection > pfMetToken_
float chargedEmEnergyFraction() const
chargedEmEnergyFraction
Definition: PFJet.h:144
T const * product() const
Definition: Handle.h:81
L1JetRecoTreeProducer(const edm::ParameterSet &)
void doCaloJets(edm::Handle< reco::CaloJetCollection > caloJets)
int muonMultiplicity() const
muonMultiplicity
Definition: PFJet.h:135
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
bool jetId(const reco::PFJet &jet)
virtual double et() const final
transverse energy
virtual double eta() const final
momentum pseudorapidity
volatile std::atomic< bool > shutdown_flag false
float muonEnergyFraction() const
muonEnergyFraction
Definition: PFJet.h:116
tuple pfJets
Definition: pfJets_cff.py:8
int electronMultiplicity() const
electronMultiplicity
Definition: PFJet.h:133