CMS 3D CMS Logo

PFMCTruthTreeProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <istream>
4 #include <fstream>
5 #include <iomanip>
6 #include <string>
7 #include <cmath>
8 #include <functional>
9 
20 using namespace edm;
21 using namespace reco;
22 using namespace std;
23 //namespace cms
24 //{
25 
27 {
28  jets_ = consumes<PFJetCollection>(edm::InputTag(cfg.getParameter<std::string> ("jets")));
29  genjets_ = consumes<GenJetCollection>(edm::InputTag(cfg.getParameter<std::string> ("genjets")));
30  gen_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
31  histogramFile_ = cfg.getParameter<std::string> ("histogramFile");
32 }
35 {
36  file_ = new TFile(histogramFile_.c_str(),"RECREATE");
37  mcTruthTree_ = new TTree("mcTruthTree","mcTruthTree");
38 
39  mcTruthTree_->Branch("ptJet", &ptJet_, "ptJet_/F");
40  mcTruthTree_->Branch("ptGen", &ptGen_, "ptGen_/F");
41  mcTruthTree_->Branch("ptHat", &ptHat_, "ptHat_/F");
42  mcTruthTree_->Branch("chfJet", &chfJet_, "chfJet_/F");
43  mcTruthTree_->Branch("nhfJet", &nhfJet_, "nhfJet_/F");
44  mcTruthTree_->Branch("cemfJet", &cemfJet_, "cemfJet_/F");
45  mcTruthTree_->Branch("nemfJet", &nemfJet_, "nemfJet_/F");
46  mcTruthTree_->Branch("cmultiJet", &cmultiJet_, "cmultiJet_/I");
47  mcTruthTree_->Branch("nmultiJet", &nmultiJet_, "nmultiJet_/I");
48  mcTruthTree_->Branch("etaJet", &etaJet_, "etaJet_/F");
49  mcTruthTree_->Branch("etaGen", &etaGen_, "etaGen_/F");
50  mcTruthTree_->Branch("phiJet", &phiJet_, "phiJet_/F");
51  mcTruthTree_->Branch("phiGen", &phiGen_, "phiGen_/F");
52  mcTruthTree_->Branch("dR", &dR_, "dR_/F");
53  mcTruthTree_->Branch("rank", &rank_, "rank_/I");
54 }
57 {
58  if (file_ !=0)
59  {
60  file_->cd();
61  mcTruthTree_->Write();
62  }
63  file_ = 0;
64 }
67 {
71  PFJetCollection::const_iterator i_jet,i_matched;
72  GenJetCollection::const_iterator i_genjet;
73  event.getByToken (genjets_,genjets);
74  event.getByToken (jets_,jets);
75  event.getByToken(gen_,hEventInfo);
76  ptHat_ = hEventInfo->binningValues()[0];
77  float rr;
78  int njet(0);
79  if (jets->size()>0 && genjets->size()>0)
80  {
81  for (i_genjet = genjets->begin(); i_genjet != genjets->end(); i_genjet++)
82  {
83  float rmin(99);
84  for(i_jet = jets->begin();i_jet != jets->end(); i_jet++)
85  {
86  rr=radius(i_genjet,i_jet);
87  if (rr<rmin)
88  {
89  rmin = rr;
90  i_matched = i_jet;
91  }
92  }
93  ptGen_ = i_genjet->pt();
94  etaGen_ = i_genjet->eta();
95  phiGen_ = i_genjet->phi();
96  ptJet_ = i_matched->pt();
97  etaJet_ = i_matched->eta();
98  phiJet_ = i_matched->phi();
99  chfJet_ = i_matched->chargedHadronEnergyFraction();
100  nhfJet_ = i_matched->neutralHadronEnergyFraction();
101  cemfJet_ = i_matched->chargedEmEnergyFraction();
102  nemfJet_ = i_matched->neutralEmEnergyFraction();
103  cmultiJet_ = i_matched->chargedMultiplicity();
104  nmultiJet_ = i_matched->neutralMultiplicity();
105  dR_ = rmin;
106  rank_ = njet;
107  mcTruthTree_->Fill();
108  njet++;
109  }
110  }
111 }
114 {
115  delete file_;
116  delete mcTruthTree_;
117 }
118 //}
T getParameter(std::string const &) const
const std::vector< double > & binningValues() const
vector< PseudoJet > jets
virtual void analyze(edm::Event const &e, edm::EventSetup const &iSetup)
fixed size matrix
HLT enums.
PFMCTruthTreeProducer(edm::ParameterSet const &cfg)
Definition: event.py:1