CMS 3D CMS Logo

CaloMCTruthTreeProducer.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<CaloJetCollection>(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("emfJet", &emfJet_, "emfJet_/F");
43  mcTruthTree_->Branch("etaJet", &etaJet_, "etaJet_/F");
44  mcTruthTree_->Branch("etaGen", &etaGen_, "etaGen_/F");
45  mcTruthTree_->Branch("phiJet", &phiJet_, "phiJet_/F");
46  mcTruthTree_->Branch("phiGen", &phiGen_, "phiGen_/F");
47  mcTruthTree_->Branch("dR", &dR_, "dR_/F");
48  mcTruthTree_->Branch("rank", &rank_, "rank_/I");
49 }
52 {
53  if (file_ !=0)
54  {
55  file_->cd();
56  mcTruthTree_->Write();
57  }
58  file_ = 0;
59 }
62 {
66  CaloJetCollection::const_iterator i_jet,i_matched;
67  GenJetCollection::const_iterator i_genjet;
68  event.getByToken (genjets_,genjets);
69  event.getByToken (jets_,jets);
70  event.getByToken(gen_,hEventInfo);
71  ptHat_ = hEventInfo->binningValues()[0];
72  float rr;
73  int njet(0);
74  if (jets->size()>0 && genjets->size()>0)
75  {
76  for (i_genjet = genjets->begin(); i_genjet != genjets->end(); i_genjet++)
77  {
78  float rmin(99);
79  for(i_jet = jets->begin();i_jet != jets->end(); i_jet++)
80  {
81  rr=radius(i_genjet,i_jet);
82  if (rr<rmin)
83  {
84  rmin = rr;
85  i_matched = i_jet;
86  }
87  }
88  ptGen_ = i_genjet->pt();
89  etaGen_ = i_genjet->eta();
90  phiGen_ = i_genjet->phi();
91  ptJet_ = i_matched->pt();
92  etaJet_ = i_matched->eta();
93  phiJet_ = i_matched->phi();
94  emfJet_ = i_matched->emEnergyFraction();
95  dR_ = rmin;
96  rank_ = njet;
97  mcTruthTree_->Fill();
98  njet++;
99  }
100  }
101 }
104 {
105  delete file_;
106  delete mcTruthTree_;
107 }
108 //}
T getParameter(std::string const &) const
const std::vector< double > & binningValues() const
CaloMCTruthTreeProducer(edm::ParameterSet const &cfg)
int njet
Definition: HydjetWrapper.h:95
vector< PseudoJet > jets
fixed size matrix
HLT enums.
virtual void analyze(edm::Event const &e, edm::EventSetup const &iSetup)
Definition: event.py:1