CMS 3D CMS Logo

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

#include <Onia2MuMuPAT.h>

Inheritance diagram for Onia2MuMuPAT:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 Onia2MuMuPAT (const edm::ParameterSet &)
 
 ~Onia2MuMuPAT () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () 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)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
std::pair< int, float > findJpsiMCInfo (reco::GenParticleRef genJpsi)
 
bool isAbHadron (int pdgID)
 
bool isAMixedbHadron (int pdgID, int momPdgID)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

bool addCommonVertex_
 
bool addMCTruth_
 
bool addMuonlessPrimaryVertex_
 
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
 
StringCutObjectSelector< pat::MuonhigherPuritySelection_
 
StringCutObjectSelector< pat::MuonlowerPuritySelection_
 
InvariantMassFromVertex massCalculator
 
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
 
bool resolveAmbiguity_
 
edm::EDGetTokenT< reco::BeamSpotrevtxbs_
 
edm::EDGetTokenT< reco::TrackCollectionrevtxtrks_
 
edm::EDGetTokenT< reco::BeamSpotthebeamspot_
 
edm::EDGetTokenT< reco::VertexCollectionthePVs_
 
GreaterByVProb< pat::CompositeCandidatevPComparator_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer 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
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- 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 33 of file Onia2MuMuPAT.h.

Constructor & Destructor Documentation

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

Definition at line 29 of file Onia2MuMuPAT.cc.

References HLT_2018_cff::InputTag, revtxbs_, and revtxtrks_.

