CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
L1GenTreeProducer Class Reference

#include <L1TriggerDPG/L1Ntuples/src/L1GenTreeProducer.cc>

Inheritance diagram for L1GenTreeProducer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 L1GenTreeProducer (const edm::ParameterSet &)
 
 ~L1GenTreeProducer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob (void)
 
virtual void endJob ()
 

Private Attributes

edm::Service< TFileServicefs_
 
edm::EDGetTokenT< reco::GenJetCollectiongenJetToken_
 
edm::EDGetTokenT< reco::GenParticleCollectiongenParticleToken_
 
std::unique_ptr< L1Analysis::L1AnalysisGeneratorDataFormatl1GenData_
 
unsigned maxL1Upgrade_
 
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
 
TTree * tree_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Produce L1 Extra tree

Implementation:

Definition at line 55 of file L1GenTreeProducer.cc.

Constructor & Destructor Documentation

L1GenTreeProducer::L1GenTreeProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 88 of file L1GenTreeProducer.cc.

References fs_, genJetToken_, genParticleToken_, edm::ParameterSet::getUntrackedParameter(), l1GenData_, TFileService::make(), pileupInfoToken_, and tree_.

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  l1GenData_ = std::make_unique<L1Analysis::L1AnalysisGeneratorDataFormat>();
96 
97  // set up output
98  tree_=fs_->make<TTree>("L1GenTree", "L1GenTree");
99  tree_->Branch("Generator", "L1Analysis::L1AnalysisGeneratorDataFormat", l1GenData_.get(), 32000, 3);
100 }
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::Service< TFileService > fs_
edm::EDGetTokenT< reco::GenJetCollection > genJetToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
std::unique_ptr< L1Analysis::L1AnalysisGeneratorDataFormat > l1GenData_
L1GenTreeProducer::~L1GenTreeProducer ( )

Definition at line 103 of file L1GenTreeProducer.cc.

104 {
105 
106  // do anything here that needs to be done at desctruction time
107  // (e.g. close files, deallocate resources etc.)
108 
109 }

Member Function Documentation

void L1GenTreeProducer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Definition at line 118 of file L1GenTreeProducer.cc.

References funct::abs(), reco::LeafCandidate::charge(), reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), Exception, patPFMETCorrections_cff::genJets, genJetToken_, GenHFHadronMatcher_cfi::genParticles, genParticleToken_, edm::Event::getByToken(), mps_fire::i, edm::HandleBase::isValid(), l1GenData_, reco::CompositeRefCandidateT< D >::mother(), nPart(), reco::CompositeRefCandidateT< D >::numberOfMothers(), AlCaHLTBitMon_ParallelJobs::p, cosmictrackingParticleSelector_cfi::pdgId, reco::LeafCandidate::pdgId(), reco::LeafCandidate::phi(), pileupInfoToken_, reco::LeafCandidate::pt(), reco::LeafCandidate::status(), and tree_.

