17 #include "Math/VectorUtil.h"
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()));
138 float vChi2 = myVertex.totalChiSquared();
139 float vNDF = myVertex.degreesOfFreedom();
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;
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.";
198 const reco::Muon *rmu1 = dynamic_cast<const reco::Muon *>(it->originalObject());
199 const reco::Muon *rmu2 = dynamic_cast<const reco::Muon *>(it2->originalObject());
202 if (rmu1 !=
nullptr && rmu2 !=
nullptr && rmu1->
track().
id() == pvtracks.
id() &&
203 rmu2->track().
id() == pvtracks.
id()) {
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) {
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()) {
235 thePrimaryV = muonLessPV;
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());
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);
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());
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");