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>
25 #include <set>
26 
28 public:
29  explicit ProbeTreeProducer(const edm::ParameterSet&);
30  ~ProbeTreeProducer() override;
31 
32 private:
33  bool filter(edm::Event&, const edm::EventSetup&) override;
34  void endJob() override;
35 
38 
41 
43  bool filter_;
44 
47 
50 
52  int32_t maxProbes_;
53 
55  std::unique_ptr<tnp::BaseTreeFiller> probeFiller_;
56 };
57 
59  : probesToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("src"))),
60  cut_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : ""),
61  filter_(iConfig.existsAs<bool>("filter") ? iConfig.getParameter<bool>("filter") : false),
62  sortDescendingBy_(iConfig.existsAs<std::string>("sortDescendingBy")
63  ? iConfig.getParameter<std::string>("sortDescendingBy")
64  : ""),
65  sortFunction_(!sortDescendingBy_.empty() ? sortDescendingBy_ : "pt"), //need to pass a valid default
66  maxProbes_(iConfig.existsAs<int32_t>("maxProbes") ? iConfig.getParameter<int32_t>("maxProbes") : -1),
67  probeFiller_(new tnp::BaseTreeFiller("probe_tree", iConfig, consumesCollector())) {}
68 
70 
72  bool result = !filter_;
74  iEvent.getByToken(probesToken_, probes);
75  if (!probes.isValid())
76  return result;
77  probeFiller_->init(iEvent);
78  // select probes and calculate the sorting value
79  typedef std::pair<reco::CandidateBaseRef, double> Pair;
80  std::vector<Pair> selectedProbes;
81  for (size_t i = 0; i < probes->size(); ++i) {
82  const reco::CandidateBaseRef& probe = probes->refAt(i);
83  if (cut_(*probe)) {
84  selectedProbes.push_back(Pair(probe, sortFunction_(*probe)));
85  }
86  }
87  // sort only if a function was provided
88  if (!sortDescendingBy_.empty())
89  sort(selectedProbes.begin(), selectedProbes.end(), [&](auto& arg1, auto& arg2) {
90  return arg1.second > arg2.second;
91  });
92  // fill the first maxProbes_ into the tree
93  for (size_t i = 0; i < (maxProbes_ < 0 ? selectedProbes.size() : std::min((size_t)maxProbes_, selectedProbes.size()));
94  ++i) {
95  probeFiller_->fill(selectedProbes[i].first);
96  result = true;
97  }
98  return result;
99 }
100 
102  // ask to write the current PSet info into the TTree header
104 }
105 
106 //define this as a plug-in
ProbeTreeProducer::filter_
bool filter_
Specifies whether this module should filter.
Definition: ProbeTreeProducer.cc:43
reco::CandidateView
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
StringObjectFunction< reco::Candidate, true >
funct::false
false
Definition: Factorize.h:29
edm::EDFilter::moduleDescription
ModuleDescription const & moduleDescription() const
Definition: EDFilter.h:55
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:37
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
ProbeTreeProducer::sortFunction_
StringObjectFunction< reco::Candidate, true > sortFunction_
The StringObjectFunction itself.
Definition: ProbeTreeProducer.cc:49
EDFilter.h
ProbeTreeProducer::~ProbeTreeProducer
~ProbeTreeProducer() override
Definition: ProbeTreeProducer.cc:69
ProbeTreeProducer::ProbeTreeProducer
ProbeTreeProducer(const edm::ParameterSet &)
Definition: ProbeTreeProducer.cc:58
edm::getProcessParameterSetContainingModule
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
Definition: ParameterSet.cc:870
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
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:52
ProbeTreeProducer::endJob
void endJob() override
Definition: ProbeTreeProducer.cc:101
ProbeTreeProducer::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: ProbeTreeProducer.cc:71
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
tnp
Definition: BaseTreeFiller.h:43
edm::ParameterSet
Definition: ParameterSet.h:47
ProbeTreeProducer::cut_
StringCutObjectSelector< reco::Candidate, true > cut_
The selector object.
Definition: ProbeTreeProducer.cc:40
Event.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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:55
edm::EDFilter
Definition: EDFilter.h:38
edm::EventSetup
Definition: EventSetup.h:58
ProbeTreeProducer::sortDescendingBy_
std::string sortDescendingBy_
Name of the reco::Candidate function used for sorting.
Definition: ProbeTreeProducer.cc:46
InputTag.h
ProbeTreeProducer
Definition: ProbeTreeProducer.cc:27
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:311
Candidate.h
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73