CMS 3D CMS Logo

GenJetBCEnergyRatio.cc
Go to the documentation of this file.
1 //
2 // Plugin to store B and C ratio for a GenJet in the event
3 // Author: Attilio
4 // Date: 05.10.2007
5 //
6 
7 //=======================================================================
8 
9 // user include files
14 
21 
25 
32 
36 
37 #include <memory>
38 #include <string>
39 #include <iostream>
40 #include <vector>
41 #include <Math/VectorUtil.h>
42 #include <TMath.h>
43 
44 using namespace std;
45 using namespace reco;
46 using namespace edm;
47 using namespace ROOT::Math::VectorUtil;
48 using namespace JetMCTagUtils;
49 using namespace CandMCTagUtils;
50 
52 public:
54  ~GenJetBCEnergyRatio() override;
55 
57 
58 private:
59  void produce(StreamID, edm::Event&, const edm::EventSetup&) const override;
61 };
62 
63 //=========================================================================
64 
66  produces<JetBCEnergyRatioCollection>("bRatioCollection");
67  produces<JetBCEnergyRatioCollection>("cRatioCollection");
68  m_genjetsSrcToken = consumes<View<Jet> >(iConfig.getParameter<edm::InputTag>("genJets"));
69 }
70 
71 //=========================================================================
72 
74 
75 // ------------ method called to produce the data ------------
76 
78  Handle<View<Jet> > genjets;
79  iEvent.getByToken(m_genjetsSrcToken, genjets);
80 
82 
85 
86  if (!genjets.product()->empty()) {
87  const JetRef jj = genjets->refAt(0);
90  } else {
91  jtc1 = new JetBCEnergyRatioCollection();
92  jtc2 = new JetBCEnergyRatioCollection();
93  }
94 
95  std::unique_ptr<JetBCEnergyRatioCollection> bRatioColl(jtc1);
96  std::unique_ptr<JetBCEnergyRatioCollection> cRatioColl(jtc2);
97 
98  for (size_t j = 0; j != genjets->size(); ++j) {
99  float bRatio = EnergyRatioFromBHadrons((*genjets)[j]);
100  float cRatio = EnergyRatioFromCHadrons((*genjets)[j]);
101 
102  const JetRef& aJet = genjets->refAt(j);
103 
104  JetFloatAssociation::setValue(*bRatioColl, aJet, bRatio);
105  JetFloatAssociation::setValue(*cRatioColl, aJet, cRatio);
106  }
107 
108  iEvent.put(std::move(bRatioColl), "bRatioCollection");
109  iEvent.put(std::move(cRatioColl), "cRatioCollection");
110 }
111 
112 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void produce(StreamID, edm::Event &, const edm::EventSetup &) const override
T const * product() const
Definition: Handle.h:70
edm::Ref< JetBxCollection > JetRef
Definition: Jet.h:12
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
int iEvent
Definition: GenABIO.cc:224
double EnergyRatioFromBHadrons(const reco::Candidate &c)
Definition: JetMCTag.cc:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GenJetBCEnergyRatio(const edm::ParameterSet &)
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
fixed size matrix
HLT enums.
double EnergyRatioFromCHadrons(const reco::Candidate &c)
Definition: JetMCTag.cc:24
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< View< Jet > > m_genjetsSrcToken
reco::JetFloatAssociation::Container JetBCEnergyRatioCollection