CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
JetResolutionDemo Class Reference
Inheritance diagram for JetResolutionDemo:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 JetResolutionDemo (const edm::ParameterSet &)
 
 ~JetResolutionDemo ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
virtual void endJob () override
 

Private Attributes

edm::Service< TFileServicefs
 
bool m_debug = false
 
edm::EDGetTokenT< std::vector
< pat::Jet > > 
m_jets_token
 
std::string m_payload
 
TH2 * m_res_vs_eta = 0
 
std::string m_resolutions_file
 
std::string m_scale_factors_file
 
bool m_use_conddb = false
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 25 of file JetResolutionDemo.cc.

Constructor & Destructor Documentation

JetResolutionDemo::JetResolutionDemo ( const edm::ParameterSet iConfig)
explicit

Definition at line 51 of file JetResolutionDemo.cc.

References contentValuesFiles::fullPath, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_debug, m_jets_token, m_payload, m_resolutions_file, m_scale_factors_file, m_use_conddb, and AlCaHLTBitMon_QueryRunRegistry::string.

52 {
53  m_jets_token = consumes<std::vector<pat::Jet>>(iConfig.getParameter<edm::InputTag>("jets"));
54  m_debug = iConfig.getUntrackedParameter<bool>("debug", false);
55  m_use_conddb = iConfig.getUntrackedParameter<bool>("useCondDB", false);
56 
57  if (m_use_conddb)
58  m_payload = iConfig.getParameter<std::string>("payload");
59  else {
60  m_resolutions_file = iConfig.getParameter<edm::FileInPath>("resolutionsFile").fullPath();
61  m_scale_factors_file = iConfig.getParameter<edm::FileInPath>("scaleFactorsFile").fullPath();
62  }
63 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::string m_scale_factors_file
std::string m_resolutions_file
edm::EDGetTokenT< std::vector< pat::Jet > > m_jets_token
JetResolutionDemo::~JetResolutionDemo ( )

Definition at line 65 of file JetResolutionDemo.cc.

66 {
67 
68 }

Member Function Documentation

void JetResolutionDemo::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDAnalyzer.

Definition at line 71 of file JetResolutionDemo.cc.

References gather_cfg::cout, DOWN, JME::JetResolution::dump(), EnergyCorrector::etas, fs, JME::JetResolution::get(), JME::JetResolutionScaleFactor::get(), JME::JetResolutionObject::Definition::getBins(), edm::Event::getByToken(), JME::JetResolutionObject::getDefinition(), JME::JetResolutionObject::getRecords(), JME::JetResolution::getResolution(), JME::JetResolution::getResolutionObject(), JME::JetResolutionScaleFactor::getScaleFactor(), i, metsig::jet, JME::JetEta, JME::JetPt, fwrapper::jets, m_debug, m_jets_token, m_payload, m_res_vs_eta, m_resolutions_file, m_scale_factors_file, m_use_conddb, TFileService::make(), alignCSCRings::r, diffTwoXMLs::r2, record, dtDQMClient_cfg::resolution, JME::JetParameters::set(), JME::JetParameters::setJetEta(), JME::JetParameters::setJetPt(), and UP.

72 {
73 
75  iEvent.getByToken(m_jets_token, jets);
76 
77  // Access jet resolution and scale factor from the condition database
78  // or from text files
81 
82  // Two differents way to create a class instance
83  if (m_use_conddb) {
84  // First way, using the get() static method
85  resolution = JME::JetResolution::get(iSetup, m_payload);
87  } else {
88  // Second way, using the constructor
91  }
92 
93  if (m_debug) {
94  // Dump resolution
95  resolution.dump();
96  }
97 
98  if (! m_res_vs_eta) {
99 
100  // Advanced usage. Create the histogram by retriving the eta binning directly from the JetResolutionObject. This suppose you need that the parametrization only depends on eta.
101 
102  // Get the list of bins of this object
103  const std::vector<JME::Binning>& bins = resolution.getResolutionObject()->getDefinition().getBins();
104 
105  // Check that the first bin is eta
106  if ((bins.size()) && (bins[0] == JME::Binning::JetEta)) {
107 
108  const std::vector<JME::JetResolutionObject::Record> records = resolution.getResolutionObject()->getRecords();
109  // Get all records from the object. Each record correspond to a different binning and different parameters
110 
111  std::vector<float> etas;
112  for (const auto& record: records) {
113  if (etas.empty()) {
114  etas.push_back(record.getBinsRange()[0].min);
115  etas.push_back(record.getBinsRange()[0].max);
116  } else {
117  etas.push_back(record.getBinsRange()[0].max);
118  }
119  }
120 
121  std::vector<float> res;
122  for (std::size_t i = 0; i < 40; i++) {
123  res.push_back(i * 0.005);
124  }
125 
126  m_res_vs_eta = fs->make<TH2F>("res_vs_eta", "res_vs_eta", etas.size() - 1, &etas[0], res.size() - 1, &res[0]);
127  }
128  }
129 
130  for (const auto& jet: *jets) {
131  if (m_debug) {
132  std::cout << "New jet; pt=" << jet.pt() << " eta=" << jet.eta() << " phi=" << jet.phi() << " e=" << jet.energy() << std::endl;
133  }
134 
135 
136  // Get resolution for this jet
137  // The method to use is getResolution(const JME::JetParameters& parameters) from a JetResolution object
138 
139  // You *must* now in advance which variables are needed for getting the resolution. For the moment, only pt and eta are needed, but this will
140  // probably change in the futur when PU dependency is added. Please keep an eye on the twiki page
141  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyResolution
142  // to stay up-to-date. All currently supported parameters (ie, 'set' functions) are available here:
143  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookJetEnergyResolution#List_of_supported_parameters
144 
145 
146  // Three way to create a JetParameters object
147 
148  // First, using 'set' functions
149  JME::JetParameters parameters_1;
150  parameters_1.setJetPt(jet.pt());
151  parameters_1.setJetEta(jet.eta());
152 
153  // You can also chain calls
154 
155  JME::JetParameters parameters_2;
156  parameters_2.setJetPt(jet.pt()).setJetEta(jet.eta());
157 
158  // Second, using the set() function
159  JME::JetParameters parameters_3;
160  parameters_3.set(JME::Binning::JetPt, jet.pt());
161  parameters_3.set({JME::Binning::JetEta, jet.eta()});
162 
163  // Or
164 
165  JME::JetParameters parameters_4;
166  parameters_4.set(JME::Binning::JetPt, jet.pt()).set(JME::Binning::JetEta, jet.eta());
167 
168  // Third, using a initializer_list
169  JME::JetParameters parameters_5 = {{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}};
170 
171  // Now, get the resolution
172 
173  float r = resolution.getResolution(parameters_1);
174  if (m_debug) {
175  std::cout << "Resolution with parameters_1: " << r << std::endl;
176  std::cout << "Resolution with parameters_2: " << resolution.getResolution(parameters_2) << std::endl;
177  std::cout << "Resolution with parameters_3: " << resolution.getResolution(parameters_3) << std::endl;
178  std::cout << "Resolution with parameters_4: " << resolution.getResolution(parameters_4) << std::endl;
179  std::cout << "Resolution with parameters_5: " << resolution.getResolution(parameters_5) << std::endl;
180 
181  // You can also use a shortcut to get the resolution
182  float r2 = resolution.getResolution({{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}});
183  std::cout << "Resolution using shortcut : " << r2 << std::endl;
184  }
185 
186  m_res_vs_eta->Fill(jet.eta(), r);
187 
188  // We do the same thing to access the scale factors
189  float sf = res_sf.getScaleFactor({{JME::Binning::JetEta, jet.eta()}});
190 
191  // Access up and down variation of the scale factor
192  float sf_up = res_sf.getScaleFactor({{JME::Binning::JetEta, jet.eta()}}, Variation::UP);
193  float sf_down = res_sf.getScaleFactor({{JME::Binning::JetEta, jet.eta()}}, Variation::DOWN);
194 
195  if (m_debug) {
196  std::cout << "Scale factors (Nominal / Up / Down) : " << sf << " / " << sf_up << " / " << sf_down << std::endl;
197  }
198  }
199 }
std::string m_scale_factors_file
int i
Definition: DBlmapReader.cc:9
float getResolution(const JetParameters &parameters) const
JetParameters & setJetEta(float eta)
const std::vector< Binning > & getBins() const
static const JetResolution get(const edm::EventSetup &, const std::string &)
JetCorrectorParameters::Record record
Definition: classes.h:7
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
JetParameters & set(const Binning &bin, float value)
void dump() const
Definition: JetResolution.h:32
const std::vector< Record > & getRecords() const
const Definition & getDefinition() const
vector< PseudoJet > jets
std::string m_resolutions_file
edm::EDGetTokenT< std::vector< pat::Jet > > m_jets_token
const JetResolutionObject * getResolutionObject() const
Definition: JetResolution.h:37
float getScaleFactor(const JetParameters &parameters, Variation variation=Variation::NOMINAL) const
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
tuple cout
Definition: gather_cfg.py:121
JetParameters & setJetPt(float pt)
edm::Service< TFileService > fs
void JetResolutionDemo::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 201 of file JetResolutionDemo.cc.

202 {
203 
204 }

Member Data Documentation

edm::Service<TFileService> JetResolutionDemo::fs
private

Definition at line 43 of file JetResolutionDemo.cc.

Referenced by analyze().

bool JetResolutionDemo::m_debug = false
private

Definition at line 36 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

edm::EDGetTokenT<std::vector<pat::Jet> > JetResolutionDemo::m_jets_token
private

Definition at line 34 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

std::string JetResolutionDemo::m_payload
private

Definition at line 39 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

TH2* JetResolutionDemo::m_res_vs_eta = 0
private

Definition at line 45 of file JetResolutionDemo.cc.

Referenced by analyze().

std::string JetResolutionDemo::m_resolutions_file
private

Definition at line 40 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

std::string JetResolutionDemo::m_scale_factors_file
private

Definition at line 41 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().

bool JetResolutionDemo::m_use_conddb = false
private

Definition at line 37 of file JetResolutionDemo.cc.

Referenced by analyze(), and JetResolutionDemo().