CMS 3D CMS Logo

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 // analyze
193 //------------------------------------------------------------------------------
195  // Get the Jet collection
196  //----------------------------------------------------------------------------
197 
198  std::vector<const Jet*> recoJet1;
199  recoJet1.clear();
200  std::vector<const Jet*> recoJet2;
201  recoJet2.clear();
202 
208 
209  if (std::string("VsCalo") == JetType1) {
210  mEvent.getByToken(caloJet1Token_, caloJet1);
211  for (unsigned ijet = 0; ijet < caloJet1->size(); ++ijet)
212  recoJet1.push_back(&(*caloJet1)[ijet]);
213  }
214  if (std::string("PuCalo") == JetType1) {
215  mEvent.getByToken(caloJet2Token_, caloJet1);
216  for (unsigned ijet = 0; ijet < caloJet1->size(); ++ijet)
217  recoJet1.push_back(&(*caloJet1)[ijet]);
218  }
219  if (std::string("VsPF") == JetType1) {
220  mEvent.getByToken(pfJetsToken_, pfJets);
221  for (unsigned ijet = 0; ijet < pfJets->size(); ++ijet)
222  recoJet1.push_back(&(*pfJets)[ijet]);
223  }
224  if (std::string("PuPF") == JetType1) {
225  mEvent.getByToken(basicJetsToken_, basicJets);
226  for (unsigned ijet = 0; ijet < basicJets->size(); ++ijet)
227  recoJet1.push_back(&(*basicJets)[ijet]);
228  }
229 
230  if (std::string("VsCalo") == JetType2) {
231  mEvent.getByToken(caloJet1Token_, caloJet2);
232  for (unsigned ijet = 0; ijet < caloJet2->size(); ++ijet)
233  recoJet2.push_back(&(*caloJet2)[ijet]);
234  }
235  if (std::string("PuCalo") == JetType2) {
236  mEvent.getByToken(caloJet2Token_, caloJet2);
237  for (unsigned ijet = 0; ijet < caloJet2->size(); ++ijet)
238  recoJet2.push_back(&(*caloJet2)[ijet]);
239  }
240  if (std::string("VsPF") == JetType2) {
241  mEvent.getByToken(pfJetsToken_, pfJets);
242  for (unsigned ijet = 0; ijet < pfJets->size(); ++ijet)
243  recoJet2.push_back(&(*pfJets)[ijet]);
244  }
245  if (std::string("PuPF") == JetType2) {
246  mEvent.getByToken(basicJetsToken_, basicJets);
247  for (unsigned ijet = 0; ijet < basicJets->size(); ++ijet)
248  recoJet2.push_back(&(*basicJets)[ijet]);
249  }
250 
251  // start to perform the matching - between recoJet1 and recoJet2.
252 
253  Int_t Jet1_nref = recoJet1.size();
254  Int_t Jet2_nref = recoJet2.size();
255 
256  int jet1 = 0;
257  int jet2 = 0;
258 
259  std::vector<MyJet> vJet1, vJet2;
260  std::vector<int> Jet1_ID(Jet1_nref), Jet2_ID(Jet2_nref);
261 
262  if (Jet1_nref == 0 || Jet2_nref == 0)
263  return;
264 
265  for (unsigned ijet1 = 0; ijet1 < recoJet1.size(); ++ijet1) {
266  if (recoJet1[ijet1]->pt() < mRecoJetPtThreshold)
267  continue;
268  if (fabs(recoJet1[ijet1]->eta()) < mRecoJetEtaCut)
269  continue;
270 
271  MyJet JET1;
272  JET1.eta = recoJet1[ijet1]->eta();
273  JET1.phi = recoJet1[ijet1]->phi();
274  JET1.pt = recoJet1[ijet1]->pt();
275  JET1.id = ijet1;
276 
277  vJet1.push_back(JET1);
278  jet1++;
279 
280  } // first jet loop
281 
282  for (unsigned ijet2 = 0; ijet2 < recoJet2.size(); ++ijet2) {
283  if (recoJet2[ijet2]->pt() < mRecoJetPtThreshold)
284  continue;
285  if (fabs(recoJet2[ijet2]->eta()) < mRecoJetEtaCut)
286  continue;
287 
288  MyJet JET2;
289  JET2.eta = recoJet2[ijet2]->eta();
290  JET2.phi = recoJet2[ijet2]->phi();
291  JET2.pt = recoJet2[ijet2]->pt();
292  JET2.id = ijet2;
293 
294  vJet2.push_back(JET2);
295  jet2++;
296 
297  } // second jet loop
298 
299  bool onlyJet1 = (jet1 > 0 && jet2 == 0) ? true : false;
300  bool onlyJet2 = (jet1 == 0 && jet2 > 0) ? true : false;
301  bool bothJet1Jet2 = (jet1 > 0 && jet2 > 0) ? true : false;
302 
303  int matchedJets = 0;
304  int unmatchedJet1 = 0;
305  int unmatchedJet2 = 0;
306 
307  std::vector<MyJet>::const_iterator iJet, jJet;
308 
309  if (onlyJet1) {
310  for (iJet = vJet1.begin(); iJet != vJet1.end(); ++iJet) {
311  int pj = (*iJet).id;
312 
313  mpT_Jet1_unmatched->Fill(recoJet1[pj]->pt());
314  }
315 
316  } else if (onlyJet2) {
317  for (iJet = vJet2.begin(); iJet != vJet2.end(); ++iJet) {
318  int cj = (*iJet).id;
319 
320  mpT_Jet2_unmatched->Fill(recoJet2[cj]->pt());
321  }
322 
323  } else if (bothJet1Jet2) {
324  ABMatchedJets mABMatchedJets;
325 
326  for (iJet = vJet1.begin(); iJet != vJet1.end(); ++iJet) {
327  for (jJet = vJet2.begin(); jJet != vJet2.end(); ++jJet) {
328  mABMatchedJets.insert(std::make_pair(*iJet, *jJet));
329  }
330  }
331 
332  ABItr itr;
333  // matched Jets matching Jet 1 to Jet 2
334  for (itr = mABMatchedJets.begin(); itr != mABMatchedJets.end(); ++itr) {
335  ABJetPair jetpair = (*itr);
336  MyJet Aj = jetpair.first;
337  MyJet Bj = jetpair.second;
338 
339  float delr = JetAnalyzer_HeavyIons_matching::deltaRR(Bj.eta, Bj.phi, Aj.eta, Aj.phi);
340 
341  if (delr < mRecoDelRMatch && Jet1_ID[Aj.id] == 0) {
342  mpT_ratio_Jet1Jet2->Fill((Float_t)recoJet2[Bj.id]->pt() / recoJet1[Aj.id]->pt());
343 
344  mpT_Jet1_matched->Fill(recoJet1[Aj.id]->pt());
345  mpT_Jet2_matched->Fill(recoJet2[Bj.id]->pt());
346 
347  Jet1_ID[Aj.id] = 1;
348  Jet2_ID[Bj.id] = 1;
349 
350  matchedJets++;
351  }
352  }
353 
354  // for unmatched Jets
355  for (itr = mABMatchedJets.begin(); itr != mABMatchedJets.end(); ++itr) {
356  ABJetPair jetpair = (*itr);
357 
358  MyJet Aj = jetpair.first;
359  MyJet Bj = jetpair.second;
360 
361  if (Jet1_ID[Aj.id] == 0) {
362  mpT_Jet1_unmatched->Fill(recoJet1[Aj.id]->pt());
363  unmatchedJet1++;
364  Jet1_ID[Aj.id] = 1;
365 
366  if (std::string("VsCalo") == JetType1 || std::string("PuCalo") == JetType1) {
367  mHadEnergy_Jet1_unmatched->Fill((*caloJet1)[Aj.id].hadEnergyInHO() + (*caloJet1)[Aj.id].hadEnergyInHB() +
368  (*caloJet1)[Aj.id].hadEnergyInHF() + (*caloJet1)[Aj.id].hadEnergyInHE());
369  mEmEnergy_Jet1_unmatched->Fill((*caloJet1)[Aj.id].emEnergyInEB() + (*caloJet1)[Aj.id].emEnergyInEE() +
370  (*caloJet1)[Aj.id].emEnergyInHF());
371  }
372 
373  if (std::string("VsPF") == JetType1) {
374  mChargedHadronEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedHadronEnergy());
375  mNeutralHadronEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralHadronEnergy());
376  mChargedEmEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedEmEnergy());
377  mNeutralEmEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralEmEnergy());
378  mChargedMuEnergy_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedMuEnergy());
379 
380  mChargedHadEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].chargedHadronEnergyFraction());
381  mNeutralHadEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].neutralHadronEnergyFraction());
382  mPhotonEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].photonEnergyFraction());
383  mElectronEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].electronEnergyFraction());
384  mMuonEnergyFraction_Jet1_unmatched->Fill((*pfJets)[Aj.id].muonEnergyFraction());
385  }
386  }
387 
388  if (Jet2_ID[Bj.id] == 0) {
389  mpT_Jet2_unmatched->Fill(recoJet2[Bj.id]->pt());
390  unmatchedJet2++;
391  Jet2_ID[Bj.id] = 2;
392  if (std::string("VsCalo") == JetType2 || std::string("PuCalo") == JetType2) {
393  mHadEnergy_Jet2_unmatched->Fill((*caloJet2)[Bj.id].hadEnergyInHO() + (*caloJet2)[Bj.id].hadEnergyInHB() +
394  (*caloJet2)[Bj.id].hadEnergyInHF() + (*caloJet2)[Bj.id].hadEnergyInHE());
395  mEmEnergy_Jet2_unmatched->Fill((*caloJet2)[Bj.id].emEnergyInEB() + (*caloJet2)[Bj.id].emEnergyInEE() +
396  (*caloJet2)[Bj.id].emEnergyInHF());
397  }
398 
399  if (std::string("VsPF") == JetType2) {
400  mChargedHadronEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedHadronEnergy());
401  mNeutralHadronEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralHadronEnergy());
402  mChargedEmEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedEmEnergy());
403  mNeutralEmEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralEmEnergy());
404  mChargedMuEnergy_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedMuEnergy());
405 
406  mChargedHadEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].chargedHadronEnergyFraction());
407  mNeutralHadEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].neutralHadronEnergyFraction());
408  mPhotonEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].photonEnergyFraction());
409  mElectronEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].electronEnergyFraction());
410  mMuonEnergyFraction_Jet2_unmatched->Fill((*pfJets)[Bj.id].muonEnergyFraction());
411  }
412  }
413  }
414 
415  } // both Jet1 and Jet2 in the event.
416 }
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
std::string const & label() const
Definition: InputTag.h:36
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)
JetAnalyzer_HeavyIons_matching(const edm::ParameterSet &)
fixed size matrix
HLT enums.
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
std::multiset< ABJetPair, CompareMatchedJets > ABMatchedJets
Definition: Run.h:45
edm::EDGetTokenT< reco::BasicJetCollection > basicJetsToken_