31  thebeamspot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotTag"))),
32  thePVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexTag"))),
33  higherPuritySelection_(iConfig.getParameter<std::string>("higherPuritySelection")),
34  lowerPuritySelection_(iConfig.getParameter<std::string>("lowerPuritySelection")),
36  iConfig.existsAs<std::string>("dimuonSelection") ? iConfig.getParameter<std::string>("dimuonSelection") : ""),
37  addCommonVertex_(iConfig.getParameter<bool>("addCommonVertex")),
38  addMuonlessPrimaryVertex_(iConfig.getParameter<bool>("addMuonlessPrimaryVertex")),
39  resolveAmbiguity_(iConfig.getParameter<bool>("resolvePileUpAmbiguity")),
40  addMCTruth_(iConfig.getParameter<bool>("addMCTruth")) {
41  revtxtrks_ = consumes<reco::TrackCollection>(
42  (edm::InputTag) "generalTracks"); //if that is not true, we will raise an exception
43  revtxbs_ = consumes<reco::BeamSpot>((edm::InputTag) "offlineBeamSpot");
44  produces<pat::CompositeCandidateCollection>();
45 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
bool addCommonVertex_
Definition: Onia2MuMuPAT.h:56
StringCutObjectSelector< pat::Muon > higherPuritySelection_
Definition: Onia2MuMuPAT.h:53
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::BeamSpot > revtxbs_
Definition: Onia2MuMuPAT.h:52
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
Definition: Onia2MuMuPAT.h:55
edm::EDGetTokenT< reco::TrackCollection > revtxtrks_
Definition: Onia2MuMuPAT.h:51
bool addMuonlessPrimaryVertex_
Definition: Onia2MuMuPAT.h:56
bool resolveAmbiguity_
Definition: Onia2MuMuPAT.h:57
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
Definition: Onia2MuMuPAT.h:54
bool addMCTruth_
Definition: Onia2MuMuPAT.h:58
edm::EDGetTokenT< reco::BeamSpot > thebeamspot_
Definition: Onia2MuMuPAT.h:49
edm::EDGetTokenT< reco::VertexCollection > thePVs_
Definition: Onia2MuMuPAT.h:50
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
Definition: Onia2MuMuPAT.h:48
Onia2MuMuPAT::~Onia2MuMuPAT ( )
override

Definition at line 47 of file Onia2MuMuPAT.cc.

47  {
48  // do anything here that needs to be done at desctruction time
49  // (e.g. close files, deallocate resources etc.)
50 }

Member Function Documentation

void Onia2MuMuPAT::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 496 of file Onia2MuMuPAT.cc.

496 {}
void Onia2MuMuPAT::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 499 of file Onia2MuMuPAT.cc.

References DEFINE_FWK_MODULE.

499 {}
std::pair< int, float > Onia2MuMuPAT::findJpsiMCInfo ( reco::GenParticleRef  genJpsi)
private

Definition at line 439 of file Onia2MuMuPAT.cc.

References isAbHadron(), isAMixedbHadron(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), and mps_fire::result.

Referenced by produce().

439  {
440  int momJpsiID = 0;
441  float trueLife = -99.;
442 
443  if (genJpsi->numberOfMothers() > 0) {
444  TVector3 trueVtx(0.0, 0.0, 0.0);
445  TVector3 trueP(0.0, 0.0, 0.0);
446  TVector3 trueVtxMom(0.0, 0.0, 0.0);
447 
448  trueVtx.SetXYZ(genJpsi->vertex().x(), genJpsi->vertex().y(), genJpsi->vertex().z());
449  trueP.SetXYZ(genJpsi->momentum().x(), genJpsi->momentum().y(), genJpsi->momentum().z());
450 
451  bool aBhadron = false;
452  reco::GenParticleRef Jpsimom = genJpsi->motherRef(); // find mothers
453  if (Jpsimom.isNull()) {
454  std::pair<int, float> result = std::make_pair(momJpsiID, trueLife);
455  return result;
456  } else {
457  reco::GenParticleRef Jpsigrandmom = Jpsimom->motherRef();
458  if (isAbHadron(Jpsimom->pdgId())) {
459  if (Jpsigrandmom.isNonnull() && isAMixedbHadron(Jpsimom->pdgId(), Jpsigrandmom->pdgId())) {
460  momJpsiID = Jpsigrandmom->pdgId();
461  trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(), Jpsigrandmom->vertex().y(), Jpsigrandmom->vertex().z());
462  } else {
463  momJpsiID = Jpsimom->pdgId();
464  trueVtxMom.SetXYZ(Jpsimom->vertex().x(), Jpsimom->vertex().y(), Jpsimom->vertex().z());
465  }
466  aBhadron = true;
467  } else {
468  if (Jpsigrandmom.isNonnull() && isAbHadron(Jpsigrandmom->pdgId())) {
469  reco::GenParticleRef JpsiGrandgrandmom = Jpsigrandmom->motherRef();
470  if (JpsiGrandgrandmom.isNonnull() && isAMixedbHadron(Jpsigrandmom->pdgId(), JpsiGrandgrandmom->pdgId())) {
471  momJpsiID = JpsiGrandgrandmom->pdgId();
472  trueVtxMom.SetXYZ(
473  JpsiGrandgrandmom->vertex().x(), JpsiGrandgrandmom->vertex().y(), JpsiGrandgrandmom->vertex().z());
474  } else {
475  momJpsiID = Jpsigrandmom->pdgId();
476  trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(), Jpsigrandmom->vertex().y(), Jpsigrandmom->vertex().z());
477  }
478  aBhadron = true;
479  }
480  }
481  if (!aBhadron) {
482  momJpsiID = Jpsimom->pdgId();
483  trueVtxMom.SetXYZ(Jpsimom->vertex().x(), Jpsimom->vertex().y(), Jpsimom->vertex().z());
484  }
485  }
486 
487  TVector3 vdiff = trueVtx - trueVtxMom;
488  //trueLife = vdiff.Perp()*3.09688/trueP.Perp();
489  trueLife = vdiff.Perp() * genJpsi->mass() / trueP.Perp();
490  }
491  std::pair<int, float> result = std::make_pair(momJpsiID, trueLife);
492  return result;
493 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool isAbHadron(int pdgID)
bool isNull() const
Checks for null.
Definition: Ref.h:235
bool isAMixedbHadron(int pdgID, int momPdgID)
bool Onia2MuMuPAT::isAbHadron ( int  pdgID)
private

Definition at line 426 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

