CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

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

Private Attributes

bool addCommonVertex_
 
bool addMCTruth_
 
bool addMuonlessPrimaryVertex_
 
StringCutObjectSelector
< reco::Candidate, true > 
dimuonSelection_
 
StringCutObjectSelector
< pat::Muon
higherPuritySelection_
 
StringCutObjectSelector
< pat::Muon
lowerPuritySelection_
 
InvariantMassFromVertex massCalculator
 
edm::EDGetTokenT< edm::View
< pat::Muon > > 
muons_
 
bool resolveAmbiguity_
 
edm::EDGetTokenT< reco::BeamSpotthebeamspot_
 
edm::EDGetTokenT
< reco::VertexCollection
thePVs_
 
GreaterByVProb
< pat::CompositeCandidate
vPComparator_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
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)
 
- 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 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 37 of file Onia2MuMuPAT.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file Onia2MuMuPAT.cc.

28  :
30  thebeamspot_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotTag"))),
31  thePVs_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertexTag"))),
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"))
39 {
40  produces<pat::CompositeCandidateCollection>();
41 }
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:186
bool addCommonVertex_
Definition: Onia2MuMuPAT.h:59
StringCutObjectSelector< pat::Muon > higherPuritySelection_
Definition: Onia2MuMuPAT.h:56
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
StringCutObjectSelector< reco::Candidate, true > dimuonSelection_
Definition: Onia2MuMuPAT.h:58
bool addMuonlessPrimaryVertex_
Definition: Onia2MuMuPAT.h:59
bool resolveAmbiguity_
Definition: Onia2MuMuPAT.h:60
StringCutObjectSelector< pat::Muon > lowerPuritySelection_
Definition: Onia2MuMuPAT.h:57
bool addMCTruth_
Definition: Onia2MuMuPAT.h:61
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
Onia2MuMuPAT::~Onia2MuMuPAT ( )

Definition at line 44 of file Onia2MuMuPAT.cc.

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

Member Function Documentation

void Onia2MuMuPAT::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 478 of file Onia2MuMuPAT.cc.

479 {
480 }
void Onia2MuMuPAT::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 484 of file Onia2MuMuPAT.cc.

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

Definition at line 418 of file Onia2MuMuPAT.cc.

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

Referenced by produce().

418  {
419 
420  int momJpsiID = 0;
421  float trueLife = -99.;
422 
423  if (genJpsi->numberOfMothers()>0) {
424 
425  TVector3 trueVtx(0.0,0.0,0.0);
426  TVector3 trueP(0.0,0.0,0.0);
427  TVector3 trueVtxMom(0.0,0.0,0.0);
428 
429  trueVtx.SetXYZ(genJpsi->vertex().x(),genJpsi->vertex().y(),genJpsi->vertex().z());
430  trueP.SetXYZ(genJpsi->momentum().x(),genJpsi->momentum().y(),genJpsi->momentum().z());
431 
432  bool aBhadron = false;
433  reco::GenParticleRef Jpsimom = genJpsi->motherRef(); // find mothers
434  if (Jpsimom.isNull()) {
435  std::pair<int, float> result = std::make_pair(momJpsiID, trueLife);
436  return result;
437  } else {
438  reco::GenParticleRef Jpsigrandmom = Jpsimom->motherRef();
439  if (isAbHadron(Jpsimom->pdgId())) {
440  if (Jpsigrandmom.isNonnull() && isAMixedbHadron(Jpsimom->pdgId(),Jpsigrandmom->pdgId())) {
441  momJpsiID = Jpsigrandmom->pdgId();
442  trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(),Jpsigrandmom->vertex().y(),Jpsigrandmom->vertex().z());
443  } else {
444  momJpsiID = Jpsimom->pdgId();
445  trueVtxMom.SetXYZ(Jpsimom->vertex().x(),Jpsimom->vertex().y(),Jpsimom->vertex().z());
446  }
447  aBhadron = true;
448  } else {
449  if (Jpsigrandmom.isNonnull() && isAbHadron(Jpsigrandmom->pdgId())) {
450  reco::GenParticleRef JpsiGrandgrandmom = Jpsigrandmom->motherRef();
451  if (JpsiGrandgrandmom.isNonnull() && isAMixedbHadron(Jpsigrandmom->pdgId(),JpsiGrandgrandmom->pdgId())) {
452  momJpsiID = JpsiGrandgrandmom->pdgId();
453  trueVtxMom.SetXYZ(JpsiGrandgrandmom->vertex().x(),JpsiGrandgrandmom->vertex().y(),JpsiGrandgrandmom->vertex().z());
454  } else {
455  momJpsiID = Jpsigrandmom->pdgId();
456  trueVtxMom.SetXYZ(Jpsigrandmom->vertex().x(),Jpsigrandmom->vertex().y(),Jpsigrandmom->vertex().z());
457  }
458  aBhadron = true;
459  }
460  }
461  if (!aBhadron) {
462  momJpsiID = Jpsimom->pdgId();
463  trueVtxMom.SetXYZ(Jpsimom->vertex().x(),Jpsimom->vertex().y(),Jpsimom->vertex().z());
464  }
465  }
466 
467  TVector3 vdiff = trueVtx - trueVtxMom;
468  //trueLife = vdiff.Perp()*3.09688/trueP.Perp();
469  trueLife = vdiff.Perp()*genJpsi->mass()/trueP.Perp();
470  }
471  std::pair<int, float> result = std::make_pair(momJpsiID, trueLife);
472  return result;
473 
474 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
bool isAbHadron(int pdgID)
tuple result
Definition: query.py:137
bool isNull() const
Checks for null.
Definition: Ref.h:249
bool isAMixedbHadron(int pdgID, int momPdgID)
bool Onia2MuMuPAT::isAbHadron ( int  pdgID)
private

