CP3-llbb Framework
CandidatesProducer.h
1 #ifndef CANDIDATES_PRODUCER
2 #define CANDIDATES_PRODUCER
3 
4 #include <CommonTools/Utils/interface/StringCutObjectSelector.h>
5 
6 #include <cp3_llbb/Framework/interface/Producer.h>
7 
8 template<typename ObjectType>
10  public:
11  CandidatesProducer(const std::string& name, const ROOT::TreeGroup& tree, const edm::ParameterSet& config):
12  Producer(name, tree, config),
13  m_cut(config.getUntrackedParameter<std::string>("cut", "1"))
14  {
15  // Empty
16  }
17 
18  virtual ~CandidatesProducer() {}
19 
20  protected:
21  template<typename T, typename U>
22  void fill_candidate(const T& p, const U* gen) {
23  p4.push_back(LorentzVector(p.pt(), p.eta(), p.phi(), p.energy()));
24  y.push_back(p.rapidity());
25  charge.push_back(p.charge());
26  if( gen != 0 )
27  {
28  matched.push_back(true);
29  gen_p4.push_back(LorentzVector(gen->pt(), gen->eta(), gen->phi(), gen->energy()));
30  gen_y.push_back(gen->y());
31  gen_charge.push_back(gen->charge());
32  } else {
33  matched.push_back(false);
34  gen_p4.push_back(LorentzVector(0., 0., 0., 0.));
35  gen_y.push_back(0.);
36  gen_charge.push_back(0.);
37  }
38  }
39 
40  bool pass_cut(const ObjectType& p) {
41  return m_cut(p);
42  }
43 
44  private:
45  // Cut
46  StringCutObjectSelector<ObjectType> m_cut;
47 
48  public:
49  // Tree members
50  std::vector<LorentzVector>& p4 = tree["p4"].write<std::vector<LorentzVector>>();
51  std::vector<float>& y = tree["y"].transient_write<std::vector<float>>();
52  std::vector<int8_t>& charge = tree["charge"].transient_write<std::vector<int8_t>>();
53 
54  std::vector<bool>& matched = tree["has_matched_gen_particle"].write<std::vector<bool>>();
55  std::vector<LorentzVector>& gen_p4 = tree["gen_p4"].write<std::vector<LorentzVector>>();
56  std::vector<float>& gen_y = tree["gen_y"].transient_write<std::vector<float>>();
57  std::vector<int8_t>& gen_charge = tree["gen_charge"].transient_write<std::vector<int8_t>>();
58 
59 };
60 
61 #endif
62 
63 
Definition: CandidatesProducer.h:9
Base class for Framework producers.
Definition: Producer.h:33
ROOT::TreeGroup tree
Access point to output tree.
Definition: Producer.h:132
Producer(const std::string &name, const ROOT::TreeGroup &tree_, const edm::ParameterSet &config)
Base constructor.
Definition: Producer.h:46