426  {
427  if (abs(pdgID) == 511 || abs(pdgID) == 521 || abs(pdgID) == 531 || abs(pdgID) == 5122)
428  return true;
429  return false;
430 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool Onia2MuMuPAT::isAMixedbHadron ( int  pdgID,
int  momPdgID 
)
private

Definition at line 432 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

432  {
433  if ((abs(pdgID) == 511 && abs(momPdgID) == 511 && pdgID * momPdgID < 0) ||
434  (abs(pdgID) == 531 && abs(momPdgID) == 531 && pdgID * momPdgID < 0))
435  return true;
436  return false;
437 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void Onia2MuMuPAT::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

DCA

end DCA

Definition at line 57 of file Onia2MuMuPAT.cc.

References IPTools::absoluteImpactParameter3D(), addCommonVertex_, reco::CompositeCandidate::addDaughter(), addMCTruth_, addMuonlessPrimaryVertex_, pat::PATObject< ObjectType >::addUserData(), pat::PATObject< ObjectType >::addUserFloat(), pat::PATObject< ObjectType >::addUserInt(), align::BeamSpot, TransientTrackBuilder::build(), TwoTrackMinimumDistance::calculate(), ClosestApproachInRPhi::calculate(), gather_cfg::cout, TransientVertex::degreesOfFreedom(), dimuonSelection_, VertexDistanceXY::distance(), ClosestApproachInRPhi::distance(), pat::PATObject< ObjectType >::embedGenParticle(), runTheMatrix::err, Measurement1D::error(), relativeConstraints::error, reco::Vertex::error(), cppFunctionSkipper::exception, findJpsiMCInfo(), edm::EventSetup::get(), edm::Event::getByToken(), reco::Vertex::hasRefittedTracks(), higherPuritySelection_, reco::TrackBase::highPurity, edm::HandleBase::id(), edm::Ref< C, T, F >::id(), reco::Muon::innerTrack(), HLT_2018_cff::InputTag, InvariantMassFromVertex::invariantMass(), edm::Ref< C, T, F >::isNonnull(), edm::HandleBase::isValid(), TrajectoryStateClosestToPoint::isValid(), TransientVertex::isValid(), jpsi, edm::RefToBase< T >::key(), edm::Ref< C, T, F >::key(), lowerPuritySelection_, HLT_2018_cff::magneticField, OniaVtxReProducer::makeVertices(), reco::LeafCandidate::mass(), massCalculator, GlobalErrorBase< T, ErrorWeightType >::matrix(), pfMETCorrectionType0_cfi::minDz, eostools::move(), PDWG_BPHSkim_cff::muons, muons_, MagneticField::nominalValue(), reco::Vertex::originalTrack(), reco::Candidate::pdgId(), TwoTrackMinimumDistance::points(), reco::Vertex::position(), TransientVertex::position(), edm::ESHandle< T >::product(), reco::TrackBase::pt(), reco::TrackBase::ptError(), edm::Event::put(), FSQDQM_cfi::pvs, reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), reco::TrackBase::quality(), reco::Vertex::refittedTracks(), resolveAmbiguity_, revtxbs_, revtxtrks_, reco::LeafCandidate::setCharge(), pat::PATObject< ObjectType >::setGenParticleRef(), reco::LeafCandidate::setP4(), mathSSE::sqrt(), ClosestApproachInRPhi::status(), mps_update::status, thebeamspot_, thePVs_, TrajectoryStateClosestToPoint::theState(), TransientVertex::totalChiSquared(), reco::Muon::track(), HLT_2018_cff::track, reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), reco::Vertex::tracksSize(), reco::Vertex::trackWeight(), groupFilesInBlocks::tt, Measurement1D::value(), HltBtagValidation_cff::Vertex, KalmanVertexFitter::vertex(), vPComparator_, badGlobalMuonTaggersAOD_cff::vtx, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

