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>
28 
30  public:
31  explicit ProbeTreeProducer(const edm::ParameterSet&);
33 
34  private:
35  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
36  virtual void endJob() override;
37 
40 
43 
45  bool filter_;
46 
49 
52 
54  int32_t maxProbes_;
55 
57  std::auto_ptr<tnp::BaseTreeFiller> probeFiller_;
58 };
59 
61  probesToken_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("src"))),
62  cut_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : ""),
63  filter_(iConfig.existsAs<bool>("filter") ? iConfig.getParameter<bool>("filter") : false),
64  sortDescendingBy_(iConfig.existsAs<std::string>("sortDescendingBy") ? iConfig.getParameter<std::string>("sortDescendingBy") : ""),
65  sortFunction_(sortDescendingBy_.size()>0 ? 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 {
69 }
70 
72 }
73 
75  bool result = !filter_;
77  iEvent.getByToken(probesToken_, probes);
78  if(!probes.isValid()) return result;
79  probeFiller_->init(iEvent);
80  // select probes and calculate the sorting value
81  typedef std::pair<reco::CandidateBaseRef, double> Pair;
82  std::vector<Pair> selectedProbes;
83  for (size_t i = 0; i < probes->size(); ++i){
84  const reco::CandidateBaseRef &probe = probes->refAt(i);
85  if(cut_(*probe)){
86  selectedProbes.push_back(Pair(probe, sortFunction_(*probe)));
87  }
88  }
89  // sort only if a function was provided
90  if(sortDescendingBy_.size()>0) 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())); ++i){
93  probeFiller_->fill(selectedProbes[i].first);
94  result = true;
95  }
96  return result;
97 }
98 
100  // ask to write the current PSet info into the TTree header
101  probeFiller_->writeProvenance(edm::getProcessParameterSet());
102 }
103 
104 //define this as a plug-in
106 
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:446
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.
virtual void endJob() override
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
virtual bool filter(edm::Event &, const edm::EventSetup &) override
tuple result
Definition: query.py:137
T min(T a, T b)
Definition: MathUtil.h:58
bool first
Definition: L1TdeRCT.cc:75
bool isValid() const
Definition: HandleBase.h:76
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:85
StringCutObjectSelector< reco::Candidate, true > cut_
The selector object.
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.