119 {
120 
121  l1GenData_->Reset();
122 
124  iEvent.getByToken(genJetToken_, genJets);
125 
126 
127  if (genJets.isValid()){
128 
129  reco::GenJetCollection::const_iterator jetItr = genJets->begin();
130  reco::GenJetCollection::const_iterator jetEnd = genJets->end();
131  for( ; jetItr != jetEnd ; ++jetItr) {
132  l1GenData_->jetPt.push_back( jetItr->pt() );
133  l1GenData_->jetEta.push_back( jetItr->eta() );
134  l1GenData_->jetPhi.push_back( jetItr->phi() );
135  l1GenData_->nJet++;
136  }
137 
138  } else {
139  edm::LogWarning("MissingProduct") << "Gen jets not found. Branch will not be filled" << std::endl;
140  }
141 
143  iEvent.getByToken(genParticleToken_, genParticles);
144 
145  if (genParticles.isValid()) {
146 
147  int nPart {0};
148 
149  for(size_t i = 0; i < genParticles->size(); ++ i) {
150  const reco::GenParticle & p = (*genParticles)[i];
151  int id = p.pdgId();
152 
153  // See if the parent was interesting
154  int parentID = -10000;
155  unsigned int nMo=p.numberOfMothers();
156  for(unsigned int i=0;i<nMo;++i){
157  int thisParentID = dynamic_cast
158  <const reco::GenParticle*>(p.mother(i))->pdgId();
159  //
160  // Is this a bottom hadron?
161  int hundredsIndex = abs(thisParentID)/100;
162  int thousandsIndex = abs(thisParentID)/1000;
163  if ( ((abs(thisParentID) >= 23) &&
164  (abs(thisParentID) <= 25)) ||
165  (abs(thisParentID) == 6) ||
166  (hundredsIndex == 5) ||
167  (hundredsIndex == 4) ||
168  (thousandsIndex == 5) ||
169  (thousandsIndex == 4)
170  )
171  parentID = thisParentID;
172  }
173  if ((parentID == -10000) && (nMo > 0))
174  parentID = dynamic_cast
175  <const reco::GenParticle*>(p.mother(0))->pdgId();
176  //
177  // If the parent of this particle is interesting, store all of the info
178  if ((parentID != p.pdgId()) &&
179  ((parentID > -9999)
180  || (abs(id) == 11)
181  || (abs(id) == 13)
182  || (abs(id) == 23)
183  || (abs(id) == 24)
184  || (abs(id) == 25)
185  || (abs(id) == 4)
186  || (abs(id) == 5)
187  || (abs(id) == 6))
188  )
189  {
190  l1GenData_->partId.push_back(p.pdgId());
191  l1GenData_->partStat.push_back(p.status());
192  l1GenData_->partPt.push_back(p.pt());
193  l1GenData_->partEta.push_back(p.eta());
194  l1GenData_->partPhi.push_back(p.phi());
195  l1GenData_->partE.push_back(p.energy());
196  l1GenData_->partParent.push_back(parentID);
197  l1GenData_->partCh.push_back(p.charge());
198  ++nPart;
199  }
200  }
201  l1GenData_->nPart = nPart;
202  }
203 
204 
206  iEvent.getByToken(pileupInfoToken_, puInfoCollection);
207 
208  if (!puInfoCollection.isValid()) {
209  throw cms::Exception("ProductNotValid") << "pileupInfoSource not valid";
210  }
211 
212  // Loop over vector, find in-time entry, then store the relevant info
213  std::vector<PileupSummaryInfo>::const_iterator puItr = puInfoCollection->begin();
214  std::vector<PileupSummaryInfo>::const_iterator puEnd = puInfoCollection->end();
215  for( ; puItr != puEnd; ++puItr) {
216  int bx = puItr->getBunchCrossing();
217  if (bx == 0) {
218  l1GenData_->nMeanPU = puItr->getTrueNumInteractions();
219  l1GenData_->nVtx = puItr->getPU_NumInteractions();
220  break;
221  }
222  }
223 
224 
225 
226  tree_->Fill();
227 
228 }
virtual double pt() const final
transverse momentum
virtual double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileupInfoToken_
virtual int status() const final
status word
virtual double phi() const final
momentum azimuthal angle
virtual int charge() const final
electric charge
Definition: LeafCandidate.h:91
virtual size_t numberOfMothers() const
number of mothers
edm::EDGetTokenT< reco::GenJetCollection > genJetToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
virtual int pdgId() const final
PDG identifier.
virtual double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:74
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
std::unique_ptr< L1Analysis::L1AnalysisGeneratorDataFormat > l1GenData_
virtual const Candidate * mother(size_type=0) const
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
void L1GenTreeProducer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 232 of file L1GenTreeProducer.cc.

233 {
234 }
void L1GenTreeProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 238 of file L1GenTreeProducer.cc.

References DEFINE_FWK_MODULE.

238  {
239 }

Member Data Documentation

edm::Service<TFileService> L1GenTreeProducer::fs_
private

Definition at line 71 of file L1GenTreeProducer.cc.

Referenced by L1GenTreeProducer().

edm::EDGetTokenT<reco::GenJetCollection> L1GenTreeProducer::genJetToken_
private

Definition at line 80 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

edm::EDGetTokenT<reco::GenParticleCollection> L1GenTreeProducer::genParticleToken_
private

Definition at line 81 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

std::unique_ptr<L1Analysis::L1AnalysisGeneratorDataFormat> L1GenTreeProducer::l1GenData_
private

Definition at line 77 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

unsigned L1GenTreeProducer::maxL1Upgrade_
private

Definition at line 68 of file L1GenTreeProducer.cc.

edm::EDGetTokenT<std::vector<PileupSummaryInfo> > L1GenTreeProducer::pileupInfoToken_
private

Definition at line 82 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

TTree* L1GenTreeProducer::tree_
private

Definition at line 74 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().