CMS 3D CMS Logo

HLTmumutktkVtxProducer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 #include <vector>
4 
19 #include "HLTmumutktkVtxProducer.h"
20 
21 using namespace edm;
22 using namespace reco;
23 using namespace std;
24 using namespace trigger;
25 
26 // ----------------------------------------------------------------------
28  : transientTrackRecordToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
29  muCandTag_(iConfig.getParameter<edm::InputTag>("MuCand")),
30  muCandToken_(consumes<reco::RecoChargedCandidateCollection>(muCandTag_)),
31  trkCandTag_(iConfig.getParameter<edm::InputTag>("TrackCand")),
32  trkCandToken_(consumes<reco::RecoChargedCandidateCollection>(trkCandTag_)),
33  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
34  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
35  mfName_(iConfig.getParameter<std::string>("SimpleMagneticField")),
36  idealMagneticFieldRecordToken_(esConsumes(edm::ESInputTag("", mfName_))),
37  thirdTrackMass_(iConfig.getParameter<double>("ThirdTrackMass")),
38  fourthTrackMass_(iConfig.getParameter<double>("FourthTrackMass")),
39  maxEta_(iConfig.getParameter<double>("MaxEta")),
40  minPt_(iConfig.getParameter<double>("MinPt")),
41  minInvMass_(iConfig.getParameter<double>("MinInvMass")),
42  maxInvMass_(iConfig.getParameter<double>("MaxInvMass")),
43  minTrkTrkMass_(iConfig.getParameter<double>("MinTrkTrkMass")),
44  maxTrkTrkMass_(iConfig.getParameter<double>("MaxTrkTrkMass")),
45  minD0Significance_(iConfig.getParameter<double>("MinD0Significance")),
46  oppositeSign_(iConfig.getParameter<bool>("OppositeSign")),
47  overlapDR_(iConfig.getParameter<double>("OverlapDR")),
48  beamSpotTag_(iConfig.getParameter<edm::InputTag>("BeamSpotTag")),
49  beamSpotToken_(consumes<reco::BeamSpot>(beamSpotTag_)) {
50  produces<VertexCollection>();
51 }
52 
53 // ----------------------------------------------------------------------
55 
58  desc.add<edm::InputTag>("MuCand", edm::InputTag("hltMuTracks"));
59  desc.add<edm::InputTag>("TrackCand", edm::InputTag("hltMumukAllConeTracks"));
60  desc.add<edm::InputTag>("PreviousCandTag", edm::InputTag("hltDisplacedmumuFilterDoubleMu4Jpsi"));
61  desc.add<std::string>("SimpleMagneticField", "");
62  desc.add<double>("ThirdTrackMass", 0.493677);
63  desc.add<double>("FourthTrackMass", 0.493677);
64  desc.add<double>("MaxEta", 2.5);
65  desc.add<double>("MinPt", 0.0);
66  desc.add<double>("MinInvMass", 0.0);
67  desc.add<double>("MaxInvMass", 99999.);
68  desc.add<double>("MinTrkTrkMass", 0.0);
69  desc.add<double>("MaxTrkTrkMass", 99999.);
70  desc.add<double>("MinD0Significance", 0.0);
71  desc.add<bool>("OppositeSign", false);
72  desc.add<double>("OverlapDR", 0.001);
73  desc.add<edm::InputTag>("BeamSpotTag", edm::InputTag("hltOfflineBeamSpot"));
74  descriptions.add("HLTmumutktkVtxProducer", desc);
75 }
76 
77 // ----------------------------------------------------------------------
79  const double MuMass(0.106);
80  const double MuMass2(MuMass * MuMass);
81  const double thirdTrackMass2(thirdTrackMass_ * thirdTrackMass_);
82  const double fourthTrackMass2(fourthTrackMass_ * fourthTrackMass_);
83 
84  // get hold of muon trks
86  iEvent.getByToken(muCandToken_, mucands);
87 
88  // get the transient track builder
89  auto const& theB = iSetup.getHandle(transientTrackRecordToken_);
90 
91  // get the beamspot position
92  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
93  iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
94 
95  // get the b field
96  auto const& bFieldHandle = iSetup.getHandle(idealMagneticFieldRecordToken_);
97  const MagneticField* magField = bFieldHandle.product();
98  TSCBLBuilderNoMaterial blsBuilder;
99 
100  // get track candidates around displaced muons
102  iEvent.getByToken(trkCandToken_, trkcands);
103 
104  unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
105 
106  // Ref to Candidate object to be recorded in filter object
109  RecoChargedCandidateRef refTrk1;
110  RecoChargedCandidateRef refTrk2;
111 
112  double e1, e2, e3_m3, e3_m4, e4_m3, e4_m4;
113  Particle::LorentzVector p, pBar, p1, p2, p3_m3, p3_m4, p4_m3, p4_m4, p_m3m4, p_m4m3;
114 
115  if (mucands->size() < 2)
116  return;
117  if (trkcands->size() < 2)
118  return;
119 
120  RecoChargedCandidateCollection::const_iterator mucand1;
121  RecoChargedCandidateCollection::const_iterator mucand2;
122  RecoChargedCandidateCollection::const_iterator trkcand1;
123  RecoChargedCandidateCollection::const_iterator trkcand2;
124 
125  // get the objects passing the previous filter
127  iEvent.getByToken(previousCandToken_, previousCands);
128 
129  vector<RecoChargedCandidateRef> vPrevCands;
130  previousCands->getObjects(TriggerMuon, vPrevCands);
131 
132  for (mucand1 = mucands->begin(); mucand1 != mucands->end(); ++mucand1) {
133  TrackRef trk1 = mucand1->get<TrackRef>();
134  LogDebug("HLTmumutktkVtxProducer") << " 1st muon: q*pt= " << trk1->charge() * trk1->pt() << ", eta= " << trk1->eta()
135  << ", hits= " << trk1->numberOfValidHits();
136 
137  //first check if this muon passed the previous filter
138  if (!checkPreviousCand(trk1, vPrevCands))
139  continue;
140  // eta and pt cut
141  if (fabs(trk1->eta()) > maxEta_)
142  continue;
143  if (trk1->pt() < minPt_)
144  continue;
145 
146  mucand2 = mucand1;
147  ++mucand2;
148  for (; mucand2 != mucands->end(); mucand2++) {
149  TrackRef trk2 = mucand2->get<TrackRef>();
150  if (overlap(trk1, trk2))
151  continue;
152 
153  LogDebug("HLTDisplacedMumukFilter") << " 2nd muon: q*pt= " << trk2->charge() * trk2->pt()
154  << ", eta= " << trk2->eta() << ", hits= " << trk2->numberOfValidHits();
155 
156  //first check if this muon passed the previous filter
157  if (!checkPreviousCand(trk2, vPrevCands))
158  continue;
159  // eta and pt cut
160  if (fabs(trk2->eta()) > maxEta_)
161  continue;
162  if (trk2->pt() < minPt_)
163  continue;
164 
165  //loop on track collection - trk1
166  for (trkcand1 = trkcands->begin(); trkcand1 != trkcands->end(); ++trkcand1) {
167  TrackRef trk3 = trkcand1->get<TrackRef>();
168 
169  if (overlap(trk1, trk3))
170  continue;
171  if (overlap(trk2, trk3))
172  continue;
173 
174  LogDebug("HLTDisplacedMumukFilter") << " 3rd track: q*pt= " << trk3->charge() * trk3->pt()
175  << ", eta= " << trk3->eta() << ", hits= " << trk3->numberOfValidHits();
176 
177  // eta and pt cut
178  if (fabs(trk3->eta()) > maxEta_)
179  continue;
180  if (trk3->pt() < minPt_)
181  continue;
182 
183  FreeTrajectoryState InitialFTS_Trk3 = initialFreeState(*trk3, magField);
184  TrajectoryStateClosestToBeamLine tscb_Trk3(blsBuilder(InitialFTS_Trk3, *recoBeamSpotHandle));
185  double d0sigTrk3 = tscb_Trk3.transverseImpactParameter().significance();
186  if (d0sigTrk3 < minD0Significance_)
187  continue;
188 
189  //loop on track collection - trk2
190  for (trkcand2 = trkcands->begin(); trkcand2 != trkcands->end(); ++trkcand2) {
191  TrackRef trk4 = trkcand2->get<TrackRef>();
192 
193  if (oppositeSign_) {
194  if (trk3->charge() * trk4->charge() != -1)
195  continue;
196  }
197  if (overlap(trk1, trk4))
198  continue;
199  if (overlap(trk2, trk4))
200  continue;
201  if (overlap(trk3, trk4))
202  continue;
203 
204  LogDebug("HLTDisplacedMumukFilter") << " 4th track: q*pt= " << trk4->charge() * trk4->pt()
205  << ", eta= " << trk4->eta() << ", hits= " << trk4->numberOfValidHits();
206 
207  // eta and pt cut
208  if (fabs(trk4->eta()) > maxEta_)
209  continue;
210  if (trk4->pt() < minPt_)
211  continue;
212 
213  FreeTrajectoryState InitialFTS_Trk4 = initialFreeState(*trk4, magField);
214  TrajectoryStateClosestToBeamLine tscb_Trk4(blsBuilder(InitialFTS_Trk4, *recoBeamSpotHandle));
215  double d0sigTrk4 = tscb_Trk4.transverseImpactParameter().significance();
216  if (d0sigTrk4 < minD0Significance_)
217  continue;
218 
219  // Combined system
220  e1 = sqrt(trk1->momentum().Mag2() + MuMass2);
221  e2 = sqrt(trk2->momentum().Mag2() + MuMass2);
222  e3_m3 = sqrt(trk3->momentum().Mag2() + thirdTrackMass2);
223  e3_m4 = sqrt(trk3->momentum().Mag2() + fourthTrackMass2);
224  e4_m3 = sqrt(trk4->momentum().Mag2() + thirdTrackMass2);
225  e4_m4 = sqrt(trk4->momentum().Mag2() + fourthTrackMass2);
226 
227  p1 = Particle::LorentzVector(trk1->px(), trk1->py(), trk1->pz(), e1);
228  p2 = Particle::LorentzVector(trk2->px(), trk2->py(), trk2->pz(), e2);
229  p3_m3 = Particle::LorentzVector(trk3->px(), trk3->py(), trk3->pz(), e3_m3);
230  p3_m4 = Particle::LorentzVector(trk3->px(), trk3->py(), trk3->pz(), e3_m4);
231  p4_m3 = Particle::LorentzVector(trk4->px(), trk4->py(), trk4->pz(), e4_m3);
232  p4_m4 = Particle::LorentzVector(trk4->px(), trk4->py(), trk4->pz(), e4_m4);
233 
234  p = p1 + p2 + p3_m3 + p4_m4;
235  pBar = p1 + p2 + p3_m4 + p4_m3;
236  p_m3m4 = p3_m3 + p4_m4;
237  p_m4m3 = p3_m4 + p4_m3;
238 
239  //invariant mass cut
240  if (!((p_m3m4.mass() > minTrkTrkMass_ && p_m3m4.mass() < maxTrkTrkMass_) ||
241  (p_m4m3.mass() > minTrkTrkMass_ && p_m4m3.mass() < maxTrkTrkMass_)))
242  continue;
243  if (!((p.mass() > minInvMass_ && p.mass() < maxInvMass_) ||
244  (pBar.mass() > minInvMass_ && pBar.mass() < maxInvMass_)))
245  continue;
246 
247  // do the vertex fit
248  vector<TransientTrack> t_tks;
249  t_tks.push_back((*theB).build(&trk1));
250  t_tks.push_back((*theB).build(&trk2));
251  t_tks.push_back((*theB).build(&trk3));
252  t_tks.push_back((*theB).build(&trk4));
253  if (t_tks.size() != 4)
254  continue;
255 
256  KalmanVertexFitter kvf;
257  TransientVertex tv = kvf.vertex(t_tks);
258  if (!tv.isValid())
259  continue;
260  Vertex vertex = tv;
261 
262  vertexCollection->push_back(vertex);
263  }
264  }
265  }
266  }
268 }
269 
272  GlobalPoint gpos(pos);
273  Basic3DVector<float> mom(tk.momentum());
274  GlobalVector gmom(mom);
275  GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
277  return FreeTrajectoryState(par, err);
278 }
279 
280 bool HLTmumutktkVtxProducer::overlap(const TrackRef& trackref1, const TrackRef& trackref2) {
281  if (deltaR(trackref1->eta(), trackref1->phi(), trackref2->eta(), trackref2->phi()) < overlapDR_)
282  return true;
283  return false;
284 }
285 
287  const vector<RecoChargedCandidateRef>& refVect) const {
288  bool ok = false;
289  for (auto& i : refVect) {
290  if (i->get<TrackRef>() == trackref) {
291  ok = true;
292  break;
293  }
294  }
295  return ok;
296 }
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool checkPreviousCand(const reco::TrackRef &trackref, const std::vector< reco::RecoChargedCandidateRef > &ref2) const
void produce(edm::Event &, const edm::EventSetup &) override
bool overlap(const reco::TrackRef &trackref1, const reco::TrackRef &trackref2)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
static FreeTrajectoryState initialFreeState(const reco::Track &, const MagneticField *)
~HLTmumutktkVtxProducer() override
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > trkCandToken_
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muCandToken_
int charge() const
track electric charge
Definition: TrackBase.h:597
int iEvent
Definition: GenABIO.cc:224
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:717
bool isValid() const
T sqrt(T t)
Definition: SSEVec.h:19
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackRecordToken_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:677
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
HLTmumutktkVtxProducer(const edm::ParameterSet &)
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > idealMagneticFieldRecordToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:665
double significance() const
Definition: Measurement1D.h:29
fixed size matrix
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
HLT enums.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
def move(src, dest)
Definition: eostools.py:511
math::PtEtaPhiELorentzVectorF LorentzVector
#define LogDebug(id)