CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuIsolatorResultProducer.h
Go to the documentation of this file.
1 #ifndef MuonIsolationProducers_MuIsolatorResultProducer_H
2 #define MuonIsolationProducers_MuIsolatorResultProducer_H
3 
6 
8 
10 
13 
16 
17 
18 #include <string>
19 
20 namespace edm { class EventSetup; }
21 
22 struct muisorhelper {
26  typedef std::vector<Result> Results;
28 
29  template<typename BT>
30  class CandMap {
31  public:
32  typedef typename edm::RefToBase<BT> key_type;
35  typedef std::pair<key_type, value_type> pair_type;
36  typedef typename std::vector<pair_type > map_type;
37  typedef typename map_type::iterator iterator;
38 
39  map_type& get() { return cMap_;}
40  const map_type& get() const {return cMap_;}
41  const handle_type& handle() const { return handle_;}
42  void setHandle(const handle_type& rhs) { handle_ = rhs;}
43  private:
46  };
47 
48 };
49 
51 template <typename BT= reco::Candidate>
53 
54  public:
56 
57  virtual ~MuIsolatorResultProducer();
58 
59  virtual void produce(edm::Event&, const edm::EventSetup&);
60 
61  private:
67 
69 
70  struct DepositConf {
72  double weight;
73  double threshold;
74  };
75 
76  struct VetoCuts {
77  bool selectAll;
78  double muAbsEtaMax;
79  double muPtMin;
80  double muAbsZMax;
81  double muD0Max;
82  };
83 
84 
85 
86  void callWhatProduces();
87 
88  unsigned int initAssociation(edm::Event& event, CandMap& candMapT) const;
89 
90  void initVetos(std::vector<reco::IsoDeposit::Vetos*>& vetos, CandMap& candMap) const;
91 
92  template <typename RT>
93  void writeOutImpl(edm::Event& event, const CandMap& candMapT, const Results& results) const;
94 
95  void writeOut(edm::Event& event, const CandMap& candMap, const Results& results) const;
96 
98  std::vector<DepositConf> theDepositConfs;
99 
103 
107 
108 
113 };
114 
115 
117 template<typename BT>
118 template<typename RT> inline
120  const Results& results) const {
122  std::vector<RT> resV(results.size());
123  for (unsigned int i = 0; i< resV.size(); ++i) resV[i] = results[i].val<RT>();
124  std::auto_ptr<edm::ValueMap<RT> > outMap(new edm::ValueMap<RT>());
125  typename edm::ValueMap<RT>::Filler filler(*outMap);
126 
128  if (candMapT.get().size()>0){
129  filler.insert(candMapT.handle(), resV.begin(), resV.end());
130  filler.fill();
131  }
132 
133  event.put(outMap);
134 }
135 
136 
138 template<typename BT>
140  const CandMap& candMapT,
141  const Results& results) const {
142 
143  std::string metname = "RecoMuon|MuonIsolationProducers";
144  LogDebug(metname)<<"Before calling writeOutMap with result type "<<theIsolator->resultType();
145 
146  if (theResultType == Isolator::ISOL_INT_TYPE) writeOutImpl<int>(event, candMapT, results);
147  if (theResultType == Isolator::ISOL_FLOAT_TYPE) writeOutImpl<float>(event, candMapT, results);
148  if (theResultType == Isolator::ISOL_BOOL_TYPE) writeOutImpl<bool>(event, candMapT, results);
149 }
150 
151 
153 template<typename BT>
155  if (theResultType == Isolator::ISOL_FLOAT_TYPE) produces<edm::ValueMap<float> >();
156  if (theResultType == Isolator::ISOL_INT_TYPE ) produces<edm::ValueMap<int> >();
157  if (theResultType == Isolator::ISOL_BOOL_TYPE ) produces<edm::ValueMap<bool> >();
158 }
159 
160 // Framework
164 
166 
173 
176 
180 
181 #include <string>
182 
183 
185 template<typename BT>
187  theConfig(par),
188  theRemoveOtherVetos(par.getParameter<bool>("RemoveOtherVetos")),
189  theIsolator(0),
190  theBeam(0,0,0)
191 {
192  LogDebug("RecoMuon|MuonIsolation")<<" MuIsolatorResultProducer CTOR";
193 
195  std::vector<edm::ParameterSet> depositInputs =
196  par.getParameter<std::vector<edm::ParameterSet> >("InputMuIsoDeposits");
197 
198  std::vector<double> dWeights( depositInputs.size());
199  std::vector<double> dThresholds( depositInputs.size());
200 
201  for (unsigned int iDep = 0; iDep < depositInputs.size(); ++iDep){
202  DepositConf dConf;
203  dConf.tag = depositInputs[iDep].getParameter<edm::InputTag>("DepositTag");
204  dConf.weight = depositInputs[iDep].getParameter<double>("DepositWeight");
205  dConf.threshold = depositInputs[iDep].getParameter<double>("DepositThreshold");
206 
207  dWeights[iDep] = dConf.weight;
208  dThresholds[iDep] = dConf.threshold;
209 
210  theDepositConfs.push_back(dConf);
211  }
212 
213  edm::ParameterSet isoPset = par.getParameter<edm::ParameterSet>("IsolatorPSet");
215  std::string isolatorType = isoPset.getParameter<std::string>("ComponentName");
216  if ( isolatorType == "IsolatorByDeposit"){
217  std::string coneSizeType = isoPset.getParameter<std::string>("ConeSizeType");
218  if (coneSizeType == "FixedConeSize"){
219  float coneSize(isoPset.getParameter<double>("coneSize"));
220 
221  theIsolator = new muonisolation::IsolatorByDeposit(coneSize, dWeights, dThresholds);
222 
223  // theIsolator = new IsolatorByDeposit(isoPset);
224  } else if (coneSizeType == "CutsConeSize"){
226 // Cuts cuts(isoPset.getParameter<edm::ParameterSet>("CutsPSet"));
227 
228 // theIsolator = new IsolatorByDeposit(coneSize, dWeights, dThresholds);
229  }
230  } else if ( isolatorType == "IsolatorByNominalEfficiency"){
232  theIsolator = new muonisolation::IsolatorByNominalEfficiency("noname", std::vector<std::string>(1,"8:0.97"), dWeights);
233  } else if ( isolatorType == "IsolatorByDepositCount"){
234  std::string coneSizeType = isoPset.getParameter<std::string>("ConeSizeType");
235  if (coneSizeType == "FixedConeSize"){
236  float coneSize(isoPset.getParameter<double>("coneSize"));
237 
238  theIsolator = new muonisolation::IsolatorByDepositCount(coneSize, dThresholds);
239 
240  // theIsolator = new IsolatorByDeposit(isoPset);
241  } else if (coneSizeType == "CutsConeSize"){
242  // Cuts cuts(isoPset.getParameter<edm::ParameterSet>("CutsPSet"));
243 
244  // theIsolator = new IsolatorByDeposit(coneSize, dWeights, dThresholds);
245  }
246  }
247 
248  if (theIsolator == 0 ){
249  edm::LogError("MuonIsolationProducers")<<"Failed to initialize an isolator";
250  }
252 
254 
255  if (theRemoveOtherVetos){
256  edm::ParameterSet vetoPSet = par.getParameter<edm::ParameterSet>("VetoPSet");
257  theVetoCuts.selectAll = vetoPSet.getParameter<bool>("SelectAll");
258 
262  if (! theVetoCuts.selectAll){
263  theVetoCuts.muAbsEtaMax = vetoPSet.getParameter<double>("MuAbsEtaMax");
264  theVetoCuts.muPtMin = vetoPSet.getParameter<double>("MuPtMin");
265  theVetoCuts.muAbsZMax = vetoPSet.getParameter<double>("MuAbsZMax");
266  theVetoCuts.muD0Max = vetoPSet.getParameter<double>("MuD0Max");
267  theBeamlineOption = par.getParameter<std::string>("BeamlineOption");
268  theBeamSpotLabel = par.getParameter<edm::InputTag>("BeamSpotLabel");
269  }
270  }
271 }
272 
274 template<typename BT>
276  if (theIsolator) delete theIsolator;
277  LogDebug("RecoMuon|MuIsolatorResultProducer")<<" MuIsolatorResultProducer DTOR";
278 }
279 
280 
281 template<typename BT>
283 
284  std::string metname = "RecoMuon|MuonIsolationProducers";
285  LogDebug(metname)<<" Muon Deposit producing..."
286  <<" BEGINING OF EVENT " <<"================================";
287 
288  theBeam = reco::TrackBase::Point(0,0, 0);
289 
291  if(theRemoveOtherVetos && ! theVetoCuts.selectAll){
292  if (theBeamlineOption.compare("BeamSpotFromEvent") == 0){
293  //pick beamSpot
295  edm::Handle<reco::BeamSpot> beamSpotH;
296 
297  event.getByLabel(theBeamSpotLabel,beamSpotH);
298 
299  if (beamSpotH.isValid()){
300  theBeam = beamSpotH->position();
301  LogTrace(metname)<<"Extracted beam point at "<<theBeam<<std::endl;
302  }
303  }
304  }
305 
311  CandMap candMapT;
312 
313  unsigned int colSize = initAssociation(event, candMapT);
314 
316  Results results(colSize);
317 
319  std::vector<reco::IsoDeposit::Vetos*> vetoDeps(theDepositConfs.size(), 0);
320 
321  if (colSize != 0){
322  if (theRemoveOtherVetos){
323 
324  initVetos(vetoDeps, candMapT);
325  }
326 
328  for (unsigned int muI=0; muI < colSize; ++muI){
329  results[muI] = theIsolator->result(candMapT.get()[muI].second, *(candMapT.get()[muI].first));
330 
331  if (results[muI].typeF()!= theIsolator->resultType()){
332  edm::LogError("MuonIsolationProducers")<<"Failed to get result from the isolator";
333  }
334  }
335 
336  }
337 
338  LogDebug(metname)<<"Ready to write out results of size "<<results.size();
339  writeOut(event, candMapT, results);
340 
341  for(unsigned int iDep = 0; iDep< vetoDeps.size(); ++iDep){
343  if (vetoDeps[iDep]){
344  delete vetoDeps[iDep];
345  vetoDeps[iDep] = 0;
346  }
347  }
348 }
349 
350 template<typename BT>
351 unsigned int
353  std::string metname = "RecoMuon|MuonIsolationProducers";
354 
356 
357  for (unsigned int iMap = 0; iMap < theDepositConfs.size(); ++iMap){
359  event.getByLabel(theDepositConfs[iMap].tag, depH);
360  LogDebug(metname) <<"Got Deposits of size "<<depH->size();
361  if (depH->size()==0) continue;
362 
365  typename CandMap::handle_type keyH;
366  event.get(depH->begin().id(), keyH);
367  candMapT.setHandle(keyH);
368  typename CT::const_iterator depHCI = depH->begin().begin();
369  typename CT::const_iterator depEnd = depH->begin().end();
370  unsigned int keyI=0;
371  for (; depHCI != depEnd; ++depHCI, ++keyI){
372 
373  typename CandMap::key_type muPtr(keyH->refAt(keyI));
375  if (iMap == 0) candMapT.get().push_back(typename CandMap::pair_type(muPtr, DepositContainer(theDepositConfs.size())));
376  typename CandMap::iterator muI = candMapT.get().begin();
377  for (; muI != candMapT.get().end(); ++muI){
378  if (muI->first == muPtr) break;
379  }
380  if (muI->first != muPtr){
381  edm::LogError("MuonIsolationProducers")<<"Failed to align muon map";
382  }
383  muI->second[iMap].dep = &*depHCI;
384  }
385  }
386 
387  LogDebug(metname)<<"Picked and aligned nDeps = "<<candMapT.get().size();
388  return candMapT.get().size();
389 }
390 
391 template <typename BT >
392 void MuIsolatorResultProducer<BT>::initVetos(std::vector<reco::IsoDeposit::Vetos*>& vetos, CandMap& candMapT) const {
393  std::string metname = "RecoMuon|MuonIsolationProducers";
394 
395 
396  if (theRemoveOtherVetos){
397  LogDebug(metname)<<"Start checking for vetos based on input/expected vetos.size of "<<vetos.size()
398  <<" passed at "<<&vetos
399  <<" and an input map.size of "<<candMapT.get().size();
400 
401  unsigned int muI = 0;
402  for (; muI < candMapT.get().size(); ++muI) {
403  typename CandMap::key_type mu = candMapT.get()[muI].first;
404  double d0 = ( (mu->vx() - theBeam.x() )* mu->py() - (mu->vy() - theBeam.y())* mu->px() ) / mu->pt();
405  LogDebug(metname)<<"Muon at index "<<muI;
406  if (theVetoCuts.selectAll
407  || (fabs(mu->eta()) < theVetoCuts.muAbsEtaMax
408  && mu->pt() > theVetoCuts.muPtMin
409  && fabs(mu->vz()) < theVetoCuts.muAbsZMax
410  && fabs(d0) < theVetoCuts.muD0Max
411  )
412  ){
413  LogDebug(metname)<<"muon passes the cuts";
414  for (unsigned int iDep =0; iDep < candMapT.get()[muI].second.size(); ++iDep){
415  if (vetos[iDep] == 0) vetos[iDep] = new reco::IsoDeposit::Vetos();
416 
417  vetos[iDep]->push_back(candMapT.get()[muI].second[iDep].dep->veto());
418  }
419  }
420  }
421 
422  LogDebug(metname)<<"Assigning vetos";
423  muI = 0;
424  for (; muI < candMapT.get().size(); ++muI) {
425  for(unsigned int iDep =0; iDep < candMapT.get()[muI].second.size(); ++iDep){
426  candMapT.get()[muI].second[iDep].vetos = vetos[iDep];
427  }
428  }
429  LogDebug(metname)<<"Done with vetos";
430  }
431 }
432 
433 
434 
435 #endif
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
muisorhelper::ResultType ResultType
std::pair< key_type, value_type > pair_type
MuIsolatorResultProducer(const edm::ParameterSet &)
constructor with config
std::vector< Result > Results
ProductID id() const
Definition: HandleBase.cc:15
const std::string metname
std::vector< DepositConf > theDepositConfs
bool theRemoveOtherVetos
choose which muon vetos should be removed from all deposits
void callWhatProduces()
declare what&#39;s going to be produced
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
muonisolation::MuIsoBaseIsolator Isolator
edm::RefToBase< BT > key_type
Isolator * theIsolator
the isolator
std::string theBeamlineOption
beam spot
Isolator::Result Result
void setHandle(const handle_type &rhs)
edm::Handle< edm::View< BT > > handle_type
const int mu
Definition: Constants.h:22
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
void initVetos(std::vector< reco::IsoDeposit::Vetos * > &vetos, CandMap &candMap) const
muisorhelper::Isolator Isolator
virtual ~MuIsolatorResultProducer()
destructor
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:75
virtual ResultType resultType() const =0
#define LogTrace(id)
muisorhelper::DepositContainer DepositContainer
std::vector< DepositAndVetos > DepositContainer
Isolator::ResultType ResultType
unsigned int initAssociation(edm::Event &event, CandMap &candMapT) const
Isolator::DepositContainer DepositContainer
std::vector< pair_type > map_type
std::vector< Veto > Vetos
Definition: IsoDeposit.h:63
std::vector< value_type > container
Definition: ValueMap.h:107
void writeOutImpl(edm::Event &event, const CandMap &candMapT, const Results &results) const
actually do the writing here
const handle_type & handle() const
void writeOut(edm::Event &event, const CandMap &candMap, const Results &results) const
choose which result type to write here
reco::TrackBase::Point theBeam
virtual void produce(edm::Event &, const edm::EventSetup &)
muisorhelper::CandMap< BT > CandMap