CMS 3D CMS Logo

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