CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTauSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_TauTagTools_CaloTauSelectorDefinition
2 #define RecoTauTag_TauTagTools_CaloTauSelectorDefinition
3 
6 
8 
9 #include <iostream>
10 
12 
15  typedef std::vector< reco::CaloTau *> container;
16  typedef container::const_iterator const_iterator;
17 
18  struct TDiscCutPair {
20  double m_cut;
21  };
22  typedef std::vector<TDiscCutPair> TDiscCutPairVec;
23 
25  discriminators_ = cfg.getParameter< std::vector<edm::ParameterSet> >( "discriminators" );
26  cut_ = ( cfg.exists("cut") ) ? new StringCutObjectSelector<reco::CaloTau>( cfg.getParameter<std::string>( "cut" ) ) : 0;
27  }
28 
30 
31  const_iterator begin() const { return selected_.begin(); }
32 
33  const_iterator end() const { return selected_.end(); }
34 
35  void select( const HandleToCollection & hc,
36  const edm::Event & e,
37  const edm::EventSetup& s)
38  {
39 
40  selected_.clear();
41  assert( hc.isValid() ); // collection of CaloTaus
42 
43  // get discriminators and coresponding cuts from stored vpset
44  static TDiscCutPairVec discriminators;
45  discriminators.clear();
46 
47  for(std::vector< edm::ParameterSet >::iterator it = discriminators_.begin();
48  it != discriminators_.end();
49  ++it)
50  {
51  TDiscCutPair disc;
52  // get discriminator, check if valid
53  // assert isn't a good method to do it
54  if(!(e.getByLabel( it->getParameter<edm::InputTag>("discriminator"), disc.m_discHandle))) assert(0);
55  disc.m_cut = it->getParameter<double>("selectionCut");
56  // the discriminator collection and the CaloTau collection
57  // must have the same size
58  assert( disc.m_discHandle->size() == hc->size());
59  discriminators.push_back(disc);
60  }
61 
62  unsigned key=0;
63  static bool passedAllCuts;
64  for( collection::const_iterator calotau = hc->begin();
65  calotau != hc->end();
66  ++calotau, ++key)
67  {
68  passedAllCuts = true;
69  reco::CaloTauRef calotauRef(hc, key);
70 
71  //iterate over all discriminators, check the cuts
72  for (TDiscCutPairVec::iterator discIt = discriminators.begin();
73  discIt!=discriminators.end();
74  ++discIt)
75  {
76  if ( (*(discIt->m_discHandle))[calotauRef] <= discIt->m_cut)
77  passedAllCuts = false;
78  }
79 
80  if ( cut_ ) passedAllCuts &= (*cut_)(*calotau);
81 
82  if(passedAllCuts)
83  selected_.push_back( new reco::CaloTau(*calotau) );
84  } // end collection iteration
85  } // end select()
86 
87  size_t size() const { return selected_.size(); }
88 
89  private:
91  std::vector< edm::ParameterSet > discriminators_;
93 
94 };
95 
96 #endif
T getParameter(std::string const &) const
edm::Handle< collection > HandleToCollection
std::vector< edm::ParameterSet > discriminators_
bool exists(std::string const &parameterName) const
checks if a parameter exists
StringCutObjectSelector< reco::CaloTau > * cut_
std::vector< CaloTau > CaloTauCollection
collection of CaloTau objects
Definition: CaloTauFwd.h:9
container::const_iterator const_iterator
std::vector< reco::CaloTau * > container
std::vector< TDiscCutPair > TDiscCutPairVec
bool isValid() const
Definition: HandleBase.h:76
reco::CaloTauCollection collection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
list key
Definition: combine.py:13
string s
Definition: asciidump.py:422
edm::Handle< reco::CaloTauDiscriminator > m_discHandle
CaloTauSelectorDefinition(const edm::ParameterSet &cfg)