CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
LHETablesProducer Class Reference
Inheritance diagram for LHETablesProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

std::unique_ptr< nanoaod::FlatTablefillLHEObjectTable (const LHEEventProduct &lheProd, nanoaod::FlatTable &out) const
 
 LHETablesProducer (edm::ParameterSet const &params)
 
void produce (edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
 ~LHETablesProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) 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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Attributes

const std::vector< edm::EDGetTokenT< LHEEventProduct > > lheTag_
 
const unsigned int precision_
 
const bool storeLHEParticles_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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 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

Definition at line 15 of file LHETablesProducer.cc.

Constructor & Destructor Documentation

LHETablesProducer::LHETablesProducer ( edm::ParameterSet const &  params)
inline

Definition at line 17 of file LHETablesProducer.cc.

References precision_, storeLHEParticles_, and GlobalPosition_Frontier_DevDB_cff::tag.

17  :
18  lheTag_(edm::vector_transform(params.getParameter<std::vector<edm::InputTag>>("lheInfo"), [this](const edm::InputTag & tag) { return mayConsume<LHEEventProduct>(tag); })),
19  precision_( params.getParameter<int>("precision") ),
20  storeLHEParticles_( params.getParameter<bool>("storeLHEParticles") )
21  {
22  produces<nanoaod::FlatTable>("LHE");
24  produces<nanoaod::FlatTable>("LHEPart");
25 
26  }
const unsigned int precision_
const bool storeLHEParticles_
const std::vector< edm::EDGetTokenT< LHEEventProduct > > lheTag_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
LHETablesProducer::~LHETablesProducer ( )
inlineoverride

Definition at line 28 of file LHETablesProducer.cc.

28 {}

Member Function Documentation

static void LHETablesProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 130 of file LHETablesProducer.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::add().

130  {
132  desc.add<std::vector<edm::InputTag>>("lheInfo", std::vector<edm::InputTag>{{"externalLHEProducer"},{"source"}})->setComment("tag(s) for the LHE information (LHEEventProduct)");
133  desc.add<int>("precision", -1)->setComment("precision on the 4-momenta of the LHE particles");
134  desc.add<bool>("storeLHEParticles", false)->setComment("Whether we want to store the 4-momenta of the status 1 particles at LHE level");
135  descriptions.add("lheInfoTable", desc);
136  }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr<nanoaod::FlatTable> LHETablesProducer::fillLHEObjectTable ( const LHEEventProduct lheProd,
nanoaod::FlatTable out 
) const
inline

Definition at line 53 of file LHETablesProducer.cc.

References funct::abs(), nanoaod::FlatTable::addColumnValue(), nanoaod::FlatTable::FloatColumn, LHEEventProduct::hepeup(), mps_fire::i, nanoaod::FlatTable::IntColumn, SiStripPI::max, gen::n, LHEEventProduct::npLO(), LHEEventProduct::npNLO(), p4, precision_, EnergyCorrector::pt, lhef::HEPEUP::PUP, mps_update::status, nanoaod::FlatTable::UInt8Column, and findQualityFiles::v.

Referenced by produce().

