CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JetAnalyzer_HeavyIons_matching.cc
Go to the documentation of this file.
1 //
2 // Jet Analyzer class for heavy ion jets. for DQM jet analysis monitoring
3 // For CMSSW_7_5_X, especially reading background subtracted jets - jet matching 1 - 1
4 // author: Raghav Kunnawalkam Elayavalli,
5 // April 6th 2015
6 // Rutgers University, email: raghav.k.e at CERN dot CH
7 //
8 
10 
11 using namespace edm;
12 using namespace reco;
13 using namespace std;
14 
15 // declare the constructors:
16 
18  : mInputJet1Collection(iConfig.getParameter<edm::InputTag>("src_Jet1")),
19  mInputJet2Collection(iConfig.getParameter<edm::InputTag>("src_Jet2")),
20  JetType1(iConfig.getUntrackedParameter<std::string>("Jet1")),
21  JetType2(iConfig.getUntrackedParameter<std::string>("Jet2")),
22  mRecoJetPtThreshold(iConfig.getParameter<double>("recoJetPtThreshold")),
23  mRecoDelRMatch(iConfig.getParameter<double>("recoDelRMatch")),
24  mRecoJetEtaCut(iConfig.getParameter<double>("recoJetEtaCut")) {
25  std::string inputCollectionLabelJet1(mInputJet1Collection.label());
26  std::string inputCollectionLabelJet2(mInputJet2Collection.label());
27 
28  //consumes
29 
30  if (std::string("VsCalo") == JetType1)
31  caloJet1Token_ = consumes<reco::CaloJetCollection>(mInputJet1Collection);
32  if (std::string("VsPF") == JetType1)
33  pfJetsToken_ = consumes<reco::PFJetCollection>(mInputJet1Collection);
34  if (std::string("PuCalo") == JetType1)
35  caloJet2Token_ = consumes<reco::CaloJetCollection>(mInputJet1Collection);
36  if (std::string("PuPF") == JetType1)
37  basicJetsToken_ = consumes<reco::BasicJetCollection>(mInputJet1Collection);
38 
39  if (std::string("VsCalo") == JetType2)
40  caloJet1Token_ = consumes<reco::CaloJetCollection>(mInputJet2Collection);
41  if (std::string("VsPF") == JetType2)
42  pfJetsToken_ = consumes<reco::PFJetCollection>(mInputJet2Collection);
43  if (std::string("PuCalo") == JetType2)
44  caloJet2Token_ = consumes<reco::CaloJetCollection>(mInputJet2Collection);
45  if (std::string("PuPF") == JetType2)
46  basicJetsToken_ = consumes<reco::BasicJetCollection>(mInputJet2Collection);
47 
48  // initialize the Jet matching histograms
49 
50  mpT_ratio_Jet1Jet2 = nullptr;
51  mpT_Jet1_matched = nullptr;
52  mpT_Jet2_matched = nullptr;
53  mpT_Jet1_unmatched = nullptr;
54  mpT_Jet2_unmatched = nullptr;
55 
56  // we need to add histograms which will hold the hadronic and electromagnetic energy content for the unmatched Jets.
57  if (std::string("VsCalo") == JetType1 || std::string("PuCalo") == JetType1) {
58  mHadEnergy_Jet1_unmatched = nullptr;
59  mEmEnergy_Jet1_unmatched = nullptr;
60  }
61  if (std::string("VsCalo") == JetType2 || std::string("PuCalo") == JetType2) {
62  mHadEnergy_Jet2_unmatched = nullptr;
63  mEmEnergy_Jet2_unmatched = nullptr;
64  }
65 
66  if (std::string("VsPF") == JetType1) {
77  }
78 
79  if (std::string("VsPF") == JetType2) {
90  }
91 }
92 
94  edm::Run const& iRun,
95  edm::EventSetup const&) {
96  ibooker.setCurrentFolder("JetMET/HIJetValidation/" + mInputJet1Collection.label() + "_DeltaRMatched_" +
98 
99  mpT_ratio_Jet1Jet2 = ibooker.book1D(
100  "Ratio_Jet1pT_vs_Jet2pT", Form(";Matched %s Jet pT / %s Jet pT;Counts", "JetType1", "JetType2"), 100, 0, 10);
102  ibooker.book1D("Jet1_matched_jet_Spectra", Form(";Matched %s Spectra; counts", "JetType1"), 100, 0, 1000);
104  ibooker.book1D("Jet2_matched_jet_Spectra", Form(";Matched %s Spectra; counts", "JetType2"), 100, 0, 1000);
106  ibooker.book1D("Jet1_unmatched_jet_Spectra", Form(";Unmatched %s spectra;counts", "JetType1"), 100, 0, 1000);
108  ibooker.book1D("Jet2_unmatched_jet_Spectra", Form(";Unmatched %s spectra;counts", "JetType2"), 100, 0, 1000);
109 
110  if (std::string("VsCalo") == JetType1 || std::string("PuCalo") == JetType1) {
112  ibooker.book1D("HadEnergy_Jet1_unmatched",
113  Form("HadEnergy_Jet1_unmatched;HadEnergy unmatched %s;counts", "JetType1"),
114  50,
115  0,
116  200);
118  "EmEnergy_Jet1_unmatched", Form("EmEnergy_Jet1_unmatched;EMEnergy unmatched %s;counts", "JetType1"), 50, 0, 200);
119  }
120 
121  if (std::string("VsCalo") == JetType2 || std::string("PuCalo") == JetType2) {
123  ibooker.book1D("HadEnergy_Jet2_unmatched",
124  Form("HadEnergy_Jet2_unmatched;HadEnergy unmatched %s;counts", "JetType2"),
125  50,
126  0,
127  200);
129  "EmEnergy_Jet2_unmatched", Form("EmEnergy_Jet2_unmatched;EMEnergy unmatched %s;counts", "JetType2"), 50, 0, 200);
130  }
131 
132  if (std::string("VsPF") == JetType1) {
134  "ChargedHadronEnergy_Jet1_unmatched", Form(";charged HAD energy unmatched %s;counts", "JetType1"), 100, 0, 300);
136  "neutralHadronEnergy_Jet1_unmatched", Form(";neutral HAD energy unmatched %s;counts", "JetType1"), 100, 0, 300);
138  "ChargedEmEnergy_Jet1_unmatched", Form(";charged EM energy unmatched %s;counts", "JetType1"), 100, 0, 300);
140  "neutralEmEnergy_Jet1_unmatched", Form(";neutral EM energy unmatched %s;counts", "JetType1"), 100, 0, 300);
142  "ChargedMuEnergy_Jet1_unmatched", Form(";charged Mu energy unmatched %s;counts", "JetType1"), 100, 0, 300);
143 
145  "ChargedHadEnergyFraction_Jet1_unmatched", Form(";h^{+/-} Energy Fraction %s;counts", "JetType1"), 50, 0, 1);
147  "NeutralHadEnergyFraction_Jet1_unmatched", Form(";h^{0} Energy Fraction %s;counts", "JetType1"), 50, 0, 1);
149  "PhotonEnergyFraction_Jet1_unmatched", Form(";#gamma Energy Fraction %s;counts", "JetType1"), 50, 0, 1);
151  "ElectronEnergyFraction_Jet1_unmatched", Form(";e Energy Fraction %s;counts", "JetType1"), 50, 0, 1);
153  "MuonoEnergyFraction_Jet1_unmatched", Form(";#mu Energy Fraction %s;counts", "JetType1"), 50, 0, 1);
154  }
155 
156  if (std::string("VsPF") == JetType2) {
158  "ChargedHadronEnergy_Jet2_unmatched", Form(";charged HAD energy unmatched %s;counts", "JetType2"), 100, 0, 300);
160  "neutralHadronEnergy_Jet2_unmatched", Form(";neutral HAD energy unmatched %s;counts", "JetType2"), 100, 0, 300);
162  "ChargedEmEnergy_Jet2_unmatched", Form(";charged EM energy unmatched %s;counts", "JetType2"), 100, 0, 300);
164  "neutralEmEnergy_Jet2_unmatched", Form(";neutral EM energy unmatched %s;counts", "JetType2"), 100, 0, 300);
166  "ChargedMuEnergy_Jet2_unmatched", Form(";charged Mu energy unmatched %s;counts", "JetType2"), 100, 0, 300);
167 
169  "ChargedHadEnergyFraction_Jet2_unmatched", Form(";h^{+/-} Energy Fraction %s;counts", "JetType2"), 50, 0, 1);
171  "NeutralHadEnergyFraction_Jet2_unmatched", Form(";h^{0} Energy Fraction %s;counts", "JetType2"), 50, 0, 1);
173  "PhotonEnergyFraction_Jet2_unmatched", Form(";#gamma Energy Fraction %s;counts", "JetType2"), 50, 0, 1);
175  "ElectronEnergyFraction_Jet2_unmatched", Form(";e Energy Fraction %s;counts", "JetType2"), 50, 0, 1);
177  "MuonoEnergyFraction_Jet2_unmatched", Form(";#mu Energy Fraction %s;counts", "JetType2"), 50, 0, 1);
178  }
179 
180  if (mOutputFile.empty())
181  LogInfo("OutputInfo") << " Histograms will NOT be saved";
182  else
183  LogInfo("OutputInfo") << " Histograms will be saved to file:" << mOutputFile;
184 }
185 
186 //------------------------------------------------------------------------------
187 // ~JetAnalyzer_HeavyIons
188 //------------------------------------------------------------------------------
190 
191 //------------------------------------------------------------------------------
192 // beginJob
193 //------------------------------------------------------------------------------
194 //void JetAnalyzer_HeavyIons_matching::beginJob() {
195 // std::cout<<"inside the begin job function"<<endl;
196 //}
197 
198 //------------------------------------------------------------------------------
199 // endJob
200 //------------------------------------------------------------------------------
201 //void JetAnalyzer_HeavyIons_matching::endJob()
202 //{
203 // if (!mOutputFile.empty() && &*edm::Service<DQMStore>())
204 // {
205 // edm::Service<DQMStore>()->save(mOutputFile);
206 // }
207 //}
208 
209 //------------------------------------------------------------------------------
210 // analyze
211 //------------------------------------------------------------------------------
213  // Get the Jet collection
214  //----------------------------------------------------------------------------
215 
216  std::vector<const Jet*> recoJet1;
217  recoJet1.clear();
218  std::vector<const Jet*> recoJet2;
219  recoJet2.clear();
220 
226 
227  if (std::string("VsCalo") == JetType1) {
228  mEvent.getByToken(caloJet1Token_, caloJet1);
229  for (unsigned ijet = 0; ijet < caloJet1->size(); ++ijet)
230  recoJet1.push_back(&(*caloJet1)[ijet]);
231  }
232  if (std::string("PuCalo") == JetType1) {
233  mEvent.getByToken(caloJet2Token_, caloJet1);
234  for (unsigned ijet = 0; ijet < caloJet1->size(); ++ijet)
235  recoJet1.push_back(&(*caloJet1)[ijet]);
236  }
237  if (std::string("VsPF") == JetType1) {
238  mEvent.getByToken(pfJetsToken_, pfJets);
239  for (unsigned ijet = 0; ijet < pfJets->size(); ++ijet)
240  recoJet1.push_back(&(*pfJets)[ijet]);
241  }
242  if (std::string("PuPF") == JetType1) {
243  mEvent.getByToken(basicJetsToken_, basicJets);
244  for (unsigned ijet = 0; ijet < basicJets->size(); ++ijet)
245  recoJet1.push_back(&(*basicJets)[ijet]);
246  }
247 
248  if (std::string("VsCalo") == JetType2) {
249  mEvent.getByToken(caloJet1Token_, caloJet2);
250  for (unsigned ijet = 0; ijet < caloJet2->size(); ++ijet)
251  recoJet2.push_back(&(*caloJet2)[ijet]);
252  }
253  if (std::string("PuCalo") == JetType2) {
254  mEvent.getByToken(caloJet2Token_, caloJet2);
255  for (unsigned ijet = 0; ijet < caloJet2->size(); ++ijet)
256  recoJet2.push_back(&(*caloJet2)[ijet]);
257  }
258  if (std::string("VsPF") == JetType2) {
259  mEvent.getByToken(pfJetsToken_, pfJets);
260  for (unsigned ijet = 0; ijet < pfJets->size(); ++ijet)
261  recoJet2.push_back(&(*pfJets)[ijet]);
262  }
263  if (std::string("PuPF") == JetType2) {
264  mEvent.getByToken(basicJetsToken_, basicJets);
265  for (unsigned ijet = 0; ijet < basicJets->size(); ++ijet)
266  recoJet2.push_back(&(*basicJets)[ijet]);
267  }
268 
269  // start to perform the matching - between recoJet1 and recoJet2.
270 
271  Int_t Jet1_nref = recoJet1.size();
272  Int_t Jet2_nref = recoJet2.size();
273 
274  int jet1 = 0;
275  int jet2 = 0;
276 
277  std::vector<MyJet> vJet1, vJet2;
278  std::vector<int> Jet1_ID(Jet1_nref), Jet2_ID(Jet2_nref);
279 
280  if (Jet1_nref == 0 || Jet2_nref == 0)
281  return;
282 
283  for (unsigned ijet1 = 0; ijet1 < recoJet1.size(); ++ijet1) {
284  if (recoJet1[ijet1]->pt() < mRecoJetPtThreshold)
285  continue;
286  if (fabs(recoJet1[ijet1]->eta()) < mRecoJetEtaCut)
287  continue;
288 
289  MyJet JET1;
290  JET1.eta = recoJet1[ijet1]->eta();
291  JET1.phi = recoJet1[ijet1]->phi();
292  JET1.pt = recoJet1[ijet1]->pt();
293  JET1.id = ijet1;
294 
295  vJet1.push_back(JET1);
296  jet1++;
297 
298  } // first jet loop
299 
300  for (unsigned ijet2 = 0; ijet2 < recoJet2.size(); ++ijet2) {
301  if (recoJet2[ijet2]->pt() < mRecoJetPtThreshold)
302  continue;
303  if (fabs(recoJet2[ijet2]->eta()) < mRecoJetEtaCut)
304  continue;
305 
306  MyJet JET2;
307  JET2.eta = recoJet2[ijet2]->eta();
308  JET2.phi = recoJet2[ijet2]->phi();
309  JET2.pt = recoJet2[ijet2]->pt();
310  JET2.id = ijet2;
311 
312  vJet2.push_back(JET2);
313  jet2++;
314 
315  } // second jet loop
316 
317  bool onlyJet1 = (jet1 > 0 && jet2 == 0) ? true : false;
318  bool onlyJet2 = (jet1 == 0 && jet2 > 0) ? true : false;
319  bool bothJet1Jet2 = (jet1 > 0 && jet2 > 0) ? true : false;
320 
321  int matchedJets = 0;
322  int unmatchedJet1 = 0;
323  int unmatchedJet2 = 0;
324 
325  std::vector<MyJet>::const_iterator iJet, jJet;
326 
327  if (onlyJet1) {
328  for (iJet = vJet1.begin(); iJet != vJet1.end(); ++iJet) {
329  int pj = (*iJet).id;
330 
331  mpT_Jet1_unmatched->Fill(recoJet1[pj]->pt());
332  }
333 
334  } else if (onlyJet2) {
335  for (iJet = vJet2.begin(); iJet != vJet2.end(); ++iJet) {
336  int cj = (*iJet).id;
337 
338  mpT_Jet2_unmatched->Fill(recoJet2[cj]->pt());
339  }
340 
341  } else if (bothJet1Jet2) {
342  ABMatchedJets mABMatchedJets;
343 
344  for (iJet = vJet1.begin(); iJet != vJet1.end(); ++iJet) {
345  for (jJet = vJet2.begin(); jJet != vJet2.end(); ++jJet) {
346  mABMatchedJets.insert(std::make_pair(*iJet, *jJet));
347  }
348  }
349 
350  ABItr itr;
351  // matched Jets matching Jet 1 to Jet 2
352  for (itr = mABMatchedJets.begin(); itr != mABMatchedJets.end(); ++itr) {
353  ABJetPair jetpair = (*itr);
354  MyJet Aj = jetpair.first;
355  MyJet Bj = jetpair.second;
356 
357  float delr = JetAnalyzer_HeavyIons_matching::deltaRR(Bj.eta, Bj.phi, Aj.eta, Aj.phi);
358 
359  if (delr < mRecoDelRMatch && Jet1_ID[Aj.id] == 0) {
360  mpT_ratio_Jet1Jet2->Fill((Float_t)recoJet2[Bj.id]->pt() / recoJet1[Aj.id]->pt());
361 
362  mpT_Jet1_matched->Fill(recoJet1[Aj.id]->pt());
363  mpT_Jet2_matched->Fill(recoJet2[Bj.id]->pt());
364 
365  Jet1_ID[Aj.id] = 1;
366  Jet2_ID[Bj.id] = 1;
367 
368  matchedJets++;
369  }
370  }
371 
372  // for unmatched Jets
373  for (itr = mABMatchedJets.begin(); itr != mABMatchedJets.end(); ++itr) {
374  ABJetPair jetpair = (*itr);
375 
376  MyJet Aj = jetpair.first;
377  MyJet Bj = jetpair.second;
378 
379  if (Jet1_ID[Aj.id] == 0) {
380  mpT_Jet1_unmatched->Fill(recoJet1[Aj.id]->pt());
381  unmatchedJet1++;
382  Jet1_ID[Aj.id] = 1;
383 
384  if (std::string("VsCalo") == JetType1 || std::string("PuCalo") == JetType1) {
385  mHadEnergy_Jet1_unmatched->Fill((*caloJet1)[Aj.id].hadEnergyInHO() + (*caloJet1)[Aj.id].hadEnergyInHB() +
386  (*caloJet1)[Aj.id].hadEnergyInHF() + (*caloJet1)[Aj.id].hadEnergyInHE());
387  mEmEnergy_Jet1_unmatched->Fill((*caloJet1)[Aj.id].emEnergyInEB() + (*caloJet1)[Aj.id].emEnergyInEE() +
388  (*caloJet1)[Aj.id].emEnergyInHF());
389  }
390 
391  if (std::string("VsPF") == JetType1) {
392  mChargedHadronEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedHadronEnergy());
393  mNeutralHadronEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralHadronEnergy());
394  mChargedEmEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedEmEnergy());
395  mNeutralEmEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralEmEnergy());
396  mChargedMuEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedMuEnergy());
397 
398  mChargedHadEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedHadronEnergyFraction());
399  mNeutralHadEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralHadronEnergyFraction());
400  mPhotonEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].photonEnergyFraction());
401  mElectronEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].electronEnergyFraction());
402  mMuonEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].muonEnergyFraction());
403  }
404  }
405 
406  if (Jet2_ID[Bj.id] == 0) {
407  mpT_Jet2_unmatched->Fill(recoJet2[Bj.id]->pt());
408  unmatchedJet2++;
409  Jet2_ID[Bj.id] = 2;
410  if (std::string("VsCalo") == JetType2 || std::string("PuCalo") == JetType2) {
411  mHadEnergy_Jet2_unmatched->Fill((*caloJet2)[Bj.id].hadEnergyInHO() + (*caloJet2)[Bj.id].hadEnergyInHB() +
412  (*caloJet2)[Bj.id].hadEnergyInHF() + (*caloJet2)[Bj.id].hadEnergyInHE());
413  mEmEnergy_Jet2_unmatched->Fill((*caloJet2)[Bj.id].emEnergyInEB() + (*caloJet2)[Bj.id].emEnergyInEE() +
414  (*caloJet2)[Bj.id].emEnergyInHF());
415  }
416 
417  if (std::string("VsPF") == JetType2) {
418  mChargedHadronEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedHadronEnergy());
419  mNeutralHadronEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralHadronEnergy());
420  mChargedEmEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedEmEnergy());
421  mNeutralEmEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralEmEnergy());
422  mChargedMuEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedMuEnergy());
423 
424  mChargedHadEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedHadronEnergyFraction());
425  mNeutralHadEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralHadronEnergyFraction());
426  mPhotonEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].photonEnergyFraction());
427  mElectronEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].electronEnergyFraction());
428  mMuonEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].muonEnergyFraction());
429  }
430  }
431  }
432 
433  } // both Jet1 and Jet2 in the event.
434 }
edm::EDGetTokenT< reco::PFJetCollection > pfJetsToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void analyze(const edm::Event &, const edm::EventSetup &) override
void Fill(long long x)
std::multiset< ABJetPair >::iterator ABItr
Log< level::Info, false > LogInfo
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::CaloJetCollection > caloJet1Token_
static float deltaRR(float eta1, float phi1, float eta2, float phi2)
std::string const & label() const
Definition: InputTag.h:36
JetAnalyzer_HeavyIons_matching(const edm::ParameterSet &)
edm::EDGetTokenT< reco::CaloJetCollection > caloJet2Token_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
tuple pfJets
Definition: pfJets_cff.py:8
std::multiset< ABJetPair, CompareMatchedJets > ABMatchedJets
Definition: Run.h:45
edm::EDGetTokenT< reco::BasicJetCollection > basicJetsToken_