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 
51 public:
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  void beginJob() override;
59  void analyze(const edm::Event&, const edm::EventSetup&) override;
60  void endJob() override { }
61 
62  void bookHistograms();
63  void clearTreeVectors();
64 
65  const bool debug_;
66  TTree *tree_;
67 
70 
71  std::vector<int> *t_gjetN;
72  std::vector<double> *t_gjetE, *t_gjetPt, *t_gjetEta, *t_gjetPhi;
73  std::vector< std::vector<double> > *t_jetTrkP;
74  std::vector< std::vector<double> > *t_jetTrkPt;
75  std::vector< std::vector<double> > *t_jetTrkEta;
76  std::vector< std::vector<double> > *t_jetTrkPhi;
77  std::vector< std::vector<double> > *t_jetTrkPdg;
78  std::vector< std::vector<double> > *t_jetTrkCharge;
79 
80 };
81 
83  debug_(iConfig.getUntrackedParameter<bool>("Debug",false)),
84  tok_jets_(consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("JetSource"))),
85  tok_parts_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("ParticleSource"))) {
86 
87  usesResource(TFileService::kSharedResource);
88 
89 }
90 
93  desc.addUntracked<bool>("Debug",true);
94  desc.add<edm::InputTag>("JetSource",edm::InputTag("ak5GenJets"));
95  desc.add<edm::InputTag>("ParticleSource",edm::InputTag("genParticles"));
96  descriptions.add("isolatedParticlesGeneratedJets",desc);
97 }
98 
100 
101  //using namespace edm;
103 
104  //=== genJet information
106  iEvent.getByToken(tok_jets_, genJets);
107 
108  //=== genJet information
110  iEvent.getByToken(tok_parts_, genParticles);
111 
112  JetMatchingTools jetMatching (iEvent, consumesCollector());
113  std::vector <std::vector <const reco::GenParticle*> > genJetConstituents (genJets->size());
114 
115  int njets = 0;
116  for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
117  const reco::GenJet& genJet = (*genJets)[iGenJet];
118 
119  double genJetE = genJet.energy();
120  double genJetPt = genJet.pt();
121  double genJetEta = genJet.eta();
122  double genJetPhi = genJet.phi();
123 
124  if( genJetPt> 30.0 && std::abs(genJetEta)<3.0 ) {
125 
126  njets++;
127 
128  std::vector <const reco::GenParticle*> genJetConstituents = jetMatching.getGenParticles ((*genJets) [iGenJet]);
129  std::vector<double> v_trkP, v_trkPt, v_trkEta, v_trkPhi, v_trkPdg, v_trkCharge;
130 
131  if (debug_)
132  edm::LogVerbatim("IsoTrack") << "Jet(pt,Eta,Phi) " << genJetPt << " "
133  << genJetEta << " " << genJetPhi;
134  for(unsigned int ic=0; ic<genJetConstituents.size(); ic++) {
135 
136  if (debug_)
137  edm::LogVerbatim("IsoTrack") << "p,pt,eta,phi "
138  << genJetConstituents[ic]->p() << " "
139  << genJetConstituents[ic]->pt() << " "
140  << genJetConstituents[ic]->eta() << " "
141  << genJetConstituents[ic]->phi();
142 
143  v_trkP.push_back(genJetConstituents[ic]->p());
144  v_trkPt.push_back(genJetConstituents[ic]->pt());
145  v_trkEta.push_back(genJetConstituents[ic]->eta());
146  v_trkPhi.push_back(genJetConstituents[ic]->phi());
147  v_trkPdg.push_back(genJetConstituents[ic]->pdgId());
148  v_trkCharge.push_back(genJetConstituents[ic]->charge());
149 
150  } //loop over genjet constituents
151 
152  t_gjetE ->push_back(genJetE );
153  t_gjetPt ->push_back(genJetPt );
154  t_gjetEta ->push_back(genJetEta);
155  t_gjetPhi ->push_back(genJetPhi);
156 
157  t_jetTrkP ->push_back(v_trkP );
158  t_jetTrkPt ->push_back(v_trkPt );
159  t_jetTrkEta ->push_back(v_trkEta);
160  t_jetTrkPhi ->push_back(v_trkPhi);
161  t_jetTrkPdg ->push_back(v_trkPdg);
162  t_jetTrkCharge ->push_back(v_trkCharge);
163 
164  } // if jetPt>30
165 
166  } //loop over genjets
167 
168  t_gjetN->push_back(njets);
169 
170  if (debug_) {
171  unsigned int indx = 0;
172  reco::GenParticleCollection::const_iterator ig = genParticles->begin();
173  for (; ig!= genParticles->end(); ++ig,++indx) {
174  edm::LogVerbatim("IsoTrack") << "Track " << indx << " Status "
175  << ig->status() << " charge "
176  << ig->charge() << " pdgId " << ig->pdgId()
177  << " mass " << ig->mass() << " P "
178  << ig->momentum() << " E " << ig->energy()
179  << " Origin " << ig->vertex();
180  }
181  }
182 
183  tree_->Fill();
184 }
185 
187 
188  bookHistograms();
189 }
190 
192  t_gjetN ->clear();
193  t_gjetE ->clear();
194  t_gjetPt ->clear();
195  t_gjetEta ->clear();
196  t_gjetPhi ->clear();
197 
198  t_jetTrkP ->clear();
199  t_jetTrkPt ->clear();
200  t_jetTrkEta ->clear();
201  t_jetTrkPhi ->clear();
202  t_jetTrkPdg ->clear();
203  t_jetTrkCharge ->clear();
204 }
205 
207 
209  tree_ = fs->make<TTree>("tree", "tree");
210 
211  t_gjetN = new std::vector<int> ();
212  t_gjetE = new std::vector<double>();
213  t_gjetPt = new std::vector<double>();
214  t_gjetEta = new std::vector<double>();
215  t_gjetPhi = new std::vector<double>();
216 
217  t_jetTrkP = new std::vector<std::vector<double> >();
218  t_jetTrkPt = new std::vector<std::vector<double> >();
219  t_jetTrkEta = new std::vector<std::vector<double> >();
220  t_jetTrkPhi = new std::vector<std::vector<double> >();
221  t_jetTrkPdg = new std::vector<std::vector<double> >();
222  t_jetTrkCharge = new std::vector<std::vector<double> >();
223 
224  tree_->Branch("t_gjetN", "std::vector<int>", &t_gjetN);
225  tree_->Branch("t_gjetE", "std::vector<double>", &t_gjetE);
226  tree_->Branch("t_gjetPt", "std::vector<double>", &t_gjetPt);
227  tree_->Branch("t_gjetEta", "std::vector<double>", &t_gjetEta);
228  tree_->Branch("t_gjetPhi", "std::vector<double>", &t_gjetPhi);
229 
230  tree_->Branch("t_jetTrkP", "std::vector<vector<double> >", &t_jetTrkP);
231  tree_->Branch("t_jetTrkPt", "std::vector<vector<double> >", &t_jetTrkPt);
232  tree_->Branch("t_jetTrkEta", "std::vector<vector<double> >", &t_jetTrkEta);
233  tree_->Branch("t_jetTrkPhi", "std::vector<vector<double> >", &t_jetTrkPhi);
234  tree_->Branch("t_jetTrkPdg", "std::vector<vector<double> >", &t_jetTrkPdg);
235  tree_->Branch("t_jetTrkCharge", "std::vector<vector<double> >", &t_jetTrkCharge);
236 
237 }
238 
239 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< std::vector< double > > * t_jetTrkEta
double eta() const final
momentum pseudorapidity
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< GenJet > GenJetCollection
collection of GenJet objects
double pt() const final
transverse momentum
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< std::vector< double > > * t_jetTrkPdg
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
std::vector< std::vector< double > > * t_jetTrkPhi
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Jets made from MC generator particles.
Definition: GenJet.h:24
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::GenJetCollection > tok_jets_
std::vector< std::vector< double > > * t_jetTrkPt
std::vector< std::vector< double > > * t_jetTrkCharge
const edm::EDGetTokenT< reco::GenParticleCollection > tok_parts_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< const reco::GenParticle * > getGenParticles(const reco::CaloJet &fJet, bool fVerbose=true)
GenParticles for CaloJet.
fixed size matrix
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< std::vector< double > > * t_jetTrkP
double phi() const final
momentum azimuthal angle
IsolatedParticlesGeneratedJets(const edm::ParameterSet &)