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
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< std::vector< double > > * t_jetTrkEta
double pt() const final
transverse momentum
std::vector< GenJet > GenJetCollection
collection of GenJet objects
std::vector< std::vector< double > > * t_jetTrkCharge
int iEvent
Definition: GenABIO.cc:224
std::vector< std::vector< double > > * t_jetTrkPdg
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< std::vector< double > > * t_jetTrkPhi
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Jets made from MC generator particles.
Definition: GenJet.h:23
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< reco::GenJetCollection > tok_jets_
std::vector< std::vector< double > > * t_jetTrkP
const edm::EDGetTokenT< reco::GenParticleCollection > tok_parts_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::vector< double > > * t_jetTrkPt
double phi() const final
momentum azimuthal angle
IsolatedParticlesGeneratedJets(const edm::ParameterSet &)
double energy() const final
energy
double eta() const final
momentum pseudorapidity