57  {
58  using namespace edm;
59  using namespace std;
60  using namespace reco;
62 
63  vector<double> muMasses;
64  muMasses.push_back(0.1056583715);
65  muMasses.push_back(0.1056583715);
66 
67  std::unique_ptr<pat::CompositeCandidateCollection> oniaOutput(new pat::CompositeCandidateCollection);
68 
69  Vertex thePrimaryV;
70  Vertex theBeamSpotV;
71 
73  iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
74  const MagneticField *field = magneticField.product();
75 
76  Handle<BeamSpot> theBeamSpot;
77  iEvent.getByToken(thebeamspot_, theBeamSpot);
78  BeamSpot bs = *theBeamSpot;
79  theBeamSpotV = Vertex(bs.position(), bs.covariance3D());
80 
82  iEvent.getByToken(thePVs_, priVtxs);
83  if (priVtxs->begin() != priVtxs->end()) {
84  thePrimaryV = Vertex(*(priVtxs->begin()));
85  } else {
86  thePrimaryV = Vertex(bs.position(), bs.covariance3D());
87  }
88 
90  iEvent.getByToken(muons_, muons);
91 
93  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", theTTBuilder);
94  KalmanVertexFitter vtxFitter(true);
95  TrackCollection muonLess;
96 
97  // JPsi candidates only from muons
98  for (View<pat::Muon>::const_iterator it = muons->begin(), itend = muons->end(); it != itend; ++it) {
99  // both must pass low quality
100  if (!lowerPuritySelection_(*it))
101  continue;
102  for (View<pat::Muon>::const_iterator it2 = it + 1; it2 != itend; ++it2) {
103  // both must pass low quality
104  if (!lowerPuritySelection_(*it2))
105  continue;
106  // one must pass tight quality
107  if (!(higherPuritySelection_(*it) || higherPuritySelection_(*it2)))
108  continue;
109 
111  vector<TransientVertex> pvs;
112 
113  // ---- no explicit order defined ----
114  myCand.addDaughter(*it, "muon1");
115  myCand.addDaughter(*it2, "muon2");
116 
117  // ---- define and set candidate's 4momentum ----
118  LorentzVector jpsi = it->p4() + it2->p4();
119  myCand.setP4(jpsi);
120  myCand.setCharge(it->charge() + it2->charge());
121 
122  // ---- apply the dimuon cut ----
123  if (!dimuonSelection_(myCand))
124  continue;
125 
126  // ---- fit vertex using Tracker tracks (if they have tracks) ----
127  if (it->track().isNonnull() && it2->track().isNonnull()) {
128  //build the dimuon secondary vertex
129  vector<TransientTrack> t_tks;
130  t_tks.push_back(theTTBuilder->build(
131  *it->track())); // pass the reco::Track, not the reco::TrackRef (which can be transient)
132  t_tks.push_back(theTTBuilder->build(*it2->track())); // otherwise the vertex will have transient refs inside.
133  TransientVertex myVertex = vtxFitter.vertex(t_tks);
134 
135  CachingVertex<5> VtxForInvMass = vtxFitter.vertex(t_tks);
136 
137  Measurement1D MassWErr(jpsi.M(), -9999.);
138  if (field->nominalValue() > 0) {
139  MassWErr = massCalculator.invariantMass(VtxForInvMass, muMasses);
140  } else {
141  myVertex = TransientVertex(); // with no arguments it is invalid
142  }
143 
144  myCand.addUserFloat("MassErr", MassWErr.error());
145 
146  if (myVertex.isValid()) {
147  float vChi2 = myVertex.totalChiSquared();
148  float vNDF = myVertex.degreesOfFreedom();
149  float vProb(TMath::Prob(vChi2, (int)vNDF));
150 
151  myCand.addUserFloat("vNChi2", vChi2 / vNDF);
152  myCand.addUserFloat("vProb", vProb);
153 
154  TVector3 vtx;
155  TVector3 pvtx;
156  VertexDistanceXY vdistXY;
157 
158  vtx.SetXYZ(myVertex.position().x(), myVertex.position().y(), 0);
159  TVector3 pperp(jpsi.px(), jpsi.py(), 0);
160  AlgebraicVector3 vpperp(pperp.x(), pperp.y(), 0);
161 
162  if (resolveAmbiguity_) {
163  float minDz = 999999.;
165  bool status = ttmd.calculate(
167  GlobalPoint(myVertex.position().x(), myVertex.position().y(), myVertex.position().z()),
168  GlobalVector(myCand.px(), myCand.py(), myCand.pz()),
169  TrackCharge(0),
170  &(*magneticField)),
171  GlobalTrajectoryParameters(GlobalPoint(bs.position().x(), bs.position().y(), bs.position().z()),
172  GlobalVector(bs.dxdz(), bs.dydz(), 1.),
173  TrackCharge(0),
174  &(*magneticField)));
175  float extrapZ = -9E20;
176  if (status)
177  extrapZ = ttmd.points().first.z();
178 
179  for (VertexCollection::const_iterator itv = priVtxs->begin(), itvend = priVtxs->end(); itv != itvend;
180  ++itv) {
181  float deltaZ = fabs(extrapZ - itv->position().z());
182  if (deltaZ < minDz) {
183  minDz = deltaZ;
184  thePrimaryV = Vertex(*itv);
185  }
186  }
187  }
188 
189  Vertex theOriginalPV = thePrimaryV;
190 
191  muonLess.clear();
192  muonLess.reserve(thePrimaryV.tracksSize());
193  if (addMuonlessPrimaryVertex_ && thePrimaryV.tracksSize() > 2) {
194  // Primary vertex matched to the dimuon, now refit it removing the two muons
195  OniaVtxReProducer revertex(priVtxs, iEvent);
197  iEvent.getByToken(revtxtrks_, pvtracks);
198  if (!pvtracks.isValid()) {
199  std::cout << "pvtracks NOT valid " << std::endl;
200  } else {
201  edm::Handle<reco::BeamSpot> pvbeamspot;
202  iEvent.getByToken(revtxbs_, pvbeamspot);
203  if (pvbeamspot.id() != theBeamSpot.id())
204  edm::LogWarning("Inconsistency")
205  << "The BeamSpot used for PV reco is not the same used in this analyzer.";
206  // I need to go back to the reco::Muon object, as the TrackRef in the pat::Muon can be an embedded ref.
207  const reco::Muon *rmu1 = dynamic_cast<const reco::Muon *>(it->originalObject());
208  const reco::Muon *rmu2 = dynamic_cast<const reco::Muon *>(it2->originalObject());
209  // check that muons are truly from reco::Muons (and not, e.g., from PF Muons)
210  // also check that the tracks really come from the track collection used for the BS
211  if (rmu1 != nullptr && rmu2 != nullptr && rmu1->track().id() == pvtracks.id() &&
212  rmu2->track().id() == pvtracks.id()) {
213  // Save the keys of the tracks in the primary vertex
214  // std::vector<size_t> vertexTracksKeys;
215  // vertexTracksKeys.reserve(thePrimaryV.tracksSize());
216  if (thePrimaryV.hasRefittedTracks()) {
217  // Need to go back to the original tracks before taking the key
218  std::vector<reco::Track>::const_iterator itRefittedTrack = thePrimaryV.refittedTracks().begin();
219  std::vector<reco::Track>::const_iterator refittedTracksEnd = thePrimaryV.refittedTracks().end();
220  for (; itRefittedTrack != refittedTracksEnd; ++itRefittedTrack) {
221  if (thePrimaryV.originalTrack(*itRefittedTrack).key() == rmu1->track().key())
222  continue;
223  if (thePrimaryV.originalTrack(*itRefittedTrack).key() == rmu2->track().key())
224  continue;
225  // vertexTracksKeys.push_back(thePrimaryV.originalTrack(*itRefittedTrack).key());
226  muonLess.push_back(*(thePrimaryV.originalTrack(*itRefittedTrack)));
227  }
228  } else {
229  std::vector<reco::TrackBaseRef>::const_iterator itPVtrack = thePrimaryV.tracks_begin();
230  for (; itPVtrack != thePrimaryV.tracks_end(); ++itPVtrack)
231  if (itPVtrack->isNonnull()) {
232  if (itPVtrack->key() == rmu1->track().key())
233  continue;
234  if (itPVtrack->key() == rmu2->track().key())
235  continue;
236  // vertexTracksKeys.push_back(itPVtrack->key());
237  muonLess.push_back(**itPVtrack);
238  }
239  }
240  if (muonLess.size() > 1 && muonLess.size() < thePrimaryV.tracksSize()) {
241  pvs = revertex.makeVertices(muonLess, *pvbeamspot, iSetup);
242  if (!pvs.empty()) {
243  Vertex muonLessPV = Vertex(pvs.front());
244  thePrimaryV = muonLessPV;
245  }
246  }
247  }
248  }
249  }
250 
251  // count the number of high Purity tracks with pT > 900 MeV attached to the chosen vertex
252  double vertexWeight = -1., sumPTPV = -1.;
253  int countTksOfPV = -1;
254  const reco::Muon *rmu1 = dynamic_cast<const reco::Muon *>(it->originalObject());
255  const reco::Muon *rmu2 = dynamic_cast<const reco::Muon *>(it2->originalObject());
256  try {
257  for (reco::Vertex::trackRef_iterator itVtx = theOriginalPV.tracks_begin();
258  itVtx != theOriginalPV.tracks_end();
259  itVtx++)
260  if (itVtx->isNonnull()) {
261  const reco::Track &track = **itVtx;
263  continue;
264  if (track.pt() < 0.5)
265  continue; //reject all rejects from counting if less than 900 MeV
266  TransientTrack tt = theTTBuilder->build(track);
267  pair<bool, Measurement1D> tkPVdist = IPTools::absoluteImpactParameter3D(tt, thePrimaryV);
268  if (!tkPVdist.first)
269  continue;
270  if (tkPVdist.second.significance() > 3)
271  continue;
272  if (track.ptError() / track.pt() > 0.1)
273  continue;
274  // do not count the two muons
275  if (rmu1 != nullptr && rmu1->innerTrack().key() == itVtx->key())
276  continue;
277  if (rmu2 != nullptr && rmu2->innerTrack().key() == itVtx->key())
278  continue;
279 
280  vertexWeight += theOriginalPV.trackWeight(*itVtx);
281  if (theOriginalPV.trackWeight(*itVtx) > 0.5) {
282  countTksOfPV++;
283  sumPTPV += track.pt();
284  }
285  }
286  } catch (std::exception &err) {
287  std::cout << " muon Selection%G�%@failed " << std::endl;
288  return;
289  }
290 
291  myCand.addUserInt("countTksOfPV", countTksOfPV);
292  myCand.addUserFloat("vertexWeight", (float)vertexWeight);
293  myCand.addUserFloat("sumPTPV", (float)sumPTPV);
294 
296  TrajectoryStateClosestToPoint mu1TS = t_tks[0].impactPointTSCP();
297  TrajectoryStateClosestToPoint mu2TS = t_tks[1].impactPointTSCP();
298  float dca = 1E20;
299  if (mu1TS.isValid() && mu2TS.isValid()) {
301  cApp.calculate(mu1TS.theState(), mu2TS.theState());
302  if (cApp.status())
303  dca = cApp.distance();
304  }
305  myCand.addUserFloat("DCA", dca);
307 
309  myCand.addUserData("muonlessPV", Vertex(thePrimaryV));
310  else
311  myCand.addUserData("PVwithmuons", thePrimaryV);
312 
313  // lifetime using PV
314  pvtx.SetXYZ(thePrimaryV.position().x(), thePrimaryV.position().y(), 0);
315  TVector3 vdiff = vtx - pvtx;
316  double cosAlpha = vdiff.Dot(pperp) / (vdiff.Perp() * pperp.Perp());
317  Measurement1D distXY = vdistXY.distance(Vertex(myVertex), thePrimaryV);
318  //double ctauPV = distXY.value()*cosAlpha*3.09688/pperp.Perp();
319  double ctauPV = distXY.value() * cosAlpha * myCand.mass() / pperp.Perp();
320  GlobalError v1e = (Vertex(myVertex)).error();
321  GlobalError v2e = thePrimaryV.error();
322  AlgebraicSymMatrix33 vXYe = v1e.matrix() + v2e.matrix();
323  //double ctauErrPV = sqrt(vXYe.similarity(vpperp))*3.09688/(pperp.Perp2());
324  double ctauErrPV = sqrt(ROOT::Math::Similarity(vpperp, vXYe)) * myCand.mass() / (pperp.Perp2());
325 
326  myCand.addUserFloat("ppdlPV", ctauPV);
327  myCand.addUserFloat("ppdlErrPV", ctauErrPV);
328  myCand.addUserFloat("cosAlpha", cosAlpha);
329 
330  // lifetime using BS
331  pvtx.SetXYZ(theBeamSpotV.position().x(), theBeamSpotV.position().y(), 0);
332  vdiff = vtx - pvtx;
333  cosAlpha = vdiff.Dot(pperp) / (vdiff.Perp() * pperp.Perp());
334  distXY = vdistXY.distance(Vertex(myVertex), theBeamSpotV);
335  //double ctauBS = distXY.value()*cosAlpha*3.09688/pperp.Perp();
336  double ctauBS = distXY.value() * cosAlpha * myCand.mass() / pperp.Perp();
337  GlobalError v1eB = (Vertex(myVertex)).error();
338  GlobalError v2eB = theBeamSpotV.error();
339  AlgebraicSymMatrix33 vXYeB = v1eB.matrix() + v2eB.matrix();
340  //double ctauErrBS = sqrt(vXYeB.similarity(vpperp))*3.09688/(pperp.Perp2());
341  double ctauErrBS = sqrt(ROOT::Math::Similarity(vpperp, vXYeB)) * myCand.mass() / (pperp.Perp2());
342 
343  myCand.addUserFloat("ppdlBS", ctauBS);
344  myCand.addUserFloat("ppdlErrBS", ctauErrBS);
345 
346  if (addCommonVertex_) {
347  myCand.addUserData("commonVertex", Vertex(myVertex));
348  }
349  } else {
350  myCand.addUserFloat("vNChi2", -1);
351  myCand.addUserFloat("vProb", -1);
352  myCand.addUserFloat("ppdlPV", -100);
353  myCand.addUserFloat("ppdlErrPV", -100);
354  myCand.addUserFloat("cosAlpha", -100);
355  myCand.addUserFloat("ppdlBS", -100);
356  myCand.addUserFloat("ppdlErrBS", -100);
357  myCand.addUserFloat("DCA", -1);
358  if (addCommonVertex_) {
359  myCand.addUserData("commonVertex", Vertex());
360  }
362  myCand.addUserData("muonlessPV", Vertex());
363  } else {
364  myCand.addUserData("PVwithmuons", Vertex());
365  }
366  }
367  }
368 
369  // ---- MC Truth, if enabled ----
370  if (addMCTruth_) {
371  reco::GenParticleRef genMu1 = it->genParticleRef();
372  reco::GenParticleRef genMu2 = it2->genParticleRef();
373  if (genMu1.isNonnull() && genMu2.isNonnull()) {
374  if (genMu1->numberOfMothers() > 0 && genMu2->numberOfMothers() > 0) {
375  reco::GenParticleRef mom1 = genMu1->motherRef();
376  reco::GenParticleRef mom2 = genMu2->motherRef();
377  if (mom1.isNonnull() && (mom1 == mom2)) {
378  myCand.setGenParticleRef(mom1); // set
379  myCand.embedGenParticle(); // and embed
380  std::pair<int, float> MCinfo = findJpsiMCInfo(mom1);
381  myCand.addUserInt("momPDGId", MCinfo.first);
382  myCand.addUserFloat("ppdlTrue", MCinfo.second);
383  } else {
384  myCand.addUserInt("momPDGId", 0);
385  myCand.addUserFloat("ppdlTrue", -99.);
386  }
387  } else {
390  consumes<reco::GenParticleCollection>((edm::InputTag) "genParticles");
391  iEvent.getByToken(genCands_, theGenParticles);
392  if (theGenParticles.isValid()) {
393  for (size_t iGenParticle = 0; iGenParticle < theGenParticles->size(); ++iGenParticle) {
394  const Candidate &genCand = (*theGenParticles)[iGenParticle];
395  if (genCand.pdgId() == 443 || genCand.pdgId() == 100443 || genCand.pdgId() == 553 ||
396  genCand.pdgId() == 100553 || genCand.pdgId() == 200553) {
397  reco::GenParticleRef mom1(theGenParticles, iGenParticle);
398  myCand.setGenParticleRef(mom1);
399  myCand.embedGenParticle();
400  std::pair<int, float> MCinfo = findJpsiMCInfo(mom1);
401  myCand.addUserInt("momPDGId", MCinfo.first);
402  myCand.addUserFloat("ppdlTrue", MCinfo.second);
403  }
404  }
405  } else {
406  myCand.addUserInt("momPDGId", 0);
407  myCand.addUserFloat("ppdlTrue", -99.);
408  }
409  }
410  } else {
411  myCand.addUserInt("momPDGId", 0);
412  myCand.addUserFloat("ppdlTrue", -99.);
413  }
414  }
415 
416  // ---- Push back output ----
417  oniaOutput->push_back(myCand);
418  }
419  }
420 
421  std::sort(oniaOutput->begin(), oniaOutput->end(), vPComparator_);
422 
423  iEvent.put(std::move(oniaOutput));
424 }
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
float distance() const override
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
std::pair< GlobalPoint, GlobalPoint > points() const override
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:112
bool addCommonVertex_
Definition: Onia2MuMuPAT.h:56
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:73
StringCutObjectSelector< pat::Muon > higherPuritySelection_
Definition: Onia2MuMuPAT.h:53
ProductID id() const
Definition: HandleBase.cc:13
virtual TrackRef innerTrack() const
Definition: Muon.h:45
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
TrackBaseRef originalTrack(const Track &refTrack) const
Definition: Vertex.cc:96
const FreeTrajectoryState & theState() const
const AlgebraicSymMatrix33 matrix() const
double px() const final
x coordinate of momentum vector
bool hasRefittedTracks() const
Checks whether refitted tracks are stored.
Definition: Vertex.h:167
float totalChiSquared() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
reco::TransientTrack build(const reco::Track *p) const
std::pair< bool, Measurement1D > absoluteImpactParameter3D(const reco::TransientTrack &transientTrack, const reco::Vertex &vertex)
Definition: IPTools.cc:38
T y() const
Definition: PV3DBase.h:60
std::pair< int, float > findJpsiMCInfo(reco::GenParticleRef genJpsi)
InvariantMassFromVertex massCalculator
Definition: Onia2MuMuPAT.h:61
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:897
key_type key() const
Accessor for product key.
Definition: Ref.h:250
const std::vector< Track > & refittedTracks() const
Returns the container of refitted tracks.
Definition: Vertex.h:182
const Point & position() const
position
Definition: Vertex.h:113
void setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
Definition: PATObject.h:748
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
void setCharge(Charge q) final
set electric charge
double dydz() const
dydz slope
Definition: BeamSpot.h:80
int TrackCharge
Definition: TrackCharge.h:4
bool status() const override
edm::EDGetTokenT< reco::BeamSpot > revtxbs_
Definition: Onia2MuMuPAT.h:52
float degreesOfFreedom() const
double pz() const final
z coordinate of momentum vector
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
size_t key() const
Definition: RefToBase.h:219
void embedGenParticle()
Definition: PATObject.h:773
virtual int pdgId() const =0
PDG identifier.
T sqrt(T t)
Definition: SSEVec.h:19
GlobalPoint position() const
double pt() const
track transverse momentum
Definition: TrackBase.h:602
T z() const
Definition: PV3DBase.h:61
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:696
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
Definition: Onia2MuMuPAT.h:55
edm::EDGetTokenT< reco::TrackCollection > revtxtrks_
Definition: Onia2MuMuPAT.h:51
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:84
bool addMuonlessPrimaryVertex_
Definition: Onia2MuMuPAT.h:56
bool isValid() const
Definition: HandleBase.h:70
void addUserInt(const std::string &label, int32_t data, const bool overwrite=false)
Set user-defined int.
Definition: PATObject.h:934
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
double dxdz() const
dxdz slope
Definition: BeamSpot.h:78
bool resolveAmbiguity_
Definition: Onia2MuMuPAT.h:57
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
Definition: Onia2MuMuPAT.h:54
bool addMCTruth_
Definition: Onia2MuMuPAT.h:58
std::vector< CompositeCandidate > CompositeCandidateCollection
double py() const final
y coordinate of momentum vector
double value() const
Definition: Measurement1D.h:25
Error error() const
return SMatrix
Definition: Vertex.h:149
edm::EDGetTokenT< reco::BeamSpot > thebeamspot_
Definition: Onia2MuMuPAT.h:49
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:531
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
#define jpsi
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
T get() const
Definition: EventSetup.h:73
ROOT::Math::SVector< double, 3 > AlgebraicVector3
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
edm::EDGetTokenT< reco::VertexCollection > thePVs_
Definition: Onia2MuMuPAT.h:50
const Point & position() const
position
Definition: BeamSpot.h:59
GreaterByVProb< pat::CompositeCandidate > vPComparator_
Definition: Onia2MuMuPAT.h:59
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:71
T x() const
Definition: PV3DBase.h:59
T const * product() const
Definition: ESHandle.h:86
bool isValid() const
void setP4(const LorentzVector &p4) final
set 4-momentum
void addUserData(const std::string &label, const T &data, bool transientOnly=false, bool overwrite=false)
Definition: PATObject.h:353
def move(src, dest)
Definition: eostools.py:511
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:69
Measurement1D invariantMass(const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
Definition: Onia2MuMuPAT.h:48
math::PtEtaPhiELorentzVectorF LorentzVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
double mass() const final
mass

Member Data Documentation

bool Onia2MuMuPAT::addCommonVertex_
private

Definition at line 56 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::addMCTruth_
private

Definition at line 58 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::addMuonlessPrimaryVertex_
private

Definition at line 56 of file Onia2MuMuPAT.h.

Referenced by produce().

StringCutObjectSelector<reco::Candidate, true> Onia2MuMuPAT::dimuonSelection_
private

Definition at line 55 of file Onia2MuMuPAT.h.

Referenced by produce().

StringCutObjectSelector<pat::Muon> Onia2MuMuPAT::higherPuritySelection_
private

Definition at line 53 of file Onia2MuMuPAT.h.

Referenced by produce().

StringCutObjectSelector<pat::Muon> Onia2MuMuPAT::lowerPuritySelection_
private

Definition at line 54 of file Onia2MuMuPAT.h.

Referenced by produce().

InvariantMassFromVertex Onia2MuMuPAT::massCalculator
private

Definition at line 61 of file Onia2MuMuPAT.h.

Referenced by produce().

edm::EDGetTokenT<edm::View<pat::Muon> > Onia2MuMuPAT::muons_
private

Definition at line 48 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::resolveAmbiguity_
private

Definition at line 57 of file Onia2MuMuPAT.h.

Referenced by produce().

edm::EDGetTokenT<reco::BeamSpot> Onia2MuMuPAT::revtxbs_
private

Definition at line 52 of file Onia2MuMuPAT.h.

Referenced by Onia2MuMuPAT(), and produce().

edm::EDGetTokenT<reco::TrackCollection> Onia2MuMuPAT::revtxtrks_
private

Definition at line 51 of file Onia2MuMuPAT.h.

Referenced by Onia2MuMuPAT(), and produce().

edm::EDGetTokenT<reco::BeamSpot> Onia2MuMuPAT::thebeamspot_
private

Definition at line 49 of file Onia2MuMuPAT.h.

Referenced by produce().

edm::EDGetTokenT<reco::VertexCollection> Onia2MuMuPAT::thePVs_
private

Definition at line 50 of file Onia2MuMuPAT.h.

Referenced by produce().

GreaterByVProb<pat::CompositeCandidate> Onia2MuMuPAT::vPComparator_
private

Definition at line 59 of file Onia2MuMuPAT.h.

Referenced by produce().