CMS 3D CMS Logo

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

#include <Onia2MuMuPAT.h>

Inheritance diagram for Onia2MuMuPAT:
edm::stream::EDProducer<>

Public Member Functions

 Onia2MuMuPAT (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::stream::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
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Member Functions

std::pair< int, float > findJpsiMCInfo (reco::GenParticleRef genJpsi) const
 
bool isAbHadron (int pdgID) const
 
bool isAMixedbHadron (int pdgID, int momPdgID) const
 
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_
 
edm::ESGetToken< MagneticField, IdealMagneticFieldRecordmagneticFieldToken_
 
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_
 
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecordtheTTBuilderToken_
 
GreaterByVProb< pat::CompositeCandidatevPComparator_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 39 of file Onia2MuMuPAT.h.

Constructor & Destructor Documentation

◆ Onia2MuMuPAT()

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

Definition at line 26 of file Onia2MuMuPAT.cc.

References ProducerED_cfi::InputTag, revtxbs_, and revtxtrks_.

27  : muons_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muons"))),
28  thebeamspot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotTag"))),
29  thePVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexTag"))),
30  magneticFieldToken_(esConsumes<MagneticField, IdealMagneticFieldRecord>()),
32  esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))),
33  higherPuritySelection_(iConfig.getParameter<std::string>("higherPuritySelection")),
34  lowerPuritySelection_(iConfig.getParameter<std::string>("lowerPuritySelection")),
35  dimuonSelection_(iConfig.getParameter<std::string>("dimuonSelection")),
36  addCommonVertex_(iConfig.getParameter<bool>("addCommonVertex")),
37  addMuonlessPrimaryVertex_(iConfig.getParameter<bool>("addMuonlessPrimaryVertex")),
38  resolveAmbiguity_(iConfig.getParameter<bool>("resolvePileUpAmbiguity")),
39  addMCTruth_(iConfig.getParameter<bool>("addMCTruth")) {
40  revtxtrks_ = consumes<reco::TrackCollection>(
41  (edm::InputTag) "generalTracks"); //if that is not true, we will raise an exception
42  revtxbs_ = consumes<reco::BeamSpot>((edm::InputTag) "offlineBeamSpot");
43  produces<pat::CompositeCandidateCollection>();
44 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool addCommonVertex_
Definition: Onia2MuMuPAT.h:63
StringCutObjectSelector< pat::Muon > higherPuritySelection_
Definition: Onia2MuMuPAT.h:60
edm::EDGetTokenT< reco::BeamSpot > revtxbs_
Definition: Onia2MuMuPAT.h:57
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > theTTBuilderToken_
Definition: Onia2MuMuPAT.h:59
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
Definition: Onia2MuMuPAT.h:62
edm::EDGetTokenT< reco::TrackCollection > revtxtrks_
Definition: Onia2MuMuPAT.h:56
bool addMuonlessPrimaryVertex_
Definition: Onia2MuMuPAT.h:63
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Definition: Onia2MuMuPAT.h:58
bool resolveAmbiguity_
Definition: Onia2MuMuPAT.h:64
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
Definition: Onia2MuMuPAT.h:61
bool addMCTruth_
Definition: Onia2MuMuPAT.h:65
edm::EDGetTokenT< reco::BeamSpot > thebeamspot_
Definition: Onia2MuMuPAT.h:54
edm::EDGetTokenT< reco::VertexCollection > thePVs_
Definition: Onia2MuMuPAT.h:55
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
Definition: Onia2MuMuPAT.h:53

Member Function Documentation

◆ fillDescriptions()

void Onia2MuMuPAT::fillDescriptions ( edm::ConfigurationDescriptions iDescriptions)
static

Definition at line 486 of file Onia2MuMuPAT.cc.

References edm::ConfigurationDescriptions::addDefault(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

486  {
488  desc.add<edm::InputTag>("muons");
489  desc.add<edm::InputTag>("beamSpotTag");
490  desc.add<edm::InputTag>("primaryVertexTag");
491  desc.add<std::string>("higherPuritySelection");
492  desc.add<std::string>("lowerPuritySelection");
493  desc.add<std::string>("dimuonSelection", "");
494  desc.add<bool>("addCommonVertex");
495  desc.add<bool>("addMuonlessPrimaryVertex");
496  desc.add<bool>("resolvePileUpAmbiguity");
497  desc.add<bool>("addMCTruth");
498 
499  iDescriptions.addDefault(desc);
500 }
void addDefault(ParameterSetDescription const &psetDescription)

◆ findJpsiMCInfo()

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

Definition at line 430 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().

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

◆ isAbHadron()

bool Onia2MuMuPAT::isAbHadron ( int  pdgID) const
private

Definition at line 417 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

417  {
418  if (abs(pdgID) == 511 || abs(pdgID) == 521 || abs(pdgID) == 531 || abs(pdgID) == 5122)
419  return true;
420  return false;
421 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ isAMixedbHadron()

bool Onia2MuMuPAT::isAMixedbHadron ( int  pdgID,
int  momPdgID 
) const
private

Definition at line 423 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

423  {
424  if ((abs(pdgID) == 511 && abs(momPdgID) == 511 && pdgID * momPdgID < 0) ||
425  (abs(pdgID) == 531 && abs(momPdgID) == 531 && pdgID * momPdgID < 0))
426  return true;
427  return false;
428 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ produce()

void Onia2MuMuPAT::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

DCA

end DCA

Definition at line 51 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, cms::cuda::bs, TransientTrackBuilder::build(), TwoTrackMinimumDistance::calculate(), ClosestApproachInRPhi::calculate(), gather_cfg::cout, TransientVertex::degreesOfFreedom(), l1tTrackerHTMiss_cfi::deltaZ, dimuonSelection_, VertexDistanceXY::distance(), ClosestApproachInRPhi::distance(), pat::PATObject< ObjectType >::embedGenParticle(), submitPVResolutionJobs::err, Measurement1D::error(), relativeConstraints::error, reco::Vertex::error(), cppFunctionSkipper::exception, findJpsiMCInfo(), edm::EventSetup::getData(), edm::EventSetup::getHandle(), reco::Vertex::hasRefittedTracks(), higherPuritySelection_, reco::TrackBase::highPurity, edm::HandleBase::id(), edm::Ref< C, T, F >::id(), iEvent, reco::Muon::innerTrack(), ProducerED_cfi::InputTag, InvariantMassFromVertex::invariantMass(), edm::Ref< C, T, F >::isNonnull(), edm::HandleBase::isValid(), TrajectoryStateClosestToPoint::isValid(), TransientVertex::isValid(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, edm::RefToBase< T >::key(), edm::Ref< C, T, F >::key(), lowerPuritySelection_, magneticFieldToken_, OniaVtxReProducer::makeVertices(), reco::LeafCandidate::mass(), massCalculator, GlobalErrorBase< T, ErrorWeightType >::matrix(), pfMETCorrectionType0_cfi::minDz, eostools::move(), DiMuonV_cfg::muons, muons_, MagneticField::nominalValue(), reco::Vertex::originalTrack(), reco::Candidate::pdgId(), TwoTrackMinimumDistance::points(), reco::Vertex::position(), TransientVertex::position(), FSQDQM_cfi::pvs, reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), reco::Vertex::refittedTracks(), reco::Vertex::reserve(), resolveAmbiguity_, revtxbs_, revtxtrks_, reco::LeafCandidate::setCharge(), pat::PATObject< ObjectType >::setGenParticleRef(), reco::LeafCandidate::setP4(), jetUpdater_cfi::sort, mathSSE::sqrt(), ClosestApproachInRPhi::status(), mps_update::status, thebeamspot_, thePVs_, TrajectoryStateClosestToPoint::theState(), theTTBuilderToken_, TransientVertex::totalChiSquared(), reco::Muon::track(), HLT_2024v12_cff::track, reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), reco::Vertex::tracksSize(), reco::Vertex::trackWeight(), Measurement1D::value(), HltBtagValidation_cff::Vertex, KalmanVertexFitter::vertex(), vPComparator_, L1BJetProducer_cff::vtx, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

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

Member Data Documentation

◆ addCommonVertex_

bool Onia2MuMuPAT::addCommonVertex_
private

Definition at line 63 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ addMCTruth_

bool Onia2MuMuPAT::addMCTruth_
private

Definition at line 65 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ addMuonlessPrimaryVertex_

bool Onia2MuMuPAT::addMuonlessPrimaryVertex_
private

Definition at line 63 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ dimuonSelection_

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

Definition at line 62 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ higherPuritySelection_

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

Definition at line 60 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ lowerPuritySelection_

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

Definition at line 61 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ magneticFieldToken_

edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> Onia2MuMuPAT::magneticFieldToken_
private

Definition at line 58 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ massCalculator

InvariantMassFromVertex Onia2MuMuPAT::massCalculator
private

Definition at line 68 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ muons_

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

Definition at line 53 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ resolveAmbiguity_

bool Onia2MuMuPAT::resolveAmbiguity_
private

Definition at line 64 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ revtxbs_

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

Definition at line 57 of file Onia2MuMuPAT.h.

Referenced by Onia2MuMuPAT(), and produce().

◆ revtxtrks_

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

Definition at line 56 of file Onia2MuMuPAT.h.

Referenced by Onia2MuMuPAT(), and produce().

◆ thebeamspot_

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

Definition at line 54 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ thePVs_

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

Definition at line 55 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ theTTBuilderToken_

edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> Onia2MuMuPAT::theTTBuilderToken_
private

Definition at line 59 of file Onia2MuMuPAT.h.

Referenced by produce().

◆ vPComparator_

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

Definition at line 66 of file Onia2MuMuPAT.h.

Referenced by produce().