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 }
Vector3DBase
Definition: Vector3DBase.h:8
ConfigurationDescriptions.h
TSCBLBuilderNoMaterial.h
TrajectoryStateClosestToBeamLine
Definition: TrajectoryStateClosestToBeamLine.h:15
trigger::TriggerFilterObjectWithRefs
Definition: TriggerFilterObjectWithRefs.h:35
KalmanVertexFitter::vertex
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
Definition: KalmanVertexFitter.h:49
HLTmumutktkVtxProducer::initialFreeState
static FreeTrajectoryState initialFreeState(const reco::Track &, const MagneticField *)
Definition: HLTmumutktkVtxProducer.cc:270
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
FreeTrajectoryState.h
GlobalTrajectoryParameters.h
MessageLogger.h
KalmanVertexFitter.h
ESHandle.h
HLTmumutktkVtxProducer::minD0Significance_
const double minD0Significance_
Definition: HLTmumutktkVtxProducer.h:73
TransientVertex::isValid
bool isValid() const
Definition: TransientVertex.h:195
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLTmumutktkVtxProducer::minPt_
const double minPt_
Definition: HLTmumutktkVtxProducer.h:68
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
HLTmumutktkVtxProducer::maxTrkTrkMass_
const double maxTrkTrkMass_
Definition: HLTmumutktkVtxProducer.h:72
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
RecoCandidate.h
trigger::TriggerRefsCollections::getObjects
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
Definition: TriggerRefsCollections.h:590
reco::RecoChargedCandidateCollection
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
Definition: RecoChargedCandidateFwd.h:9
edm::Ref
Definition: AssociativeIterator.h:58
HLTmumutktkVtxProducer::HLTmumutktkVtxProducer
HLTmumutktkVtxProducer(const edm::ParameterSet &)
Definition: HLTmumutktkVtxProducer.cc:27
HLTmumutktkVtxProducer::idealMagneticFieldRecordToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > idealMagneticFieldRecordToken_
Definition: HLTmumutktkVtxProducer.h:63
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
BeamSpot.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HLTmumutktkVtxProducer::checkPreviousCand
bool checkPreviousCand(const reco::TrackRef &trackref, const std::vector< reco::RecoChargedCandidateRef > &ref2) const
Definition: HLTmumutktkVtxProducer.cc:286
HLTmumutktkVtxProducer::oppositeSign_
const bool oppositeSign_
Definition: HLTmumutktkVtxProducer.h:74
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
trigger::TriggerMuon
Definition: TriggerTypeDefs.h:79
reco::Track
Definition: Track.h:27
p2
double p2[4]
Definition: TauolaWrapper.h:90
reco::TrackBase::charge
int charge() const
track electric charge
Definition: TrackBase.h:596
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
TrajectoryStateClosestToBeamLine::transverseImpactParameter
Measurement1D transverseImpactParameter() const
Definition: TrajectoryStateClosestToBeamLine.cc:3
reco::TrackBase::covariance
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:716
Point3DBase< float, GlobalTag >
HLTmumutktkVtxProducer.h
HLTmumutktkVtxProducer::fourthTrackMass_
const double fourthTrackMass_
Definition: HLTmumutktkVtxProducer.h:66
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLTmumutktkVtxProducer::thirdTrackMass_
const double thirdTrackMass_
Definition: HLTmumutktkVtxProducer.h:65
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
HLTmumutktkVtxProducer::maxInvMass_
const double maxInvMass_
Definition: HLTmumutktkVtxProducer.h:70
HLTmumutktkVtxProducer::previousCandToken_
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
Definition: HLTmumutktkVtxProducer.h:60
Measurement1D::significance
double significance() const
Definition: Measurement1D.h:29
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
deltaR.h
HLTmumutktkVtxProducer::~HLTmumutktkVtxProducer
~HLTmumutktkVtxProducer() override
HLTmumutktkVtxProducer::trkCandToken_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > trkCandToken_
Definition: HLTmumutktkVtxProducer.h:58
StorageManager_cfg.e1
e1
Definition: StorageManager_cfg.py:16
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
p1
double p1[4]
Definition: TauolaWrapper.h:89
HLTmumutktkVtxProducer::overlapDR_
const double overlapDR_
Definition: HLTmumutktkVtxProducer.h:75
TransientVertex
Definition: TransientVertex.h:18
edm::EventSetup
Definition: EventSetup.h:58
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
HLTmumutktkVtxProducer::maxEta_
const double maxEta_
Definition: HLTmumutktkVtxProducer.h:67
reco::TrackBase::vertex
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead
Definition: TrackBase.h:676
reco::JetExtendedAssociation::LorentzVector
math::PtEtaPhiELorentzVectorF LorentzVector
Definition: JetExtendedAssociation.h:25
VertexFwd.h
TransientVertex.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HLTmumutktkVtxProducer::muCandToken_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > muCandToken_
Definition: HLTmumutktkVtxProducer.h:56
HLTmumutktkVtxProducer::beamSpotToken_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: HLTmumutktkVtxProducer.h:77
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
RecoChargedCandidate.h
HLTmumutktkVtxProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HLTmumutktkVtxProducer.cc:78
TSCBLBuilderNoMaterial
Definition: TSCBLBuilderNoMaterial.h:13
spclusmultinvestigator_cfi.vertexCollection
vertexCollection
Definition: spclusmultinvestigator_cfi.py:4
HLTmumutktkVtxProducer::minInvMass_
const double minInvMass_
Definition: HLTmumutktkVtxProducer.h:69
HLTmumutktkVtxProducer::transientTrackRecordToken_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackRecordToken_
Definition: HLTmumutktkVtxProducer.h:53
trigger
Definition: HLTPrescaleTableCond.h:8
reco::TrackBase::momentum
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
edm::InputTag
Definition: InputTag.h:15
HLTmumutktkVtxProducer::overlap
bool overlap(const reco::TrackRef &trackref1, const reco::TrackRef &trackref2)
Definition: HLTmumutktkVtxProducer.cc:280
Basic3DVector< float >
reco::Vertex
Definition: Vertex.h:35
HLTmumutktkVtxProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTmumutktkVtxProducer.cc:56
HLTmumutktkVtxProducer::minTrkTrkMass_
const double minTrkTrkMass_
Definition: HLTmumutktkVtxProducer.h:71
KalmanVertexFitter
Definition: KalmanVertexFitter.h:22