CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GenTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1TriggerDPG/L1Ntuples
4 // Class: L1GenTreeProducer
5 //
13 //
14 // Original Author:
15 // Created:
16 // $Id: L1GenTreeProducer.cc,v 1.8 2012/08/29 12:44:03 jbrooke Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // framework
31 
32 // input data formats
34 
37 #include "HepMC/GenParticle.h"
38 #include "HepMC/GenVertex.h"
40 
42 
43 
44 // ROOT output stuff
47 #include "TTree.h"
48 
50 
51 //
52 // class declaration
53 //
54 
56 public:
57  explicit L1GenTreeProducer(const edm::ParameterSet&);
59 
60 
61 private:
62  virtual void beginJob(void) ;
63  virtual void analyze(const edm::Event&, const edm::EventSetup&);
64  virtual void endJob();
65 
66 private:
67 
68  unsigned maxL1Upgrade_;
69 
70  // output file
72 
73  // tree
74  TTree * tree_;
75 
76  // data format
78 
79  // EDM input tags
83 
84 };
85 
86 
87 
89 {
90 
91  genJetToken_ = consumes<reco::GenJetCollection>(iConfig.getUntrackedParameter<edm::InputTag>("genJetToken"));
92  genParticleToken_ = consumes<reco::GenParticleCollection>(iConfig.getUntrackedParameter<edm::InputTag>("genParticleToken"));
93  pileupInfoToken_ = consumes<std::vector<PileupSummaryInfo> >(iConfig.getUntrackedParameter<edm::InputTag>("pileupInfoToken"));
94 
95  // set up output
96  tree_=fs_->make<TTree>("L1GenTree", "L1GenTree");
97  tree_->Branch("Generator", "L1Analysis::L1AnalysisGeneratorDataFormat", &l1GenData_, 32000, 3);
98 
99 }
100 
101 
103 {
104 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 
108 }
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called to for each event ------------
116 void
118 {
119 
120  l1GenData_->Reset();
121 
123  iEvent.getByToken(genJetToken_, genJets);
124 
125 
126  if (genJets.isValid()){
127 
128  reco::GenJetCollection::const_iterator jetItr = genJets->begin();
129  reco::GenJetCollection::const_iterator jetEnd = genJets->end();
130  for( ; jetItr != jetEnd ; ++jetItr) {
131  l1GenData_->jetPt.push_back( jetItr->pt() );
132  l1GenData_->jetEta.push_back( jetItr->eta() );
133  l1GenData_->jetPhi.push_back( jetItr->phi() );
134  l1GenData_->nJet++;
135  }
136 
137  } else {
138  edm::LogWarning("MissingProduct") << "Gen jets not found. Branch will not be filled" << std::endl;
139  }
140 
142  iEvent.getByToken(genParticleToken_, genParticles);
143 
144  for(size_t i = 0; i < genParticles->size(); ++ i) {
145  const reco::GenParticle & p = (*genParticles)[i];
146  int id = p.pdgId();
147  //int st = p.status();
148  if (abs(id) == 13) {
149  unsigned int nMo=p.numberOfMothers();
150  //std::cout << "id " << id << "; st " << st
151  //<< "; nMo " << nMo << std::endl;
152  for(unsigned int i=0;i<nMo;++i){
153  //int thisParentID = dynamic_cast<const reco::GenParticle*>(p.mother(i))->pdgId();
154  //std::cout << " mother ID " << thisParentID << std::endl;
155  }
156  }
157 
158  //
159  // See if the parent was interesting
160  int parentID = -10000;
161  unsigned int nMo=p.numberOfMothers();
162  for(unsigned int i=0;i<nMo;++i){
163  int thisParentID = dynamic_cast
164  <const reco::GenParticle*>(p.mother(i))->pdgId();
165  //
166  // Is this a bottom hadron?
167  int hundredsIndex = abs(thisParentID)/100;
168  int thousandsIndex = abs(thisParentID)/1000;
169  if ( ((abs(thisParentID) >= 23) &&
170  (abs(thisParentID) <= 25)) ||
171  (abs(thisParentID) == 6) ||
172  (hundredsIndex == 5) ||
173  (hundredsIndex == 4) ||
174  (thousandsIndex == 5) ||
175  (thousandsIndex == 4)
176  )
177  parentID = thisParentID;
178  }
179  if ((parentID == -10000) && (nMo > 0))
180  parentID = dynamic_cast
181  <const reco::GenParticle*>(p.mother(0))->pdgId();
182  //
183  // If the parent of this particle is interesting, store all of the info
184  if ((parentID != p.pdgId()) &&
185  ((parentID > -9999)
186  || (abs(id) == 11)
187  || (abs(id) == 13)
188  || (abs(id) == 23)
189  || (abs(id) == 24)
190  || (abs(id) == 25)
191  || (abs(id) == 4)
192  || (abs(id) == 5)
193  || (abs(id) == 6))
194  )
195  {
196  l1GenData_->partId.push_back(p.pdgId());
197  l1GenData_->partStat.push_back(p.status());
198  l1GenData_->partPt.push_back(p.pt());
199  l1GenData_->partEta.push_back(p.eta());
200  l1GenData_->partPhi.push_back(p.phi());
201  l1GenData_->partE.push_back(p.energy());
202  l1GenData_->partParent.push_back(parentID);
203  }
204  }
205 
206 
208  iEvent.getByToken(pileupInfoToken_, puInfoCollection);
209 
210  if (!puInfoCollection.isValid()) {
211  throw cms::Exception("ProductNotValid") << "pileupInfoSource not valid";
212  }
213 
214  // Loop over vector, find in-time entry, then store the relevant info
215  std::vector<PileupSummaryInfo>::const_iterator puItr = puInfoCollection->begin();
216  std::vector<PileupSummaryInfo>::const_iterator puEnd = puInfoCollection->end();
217  for( ; puItr != puEnd; ++puItr) {
218  int bx = puItr->getBunchCrossing();
219  if (bx == 0) {
220  l1GenData_->nPUPoissonMean = puItr->getTrueNumInteractions();
221  l1GenData_->nVtx = puItr->getPU_NumInteractions();
222  break;
223  }
224  }
225 
226 
227 
228  tree_->Fill();
229 
230 }
231 
232 // ------------ method called once each job just before starting event loop ------------
233 void
235 {
236 }
237 
238 // ------------ method called once each job just after ending the event loop ------------
239 void
241 }
242 
243 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual double energy() const final
energy
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual double phi() const final
momentum azimuthal angle
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual int status() const final
status word
edm::Service< TFileService > fs_
int iEvent
Definition: GenABIO.cc:230
virtual size_t numberOfMothers() const
number of mothers
edm::EDGetTokenT< reco::GenJetCollection > genJetToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual void endJob()
bool isValid() const
Definition: HandleBase.h:75
L1GenTreeProducer(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
virtual int pdgId() const final
PDG identifier.
virtual double eta() const final
momentum pseudorapidity
virtual void beginJob(void)
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
L1Analysis::L1AnalysisGeneratorDataFormat * l1GenData_
virtual double pt() const final
transverse momentum