CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
PFTauSelectorDefinition Struct Reference

#include <PFTauSelectorDefinition.h>

Classes

struct  DiscContainerCutPair
 
struct  DiscCutPair
 

Public Types

typedef reco::PFTauCollection collection
 
typedef container::const_iterator const_iterator
 
typedef std::vector< const
reco::PFTau * > 
container
 
typedef std::vector
< DiscContainerCutPair
DiscContainerCutPairVec
 
typedef std::vector< DiscCutPairDiscCutPairVec
 
typedef edm::Handle< collectionHandleToCollection
 

Public Member Functions

const_iterator begin () const
 
const_iterator end () const
 
 PFTauSelectorDefinition (const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
 
void select (const HandleToCollection &hc, const edm::Event &e, const edm::EventSetup &s)
 
size_t size () const
 

Private Attributes

std::unique_ptr
< StringCutObjectSelector
< reco::PFTau > > 
cut_
 
DiscContainerCutPairVec discriminatorContainers_
 
DiscCutPairVec discriminators_
 
edm::ProcessHistoryID phID_
 
container selected_
 

Detailed Description

Definition at line 20 of file PFTauSelectorDefinition.h.

Member Typedef Documentation

Definition at line 21 of file PFTauSelectorDefinition.h.

typedef container::const_iterator PFTauSelectorDefinition::const_iterator

Definition at line 24 of file PFTauSelectorDefinition.h.

typedef std::vector<const reco::PFTau*> PFTauSelectorDefinition::container

Definition at line 23 of file PFTauSelectorDefinition.h.

Definition at line 40 of file PFTauSelectorDefinition.h.

Definition at line 39 of file PFTauSelectorDefinition.h.

Definition at line 22 of file PFTauSelectorDefinition.h.

Constructor & Destructor Documentation

PFTauSelectorDefinition::PFTauSelectorDefinition ( const edm::ParameterSet cfg,
edm::ConsumesCollector &&  iC 
)
inline

Definition at line 42 of file PFTauSelectorDefinition.h.

References PFTauSelectorDefinition::DiscCutPair::cut, cut_, MuTauSkim_cff::discriminatorContainers, discriminatorContainers_, bTagMiniDQM_cff::discriminators, discriminators_, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), mps_fire::i, PFTauSelectorDefinition::DiscCutPair::inputToken, PFTauSelectorDefinition::DiscContainerCutPair::inputToken, TrackValidation_cff::pset, PFTauSelectorDefinition::DiscContainerCutPair::rawCuts, PFTauSelectorDefinition::DiscContainerCutPair::rawLabels, AlCaHLTBitMon_QueryRunRegistry::string, PFTauSelectorDefinition::DiscContainerCutPair::wpCuts, and PFTauSelectorDefinition::DiscContainerCutPair::wpLabels.

