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  jets_ = consumes<PFJetCollection>(edm::InputTag(cfg.getParameter<std::string>("jets")));
28  genjets_ = consumes<GenJetCollection>(edm::InputTag(cfg.getParameter<std::string>("genjets")));
29  gen_ = consumes<GenEventInfoProduct>(edm::InputTag("generator"));
30  histogramFile_ = cfg.getParameter<std::string>("histogramFile");
31 }
34  file_ = new TFile(histogramFile_.c_str(), "RECREATE");
35  mcTruthTree_ = new TTree("mcTruthTree", "mcTruthTree");
36 
37  mcTruthTree_->Branch("ptJet", &ptJet_, "ptJet_/F");
38  mcTruthTree_->Branch("ptGen", &ptGen_, "ptGen_/F");
39  mcTruthTree_->Branch("ptHat", &ptHat_, "ptHat_/F");
40  mcTruthTree_->Branch("chfJet", &chfJet_, "chfJet_/F");
41  mcTruthTree_->Branch("nhfJet", &nhfJet_, "nhfJet_/F");
42  mcTruthTree_->Branch("cemfJet", &cemfJet_, "cemfJet_/F");
43  mcTruthTree_->Branch("nemfJet", &nemfJet_, "nemfJet_/F");
44  mcTruthTree_->Branch("cmultiJet", &cmultiJet_, "cmultiJet_/I");
45  mcTruthTree_->Branch("nmultiJet", &nmultiJet_, "nmultiJet_/I");
46  mcTruthTree_->Branch("etaJet", &etaJet_, "etaJet_/F");
47  mcTruthTree_->Branch("etaGen", &etaGen_, "etaGen_/F");
48  mcTruthTree_->Branch("phiJet", &phiJet_, "phiJet_/F");
49  mcTruthTree_->Branch("phiGen", &phiGen_, "phiGen_/F");
50  mcTruthTree_->Branch("dR", &dR_, "dR_/F");
51  mcTruthTree_->Branch("rank", &rank_, "rank_/I");
52 }
55  if (file_ != nullptr) {
56  file_->cd();
57  mcTruthTree_->Write();
58  }
59  file_ = nullptr;
60 }
66  PFJetCollection::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->empty() && !genjets->empty()) {
75  for (i_genjet = genjets->begin(); i_genjet != genjets->end(); i_genjet++) {
76  float rmin(99);
77  for (i_jet = jets->begin(); i_jet != jets->end(); i_jet++) {
78  rr = radius(i_genjet, i_jet);
79  if (rr < rmin) {
80  rmin = rr;
81  i_matched = i_jet;
82  }
83  }
84  ptGen_ = i_genjet->pt();
85  etaGen_ = i_genjet->eta();
86  phiGen_ = i_genjet->phi();
87  ptJet_ = i_matched->pt();
88  etaJet_ = i_matched->eta();
89  phiJet_ = i_matched->phi();
90  chfJet_ = i_matched->chargedHadronEnergyFraction();
91  nhfJet_ = i_matched->neutralHadronEnergyFraction();
92  cemfJet_ = i_matched->chargedEmEnergyFraction();
93  nemfJet_ = i_matched->neutralEmEnergyFraction();
94  cmultiJet_ = i_matched->chargedMultiplicity();
95  nmultiJet_ = i_matched->neutralMultiplicity();
96  dR_ = rmin;
97  rank_ = njet;
98  mcTruthTree_->Fill();
99  njet++;
100  }
101  }
102 }
105  delete file_;
106  delete mcTruthTree_;
107 }
108 //}
Handle.h
ESHandle.h
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
edm
HLT enums.
Definition: AlignableModifier.h:19
PFJet.h
GenEventInfoProduct::binningValues
const std::vector< double > & binningValues() const
Definition: GenEventInfoProduct.h:48
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
PFMCTruthTreeProducer::~PFMCTruthTreeProducer
~PFMCTruthTreeProducer() override
Definition: PFMCTruthTreeProducer.cc:104
njet
int njet
Definition: HydjetWrapper.h:89
PFMCTruthTreeProducer.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PFMCTruthTreeProducer::beginJob
void beginJob() override
Definition: PFMCTruthTreeProducer.cc:33
PFMCTruthTreeProducer::PFMCTruthTreeProducer
PFMCTruthTreeProducer(edm::ParameterSet const &cfg)
Definition: PFMCTruthTreeProducer.cc:26
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
JetUtilMC.h
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
looper.cfg
cfg
Definition: looper.py:297
std
Definition: JetResolutionObject.h:76
PFMCTruthTreeProducer::analyze
void analyze(edm::Event const &e, edm::EventSetup const &iSetup) override
Definition: PFMCTruthTreeProducer.cc:62
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
EventSetup.h
PFMCTruthTreeProducer::endJob
void endJob() override
Definition: PFMCTruthTreeProducer.cc:54
GenJet.h
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15