17 #include "Math/VectorUtil.h"
27 : muons_(consumes<edm::
View<pat::
Muon>>(iConfig.getParameter<edm::
InputTag>(
"muons"))),
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")) {
43 produces<pat::CompositeCandidateCollection>();
57 vector<double> muMasses;
58 muMasses.push_back(0.1056583715);
59 muMasses.push_back(0.1056583715);
71 theBeamSpotV =
Vertex(
bs.position(),
bs.covariance3D());
75 if (priVtxs->begin() != priVtxs->end()) {
76 thePrimaryV =
Vertex(*(priVtxs->begin()));
78 thePrimaryV =
Vertex(
bs.position(),
bs.covariance3D());
102 vector<TransientVertex> pvs;
111 myCand.
setCharge(it->charge() + it2->charge());
118 if (it->track().isNonnull() && it2->track().isNonnull()) {
120 vector<TransientTrack> t_tks;
121 t_tks.push_back(theTTBuilder->build(
123 t_tks.push_back(theTTBuilder->build(*it2->track()));
129 if (field.nominalValue() > 0) {
140 float vProb(TMath::Prob(vChi2, (
int)vNDF));
150 TVector3 pperp(jpsi.px(), jpsi.py(), 0);
154 float minDz = 999999.;
166 float extrapZ = -9E20;
168 extrapZ = ttmd.
points().first.z();
170 for (VertexCollection::const_iterator itv = priVtxs->begin(), itvend = priVtxs->end(); itv != itvend;
172 float deltaZ = fabs(extrapZ - itv->position().z());
173 if (deltaZ < minDz) {
175 thePrimaryV =
Vertex(*itv);
180 Vertex theOriginalPV = thePrimaryV;
183 muonLess.
reserve(thePrimaryV.tracksSize());
190 std::cout <<
"pvtracks NOT valid " << std::endl;
194 if (pvbeamspot.
id() != theBeamSpot.
id())
196 <<
"The BeamSpot used for PV reco is not the same used in this analyzer.";
202 if (rmu1 !=
nullptr && rmu2 !=
nullptr && rmu1->
track().
id() == pvtracks.
id() &&
207 if (thePrimaryV.hasRefittedTracks()) {
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())
214 if (thePrimaryV.originalTrack(*itRefittedTrack).key() == rmu2->
track().
key())
217 muonLess.push_back(*(thePrimaryV.originalTrack(*itRefittedTrack)));
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())
225 if (itPVtrack->key() == rmu2->
track().
key())
228 muonLess.push_back(**itPVtrack);
231 if (muonLess.size() > 1 && muonLess.size() < thePrimaryV.tracksSize()) {
232 pvs = revertex.
makeVertices(muonLess, *pvbeamspot, *theTTBuilder);
235 thePrimaryV = muonLessPV;
243 double vertexWeight = -1., sumPTPV = -1.;
244 int countTksOfPV = -1;
251 if (itVtx->isNonnull()) {
255 if (track.
pt() < 0.5)
261 if (tkPVdist.second.significance() > 3)
266 if (rmu1 !=
nullptr && rmu1->
innerTrack().
key() == itVtx->key())
268 if (rmu2 !=
nullptr && rmu2->
innerTrack().
key() == itVtx->key())
274 sumPTPV += track.
pt();
278 std::cout <<
" muon Selection%G�%@failed " << std::endl;
282 myCand.
addUserInt(
"countTksOfPV", countTksOfPV);
283 myCand.
addUserFloat(
"vertexWeight", (
float)vertexWeight);
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());
310 double ctauPV = distXY.
value() * cosAlpha * myCand.
mass() / pperp.Perp();
315 double ctauErrPV =
sqrt(ROOT::Math::Similarity(vpperp, vXYe)) * myCand.
mass() / (pperp.Perp2());
322 pvtx.SetXYZ(theBeamSpotV.position().x(), theBeamSpotV.position().y(), 0);
324 cosAlpha = vdiff.Dot(pperp) / (vdiff.Perp() * pperp.Perp());
327 double ctauBS = distXY.
value() * cosAlpha * myCand.
mass() / pperp.Perp();
332 double ctauErrBS =
sqrt(ROOT::Math::Similarity(vpperp, vXYeB)) * myCand.
mass() / (pperp.Perp2());
365 if (genMu1->numberOfMothers() > 0 && genMu2->numberOfMothers() > 0) {
368 if (mom1.
isNonnull() && (mom1 == mom2)) {
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) {
408 oniaOutput->push_back(myCand);
412 std::sort(oniaOutput->begin(), oniaOutput->end(),
vPComparator_);
418 if (
abs(pdgID) == 511 ||
abs(pdgID) == 521 ||
abs(pdgID) == 531 ||
abs(pdgID) == 5122)
424 if ((
abs(pdgID) == 511 &&
abs(momPdgID) == 511 && pdgID * momPdgID < 0) ||
425 (
abs(pdgID) == 531 &&
abs(momPdgID) == 531 && pdgID * momPdgID < 0))
432 float trueLife = -99.;
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);
439 trueVtx.SetXYZ(genJpsi->vertex().x(), genJpsi->vertex().y(), genJpsi->vertex().z());
440 trueP.SetXYZ(genJpsi->momentum().x(), genJpsi->momentum().y(), genJpsi->momentum().z());
442 bool aBhadron =
false;
445 std::pair<int, float>
result = std::make_pair(momJpsiID, trueLife);
451 momJpsiID = Jpsigrandmom->pdgId();
452 trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(), Jpsigrandmom->vertex().y(), Jpsigrandmom->vertex().z());
454 momJpsiID = Jpsimom->pdgId();
455 trueVtxMom.SetXYZ(Jpsimom->vertex().x(), Jpsimom->vertex().y(), Jpsimom->vertex().z());
462 momJpsiID = JpsiGrandgrandmom->pdgId();
464 JpsiGrandgrandmom->vertex().x(), JpsiGrandgrandmom->vertex().y(), JpsiGrandgrandmom->vertex().z());
466 momJpsiID = Jpsigrandmom->pdgId();
467 trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(), Jpsigrandmom->vertex().y(), Jpsigrandmom->vertex().z());
473 momJpsiID = Jpsimom->pdgId();
474 trueVtxMom.SetXYZ(Jpsimom->vertex().x(), Jpsimom->vertex().y(), Jpsimom->vertex().z());
478 TVector3 vdiff = trueVtx - trueVtxMom;
480 trueLife = vdiff.Perp() * genJpsi->mass() / trueP.Perp();
482 std::pair<int, float>
result = std::make_pair(momJpsiID, trueLife);
494 desc.
add<
bool>(
"addCommonVertex");
495 desc.
add<
bool>(
"addMuonlessPrimaryVertex");
496 desc.
add<
bool>(
"resolvePileUpAmbiguity");
497 desc.
add<
bool>(
"addMCTruth");
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
double pz() const final
z coordinate of momentum vector
bool isNonnull() const
Checks for non-null.
float distance() const override
StringCutObjectSelector< pat::Muon > higherPuritySelection_
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
virtual TrackRef innerTrack() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const FreeTrajectoryState & theState() const
#define DEFINE_FWK_MODULE(type)
const AlgebraicSymMatrix33 matrix() const
Onia2MuMuPAT(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
float totalChiSquared() const
Global3DPoint GlobalPoint
std::vector< Track > TrackCollection
collection of Tracks
InvariantMassFromVertex massCalculator
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
key_type key() const
Accessor for product key.
void produce(edm::Event &, const edm::EventSetup &) override
TrackRef track() const override
reference to a Track
std::vector< Vertex > VertexCollection
void setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
void reserve(int size, bool refitAsWell=false)
reserve space for the tracks
ProductID id() const
Accessor for product ID.
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
bool getData(T &iHolder) const
std::vector< TransientVertex > makeVertices(const reco::TrackCollection &tracks, const reco::BeamSpot &bs, const TransientTrackBuilder &theB) const
Make the vertices.
void setCharge(Charge q) final
set electric charge
double px() const final
x coordinate of momentum vector
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::BeamSpot > revtxbs_
float degreesOfFreedom() const
bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb) override
GlobalPoint position() const
double pt() const
track transverse momentum
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > theTTBuilderToken_
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
Abs< T >::type abs(const T &t)
trackRef_iterator tracks_end() const
last iterator over tracks
edm::EDGetTokenT< reco::TrackCollection > revtxtrks_
math::XYZTLorentzVector LorentzVector
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
bool addMuonlessPrimaryVertex_
std::pair< GlobalPoint, GlobalPoint > points() const override
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
trackRef_iterator tracks_begin() const
first iterator over tracks
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double py() const final
y coordinate of momentum vector
bool isNull() const
Checks for null.
void addUserInt(const std::string &label, int32_t data, const bool overwrite=false)
Set user-defined int.
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
virtual int pdgId() const =0
PDG identifier.
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
bool isAMixedbHadron(int pdgID, int momPdgID) const
bool isAbHadron(int pdgID) const
std::vector< CompositeCandidate > CompositeCandidateCollection
edm::EDGetTokenT< reco::BeamSpot > thebeamspot_
bool quality(const TrackQuality) const
Track quality.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
double mass() const final
mass
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
ROOT::Math::SVector< double, 3 > AlgebraicVector3
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
const_iterator begin() const
first daughter const_iterator
edm::EDGetTokenT< reco::VertexCollection > thePVs_
std::pair< int, float > findJpsiMCInfo(reco::GenParticleRef genJpsi) const
GreaterByVProb< pat::CompositeCandidate > vPComparator_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) 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)
bool status() const override
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Measurement1D invariantMass(const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
math::PtEtaPhiELorentzVectorF LorentzVector
Global3DVector GlobalVector