CMS 3D CMS Logo

ProbeTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ProbeTreeProducer
4 // Class: ProbeTreeProducer
5 //
14 #include <memory>
15 #include <cctype>
16 #include "boost/bind.hpp"
26 #include <set>
27 
29 public:
30  explicit ProbeTreeProducer(const edm::ParameterSet&);
31  ~ProbeTreeProducer() override;
32 
33 private:
34  bool filter(edm::Event&, const edm::EventSetup&) override;
35  void endJob() override;
36 
39 
42 
44  bool filter_;
45 
48 
51 
53  int32_t maxProbes_;
54 
56  std::unique_ptr<tnp::BaseTreeFiller> probeFiller_;
57 };
58 
60  : probesToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("src"))),
61  cut_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : ""),
62  filter_(iConfig.existsAs<bool>("filter") ? iConfig.getParameter<bool>("filter") : false),
63  sortDescendingBy_(iConfig.existsAs<std::string>("sortDescendingBy")
64  ? iConfig.getParameter<std::string>("sortDescendingBy")
65  : ""),
66  sortFunction_(!sortDescendingBy_.empty() ? sortDescendingBy_ : "pt"), //need to pass a valid default
67  maxProbes_(iConfig.existsAs<int32_t>("maxProbes") ? iConfig.getParameter<int32_t>("maxProbes") : -1),
68  probeFiller_(new tnp::BaseTreeFiller("probe_tree", iConfig, consumesCollector())) {}
69 
71 
73  bool result = !filter_;
75  iEvent.getByToken(probesToken_, probes);
76  if (!probes.isValid())
77  return result;
78  probeFiller_->init(iEvent);
79  // select probes and calculate the sorting value
80  typedef std::pair<reco::CandidateBaseRef, double> Pair;
81  std::vector<Pair> selectedProbes;
82  for (size_t i = 0; i < probes->size(); ++i) {
83  const reco::CandidateBaseRef& probe = probes->refAt(i);
84  if (cut_(*probe)) {
85  selectedProbes.push_back(Pair(probe, sortFunction_(*probe)));
86  }
87  }
88  // sort only if a function was provided
89  if (!sortDescendingBy_.empty())
90  sort(selectedProbes.begin(), selectedProbes.end(), boost::bind(&Pair::second, _1) > boost::bind(&Pair::second, _2));
91  // fill the first maxProbes_ into the tree
92  for (size_t i = 0; i < (maxProbes_ < 0 ? selectedProbes.size() : std::min((size_t)maxProbes_, selectedProbes.size()));
93  ++i) {
94  probeFiller_->fill(selectedProbes[i].first);
95  result = true;
96  }
97  return result;
98 }
99 
101  // ask to write the current PSet info into the TTree header
103 }
104 
105 //define this as a plug-in
ProbeTreeProducer::filter_
bool filter_
Specifies whether this module should filter.
Definition: ProbeTreeProducer.cc:44
reco::CandidateView
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
StringObjectFunction< reco::Candidate, true >
funct::false
false
Definition: Factorize.h:34
edm::EDFilter::moduleDescription
ModuleDescription const & moduleDescription() const
Definition: EDFilter.h:56
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::View::refAt
RefToBase< value_type > refAt(size_type i) const
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
ProbeTreeProducer::probesToken_
edm::EDGetTokenT< reco::CandidateView > probesToken_
InputTag to the collection of all probes.
Definition: ProbeTreeProducer.cc:38
ProbeTreeProducer::sortFunction_
StringObjectFunction< reco::Candidate, true > sortFunction_
The StringObjectFunction itself.
Definition: ProbeTreeProducer.cc:50
EDFilter.h
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
ProbeTreeProducer::~ProbeTreeProducer
~ProbeTreeProducer() override
Definition: ProbeTreeProducer.cc:70
ProbeTreeProducer::ProbeTreeProducer
ProbeTreeProducer(const edm::ParameterSet &)
Definition: ProbeTreeProducer.cc:59
edm::getProcessParameterSetContainingModule
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
Definition: ParameterSet.cc:863
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
CandidateFwd.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ProbeTreeProducer::maxProbes_
int32_t maxProbes_
The number of first probes used to fill the tree.
Definition: ProbeTreeProducer.cc:53
ProbeTreeProducer::endJob
void endJob() override
Definition: ProbeTreeProducer.cc:100
ProbeTreeProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: ProbeTreeProducer.cc:72
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
tnp
Definition: BaseTreeFiller.h:41
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
ProbeTreeProducer::cut_
StringCutObjectSelector< reco::Candidate, true > cut_
The selector object.
Definition: ProbeTreeProducer.cc:41
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
ProbeTreeProducer::probeFiller_
std::unique_ptr< tnp::BaseTreeFiller > probeFiller_
The object that actually computes variables and fills the tree for the probe.
Definition: ProbeTreeProducer.cc:56
edm::EDFilter
Definition: EDFilter.h:39
edm::EventSetup
Definition: EventSetup.h:57
ProbeTreeProducer::sortDescendingBy_
std::string sortDescendingBy_
Name of the reco::Candidate function used for sorting.
Definition: ProbeTreeProducer.cc:47
InputTag.h
ProbeTreeProducer
Definition: ProbeTreeProducer.cc:28
std
Definition: JetResolutionObject.h:76
BaseTreeFiller.h
Frameworkfwd.h
StringCutObjectSelector< reco::Candidate, true >
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::RefToBase< Candidate >
mps_fire.result
result
Definition: mps_fire.py:303
Candidate.h
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73