CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLTTriMuonIsolation.h
Go to the documentation of this file.
1 #ifndef HLTrigger_Muon_HLTTriMuonIsolation_h
2 #define HLTrigger_Muon_HLTTriMuonIsolation_h
3 
4 #include <iostream>
5 #include <string>
6 
13 
22 
24 public:
26  ~HLTTriMuonIsolation() override = default;
27  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30 private:
35 
41 
42  template <typename T>
43  static bool ptComparer(const T& cand_1, const T& cand_2) {
44  return cand_1.pt() > cand_2.pt();
45  }
46 
47  const double TwiceMuonMass_ = 2. * 0.1056583715; // in GeV
48 
49  const double Muon1PtCut_;
50  const double Muon2PtCut_;
51  const double Muon3PtCut_;
52  const double TriMuonPtCut_;
53  const double TriMuonEtaCut_;
54  const double ChargedRelIsoCut_;
55  const double ChargedAbsIsoCut_;
56  const double IsoConeSize_;
57  const double MatchingConeSize_;
58  const double MinTriMuonMass_;
59  const double MaxTriMuonMass_;
60  const double MaxTriMuonRadius_;
61  const int TriMuonAbsCharge_;
62  const double MaxDZ_;
63  const bool EnableRelIso_;
64  const bool EnableAbsIso_;
65 };
66 
68  : L3MuonsToken_(consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("L3MuonsSrc"))),
69  AllMuonsToken_(
70  consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("AllMuonsSrc"))),
71  L3DiMuonsFilterToken_(
72  consumes<trigger::TriggerFilterObjectWithRefs>(iConfig.getParameter<edm::InputTag>("L3DiMuonsFilterSrc"))),
73  IsoTracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("IsoTracksSrc"))),
74  Muon1PtCut_(iConfig.getParameter<double>("Muon1PtCut")),
75  Muon2PtCut_(iConfig.getParameter<double>("Muon2PtCut")),
76  Muon3PtCut_(iConfig.getParameter<double>("Muon3PtCut")),
77  TriMuonPtCut_(iConfig.getParameter<double>("TriMuonPtCut")),
78  TriMuonEtaCut_(iConfig.getParameter<double>("TriMuonEtaCut")),
79  ChargedRelIsoCut_(iConfig.getParameter<double>("ChargedRelIsoCut")),
80  ChargedAbsIsoCut_(iConfig.getParameter<double>("ChargedAbsIsoCut")),
81  IsoConeSize_(iConfig.getParameter<double>("IsoConeSize")),
82  MatchingConeSize_(iConfig.getParameter<double>("MatchingConeSize")),
83  MinTriMuonMass_(iConfig.getParameter<double>("MinTriMuonMass")),
84  MaxTriMuonMass_(iConfig.getParameter<double>("MaxTriMuonMass")),
85  MaxTriMuonRadius_(iConfig.getParameter<double>("MaxTriMuonRadius")),
86  TriMuonAbsCharge_(iConfig.getParameter<int>("TriMuonAbsCharge")),
87  MaxDZ_(iConfig.getParameter<double>("MaxDZ")),
88  EnableRelIso_(iConfig.getParameter<bool>("EnableRelIso")),
89  EnableAbsIso_(iConfig.getParameter<bool>("EnableAbsIso")) {
90  //register products
91  produces<reco::CompositeCandidateCollection>("Taus");
92  produces<reco::CompositeCandidateCollection>("SelectedTaus");
93 }
94 
96  std::unique_ptr<reco::CompositeCandidateCollection> Taus(new reco::CompositeCandidateCollection);
97  std::unique_ptr<reco::CompositeCandidateCollection> SelectedTaus(new reco::CompositeCandidateCollection);
98 
99  // Get the L3 muon candidates
101  iEvent.getByToken(L3MuonsToken_, L3MuCands);
102 
103  // Get the L3 muon candidates that passed the filter
105  iEvent.getByToken(L3DiMuonsFilterToken_, L3DiMuonsFilterCands);
106 
107  std::vector<reco::RecoChargedCandidateRef> PassedL3Muons;
108  L3DiMuonsFilterCands->getObjects(trigger::TriggerMuon, PassedL3Muons);
109 
110  // Get the Trk + L3 muon candidates (after merging)
112  iEvent.getByToken(AllMuonsToken_, AllMuCands);
113 
114  // Get iso tracks
116  iEvent.getByToken(IsoTracksToken_, IsoTracks);
117 
118  if (AllMuCands->size() >= 3 && L3MuCands->size() >= 2) {
119  // Create the 3-muon candidates
120  // loop over L3/Trk muons and create all combinations
121  auto AllMuCands_end = AllMuCands->end();
122  for (auto i = AllMuCands->begin(); i != AllMuCands_end - 2; ++i) {
123  // check that muon_i passes the previous filter
124  bool passingPreviousFilter_1 = false;
125  for (const auto& imu : PassedL3Muons) {
126  if (reco::deltaR2(i->momentum(), imu->momentum()) < (MatchingConeSize_ * MatchingConeSize_))
127  passingPreviousFilter_1 = true;
128  }
129  for (auto j = i + 1; j != AllMuCands_end - 1; ++j) {
130  // check that muon_j passes the previous filter
131  bool passingPreviousFilter_2 = false;
132  for (const auto& jmu : PassedL3Muons) {
133  if (reco::deltaR2(j->momentum(), jmu->momentum()) < (MatchingConeSize_ * MatchingConeSize_))
134  passingPreviousFilter_2 = true;
135  }
136  // if, at this point, no muons passed the previous filter just skip to the next iteration
137  if (!(passingPreviousFilter_1 || passingPreviousFilter_2))
138  continue;
139  for (auto k = j + 1; k != AllMuCands_end; ++k) {
140  // check that muon_k passes the previous filter
141  bool passingPreviousFilter_3 = false;
142  for (const auto& kmu : PassedL3Muons) {
143  if (reco::deltaR2(k->momentum(), kmu->momentum()) < (MatchingConeSize_ * MatchingConeSize_))
144  passingPreviousFilter_3 = true;
145  }
146  // at least two muons must have passed the previous di-muon filter
147  if (!((passingPreviousFilter_1 & passingPreviousFilter_2) ||
148  (passingPreviousFilter_1 & passingPreviousFilter_3) ||
149  (passingPreviousFilter_2 & passingPreviousFilter_3)))
150  continue;
151 
152  // Create a composite candidate to be a tau
154 
155  // sort the muons by pt and add them to the tau
157  daughters.reserve(3);
158 
159  daughters.push_back(*i);
160  daughters.push_back(*j);
161  daughters.push_back(*k);
162 
163  std::sort(daughters.begin(), daughters.end(), ptComparer<reco::RecoChargedCandidate>);
164 
165  // Muon kinematic selections
166  if (daughters[0].pt() < Muon1PtCut_)
167  continue;
168  if (daughters[1].pt() < Muon2PtCut_)
169  continue;
170  if (daughters[2].pt() < Muon3PtCut_)
171  continue;
172 
173  // assign the tau its daughters
174  tau.addDaughter((daughters)[0], "Muon_1");
175  tau.addDaughter((daughters)[1], "Muon_2");
176  tau.addDaughter((daughters)[2], "Muon_3");
177 
178  // start building the tau
179  int charge = daughters[0].charge() + daughters[1].charge() + daughters[2].charge();
180  math::XYZTLorentzVectorD taup4 = daughters[0].p4() + daughters[1].p4() + daughters[2].p4();
181  int tauPdgId = charge > 0 ? 15 : -15;
182 
183  tau.setP4(taup4);
184  tau.setCharge(charge);
185  tau.setPdgId(tauPdgId);
186  tau.setVertex((daughters)[0].vertex()); // assign the leading muon vertex as tau vertex
187 
188  // the three muons must be close to each other in Z
189  if (std::abs(tau.daughter(0)->vz() - tau.vz()) > MaxDZ_)
190  continue;
191  if (std::abs(tau.daughter(1)->vz() - tau.vz()) > MaxDZ_)
192  continue;
193  if (std::abs(tau.daughter(2)->vz() - tau.vz()) > MaxDZ_)
194  continue;
195 
196  // require muons to be collimated
197  bool collimated = true;
198  for (auto const& idau : daughters) {
199  if (reco::deltaR2(tau.p4(), idau.p4()) > MaxTriMuonRadius_ * MaxTriMuonRadius_) {
200  collimated = false;
201  break;
202  }
203  }
204 
205  if (!collimated)
206  continue;
207 
208  // Tau kinematic selections
209  if (tau.pt() < TriMuonPtCut_)
210  continue;
211  if (tau.mass() < MinTriMuonMass_)
212  continue;
213  if (tau.mass() > MaxTriMuonMass_)
214  continue;
215  if (std::abs(tau.eta()) > TriMuonEtaCut_)
216  continue;
217 
218  // Tau charge selection
219  if ((std::abs(tau.charge()) != TriMuonAbsCharge_) & (TriMuonAbsCharge_ >= 0))
220  continue;
221 
222  // Sanity check against duplicates, di-muon masses must be > 2 * mass_mu
223  if ((tau.daughter(0)->p4() + tau.daughter(1)->p4()).mass() < TwiceMuonMass_)
224  continue;
225  if ((tau.daughter(0)->p4() + tau.daughter(2)->p4()).mass() < TwiceMuonMass_)
226  continue;
227  if ((tau.daughter(1)->p4() + tau.daughter(2)->p4()).mass() < TwiceMuonMass_)
228  continue;
229 
230  // a good tau, at last
231  Taus->push_back(tau);
232  }
233  }
234  }
235 
236  // Sort taus by pt
237  std::sort(Taus->begin(), Taus->end(), ptComparer<reco::CompositeCandidate>);
238 
239  // Loop over taus and further select by isolation
240  for (const auto& itau : *Taus) {
241  // remove the candidate pt from the iso sum
242  double sumPt = -itau.pt();
243 
244  // compute iso sum pT
245  for (const auto& itrk : *IsoTracks) {
246  if (reco::deltaR2(itrk.momentum(), itau.p4()) > IsoConeSize_ * IsoConeSize_)
247  continue;
248  if (std::abs(itrk.vz() - itau.vz()) > MaxDZ_)
249  continue;
250  sumPt += itrk.pt();
251  }
252 
253  // apply the isolation cut
255  double chRelIsoCut = EnableRelIso_ ? ChargedRelIsoCut_ * itau.pt() : std::numeric_limits<double>::infinity();
256 
257  if (!((sumPt < chAbsIsoCut) || (sumPt < chRelIsoCut)))
258  continue;
259 
260  SelectedTaus->push_back(itau);
261  }
262  }
263 
264  // finally put the vector of 3-muon candidates in the event
265  iEvent.put(std::move(Taus), "Taus");
266  iEvent.put(std::move(SelectedTaus), "SelectedTaus");
267 }
268 
271  desc.add<edm::InputTag>("L3MuonsSrc", edm::InputTag("hltIterL3FromL2MuonCandidates"));
272  desc.add<edm::InputTag>("AllMuonsSrc", edm::InputTag("hltGlbTrkMuonCands"));
273  desc.add<edm::InputTag>("L3DiMuonsFilterSrc", edm::InputTag("hltDiMuonForTau3MuDzFiltered0p3"));
274  desc.add<edm::InputTag>("IsoTracksSrc", edm::InputTag("hltIter2L3FromL2MuonMerged"));
275  desc.add<double>("Muon1PtCut", 5.);
276  desc.add<double>("Muon2PtCut", 3.);
277  desc.add<double>("Muon3PtCut", 0.);
278  desc.add<double>("TriMuonPtCut", 8.);
279  desc.add<double>("TriMuonEtaCut", 2.5);
280  desc.add<double>("ChargedAbsIsoCut", 3.0);
281  desc.add<double>("ChargedRelIsoCut", 0.1);
282  desc.add<double>("IsoConeSize", 0.5);
283  desc.add<double>("MatchingConeSize", 0.03);
284  desc.add<double>("MinTriMuonMass", 0.5);
285  desc.add<double>("MaxTriMuonMass", 2.8);
286  desc.add<double>("MaxTriMuonRadius", 0.6);
287  desc.add<int>("TriMuonAbsCharge", -1);
288  desc.add<double>("MaxDZ", 0.3);
289  desc.add<bool>("EnableRelIso", false);
290  desc.add<bool>("EnableAbsIso", true);
291  descriptions.add("hltTriMuonIsolationProducer", desc);
292 }
293 
294 #endif
~HLTTriMuonIsolation() override=default
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > AllMuonsToken_
edm::Handle< reco::RecoChargedCandidateCollection > L3MuCands
edm::Handle< trigger::TriggerFilterObjectWithRefs > L3DiMuonsFilterCands
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
const double MaxTriMuonMass_
double pt() const final
transverse momentum
std::vector< CompositeCandidate > CompositeCandidateCollection
collection of Candidate objects
double vz() const override
z coordinate of vertex position
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const double MinTriMuonMass_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
static bool ptComparer(const T &cand_1, const T &cand_2)
const LorentzVector & p4() const final
four-momentum Lorentz vector
void setVertex(const Point &vertex) override
set vertex
void setCharge(Charge q) final
set electric charge
int iEvent
Definition: GenABIO.cc:224
const double ChargedAbsIsoCut_
const double MatchingConeSize_
def move
Definition: eostools.py:511
const double infinity
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Handle< reco::TrackCollection > IsoTracks
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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 double ChargedRelIsoCut_
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > L3MuonsToken_
edm::Handle< reco::RecoChargedCandidateCollection > AllMuCands
virtual double vz() const =0
z coordinate of vertex position
double mass() const final
mass
edm::Handle< reco::RecoChargedCandidateRef > PassedL3Muons
HLTTriMuonIsolation(const edm::ParameterSet &iConfig)
const double MaxTriMuonRadius_
long double T
void setPdgId(int pdgId) final
void setP4(const LorentzVector &p4) final
set 4-momentum
const edm::EDGetTokenT< reco::TrackCollection > IsoTracksToken_
int charge() const final
electric charge
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > L3DiMuonsFilterToken_
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
double eta() const final
momentum pseudorapidity