CMS 3D CMS Logo

HLTmumutkVtxProducer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 #include <vector>
4 
18 #include "HLTmumutkVtxProducer.h"
19 
20 using namespace edm;
21 using namespace reco;
22 using namespace std;
23 using namespace trigger;
24 
26  : transientTrackRecordToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
27  muCandTag_(iConfig.getParameter<edm::InputTag>("MuCand")),
28  muCandToken_(consumes<reco::RecoChargedCandidateCollection>(muCandTag_)),
29  trkCandTag_(iConfig.getParameter<edm::InputTag>("TrackCand")),
30  trkCandToken_(consumes<reco::RecoChargedCandidateCollection>(trkCandTag_)),
31  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
32  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
33  mfName_(iConfig.getParameter<std::string>("SimpleMagneticField")),
34  idealMagneticFieldRecordToken_(esConsumes(edm::ESInputTag("", mfName_))),
35  thirdTrackMass_(iConfig.getParameter<double>("ThirdTrackMass")),
36  maxEta_(iConfig.getParameter<double>("MaxEta")),
37  minPt_(iConfig.getParameter<double>("MinPt")),
38  minInvMass_(iConfig.getParameter<double>("MinInvMass")),
39  maxInvMass_(iConfig.getParameter<double>("MaxInvMass")),
40  minD0Significance_(iConfig.getParameter<double>("MinD0Significance")),
41  // minimum delta-R^2 threshold (with sign) for non-overlapping tracks
42  overlapDR2_(iConfig.getParameter<double>("OverlapDR") * std::abs(iConfig.getParameter<double>("OverlapDR"))),
43  beamSpotTag_(iConfig.getParameter<edm::InputTag>("BeamSpotTag")),
44  beamSpotToken_(consumes<reco::BeamSpot>(beamSpotTag_)) {
45  produces<VertexCollection>();
46 }
47 
50  desc.add<edm::InputTag>("MuCand", edm::InputTag("hltMuTracks"));
51  desc.add<edm::InputTag>("TrackCand", edm::InputTag("hltMumukAllConeTracks"));
52  desc.add<edm::InputTag>("PreviousCandTag", edm::InputTag("hltDisplacedmumuFilterDoubleMu4Jpsi"));
53  desc.add<std::string>("SimpleMagneticField", "");
54  desc.add<double>("ThirdTrackMass", 0.493677);
55  desc.add<double>("MaxEta", 2.5);
56  desc.add<double>("MinPt", 3.0);
57  desc.add<double>("MinInvMass", 0.0);
58  desc.add<double>("MaxInvMass", 99999.);
59  desc.add<double>("MinD0Significance", 0.0);
60  desc.add<double>("OverlapDR", 1.44e-4);
61  desc.add<edm::InputTag>("BeamSpotTag", edm::InputTag("hltOfflineBeamSpot"));
62  descriptions.add("HLTmumutkVtxProducer", desc);
63 }
64 
66  const double MuMass(0.106);
67  const double MuMass2(MuMass * MuMass);
68  const double thirdTrackMass2(thirdTrackMass_ * thirdTrackMass_);
69 
70  // get hold of muon trks
72  iEvent.getByToken(muCandToken_, mucands);
73 
74  // get the transient track builder
75  auto const& theB = iSetup.getHandle(transientTrackRecordToken_);
76 
77  //get the beamspot position
78  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
79  iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
80 
81  //get the b field
82  auto const& bFieldHandle = iSetup.getHandle(idealMagneticFieldRecordToken_);
83  const MagneticField* magField = bFieldHandle.product();
84  TSCBLBuilderNoMaterial blsBuilder;
85 
86  // get track candidates around displaced muons
88  iEvent.getByToken(trkCandToken_, trkcands);
89 
90  unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
91 
92  // Ref to Candidate object to be recorded in filter object
96 
97  double e1, e2, e3;
99 
100  if (mucands->size() < 2)
101  return;
102  if (trkcands->empty())
103  return;
104 
105  RecoChargedCandidateCollection::const_iterator mucand1;
106  RecoChargedCandidateCollection::const_iterator mucand2;
107  RecoChargedCandidateCollection::const_iterator trkcand;
108 
109  // get the objects passing the previous filter
111  iEvent.getByToken(previousCandToken_, previousCands);
112 
113  vector<RecoChargedCandidateRef> vPrevCands;
114  previousCands->getObjects(TriggerMuon, vPrevCands);
115 
116  for (mucand1 = mucands->begin(); mucand1 != mucands->end(); ++mucand1) {
117  TrackRef trk1 = mucand1->get<TrackRef>();
118  LogDebug("HLTmumutkVtxProducer") << " 1st muon: q*pt= " << trk1->charge() * trk1->pt() << ", eta= " << trk1->eta()
119  << ", hits= " << trk1->numberOfValidHits();
120 
121  //first check if this muon passed the previous filter
122  if (!checkPreviousCand(trk1, vPrevCands))
123  continue;
124 
125  // eta and pt cut
126  if (fabs(trk1->eta()) > maxEta_)
127  continue;
128  if (trk1->pt() < minPt_)
129  continue;
130 
131  mucand2 = mucand1;
132  ++mucand2;
133  for (; mucand2 != mucands->end(); mucand2++) {
134  TrackRef trk2 = mucand2->get<TrackRef>();
135 
136  LogDebug("HLTDisplacedMumukFilter") << " 2nd muon: q*pt= " << trk2->charge() * trk2->pt()
137  << ", eta= " << trk2->eta() << ", hits= " << trk2->numberOfValidHits();
138 
139  //first check if this muon passed the previous filter
140  if (!checkPreviousCand(trk2, vPrevCands))
141  continue;
142  // eta and pt cut
143  if (fabs(trk2->eta()) > maxEta_)
144  continue;
145  if (trk2->pt() < minPt_)
146  continue;
147 
148  //loop on track collection
149  for (trkcand = trkcands->begin(); trkcand != trkcands->end(); ++trkcand) {
150  TrackRef trk3 = trkcand->get<TrackRef>();
151  if (overlap(trk1, trk3))
152  continue;
153  if (overlap(trk2, trk3))
154  continue;
155 
156  LogDebug("HLTDisplacedMumukFilter") << " 3rd track: q*pt= " << trk3->charge() * trk3->pt()
157  << ", eta= " << trk3->eta() << ", hits= " << trk3->numberOfValidHits();
158 
159  // eta and pt cut
160  if (fabs(trk3->eta()) > maxEta_)
161  continue;
162  if (trk3->pt() < minPt_)
163  continue;
164 
165  // Combined system
166  e1 = sqrt(trk1->momentum().Mag2() + MuMass2);
167  e2 = sqrt(trk2->momentum().Mag2() + MuMass2);
168  e3 = sqrt(trk3->momentum().Mag2() + thirdTrackMass2);
169 
170  p1 = Particle::LorentzVector(trk1->px(), trk1->py(), trk1->pz(), e1);
171  p2 = Particle::LorentzVector(trk2->px(), trk2->py(), trk2->pz(), e2);
172  p3 = Particle::LorentzVector(trk3->px(), trk3->py(), trk3->pz(), e3);
173 
174  p = p1 + p2 + p3;
175 
176  //invariant mass cut
177  double invmass = abs(p.mass());
178  LogDebug("HLTDisplacedMumukFilter") << " Invmass= " << invmass;
179  if (invmass < minInvMass_)
180  continue;
181  if (invmass > maxInvMass_)
182  continue;
183 
184  // do the vertex fit
185  vector<TransientTrack> t_tks;
186  t_tks.push_back((*theB).build(&trk1));
187  t_tks.push_back((*theB).build(&trk2));
188  t_tks.push_back((*theB).build(&trk3));
189  if (t_tks.size() != 3)
190  continue;
191 
192  FreeTrajectoryState InitialFTS = initialFreeState(*trk3, magField);
193  TrajectoryStateClosestToBeamLine tscb(blsBuilder(InitialFTS, *recoBeamSpotHandle));
194  double d0sig = tscb.transverseImpactParameter().significance();
195  if (d0sig < minD0Significance_)
196  continue;
197 
198  KalmanVertexFitter kvf;
199  TransientVertex tv = kvf.vertex(t_tks);
200  if (!tv.isValid())
201  continue;
202  Vertex vertex = tv;
203 
204  // put vertex in the event
205  vertexCollection->push_back(vertex);
206  }
207  }
208  }
210 }
211 
214  GlobalPoint gpos(pos);
215  Basic3DVector<float> mom(tk.momentum());
216  GlobalVector gmom(mom);
217  GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
219  return FreeTrajectoryState(par, err);
220 }
221 
222 bool HLTmumutkVtxProducer::overlap(const TrackRef& trackref1, const TrackRef& trackref2) {
223  return (reco::deltaR2(trackref1->eta(), trackref1->phi(), trackref2->eta(), trackref2->phi()) < overlapDR2_);
224 }
225 
227  const vector<RecoChargedCandidateRef>& refVect) const {
228  bool ok = false;
229  for (auto& i : refVect) {
230  if (i->get<TrackRef>() == trackref) {
231  ok = true;
232  break;
233  }
234  }
235  return ok;
236 }
static FreeTrajectoryState initialFreeState(const reco::Track &, const MagneticField *)
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > idealMagneticFieldRecordToken_
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
bool overlap(const reco::TrackRef &trackref1, const reco::TrackRef &trackref2)
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackRecordToken_
int charge() const
track electric charge
Definition: TrackBase.h:596
int iEvent
Definition: GenABIO.cc:224
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:716
bool isValid() const
HLTmumutkVtxProducer(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:19
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > trkCandToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:676
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muCandToken_
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
double significance() const
Definition: Measurement1D.h:29
fixed size matrix
HLT enums.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
math::PtEtaPhiELorentzVectorF LorentzVector
bool checkPreviousCand(const reco::TrackRef &trackref, const std::vector< reco::RecoChargedCandidateRef > &ref2) const
#define LogDebug(id)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)