53  {
54  double lheHT = 0, lheHTIncoming = 0;
55  unsigned int lheNj = 0, lheNb = 0, lheNc = 0, lheNuds = 0, lheNglu = 0;
56  double lheVpt = 0;
57 
58  const auto & hepeup = lheProd.hepeup();
59  const auto & pup = hepeup.PUP;
60  int lep = -1, lepBar = -1, nu = -1, nuBar = -1;
61  std::vector<float> vals_pt;
62  std::vector<float> vals_eta;
63  std::vector<float> vals_phi;
64  std::vector<float> vals_mass;
65  std::vector<int> vals_pid;
66  for (unsigned int i = 0, n = pup.size(); i < n; ++i) {
67  int status = hepeup.ISTUP[i];
68  int idabs = std::abs(hepeup.IDUP[i]);
69  if (status == 1){
70  TLorentzVector p4(pup[i][0], pup[i][1], pup[i][2], pup[i][3]); // x,y,z,t
71  vals_pt.push_back(p4.Pt());
72  vals_eta.push_back(p4.Eta());
73  vals_phi.push_back(p4.Phi());
74  vals_mass.push_back(p4.M());
75  vals_pid.push_back(hepeup.IDUP[i]);
76  }
77  if ( (status == 1) && ( ( idabs == 21 ) || (idabs > 0 && idabs < 7) ) ) { //# gluons and quarks
78  // object counters
79  lheNj++;
80  if (idabs==5) lheNb++;
81  else if (idabs==4) lheNc++;
82  else if (idabs <= 3 ) lheNuds++;
83  else if (idabs == 21) lheNglu++;
84  // HT
85  double pt = std::hypot( pup[i][0], pup[i][1] ); // first entry is px, second py
86  lheHT += pt;
87  int mothIdx = std::max(hepeup.MOTHUP[i].first-1,0); //first and last mother as pair; first entry has index 1 in LHE; incoming particles return motherindex 0
88  int mothIdxTwo = std::max(hepeup.MOTHUP[i].second-1,0);
89  int mothStatus = hepeup.ISTUP[mothIdx];
90  int mothStatusTwo = hepeup.ISTUP[mothIdxTwo];
91  bool hasIncomingAsMother = mothStatus<0 || mothStatusTwo<0;
92  if (hasIncomingAsMother) lheHTIncoming += pt;
93  } else if (idabs == 12 || idabs == 14 || idabs == 16) {
94  (hepeup.IDUP[i] > 0 ? nu : nuBar) = i;
95  } else if (idabs == 11 || idabs == 13 || idabs == 15) {
96  (hepeup.IDUP[i] > 0 ? lep : lepBar) = i;
97  }
98  }
99  std::pair<int,int> v(0,0);
100  if (lep != -1 && lepBar != -1) v = std::make_pair(lep,lepBar);
101  else if (lep != -1 && nuBar != -1) v = std::make_pair(lep, nuBar);
102  else if (nu != -1 && lepBar != -1) v = std::make_pair(nu ,lepBar);
103  else if (nu != -1 && nuBar != -1) v = std::make_pair(nu , nuBar);
104  if (v.first != -1 && v.second != -1) {
105  lheVpt = std::hypot( pup[v.first][0] + pup[v.second][0], pup[v.first][1] + pup[v.second][1] );
106  }
107 
108  out.addColumnValue<uint8_t>("Njets", lheNj, "Number of jets (partons) at LHE step", nanoaod::FlatTable::UInt8Column);
109  out.addColumnValue<uint8_t>("Nb", lheNb, "Number of b partons at LHE step", nanoaod::FlatTable::UInt8Column);
110  out.addColumnValue<uint8_t>("Nc", lheNc, "Number of c partons at LHE step", nanoaod::FlatTable::UInt8Column);
111  out.addColumnValue<uint8_t>("Nuds", lheNuds, "Number of u,d,s partons at LHE step", nanoaod::FlatTable::UInt8Column);
112  out.addColumnValue<uint8_t>("Nglu", lheNglu, "Number of gluon partons at LHE step", nanoaod::FlatTable::UInt8Column);
113  out.addColumnValue<float>("HT", lheHT, "HT, scalar sum of parton pTs at LHE step", nanoaod::FlatTable::FloatColumn);
114  out.addColumnValue<float>("HTIncoming", lheHTIncoming, "HT, scalar sum of parton pTs at LHE step, restricted to partons", nanoaod::FlatTable::FloatColumn);
115  out.addColumnValue<float>("Vpt", lheVpt, "pT of the W or Z boson at LHE step", nanoaod::FlatTable::FloatColumn);
116  out.addColumnValue<uint8_t>("NpNLO", lheProd.npNLO(), "number of partons at NLO", nanoaod::FlatTable::UInt8Column);
117  out.addColumnValue<uint8_t>("NpLO", lheProd.npLO(), "number of partons at LO", nanoaod::FlatTable::UInt8Column);
118 
119 
120  auto outPart = std::make_unique<nanoaod::FlatTable>(vals_pt.size(), "LHEPart", false);
121  outPart->addColumn<float>("pt", vals_pt, "Pt of LHE particles", nanoaod::FlatTable::FloatColumn, this->precision_);
122  outPart->addColumn<float>("eta", vals_eta, "Pseodorapidity of LHE particles", nanoaod::FlatTable::FloatColumn, this->precision_);
123  outPart->addColumn<float>("phi", vals_phi, "Phi of LHE particles", nanoaod::FlatTable::FloatColumn, this->precision_);
124  outPart->addColumn<float>("mass", vals_mass, "Mass of LHE particles", nanoaod::FlatTable::FloatColumn, this->precision_);
125  outPart->addColumn<int> ("pdgId", vals_pid, "PDG ID of LHE particles", nanoaod::FlatTable::IntColumn);
126 
127  return outPart;
128  }
const lhef::HEPEUP & hepeup() const
const unsigned int precision_
double p4[4]
Definition: TauolaWrapper.h:92
std::vector< FiveVector > PUP
Definition: LesHouches.h:261
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void addColumnValue(const std::string &name, const C &value, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
Definition: FlatTable.h:101
int npLO() const
int npNLO() const
void LHETablesProducer::produce ( edm::StreamID  id,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
inlineoverride

Definition at line 30 of file LHETablesProducer.cc.

References fillLHEObjectTable(), edm::Event::getByToken(), nano_cff::lheInfo, lheTag_, eostools::move(), edm::Event::put(), and storeLHEParticles_.

30  {
31  auto lheTab = std::make_unique<nanoaod::FlatTable>(1, "LHE", true);
32 
34  for (const auto & lheTag: lheTag_) {
35  iEvent.getByToken(lheTag, lheInfo);
36  if (lheInfo.isValid()) {
37  break;
38  }
39  }
40  if (lheInfo.isValid()) {
41  auto lhePartTab = fillLHEObjectTable(*lheInfo, *lheTab);
42  if (storeLHEParticles_) iEvent.put(std::move(lhePartTab), "LHEPart");
43  } else {
44  if (storeLHEParticles_) { // need to store a dummy table anyway to make the framework happy
45  auto lhePartTab = std::make_unique<nanoaod::FlatTable>(1, "LHEPart", true);
46  iEvent.put(std::move(lhePartTab), "LHEPart");
47  }
48  }
49  iEvent.put(std::move(lheTab), "LHE");
50 
51  }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::unique_ptr< nanoaod::FlatTable > fillLHEObjectTable(const LHEEventProduct &lheProd, nanoaod::FlatTable &out) const
const bool storeLHEParticles_
const std::vector< edm::EDGetTokenT< LHEEventProduct > > lheTag_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

const std::vector<edm::EDGetTokenT<LHEEventProduct> > LHETablesProducer::lheTag_
protected

Definition at line 139 of file LHETablesProducer.cc.

Referenced by produce().

const unsigned int LHETablesProducer::precision_
protected

Definition at line 140 of file LHETablesProducer.cc.

Referenced by fillLHEObjectTable(), and LHETablesProducer().

const bool LHETablesProducer::storeLHEParticles_
protected

Definition at line 141 of file LHETablesProducer.cc.

Referenced by LHETablesProducer(), and produce().