42  {
43  auto const& discriminators = cfg.getParameter<std::vector<edm::ParameterSet>>("discriminators");
44  auto const& discriminatorContainers = cfg.getParameter<std::vector<edm::ParameterSet>>("discriminatorContainers");
45  // Build each of our cuts
46  for (auto const& pset : discriminators) {
47  DiscCutPair newCut;
48  newCut.inputToken = iC.consumes<reco::PFTauDiscriminator>(pset.getParameter<edm::InputTag>("discriminator"));
49  newCut.cut = pset.getParameter<double>("selectionCut");
50  discriminators_.push_back(newCut);
51  }
52  for (auto const& pset : discriminatorContainers) {
53  DiscContainerCutPair newCut;
54  newCut.inputToken =
55  iC.consumes<reco::TauDiscriminatorContainer>(pset.getParameter<edm::InputTag>("discriminator"));
56  auto const& rawLabels = pset.getParameter<std::vector<std::string>>("rawValues");
57  auto const& rawCutValues = pset.getParameter<std::vector<double>>("selectionCuts");
58  if (rawLabels.size() != rawCutValues.size()) {
59  throw cms::Exception("PFTauSelectorBadHandle")
60  << "unequal number of TauIDContainer raw value indices and cut values given to PFTauSelector.";
61  }
62  for (size_t i = 0; i < rawLabels.size(); i++) {
63  newCut.rawCuts.push_back(std::pair<int, double>(-99, rawCutValues[i]));
64  newCut.rawLabels.push_back(rawLabels[i]);
65  }
66  newCut.wpLabels = pset.getParameter<std::vector<std::string>>("workingPoints");
67  newCut.wpCuts.resize(newCut.wpLabels.size());
68  discriminatorContainers_.push_back(newCut);
69  }
70 
71  // Build a string cut if desired
72  if (cfg.exists("cut")) {
73  cut_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(cfg.getParameter<std::string>("cut"));
74  }
75  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
tuple discriminatorContainers
DiscContainerCutPairVec discriminatorContainers_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

Member Function Documentation

const_iterator PFTauSelectorDefinition::begin ( void  ) const
inline

Definition at line 77 of file PFTauSelectorDefinition.h.

References selected_.

77 { return selected_.begin(); }
const_iterator PFTauSelectorDefinition::end ( void  ) const
inline

Definition at line 78 of file PFTauSelectorDefinition.h.

References selected_.

78 { return selected_.end(); }
void PFTauSelectorDefinition::select ( const HandleToCollection hc,
const edm::Event e,
const edm::EventSetup s 
)
inline

Definition at line 80 of file PFTauSelectorDefinition.h.

References cut_, discriminatorContainers_, discriminators_, Exception, newFWLiteAna::found, edm::Ref< C, T, F >::get(), edm::Event::getByToken(), edm::ParameterSet::getParameter(), mps_fire::i, edm::HandleBase::id(), edm::HandleBase::isValid(), dqmiolumiharvest::j, edm::parameterSet(), phID_, edm::Event::processHistory(), edm::Event::processHistoryID(), selected_, AlCaHLTBitMon_QueryRunRegistry::string, and metsig::tau.

80  {
81  selected_.clear();
82 
83  if (!hc.isValid()) {
84  throw cms::Exception("PFTauSelectorBadHandle")
85  << "an invalid PFTau handle with ProductID" << hc.id() << " passed to PFTauSelector.";
86  }
87 
88  // Load each discriminator
89  for (auto& disc : discriminators_) {
90  e.getByToken(disc.inputToken, disc.handle);
91  }
92  for (auto& disc : discriminatorContainers_) {
93  e.getByToken(disc.inputToken, disc.handle);
94  }
95  // Retrieve ID container indices if config history changes, in particular for the first event.
96  if (phID_ != e.processHistoryID()) {
97  phID_ = e.processHistoryID();
98  for (auto& disc : discriminatorContainers_) {
99  auto const& psetsFromProvenance = edm::parameterSet(disc.handle.provenance()->stable(), e.processHistory());
100  // find raw value indices
101  if (psetsFromProvenance.exists("rawValues")) {
102  auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("rawValues");
103  for (size_t i = 0; i < disc.rawLabels.size(); ++i) {
104  bool found = false;
105  for (size_t j = 0; j < idlist.size(); ++j) {
106  if (disc.rawLabels[i] == idlist[j]) {
107  found = true;
108  disc.rawCuts[i].first = j;
109  }
110  }
111  if (!found)
112  throw cms::Exception("Configuration")
113  << "PFTauSelector: Requested working point '" << disc.rawLabels[i] << "' not found!\n";
114  }
115  } else if (psetsFromProvenance.exists("IDdefinitions")) {
116  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDdefinitions");
117  for (size_t i = 0; i < disc.rawLabels.size(); ++i) {
118  bool found = false;
119  for (size_t j = 0; j < idlist.size(); ++j) {
120  if (disc.rawLabels[i] == idlist[j].getParameter<std::string>("IDname")) {
121  found = true;
122  disc.rawCuts[i].first = j;
123  }
124  }
125  if (!found)
126  throw cms::Exception("Configuration")
127  << "PFTauSelector: Requested working point '" << disc.rawLabels[i] << "' not found!\n";
128  }
129  } else if (psetsFromProvenance.exists("VSjetWP")) {
130  // This else statement was added in the update of the HLT paths to use DeepTauId instead of charged isolation. Because the DeepTauId module is shared
131  // with offline and its psetsFromProvenance do not contain any of the above but only VSxWP, this selector would automatically go to the else statement
132  // that follows this one and fail. It is left empty because at HLT the raw values are not used and no action is needed here.
133  } else
134  throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID list found in provenace config!\n";
135  // find working point indices
136  if (psetsFromProvenance.exists("workingPoints")) {
137  auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("workingPoints");
138  for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
139  bool found = false;
140  for (size_t j = 0; j < idlist.size(); ++j) {
141  if (disc.wpLabels[i] == idlist[j]) {
142  found = true;
143  disc.wpCuts[i] = j;
144  }
145  }
146  if (!found)
147  throw cms::Exception("Configuration")
148  << "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
149  }
150  } else if (psetsFromProvenance.exists("IDWPdefinitions")) {
151  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
152  for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
153  bool found = false;
154  for (size_t j = 0; j < idlist.size(); ++j) {
155  if (disc.wpLabels[i] == idlist[j].getParameter<std::string>("IDname")) {
156  found = true;
157  disc.wpCuts[i] = j;
158  }
159  }
160  if (!found)
161  throw cms::Exception("Configuration")
162  << "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
163  }
164  } else if (psetsFromProvenance.exists("VSjetWP")) {
165  auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("VSjetWP");
166  for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
167  bool found = false;
168  for (size_t j = 0; j < idlist.size(); ++j) {
169  if (disc.wpLabels[i] == idlist[j]) {
170  found = true;
171  disc.wpCuts[i] = j;
172  }
173  }
174  if (!found)
175  throw cms::Exception("Configuration")
176  << "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
177  }
178  } else
179  throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID WP list found in provenace config!\n";
180  }
181  }
182 
183  const size_t nTaus = hc->size();
184  for (size_t iTau = 0; iTau < nTaus; ++iTau) {
185  bool passed = true;
186  reco::PFTauRef tau(hc, iTau);
187  // Check if it passed all the discrimiantors
188  for (auto const& disc : discriminators_) {
189  // Check this discriminator passes
190  if (!((*disc.handle)[tau] > disc.cut)) {
191  passed = false;
192  break;
193  }
194  }
195  if (passed) { // if passed so far, check other discriminators
196  for (auto const& disc : discriminatorContainers_) {
197  for (auto const& rawCut : disc.rawCuts) {
198  if (!((*disc.handle)[tau].rawValues.at(rawCut.first) > rawCut.second)) {
199  passed = false;
200  break;
201  }
202  }
203  if (!passed)
204  break;
205  for (auto const& wpCut : disc.wpCuts) {
206  if (!((*disc.handle)[tau].workingPoints.at(wpCut))) {
207  passed = false;
208  break;
209  }
210  }
211  if (!passed)
212  break;
213  }
214  }
215 
216  if (passed && cut_.get()) {
217  passed = (*cut_)(*tau);
218  }
219 
220  if (passed)
221  selected_.push_back(tau.get());
222  }
223  } // end select()
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
DiscContainerCutPairVec discriminatorContainers_
ProcessHistory const & processHistory() const override
Definition: Event.cc:250
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ProcessHistoryID const & processHistoryID() const
Definition: Event.cc:116
size_t PFTauSelectorDefinition::size ( void  ) const
inline

Member Data Documentation

std::unique_ptr<StringCutObjectSelector<reco::PFTau> > PFTauSelectorDefinition::cut_
private

Definition at line 233 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

DiscContainerCutPairVec PFTauSelectorDefinition::discriminatorContainers_
private

Definition at line 230 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

DiscCutPairVec PFTauSelectorDefinition::discriminators_
private

Definition at line 229 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

edm::ProcessHistoryID PFTauSelectorDefinition::phID_
private

Definition at line 231 of file PFTauSelectorDefinition.h.

Referenced by select().

container PFTauSelectorDefinition::selected_
private

Definition at line 228 of file PFTauSelectorDefinition.h.

Referenced by begin(), end(), select(), and size().