Definition at line 400 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

400  {
401 
402  if (abs(pdgID) == 511 || abs(pdgID) == 521 || abs(pdgID) == 531 || abs(pdgID) == 5122) return true;
403  return false;
404 
405 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool Onia2MuMuPAT::isAMixedbHadron ( int  pdgID,
int  momPdgID 
)
private

Definition at line 408 of file Onia2MuMuPAT.cc.

References funct::abs().

Referenced by findJpsiMCInfo().

408  {
409 
410  if ((abs(pdgID) == 511 && abs(momPdgID) == 511 && pdgID*momPdgID < 0) ||
411  (abs(pdgID) == 531 && abs(momPdgID) == 531 && pdgID*momPdgID < 0))
412  return true;
413  return false;
414 
415 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void Onia2MuMuPAT::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

DCA

end DCA

Implements edm::EDProducer.

Definition at line 59 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, reco::Candidate::begin(), ClosestApproachInRPhi::calculate(), TwoTrackMinimumDistance::calculate(), gather_cfg::cout, TransientVertex::degreesOfFreedom(), dimuonSelection_, VertexDistanceXY::distance(), ClosestApproachInRPhi::distance(), pat::PATObject< ObjectType >::embedGenParticle(), Measurement1D::error(), relativeConstraints::error, cppFunctionSkipper::exception, findJpsiMCInfo(), edm::EventSetup::get(), edm::Event::getByToken(), higherPuritySelection_, reco::TrackBase::highPurity, edm::ProductID::id(), edm::HandleBase::id(), edm::Ref< C, T, F >::id(), reco::Muon::innerTrack(), OniaVtxReProducer::inputBeamSpot(), HLT_25ns14e33_v1_cff::InputTag, OniaVtxReProducer::inputTracks(), InvariantMassFromVertex::invariantMass(), edm::Ref< C, T, F >::isNonnull(), edm::HandleBase::isValid(), TrajectoryStateClosestToPoint::isValid(), TransientVertex::isValid(), jpsi, edm::Ref< C, T, F >::key(), lowerPuritySelection_, HLT_25ns14e33_v1_cff::magneticField, OniaVtxReProducer::makeVertices(), reco::LeafCandidate::mass(), massCalculator, GlobalErrorBase< T, ErrorWeightType >::matrix(), patZpeak::muons, muons_, reco::Candidate::pdgId(), TwoTrackMinimumDistance::points(), TransientVertex::position(), reco::TrackBase::pt(), reco::TrackBase::ptError(), edm::Event::put(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), reco::TrackBase::quality(), dt_dqm_sourceclient_common_cff::reco, resolveAmbiguity_, mathSSE::return(), reco::LeafCandidate::setCharge(), pat::PATObject< ObjectType >::setGenParticleRef(), reco::LeafCandidate::setP4(), python.multivaluedict::sort(), mathSSE::sqrt(), ClosestApproachInRPhi::status(), ntuplemaker::status, thebeamspot_, thePVs_, TrajectoryStateClosestToPoint::theState(), TransientVertex::totalChiSquared(), reco::Muon::track(), reco::Vertex::tracks_begin(), reco::Vertex::tracks_end(), reco::Vertex::trackWeight(), groupFilesInBlocks::tt, Measurement1D::value(), KalmanVertexFitter::vertex(), vPComparator_, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

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

Member Data Documentation

bool Onia2MuMuPAT::addCommonVertex_
private

Definition at line 59 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::addMCTruth_
private

Definition at line 61 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::addMuonlessPrimaryVertex_
private

Definition at line 59 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 58 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 56 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 57 of file Onia2MuMuPAT.h.

Referenced by produce().

InvariantMassFromVertex Onia2MuMuPAT::massCalculator
private

Definition at line 64 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 53 of file Onia2MuMuPAT.h.

Referenced by produce().

bool Onia2MuMuPAT::resolveAmbiguity_
private

Definition at line 60 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 54 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 55 of file Onia2MuMuPAT.h.

Referenced by produce().

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

Definition at line 62 of file Onia2MuMuPAT.h.

Referenced by produce().