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 final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
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)) {
70  stvc.constrain(ttkb->build(muon.muonBestTrack()), *beamSpotHandle);
71  if (std::get<0>(btft)) {
72  const reco::Track& trkBS = std::get<1>(btft).track();
73  pts.push_back(trkBS.pt());
74  ptErrs.push_back(trkBS.ptError());
75  chi2s.push_back(std::get<2>(btft));
76  tbd = false;
77  }
78  }
79  }
80 
81  if (tbd) {
82  // Invalid BS; use PV instead
84  event.getByToken(PrimaryVertexToken_, pvHandle);
85 
86  if (pvHandle.isValid() && !pvHandle->empty()) {
87  auto pv = pvHandle->at(0);
89 
90  try {
91  SingleTrackVertexConstraint::BTFtuple btft = stvc.constrain(ttkb->build(muon.muonBestTrack()), pvs);
92  if (std::get<0>(btft)) {
93  const reco::Track& trkBS = std::get<1>(btft).track();
94  pts.push_back(trkBS.pt());
95  ptErrs.push_back(trkBS.ptError());
96  chi2s.push_back(std::get<2>(btft));
97  tbd = false;
98  }
99  } catch (const VertexException& exc) {
100  // Update failed; give up.
101  }
102  }
103  }
104 
105  if (tbd) {
106  // Fall-back case, keep the unconstrained values
107  pts.push_back(muon.pt());
108  ptErrs.push_back(muon.bestTrack()->ptError());
109  chi2s.push_back(-1.f);
110  }
111  }
112 
113  {
114  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
116  filler.insert(muons, pts.begin(), pts.end());
117  filler.fill();
118  event.put(std::move(valueMap), "muonBSConstrainedPt");
119  }
120 
121  {
122  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
124  filler.insert(muons, ptErrs.begin(), ptErrs.end());
125  filler.fill();
126  event.put(std::move(valueMap), "muonBSConstrainedPtErr");
127  }
128 
129  {
130  std::unique_ptr<edm::ValueMap<float>> valueMap(new edm::ValueMap<float>());
132  filler.insert(muons, chi2s.begin(), chi2s.end());
133  filler.fill();
134  event.put(std::move(valueMap), "muonBSConstrainedChi2");
135  }
136  }
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 139 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ muonToken_

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

Definition at line 138 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ PrimaryVertexToken_

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

Definition at line 140 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ stvc

SingleTrackVertexConstraint MuonBeamspotConstraintValueMapProducer::stvc
private

Definition at line 142 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().

◆ ttbToken_

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

Definition at line 141 of file MuonBeamspotConstraintValueMapProducer.cc.

Referenced by produce().