CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTMuonIsoFilter.cc
Go to the documentation of this file.
1 
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_(0),
40  theDepositIsolator(0),
41  min_N_ (iConfig.getParameter<int> ("MinN"))
42 {
43  std::stringstream tags;
44  for (unsigned int i=0;i!=depTag_.size();++i) {
46  tags<<" IsoTag["<<i<<"] : "<<depTag_[i].encode()<<" \n";
47  }
48  decMapToken_ = consumes<edm::ValueMap<bool> >(depTag_.front());
49 
50  LogDebug("HLTMuonIsoFilter") << " candTag : " << candTag_.encode()
51  << "\n" << tags
52  << " MinN : " << min_N_;
53 
54  edm::ParameterSet isolatorPSet = iConfig.getParameter<edm::ParameterSet>("IsolatorPSet");
55  if (isolatorPSet.empty()) {
57  }else{
58  std::string type = isolatorPSet.getParameter<std::string>("ComponentName");
59  theDepositIsolator = MuonIsolatorFactory::get()->create(type, isolatorPSet, consumesCollector());
60  }
61 
62  if (theDepositIsolator) produces<edm::ValueMap<bool> >();
63 }
64 
66 {
67 }
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::auto_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(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 
#define LogDebug(id)
type
Definition: HCALResponse.h:21
virtual bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:218
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< edm::ValueMap< bool > > decMapToken_
selection
main part
Definition: corrVsCorr.py:98
virtual Result result(const DepositContainer &deposits, const edm::Event *=0) const =0
Compute and return the isolation variable.
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< edm::EDGetTokenT< edm::ValueMap< reco::IsoDeposit > > > depToken_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:24
edm::InputTag candTag_
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > previousCandToken_
std::string encode() const
Definition: InputTag.cc:164
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref&lt;C&gt;)
HLTMuonIsoFilter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static bool triggerdByPreviousLevel(const reco::RecoChargedCandidateRef &, const std::vector< reco::RecoChargedCandidateRef > &)
const muonisolation::MuIsoBaseIsolator * theDepositIsolator
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Container::value_type value_type
tuple tags
Definition: o2o.py:248
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)
bool saveTags() const
Definition: HLTFilter.h:45
std::string print() const
Definition: IsoDeposit.cc:181
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > candToken_
std::vector< edm::InputTag > depTag_
T get(const Candidate &c)
Definition: component.h:55