CMS 3D CMS Logo

HLTMuonIsoFilter.cc
Go to the documentation of this file.
1 
9 #include "HLTMuonIsoFilter.h"
10 
14 
16 
22 
24 
26 
28 
29 #include <iostream>
30 //
31 // constructors and destructor
32 //
34  candTag_ (iConfig.getParameter< edm::InputTag > ("CandTag") ),
35  candToken_(consumes<reco::RecoChargedCandidateCollection>(candTag_)),
36  previousCandTag_ (iConfig.getParameter<edm::InputTag > ("PreviousCandTag")),
37  previousCandToken_ (consumes<trigger::TriggerFilterObjectWithRefs>(previousCandTag_)),
38  depTag_ (iConfig.getParameter< std::vector< edm::InputTag > >("DepTag" ) ),
39  depToken_(),
40  min_N_ (iConfig.getParameter<int> ("MinN"))
41 {
42  depToken_.reserve(depTag_.size());
43  for (auto const& t: depTag_) {
45  }
46  decMapToken_ = consumes<edm::ValueMap<bool> >(depTag_.front());
47 
48  LogDebug("HLTMuonIsoFilter").log( [this]( auto& iLog) {
49  iLog<< " candTag : " << candTag_.encode()<<"\n";
50  int i =0;
51  for(auto const& t: depTag_) {
52  iLog<<" IsoTag["<<i++<<"] : "<<t.encode()<<" \n";
53  }
54  iLog<< " MinN : " << min_N_;
55  }
56  );
57 
58  edm::ParameterSet isolatorPSet = iConfig.getParameter<edm::ParameterSet>("IsolatorPSet");
59  if (not isolatorPSet.empty()) {
60  std::string type = isolatorPSet.getParameter<std::string>("ComponentName");
61  theDepositIsolator = std::unique_ptr<muonisolation::MuIsoBaseIsolator>(MuonIsolatorFactory::get()->create(type, isolatorPSet, consumesCollector()));
62  }
63 
64  if (theDepositIsolator) produces<edm::ValueMap<bool> >();
65 }
66 
68 
69 //
70 // member functions
71 //
72 void
76  desc.add<edm::InputTag>("CandTag",edm::InputTag("hltL3MuonCandidates"));
77  desc.add<edm::InputTag>("PreviousCandTag",edm::InputTag(""));
78  desc.add<int>("MinN",1);
79  std::vector<edm::InputTag> depTag(1,edm::InputTag("hltL3MuonIsolations"));
80  desc.add<std::vector<edm::InputTag> >("DepTag",depTag);
81  edm::ParameterSetDescription isolatorPSet;
82  desc.add<edm::ParameterSetDescription>("IsolatorPSet",isolatorPSet);
83  descriptions.add("hltMuonIsoFilter", desc);
84 }
85 
86 // ------------ method called to produce the data ------------
87 bool
89 {
90  using namespace std;
91  using namespace edm;
92  using namespace trigger;
93  using namespace reco;
94 
95  // All HLT filters must create and fill an HLT filter object,
96  // recording any reconstructed physics objects satisfying (or not)
97  // this HLT filter, and place it in the Event.
98 
99  //the decision map
100  std::unique_ptr<edm::ValueMap<bool> >
101  isoMap( new edm::ValueMap<bool> ());
102 
103  // get hold of trks
105  if (saveTags()) filterproduct.addCollectionTag(candTag_);
106  iEvent.getByToken(candToken_,mucands);
107  Handle<TriggerFilterObjectWithRefs> previousLevelCands;
108  iEvent.getByToken(previousCandToken_,previousLevelCands);
109  vector<RecoChargedCandidateRef> vcands;
110  previousLevelCands->getObjects(TriggerMuon,vcands);
111 
112  //get hold of energy deposition
113  unsigned int nDep=depTag_.size();
114  std::vector< Handle<edm::ValueMap<reco::IsoDeposit> > > depMap(nDep);
115  Handle<edm::ValueMap<bool> > decisionMap;
117 
118  if (theDepositIsolator){
119  for (unsigned int i=0;i!=nDep;++i) iEvent.getByToken(depToken_[i],depMap[i]);
120  }else{
121  bool success = iEvent.getByToken(decMapToken_, decisionMap);
122  LogDebug("HLTMuonIsoFilter")<<"get decisionMap " << success;
123  }
124 
125  // look at all mucands, check cuts and add to filter object
126  int nIsolatedMu = 0;
127  unsigned int nMu=mucands->size();
128  std::vector<bool> isos(nMu, false);
129  unsigned int iMu=0;
130  for (; iMu<nMu; iMu++) {
131  RecoChargedCandidateRef candref(mucands,iMu);
132  LogDebug("HLTMuonIsoFilter") << "candref isNonnull " << candref.isNonnull();
133 
134  //did this candidate triggered at previous stage.
135  if (!triggerdByPreviousLevel(candref,vcands)) continue;
136 
137  //reference to the track
138  TrackRef tk = candref->get<TrackRef>();
139  LogDebug("HLTMuonIsoFilter") << "tk isNonNull " << tk.isNonnull();
140  if (theDepositIsolator){
141 
142  //get the deposits
143  for(unsigned int iDep=0;iDep!=nDep;++iDep){
144 
145  const edm::ValueMap<reco::IsoDeposit> ::value_type & muonDeposit = (*(depMap[iDep]))[candref];
146  LogDebug("HLTMuonIsoFilter") << " Muon with q*pt= " << tk->charge()*tk->pt() << " (" << candref->charge()*candref->pt() << ") " << ", eta= " << tk->eta() << " (" << candref->eta() << ") " << "; has deposit["<<iDep<<"]: " << muonDeposit.print();
147  isoContainer[iDep] = muonisolation::MuIsoBaseIsolator::DepositAndVetos(&muonDeposit);
148 
149  }
150 
151  //get the selection
153  isos[iMu]=selection.valBool;
154 
155  }else{
156  //get the decision from the event
157  isos[iMu]=(*decisionMap)[candref];
158  }
159  LogDebug("HLTMuonIsoFilter") << " Muon with q*pt= " << tk->charge()*tk->pt() << ", eta= " << tk->eta() << "; "<<(isos[iMu]?"Is an isolated muon.":"Is NOT an isolated muon.");
160 
161  if (!isos[iMu]) continue;
162 
163  nIsolatedMu++;
164  filterproduct.addObject(TriggerMuon,candref);
165  }
166 
167  // filter decision
168  const bool accept (nIsolatedMu >= min_N_);
169 
170  if (theDepositIsolator){
171  //put the decision map
172  if (nMu!=0){
173  edm::ValueMap<bool> ::Filler isoFiller(*isoMap);
174  isoFiller.insert(mucands, isos.begin(), isos.end());
175  isoFiller.fill();
176  }
177  iEvent.put(std::move(isoMap));
178  }
179 
180  LogDebug("HLTMuonIsoFilter") << " >>>>> Result of HLTMuonIsoFilter is " << accept << ", number of muons passing isolation cuts= " << nIsolatedMu;
181 
182  return accept;
183 }
184 
185 bool HLTMuonIsoFilter::triggerdByPreviousLevel(const reco::RecoChargedCandidateRef & candref, const std::vector<reco::RecoChargedCandidateRef>& vcands){
186  bool ok=false;
187  unsigned int i=0;
188  unsigned int i_max=vcands.size();
189  for (;i!=i_max;++i){
190  if (candref == vcands[i]) { ok=true; break;}
191  }
192 
193  return ok;
194 }
195 
196 
197 // declare this class as a framework plugin
#define LogDebug(id)
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:191
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< edm::ValueMap< bool > > decMapToken_
selection
main part
Definition: corrVsCorr.py:100
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< edm::EDGetTokenT< edm::ValueMap< reco::IsoDeposit > > > depToken_
std::unique_ptr< const muonisolation::MuIsoBaseIsolator > theDepositIsolator
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
edm::InputTag candTag_
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
std::string encode() const
Definition: InputTag.cc:159
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>)
HLTMuonIsoFilter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static bool triggerdByPreviousLevel(const reco::RecoChargedCandidateRef &, const std::vector< reco::RecoChargedCandidateRef > &)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
static void makeHLTFilterDescription(edm::ParameterSetDescription &desc)
Definition: HLTFilter.cc:29
std::vector< DepositAndVetos > DepositContainer
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::string print() const
Definition: IsoDeposit.cc:181
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > candToken_
~HLTMuonIsoFilter() override
std::vector< edm::InputTag > depTag_
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55