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>
25 #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();
36 
39 
42 
44  bool filter_;
45 
48 
51 
53  int32_t maxProbes_;
54 
56  std::auto_ptr<tnp::BaseTreeFiller> probeFiller_;
57 };
58 
60  probesTag_(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))
67 {
68 }
69 
71 }
72 
74  bool result = !filter_;
76  iEvent.getByLabel(probesTag_, 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
100  probeFiller_->writeProvenance(edm::getProcessParameterSet());
101 }
102 
103 //define this as a plug-in
105 
int i
Definition: DBlmapReader.cc:9
StringObjectFunction< reco::Candidate, true > sortFunction_
The StringObjectFunction itself.
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.
#define min(a, b)
Definition: mlp_lapack.h:161
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:243
virtual bool filter(edm::Event &, const edm::EventSetup &) override
tuple result
Definition: query.py:137
edm::InputTag probesTag_
InputTag to the collection of all probes.
bool first
Definition: L1TdeRCT.cc:94
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
ParameterSet const & getProcessParameterSet()
Definition: Registry.cc:34
StringCutObjectSelector< reco::Candidate, true > cut_
The selector object.
virtual void endJob()
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.
tuple size
Write out results.
bool filter_
Specifies whether this module should filter.