CMS 3D CMS Logo

DiMuonVertexMonitor.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  */
5 
20 
21 #include "TLorentzVector.h"
22 
23 namespace {
24  constexpr float cmToum = 10e4;
25  constexpr float mumass2 = 0.105658367 * 0.105658367; //mu mass squared (GeV^2/c^4)
26 } // namespace
27 
29  : ttbESToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
30  tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("muonTracks"))),
31  vertexToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
32  MEFolderName_(iConfig.getParameter<std::string>("FolderName")),
33  maxSVdist_(iConfig.getParameter<double>("maxSVdist")) {}
34 
36  iBooker.setCurrentFolder(MEFolderName_ + "/DiMuonVertexMonitor");
37  hSVProb_ = iBooker.book1D("VtxProb", ";ZV vertex probability;N(#mu#mu pairs)", 100, 0., 1.);
38  hSVDist_ = iBooker.book1D("VtxDist", ";PV-ZV xy distance [#mum];N(#mu#mu pairs)", 100, 0., 300.);
39  hSVDistErr_ = iBooker.book1D("VtxDistErr", ";PV-ZV xy distance error [#mum];N(#mu#mu pairs)", 100, 0., 1000.);
40  hSVDistSig_ = iBooker.book1D("VtxDistSig", ";PV-ZV xy distance signficance;N(#mu#mu pairs)", 100, 0., 5.);
41  hSVDist3D_ = iBooker.book1D("VtxDist3D", ";PV-ZV 3D distance [#mum];N(#mu#mu pairs)", 100, 0., 300.);
42  hSVDist3DErr_ = iBooker.book1D("VtxDist3DErr", ";PV-ZV 3D distance error [#mum];N(#mu#mu pairs)", 100, 0., 1000.);
43  hSVDist3DSig_ = iBooker.book1D("VtxDist3DSig", ";PV-ZV 3D distance signficance;N(#mu#mu pairs)", 100, 0., 5.);
44  hTrackInvMass_ = iBooker.book1D("TkTkInvMass", ";M(tk,tk) [GeV];N(tk tk pairs)", 70., 50., 120.);
45  hCosPhi_ = iBooker.book1D("CosPhi", ";cos(#phi_{xy});N(#mu#mu pairs)", 50, -1., 1.);
46  hCosPhi3D_ = iBooker.book1D("CosPhi3D", ";cos(#phi_{3D});N(#mu#mu pairs)", 50, -1., 1.);
47  hCosPhiInv_ = iBooker.book1D("CosPhiInv", ";inverted cos(#phi_{xy});N(#mu#mu pairs)", 50, -1., 1.);
48  hCosPhiInv3D_ = iBooker.book1D("CosPhiInv3D", ";inverted cos(#phi_{3D});N(#mu#mu pairs)", 50, -1., 1.);
49 
50  hdxy_ = iBooker.book1D("dxy", ";muon track d_{xy}(PV) [#mum];muon tracks", 150, -300, 300);
51  hdz_ = iBooker.book1D("dz", ";muon track d_{z}(PV) [#mum];muon tracks", 150, -300, 300);
52  hdxyErr_ = iBooker.book1D("dxyErr", ";muon track err_{dxy} [#mum];muon tracks", 250, 0., 500.);
53  hdzErr_ = iBooker.book1D("dzErr", ";muon track err_{dz} [#mum];muon tracks", 250, 0., 500.);
54  hIP2d_ = iBooker.book1D("IP2d", ";muon track IP_{2D} [#mum];muon tracks", 150, -300, 300);
55  hIP3d_ = iBooker.book1D("IP3d", ";muon track IP_{3D} [#mum];muon tracks", 150, -300, 300);
56  hIP2dsig_ = iBooker.book1D("IP2Dsig", ";muon track IP_{2D} significance;muon tracks", 100, 0., 5.);
57  hIP3dsig_ = iBooker.book1D("IP3Dsig", ";muon track IP_{3D} significance;muon tracks", 100, 0., 5.);
58 }
59 
61  std::vector<const reco::Track*> myTracks;
62  const auto trackHandle = iEvent.getHandle(tracksToken_);
63  if (!trackHandle.isValid()) {
64  edm::LogError("DiMuonVertexMonitor") << "invalid track collection encountered!";
65  return;
66  }
67 
68  for (const auto& muonTrk : *trackHandle) {
69  myTracks.emplace_back(&muonTrk);
70  }
71 
72  const TransientTrackBuilder* theB = &iSetup.getData(ttbESToken_);
73  TransientVertex mumuTransientVtx;
74  std::vector<reco::TransientTrack> tks;
75 
76  if (myTracks.size() != 2) {
77  edm::LogWarning("DiMuonVertexMonitor") << "There are not enough tracks to monitor!";
78  return;
79  }
80 
81  const auto& t1 = myTracks[1]->momentum();
82  const auto& t0 = myTracks[0]->momentum();
83  const auto& ditrack = t1 + t0;
84 
85  const auto& tplus = myTracks[0]->charge() > 0 ? myTracks[0] : myTracks[1];
86  const auto& tminus = myTracks[0]->charge() < 0 ? myTracks[0] : myTracks[1];
87 
88  TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(), sqrt((tplus->p() * tplus->p()) + mumass2));
89  TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(), sqrt((tminus->p() * tminus->p()) + mumass2));
90 
91  const auto& Zp4 = p4_tplus + p4_tminus;
92  float track_invMass = Zp4.M();
93  hTrackInvMass_->Fill(track_invMass);
94 
95  // creat the pair of TLorentVectors used to make the plos
96  std::pair<TLorentzVector, TLorentzVector> tktk_p4 = std::make_pair(p4_tplus, p4_tminus);
97 
98  math::XYZPoint ZpT(ditrack.x(), ditrack.y(), 0);
99  math::XYZPoint Zp(ditrack.x(), ditrack.y(), ditrack.z());
100 
101  for (const auto& track : myTracks) {
102  reco::TransientTrack trajectory = theB->build(track);
103  tks.push_back(trajectory);
104  }
105 
106  KalmanVertexFitter kalman(true);
107  mumuTransientVtx = kalman.vertex(tks);
108 
109  double SVProb = TMath::Prob(mumuTransientVtx.totalChiSquared(), (int)mumuTransientVtx.degreesOfFreedom());
110  hSVProb_->Fill(SVProb);
111 
112  if (!mumuTransientVtx.isValid())
113  return;
114 
115  // get collection of reconstructed vertices from event
116  edm::Handle<reco::VertexCollection> vertexHandle = iEvent.getHandle(vertexToken_);
117 
118  math::XYZPoint theMainVtxPos(0, 0, 0);
119  reco::Vertex theMainVertex = vertexHandle.product()->front();
120 
121  if (vertexHandle.isValid()) {
122  const reco::VertexCollection* vertices = vertexHandle.product();
123  if ((*vertices)[0].isValid()) {
124  auto theMainVtx = (*vertices)[0];
125  theMainVtxPos.SetXYZ(theMainVtx.position().x(), theMainVtx.position().y(), theMainVtx.position().z());
126  } else {
127  edm::LogWarning("DiMuonVertexMonitor") << "hardest primary vertex in the event is not valid!";
128  }
129  } else {
130  edm::LogWarning("DiMuonVertexMonitor") << "invalid vertex collection encountered!";
131  }
132 
133  const math::XYZPoint myVertex(
134  mumuTransientVtx.position().x(), mumuTransientVtx.position().y(), mumuTransientVtx.position().z());
135  const math::XYZPoint deltaVtx(
136  theMainVtxPos.x() - myVertex.x(), theMainVtxPos.y() - myVertex.y(), theMainVtxPos.z() - myVertex.z());
137 
138  if (theMainVertex.isValid()) {
139  // fill the impact parameter plots
140  for (const auto& track : myTracks) {
141  hdxy_->Fill(track->dxy(theMainVtxPos) * cmToum);
142  hdz_->Fill(track->dz(theMainVtxPos) * cmToum);
143  hdxyErr_->Fill(track->dxyError() * cmToum);
144  hdzErr_->Fill(track->dzError() * cmToum);
145 
146  const auto& ttrk = theB->build(track);
147  Global3DVector dir(track->px(), track->py(), track->pz());
148  const auto& ip2d = IPTools::signedTransverseImpactParameter(ttrk, dir, theMainVertex);
149  const auto& ip3d = IPTools::signedImpactParameter3D(ttrk, dir, theMainVertex);
150 
151  hIP2d_->Fill(ip2d.second.value() * cmToum);
152  hIP3d_->Fill(ip3d.second.value() * cmToum);
153  hIP2dsig_->Fill(ip2d.second.significance());
154  hIP3dsig_->Fill(ip3d.second.significance());
155  }
156 
157  // Z Vertex distance in the xy plane
158  VertexDistanceXY vertTool;
159  double distance = vertTool.distance(mumuTransientVtx, theMainVertex).value();
160  double dist_err = vertTool.distance(mumuTransientVtx, theMainVertex).error();
161 
163  hSVDistErr_->Fill(dist_err * cmToum);
164  hSVDistSig_->Fill(distance / dist_err);
165 
166  // Z Vertex distance in 3D
167  VertexDistance3D vertTool3D;
168  double distance3D = vertTool3D.distance(mumuTransientVtx, theMainVertex).value();
169  double dist3D_err = vertTool3D.distance(mumuTransientVtx, theMainVertex).error();
170 
171  hSVDist3D_->Fill(distance3D * cmToum);
172  hSVDist3DErr_->Fill(dist3D_err * cmToum);
173  hSVDist3DSig_->Fill(distance3D / dist3D_err);
174 
175  // cut on the PV - SV distance
176  if (distance * cmToum < maxSVdist_) {
177  double cosphi = (ZpT.x() * deltaVtx.x() + ZpT.y() * deltaVtx.y()) /
178  (sqrt(ZpT.x() * ZpT.x() + ZpT.y() * ZpT.y()) *
179  sqrt(deltaVtx.x() * deltaVtx.x() + deltaVtx.y() * deltaVtx.y()));
180 
181  double cosphi3D = (Zp.x() * deltaVtx.x() + Zp.y() * deltaVtx.y() + Zp.z() * deltaVtx.z()) /
182  (sqrt(Zp.x() * Zp.x() + Zp.y() * Zp.y() + Zp.z() * Zp.z()) *
183  sqrt(deltaVtx.x() * deltaVtx.x() + deltaVtx.y() * deltaVtx.y() + deltaVtx.z() * deltaVtx.z()));
184 
185  hCosPhi_->Fill(cosphi);
186  hCosPhi3D_->Fill(cosphi3D);
187  // inverted
188  hCosPhiInv_->Fill(-cosphi);
189  hCosPhiInv3D_->Fill(-cosphi3D);
190  }
191  } else {
192  edm::LogWarning("DiMuonVertexMonitor") << "hardest primary vertex in the event is not valid!";
193  }
194 }
195 
198  desc.add<edm::InputTag>("muonTracks", edm::InputTag("ALCARECOTkAlDiMuon"));
199  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
200  desc.add<std::string>("FolderName", "DiMuonVertexMonitor");
201  desc.add<double>("maxSVdist", 50.);
202  descriptions.addWithDefaultLabel(desc);
203 }
204 
MonitorElement * hdxyErr_
const std::string MEFolderName_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
float totalChiSquared() const
MonitorElement * hIP2d_
MonitorElement * hCosPhiInv_
GlobalPoint position() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
MonitorElement * hSVDist3DErr_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
MonitorElement * hIP2dsig_
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
MonitorElement * hSVProb_
T z() const
Definition: PV3DBase.h:61
static constexpr float mumass2
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
MonitorElement * hdz_
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:81
MonitorElement * hCosPhi_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
float degreesOfFreedom() const
MonitorElement * hIP3dsig_
MonitorElement * hdxy_
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
MonitorElement * hCosPhiInv3D_
reco::TransientTrack build(const reco::Track *p) const
void Fill(long long x)
MonitorElement * hSVDist3D_
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
MonitorElement * hSVDist3DSig_
DiMuonVertexMonitor(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
bool isValid() const
T sqrt(T t)
Definition: SSEVec.h:19
const edm::EDGetTokenT< reco::TrackCollection > tracksToken_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * hSVDistSig_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Measurement1D distance(const GlobalPoint &vtx1Position, const GlobalError &vtx1PositionError, const GlobalPoint &vtx2Position, const GlobalError &vtx2PositionError) const override
void analyze(const edm::Event &, const edm::EventSetup &) override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
MonitorElement * hTrackInvMass_
MonitorElement * hSVDist_
bool isValid() const
Definition: HandleBase.h:70
double value() const
Definition: Measurement1D.h:25
MonitorElement * hIP3d_
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::VertexCollection > vertexToken_
MonitorElement * hSVDistErr_
double error() const
Definition: Measurement1D.h:27
MonitorElement * hCosPhi3D_
MonitorElement * hdzErr_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
static constexpr float cmToum
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:72
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > ttbESToken_
Definition: Run.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)