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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double EnergyRatioFromBHadrons(const reco::Candidate &c)
Definition: JetMCTag.cc:12
GenJetBCEnergyRatio(const edm::ParameterSet &)
T const * product() const
Definition: Handle.h:69
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
void produce(StreamID, edm::Event &, const edm::EventSetup &) const override
edm::EDGetTokenT< View< Jet > > m_genjetsSrcToken
reco::JetFloatAssociation::Container JetBCEnergyRatioCollection