CMS 3D CMS Logo

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