19 #include "Math/VectorUtil.h"
29 muons_(consumes<edm::
View<pat::
Muon>>(iConfig.getParameter<edm::
InputTag>(
"muons"))),
32 higherPuritySelection_(iConfig.getParameter<std::
string>(
"higherPuritySelection")),
33 lowerPuritySelection_(iConfig.getParameter<std::
string>(
"lowerPuritySelection")),
34 dimuonSelection_(iConfig.existsAs<std::
string>(
"dimuonSelection") ? iConfig.getParameter<std::
string>(
"dimuonSelection") :
""),
35 addCommonVertex_(iConfig.getParameter<bool>(
"addCommonVertex")),
36 addMuonlessPrimaryVertex_(iConfig.getParameter<bool>(
"addMuonlessPrimaryVertex")),
37 resolveAmbiguity_(iConfig.getParameter<bool>(
"resolvePileUpAmbiguity")),
38 addMCTruth_(iConfig.getParameter<bool>(
"addMCTruth"))
42 produces<pat::CompositeCandidateCollection>();
68 vector<double> muMasses;
69 muMasses.push_back( 0.1056583715 );
70 muMasses.push_back( 0.1056583715 );
83 theBeamSpotV =
Vertex(bs.position(), bs.covariance3D());
87 if ( priVtxs->begin() != priVtxs->end() ) {
88 thePrimaryV =
Vertex(*(priVtxs->begin()));
91 thePrimaryV =
Vertex(bs.position(), bs.covariance3D());
113 vector<TransientVertex> pvs;
122 myCand.
setCharge(it->charge()+it2->charge());
128 if (it->track().isNonnull() && it2->track().isNonnull()) {
131 vector<TransientTrack> t_tks;
132 t_tks.push_back(theTTBuilder->build(*it->track()));
133 t_tks.push_back(theTTBuilder->build(*it2->track()));
144 float vProb(TMath::Prob(vChi2,(
int)vNDF));
154 TVector3 pperp(jpsi.px(), jpsi.py(), 0);
159 float minDz = 999999.;
165 GlobalPoint(bs.position().x(), bs.position().y(), bs.position().z()),
168 if (status) extrapZ=ttmd.
points().first.z();
170 for(VertexCollection::const_iterator itv = priVtxs->begin(), itvend = priVtxs->end(); itv != itvend; ++itv){
171 float deltaZ = fabs(extrapZ - itv->position().z()) ;
172 if ( deltaZ < minDz ) {
174 thePrimaryV =
Vertex(*itv);
179 Vertex theOriginalPV = thePrimaryV;
182 muonLess.reserve(thePrimaryV.tracksSize());
188 if( !pvtracks.
isValid()) {
std::cout <<
"pvtracks NOT valid " << std::endl; }
192 if (pvbeamspot.
id() != theBeamSpot.
id())
edm::LogWarning(
"Inconsistency") <<
"The BeamSpot used for PV reco is not the same used in this analyzer.";
198 if (rmu1 != 0 && rmu2 != 0 && rmu1->
track().
id() == pvtracks.
id() && rmu2->
track().
id() == pvtracks.
id()) {
202 if( thePrimaryV.hasRefittedTracks() ) {
204 std::vector<reco::Track>::const_iterator itRefittedTrack = thePrimaryV.refittedTracks().
begin();
205 std::vector<reco::Track>::const_iterator refittedTracksEnd = thePrimaryV.refittedTracks().end();
206 for( ; itRefittedTrack != refittedTracksEnd; ++itRefittedTrack ) {
207 if( thePrimaryV.originalTrack(*itRefittedTrack).key() == rmu1->
track().
key() )
continue;
208 if( thePrimaryV.originalTrack(*itRefittedTrack).key() == rmu2->
track().
key() )
continue;
210 muonLess.push_back(*(thePrimaryV.originalTrack(*itRefittedTrack)));
214 std::vector<reco::TrackBaseRef>::const_iterator itPVtrack = thePrimaryV.tracks_begin();
215 for( ; itPVtrack != thePrimaryV.tracks_end(); ++itPVtrack )
if (itPVtrack->isNonnull()) {
216 if( itPVtrack->key() == rmu1->
track().
key() )
continue;
217 if( itPVtrack->key() == rmu2->
track().
key() )
continue;
219 muonLess.push_back(**itPVtrack);
222 if (muonLess.size()>1 && muonLess.size() < thePrimaryV.tracksSize()){
223 pvs = revertex.
makeVertices(muonLess, *pvbeamspot, iSetup) ;
226 thePrimaryV = muonLessPV;
234 double vertexWeight = -1., sumPTPV = -1.;
235 int countTksOfPV = -1;
242 if(track.
pt() < 0.5)
continue;
245 if (!tkPVdist.first)
continue;
246 if (tkPVdist.second.significance()>3)
continue;
247 if (track.
ptError()/track.
pt()>0.1)
continue;
257 sumPTPV += track.
pt();
262 myCand.
addUserInt(
"countTksOfPV", countTksOfPV);
263 myCand.
addUserFloat(
"vertexWeight", (
float) vertexWeight);
284 pvtx.SetXYZ(thePrimaryV.position().x(),thePrimaryV.position().y(),0);
285 TVector3 vdiff = vtx - pvtx;
286 double cosAlpha = vdiff.Dot(pperp)/(vdiff.Perp()*pperp.Perp());
289 double ctauPV = distXY.
value()*cosAlpha * myCand.
mass()/pperp.Perp();
294 double ctauErrPV =
sqrt(ROOT::Math::Similarity(vpperp,vXYe))*myCand.
mass()/(pperp.Perp2());
301 pvtx.SetXYZ(theBeamSpotV.position().x(),theBeamSpotV.position().y(),0);
303 cosAlpha = vdiff.Dot(pperp)/(vdiff.Perp()*pperp.Perp());
306 double ctauBS = distXY.
value()*cosAlpha*myCand.
mass()/pperp.Perp();
311 double ctauErrBS =
sqrt(ROOT::Math::Similarity(vpperp,vXYeB))*myCand.
mass()/(pperp.Perp2());
344 if (genMu1->numberOfMothers()>0 && genMu2->numberOfMothers()>0){
347 if (mom1.
isNonnull() && (mom1 == mom2)) {
360 iEvent.
getByToken(genCands_, theGenParticles);
361 if (theGenParticles.
isValid()){
362 for(
size_t iGenParticle=0; iGenParticle<theGenParticles->size();++iGenParticle) {
363 const Candidate & genCand = (*theGenParticles)[iGenParticle];
364 if (genCand.
pdgId()==443 || genCand.
pdgId()==100443 ||
365 genCand.
pdgId()==553 || genCand.
pdgId()==100553 || genCand.
pdgId()==200553) {
389 oniaOutput->push_back(myCand);
393 std::sort(oniaOutput->begin(),oniaOutput->end(),
vPComparator_);
395 iEvent.
put(oniaOutput);
403 if (
abs(pdgID) == 511 ||
abs(pdgID) == 521 ||
abs(pdgID) == 531 ||
abs(pdgID) == 5122)
return true;
411 if ((
abs(pdgID) == 511 &&
abs(momPdgID) == 511 && pdgID*momPdgID < 0) ||
412 (
abs(pdgID) == 531 &&
abs(momPdgID) == 531 && pdgID*momPdgID < 0))
418 std::pair<int, float>
422 float trueLife = -99.;
424 if (genJpsi->numberOfMothers()>0) {
426 TVector3 trueVtx(0.0,0.0,0.0);
427 TVector3 trueP(0.0,0.0,0.0);
428 TVector3 trueVtxMom(0.0,0.0,0.0);
430 trueVtx.SetXYZ(genJpsi->vertex().x(),genJpsi->vertex().y(),genJpsi->vertex().z());
431 trueP.SetXYZ(genJpsi->momentum().x(),genJpsi->momentum().y(),genJpsi->momentum().z());
433 bool aBhadron =
false;
436 std::pair<int, float>
result = std::make_pair(momJpsiID, trueLife);
442 momJpsiID = Jpsigrandmom->pdgId();
443 trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(),Jpsigrandmom->vertex().y(),Jpsigrandmom->vertex().z());
445 momJpsiID = Jpsimom->pdgId();
446 trueVtxMom.SetXYZ(Jpsimom->vertex().x(),Jpsimom->vertex().y(),Jpsimom->vertex().z());
453 momJpsiID = JpsiGrandgrandmom->pdgId();
454 trueVtxMom.SetXYZ(JpsiGrandgrandmom->vertex().x(),JpsiGrandgrandmom->vertex().y(),JpsiGrandgrandmom->vertex().z());
456 momJpsiID = Jpsigrandmom->pdgId();
457 trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(),Jpsigrandmom->vertex().y(),Jpsigrandmom->vertex().z());
463 momJpsiID = Jpsimom->pdgId();
464 trueVtxMom.SetXYZ(Jpsimom->vertex().x(),Jpsimom->vertex().y(),Jpsimom->vertex().z());
468 TVector3 vdiff = trueVtx - trueVtxMom;
470 trueLife = vdiff.Perp()*genJpsi->mass()/trueP.Perp();
472 std::pair<int, float>
result = std::make_pair(momJpsiID, trueLife);
Analysis-level particle class.
virtual bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb)
bool isNonnull() const
Checks for non-null.
trackRef_iterator tracks_end() const
last iterator over tracks
StringCutObjectSelector< pat::Muon > higherPuritySelection_
bool isAbHadron(int pdgID)
virtual TrackRef innerTrack() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const FreeTrajectoryState & theState() const
#define DEFINE_FWK_MODULE(type)
Onia2MuMuPAT(const edm::ParameterSet &)
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const
float totalChiSquared() const
math::XYZTLorentzVector LorentzVector
Global3DPoint GlobalPoint
const AlgebraicSymMatrix33 & matrix() const
std::vector< Track > TrackCollection
collection of Tracks
std::pair< int, float > findJpsiMCInfo(reco::GenParticleRef genJpsi)
virtual TrackRef track() const
reference to a Track
std::vector< Vertex > VertexCollection
collection of Vertex objects
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 setGenParticleRef(const reco::GenParticleRef &ref, bool embed=false)
Set the generator level particle reference.
ProductID id() const
Accessor for product ID.
virtual void produce(edm::Event &, const edm::EventSetup &)
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
edm::EDGetTokenT< reco::BeamSpot > revtxbs_
float degreesOfFreedom() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
GlobalPoint position() const
double pt() const
track transverse momentum
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
virtual void setCharge(Charge q) final
set electric charge
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
ROOT::Math::SVector< double, 3 > AlgebraicVector3
Abs< T >::type abs(const T &t)
std::vector< TransientVertex > makeVertices(const reco::TrackCollection &tracks, const reco::BeamSpot &bs, const edm::EventSetup &iSetup) const
Make the vertices.
edm::EDGetTokenT< reco::TrackCollection > revtxtrks_
virtual double py() const final
y coordinate of momentum vector
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
bool addMuonlessPrimaryVertex_
virtual Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const
virtual double mass() const final
mass
bool isNull() const
Checks for null.
void addUserInt(const std::string &label, int32_t data, const bool overwrite=false)
Set user-defined int.
virtual double pz() const final
z coordinate of momentum vector
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
bool isAMixedbHadron(int pdgID, int momPdgID)
virtual int pdgId() const =0
PDG identifier.
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
virtual bool calculate(const TrajectoryStateOnSurface &sta, const TrajectoryStateOnSurface &stb)
std::vector< CompositeCandidate > CompositeCandidateCollection
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
edm::EDGetTokenT< reco::BeamSpot > thebeamspot_
bool quality(const TrackQuality) const
Track quality.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
return(e1-e2)*(e1-e2)+dp *dp
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
const_iterator begin() const
first daughter const_iterator
edm::EDGetTokenT< reco::VertexCollection > thePVs_
virtual double px() const final
x coordinate of momentum vector
GreaterByVProb< pat::CompositeCandidate > vPComparator_
trackRef_iterator tracks_begin() const
first iterator over tracks
virtual float distance() const
virtual std::pair< GlobalPoint, GlobalPoint > points() const
void addUserData(const std::string &label, const T &data, bool transientOnly=false, bool overwrite=false)
virtual bool status() const
Measurement1D invariantMass(const CachingVertex< 5 > &vertex, const std::vector< double > &masses) const
edm::EDGetTokenT< edm::View< pat::Muon > > muons_
math::PtEtaPhiELorentzVectorF LorentzVector
Global3DVector GlobalVector