CMS 3D CMS Logo

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< DiscContainerCutPairDiscContainerCutPairVec
 
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

◆ collection

Definition at line 21 of file PFTauSelectorDefinition.h.

◆ const_iterator

typedef container::const_iterator PFTauSelectorDefinition::const_iterator

Definition at line 24 of file PFTauSelectorDefinition.h.

◆ container

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

Definition at line 23 of file PFTauSelectorDefinition.h.

◆ DiscContainerCutPairVec

Definition at line 40 of file PFTauSelectorDefinition.h.

◆ DiscCutPairVec

Definition at line 39 of file PFTauSelectorDefinition.h.

◆ HandleToCollection

Definition at line 22 of file PFTauSelectorDefinition.h.

Constructor & Destructor Documentation

◆ PFTauSelectorDefinition()

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

Definition at line 42 of file PFTauSelectorDefinition.h.

References looper::cfg, PFTauSelectorDefinition::DiscCutPair::cut, cut_, PDWG_TauSkim_cff::discriminatorContainers, discriminatorContainers_, PDWG_TauSkim_cff::discriminators, discriminators_, Exception, mps_fire::i, PFTauSelectorDefinition::DiscCutPair::inputToken, PFTauSelectorDefinition::DiscContainerCutPair::inputToken, muonDTDigis_cfi::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  cut_ = std::make_unique<StringCutObjectSelector<reco::PFTau>>(cfg.getParameter<std::string>("cut"));
73  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
DiscContainerCutPairVec discriminatorContainers_

Member Function Documentation

◆ begin()

const_iterator PFTauSelectorDefinition::begin ( void  ) const
inline

Definition at line 75 of file PFTauSelectorDefinition.h.

References selected_.

75 { return selected_.begin(); }

◆ end()

const_iterator PFTauSelectorDefinition::end ( void  ) const
inline

Definition at line 76 of file PFTauSelectorDefinition.h.

References selected_.

76 { return selected_.end(); }

◆ select()

void PFTauSelectorDefinition::select ( const HandleToCollection hc,
const edm::Event e,
const edm::EventSetup s 
)
inline

Definition at line 78 of file PFTauSelectorDefinition.h.

References cut_, TtSemiLepEvtBuilder_cfi::disc, discriminatorContainers_, discriminators_, MillePedeFileConverter_cfg::e, Exception, newFWLiteAna::found, edm::ParameterSet::getParameter(), mps_fire::i, edm::HandleBase::id(), edm::HandleBase::isValid(), dqmiolumiharvest::j, edm::parameterSet(), TriggerAnalyzer::passed, phID_, selected_, AlCaHLTBitMon_QueryRunRegistry::string, and metsig::tau.

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

◆ size()

size_t PFTauSelectorDefinition::size ( void  ) const
inline

Member Data Documentation

◆ cut_

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

Definition at line 231 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ discriminatorContainers_

DiscContainerCutPairVec PFTauSelectorDefinition::discriminatorContainers_
private

Definition at line 228 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ discriminators_

DiscCutPairVec PFTauSelectorDefinition::discriminators_
private

Definition at line 227 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ phID_

edm::ProcessHistoryID PFTauSelectorDefinition::phID_
private

Definition at line 229 of file PFTauSelectorDefinition.h.

Referenced by select().

◆ selected_

container PFTauSelectorDefinition::selected_
private

Definition at line 226 of file PFTauSelectorDefinition.h.

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