CMS 3D CMS Logo

CaloTauSelectorDefinition.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_TauTagTools_CaloTauSelectorDefinition
2 #define RecoTauTag_TauTagTools_CaloTauSelectorDefinition
3 
6 
9 
11 
12 #include <iostream>
13 
15 
18  typedef std::vector< reco::CaloTau *> container;
19  typedef container::const_iterator const_iterator;
20 
21  struct TDiscCutPair {
23  double m_cut;
24  };
25  typedef std::vector<TDiscCutPair> TDiscCutPairVec;
26 
28  discriminatorsPSets_ = cfg.getParameter< std::vector<edm::ParameterSet> >( "discriminators" );
30  cut_ = ( cfg.exists("cut") ) ? new StringCutObjectSelector<reco::CaloTau>( cfg.getParameter<std::string>( "cut" ) ) : 0;
31  }
32 
34 
35  const_iterator begin() const { return selected_.begin(); }
36 
37  const_iterator end() const { return selected_.end(); }
38 
39  void select( const HandleToCollection & hc,
40  const edm::Event & e,
41  const edm::EventSetup& s)
42  {
43 
44  selected_.clear();
45  assert( hc.isValid() ); // collection of CaloTaus
46 
47  // get discriminators and coresponding cuts from stored vpset
48  discriminators_.clear();
49 
50  std::vector< edm::EDGetTokenT<reco::CaloTauDiscriminator> >::iterator itToken = discriminatorTokens_.begin();
51  for(std::vector< edm::ParameterSet >::iterator it = discriminatorsPSets_.begin();
52  it != discriminatorsPSets_.end();
53  ++it, ++itToken)
54  {
56  // get discriminator, check if valid
57  // assert isn't a good method to do it
58  if(!(e.getByToken( *itToken, disc.m_discHandle))) assert(0);
59  disc.m_cut = it->getParameter<double>("selectionCut");
60  // the discriminator collection and the CaloTau collection
61  // must have the same size
62  assert( disc.m_discHandle->size() == hc->size());
63  discriminators_.push_back(disc);
64  }
65 
66  unsigned key=0;
67  bool passedAllCuts;
68  for( collection::const_iterator calotau = hc->begin();
69  calotau != hc->end();
70  ++calotau, ++key)
71  {
72  passedAllCuts = true;
73  reco::CaloTauRef calotauRef(hc, key);
74 
75  //iterate over all discriminators, check the cuts
76  for (TDiscCutPairVec::iterator discIt = discriminators_.begin();
77  discIt!=discriminators_.end();
78  ++discIt)
79  {
80  if ( (*(discIt->m_discHandle))[calotauRef] <= discIt->m_cut)
81  passedAllCuts = false;
82  }
83 
84  if ( cut_ ) passedAllCuts &= (*cut_)(*calotau);
85 
86  if(passedAllCuts)
87  selected_.push_back( new reco::CaloTau(*calotau) );
88  } // end collection iteration
89  } // end select()
90 
91  size_t size() const { return selected_.size(); }
92 
93  private:
94  TDiscCutPairVec discriminators_;
95  container selected_;
96  std::vector< edm::ParameterSet > discriminatorsPSets_;
97  std::vector< edm::EDGetTokenT<reco::CaloTauDiscriminator> > discriminatorTokens_;
99 
100 };
101 
102 #endif
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::Handle< collection > HandleToCollection
bool exists(std::string const &parameterName) const
checks if a parameter exists
StringCutObjectSelector< reco::CaloTau > * cut_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
CaloTauSelectorDefinition(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
std::vector< CaloTau > CaloTauCollection
collection of CaloTau objects
Definition: CaloTauFwd.h:9
container::const_iterator const_iterator
std::vector< edm::EDGetTokenT< reco::CaloTauDiscriminator > > discriminatorTokens_
std::vector< reco::CaloTau * > container
std::vector< TDiscCutPair > TDiscCutPairVec
bool isValid() const
Definition: HandleBase.h:74
reco::CaloTauCollection collection
void select(const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
std::vector< edm::ParameterSet > discriminatorsPSets_
susybsm::HSCParticleCollection hc
Definition: classes.h:25
edm::Handle< reco::CaloTauDiscriminator > m_discHandle
size_type size() const