CMS 3D CMS Logo

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

Public Member Functions

 MuonBeamspotConstraintValueMapProducer (const edm::ParameterSet &config)
 
 ~MuonBeamspotConstraintValueMapProducer () override=default
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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)
 

Private Member Functions

void produce (edm::StreamID streamID, edm::Event &event, const edm::EventSetup &setup) const override
 

Private Attributes

edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
edm::EDGetTokenT< pat::MuonCollectionmuonToken_
 
edm::EDGetTokenT< reco::VertexCollectionPrimaryVertexToken_
 
SingleTrackVertexConstraint stvc
 
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordttbToken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Compute muon pt and ptErr after beamspot constraint.

Definition at line 19 of file MuonBeamspotConstraintValueMapProducer.cc.

Constructor & Destructor Documentation

◆ MuonBeamspotConstraintValueMapProducer()

MuonBeamspotConstraintValueMapProducer::MuonBeamspotConstraintValueMapProducer ( const edm::ParameterSet config)
inlineexplicit

Definition at line 21 of file MuonBeamspotConstraintValueMapProducer.cc.

22  : muonToken_(consumes<pat::MuonCollection>(config.getParameter<edm::InputTag>("src"))),
23  beamSpotToken_(consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("beamspot"))),
24  PrimaryVertexToken_(consumes<reco::VertexCollection>(config.getParameter<edm::InputTag>("vertices"))),
25  ttbToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))) {
26  produces<edm::ValueMap<float>>("muonBSConstrainedPt");
27  produces<edm::ValueMap<float>>("muonBSConstrainedPtErr");
28  produces<edm::ValueMap<float>>("muonBSConstrainedChi2");
29  }
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttbToken_
Definition: config.py:1
edm::EDGetTokenT< reco::VertexCollection > PrimaryVertexToken_

◆ ~MuonBeamspotConstraintValueMapProducer()

MuonBeamspotConstraintValueMapProducer::~MuonBeamspotConstraintValueMapProducer ( )
overridedefault

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 33 of file MuonBeamspotConstraintValueMapProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

33  {
35  desc.add<edm::InputTag>("src", edm::InputTag("muons"))->setComment("Muon collection");
36  desc.add<edm::InputTag>("beamspot", edm::InputTag("offlineBeamSpot"))->setComment("Beam spot collection");
37  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"))
38  ->setComment("Primary vertex collection");
39 
40  descriptions.addWithDefaultLabel(desc);
41  }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ produce()

void MuonBeamspotConstraintValueMapProducer::produce ( edm::StreamID  streamID,
edm::Event event,
const edm::EventSetup setup 
) const
inlineoverrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 44 of file MuonBeamspotConstraintValueMapProducer.cc.

References beamSpotToken_, reco::BeamSpot::BeamWidthX(), reco::BeamSpot::BeamWidthXError(), reco::BeamSpot::BeamWidthY(), reco::BeamSpot::BeamWidthYError(), TransientTrackBuilder::build(), SingleTrackVertexConstraint::constrain(), f, trigObjTnPSource_cfi::filler, edm::HandleBase::isValid(), eostools::move(), DiMuonV_cfg::muons, muonToken_, PrimaryVertexToken_, reco::TrackBase::pt(), reco::TrackBase::ptError(), RPCpg::pts, FSQDQM_cfi::pvs, singleTopDQM_cfi::setup, stvc, HLT_2024v14_cff::track, and ttbToken_.

