CMS 3D CMS Logo

HLTMuonPFIsoFilter.cc
Go to the documentation of this file.
1 
8 #include "HLTMuonPFIsoFilter.h"
9 
13 
15 
19 
21 
22 #include <iostream>
23 //
24 // constructors and destructor
25 //
27  candTag_ (iConfig.getParameter< edm::InputTag > ("CandTag") ),
28  previousCandTag_ (iConfig.getParameter< edm::InputTag > ("PreviousCandTag")),
29  depTag_ (iConfig.getParameter< std::vector< edm::InputTag > >("DepTag" ) ),
30  depToken_(),
31  rhoTag_ (iConfig.getParameter< edm::InputTag >("RhoTag" ) ),
32  maxIso_ (iConfig.getParameter<double>("MaxIso" ) ),
33  min_N_ (iConfig.getParameter<int> ("MinN")),
34  onlyCharged_ (iConfig.getParameter<bool> ("onlyCharged")),
35  doRho_ (iConfig.getParameter<bool> ("applyRhoCorrection")),
36  effArea_ (iConfig.getParameter<double> ("EffectiveArea"))
37 {
38  depToken_.reserve(depTag_.size());
39  for (auto const& t: depTag_) {
41  }
42 
43  candToken_ = consumes<reco::RecoChargedCandidateCollection>(candTag_);
44  previousCandToken_ = consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_);
45  if (doRho_) rhoToken_ = consumes<double>(rhoTag_);
46 
47  LogDebug("HLTMuonPFIsoFilter").log( [this](auto& l) {
48  l << " candTag : " << candTag_.encode()
49  << "\n" ;
50  for (unsigned int i=0;i!=depTag_.size();++i) {
51  l<<" PFIsoTag["<<i<<"] : "<<depTag_[i].encode()<<" \n";
52  }
53  l << " MinN : " << min_N_;
54  });
55  produces<edm::ValueMap<bool> >();
56 }
57 
58 
60 
61 //
62 // member functions
63 //
64 void
68  desc.add<edm::InputTag>("CandTag",edm::InputTag("hltL3MuonCandidates"));
69  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag(""));
70  std::vector<edm::InputTag> depTag(1,edm::InputTag("hltMuPFIsoValueCharged03"));
71  desc.add<std::vector<edm::InputTag> >("DepTag",depTag);
72  desc.add<edm::InputTag>("RhoTag",edm::InputTag("hltFixedGridRhoFastjetAllCaloForMuonsPF"));
73  desc.add<double>("MaxIso",1.);
74  desc.add<int>("MinN",1);
75  desc.add<bool>("onlyCharged",false);
76  desc.add<bool>("applyRhoCorrection",true);
77  desc.add<double>("EffectiveArea",1.);
78  descriptions.add("hltMuonPFIsoFilter", desc);
79 }
80 
81 // ------------ method called to produce the data ------------
82  bool
84  {
85  using namespace std;
86  using namespace edm;
87  using namespace trigger;
88  using namespace reco;
89 
90  // All HLT filters must create and fill an HLT filter object,
91  // recording any reconstructed physics objects satisfying (or not)
92  // this HLT filter, and place it in the Event.
93 
94  //the decision map
95  std::unique_ptr<edm::ValueMap<bool> > PFisoMap( new edm::ValueMap<bool> ());
96 
97  // get hold of trks
99  if (saveTags()) filterproduct.addCollectionTag(candTag_);
100  iEvent.getByToken (candToken_,mucands);
101  Handle<TriggerFilterObjectWithRefs> previousLevelCands;
102  iEvent.getByToken (previousCandToken_,previousLevelCands);
103  vector<RecoChargedCandidateRef> vcands;
104  previousLevelCands->getObjects(TriggerMuon,vcands);
105 
106  //get hold of energy deposition
107  unsigned int nDep=depTag_.size();
108  std::vector< Handle<edm::ValueMap<double> > > depMap(nDep);
109 
110  //get hold of rho of the event
111  double Rho = 0;
112  if (doRho_){
113  Handle <double> RhoCorr;
114  iEvent.getByToken(rhoToken_, RhoCorr);
115  Rho = *RhoCorr.product();
116  }
117 
118  for (unsigned int i=0;i!=nDep;++i) iEvent.getByToken (depToken_[i],depMap[i]);
119 
120  // look at all mucands, check cuts and add to filter object
121  int nIsolatedMu = 0;
122  unsigned int nMu=mucands->size();
123  std::vector<bool> isos(nMu, false);
124 
125  unsigned int iMu=0;
126  for (; iMu<nMu; iMu++)
127  {
128  double MuonDeposits = 0;
129  RecoChargedCandidateRef candref(mucands,iMu);
130  LogDebug("HLTMuonPFIsoFilter") << "candref isNonnull " << candref.isNonnull();
131 
132  //did this candidate triggered at previous stage.
133  if (!triggerdByPreviousLevel(candref,vcands)) continue;
134 
135  //reference to the track
136  TrackRef tk = candref->get<TrackRef>();
137  LogDebug("HLTMuonPFIsoFilter") << "tk isNonNull " << tk.isNonnull();
138 
139  //get the deposits and evaluate relIso if only the charged component is considered
140  if (onlyCharged_){
141  for(unsigned int iDep=0;iDep!=nDep;++iDep)
142  {
143  const edm::ValueMap<double> ::value_type & muonDeposit = (*(depMap[iDep]))[candref];
144  LogDebug("HLTMuonPFIsoFilter") << " Muon with q*pt= " << tk->charge()*tk->pt()
145  << " (" << candref->charge()*candref->pt() << ") "
146  << ", eta= " << tk->eta() << " (" << candref->eta() << ") "
147  << "; has deposit["<<iDep<<"]: " << muonDeposit;
148 
149  std::size_t foundCharged = depTag_[iDep].label().find("Charged");
150  if (foundCharged!=std::string::npos) MuonDeposits += muonDeposit;
151  }
152  MuonDeposits = MuonDeposits/tk->pt();
153  }
154  else {
155  //get all the deposits
156  for(unsigned int iDep=0;iDep!=nDep;++iDep)
157  {
158  const edm::ValueMap<double> ::value_type & muonDeposit = (*(depMap[iDep]))[candref];
159  LogDebug("HLTMuonPFIsoFilter") << " Muon with q*pt= " << tk->charge()*tk->pt()
160  << " (" << candref->charge()*candref->pt() << ") "
161  << ", eta= " << tk->eta() << " (" << candref->eta() << ") "
162  << "; has deposit["<<iDep<<"]: " << muonDeposit;
163  MuonDeposits += muonDeposit;
164  }
165  //apply rho correction
166  if (doRho_) MuonDeposits -= effArea_*Rho;
167  MuonDeposits = MuonDeposits/tk->pt();
168  }
169 
170  //get the selection
171  if (MuonDeposits < maxIso_) isos[iMu] = true;
172 
173  LogDebug("HLTMuonPFIsoFilter") << " Muon with q*pt= " << tk->charge()*tk->pt() << ", eta= " << tk->eta()
174  << "; "<<(isos[iMu]?"Is an isolated muon.":"Is NOT an isolated muon.");
175 
176  if (!isos[iMu]) continue;
177 
178  nIsolatedMu++;
179  filterproduct.addObject(TriggerMuon,candref);
180  }//for iMu
181 
182  // filter decision
183  const bool accept (nIsolatedMu >= min_N_);
184 
185  //put the decision map
186  if (nMu!=0)
187  {
188  edm::ValueMap<bool> ::Filler isoFiller(*PFisoMap);
189  isoFiller.insert(mucands, isos.begin(), isos.end());
190  isoFiller.fill();
191  }
192 
193  iEvent.put(std::move(PFisoMap));
194 
195  LogDebug("HLTMuonPFIsoFilter") << " >>>>> Result of HLTMuonPFIsoFilter is " << accept << ", number of muons passing isolation cuts= " << nIsolatedMu;
196  return accept;
197  }
198 
199 
200 bool HLTMuonPFIsoFilter::triggerdByPreviousLevel(const reco::RecoChargedCandidateRef & candref, const std::vector<reco::RecoChargedCandidateRef>& vcands){
201  unsigned int i=0;
202  unsigned int i_max=vcands.size();
203  for (;i!=i_max;++i){
204  if (candref == vcands[i]) return true;
205  }
206 
207  return false;
208 }
209 
210 // declare this class as a framework plugin
#define LogDebug(id)
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void getObjects(Vids &ids, VRphoton &refs) const
various physics-level getters:
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
std::vector< edm::InputTag > depTag_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
~HLTMuonPFIsoFilter() override
static bool triggerdByPreviousLevel(const reco::RecoChargedCandidateRef &, const std::vector< reco::RecoChargedCandidateRef > &)
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::InputTag candTag_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
std::string encode() const
Definition: InputTag.cc:159
edm::EDGetTokenT< double > rhoToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref<C>)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag previousCandTag_
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > candToken_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
HLTMuonPFIsoFilter(const edm::ParameterSet &)
static void makeHLTFilterDescription(edm::ParameterSetDescription &desc)
Definition: HLTFilter.cc:29
T const * product() const
Definition: Handle.h:74
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
bool saveTags() const
Definition: HLTFilter.h:45
HLT enums.
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > depToken_
def move(src, dest)
Definition: eostools.py:511