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.

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_.reset(new StringCutObjectSelector<reco::PFTau>(cfg.getParameter<std::string>("cut")));
74  }
75  }

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.

Member Function Documentation

◆ begin()

const_iterator PFTauSelectorDefinition::begin ( void  ) const
inline

Definition at line 77 of file PFTauSelectorDefinition.h.

77 { return selected_.begin(); }

References selected_.

◆ end()

const_iterator PFTauSelectorDefinition::end ( void  ) const
inline

Definition at line 78 of file PFTauSelectorDefinition.h.

78 { return selected_.end(); }

References selected_.

◆ select()

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

Definition at line 80 of file PFTauSelectorDefinition.h.

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(), 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
130  throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID list found in provenace config!\n";
131  // find working point indices
132  if (psetsFromProvenance.exists("workingPoints")) {
133  auto const idlist = psetsFromProvenance.getParameter<std::vector<std::string>>("workingPoints");
134  for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
135  bool found = false;
136  for (size_t j = 0; j < idlist.size(); ++j) {
137  if (disc.wpLabels[i] == idlist[j]) {
138  found = true;
139  disc.wpCuts[i] = j;
140  }
141  }
142  if (!found)
143  throw cms::Exception("Configuration")
144  << "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
145  }
146  } else if (psetsFromProvenance.exists("IDWPdefinitions")) {
147  auto const idlist = psetsFromProvenance.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
148  for (size_t i = 0; i < disc.wpLabels.size(); ++i) {
149  bool found = false;
150  for (size_t j = 0; j < idlist.size(); ++j) {
151  if (disc.wpLabels[i] == idlist[j].getParameter<std::string>("IDname")) {
152  found = true;
153  disc.wpCuts[i] = j;
154  }
155  }
156  if (!found)
157  throw cms::Exception("Configuration")
158  << "PFTauSelector: Requested working point '" << disc.wpLabels[i] << "' not found!\n";
159  }
160  } else
161  throw cms::Exception("Configuration") << "PFTauSelector: No suitable ID list found in provenace config!\n";
162  }
163  }
164 
165  const size_t nTaus = hc->size();
166  for (size_t iTau = 0; iTau < nTaus; ++iTau) {
167  bool passed = true;
168  reco::PFTauRef tau(hc, iTau);
169  // Check if it passed all the discrimiantors
170  for (auto const& disc : discriminators_) {
171  // Check this discriminator passes
172  if (!((*disc.handle)[tau] > disc.cut)) {
173  passed = false;
174  break;
175  }
176  }
177  if (passed) { // if passed so far, check other discriminators
178  for (auto const& disc : discriminatorContainers_) {
179  for (auto const& rawCut : disc.rawCuts) {
180  if (!((*disc.handle)[tau].rawValues.at(rawCut.first) > rawCut.second)) {
181  passed = false;
182  break;
183  }
184  }
185  if (!passed)
186  break;
187  for (auto const& wpCut : disc.wpCuts) {
188  if (!((*disc.handle)[tau].workingPoints.at(wpCut))) {
189  passed = false;
190  break;
191  }
192  }
193  if (!passed)
194  break;
195  }
196  }
197 
198  if (passed && cut_.get()) {
199  passed = (*cut_)(*tau);
200  }
201 
202  if (passed)
203  selected_.push_back(tau.get());
204  }
205  } // end select()

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.

◆ size()

size_t PFTauSelectorDefinition::size ( void  ) const
inline

Definition at line 207 of file PFTauSelectorDefinition.h.

207 { return selected_.size(); }

References selected_.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

Member Data Documentation

◆ cut_

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

Definition at line 215 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ discriminatorContainers_

DiscContainerCutPairVec PFTauSelectorDefinition::discriminatorContainers_
private

Definition at line 212 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ discriminators_

DiscCutPairVec PFTauSelectorDefinition::discriminators_
private

Definition at line 211 of file PFTauSelectorDefinition.h.

Referenced by PFTauSelectorDefinition(), and select().

◆ phID_

edm::ProcessHistoryID PFTauSelectorDefinition::phID_
private

Definition at line 213 of file PFTauSelectorDefinition.h.

Referenced by select().

◆ selected_

container PFTauSelectorDefinition::selected_
private

Definition at line 210 of file PFTauSelectorDefinition.h.

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

PFTauSelectorDefinition::discriminators_
DiscCutPairVec discriminators_
Definition: PFTauSelectorDefinition.h:211
mps_fire.i
i
Definition: mps_fire.py:428
metsig::tau
Definition: SignAlgoResolutions.h:49
PDWG_TauSkim_cff.discriminators
discriminators
Definition: PDWG_TauSkim_cff.py:6
reco::PFTauDiscriminator
Definition: PFTauDiscriminator.h:12
PFTauSelectorDefinition::phID_
edm::ProcessHistoryID phID_
Definition: PFTauSelectorDefinition.h:213
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
TtSemiLepEvtBuilder_cfi.disc
disc
Definition: TtSemiLepEvtBuilder_cfi.py:60
edm::Ref< PFTauCollection >
PDWG_TauSkim_cff.discriminatorContainers
discriminatorContainers
Definition: PDWG_TauSkim_cff.py:11
PFTauSelectorDefinition::selected_
container selected_
Definition: PFTauSelectorDefinition.h:210
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
looper.cfg
cfg
Definition: looper.py:297
edm::ValueMap
Definition: ValueMap.h:107
StringCutObjectSelector< reco::PFTau >
Exception
Definition: hltDiff.cc:246
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
PFTauSelectorDefinition::discriminatorContainers_
DiscContainerCutPairVec discriminatorContainers_
Definition: PFTauSelectorDefinition.h:212
TriggerAnalyzer.passed
passed
Definition: TriggerAnalyzer.py:62
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
PFTauSelectorDefinition::cut_
std::unique_ptr< StringCutObjectSelector< reco::PFTau > > cut_
Definition: PFTauSelectorDefinition.h:215
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37