CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProbeTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ProbeTreeProducer
4 // Class: ProbeTreeProducer
5 //
14 #include <memory>
15 #include <ctype.h>
16 #include "boost/bind.hpp"
26 #include <set>
27 
29  public:
30  explicit ProbeTreeProducer(const edm::ParameterSet&);
32 
33  private:
34  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
35  virtual void endJob() override;
36 
39 
42 
44  bool filter_;
45 
48 
51 
53  int32_t maxProbes_;
54 
56  std::auto_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") ? iConfig.getParameter<std::string>("sortDescendingBy") : ""),
64  sortFunction_(sortDescendingBy_.size()>0 ? sortDescendingBy_ : "pt"), //need to pass a valid default
65  maxProbes_(iConfig.existsAs<int32_t>("maxProbes") ? iConfig.getParameter<int32_t>("maxProbes") : -1),
66  probeFiller_(new tnp::BaseTreeFiller("probe_tree", iConfig, consumesCollector()))
67 {
68 }
69 
71 }
72 
74  bool result = !filter_;
76  iEvent.getByToken(probesToken_, probes);
77  if(!probes.isValid()) 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_.size()>0) sort(selectedProbes.begin(), selectedProbes.end(), boost::bind(&Pair::second, _1) > boost::bind(&Pair::second, _2));
90  // fill the first maxProbes_ into the tree
91  for (size_t i = 0; i < (maxProbes_<0 ? selectedProbes.size() : std::min((size_t)maxProbes_, selectedProbes.size())); ++i){
92  probeFiller_->fill(selectedProbes[i].first);
93  result = true;
94  }
95  return result;
96 }
97 
99  // ask to write the current PSet info into the TTree header
101 }
102 
103 //define this as a plug-in
105 
int i
Definition: DBlmapReader.cc:9
StringObjectFunction< reco::Candidate, true > sortFunction_
The StringObjectFunction itself.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
ProbeTreeProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int32_t maxProbes_
The number of first probes used to fill the tree.
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
virtual void endJob() override
tuple result
Definition: mps_fire.py:83
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
virtual bool filter(edm::Event &, const edm::EventSetup &) override
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:75
StringCutObjectSelector< reco::Candidate, true > cut_
The selector object.
ModuleDescription const & moduleDescription() const
Definition: EDFilter.h:52
std::auto_ptr< tnp::BaseTreeFiller > probeFiller_
The object that actually computes variables and fills the tree for the probe.
std::string sortDescendingBy_
Name of the reco::Candidate function used for sorting.
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.
bool filter_
Specifies whether this module should filter.
edm::EDGetTokenT< reco::CandidateView > probesToken_
InputTag to the collection of all probes.