CMS 3D CMS Logo

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