CMS 3D CMS Logo

HLTDisplacedmumumuVtxProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 
20 
21 using namespace edm;
22 using namespace reco;
23 using namespace std;
24 using namespace trigger;
25 //
26 // constructors and destructor
27 //
29  : transientTrackRecordToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
30  srcTag_(iConfig.getParameter<edm::InputTag>("Src")),
31  srcToken_(consumes<reco::RecoChargedCandidateCollection>(srcTag_)),
32  previousCandTag_(iConfig.getParameter<edm::InputTag>("PreviousCandTag")),
33  previousCandToken_(consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
34  maxEta_(iConfig.getParameter<double>("MaxEta")),
35  minPt_(iConfig.getParameter<double>("MinPt")),
36  minPtTriplet_(iConfig.getParameter<double>("MinPtTriplet")),
37  minInvMass_(iConfig.getParameter<double>("MinInvMass")),
38  maxInvMass_(iConfig.getParameter<double>("MaxInvMass")),
39  chargeOpt_(iConfig.getParameter<int>("ChargeOpt")) {
40  produces<VertexCollection>();
41 }
42 
44 
47  desc.add<edm::InputTag>("Src", edm::InputTag("hltL3MuonCandidates"));
48  desc.add<edm::InputTag>("PreviousCandTag", edm::InputTag(""));
49  desc.add<double>("MaxEta", 2.5);
50  desc.add<double>("MinPt", 0.0);
51  desc.add<double>("MinPtTriplet", 0.0);
52  desc.add<double>("MinInvMass", 1.0);
53  desc.add<double>("MaxInvMass", 20.0);
54  desc.add<int>("ChargeOpt", -1);
55  descriptions.add("hltDisplacedmumumuVtxProducer", desc);
56 }
57 
58 // ------------ method called on each new Event ------------
60  double const MuMass = 0.106;
61  double const MuMass2 = MuMass * MuMass;
62 
63  // get hold of muon trks
65  iEvent.getByToken(srcToken_, mucands);
66 
67  // get the transient track builder
68  auto const& theB = iSetup.getHandle(transientTrackRecordToken_);
69 
70  std::unique_ptr<VertexCollection> vertexCollection(new VertexCollection());
71 
72  // look at all mucands, check cuts and make vertices
73  double e1, e2, e3;
75 
76  RecoChargedCandidateCollection::const_iterator cand1;
77  RecoChargedCandidateCollection::const_iterator cand2;
78  RecoChargedCandidateCollection::const_iterator cand3;
79 
80  // get the objects passing the previous filter
82  iEvent.getByToken(previousCandToken_, previousCands);
83 
84  vector<RecoChargedCandidateRef> vPrevCands;
85  previousCands->getObjects(TriggerMuon, vPrevCands);
86 
87  for (cand1 = mucands->begin(); cand1 != mucands->end(); cand1++) {
88  TrackRef tk1 = cand1->get<TrackRef>();
89  LogDebug("HLTDisplacedMumumuFilter") << " 1st muon in loop: q*pt= " << cand1->charge() * cand1->pt()
90  << ", eta= " << cand1->eta() << ", hits= " << tk1->numberOfValidHits();
91 
92  //first check if this muon passed the previous filter
93  if (!checkPreviousCand(tk1, vPrevCands))
94  continue;
95 
96  // cuts
97  if (fabs(cand1->eta()) > maxEta_)
98  continue;
99  if (cand1->pt() < minPt_)
100  continue;
101 
102  cand2 = cand1;
103  cand2++;
104  for (; cand2 != mucands->end(); cand2++) {
105  TrackRef tk2 = cand2->get<TrackRef>();
106 
107  // eta cut
108  LogDebug("HLTMuonDimuonFilter") << " 2nd muon in loop: q*pt= " << cand2->charge() * cand2->pt()
109  << ", eta= " << cand2->eta() << ", hits= " << tk2->numberOfValidHits()
110  << ", d0= " << tk2->d0();
111  //first check if this muon passed the previous filter
112  if (!checkPreviousCand(tk2, vPrevCands))
113  continue;
114 
115  // cuts
116  if (fabs(cand2->eta()) > maxEta_)
117  continue;
118  if (cand2->pt() < minPt_)
119  continue;
120 
121  cand3 = cand2;
122  cand3++;
123  for (; cand3 != mucands->end(); cand3++) {
124  TrackRef tk3 = cand3->get<TrackRef>();
125 
126  // eta cut
127  LogDebug("HLTMuonDimuonFilter") << " 3rd muon in loop: q*pt= " << cand3->charge() * cand3->pt()
128  << ", eta= " << cand3->eta() << ", hits= " << tk3->numberOfValidHits()
129  << ", d0= " << tk3->d0();
130  //first check if this muon passed the previous filter
131  if (!checkPreviousCand(tk3, vPrevCands))
132  continue;
133 
134  // cuts
135  if (fabs(cand3->eta()) > maxEta_)
136  continue;
137  if (cand3->pt() < minPt_)
138  continue;
139 
140  // opposite sign or same sign
141  if (chargeOpt_ > 0) {
142  if (fabs(cand1->charge() + cand2->charge() + cand3->charge()) != chargeOpt_)
143  continue;
144  }
145 
146  // Combined dimuon system
147  e1 = sqrt(cand1->momentum().Mag2() + MuMass2);
148  e2 = sqrt(cand2->momentum().Mag2() + MuMass2);
149  e3 = sqrt(cand3->momentum().Mag2() + MuMass2);
150  p1 = Particle::LorentzVector(cand1->px(), cand1->py(), cand1->pz(), e1);
151  p2 = Particle::LorentzVector(cand2->px(), cand2->py(), cand2->pz(), e2);
152  p3 = Particle::LorentzVector(cand3->px(), cand3->py(), cand3->pz(), e3);
153  p = p1 + p2 + p3;
154 
155  if (p.pt() < minPtTriplet_)
156  continue;
157 
158  double invmass = abs(p.mass());
159  LogDebug("HLTDisplacedMumumuFilter") << " ... 1-2 invmass= " << invmass;
160 
161  if (invmass < minInvMass_)
162  continue;
163  if (invmass > maxInvMass_)
164  continue;
165 
166  // do the vertex fit
167  vector<TransientTrack> t_tks;
168  TransientTrack ttkp1 = (*theB).build(&tk1);
169  TransientTrack ttkp2 = (*theB).build(&tk2);
170  TransientTrack ttkp3 = (*theB).build(&tk3);
171  t_tks.push_back(ttkp1);
172  t_tks.push_back(ttkp2);
173  t_tks.push_back(ttkp3);
174 
175  if (t_tks.size() != 3)
176  continue;
177 
178  KalmanVertexFitter kvf;
179  TransientVertex tv = kvf.vertex(t_tks);
180 
181  if (!tv.isValid())
182  continue;
183 
184  Vertex vertex = tv;
185 
186  // put vertex in the event
187  vertexCollection->push_back(vertex);
188  }
189  }
190  }
192 }
193 
195  const vector<RecoChargedCandidateRef>& refVect) const {
196  bool ok = false;
197  for (auto& i : refVect) {
198  if (i->get<TrackRef>() == trackref) {
199  ok = true;
200  break;
201  }
202  }
203  return ok;
204 }
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
HLTDisplacedmumumuVtxProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackRecordToken_
int iEvent
Definition: GenABIO.cc:224
bool isValid() const
T sqrt(T t)
Definition: SSEVec.h:23
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > srcToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
bool checkPreviousCand(const reco::TrackRef &trackref, const std::vector< reco::RecoChargedCandidateRef > &ref2) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:226
def move(src, dest)
Definition: eostools.py:511
~HLTDisplacedmumumuVtxProducer() override
math::PtEtaPhiELorentzVectorF LorentzVector
#define LogDebug(id)