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 () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

edm::Service< TFileServicefs_
 
edm::EDGetTokenT< GenEventInfoProductgenInfoToken_
 
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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ESProduct , Transition Tr = Transition::Event>
auto esConsumes (eventsetup::EventSetupRecordKey const &, ESInputTag const &tag)
 
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 56 of file L1GenTreeProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 90 of file L1GenTreeProducer.cc.

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

91 {
92 
93  genJetToken_ = consumes<reco::GenJetCollection>(iConfig.getUntrackedParameter<edm::InputTag>("genJetToken"));
94  genParticleToken_ = consumes<reco::GenParticleCollection>(iConfig.getUntrackedParameter<edm::InputTag>("genParticleToken"));
95  pileupInfoToken_ = consumes<std::vector<PileupSummaryInfo> >(iConfig.getUntrackedParameter<edm::InputTag>("pileupInfoToken"));
96  genInfoToken_ = consumes<GenEventInfoProduct>(iConfig.getParameter<edm::InputTag>("genInfoToken"));
97 
98  l1GenData_ = std::make_unique<L1Analysis::L1AnalysisGeneratorDataFormat>();
99 
100  // set up output
101  tree_=fs_->make<TTree>("L1GenTree", "L1GenTree");
102  tree_->Branch("Generator", "L1Analysis::L1AnalysisGeneratorDataFormat", l1GenData_.get(), 32000, 3);
103 }
T getParameter(std::string const &) const
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::EDGetTokenT< GenEventInfoProduct > genInfoToken_
edm::Service< TFileService > fs_
edm::EDGetTokenT< reco::GenJetCollection > genJetToken_
edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
std::unique_ptr< L1Analysis::L1AnalysisGeneratorDataFormat > l1GenData_
L1GenTreeProducer::~L1GenTreeProducer ( )
override

Definition at line 106 of file L1GenTreeProducer.cc.

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

Member Function Documentation

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

Definition at line 121 of file L1GenTreeProducer.cc.

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

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

Reimplemented from edm::EDAnalyzer.

Definition at line 242 of file L1GenTreeProducer.cc.

243 {
244 }
void L1GenTreeProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 248 of file L1GenTreeProducer.cc.

References DEFINE_FWK_MODULE.

248  {
249 }

Member Data Documentation

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

Definition at line 72 of file L1GenTreeProducer.cc.

Referenced by L1GenTreeProducer().

edm::EDGetTokenT<GenEventInfoProduct> L1GenTreeProducer::genInfoToken_
private

Definition at line 84 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

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

Definition at line 81 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

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

Definition at line 82 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

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

Definition at line 78 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

unsigned L1GenTreeProducer::maxL1Upgrade_
private

Definition at line 69 of file L1GenTreeProducer.cc.

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

Definition at line 83 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().

TTree* L1GenTreeProducer::tree_
private

Definition at line 75 of file L1GenTreeProducer.cc.

Referenced by analyze(), and L1GenTreeProducer().