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  jets_ = consumes<CaloJetCollection>(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("emfJet", &emfJet_, "emfJet_/F");
41  mcTruthTree_->Branch("etaJet", &etaJet_, "etaJet_/F");
42  mcTruthTree_->Branch("etaGen", &etaGen_, "etaGen_/F");
43  mcTruthTree_->Branch("phiJet", &phiJet_, "phiJet_/F");
44  mcTruthTree_->Branch("phiGen", &phiGen_, "phiGen_/F");
45  mcTruthTree_->Branch("dR", &dR_, "dR_/F");
46  mcTruthTree_->Branch("rank", &rank_, "rank_/I");
47 }
50  if (file_ != nullptr) {
51  file_->cd();
52  mcTruthTree_->Write();
53  }
54  file_ = nullptr;
55 }
61  CaloJetCollection::const_iterator i_jet, i_matched;
62  GenJetCollection::const_iterator i_genjet;
63  event.getByToken(genjets_, genjets);
64  event.getByToken(jets_, jets);
65  event.getByToken(gen_, hEventInfo);
66  ptHat_ = hEventInfo->binningValues()[0];
67  float rr;
68  int njet(0);
69  if (!jets->empty() && !genjets->empty()) {
70  for (i_genjet = genjets->begin(); i_genjet != genjets->end(); i_genjet++) {
71  float rmin(99);
72  for (i_jet = jets->begin(); i_jet != jets->end(); i_jet++) {
73  rr = radius(i_genjet, i_jet);
74  if (rr < rmin) {
75  rmin = rr;
76  i_matched = i_jet;
77  }
78  }
79  ptGen_ = i_genjet->pt();
80  etaGen_ = i_genjet->eta();
81  phiGen_ = i_genjet->phi();
82  ptJet_ = i_matched->pt();
83  etaJet_ = i_matched->eta();
84  phiJet_ = i_matched->phi();
85  emfJet_ = i_matched->emEnergyFraction();
86  dR_ = rmin;
87  rank_ = njet;
88  mcTruthTree_->Fill();
89  njet++;
90  }
91  }
92 }
95  delete file_;
96  delete mcTruthTree_;
97 }
98 //}
Handle.h
CaloJet.h
ESHandle.h
CaloMCTruthTreeProducer::beginJob
void beginJob() override
Definition: CaloMCTruthTreeProducer.cc:33
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
edm
HLT enums.
Definition: AlignableModifier.h:19
GenEventInfoProduct::binningValues
const std::vector< double > & binningValues() const
Definition: GenEventInfoProduct.h:48
CaloMCTruthTreeProducer::CaloMCTruthTreeProducer
CaloMCTruthTreeProducer(edm::ParameterSet const &cfg)
Definition: CaloMCTruthTreeProducer.cc:26
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
njet
int njet
Definition: HydjetWrapper.h:89
CaloMCTruthTreeProducer::~CaloMCTruthTreeProducer
~CaloMCTruthTreeProducer() override
Definition: CaloMCTruthTreeProducer.cc:94
CaloMCTruthTreeProducer::analyze
void analyze(edm::Event const &e, edm::EventSetup const &iSetup) override
Definition: CaloMCTruthTreeProducer.cc:57
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
CaloMCTruthTreeProducer::endJob
void endJob() override
Definition: CaloMCTruthTreeProducer.cc:49
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
EventSetup.h
CaloMCTruthTreeProducer.h
GenJet.h
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15