CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IsolatedPFCandidateSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PFCandProducer_IsolatedPFCandidateSelectorDefinition
2 #define PhysicsTools_PFCandProducer_IsolatedPFCandidateSelectorDefinition
3 
9 
10 namespace pf2pat {
11 
13 
14  public:
16 
18  isolationValueMapLabels_(cfg.getParameter< std::vector<edm::InputTag> >("isolationValueMaps") ),
19  isRelative_(cfg.getParameter<bool>("isRelative")),
20  isCombined_(cfg.getParameter<bool>("isCombined")),
21  isolationCuts_(cfg.getParameter< std::vector<double> >("isolationCuts")),
22  combinedIsolationCut_(cfg.getParameter<double>("combinedIsolationCut")) {
23 
24 
25  if( isolationCuts_.size() != isolationValueMapLabels_.size() )
26  throw cms::Exception("BadConfiguration")<<"the vector of isolation ValueMaps and the vector of the corresponding cuts must have the same size."<<std::endl;
27  }
28 
29  void select( const HandleToCollection & hc,
30  const edm::EventBase & e,
31  const edm::EventSetup& s) {
32  selected_.clear();
33 
34  /* assert( hc.isValid() ); */
35 
36  // read all isolation value maps
37  std::vector< edm::Handle<IsoMap> >
38  isoMaps(isolationValueMapLabels_.size());
39  for(unsigned iMap = 0; iMap<isolationValueMapLabels_.size(); ++iMap) {
40  e.getByLabel(isolationValueMapLabels_[iMap], isoMaps[iMap]);
41  }
42 
43  unsigned key=0;
44  // for( unsigned i=0; i<collection->size(); i++ ) {
45  for( collection::const_iterator pfc = hc->begin();
46  pfc != hc->end(); ++pfc, ++key) {
47  reco::PFCandidateRef candidate(hc,key);
48 
49  bool passed = true;
50  double isoSum=0.0;
51  for(unsigned iMap = 0; iMap<isoMaps.size(); ++iMap) {
52 
53  const IsoMap & isoMap = *(isoMaps[iMap]);
54 
55  double val = isoMap[candidate];
56  double cut = isolationCuts_[iMap];
57  if(isRelative_ && candidate->pt()>0.0) val/=candidate->pt();
58  isoSum+=val;
59  //std::cout << "val " << iMap << " = " << val << std::endl;
60 
61  if ( !isCombined_ && val>cut ) {
62  passed = false;
63  break;
64  }
65  }
66 
67  if ( isCombined_ && isoSum>combinedIsolationCut_ )
68  {
69  passed = false;
70  }
71 
72  if(passed) {
73  // passed all cuts, selected
74  selected_.push_back( reco::PFCandidate(*pfc) );
75  reco::PFCandidatePtr ptrToMother( hc, key );
76  selected_.back().setSourceCandidatePtr( ptrToMother );
77  }
78  }
79  }
80 
81  private:
82  std::vector<edm::InputTag> isolationValueMapLabels_;
84  std::vector<double> isolationCuts_;
86  };
87 
88 }
89 
90 #endif
bool getByLabel(const InputTag &, Handle< T > &) const
Definition: EventBase.h:85
tuple cut
Definition: align_tpl.py:88
void select(const HandleToCollection &hc, const edm::EventBase &e, const edm::EventSetup &s)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:34
list key
Definition: combine.py:13
string s
Definition: asciidump.py:422