44  {
46  event.getByToken(muonToken_, muons);
47 
48  edm::Handle<reco::BeamSpot> beamSpotHandle;
49  event.getByToken(beamSpotToken_, beamSpotHandle);
50 
52 
53  std::vector<float> pts, ptErrs, chi2s;
54  pts.reserve(muons->size());
55  ptErrs.reserve(muons->size());
56  chi2s.reserve(muons->size());
57 
58  for (const auto& muon : *muons) {
59  bool tbd = true;
60  if (beamSpotHandle.isValid()) {
61  double BeamWidthX = beamSpotHandle->BeamWidthX();
62  double BeamWidthXError = beamSpotHandle->BeamWidthXError();
63  double BeamWidthY = beamSpotHandle->BeamWidthY();
64  double BeamWidthYError = beamSpotHandle->BeamWidthYError();
65  // Protect for mis-reconstructed beamspots (note that
66  // SingleTrackVertexConstraint uses the width for the constraint,
67  // not the error)
68  if ((BeamWidthXError / BeamWidthX < 0.3) && (BeamWidthYError / BeamWidthY < 0.3)) {
69  try {
71  stvc.constrain(ttkb->build(muon.muonBestTrack()), *beamSpotHandle);
72 
73  if (std::get<0>(btft)) {
74  const reco::Track& trkBS = std::get<1>(btft).track();
75  pts.push_back(trkBS.pt());
76  ptErrs.push_back(trkBS.ptError());
77  chi2s.push_back(std::get<2>(btft));
78  tbd = false;
79  }
80  } catch (const VertexException& exc) {
81  // Update failed; give up.
82  }
83  }
84  }
85 
86  if (tbd) {
87  // Invalid BS; use PV instead
89  event.getByToken(PrimaryVertexToken_, pvHandle);
90 
91  if (pvHandle.isValid() && !pvHandle->empty()) {
92  auto pv = pvHandle->at(0);
94 
95  try {
96  SingleTrackVertexConstraint::BTFtuple btft = stvc.constrain(ttkb->build(muon.muonBestTrack()), pvs);
97  if (std::get<0>(btft)) {
98  const reco::Track& trkBS = std::get<1>(btft).track();
99  pts.push_back(trkBS.pt());
100  ptErrs.push_back(trkBS.ptError());
101  chi2s.push_back(std::get<2>(btft));
102  tbd = false;
103  }
104  } catch (const VertexException& exc) {
105  // Update failed; give up.
106  }
107  }
108  }
109 
110  if (tbd) {
111  // Fall-back case, keep the unconstrained values
112  pts.push_back(muon.pt());
113  ptErrs.push_back(muon.bestTrack()->ptError());
114  chi2s.push_back(-1.f);
115  }
116  }
117 
118  {
119  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
121  filler.insert(muons, pts.begin(), pts.end());
122  filler.fill();
123  event.put(std::move(valueMap), "muonBSConstrainedPt");
124  }
125 
126  {
127  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
129  filler.insert(muons, ptErrs.begin(), ptErrs.end());
130  filler.fill();
131  event.put(std::move(valueMap), "muonBSConstrainedPtErr");
132  }
133 
134  {
135  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
137  filler.insert(muons, chi2s.begin(), chi2s.end());
138  filler.fill();
139  event.put(std::move(valueMap), "muonBSConstrainedChi2");
140  }
141  }
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
double BeamWidthYError() const
error on beam width Y, assume error in X = Y
Definition: BeamSpot.h:101
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
std::tuple< bool, reco::TransientTrack, float > BTFtuple
Common base class.
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
Definition: GlobalError.h:13
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttbToken_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
BTFtuple constrain(const reco::TransientTrack &track, const GlobalPoint &priorPos, const GlobalError &priorError) const
reco::TransientTrack build(const reco::Track *p) const
static const double pts[33]
Definition: Constants.h:30
double pt() const
track transverse momentum
Definition: TrackBase.h:637
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
double f[11][100]
double BeamWidthXError() const
error on beam width X, assume error in X = Y
Definition: BeamSpot.h:99
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< reco::VertexCollection > PrimaryVertexToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ beamSpotToken_

edm::EDGetTokenT<reco::BeamSpot> MuonBeamspotConstraintValueMapProducer::beamSpotToken_
private

Definition at line 144 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ muonToken_

edm::EDGetTokenT<pat::MuonCollection> MuonBeamspotConstraintValueMapProducer::muonToken_
private

Definition at line 143 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ PrimaryVertexToken_

edm::EDGetTokenT<reco::VertexCollection> MuonBeamspotConstraintValueMapProducer::PrimaryVertexToken_
private

Definition at line 145 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ stvc

SingleTrackVertexConstraint MuonBeamspotConstraintValueMapProducer::stvc
private

Definition at line 147 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ ttbToken_

edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> MuonBeamspotConstraintValueMapProducer::ttbToken_
private

Definition at line 146 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().