CMS 3D CMS Logo

IsolatedParticlesGeneratedJets.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: IsolatedParticles
4 // Class: IsolatedParticlesGeneratedJets
5 //
14 //
15 // Original Author: Seema Sharma
16 // Created: Thu Mar 4 18:52:02 CST 2010
17 //
18 //
19 
20 // user include files
25 
32 
33 //TFile Service
36 
38 
39 // root objects
40 #include "TROOT.h"
41 #include "TSystem.h"
42 #include "TFile.h"
43 #include "TH1F.h"
44 #include "TH2F.h"
45 #include "TProfile.h"
46 #include "TDirectory.h"
47 #include "TTree.h"
48 
49 class IsolatedParticlesGeneratedJets : public edm::one::EDAnalyzer<edm::one::SharedResources> {
50 public:
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
55 
56 private:
57  void beginJob() override;
58  void analyze(const edm::Event &, const edm::EventSetup &) override;
59  void endJob() override {}
60 
61  void bookHistograms();
62  void clearTreeVectors();
63 
64  const bool debug_;
65  TTree *tree_;
66 
69 
70  std::vector<int> *t_gjetN;
71  std::vector<double> *t_gjetE, *t_gjetPt, *t_gjetEta, *t_gjetPhi;
72  std::vector<std::vector<double> > *t_jetTrkP;
73  std::vector<std::vector<double> > *t_jetTrkPt;
74  std::vector<std::vector<double> > *t_jetTrkEta;
75  std::vector<std::vector<double> > *t_jetTrkPhi;
76  std::vector<std::vector<double> > *t_jetTrkPdg;
77  std::vector<std::vector<double> > *t_jetTrkCharge;
78 };
79 
81  : debug_(iConfig.getUntrackedParameter<bool>("Debug", false)),
82  tok_jets_(consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("JetSource"))),
83  tok_parts_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("ParticleSource"))) {
84  usesResource(TFileService::kSharedResource);
85 }
86 
89  desc.addUntracked<bool>("Debug", true);
90  desc.add<edm::InputTag>("JetSource", edm::InputTag("ak5GenJets"));
91  desc.add<edm::InputTag>("ParticleSource", edm::InputTag("genParticles"));
92  descriptions.add("isolatedParticlesGeneratedJets", desc);
93 }
94 
96  //using namespace edm;
98 
99  //=== genJet information
101  iEvent.getByToken(tok_jets_, genJets);
102 
103  //=== genJet information
105  iEvent.getByToken(tok_parts_, genParticles);
106 
108  std::vector<std::vector<const reco::GenParticle *> > genJetConstituents(genJets->size());
109 
110  int njets = 0;
111  for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
112  const reco::GenJet &genJet = (*genJets)[iGenJet];
113 
114  double genJetE = genJet.energy();
115  double genJetPt = genJet.pt();
116  double genJetEta = genJet.eta();
117  double genJetPhi = genJet.phi();
118 
119  if (genJetPt > 30.0 && std::abs(genJetEta) < 3.0) {
120  njets++;
121 
122  std::vector<const reco::GenParticle *> genJetConstituents = jetMatching.getGenParticles((*genJets)[iGenJet]);
123  std::vector<double> v_trkP, v_trkPt, v_trkEta, v_trkPhi, v_trkPdg, v_trkCharge;
124 
125  if (debug_)
126  edm::LogVerbatim("IsoTrack") << "Jet(pt,Eta,Phi) " << genJetPt << " " << genJetEta << " " << genJetPhi;
127  for (unsigned int ic = 0; ic < genJetConstituents.size(); ic++) {
128  if (debug_)
129  edm::LogVerbatim("IsoTrack") << "p,pt,eta,phi " << genJetConstituents[ic]->p() << " "
130  << genJetConstituents[ic]->pt() << " " << genJetConstituents[ic]->eta() << " "
131  << genJetConstituents[ic]->phi();
132 
133  v_trkP.push_back(genJetConstituents[ic]->p());
134  v_trkPt.push_back(genJetConstituents[ic]->pt());
135  v_trkEta.push_back(genJetConstituents[ic]->eta());
136  v_trkPhi.push_back(genJetConstituents[ic]->phi());
137  v_trkPdg.push_back(genJetConstituents[ic]->pdgId());
138  v_trkCharge.push_back(genJetConstituents[ic]->charge());
139 
140  } //loop over genjet constituents
141 
142  t_gjetE->push_back(genJetE);
143  t_gjetPt->push_back(genJetPt);
144  t_gjetEta->push_back(genJetEta);
145  t_gjetPhi->push_back(genJetPhi);
146 
147  t_jetTrkP->push_back(v_trkP);
148  t_jetTrkPt->push_back(v_trkPt);
149  t_jetTrkEta->push_back(v_trkEta);
150  t_jetTrkPhi->push_back(v_trkPhi);
151  t_jetTrkPdg->push_back(v_trkPdg);
152  t_jetTrkCharge->push_back(v_trkCharge);
153 
154  } // if jetPt>30
155 
156  } //loop over genjets
157 
158  t_gjetN->push_back(njets);
159 
160  if (debug_) {
161  unsigned int indx = 0;
162  reco::GenParticleCollection::const_iterator ig = genParticles->begin();
163  for (; ig != genParticles->end(); ++ig, ++indx) {
164  edm::LogVerbatim("IsoTrack") << "Track " << indx << " Status " << ig->status() << " charge " << ig->charge()
165  << " pdgId " << ig->pdgId() << " mass " << ig->mass() << " P " << ig->momentum()
166  << " E " << ig->energy() << " Origin " << ig->vertex();
167  }
168  }
169 
170  tree_->Fill();
171 }
172 
174 
176  t_gjetN->clear();
177  t_gjetE->clear();
178  t_gjetPt->clear();
179  t_gjetEta->clear();
180  t_gjetPhi->clear();
181 
182  t_jetTrkP->clear();
183  t_jetTrkPt->clear();
184  t_jetTrkEta->clear();
185  t_jetTrkPhi->clear();
186  t_jetTrkPdg->clear();
187  t_jetTrkCharge->clear();
188 }
189 
192  tree_ = fs->make<TTree>("tree", "tree");
193 
194  t_gjetN = new std::vector<int>();
195  t_gjetE = new std::vector<double>();
196  t_gjetPt = new std::vector<double>();
197  t_gjetEta = new std::vector<double>();
198  t_gjetPhi = new std::vector<double>();
199 
200  t_jetTrkP = new std::vector<std::vector<double> >();
201  t_jetTrkPt = new std::vector<std::vector<double> >();
202  t_jetTrkEta = new std::vector<std::vector<double> >();
203  t_jetTrkPhi = new std::vector<std::vector<double> >();
204  t_jetTrkPdg = new std::vector<std::vector<double> >();
205  t_jetTrkCharge = new std::vector<std::vector<double> >();
206 
207  tree_->Branch("t_gjetN", "std::vector<int>", &t_gjetN);
208  tree_->Branch("t_gjetE", "std::vector<double>", &t_gjetE);
209  tree_->Branch("t_gjetPt", "std::vector<double>", &t_gjetPt);
210  tree_->Branch("t_gjetEta", "std::vector<double>", &t_gjetEta);
211  tree_->Branch("t_gjetPhi", "std::vector<double>", &t_gjetPhi);
212 
213  tree_->Branch("t_jetTrkP", "std::vector<vector<double> >", &t_jetTrkP);
214  tree_->Branch("t_jetTrkPt", "std::vector<vector<double> >", &t_jetTrkPt);
215  tree_->Branch("t_jetTrkEta", "std::vector<vector<double> >", &t_jetTrkEta);
216  tree_->Branch("t_jetTrkPhi", "std::vector<vector<double> >", &t_jetTrkPhi);
217  tree_->Branch("t_jetTrkPdg", "std::vector<vector<double> >", &t_jetTrkPdg);
218  tree_->Branch("t_jetTrkCharge", "std::vector<vector<double> >", &t_jetTrkCharge);
219 }
220 
221 //define this as a plug-in
GenJetCollection.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
EDAnalyzer.h
reco::GenJet
Jets made from MC generator particles.
Definition: GenJet.h:23
MessageLogger.h
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
funct::false
false
Definition: Factorize.h:29
IsolatedParticlesGeneratedJets::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: IsolatedParticlesGeneratedJets.cc:87
reco::GenJetCollection
std::vector< GenJet > GenJetCollection
collection of GenJet objects
Definition: GenJetCollection.h:14
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT< reco::GenJetCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
IsolatedParticlesGeneratedJets::clearTreeVectors
void clearTreeVectors()
Definition: IsolatedParticlesGeneratedJets.cc:175
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
IsolatedParticlesGeneratedJets::t_jetTrkPdg
std::vector< std::vector< double > > * t_jetTrkPdg
Definition: IsolatedParticlesGeneratedJets.cc:76
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:46
IsolatedParticlesGeneratedJets::~IsolatedParticlesGeneratedJets
~IsolatedParticlesGeneratedJets() override
Definition: IsolatedParticlesGeneratedJets.cc:52
JetMatchingTools.h
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
IsolatedParticlesGeneratedJets::tok_jets_
const edm::EDGetTokenT< reco::GenJetCollection > tok_jets_
Definition: IsolatedParticlesGeneratedJets.cc:67
edm::Handle< reco::GenJetCollection >
IsolatedParticlesGeneratedJets::t_jetTrkP
std::vector< std::vector< double > > * t_jetTrkP
Definition: IsolatedParticlesGeneratedJets.cc:72
IsolatedParticlesGeneratedJets::beginJob
void beginJob() override
Definition: IsolatedParticlesGeneratedJets.cc:173
GenParticle.h
IsolatedParticlesGeneratedJets::t_jetTrkPt
std::vector< std::vector< double > > * t_jetTrkPt
Definition: IsolatedParticlesGeneratedJets.cc:73
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
IsolatedParticlesGeneratedJets
Definition: IsolatedParticlesGeneratedJets.cc:49
Service.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
GenParticleFwd.h
IsolatedParticlesGeneratedJets::t_gjetPhi
std::vector< double > * t_gjetPhi
Definition: IsolatedParticlesGeneratedJets.cc:71
IsolatedParticlesGeneratedJets::IsolatedParticlesGeneratedJets
IsolatedParticlesGeneratedJets(const edm::ParameterSet &)
Definition: IsolatedParticlesGeneratedJets.cc:80
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TFileService.h
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
edm::ParameterSet
Definition: ParameterSet.h:47
IsolatedParticlesGeneratedJets::tok_parts_
const edm::EDGetTokenT< reco::GenParticleCollection > tok_parts_
Definition: IsolatedParticlesGeneratedJets.cc:68
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
IsolatedParticlesGeneratedJets::t_jetTrkPhi
std::vector< std::vector< double > > * t_jetTrkPhi
Definition: IsolatedParticlesGeneratedJets.cc:75
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
ttbarCategorization_cff.genJets
genJets
Definition: ttbarCategorization_cff.py:29
generator_cfi.jetMatching
jetMatching
Definition: generator_cfi.py:21
edm::EventSetup
Definition: EventSetup.h:57
JetMatchingTools
Definition: JetMatchingTools.h:28
DDAxes::phi
IsolatedParticlesGeneratedJets::t_gjetPt
std::vector< double > * t_gjetPt
Definition: IsolatedParticlesGeneratedJets.cc:71
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
BTaggingMonitoring_cff.njets
njets
Definition: BTaggingMonitoring_cff.py:10
IsolatedParticlesGeneratedJets::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: IsolatedParticlesGeneratedJets.cc:95
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TFileService::kSharedResource
static const std::string kSharedResource
Definition: TFileService.h:76
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
GenJet.h
IsolatedParticlesGeneratedJets::t_jetTrkCharge
std::vector< std::vector< double > > * t_jetTrkCharge
Definition: IsolatedParticlesGeneratedJets.cc:77
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
IsolatedParticlesGeneratedJets::endJob
void endJob() override
Definition: IsolatedParticlesGeneratedJets.cc:59
edm::Event
Definition: Event.h:73
IsolatedParticlesGeneratedJets::t_gjetEta
std::vector< double > * t_gjetEta
Definition: IsolatedParticlesGeneratedJets.cc:71
IsolatedParticlesGeneratedJets::debug_
const bool debug_
Definition: IsolatedParticlesGeneratedJets.cc:64
edm::InputTag
Definition: InputTag.h:15
IsolatedParticlesGeneratedJets::tree_
TTree * tree_
Definition: IsolatedParticlesGeneratedJets.cc:65
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
IsolatedParticlesGeneratedJets::bookHistograms
void bookHistograms()
Definition: IsolatedParticlesGeneratedJets.cc:190
IsolatedParticlesGeneratedJets::t_gjetE
std::vector< double > * t_gjetE
Definition: IsolatedParticlesGeneratedJets.cc:71
IsolatedParticlesGeneratedJets::t_jetTrkEta
std::vector< std::vector< double > > * t_jetTrkEta
Definition: IsolatedParticlesGeneratedJets.cc:74
IsolatedParticlesGeneratedJets::t_gjetN
std::vector< int > * t_gjetN
Definition: IsolatedParticlesGeneratedJets.cc:70